Skip to contentSkip to conversation

master - lvmcache: simplify

PATCH David Teigland 1 participant 1 message Apr 23, 2018

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9b6a62f9445b104f8b4f14b1ebe8258b360950e4
Commit:        9b6a62f9445b104f8b4f14b1ebe8258b360950e4
Parent:        c0973e70a58e7e14e9cca29a0f8ad12719ea554f
Author:        David Teigland <[email protected]>
AuthorDate:    Mon Apr 9 13:40:49 2018 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Fri Apr 20 11:22:48 2018 -0500

lvmcache: simplify

Recent changes allow some major simplification of the way lvmcache works and is used. lvmcache_label_scan is now called in a controlled fashion at the start of commands, and not via various unpredictable side effects. Remove various calls to it from other places. lvmcache_label_scan should not be called from anywhere during a command, because it produces an incorrect representation of PVs with no MDAs, and misclassifies them as orphans. This has been a long standing problem. The invalid flag and rescanning based on that is no longer used and removed. The 'force' variation is no longer needed and removed.

---
 daemons/clvmd/lvm-functions.c  |    1 -
 lib/cache/lvmcache.c           |  259 ++++++----------------------------------
 lib/cache/lvmcache.h           |    8 --
 lib/format1/disk-rep.c         |    1 -
 lib/format1/lvm1-label.c       |    1 -
 lib/format_pool/disk_rep.c     |    3 -
 lib/format_text/text_label.c   |    1 -
 lib/metadata/metadata-liblvm.c |    1 -
 lib/metadata/metadata.c        |   10 +--
 libdm/libdm-config.c           |   10 +-
 liblvm/lvm_vg.c                |    1 -
 tools/toollib.c                |    6 +
 tools/vgcreate.c               |    1 -
 tools/vgmerge.c                |    3 +
 tools/vgsplit.c                |    3 +
 15 files changed, 54 insertions(+), 255 deletions(-)
daemons/clvmd/lvm-functions.c +0 -1
index c278692..6254122 100644
@@ -662,7 +662,6 @@ int do_refresh_cache(void)
 	}
 
 	init_ignore_suspended_devices(1);
-	lvmcache_force_next_label_scan();
 	lvmcache_label_scan(cmd);
 	label_scan_destroy(cmd); /* destroys bcache (to close devs), keeps lvmcache */
 	dm_pool_empty(cmd->mem);
lib/cache/lvmcache.c +36 -223

378 lines not on this page · raw message

lib/cache/lvmcache.h +0 -8
index 4343060..107c993 100644
@@ -67,13 +67,6 @@ void lvmcache_allow_reads_with_lvmetad(void);
 
 void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset);
 
-/*
- * lvmcache_label_scan() will scan labels the first time it's
- * called, but not on subsequent calls, unless
- * lvmcache_force_next_label_scan() is called first
- * to force the next lvmcache_label_scan() to scan again.
- */
-void lvmcache_force_next_label_scan(void);
 int lvmcache_label_scan(struct cmd_context *cmd);
 int lvmcache_label_rescan_vg(struct cmd_context *cmd, const char *vgname, const char *vgid);
 
