Skip to contentSkip to conversation

lvm2app: Implementation of pv resize (v5)

PATCH New Tony Asleson 1 participant 1 message Jan 9, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lvm2app: Implementation of pv resize (v5)

Patch correctly checks for update lock before allowing resize to process and also requires lvm_vg_write to make changes persistent. As the API does not allow the re-size of a orphaned pv this is accomplished through the existing vg_write, vg_commit sequence which is done in lvm_vg_write.

---
 lib/metadata/metadata-exported.h |  8 +++++--
 lib/metadata/pv_manip.c          | 48 +++++++++++++++++++++++++++++++++++++++-
 liblvm/lvm2app.h                 |  5 +++--
 liblvm/lvm_pv.c                  | 21 ++++++++++++++----
 tools/pvresize.c                 | 36 +++++-------------------------
 5 files changed, 79 insertions(+), 39 deletions(-)
lib/metadata/metadata-exported.h +6 -2
index ffec129..4af9edf 100644
@@ -482,8 +482,12 @@ struct physical_volume *pv_create(const struct cmd_context *cmd,
 				  unsigned pvmetadatacopies,
 				  uint64_t pvmetadatasize,
 				  unsigned metadataignore);
-int pv_resize(struct physical_volume *pv, struct volume_group *vg,
-	      uint64_t size);
+
+int pv_resize(struct cmd_context *cmd,
+				struct volume_group *vg,
+				struct physical_volume *pv,
+				const uint64_t new_size);
+
 int pv_analyze(struct cmd_context *cmd, const char *pv_name,
 	       uint64_t label_sector);
 
lib/metadata/pv_manip.c +47 -1

63 lines not on this page · raw message

liblvm/lvm2app.h +3 -2
index 93a78c3..00f92ab 100644
@@ -1624,9 +1624,10 @@ pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid);
 /**
  * Resize physical volume to new_size bytes.
  *
- * \memberof pv_t
+ * Note: Make sure to do a lvm_vg_write on the containing vg to save the
+ * new size.
  *
- * NOTE: This function is currently not implemented.
+ * \memberof pv_t
  *
  * \param   pv
  * Physical volume handle.
liblvm/lvm_pv.c +17 -4
index 90edaed..c12adf1 100644
@@ -120,10 +120,23 @@ pv_t lvm_pv_from_uuid(vg_t vg, const char *uuid)
 	return NULL;
 }
 
-
 int lvm_pv_resize(const pv_t pv, uint64_t new_size)
 {
-	/* FIXME: add pv resize code here */
-	log_error("NOT IMPLEMENTED YET");
-	return -1;
+	uint64_t size = new_size >> SECTOR_SHIFT;
+
+	if (new_size % SECTOR_SIZE) {
+		log_errno(EINVAL, "Size not a multiple of 512");
+		return -1;
+	}
+
+	if (!vg_check_write_mode(pv->vg)) {
+		return -1;
+	}
+
+	if (!pv_resize(pv->vg->cmd, pv->vg, pv, size)) {
+		log_error("PV re-size failed!");
+		return -1;
+	} else {
+		return 0;
+	}
 }
tools/pvresize.c +6 -30
index 2f0693a..21980b3 100644
@@ -30,7 +30,6 @@ static int _pv_resize_single(struct cmd_context *cmd,
 			     const uint64_t new_size)
 {
 	struct pv_list *pvl;
-	uint64_t size = 0;
 	int r = 0;
 	const char *pv_name = pv_dev_name(pv);
 	const char *vg_name = pv_vg_name(pv);
@@ -61,41 +60,18 @@ static int _pv_resize_single(struct cmd_context *cmd,
 		if (!(pvl = find_pv_in_vg(vg, pv_name))) {
 			log_error("Unable to find \"%s\" in volume group \"%s\"",
 				  pv_name, vg->name);
-			goto out;
+			goto_out;
 		}
 
 		pv = pvl->pv;
 
 		if (!archive(vg))
-			goto out;
+			goto_out;
 	}
 
-	if (!(pv->fmt->features & FMT_RESIZE_PV)) {
-		log_error("Physical volume %s format does not support resizing.",
-			  pv_name);
-		goto out;
-	}
-
-	/* Get new size */
-	if (!dev_get_size(pv_dev(pv), &size)) {
-		log_error("%s: Couldn't get size.", pv_name);
-		goto out;
-	}
-
-	if (new_size) {
-		if (new_size > size)
-			log_warn("WARNING: %s: Overriding real size. "
-				  "You could lose data.", pv_name);
-		log_verbose("%s: Pretending size is %" PRIu64 " not %" PRIu64
-			    " sectors.", pv_name, new_size, pv_size(pv));
-		size = new_size;
-	}
-
-	log_verbose("Resizing volume \"%s\" to %" PRIu64 " sectors.",
-		    pv_name, pv_size(pv));
-
-	if (!pv_resize(pv, vg, size))
+	if( !pv_resize(cmd, vg, pv, new_size)) {
 		goto_out;
+	}
 
 	log_verbose("Updating physical volume \"%s\"", pv_name);
 
@@ -106,14 +82,14 @@ static int _pv_resize_single(struct cmd_context *cmd,
 	    !pv_write(cmd, pv, 1)) {
 		log_error("Failed to store physical volume \"%s\"",
 			  pv_name);
-		goto out;
+		goto_out;
 	}
 
 	if (!is_orphan_vg(vg_name)) {
 		if (!vg_write(vg) || !vg_commit(vg)) {
 			log_error("Failed to store physical volume \"%s\" in "
 				  "volume group \"%s\"", pv_name, vg_name);
-			goto out;
+			goto_out;
 		}
 		backup(vg);
 	}
Signature · 1 line
1.7.11.7