Skip to contentSkip to conversation

master - clvmd: defer freeing saved vgs

PATCH David Teigland 1 participant 1 message May 3, 2018

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a5e13f2eef5314666e19923a03ae01f479a74fd8
Commit:        a5e13f2eef5314666e19923a03ae01f479a74fd8
Parent:        88fe07ad0ac8f12c2a2f4873d9bd32852c2f1536
Author:        David Teigland <[email protected]>
AuthorDate:    Mon Apr 30 16:48:53 2018 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Thu May 3 14:54:48 2018 -0500

clvmd: defer freeing saved vgs

To avoid the chance of freeing a saved vg while another code path is using it, defer freeing saved vgs until all the lvmcache content is dropped for the vg.

---
 lib/activate/activate.c |   54 +++++++++--------
 lib/cache/lvmcache.c    |  149 +++++++++++++++++++++++++++++++++++++----------
 lib/cache/lvmcache.h    |    1 -
 3 files changed, 148 insertions(+), 56 deletions(-)
lib/activate/activate.c +29 -25
index 2d00dc6..985215a 100644
@@ -2161,36 +2161,40 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
 	if (lv && lv_pre)
 		goto skip_read;
 
-	vg = lvmcache_get_saved_vg(vgid, 0);
-	vg_pre = lvmcache_get_saved_vg(vgid, 1);
-
-	if (!vg || !vg_pre) {
-		log_debug("lv_suspend dropping both saved vgs and rereading");
-
-		lvmcache_drop_saved_vgid(vgid);
-
-		vg = vg_read_by_vgid(cmd, vgid, 0);
-		vg_pre = vg_read_by_vgid(cmd, vgid, 1);
-
-		if (!vg || !vg_pre) {
-			log_error("lv_suspend could not find vgid %.8s vg %p vg_pre %p",
-				  vgid, vg, vg_pre);
+	if (!(vg = lvmcache_get_saved_vg(vgid, 0))) {
+		log_debug("lv_suspend did not find saved_vg %.8s so reading", vgid);
+		if (!(vg = vg_read_by_vgid(cmd, vgid, 0))) {
+			log_error("lv_suspend could not read vgid %.8s", vgid);
 			goto out;
 		}
+		log_debug("lv_suspend using read vg %s %d %p", vg->name, vg->seqno, vg);
+	} else {
+		log_debug("lv_suspend using saved_vg %s %d %p", vg->name, vg->seqno, vg);
+	}
 
-		/*
-		 * Note that vg and vg_pre returned by vg_read_by_vgid will
-		 * not be the same as saved_vg_old/saved_vg_new that would
-		 * be returned by lvmcache_get_saved_vg() because the saved_vg's
-		 * are copies of the vg struct that is created by _vg_read.
-		 * (Should we grab and use the saved_vg to use here instead of
-		 * the vg returned by vg_read_by_vgid?)
-		 */
-
-		if ((vg->status & EXPORTED_VG) || (vg_pre->status & EXPORTED_VG)) {
-			log_error("Volume group \"%s\" is exported", vg->name);
+	if (!(vg_pre = lvmcache_get_saved_vg(vgid, 1))) {
+		log_debug("lv_suspend did not find pre saved_vg %.8s so reading", vgid);
+		if (!(vg_pre = vg_read_by_vgid(cmd, vgid, 1))) {
+			log_error("lv_suspend could not read pre vgid %.8s", vgid);
 			goto out;
 		}
+		log_debug("lv_suspend using pre read vg %s %d %p", vg_pre->name, vg_pre->seqno, vg_pre);
+	} else {
+		log_debug("lv_suspend using pre saved_vg %s %d %p", vg_pre->name, vg_pre->seqno, vg_pre);
+	}
+
+	/*
+	 * Note that vg and vg_pre returned by vg_read_by_vgid will
+	 * not be the same as saved_vg_old/saved_vg_new that would
+	 * be returned by lvmcache_get_saved_vg() because the saved_vg's
+	 * are copies of the vg struct that is created by _vg_read.
+	 * (Should we grab and use the saved_vg to use here instead of
+	 * the vg returned by vg_read_by_vgid?)
+	 */
+
+	if ((vg->status & EXPORTED_VG) || (vg_pre->status & EXPORTED_VG)) {
+		log_error("Volume group \"%s\" is exported", vg->name);
+		goto out;
 	}
 
 	lv = lv_to_free = find_lv_in_vg_by_lvid(vg, lvid);
lib/cache/lvmcache.c +119 -30

245 lines not on this page · raw message

lib/cache/lvmcache.h +0 -1
index 7cdda43..20ce74b 100644
@@ -216,7 +216,6 @@ void lvmcache_set_independent_location(const char *vgname);
 void lvmcache_save_vg(struct volume_group *vg, int precommitted);
 struct volume_group *lvmcache_get_saved_vg(const char *vgid, int precommitted);
 struct volume_group *lvmcache_get_saved_vg_latest(const char *vgid);
-void lvmcache_drop_saved_vg(struct volume_group *vg);
 void lvmcache_drop_saved_vgid(const char *vgid);
 
 int lvmcache_scan_mismatch(struct cmd_context *cmd, const char *vgname, const char *vgid);