@@ -187,7 +180,6 @@ int lvmcache_foreach_pv(struct lvmcache_vginfo *vginfo,
 uint64_t lvmcache_device_size(struct lvmcache_info *info);
 void lvmcache_set_device_size(struct lvmcache_info *info, uint64_t size);
 struct device *lvmcache_device(struct lvmcache_info *info);
-void lvmcache_make_valid(struct lvmcache_info *info);
 int lvmcache_is_orphan(struct lvmcache_info *info);
 int lvmcache_uncertain_ownership(struct lvmcache_info *info);
 unsigned lvmcache_mda_count(struct lvmcache_info *info);
lib/format1/disk-rep.c +0 -1
index 41955af..281adc1 100644
@@ -337,7 +337,6 @@ static void __update_lvmcache(const struct format_type *fmt,
 
 	lvmcache_set_device_size(info, ((uint64_t)xlate32(dl->pvd.pv_size)) << SECTOR_SHIFT);
 	lvmcache_del_mdas(info);
-	lvmcache_make_valid(info);
 }
 
 static struct disk_list *__read_disk(const struct format_type *fmt,
lib/format1/lvm1-label.c +0 -1
index 3b8a655..691a05a 100644
@@ -84,7 +84,6 @@ static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
 	lvmcache_set_ext_flags(info, 0);
 	lvmcache_del_mdas(info);
 	lvmcache_del_bas(info);
-	lvmcache_make_valid(info);
 
 	return 1;
 }
lib/format_pool/disk_rep.c +0 -3
index 374ff44..fe9b03e 100644
@@ -111,7 +111,6 @@ int read_pool_label(struct pool_list *pl, struct labeller *l,
 	lvmcache_set_ext_flags(info, 0);
 	lvmcache_del_mdas(info);
 	lvmcache_del_bas(info);
-	lvmcache_make_valid(info);
 
 	pl->dev = dev;
 	pl->pv = NULL;
@@ -379,8 +378,6 @@ int read_pool_pds(const struct format_type *fmt, const char *vg_name,
 					   vg_name);
 			return 0;
 		}
-		if (full_scan > 0)
-			lvmcache_force_next_label_scan();
 		lvmcache_label_scan(fmt->cmd);
 
 	} while (1);
lib/format_text/text_label.c +0 -1
index e65079e..c47a35a 100644
@@ -443,7 +443,6 @@ out:
 		return 0;
 	}
 
-	lvmcache_make_valid(info);
 	return 1;
 }
 
