platform-intel - cache 'intel_devices' for a few seconds.

find_intel_devices() has take a little while to run as it scans
some directory tree, and the result isn't likely to change
often.
So cache the value and only discard it after 10 seconds.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2013-01-07 10:34:43 +11:00
parent 06d2ffc3e2
commit 9bc4ae77e4
3 changed files with 17 additions and 37 deletions

View File

@ -36,7 +36,7 @@ static int devpath_to_ll(const char *dev_path, const char *entry,
static __u16 devpath_to_vendor(const char *dev_path);
void free_sys_dev(struct sys_dev **list)
static void free_sys_dev(struct sys_dev **list)
{
while (*list) {
struct sys_dev *next = (*list)->next;
@ -127,6 +127,7 @@ struct sys_dev *find_driver_devices(const char *bus, const char *driver)
static struct sys_dev *intel_devices=NULL;
static time_t valid_time = 0;
static enum sys_dev_type device_type_by_id(__u16 device_id)
{
@ -183,6 +184,12 @@ struct sys_dev *find_intel_devices(void)
{
struct sys_dev *ahci, *isci;
if (valid_time > time(0) - 10)
return intel_devices;
if (intel_devices)
free_sys_dev(&intel_devices);
isci = find_driver_devices("pci", "isci");
ahci = find_driver_devices("pci", "ahci");
@ -194,7 +201,9 @@ struct sys_dev *find_intel_devices(void)
elem = elem->next;
elem->next = isci;
}
return ahci;
intel_devices = ahci;
valid_time = time(0);
return intel_devices;
}
/*
@ -305,11 +314,7 @@ static const struct imsm_orom *find_imsm_hba_orom(enum sys_dev_type hba_id)
check_env("IMSM_TEST_SCU_EFI"))
return NULL;
if (intel_devices != NULL)
free_sys_dev(&intel_devices);
intel_devices = find_intel_devices();
find_intel_devices();
if (intel_devices == NULL)
return NULL;
@ -326,10 +331,6 @@ static const struct imsm_orom *find_imsm_hba_orom(enum sys_dev_type hba_id)
scan_adapter_roms(scan);
probe_roms_exit();
if (intel_devices != NULL)
free_sys_dev(&intel_devices);
intel_devices = NULL;
if (populated_orom[hba_id])
return &imsm_orom[hba_id];
return NULL;

View File

@ -202,7 +202,6 @@ static inline char *guid_str(char *buf, struct efi_guid guid)
char *diskfd_to_devpath(int fd);
struct sys_dev *find_driver_devices(const char *bus, const char *driver);
struct sys_dev *find_intel_devices(void);
void free_sys_dev(struct sys_dev **list);
const struct imsm_orom *find_imsm_capability(enum sys_dev_type hba_id);
const struct imsm_orom *find_imsm_orom(void);
int disk_attached_to_hba(int fd, const char *hba_path);

View File

@ -567,7 +567,7 @@ static int attach_hba_to_super(struct intel_super *super, struct sys_dev *device
static struct sys_dev* find_disk_attached_hba(int fd, const char *devname)
{
struct sys_dev *list, *elem, *prev;
struct sys_dev *list, *elem;
char *disk_path;
if ((list = find_intel_devices()) == NULL)
@ -578,27 +578,15 @@ static struct sys_dev* find_disk_attached_hba(int fd, const char *devname)
else
disk_path = diskfd_to_devpath(fd);
if (!disk_path) {
free_sys_dev(&list);
if (!disk_path)
return 0;
}
for (prev = NULL, elem = list; elem; prev = elem, elem = elem->next) {
if (path_attached_to_hba(disk_path, elem->path)) {
if (prev == NULL)
list = list->next;
else
prev->next = elem->next;
elem->next = NULL;
if (disk_path != devname)
free(disk_path);
free_sys_dev(&list);
for (elem = list; elem; elem = elem->next)
if (path_attached_to_hba(disk_path, elem->path))
return elem;
}
}
if (disk_path != devname)
free(disk_path);
free_sys_dev(&list);
return NULL;
}
@ -1858,7 +1846,6 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
else
result = 0;
}
free_sys_dev(&list);
return result;
}
@ -1867,7 +1854,6 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
if (verbose > 0)
pr_err("no active Intel(R) RAID "
"controller found.\n");
free_sys_dev(&list);
return 2;
} else if (verbose > 0)
print_found_intel_controllers(list);
@ -1900,7 +1886,6 @@ static int detail_platform_imsm(int verbose, int enumerate_only, char *controlle
pr_err("no active Intel(R) RAID "
"controller found under %s\n",controller_path);
free_sys_dev(&list);
return result;
}
@ -1915,7 +1900,6 @@ static int export_detail_platform_imsm(int verbose, char *controller_path)
if (verbose > 0)
pr_err("IMSM_DETAIL_PLATFORM_ERROR=NO_INTEL_DEVICES\n");
result = 2;
free_sys_dev(&list);
return result;
}
@ -3813,11 +3797,9 @@ static int find_intel_hba_capability(int fd, struct intel_super *super, char *de
" Mixing devices attached to multiple controllers "
"is not allowed.\n");
}
free_sys_dev(&hba_name);
return 2;
}
super->orom = find_imsm_capability(hba_name->type);
free_sys_dev(&hba_name);
if (!super->orom)
return 3;
return 0;
@ -9346,8 +9328,6 @@ static const char *imsm_get_disk_controller_domain(const char *path)
dprintf("path: %s hba: %s attached: %s\n",
path, (hba) ? hba->path : "NULL", drv);
free(path);
if (hba)
free_sys_dev(&hba);
}
return drv;
}