[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[linux-lvm] [RFC] Allow pesize change to adjust free values



Hi folks

I run again over the problem that vgchange is able to change the size of
a PE, but refuses to recalculate certain free values.

The attached patch seems to work for one PV but it it is not safe for
more. It may change the following things:
- Number of extents in VG.
- Free space of VG.
- Number of extents in PV.
- Size of free PV segment.

Fix for the later: Do PV resize as in this patch. Collect numbers of
removed extents and remove them from the VG.

--- lvm2-2.02.33.orig/tools/vgchange.c
+++ lvm2-2.02.33/tools/vgchange.c
@@ -405,14 +405,6 @@
 		return EINVALID_CMD_LINE;
 	}
 
-	if (extent_size > vg->extent_size) {
-		if ((uint64_t) vg->extent_size * vg->extent_count % extent_size) {
-			/* FIXME Adjust used PV sizes instead */
-			log_error("New extent size is not a perfect fit");
-			return EINVALID_CMD_LINE;
-		}
-	}
-
 	if (!archive(vg))
 		return ECMD_FAILED;
 
--- lvm2-2.02.33.orig/lib/metadata/metadata.c
+++ lvm2-2.02.33/lib/metadata/metadata.c
@@ -545,18 +545,12 @@
 	return NULL;
 }
 
-static int _recalc_extents(uint32_t *extents, const char *desc1,
-			   const char *desc2, uint32_t old_size,
-			   uint32_t new_size)
+static int _recalc_extents_adjust(uint32_t *extents, const char *desc1,
+		        	  const char *desc2, uint32_t old_size,
+			          uint32_t new_size)
 {
 	uint64_t size = (uint64_t) old_size * (*extents);
 
-	if (size % new_size) {
-		log_error("New size %" PRIu64 " for %s%s not an exact number "
-			  "of new extents.", size, desc1, desc2);
-		return 0;
-	}
-
 	size /= new_size;
 
 	if (size > UINT32_MAX) {
@@ -570,6 +564,22 @@
 	return 1;
 }
 
+static int _recalc_extents(uint32_t *extents, const char *desc1,
+			   const char *desc2, uint32_t old_size,
+			   uint32_t new_size)
+{
+	uint64_t size = (uint64_t) old_size * (*extents);
+
+	if (size % new_size) {
+		log_error("New size %" PRIu64 " for %s%s not an exact number "
+			  "of new extents.", size, desc1, desc2);
+		return 0;
+	}
+
+	return _recalc_extents_adjust(extents, desc1, desc2, old_size,
+				      new_size);
+}
+
 int vg_change_pesize(struct cmd_context *cmd __attribute((unused)),
 		     struct volume_group *vg, uint32_t new_size)
 {
@@ -588,12 +598,12 @@
 	    !vg->fid->fmt->ops->vg_setup(vg->fid, vg))
 		return_0;
 
-	if (!_recalc_extents(&vg->extent_count, vg->name, "", old_size,
-			     new_size))
+	if (!_recalc_extents_adjust(&vg->extent_count, vg->name, "", old_size,
+				    new_size))
 		return_0;
 
-	if (!_recalc_extents(&vg->free_count, vg->name, " free space",
-			     old_size, new_size))
+	if (!_recalc_extents_adjust(&vg->free_count, vg->name, " free space",
+				    old_size, new_size))
 		return_0;
 
 	/* foreach PV */
@@ -601,8 +611,8 @@
 		pv = pvl->pv;
 
 		pv->pe_size = new_size;
-		if (!_recalc_extents(&pv->pe_count, pv_dev_name(pv), "",
-				     old_size, new_size))
+		if (!_recalc_extents_adjust(&pv->pe_count, pv_dev_name(pv), "",
+					    old_size, new_size))
 			return_0;
 
 		if (!_recalc_extents(&pv->pe_alloc_count, pv_dev_name(pv),
@@ -618,9 +628,9 @@
 					     " PV segment start", old_size,
 					     new_size))
 				return_0;
-			if (!_recalc_extents(&pvseg->len, pv_dev_name(pv),
-					     " PV segment length", old_size,
-					     new_size))
+			if (!_recalc_extents_adjust(&pvseg->len, pv_dev_name(pv),
+						    " PV segment length", old_size,
+						    new_size))
 				return_0;
 		}
 	}

-- 
Each kiss is as the first.
		-- Miramanee, Kirk's wife, "The Paradise Syndrome",
		   stardate 4842.6

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]