lib/metadata/metadata-liblvm.c +0 -1
index d8b3b2a..b0b678a 100644
@@ -273,7 +273,6 @@ out:
 		}
 
 	if (scan_needed) {
-		lvmcache_force_next_label_scan();
 		if (!lvmcache_label_scan(cmd)) {
 			stack;
 			r = 0;
lib/metadata/metadata.c +1 -9
index 8cb06be..8c8ce25 100644
@@ -3392,8 +3392,6 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,
 	struct pv_list head;
 
 	dm_list_init(&head.list);
-	lvmcache_label_scan(cmd);
-	lvmcache_seed_infos_from_lvmetad(cmd);
 
 	if (!(vginfo = lvmcache_vginfo_from_vgname(orphan_vgname, NULL)))
 		return_NULL;
@@ -3839,11 +3837,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
 	 */
 	log_debug_metadata("Reading VG rereading labels for %s", vgname);
 
-	if (!lvmcache_label_rescan_vg(cmd, vgname, vgid)) {
-		/* The VG wasn't found, so force a full label scan. */
-		lvmcache_force_next_label_scan();
-		lvmcache_label_scan(cmd);
-	}
+	lvmcache_label_rescan_vg(cmd, vgname, vgid);
 
 	if (!(fmt = lvmcache_fmt_from_vgname(cmd, vgname, vgid, 0))) {
 		log_debug_metadata("Cache did not find fmt for vgname %s", vgname);
@@ -4531,7 +4525,6 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
 	if (!(vgname = lvmcache_vgname_from_vgid(cmd->mem, vgid))) {
 		log_debug_metadata("Reading VG by vgid %.8s no VG name found, retrying.", vgid);
 		lvmcache_destroy(cmd, 0, 0);
-		lvmcache_force_next_label_scan();
 		lvmcache_label_scan(cmd);
 	}
 
@@ -5572,7 +5565,6 @@ uint32_t vg_lock_newname(struct cmd_context *cmd, const char *vgname)
 				unlock_vg(cmd, NULL, vgname);
 				return FAILED_LOCKING;
 			}
-			lvmcache_force_next_label_scan();
 			lvmcache_label_scan(cmd);
 			if (!lvmcache_fmt_from_vgname(cmd, vgname, NULL, 0))
 				return SUCCESS; /* vgname not found after scanning */
libdm/libdm-config.c +5 -5
index 746ef07..3f0d251 100644
@@ -963,7 +963,7 @@ static const char *_find_config_str(const void *start, node_lookup_fn find_fn,
 	if (n && n->v) {
 		if ((n->v->type == DM_CFG_STRING) &&
 		    (allow_empty || (*n->v->v.str))) {
-			log_very_verbose("Setting %s to %s", path, n->v->v.str);
+			/* log_very_verbose("Setting %s to %s", path, n->v->v.str); */
 			return n->v->v.str;
 		}
 		if ((n->v->type != DM_CFG_STRING) || (!allow_empty && fail))
@@ -994,7 +994,7 @@ static int64_t _find_config_int64(const void *start, node_lookup_fn find,
 	const struct dm_config_node *n = find(start, path);
 
 	if (n && n->v && n->v->type == DM_CFG_INT) {
-		log_very_verbose("Setting %s to %" PRId64, path, n->v->v.i);
+		/* log_very_verbose("Setting %s to %" PRId64, path, n->v->v.i); */
 		return n->v->v.i;
 	}
 
@@ -1009,7 +1009,7 @@ static float _find_config_float(const void *start, node_lookup_fn find,
 	const struct dm_config_node *n = find(start, path);
 
 	if (n && n->v && n->v->type == DM_CFG_FLOAT) {
-		log_very_verbose("Setting %s to %f", path, n->v->v.f);
+		/* log_very_verbose("Setting %s to %f", path, n->v->v.f); */
 		return n->v->v.f;
 	}
 
@@ -1058,12 +1058,12 @@ static int _find_config_bool(const void *start, node_lookup_fn find,
 		switch (v->type) {
 		case DM_CFG_INT:
 			b = v->v.i ? 1 : 0;
-			log_very_verbose("Setting %s to %d", path, b);
+			/* log_very_verbose("Setting %s to %d", path, b); */
 			return b;
 
 		case DM_CFG_STRING:
 			b = _str_to_bool(v->v.str, fail);
-			log_very_verbose("Setting %s to %d", path, b);
+			/* log_very_verbose("Setting %s to %d", path, b); */
 			return b;
 		default:
 			;
liblvm/lvm_vg.c +0 -1
index 5593579..0678bdc 100644
@@ -512,7 +512,6 @@ int lvm_scan(lvm_t libh)
 	int rc = 0;
 	struct saved_env e = store_user_env((struct cmd_context *)libh);
 
-	lvmcache_force_next_label_scan();
 	if (!lvmcache_label_scan((struct cmd_context *)libh))
 		rc = -1;
 
tools/toollib.c +6 -0
index fabf2dc..e887f65 100644
@@ -1485,6 +1485,12 @@ int change_tag(struct cmd_context *cmd, struct volume_group *vg,
 	return 1;
 }
 
+/*
+ * FIXME: replace process_each_label() with process_each_vg() which is
+ * based on performing vg_read(), which provides a correct representation
+ * of VGs/PVs, that is not provided by lvmcache_label_scan().
+ */
+
 int process_each_label(struct cmd_context *cmd, int argc, char **argv,
 		       struct processing_handle *handle,
 		       process_single_label_fn_t process_single_label)
tools/vgcreate.c +0 -1
index 87a296f..0c4c428 100644
@@ -82,7 +82,6 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
 		return ECMD_FAILED;
 	}
 
-	lvmcache_force_next_label_scan();
 	lvmcache_label_scan(cmd);              /* Does nothing when using lvmetad. */
 	lvmcache_seed_infos_from_lvmetad(cmd); /* Does nothing unless using lvmetad. */
 
tools/vgmerge.c +3 -0
index 013bef4..67c3498 100644
@@ -72,6 +72,9 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
 		return ECMD_FAILED;
 	}
 
+	lvmcache_label_scan(cmd);
+	lvmcache_seed_infos_from_lvmetad(cmd);
+
 	if (strcmp(vg_name_to, vg_name_from) > 0)
 		lock_vg_from_first = 1;
 
tools/vgsplit.c +3 -0
index 46c8911..2d39111 100644
@@ -581,6 +581,9 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
 		return ECMD_FAILED;
 	}
 
+	lvmcache_label_scan(cmd);
+	lvmcache_seed_infos_from_lvmetad(cmd);
+
 	if (strcmp(vg_name_to, vg_name_from) < 0)
 		lock_vg_from_first = 0;