From: Dave Wysochanski <dwysocha@redhat.com>
Date: Tue, 29 Jun 2010 21:32:44 +0000 (+0000)
Subject: Move code into pv_change_metadataignore library function.
X-Git-Tag: v2_02_91~1764
X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=a375ced3000d2ec07f2c54757fb3092550032a57;p=lvm2.git

Move code into pv_change_metadataignore library function.

In preparation to call this from both pvcreate as well as pvchange,
move the guts of metadataignore into a library function.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---

diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 26ba5456f..81424a529 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -866,6 +866,7 @@ uint32_t pv_pe_alloc_count(const struct physical_volume *pv);
 uint32_t pv_mda_count(const struct physical_volume *pv);
 uint32_t pv_mda_used_count(const struct physical_volume *pv);
 unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored);
+int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignore);
 
 uint64_t lv_size(const struct logical_volume *lv);
 
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 45bc72b8e..6eaf6b415 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4223,6 +4223,50 @@ int mdas_empty_or_ignored(struct dm_list *mdas)
 	return 0;
 }
 
+int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignore)
+{
+	const char *pv_name = pv_dev_name(pv);
+
+	if (mda_ignore && (pv_mda_used_count(pv) == 0)) {
+		log_error("Physical volume \"%s\" metadata already "
+			  "ignored", pv_name);
+		return 0;
+	}
+	if (!mda_ignore && (pv_mda_used_count(pv) == pv_mda_count(pv))) {
+		log_error("Physical volume \"%s\" metadata already "
+			  "not ignored", pv_name);
+		return 0;
+	}
+	if (!pv_mda_count(pv)) {
+		log_error("Physical volume \"%s\" has no metadata "
+			  "areas ", pv_name);
+		return 0;
+	}
+	if (mda_ignore) {
+		log_verbose("Setting physical volume \"%s\" "
+			    "metadata ignored", pv_name);
+	} else {
+		log_verbose("Setting physical volume \"%s\" "
+			    "metadata not ignored", pv_name);
+	}
+	if (!pv_mda_set_ignored(pv, mda_ignore)) {
+		return 0;
+	}
+	/*
+	 * Update vg_mda_copies based on the mdas in this PV.
+	 * This is most likely what the user would expect - if they
+	 * specify a specific PV to be ignored/un-ignored, they will
+	 * most likely not want LVM to turn around and change the
+	 * ignore / un-ignore value when it writes the VG to disk.
+	 * This does not guarantee this PV's ignore bits will be
+	 * preserved in future operations.
+	 */
+	if (!is_orphan(pv) && vg_mda_copies(pv->vg)) {
+		vg_set_mda_copies(pv->vg, vg_mda_used_count(pv->vg));
+	}
+	return 1;
+}
+
 uint32_t vg_seqno(const struct volume_group *vg)
 {
 	return vg->seqno;
diff --git a/tools/pvchange.c b/tools/pvchange.c
index de521b366..1e274eff6 100644
--- a/tools/pvchange.c
+++ b/tools/pvchange.c
@@ -122,42 +122,8 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg,
 			}
 		}
 	} else if (arg_count(cmd, metadataignore_ARG)) {
-		if (mda_ignore && (pv_mda_used_count(pv) == 0)) {
-			log_error("Physical volume \"%s\" metadata already "
-				  "ignored", pv_name);
+		if (!pv_change_metadataignore(pv, mda_ignore))
 			goto out;
-		}
-		if (!mda_ignore && (pv_mda_used_count(pv) == pv_mda_count(pv))) {
-			log_error("Physical volume \"%s\" metadata already "
-				  "not ignored", pv_name);
-			goto out;
-		}
-		if (!pv_mda_count(pv)) {
-			log_error("Physical volume \"%s\" has no metadata "
-				  "areas ", pv_name);
-			goto out;
-		}
-		if (mda_ignore) {
-			log_verbose("Setting physical volume \"%s\" "
-				    "metadata ignored", pv_name);
-		} else {
-			log_verbose("Setting physical volume \"%s\" "
-				    "metadata not ignored", pv_name);
-		}
-		if (!pv_mda_set_ignored(pv, mda_ignore)) {
-			goto out;
-		}
-		/*
-		 * Update vg_mda_copies based on the mdas in this PV.
-		 * This is most likely what the user would expect - if they
-		 * specify a specific PV to be ignored/un-ignored, they will
-		 * most likely not want LVM to turn around and change the
-		 * ignore / un-ignore value when it writes the VG to disk.
-		 * This does not guarantee this PV's ignore bits will be
-		 * preserved in future operations.
-		 */
-		if (!is_orphan(pv) && vg_mda_copies(vg))
-			vg_set_mda_copies(vg, vg_mda_used_count(vg));
 	} else {
 		/* --uuid: Change PV ID randomly */
 		if (!id_create(&pv->id)) {