Skip to contentSkip to conversation

lvm_vg_reduce and vg_reduce

PATCH New Thomas Woerner 1 participant 4 messages Jul 27, 2009

lore
Share & tools
lore
#0 lore raw

cover lvm_vg_reduce and vg_reduce

This patch series adds lvm_vg_reduce and vg_reduce. For more information please have a look at the patches.

Dave Wysochanski (1):
Initialize removed_pvs list in format-specific volume_group
constructors.

Thomas Woerner (2):
Add vg_reduce to metadata.c and metadata-exported.h Add lvm_vg_reduce to liblvm2app

 lib/format1/format1.c            |    1 +
 lib/format_pool/format_pool.c    |    1 +
 lib/format_text/import_vsn1.c    |    1 +
 lib/metadata/metadata-exported.h |    7 ++
 lib/metadata/metadata.c          |   61 +++++++++++++++++++
 liblvm/.exported_symbols         |    1 +
 liblvm/lvm.h                     |   18 ++++++
 liblvm/lvm_vg.c                  |   25 ++++++++
 test/api/vgtest.c                |  118 ++++++++++++++++++++++++--------------
 9 files changed, 190 insertions(+), 43 deletions(-)
#1 lore raw

PATCH 1/3 Add vg_reduce to metadata.c and metadata-exported.h

This function behaves a little bit different than vg_reduce_single, because it allowes to remove even the latest pv. This has been done to be consistent to lvm_vg_create, which creates an empty vg.

removed_pvs has been added to the volume_group struct. vg_reduce adds removed pvs to this list to be able to commit the changes for the pvs in lvm_vg_commit in liblvm2app.

---
 lib/metadata/metadata-exported.h |    7 ++++
 lib/metadata/metadata.c          |   61 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 0 deletions(-)
lib/metadata/metadata-exported.h +7 -0
index 142381b..bc946da 100644
@@ -243,6 +243,12 @@ struct volume_group {
 	 */
 
 	/*
+	 * List of removed physical volumes by pvreduce.
+	 * They have to get cleared on vg_commit.
+	 */
+	struct dm_list removed_pvs;
+
+	/*
 	 * Store result of the last vg_read().
 	 * 0 for success else appropriate FAILURE_* bits set.
 	 */
@@ -437,6 +443,7 @@ int vg_remove_single(vg_t *vg);
 int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
 	      const char *new_name);
 int vg_extend(struct volume_group *vg, int pv_count, char **pv_names);
+int vg_reduce(struct volume_group *vg, char *pv_name);
 int vg_set_extent_size(vg_t *vg, uint32_t new_extent_size);
 int vg_set_max_lv(vg_t *vg, uint32_t max_lv);
 int vg_set_max_pv(vg_t *vg, uint32_t max_pv);
lib/metadata/metadata.c +61 -0

79 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 2/3 Add lvm_vg_reduce to liblvm2app

Extend lvm_vg_write to remove pvs removed in lvm_vg_reduce. The lvm volume_group internal structure removed_pvs is used for that. The list is empty afterwards.

Add new test for vg->pvs emptyness to lvm_vg_write to prevent to write empty vgs. This is needed cbecause of lvm_vg_reduce and lv_vg_create, which creates empty vgs.

---
 liblvm/.exported_symbols |    1 +
 liblvm/lvm.h             |   18 +++++++
 liblvm/lvm_vg.c          |   25 ++++++++++
 test/api/vgtest.c        |  118 +++++++++++++++++++++++++++++-----------------
 4 files changed, 119 insertions(+), 43 deletions(-)
liblvm/.exported_symbols +1 -0
index 9911423..68edb87 100644
@@ -21,6 +21,7 @@ lvm_lv_is_active
 lvm_lv_is_suspended
 lvm_vg_create
 lvm_vg_extend
+lvm_vg_reduce
 lvm_vg_set_extent_size
 lvm_vg_write
 lvm_vg_open
