]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
platform-intel - cache 'intel_devices' for a few seconds.
authorNeilBrown <neilb@suse.de>
Sun, 6 Jan 2013 23:34:43 +0000 (10:34 +1100)
committerNeilBrown <neilb@suse.de>
Sun, 6 Jan 2013 23:34:43 +0000 (10:34 +1100)
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>
platform-intel.c
platform-intel.h
super-intel.c

index 0dcf07c298e51ec753078b3f52d3f686d76ff96d..435a9b9963d2adaf389b891e455a689a9e40991f 100644 (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;
index 94f2e81b9b141cd1a5f185404c289ffeae5b09dd..de433bd6b20a68682ea5b8067d919aecc1dd822c 100644 (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);
index 4ac9d42badd124355ca14439289bbea445348da0..4c30b7e849f5fc46349d166ba8d29309cb11380e 100644 (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;
 }