summaryrefslogtreecommitdiffstats
path: root/platform-intel.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2013-01-07 00:34:43 +0100
committerNeilBrown <neilb@suse.de>2013-01-07 00:34:43 +0100
commit9bc4ae77e40b5af3cd4be3e4d5aff18e6964e8fa (patch)
tree7e3deec8cb057c665e1b6ea0b9ce996cb18e8aa3 /platform-intel.c
parentconditionally remove map_dev from find_free_devnum (diff)
downloadmdadm-9bc4ae77e40b5af3cd4be3e4d5aff18e6964e8fa.tar.xz
mdadm-9bc4ae77e40b5af3cd4be3e4d5aff18e6964e8fa.zip
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>
Diffstat (limited to 'platform-intel.c')
-rw-r--r--platform-intel.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/platform-intel.c b/platform-intel.c
index 0dcf07c2..435a9b99 100644
--- a/platform-intel.c
+++ b/platform-intel.c
@@ -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;