]> sourceware.org Git - lvm2.git/commitdiff
Merge lv_is_displayable and lv_is_visible.
authorMilan Broz <mbroz@redhat.com>
Wed, 13 May 2009 21:27:43 +0000 (21:27 +0000)
committerMilan Broz <mbroz@redhat.com>
Wed, 13 May 2009 21:27:43 +0000 (21:27 +0000)
Displayable and visible is the same thing.

volumes_count(vg) is now vg_visible_lvs() and always
returns number of LVs from user perspective.

16 files changed:
WHATS_NEW
lib/activate/activate.c
lib/display/display.c
lib/format1/import-export.c
lib/format_text/export.c
lib/metadata/lv_manip.c
lib/metadata/metadata-exported.h
lib/metadata/metadata.c
lib/metadata/metadata.h
lib/metadata/snapshot_manip.c
lib/report/report.c
tools/lvchange.c
tools/lvdisplay.c
tools/lvscan.c
tools/reporter.c
tools/vgchange.c

index 990f6f5a1c1778063b7061150a27543b335b395a..56bc03bf80e939eff2333815ca8821f3c5cf282b 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.46 - 
 ================================
+  Merge lv_is_displayable and lv_is_visible functions.
   Introduce lv_set_visible & lv_set_invisible functions.
   Fix lv_is_visible to handle virtual origin.
   Introduce link_lv_to_vg and unlink_lv_from_vg functions.
index e38c4d84083ec82e1a0e0709b2ebad071cd2091f..34f979a88fdb6a31a548e205c466f4bb93651cd3 100644 (file)
@@ -673,7 +673,7 @@ int lvs_in_vg_opened(const struct volume_group *vg)
                return 0;
 
        dm_list_iterate_items(lvl, &vg->lvs) {
-               if (lv_is_displayable(lvl->lv))
+               if (lv_is_visible(lvl->lv))
                        count += (_lv_open_count(vg->cmd, lvl->lv) > 0);
        }
 
index c1ae8dbab4d27904e5d9d6108bd33ffc1640a707..0de0a8e8db4b525f85ab0f5edcbe696d5d2de0cc 100644 (file)
@@ -606,7 +606,7 @@ void vgdisplay_full(const struct volume_group *vg)
        }
 
        log_print("MAX LV                %u", vg->max_lv);
-       log_print("Cur LV                %u", displayable_lvs_in_vg(vg));
+       log_print("Cur LV                %u", vg_visible_lvs(vg));
        log_print("Open LV               %u", lvs_in_vg_opened(vg));
 /****** FIXME Max LV Size
       log_print ( "MAX LV Size           %s",
@@ -681,7 +681,7 @@ void vgdisplay_colons(const struct volume_group *vg)
                vg->status,
                /* internal volume group number; obsolete */
                vg->max_lv,
-               displayable_lvs_in_vg(vg),
+               vg_visible_lvs(vg),
                lvs_in_vg_opened(vg),
                /* FIXME: maximum logical volume size */
                vg->max_pv,
index 5250e4843e5a5cdf8f9af5edc42396e8791ba886..c0a89c5aa9081b8942de85dae8afab3669210429 100644 (file)
@@ -282,7 +282,7 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg)
                vgd->vg_status |= VG_EXTENDABLE;
 
        vgd->lv_max = vg->max_lv;
-       vgd->lv_cur = volumes_count(vg) + snapshot_count(vg);
+       vgd->lv_cur = vg_visible_lvs(vg) + snapshot_count(vg);
 
        vgd->pv_max = vg->max_pv;
        vgd->pv_cur = vg->pv_count;
