]> sourceware.org Git - lvm2.git/commitdiff
process_each_label: use lvmcache
authorDavid Teigland <teigland@redhat.com>
Fri, 9 Feb 2018 17:24:40 +0000 (11:24 -0600)
committerDavid Teigland <teigland@redhat.com>
Fri, 20 Apr 2018 16:22:46 +0000 (11:22 -0500)
In the same way as the other process_each functions.
In the common case all the info that's needed can be
used from lvmcache after a label scan.  But this means
that unchosen devs for duplicate PVs need to be handled
explicitly.

tools/toollib.c

index 659319528afb573dfd38cae9765a5cc990fb80e0..f6169ae6bf8536ec98835fed6a58af5f9bd00e1f 100644 (file)
@@ -1493,13 +1493,19 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
        struct label *label;
        struct dev_iter *iter;
        struct device *dev;
-
+       struct lvmcache_info *info;
+       struct dm_list process_duplicates;
+       struct device_list *devl;
        int ret_max = ECMD_PROCESSED;
        int ret;
        int opt = 0;
 
+       dm_list_init(&process_duplicates);
+
        log_set_report_object_type(LOG_REPORT_OBJECT_TYPE_LABEL);
 
+       lvmcache_label_scan(cmd);
+
        if (argc) {
                for (; opt < argc; opt++) {
                        if (!(dev = dev_cache_get(argv[opt], cmd->full_filter))) {
@@ -1509,14 +1515,54 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
                                continue;
                        }
 
+                       if (!(label = lvmcache_get_dev_label(dev))) {
+                               if (!lvmcache_dev_is_unchosen_duplicate(dev)) {
+                                       log_error("No physical volume label read from %s.", argv[opt]);
+                                       ret_max = ECMD_FAILED;
+                               } else {
+                                       if (!(devl = dm_malloc(sizeof(*devl))))
+                                               return_0;
+                                       devl->dev = dev;
+                                       dm_list_add(&process_duplicates, &devl->list);
+                               }
+                               continue;
+                       }
+
                        log_set_report_object_name_and_id(dev_name(dev), NULL);
 
-                       if (!label_read(dev, &label, 0)) {
-                               log_error("No physical volume label read from %s.",
-                                         argv[opt]);
-                               ret_max = ECMD_FAILED;
+                       ret = process_single_label(cmd, label, handle);
+                       report_log_ret_code(ret);
+
+                       if (ret > ret_max)
+                               ret_max = ret;
+
+                       log_set_report_object_name_and_id(NULL, NULL);
+
+                       if (sigint_caught())
+                               break;
+               }
+
+               dm_list_iterate_items(devl, &process_duplicates) {
+                       /* 
+                        * remove the existing dev for this pvid from lvmcache
+                        * so that the duplicate dev can replace it.
+                        */
+                       if ((info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
+                               lvmcache_del(info);
+
+                       /*
+                        * add info to lvmcache from the duplicate dev.
+                        */
+                       label_read(devl->dev, NULL, 0);
+
+                       /*
+                        * the info/label should now be found because
+                        * the label_read should have added it.
+                        */
+                       if (!(label = lvmcache_get_dev_label(devl->dev)))
                                continue;
-                       }
+
+                       log_set_report_object_name_and_id(dev_name(dev), NULL);
 
                        ret = process_single_label(cmd, label, handle);
                        report_log_ret_code(ret);
@@ -1541,7 +1587,7 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
 
        while ((dev = dev_iter_get(iter)))
        {
-               if (!label_read(dev, &label, 0))
+               if (!(label = lvmcache_get_dev_label(dev)))
                        continue;
 
                log_set_report_object_name_and_id(dev_name(label->dev), NULL);
This page took 0.037298 seconds and 5 git commands to generate.