All of lore.kernel.org
 help / color / mirror / Atom feed
From: Milan Broz <mbroz@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH v2] Fix pvseg report for orphan PVs and other devices.
Date: Tue, 21 Apr 2009 14:31:50 +0200	[thread overview]
Message-ID: <49EDBCB6.30903@redhat.com> (raw)
In-Reply-To: <49EDA675.9080902@redhat.com>

Fix pvseg report for orphan PVs and other devices.

If user requests report attribute from PVSEG type
and PV is orphan (or all devices is set), the report
is empty.

Try for example (when only orphan PV are present)
 #pvs
 #pvs -o +devices
# pvs /dev/sdb1
  PV         VG   Fmt  Attr PSize  PFree
    /dev/sdb1       lvm2 --   46.58G 46.58G
# pvs -o +devices /dev/sdb1
(no output)

The problem is caused by empty pv->segments list.

Fix it by providing fake segment here (similar to fake structures
in _pvsegs_sub_single() calls.

Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 test/t-listings.sh |    4 ++++
 tools/reporter.c   |   12 ++++++++++--
 tools/toollib.c    |   16 +++++++++++-----
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/test/t-listings.sh b/test/t-listings.sh
index e6da5b0..9ea10b6 100644
--- a/test/t-listings.sh
+++ b/test/t-listings.sh
@@ -34,6 +34,10 @@ pvcreate --metadatacopies 0 $dev5
 pvs --noheadings|tee out
 test $(wc -l <out) -eq 5
 
+#COMM pvs with segment attributes works even for orphans
+pvs --noheadings -o  seg_all,pv_all,lv_all,vg_all | tee out
+test $(wc -l <out) -eq 5
+
 vgcreate -c n $vg $devs
 
 #COMM pvs and vgs report mda_count, mda_free (bz202886, bz247444)
diff --git a/tools/reporter.c b/tools/reporter.c
index 9d03f58..0a9de09 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -54,15 +54,20 @@ static int _segs_single(struct cmd_context *cmd __attribute((unused)),
 	return ECMD_PROCESSED;
 }
 
-static int _pvsegs_sub_single(struct cmd_context *cmd __attribute((unused)),
+static int _pvsegs_sub_single(struct cmd_context *cmd,
 			      struct volume_group *vg,
 			      struct pv_segment *pvseg, void *handle)
 {
 	int ret = ECMD_PROCESSED;
 	struct lv_segment *seg = pvseg->lvseg;
 
+	struct volume_group _free_vg = {
+		.cmd = cmd,
+		.name = (char *)"",
+	};
+
 	struct logical_volume _free_logical_volume = {
-		.vg = vg,
+		.vg = vg ?: &_free_vg,
 		.name = (char *) "",
 	        .snapshot = NULL,
 		.status = VISIBLE_LV,
@@ -88,6 +93,9 @@ static int _pvsegs_sub_single(struct cmd_context *cmd __attribute((unused)),
 
         _free_lv_segment.segtype = get_segtype_from_string(cmd, "free");
 	_free_lv_segment.len = pvseg->len;
+	dm_list_init(&_free_vg.pvs);
+	dm_list_init(&_free_vg.lvs);
+	dm_list_init(&_free_vg.tags);
 	dm_list_init(&_free_lv_segment.tags);
 	dm_list_init(&_free_lv_segment.origin_list);
 	dm_list_init(&_free_logical_volume.tags);
diff --git a/tools/toollib.c b/tools/toollib.c
index bdca53f..ae600c7 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -375,6 +375,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
 	int ret_max = ECMD_PROCESSED;
 	int ret;
 	struct volume_group *old_vg = vg;
+	struct pv_segment _free_pv_segment = { .pv = pv };
 
 	if (is_pv(pv) && !vg && !is_orphan(pv)) {
 		vg_name = pv_vg_name(pv);
@@ -399,13 +400,18 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
 		pv = pvl->pv;
 	}
 
-	dm_list_iterate_items(pvseg, &pv->segments) {
-		ret = process_single(cmd, vg, pvseg, handle);
+	if (dm_list_empty(&pv->segments)) {
+		ret = process_single(cmd, NULL, &_free_pv_segment, handle);
 		if (ret > ret_max)
 			ret_max = ret;
-		if (sigint_caught())
-			break;
-	}
+	} else
+		dm_list_iterate_items(pvseg, &pv->segments) {
+			ret = process_single(cmd, vg, pvseg, handle);
+			if (ret > ret_max)
+				ret_max = ret;
+			if (sigint_caught())
+				break;
+		}
 
 	if (vg_name)
 		unlock_vg(cmd, vg_name);




      reply	other threads:[~2009-04-21 12:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-21 10:56 [PATCH] Fix pvseg report for orphan PVs and other devices Milan Broz
2009-04-21 12:31 ` Milan Broz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49EDBCB6.30903@redhat.com \
    --to=mbroz@redhat.com \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.