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

[lvm-devel] [PATCH] (4/11) start using vg_read_for_update



Hi,

this patch starts converting some tools to use the (at this time still fairly
rudimentary) vg_read_for_update. More API unification will follow in later
patches.

Sat Jul 12 17:17:51 CEST 2008  me mornfall net
  * Fix polldaemon that got inadverently borked.
Sat Jul 12 15:31:42 CEST 2008  me mornfall net
  * Another vg_read_internal bites the dust: vgrename.
Sat Jul 12 14:36:31 CEST 2008  me mornfall net
  * Convert pvresize to vg_read_for_update (from vg_read_internal).
Sat Jul 12 12:00:10 CEST 2008  me mornfall net
  * Update vgmerge with vg_read_for_update.
  
  Are we sure vgmerge does not want the group(s) to be RESIZEABLE?
Sat Jul 12 11:56:50 CEST 2008  me mornfall net
  * Replace most uses of vg_lock_and_read with vg_read_for_update.
Thu Oct 30 18:13:13 CET 2008  Petr Rockai <me mornfall net>
  tagged base 8-2
diff -rN -p -u old-lvmlib-b/tools/lvconvert.c new-lvmlib-b/tools/lvconvert.c
--- old-lvmlib-b/tools/lvconvert.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/lvconvert.c	2008-10-30 18:15:07.525836116 +0100
@@ -240,10 +240,8 @@ static struct volume_group *_get_lvconve
 {
 	dev_close_all();
 
-        return vg_lock_and_read(cmd, extract_vgname(cmd, lv_name),
-				NULL, LCK_VG_WRITE,
- 				CLUSTERED | EXPORTED_VG | LVM_WRITE,
-				CORRECT_INCONSISTENT | FAIL_INCONSISTENT);
+        return vg_read_for_update(cmd, extract_vgname(cmd, lv_name),
+				  NULL, 0);
 }
 
 static struct logical_volume *_get_lvconvert_lv(struct cmd_context *cmd __attribute((unused)),
@@ -746,9 +744,7 @@ int lvconvert(struct cmd_context * cmd, 
 
 	log_verbose("Checking for existing volume group \"%s\"", lp.vg_name);
 
-	if (!(vg = vg_lock_and_read(cmd, lp.vg_name, NULL, LCK_VG_WRITE,
-				    CLUSTERED | EXPORTED_VG | LVM_WRITE,
-				    CORRECT_INCONSISTENT)))
+	if (!(vg = vg_read_for_update(cmd, lp.vg_name, NULL, 0)))
 		return ECMD_FAILED;
 
 	if (!(lvl = find_lv_in_vg(vg, lp.lv_name))) {
diff -rN -p -u old-lvmlib-b/tools/lvcreate.c new-lvmlib-b/tools/lvcreate.c
--- old-lvmlib-b/tools/lvcreate.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/lvcreate.c	2008-10-30 18:15:07.529838091 +0100
@@ -896,9 +896,7 @@ int lvcreate(struct cmd_context *cmd, in
 		return EINVALID_CMD_LINE;
 
 	log_verbose("Finding volume group \"%s\"", lp.vg_name);
-	if (!(vg = vg_lock_and_read(cmd, lp.vg_name, NULL, LCK_VG_WRITE,
-				    CLUSTERED | EXPORTED_VG | LVM_WRITE,
-				    CORRECT_INCONSISTENT)))
+	if (!(vg = vg_read_for_update(cmd, lp.vg_name, NULL, 0)))
 		return ECMD_FAILED;
 
 	if (!_lvcreate(cmd, vg, &lp))
diff -rN -p -u old-lvmlib-b/tools/lvrename.c new-lvmlib-b/tools/lvrename.c
--- old-lvmlib-b/tools/lvrename.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/lvrename.c	2008-10-30 18:15:07.529838091 +0100
@@ -101,9 +101,7 @@ int lvrename(struct cmd_context *cmd, in
 	}
 
 	log_verbose("Checking for existing volume group \"%s\"", vg_name);
-	if (!(vg = vg_lock_and_read(cmd, vg_name, NULL, LCK_VG_WRITE,
-				    CLUSTERED | EXPORTED_VG | LVM_WRITE,
-				    CORRECT_INCONSISTENT)))
+	if (!(vg = vg_read_for_update(cmd, vg_name, NULL, 0)))
 		return ECMD_FAILED;
 
 	if (!(lvl = find_lv_in_vg(vg, lv_name_old))) {
diff -rN -p -u old-lvmlib-b/tools/lvresize.c new-lvmlib-b/tools/lvresize.c
--- old-lvmlib-b/tools/lvresize.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/lvresize.c	2008-10-30 18:15:07.529838091 +0100
@@ -661,9 +661,7 @@ int lvresize(struct cmd_context *cmd, in
 		return EINVALID_CMD_LINE;
 
 	log_verbose("Finding volume group %s", lp.vg_name);
-	if (!(vg = vg_lock_and_read(cmd, lp.vg_name, NULL, LCK_VG_WRITE,
-				    CLUSTERED | EXPORTED_VG | LVM_WRITE,
-				    CORRECT_INCONSISTENT))) {
+	if (!(vg = vg_read_for_update(cmd, lp.vg_name, NULL, 0))) {
 		stack;
 		return ECMD_FAILED;
 	}
diff -rN -p -u old-lvmlib-b/tools/polldaemon.c new-lvmlib-b/tools/polldaemon.c
--- old-lvmlib-b/tools/polldaemon.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/polldaemon.c	2008-10-30 18:15:07.525836116 +0100
@@ -174,7 +174,7 @@ static int _wait_for_single_mirror(struc
 }
 
 static int _poll_vg(struct cmd_context *cmd, const char *vgname,
-		    struct volume_group *vg, int consistent, void *handle)
+		    struct volume_group *vg, void *handle)
 {
 	struct daemon_parms *parms = (struct daemon_parms *) handle;
 	struct lv_list *lvl;
@@ -182,16 +182,8 @@ static int _poll_vg(struct cmd_context *
 	const char *name;
 	int finished;
 
-	if (!vg) {
-		log_error("Couldn't read volume group %s", vgname);
+	if (!vg || vg->failed)
 		return ECMD_FAILED;
-	}
-
-	if (!consistent) {
-		log_error("Volume Group %s inconsistent - skipping", vgname);
-		/* FIXME Should we silently recover it here or not? */
-		return ECMD_FAILED;
-	}
 
 	if (!vg_check_status(vg, EXPORTED_VG))
 		return ECMD_FAILED;
diff -rN -p -u old-lvmlib-b/tools/pvchange.c new-lvmlib-b/tools/pvchange.c
--- old-lvmlib-b/tools/pvchange.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/pvchange.c	2008-10-30 18:15:07.529838091 +0100
@@ -56,9 +56,7 @@ static int _pvchange_single(struct cmd_c
 
 		log_verbose("Finding volume group %s of physical volume %s",
 			    vg_name, pv_name);
-		if (!(vg = vg_lock_and_read(cmd, vg_name, NULL, LCK_VG_WRITE,
-					    CLUSTERED | EXPORTED_VG | LVM_WRITE,
-					    CORRECT_INCONSISTENT)))
+		if (!(vg = vg_read_for_update(cmd, vg_name, NULL, 0)))
 			return_0;
 
 		if (!(pvl = find_pv_in_vg(vg, pv_name))) {
diff -rN -p -u old-lvmlib-b/tools/pvmove.c new-lvmlib-b/tools/pvmove.c
--- old-lvmlib-b/tools/pvmove.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/pvmove.c	2008-10-30 18:15:07.529838091 +0100
@@ -93,9 +93,7 @@ static struct volume_group *_get_vg(stru
 
 	dev_close_all();
 
-	if (!(vg = vg_lock_and_read(cmd, vgname, NULL, LCK_VG_WRITE,
-				    CLUSTERED | EXPORTED_VG | LVM_WRITE,
-				    CORRECT_INCONSISTENT | FAIL_INCONSISTENT)))
+	if (!(vg = vg_read_for_update(cmd, vgname, NULL, 0)))
 		 return NULL;
 
 	return vg;
diff -rN -p -u old-lvmlib-b/tools/pvresize.c new-lvmlib-b/tools/pvresize.c
--- old-lvmlib-b/tools/pvresize.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/pvresize.c	2008-10-30 18:15:07.525836116 +0100
@@ -29,7 +29,6 @@ static int _pv_resize_single(struct cmd_
 			     const uint64_t new_size)
 {
 	struct pv_list *pvl;
-	int consistent = 1;
 	uint64_t size = 0;
 	uint32_t new_pe_count = 0;
 	struct list mdas;
@@ -57,22 +56,10 @@ static int _pv_resize_single(struct cmd_
 	} else {
 		vg_name = pv_vg_name(pv);
 
-		if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
-			log_error("Can't get lock for %s", pv_vg_name(pv));
-			return 0;
-		}
-
-		if (!(vg = vg_read_internal(cmd, vg_name, NULL, &consistent))) {
-			unlock_vg(cmd, vg_name);
-			log_error("Unable to find volume group of \"%s\"",
-				  pv_name);
-			return 0;
-		}
+		vg = vg_read_for_update(cmd, vg_name, NULL, 0);
 
-		if (!vg_check_status(vg, CLUSTERED | EXPORTED_VG | LVM_WRITE)) {
-			unlock_vg(cmd, vg_name);
+		if (!vg || vg->failed)
 			return 0;
-		}
 
 		if (!(pvl = find_pv_in_vg(vg, pv_name))) {
 			unlock_vg(cmd, vg_name);
diff -rN -p -u old-lvmlib-b/tools/vgextend.c new-lvmlib-b/tools/vgextend.c
--- old-lvmlib-b/tools/vgextend.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/vgextend.c	2008-10-30 18:15:07.529838091 +0100
@@ -41,11 +41,9 @@ int vgextend(struct cmd_context *cmd, in
 	}
 
 	log_verbose("Checking for volume group \"%s\"", vg_name);
-	if (!(vg = vg_lock_and_read(cmd, vg_name, NULL, LCK_VG_WRITE | LCK_NONBLOCK,
-				    CLUSTERED | EXPORTED_VG |
-				    LVM_WRITE | RESIZEABLE_VG,
-				    CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) {
-		 unlock_vg(cmd, VG_ORPHANS);
+	if (!(vg = vg_read_for_update(cmd, vg_name, NULL,
+				      REQUIRE_RESIZEABLE | LOCK_NONBLOCK))) {
+		unlock_vg(cmd, VG_ORPHANS);
 		return ECMD_FAILED;
 	 }
 /********** FIXME
diff -rN -p -u old-lvmlib-b/tools/vgmerge.c new-lvmlib-b/tools/vgmerge.c
--- old-lvmlib-b/tools/vgmerge.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/vgmerge.c	2008-10-30 18:15:07.529838091 +0100
@@ -27,16 +27,12 @@ static int _vgmerge_single(struct cmd_co
 	}
 
 	log_verbose("Checking for volume group \"%s\"", vg_name_to);
-	if (!(vg_to = vg_lock_and_read(cmd, vg_name_to, NULL, LCK_VG_WRITE,
-				       CLUSTERED | EXPORTED_VG | LVM_WRITE,
-				       CORRECT_INCONSISTENT | FAIL_INCONSISTENT)))
+	if (!(vg_to = vg_read_for_update(cmd, vg_name_to, NULL, 0)))
 		 return ECMD_FAILED;
 
 	log_verbose("Checking for volume group \"%s\"", vg_name_from);
-	if (!(vg_from = vg_lock_and_read(cmd, vg_name_from, NULL,
-					 LCK_VG_WRITE | LCK_NONBLOCK,
-					 CLUSTERED | EXPORTED_VG | LVM_WRITE,
-					 CORRECT_INCONSISTENT | FAIL_INCONSISTENT))) {
+	if (!(vg_from = vg_read_for_update(cmd, vg_name_from, NULL,
+					   LOCK_NONBLOCK))) {
 		unlock_vg(cmd, vg_name_to);
 		return ECMD_FAILED;
 	}
diff -rN -p -u old-lvmlib-b/tools/vgrename.c new-lvmlib-b/tools/vgrename.c
--- old-lvmlib-b/tools/vgrename.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/vgrename.c	2008-10-30 18:15:07.529838091 +0100
@@ -70,25 +70,11 @@ static int vg_rename_path(struct cmd_con
 	} else
 		vgid = NULL;
 
-	if (!lock_vol(cmd, vg_name_old, LCK_VG_WRITE)) {
-		log_error("Can't get lock for %s", vg_name_old);
-		return 0;
-	}
-
-	if (!(vg = vg_read_internal(cmd, vg_name_old, vgid, &consistent)) || !consistent) {
-		log_error("Volume group %s %s%s%snot found.", vg_name_old,
-		vgid ? "(" : "", vgid ? vgid : "", vgid ? ") " : "");
-		unlock_vg(cmd, vg_name_old);
-		return 0;
-	}
-
-	if (!vg_check_status(vg, CLUSTERED | LVM_WRITE)) {
-		unlock_vg(cmd, vg_name_old);
-		return 0;
-	}
-
-	/* Don't return failure for EXPORTED_VG */
-	vg_check_status(vg, EXPORTED_VG);
+	/* FIXME we used to print an error about EXPORTED, but proceeded
+	   nevertheless. */
+	vg = vg_read_for_update(cmd, vg_name_old, vgid, ALLOW_EXPORTED);
+	if (!vg || vg->failed)
+		return_0;
 
 	if (lvs_in_vg_activated_by_uuid_only(vg)) {
 		unlock_vg(cmd, vg_name_old);
diff -rN -p -u old-lvmlib-b/tools/vgsplit.c new-lvmlib-b/tools/vgsplit.c
--- old-lvmlib-b/tools/vgsplit.c	2008-10-30 18:15:07.497835560 +0100
+++ new-lvmlib-b/tools/vgsplit.c	2008-10-30 18:15:07.529838091 +0100
@@ -320,10 +320,8 @@ int vgsplit(struct cmd_context *cmd, int
 	}
 
 	log_verbose("Checking for volume group \"%s\"", vg_name_from);
-	if (!(vg_from = vg_lock_and_read(cmd, vg_name_from, NULL, LCK_VG_WRITE,
-				       CLUSTERED | EXPORTED_VG |
-				       RESIZEABLE_VG | LVM_WRITE,
-				       CORRECT_INCONSISTENT | FAIL_INCONSISTENT)))
+	if (!(vg_from = vg_read_for_update(cmd, vg_name_from, NULL,
+					   REQUIRE_RESIZEABLE)))
 		 return ECMD_FAILED;
 
 	log_verbose("Checking for new volume group \"%s\"", vg_name_to);

-- 
Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation

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