summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2017-10-26 14:32:30 -0500
committerDavid Teigland <teigland@redhat.com>2017-10-26 17:04:32 -0500
commit1674af2e566aea8bf7204480ae94cf68f3c35884 (patch)
treea820481d46d11f2b2fb75c4b048f3721c59ae447
parent7bb75a71e30857b0e1866ec4a855ba9769e36b01 (diff)
downloadlvm2-dev-dct-new-scan-15.tar.gz
vgcreate: improve the use of label_scandev-dct-new-scan-15
The old code was doing unnecessary label scans when checking to see if the new VG name exists. A single label_scan is sufficient if it is done after the new VG lock is held.
-rw-r--r--tools/vgcreate.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
index af0c36364..69e08b367 100644
--- a/tools/vgcreate.c
+++ b/tools/vgcreate.c
@@ -66,17 +66,30 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
return_ECMD_FAILED;
cmd->lockd_gl_disable = 1;
- lvmcache_seed_infos_from_lvmetad(cmd);
-
/*
* Check if the VG name already exists. This should be done before
* creating PVs on any of the devices.
+ *
+ * When searching if a VG name exists, acquire the VG lock,
+ * then do the initial label scan which reads all devices and
+ * populates lvmcache with any VG name it finds. If the VG name
+ * we want to use exists, then the label scan will find it,
+ * and the fmt_from_vgname call (used to check if the name exists)
+ * will return non-NULL.
*/
- if ((rc = vg_lock_newname(cmd, vp_new.vg_name)) != SUCCESS) {
- if (rc == FAILED_EXIST)
- log_error("A volume group called %s already exists.", vp_new.vg_name);
- else
- log_error("Can't get lock for %s.", vp_new.vg_name);
+
+ if (!lock_vol(cmd, vp_new.vg_name, LCK_VG_WRITE, NULL)) {
+ log_error("Can't get lock for %s.", vp_new.vg_name);
+ 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. */
+
+ if (lvmcache_fmt_from_vgname(cmd, vp_new.vg_name, NULL, 0)) {
+ unlock_vg(cmd, NULL, vp_new.vg_name);
+ log_error("A volume group called %s already exists.", vp_new.vg_name);
return ECMD_FAILED;
}