summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2014-12-05 17:01:25 -0600
committerDavid Teigland <teigland@redhat.com>2015-02-27 13:44:56 -0600
commit273c4bfa936ee0ba272a54304d2baa868138a761 (patch)
treed24fb072b23b0177ce603c25ba3f3dc32d3bc32e
parentc30124fe8f47abf418f9a566067dc29f8faef439 (diff)
downloadlvm2-273c4bfa936ee0ba272a54304d2baa868138a761.tar.gz
lvrename: support lock renaming with lvmlockd
The steps are: - lock the old LV name - create a lock for the new LV name (creates new lock_args) - lock the new LV name (only needed if the LV is active) - set new lock_args in the LV - rename the LV - unlock the old LV name - remove the lock for the old LV args (frees old lock_args)
-rw-r--r--lib/metadata/lv_manip.c45
-rw-r--r--tools/lvrename.c8
2 files changed, 47 insertions, 6 deletions
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index ed58130ac..f42cc8c67 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -4016,7 +4016,50 @@ int lv_rename_update(struct cmd_context *cmd, struct logical_volume *lv,
int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
const char *new_name)
{
- return lv_rename_update(cmd, lv, new_name, 1);
+ struct volume_group *vg;
+ const char *old_name;
+ const char *old_args;
+ const char *new_args;
+ int is_active = 0;
+
+ if (!is_lockd_type(lv->lock_type))
+ return lv_rename_update(cmd, lv, new_name, 1);
+
+ vg = lv->vg;
+ old_name = lv->name;
+ old_args = lv->lock_args;
+ is_active = lv_is_active(lv);
+
+ /* Lock the old LV name. */
+ if (!lockd_lv_name(cmd, vg, old_name, old_args, "ex", is_active ? LDLV_PERSISTENT : 0))
+ return_0;
+
+ /* Create a lock for the new LV name. */
+ if (!lockd_init_lv_args(cmd, vg, new_name, lv->lock_type, &new_args)) {
+ log_error("Failed to init %s lock args for new LV", lv->lock_type);
+ return 0;
+ }
+
+ /* Lock the new LV name. */
+ if (is_active && !lockd_lv_name(cmd, vg, new_name, new_args, "ex", LDLV_PERSISTENT)) {
+ log_error("Failed to lock new LV name %s/%s.", vg->name, new_name);
+ return 0;
+ }
+
+ /* The new lock args need to be written in the metadata with the new name. */
+ lv->lock_args = new_args;
+
+ if (!lv_rename_update(cmd, lv, new_name, 1)) {
+ if (is_active)
+ lockd_lv_name(cmd, vg, new_name, new_args, "un", LDLV_PERSISTENT);
+ lockd_free_lv(cmd, vg, new_name, new_args);
+ return 0;
+ }
+
+ /* Unlock and free the lock on the old name. */
+ lockd_lv_name(cmd, vg, old_name, old_args, "un", is_active ? LDLV_PERSISTENT : 0);
+ lockd_free_lv(cmd, vg, old_name, old_args);
+ return 1;
}
/*
diff --git a/tools/lvrename.c b/tools/lvrename.c
index 98559202b..dbfa4caa0 100644
--- a/tools/lvrename.c
+++ b/tools/lvrename.c
@@ -98,6 +98,9 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
+ if (!lockd_vg(cmd, vg_name, "ex", 0))
+ return_ECMD_FAILED;
+
log_verbose("Checking for existing volume group \"%s\"", vg_name);
vg = vg_read_for_update(cmd, vg_name, NULL, 0);
if (vg_read_error(vg)) {
@@ -124,11 +127,6 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
goto bad;
}
- if (is_lockd_type(vg->lock_type)) {
- log_error("Cannot rename LV with lock_type %s", vg->lock_type);
- goto bad;
- }
-
if (!lv_rename(cmd, lvl->lv, lv_name_new))
goto_bad;