index 604138cb4297f5977db48586f936359a7a95a7a5..ce6676ebe1b5a17e37ddc468ff2e2448f65572c6 100644 (file)
@@ -592,14 +592,14 @@ static int _print_lvs(struct formatter *f, struct volume_group *vg)
         * Write visible LVs first
         */
        dm_list_iterate_items(lvl, &vg->lvs) {
-               if (!(lv_is_displayable(lvl->lv)))
+               if (!(lv_is_visible(lvl->lv)))
                        continue;
                if (!_print_lv(f, lvl->lv))
                        return_0;
        }
 
        dm_list_iterate_items(lvl, &vg->lvs) {
-               if ((lv_is_displayable(lvl->lv)))
+               if ((lv_is_visible(lvl->lv)))
                        continue;
                if (!_print_lv(f, lvl->lv))
                        return_0;
index 1a2654b8b31647c3405bbce8d5b6979feeaf9b1e..910f54508f8c297529add4448e49cce3d27b7469 100644 (file)
@@ -1732,7 +1732,7 @@ int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
        int r = 0;
 
        /* rename is not allowed on sub LVs */
-       if (!lv_is_displayable(lv)) {
+       if (!lv_is_visible(lv)) {
                log_error("Cannot rename internal LV \"%s\".", lv->name);
                return 0;
        }
@@ -1818,7 +1818,7 @@ struct logical_volume *lv_create_empty(const char *name,
        struct logical_volume *lv;
        char dname[NAME_LEN];
 
-       if (vg->max_lv && (vg->max_lv == volumes_count(vg))) {
+       if (vg->max_lv && (vg->max_lv == vg_visible_lvs(vg))) {
                log_error("Maximum number of logical volumes (%u) reached "
                          "in volume group %s", vg->max_lv, vg->name);
                return NULL;
index d7dc3c52e7b85bd83e2b13fedf2b2fbe7c82f496..2de8c01af4719e784cd05cc02feffb9cfa9a0f8e 100644 (file)
@@ -238,18 +238,16 @@ struct volume_group {
        /*
         * logical volumes
         * The following relationship should always hold:
-        * dm_list_size(lvs) = lv_count + 2 * snapshot_count
+        * dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs
         *
         * Snapshots consist of 2 instances of "struct logical_volume":
         * - cow (lv_name is visible to the user)
         * - snapshot (lv_name is 'snapshotN')
-        * Neither of these instances is reflected in lv_count.
         *
         * Mirrors consist of multiple instances of "struct logical_volume":
         * - one for the mirror log
         * - one for each mirror leg
         * - one for the user-visible mirror LV
-        * all of the instances are reflected in lv_count.
         */
        struct dm_list lvs;
 
@@ -539,10 +537,9 @@ struct lv_segment *first_seg(const struct logical_volume *lv);
 int lv_is_origin(const struct logical_volume *lv);
 int lv_is_virtual_origin(const struct logical_volume *lv);
 int lv_is_cow(const struct logical_volume *lv);
-int lv_is_visible(const struct logical_volume *lv);
 
 /* Test if given LV is visible from user's perspective */
-int lv_is_displayable(const struct logical_volume *lv);
+int lv_is_visible(const struct logical_volume *lv);
 
 int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv);
 
@@ -563,7 +560,10 @@ int vg_remove_snapshot(struct logical_volume *cow);
 
 int vg_check_status(const struct volume_group *vg, uint32_t status);
 
-unsigned volumes_count(const struct volume_group *vg);
+/*
+ * Returns visible LV count - number of LVs from user perspective
+ */
+unsigned vg_visible_lvs(const struct volume_group *vg);
 
 /*
 * Mirroring functions
index 97b9ebbdc5469f69685b1a33f552598bcc099222..85a0163e424a18e16c4e0471f714a478e66fccf3 100644 (file)
@@ -376,7 +376,7 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name,
        if (!vg_check_status(vg, EXPORTED_VG))
                return 0;
 
-       lv_count = displayable_lvs_in_vg(vg);
+       lv_count = vg_visible_lvs(vg);
 
        if (lv_count) {
                if ((force == PROMPT) &&
@@ -391,8 +391,8 @@ int vg_remove_single(struct cmd_context *cmd, const char *vg_name,
                        return 0;
        }
 
-       lv_count = displayable_lvs_in_vg(vg);
-       
+       lv_count = vg_visible_lvs(vg);
+
        if (lv_count) {
                log_error("Volume group \"%s\" still contains %u "
                          "logical volume(s)", vg_name, lv_count);
@@ -1140,18 +1140,6 @@ int vg_remove(struct volume_group *vg)
        return 1;
 }
 
-unsigned displayable_lvs_in_vg(const struct volume_group *vg)
-{
-       struct lv_list *lvl;
-       unsigned lv_count = 0;
-
-       dm_list_iterate_items(lvl, &vg->lvs)
-               if (lv_is_displayable(lvl->lv))
-                       lv_count++;
-
-       return lv_count;
-}
-
 unsigned snapshot_count(const struct volume_group *vg)
 {
        struct lv_list *lvl;
@@ -1164,17 +1152,14 @@ unsigned snapshot_count(const struct volume_group *vg)
        return num_snapshots;
 }
 
-unsigned volumes_count(const struct volume_group *vg)
+unsigned vg_visible_lvs(const struct volume_group *vg)
 {
        struct lv_list *lvl;
        unsigned lv_count = 0;
 
        dm_list_iterate_items(lvl, &vg->lvs) {
-               if (lv_is_cow(lvl->lv))
-                       continue;
-               if (lvl->lv->status & SNAPSHOT)
-                       continue;
-               lv_count++;
+               if (lv_is_visible(lvl->lv))
+                       lv_count++;
        }
 
        return lv_count;
@@ -1214,7 +1199,7 @@ int vgs_are_compatible(struct cmd_context *cmd __attribute((unused)),
        }
 
        if (vg_to->max_lv &&
-           (vg_to->max_lv < volumes_count(vg_to) + volumes_count(vg_from))) {
+           (vg_to->max_lv < vg_visible_lvs(vg_to) + vg_visible_lvs(vg_from))) {
                log_error("Maximum number of logical volumes (%d) exceeded "
                          " for \"%s\" and \"%s\"", vg_to->max_lv, vg_to->name,
                          vg_from->name);
@@ -1469,12 +1454,38 @@ int vg_validate(struct volume_group *vg)
                r = 0;
        }
 
-       if ((lv_count = (uint32_t) dm_list_size(&vg->lvs)) !=
-           volumes_count(vg) + 2 * snapshot_count(vg)) {
+       /*
+        * Count all non-snapshot invisible LVs
+        */
+       lv_count = 0;
+       dm_list_iterate_items(lvl, &vg->lvs) {
+               if (lvl->lv->status & VISIBLE_LV)
+                       continue;
+
+               /* snapshots */
+               if (lv_is_cow(lvl->lv) || lv_is_origin(lvl->lv))
+                       continue;
+
+               /* count other non-snapshot invisible volumes */
+               lv_count++;
+
+               /*
+                *  FIXME: add check for unreferenced invisible LVs
+                *   - snapshot cow & origin
+                *   - mirror log & images
+                *   - mirror conversion volumes (_mimagetmp*)
+                */
+       }
+
+       /*
+        * all volumes = visible LVs + snapshot_cows + invisible LVs
+        */
+       if (((uint32_t) dm_list_size(&vg->lvs)) !=
+           vg_visible_lvs(vg) + snapshot_count(vg) + lv_count) {
                log_error("Internal error: #internal LVs (%u) != #LVs (%"
-                         PRIu32 ") + 2 * #snapshots (%" PRIu32 ") in VG %s",
-                         dm_list_size(&vg->lvs), volumes_count(vg),
-                         snapshot_count(vg), vg->name);
+                         PRIu32 ") + #snapshots (%" PRIu32 ") + #invisible LVs %u in VG %s",
+                         dm_list_size(&vg->lvs), vg_visible_lvs(vg),
+                         snapshot_count(vg), lv_count, vg->name);
                r = 0;
        }
 
@@ -1517,10 +1528,10 @@ int vg_validate(struct volume_group *vg)
                r = 0;
        }
 
-       if (vg->max_lv && (vg->max_lv < volumes_count(vg))) {
+       if (vg->max_lv && (vg->max_lv < vg_visible_lvs(vg))) {
                log_error("Internal error: Volume group %s contains %u volumes"
                          " but the limit is set to %u.",
-                         vg->name, volumes_count(vg), vg->max_lv);
+                         vg->name, vg_visible_lvs(vg), vg->max_lv);
                r = 0;
        }
 
index aca57f4c0df43604fa13888e8a396e92c4981f24..b2294bb140a67b77ba6ae7412a51fc9f9ea2ce31 100644 (file)
@@ -339,11 +339,6 @@ int add_seg_to_segs_using_this_lv(struct logical_volume *lv, struct lv_segment *
 int remove_seg_from_segs_using_this_lv(struct logical_volume *lv, struct lv_segment *seg);
 struct lv_segment *get_only_segment_using_this_lv(struct logical_volume *lv);
 
-/*
- * Count LVs that are visible from user's perspective.
- */
-unsigned displayable_lvs_in_vg(const struct volume_group *vg);
-
 /*
  * Count snapshot LVs.
  */
index 367656261019af843199e9da7f037408c80d6c3c..4b8691a32f70949fcf5a083897599e464b4741c8 100644 (file)
@@ -43,14 +43,6 @@ int lv_is_visible(const struct logical_volume *lv)
        return lv->status & VISIBLE_LV ? 1 : 0;
 }
 
-int lv_is_displayable(const struct logical_volume *lv)
-{
-       if (lv->status & SNAPSHOT)
-               return 0;
-
-       return (lv->status & VISIBLE_LV) || lv_is_cow(lv) ? 1 : 0;
-}
-
 int lv_is_virtual_origin(const struct logical_volume *lv)
 {
        return (lv->status & VIRTUAL_ORIGIN) ? 1 : 0;
index d8f7961de9e38aa4325db7a4e436fc9d64c0ffb3..3de63ce783ed575d66daa92d5d12a8ea25351e25 100644 (file)
@@ -497,7 +497,7 @@ static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem,
        char *repstr, *lvname;
        size_t len;
 
-       if (lv_is_displayable(lv)) {
+       if (lv_is_visible(lv)) {
                repstr = lv->name;
                return dm_report_field_string(rh, field, (const char **) &repstr);
        }
@@ -974,7 +974,7 @@ static int _lvcount_disp(struct dm_report *rh, struct dm_pool *mem,
        const struct volume_group *vg = (const struct volume_group *) data;
        uint32_t count;
 
-       count = displayable_lvs_in_vg(vg);      
+       count = vg_visible_lvs(vg);
 
        return _uint32_disp(rh, mem, field, &count, private);
 }
index 2696a95b3bf2895fbfb673f42b7c7c9d3da583cb..466fe29a2ca0b42f3c37e57954df02f83cb4276b 100644 (file)
@@ -584,7 +584,7 @@ static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
                return ECMD_FAILED;
        }
 
-       if (!(lv_is_displayable(lv))) {
+       if (!(lv_is_visible(lv))) {
                log_error("Unable to change internal LV %s directly",
                          lv->name);
                return ECMD_FAILED;
index 5263e0d12facca8d9b847edc694ca9ed4ae9f12f..16e7052f2060ed6acd9a7507d63ed65357175d14 100644 (file)
@@ -18,7 +18,7 @@
 static int _lvdisplay_single(struct cmd_context *cmd, struct logical_volume *lv,
                             void *handle)
 {
-       if (!arg_count(cmd, all_ARG) && !lv_is_displayable(lv))
+       if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
                return ECMD_PROCESSED;
 
        if (arg_count(cmd, colon_ARG))
index 1186b3bcefcaf48577ff086157ac51dd67f23d0d..a286fe17fb524b2fd1b975ae3ef822ed7bd70a7b 100644 (file)
@@ -27,7 +27,7 @@ static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv,
 
        const char *active_str, *snapshot_str;
 
-       if (!arg_count(cmd, all_ARG) && !lv_is_displayable(lv))
+       if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
                return ECMD_PROCESSED;
 
        inkernel = lv_info(cmd, lv, &info, 1, 0) && info.exists;
index 0a9de09ebbb69d701450fc1d59b66260609a1ade..28393f8857e0addbb4b71ecafedf5d4b3e0a096e 100644 (file)
@@ -36,7 +36,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute((unused)),
 static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
                       void *handle)
 {
-       if (!arg_count(cmd, all_ARG) && !lv_is_displayable(lv))
+       if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
                return ECMD_PROCESSED;
 
        if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL))
@@ -113,7 +113,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
 static int _lvsegs_single(struct cmd_context *cmd, struct logical_volume *lv,
                          void *handle)
 {
-       if (!arg_count(cmd, all_ARG) && !lv_is_displayable(lv))
+       if (!arg_count(cmd, all_ARG) && !lv_is_visible(lv))
                return ECMD_PROCESSED;
 
        return process_each_segment_in_lv(cmd, lv, handle, _segs_single);
index d01bc0114bb00bc166b0a8d4caa5f0bfd1104ce7..25a1b3b25bda3919a3e2751a78e073b9891d3b0b 100644 (file)
@@ -308,9 +308,9 @@ static int _vgchange_logicalvolume(struct cmd_context *cmd,
                }
        }
 
-       if (max_lv && max_lv < volumes_count(vg)) {
+       if (max_lv && max_lv < vg_visible_lvs(vg)) {
                log_error("MaxLogicalVolume is less than the current number "
-                         "%d of LVs for %s", volumes_count(vg),
+                         "%d of LVs for %s", vg_visible_lvs(vg),
                          vg->name);
                return ECMD_FAILED;
        }
This page took 0.693595 seconds and 5 git commands to generate.