]> sourceware.org Git - lvm2.git/commitdiff
Add checks for duplicate LV name, lvid and PV id before writing metadata.
authorAlasdair Kergon <agk@redhat.com>
Wed, 9 Aug 2006 19:33:25 +0000 (19:33 +0000)
committerAlasdair Kergon <agk@redhat.com>
Wed, 9 Aug 2006 19:33:25 +0000 (19:33 +0000)
Report all sanity check failures, not just the first.

WHATS_NEW
lib/metadata/metadata.c

index b49ead820b3f02a9bc8eba35918774452981202e..87e7bfe971ea8c0d223368403ea0b9e552bccb19 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
 Version 2.02.08 - 
 ================================
+  Add checks for duplicate LV name, lvid and PV id before writing metadata.
+  Report all sanity check failures, not just the first.
   Fix missing lockfs on first snapshot creation.
   Add unreliable --trustcache option to reporting commands.
   Fix locking for mimage removal.
index 76bbad01994b4ece64b42ae1fd7e75cb21c8b35a..e936cf5d73edd7be6577a1522f8e88870e65dceb 100644 (file)
@@ -722,23 +722,68 @@ int vg_remove(struct volume_group *vg)
 
 int vg_validate(struct volume_group *vg)
 {
-       struct lv_list *lvl;
+       struct pv_list *pvl, *pvl2;
+       struct lv_list *lvl, *lvl2;
+       char uuid[64];
+       int r = 1;
+
+       list_iterate_items(pvl, &vg->pvs) {
+               list_iterate_items(pvl2, &vg->pvs) {
+                       if (pvl == pvl2)
+                               break;
+                       if (id_equal(&pvl->pv->id,
+                                    &pvl2->pv->id)) {
+                               if (!id_write_format(&pvl->pv->id, uuid,
+                                                    sizeof(uuid)))
+                                        stack;
+                               log_error("Internal error: Duplicate PV id "
+                                         "%s detected for %s in %s.",
+                                         uuid, dev_name(pvl->pv->dev),
+                                         vg->name);
+                               r = 0;
+                       }
+               }
+       }
 
        if (!check_pv_segments(vg)) {
                log_error("Internal error: PV segments corrupted in %s.",
                          vg->name);
-               return 0;
+               r = 0;
+       }
+
+       list_iterate_items(lvl, &vg->lvs) {
+               list_iterate_items(lvl2, &vg->lvs) {
+                       if (lvl == lvl2)
+                               break;
+                       if (!strcmp(lvl->lv->name, lvl2->lv->name)) {
+                               log_error("Internal error: Duplicate LV name "
+                                         "%s detected in %s.", lvl->lv->name,
+                                         vg->name);
+                               r = 0;
+                       }
+                       if (id_equal(&lvl->lv->lvid.id[1],
+                                    &lvl2->lv->lvid.id[1])) {
+                               if (!id_write_format(&lvl->lv->lvid.id[1], uuid,
+                                                    sizeof(uuid)))
+                                        stack;
+                               log_error("Internal error: Duplicate LV id "
+                                         "%s detected for %s and %s in %s.",
+                                         uuid, lvl->lv->name, lvl2->lv->name,
+                                         vg->name);
+                               r = 0;
+                       }
+               }
        }
 
        list_iterate_items(lvl, &vg->lvs) {
                if (!check_lv_segments(lvl->lv, 1)) {
                        log_error("Internal error: LV segments corrupted in %s.",
                                  lvl->lv->name);
-                       return 0;
+                       r = 0;
                }
        }
 
-       return 1;
+       return r;
 }
 
 /*
This page took 0.042576 seconds and 5 git commands to generate.