]> sourceware.org Git - lvm2.git/commitdiff
label: use dev iterator directly
authorZdenek Kabelac <zkabelac@redhat.com>
Wed, 19 Jun 2024 12:19:52 +0000 (14:19 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Fri, 21 Jun 2024 09:28:54 +0000 (11:28 +0200)
Avoid preparing 'extra' dm_list with devices, and just
use the iterator result directly.

lib/label/label.c

index b4fcff8b0dad620e0ee8bb652fc1b54a8594f44b..20ac1bdc80e02c098184733b3ee2c96ed469ab0e 100644 (file)
@@ -875,7 +875,6 @@ int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev
        char buf[LABEL_SIZE] __attribute__((aligned(8)));
        struct dm_list devs;
        struct dev_iter *iter;
-       struct device_list *devl, *devl2;
        struct device *dev;
        struct pv_header *pvh;
        int ret = 0;
@@ -891,6 +890,9 @@ int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev
                return 0;
        }
 
+       if (!label_scan_setup_bcache())
+               return_0;
+
        /*
         * Iterating over all available devices with cmd->filter filters
         * devices; those returned from dev_iter_get are the devs that
@@ -902,23 +904,10 @@ int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev
                return 0;
        }
 
-       log_debug_devs("Filtering devices to scan");
-
-       while ((dev = dev_iter_get(cmd, iter))) {
-               if (!(devl = zalloc(sizeof(*devl))))
-                       continue;
-               devl->dev = dev;
-               dm_list_add(&devs, &devl->list);
-       };
-       dev_iter_destroy(iter);
-
-       if (!label_scan_setup_bcache())
-               goto_out;
 
        log_debug_devs("Reading labels for pvid");
 
-       dm_list_iterate_items(devl, &devs) {
-               dev = devl->dev;
+       while ((dev = dev_iter_get(cmd, iter))) {
 
                memset(buf, 0, sizeof(buf));
 
@@ -933,7 +922,7 @@ int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev
                pvh = (struct pv_header *)(buf + 32);
 
                if (!memcmp(pvh->pv_uuid, pvid, ID_LEN)) {
-                       *dev_out = devl->dev;
+                       *dev_out = dev;
                        _scan_dev_close(dev);
                        break;
                }
@@ -942,10 +931,8 @@ int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev
        }
        ret = 1;
  out:
-       dm_list_iterate_items_safe(devl, devl2, &devs) {
-               dm_list_del(&devl->list);
-               free(devl);
-       }
+       dev_iter_destroy(iter);
+
        return ret;
 }
 
This page took 0.03427 seconds and 5 git commands to generate.