]> sourceware.org Git - lvm2.git/commitdiff
Fix reporting of LV fields alongside unallocated PV segments.
authorAlasdair Kergon <agk@redhat.com>
Wed, 25 Jun 2008 16:52:27 +0000 (16:52 +0000)
committerAlasdair Kergon <agk@redhat.com>
Wed, 25 Jun 2008 16:52:27 +0000 (16:52 +0000)
WHATS_NEW
lib/Makefile.in
lib/commands/toolcontext.c
lib/freeseg/freeseg.c [new file with mode: 0644]
lib/metadata/segtype.h
lib/report/report.c
tools/reporter.c

index 30d533ed4a4ab72e7973dde305f2e9fc8a6bfd8d..4c243bb727ae93d3525519491d8cbc4ffb6d9967 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.39 -
 ================================
+  Fix reporting of LV fields alongside unallocated PV segments.
   Add --unquoted and --rows to reporting tools.
   Add and use uninitialized_var() macro to suppress invalid compiler warnings.
   Introduce enum for md minor sb version to suppress compiler warning.
index 98cc5b3325bc0b0c13437d4175501574f6dd313f..5514e55b0b966b88e2c7fe5b57ea6fc03d97ebac 100644 (file)
@@ -61,6 +61,7 @@ SOURCES =\
        format_text/import_vsn1.c \
        format_text/tags.c \
        format_text/text_label.c \
+       freeseg/freeseg.c \
        label/label.c \
        locking/file_locking.c \
        locking/locking.c \
index aa06472655ba46895f2716764fe518c1f3a02af6..f3cd13107762b57b782b0165bb6b5755f24a29ba 100644 (file)
@@ -755,6 +755,11 @@ static int _init_segtypes(struct cmd_context *cmd)
        segtype->library = NULL;
        list_add(&cmd->segtypes, &segtype->list);
 
+       if (!(segtype = init_free_segtype(cmd)))
+               return 0;
+       segtype->library = NULL;
+       list_add(&cmd->segtypes, &segtype->list);
+
 #ifdef SNAPSHOT_INTERNAL
        if (!(segtype = init_snapshot_segtype(cmd)))
                return 0;
diff --git a/lib/freeseg/freeseg.c b/lib/freeseg/freeseg.c
new file mode 100644 (file)
index 0000000..08f3100
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "lib.h"
+#include "toolcontext.h"
+#include "segtype.h"
+#include "display.h"
+#include "text_export.h"
+#include "text_import.h"
+#include "config.h"
+#include "str_list.h"
+#include "targets.h"
+#include "lvm-string.h"
+#include "activate.h"
+#include "str_list.h"
+#include "metadata.h"
+
+static const char *_freeseg_name(const struct lv_segment *seg)
+{
+       return seg->segtype->name;
+}
+
+static void _freeseg_destroy(const struct segment_type *segtype)
+{
+       dm_free((void *)segtype);
+}
+
+static struct segtype_handler _freeseg_ops = {
+       .name = _freeseg_name,
+       .destroy = _freeseg_destroy,
+};
+
+struct segment_type *init_free_segtype(struct cmd_context *cmd)
+{
+       struct segment_type *segtype = dm_malloc(sizeof(*segtype));
+
+       if (!segtype)
+               return_NULL;
+
+       segtype->cmd = cmd;
+       segtype->ops = &_freeseg_ops;
+       segtype->name = "free";
+       segtype->private = NULL;
+       segtype->flags = SEG_VIRTUAL | SEG_CANNOT_BE_ZEROED;
+
+       log_very_verbose("Initialised segtype: %s", segtype->name);
+
+       return segtype;
+}
index 91542928dd7063daef8330f2e7e944ca37592356..fa668dc168e6aa58c50574ada5d56fde71ee08a9 100644 (file)
@@ -95,6 +95,7 @@ struct segment_type *get_segtype_from_string(struct cmd_context *cmd,
 struct segment_type *init_striped_segtype(struct cmd_context *cmd);
 struct segment_type *init_zero_segtype(struct cmd_context *cmd);
 struct segment_type *init_error_segtype(struct cmd_context *cmd);
+struct segment_type *init_free_segtype(struct cmd_context *cmd);
 
 #ifdef SNAPSHOT_INTERNAL
 struct segment_type *init_snapshot_segtype(struct cmd_context *cmd);
index 8177a2ff56464dc7a7249d4810a9c5b9c5d915d7..70e25aec7f1ab77866a0d0b1161a977d4ed5b56c 100644 (file)
@@ -303,6 +303,10 @@ static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_
                return 0;
        }
 
+       /* Blank if this is a "free space" LV. */
+       if (!*lv->name)
+               goto out;
+
        if (lv->status & PVMOVE)
                repstr[0] = 'p';
        else if (lv->status & CONVERTING)
@@ -332,8 +336,10 @@ static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_
                repstr[1] = '-';
        else if (lv->status & LVM_WRITE)
                repstr[1] = 'w';
-       else
+       else if (lv->status & LVM_READ)
                repstr[1] = 'r';
+       else
+               repstr[1] = '-';
 
        repstr[2] = _alloc_policy_char(lv->alloc);
 
@@ -375,6 +381,7 @@ static int _lvstatus_disp(struct dm_report *rh __attribute((unused)), struct dm_
                repstr[5] = '-';
        }
 
+out:
        dm_report_field_set_value(field, repstr, NULL);
        return 1;
 }
index 02b51e38183de3cc1d900b47cd5a74b661f2e74d..5c35a0cbdfa36646d1814f38a3d169eae93e408d 100644 (file)
@@ -61,8 +61,39 @@ static int _pvsegs_sub_single(struct cmd_context *cmd __attribute((unused)),
        int ret = ECMD_PROCESSED;
        struct lv_segment *seg = pvseg->lvseg;
 
-       if (!report_object(handle, vg, seg ? seg->lv : NULL, pvseg->pv, seg,
-                          pvseg))
+       struct logical_volume _free_logical_volume = {
+               .vg = vg,
+               .name = (char *) "",
+               .snapshot = NULL,
+               .status = VISIBLE_LV,
+               .major = -1,
+               .minor = -1,
+       };
+
+       struct lv_segment _free_lv_segment = {
+               .lv = &_free_logical_volume,
+               .le = 0,
+               .status = 0,
+               .stripe_size = 0,
+               .area_count = 0,
+               .area_len = 0,
+               .origin = NULL,
+               .cow = NULL,
+               .chunk_size = 0,
+               .region_size = 0,
+               .extents_copied = 0,
+               .log_lv = NULL,
+               .areas = NULL,
+       };
+
+        _free_lv_segment.segtype = get_segtype_from_string(cmd, "free");
+       _free_lv_segment.len = pvseg->len;
+       list_init(&_free_logical_volume.tags);
+       list_init(&_free_logical_volume.segments);
+       list_init(&_free_logical_volume.segs_using_this_lv);
+
+       if (!report_object(handle, vg, seg ? seg->lv : &_free_logical_volume, pvseg->pv,
+                          seg ? : &_free_lv_segment, pvseg))
                ret = ECMD_FAILED;
 
        return ret;
This page took 0.04476 seconds and 5 git commands to generate.