liblvm/lvm.h +18 -0
index 328b33e..92e946c 100644
@@ -319,6 +319,24 @@ int lvm_vg_close(vg_t *vg);
 int lvm_vg_extend(vg_t *vg, const char *device);
 
 /**
+ * Reduce a VG by removeing an unused device.
+ *
+ * This API requires calling lvm_vg_write to commit the change to disk.
+ * After successfully removing a device, use lvm_vg_write to commit the new VG
+ * to disk.  Upon failure, retry the operation or release the VG handle with
+ * lvm_vg_close.
+ *
+ * \param   vg
+ *          VG handle obtained from lvm_vg_create.
+ *
+ * \param   device
+ *          Name of device to remove from VG.
+ *
+ * \return  Status code of 1 (success) or 0 (failure).
+ */
+int lvm_vg_reduce(vg_t *vg, const char *device);
+
+/**
  * Set the extent size of a VG.
  *
  * This API requires calling lvm_vg_write to commit the change to disk.
liblvm/lvm_vg.c +25 -0
index 4800555..60c6b31 100644
@@ -68,6 +68,14 @@ int lvm_vg_extend(vg_t *vg, const char *device)
 	return 0;
 }
 
+int lvm_vg_reduce(vg_t *vg, const char *device)
+{
+	if (vg_read_error(vg))
+		return 0;
+
+	return vg_reduce(vg, (char *)device);
+}
+
 int lvm_vg_set_extent_size(vg_t *vg, uint32_t new_size)
 {
 	if (vg_read_error(vg))
@@ -80,15 +88,32 @@ int lvm_vg_set_extent_size(vg_t *vg, uint32_t new_size)
 
 int lvm_vg_write(vg_t *vg)
 {
+	struct pv_list *pvl;
+
 	if (vg_read_error(vg))
 		return -1;
 
+	if (dm_list_empty(&vg->pvs)) {
+		log_error("Volume group %s does not contain any physical volumes.\n", vg->name);
+		return -1;
+	}
+
 	if (!archive(vg))
 		return -1;
 
 	/* Store VG on disk(s) */
 	if (!vg_write(vg) || !vg_commit(vg))
 		return -1;
+
+	if (! dm_list_empty(&vg->removed_pvs)) {
+		dm_list_iterate_items(pvl, &vg->removed_pvs) {
+			/* FIXME: either use pv_write_orphan or remove the pv */
+			/* pv_write_orphan(vg->cmd, pvl->pv); */
+			label_remove(pv_dev(pvl->pv));
+		}
+		dm_list_init(&vg->removed_pvs);
+	}
+
 	return 0;
 }
 
test/api/vgtest.c +75 -43

139 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#3 lore raw

PATCH 3/3 Initialize removed_pvs list in format-specific volume_group constructors.

From: Dave Wysochanski <[email protected]>

I think this is the reason the 'n' and 'p' members were still NULL. Ideally, we should have a base constructor here that initializes the general, non-format specific members of struct volume_group. But until then, there are multiple places to initialize these members. Maybe a better patch would be a base constructor patch for struct volume_group. That is more work though. Maybe you could start one - might get bonus points. ;-)

---
 lib/format1/format1.c         |    1 +
 lib/format_pool/format_pool.c |    1 +
 lib/format_text/import_vsn1.c |    1 +
 3 files changed, 3 insertions(+), 0 deletions(-)
lib/format1/format1.c +1 -0
index c8f9519..aa1483a 100644
@@ -132,6 +132,7 @@ static struct volume_group *_build_vg(struct format_instance *fid,
 	dm_list_init(&vg->pvs);
 	dm_list_init(&vg->lvs);
 	dm_list_init(&vg->tags);
+	dm_list_init(&vg->removed_pvs);
 
 	if (!_check_vgs(pvs))
 		goto_bad;
lib/format_pool/format_pool.c +1 -0
index 3f31bba..6f7e4b4 100644
@@ -124,6 +124,7 @@ static struct volume_group *_build_vg_from_pds(struct format_instance
 	dm_list_init(&vg->pvs);
 	dm_list_init(&vg->lvs);
 	dm_list_init(&vg->tags);
+	dm_list_init(&vg->removed_pvs);
 
 	if (!import_pool_vg(vg, smem, pds))
 		return_NULL;
lib/format_text/import_vsn1.c +1 -0
index 629310a..3c41675 100644
@@ -753,6 +753,7 @@ static struct volume_group *_read_vg(struct format_instance *fid,
 
 	dm_list_init(&vg->lvs);
 	dm_list_init(&vg->tags);
+	dm_list_init(&vg->removed_pvs);
 
 	/* Optional tags */
 	if ((cn = find_config_node(vgn, "tags")) &&
Signature · 1 line
1.6.2.5