diff options
author | David Teigland <teigland@redhat.com> | 2014-12-05 17:01:25 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2015-03-03 15:43:22 -0600 |
commit | 2a1f73e91d5bde9a3ce5d5f7cac1d3c03d093826 (patch) | |
tree | 669b0a903f598d1e74ee54d062ed11e246ce341a | |
parent | bfef3e32527221c71e00cc1af3a3b23c7c8126db (diff) | |
download | lvm2-2a1f73e91d5bde9a3ce5d5f7cac1d3c03d093826.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.c | 45 | ||||
-rw-r--r-- | tools/lvrename.c | 8 |
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; |