linux-lvm.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Bastian Blank <bastian@waldi.eu.org>
To: linux-lvm@redhat.com
Subject: [linux-lvm] [RFC] Allow pesize change to adjust free values
Date: Tue, 25 Mar 2008 13:53:44 +0100	[thread overview]
Message-ID: <20080325125344.GA22327@wavehammer.waldi.eu.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 3627 bytes --]

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 #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

                 reply	other threads:[~2008-03-25 12:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20080325125344.GA22327@wavehammer.waldi.eu.org \
    --to=bastian@waldi.eu.org \
    --cc=linux-lvm@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).