diff options
author | David Teigland <teigland@redhat.com> | 2015-06-02 10:03:11 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2015-06-03 14:00:48 -0500 |
commit | b57eff46aa0694d2351ed20fa1855122cd82c225 (patch) | |
tree | b3681738a5d74441372adf7b48017fddeba165b2 | |
parent | a9b532f1ccdabf4976d51b9b6a5eae1032097964 (diff) | |
download | lvm2-b57eff46aa0694d2351ed20fa1855122cd82c225.tar.gz |
lvmlockd: use LV ids for LV lock names
-rw-r--r-- | daemons/lvmlockd/lvmlockd-core.c | 147 | ||||
-rw-r--r-- | daemons/lvmlockd/lvmlockd-internal.h | 1 | ||||
-rw-r--r-- | lib/locking/lvmlockd.c | 88 | ||||
-rw-r--r-- | lib/locking/lvmlockd.h | 20 | ||||
-rw-r--r-- | lib/metadata/lv_manip.c | 63 | ||||
-rw-r--r-- | tools/lvconvert.c | 13 | ||||
-rw-r--r-- | tools/vgchange.c | 2 |
7 files changed, 169 insertions, 165 deletions
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c index a1eecfa02..ba99b2825 100644 --- a/daemons/lvmlockd/lvmlockd-core.c +++ b/daemons/lvmlockd/lvmlockd-core.c @@ -1901,7 +1901,7 @@ static struct resource *find_resource_act(struct lockspace *ls, return r; if (r->type == LD_RT_LV && act->rt == LD_RT_LV && - !strcmp(r->name, act->lv_name)) + !strcmp(r->name, act->lv_uuid)) return r; } @@ -1920,7 +1920,7 @@ static struct resource *find_resource_act(struct lockspace *ls, else if (r->type == LD_RT_VG) strncpy(r->name, R_NAME_VG, MAX_NAME); else if (r->type == LD_RT_LV) - strncpy(r->name, act->lv_name, MAX_NAME); + strncpy(r->name, act->lv_uuid, MAX_NAME); list_add_tail(&r->list, &ls->resources); @@ -2944,7 +2944,7 @@ static int work_init_lv(struct action *act) } if (lm_type == LD_LM_SANLOCK) { - rv = lm_init_lv_sanlock(ls_name, act->vg_name, act->lv_name, + rv = lm_init_lv_sanlock(ls_name, act->vg_name, act->lv_uuid, vg_args, lv_args); memcpy(act->lv_args, lv_args, MAX_ARGS); @@ -3044,7 +3044,7 @@ static void *worker_thread_main(void *arg_in) add_client_result(act); } else if ((act->op == LD_OP_INIT) && (act->rt == LD_RT_LV)) { - log_debug("work init_lv %s/%s", act->vg_name, act->lv_name); + log_debug("work init_lv %s/%s uuid %s", act->vg_name, act->lv_name, act->lv_uuid); act->result = work_init_lv(act); add_client_result(act); @@ -4086,6 +4086,10 @@ static void client_recv_action(struct client *cl) if (str && strcmp(str, "none")) strncpy(act->lv_name, str, MAX_NAME); + str = daemon_request_str(req, "lv_uuid", NULL); + if (str && strcmp(str, "none")) + strncpy(act->lv_uuid, str, MAX_NAME); + val = daemon_request_int(req, "version", 0); if (val) act->version = (uint32_t)val; @@ -4347,9 +4351,10 @@ static int get_lockd_vgs(struct list_head *vg_lockd) struct resource *r; const char *vg_name; const char *vg_uuid; + const char *lv_uuid; const char *lock_type; const char *lock_args; - char lv_lock_path[PATH_MAX]; + char find_str_path[PATH_MAX]; int mutex_unlocked = 0; int rv = 0; @@ -4449,14 +4454,22 @@ static int get_lockd_vgs(struct list_head *vg_lockd) continue; for (lv_cn = md_cn->child; lv_cn; lv_cn = lv_cn->sib) { - snprintf(lv_lock_path, PATH_MAX, "%s/lock_type", lv_cn->key); - lock_type = dm_config_find_str(lv_cn, lv_lock_path, NULL); + snprintf(find_str_path, PATH_MAX, "%s/lock_type", lv_cn->key); + lock_type = dm_config_find_str(lv_cn, find_str_path, NULL); if (!lock_type) continue; - snprintf(lv_lock_path, PATH_MAX, "%s/lock_args", lv_cn->key); - lock_args = dm_config_find_str(lv_cn, lv_lock_path, NULL); + snprintf(find_str_path, PATH_MAX, "%s/lock_args", lv_cn->key); + lock_args = dm_config_find_str(lv_cn, find_str_path, NULL); + + snprintf(find_str_path, PATH_MAX, "%s/id", lv_cn->key); + lv_uuid = dm_config_find_str(lv_cn, find_str_path, NULL); + + if (!lv_uuid) { + log_error("get_lock_vgs no lv id for name %s", lv_cn->key); + continue; + } if (!(r = alloc_resource())) { rv = -ENOMEM; @@ -4464,12 +4477,12 @@ static int get_lockd_vgs(struct list_head *vg_lockd) } r->type = LD_RT_LV; - strncpy(r->name, lv_cn->key, MAX_NAME); + strncpy(r->name, lv_uuid, MAX_NAME); if (lock_args) strncpy(r->lv_args, lock_args, MAX_ARGS); list_add_tail(&r->list, &ls->resources); - log_debug("get_lockd_vgs %s lv %s %s", - ls->vg_name, r->name, lock_args ? lock_args : ""); + log_debug("get_lockd_vgs %s lv %s %s (name %s)", + ls->vg_name, r->name, lock_args ? lock_args : "", lv_cn->key); } } next: @@ -4498,17 +4511,18 @@ out: return rv; } -static int is_lvm_device(char *name) +static char _dm_uuid[64]; + +static char *get_dm_uuid(char *dm_name) { struct dm_info info; struct dm_task *dmt; const char *uuid; - int rv = 0; if (!(dmt = dm_task_create(DM_DEVICE_INFO))) goto fail_out; - if (!dm_task_set_name(dmt, name)) + if (!dm_task_set_name(dmt, dm_name)) goto fail; if (!dm_task_run(dmt)) @@ -4521,24 +4535,63 @@ static int is_lvm_device(char *name) goto fail; uuid = dm_task_get_uuid(dmt); - - if (!uuid) + if (!uuid) { + log_error("Failed to get uuid for device %s", dm_name); goto fail; + } - if (!strncmp(uuid, "LVM", 3)) { - log_debug("dm device %s is from LVM", name); - rv = 1; - } else { - log_debug("dm device %s is not from LVM", name); + if (strncmp(uuid, "LVM", 3)) { + log_debug("dm device %s is not from LVM", dm_name); + goto fail; } + memset(_dm_uuid, 0, sizeof(_dm_uuid)); + strcpy(_dm_uuid, uuid); dm_task_destroy(dmt); - return rv; + return _dm_uuid; fail: dm_task_destroy(dmt); fail_out: - log_error("Failed to get dm info about device %s", name); + return NULL; +} + +/* + * dm reports the LV uuid as: + * LVM-ydpRIdDWBDX25upmj2k0D4deat6oxH8er03T0f4xM8rPIV8XqIhwv3h8Y7xRWjMr + * + * the lock name for the LV is: + * r03T0f-4xM8-rPIV-8XqI-hwv3-h8Y7-xRWjMr + * + * This function formats both as: + * r03T0f4xM8rPIV8XqIhwv3h8Y7xRWjMr + * + * and returns 1 if they match. + */ + +static int match_dm_uuid(char *dm_uuid, char *lv_lock_uuid) +{ + char buf1[64]; + char buf2[64]; + int i, j; + + memset(buf1, 0, sizeof(buf1)); + memset(buf2, 0, sizeof(buf2)); + + for (i = 0, j = 0; i < strlen(lv_lock_uuid); i++) { + if (lv_lock_uuid[i] == '-') + continue; + buf1[j] = lv_lock_uuid[i]; + j++; + } + + for (i = 36, j = 0; i < 69; i++) { + buf2[j] = dm_uuid[i]; + j++; + } + + if (!strcmp(buf1, buf2)) + return 1; return 0; } @@ -4547,12 +4600,14 @@ fail_out: * Remove any that are not active. The remaining * will have locks adopted. */ + static int remove_inactive_lvs(struct list_head *vg_lockd) { struct lockspace *ls; struct resource *r, *rsafe; struct dm_names *names; struct dm_task *dmt; + char *dm_uuid; char *vgname, *lvname, *layer; char namebuf[MAX_NAME+1]; unsigned next = 0; @@ -4578,8 +4633,17 @@ static int remove_inactive_lvs(struct list_head *vg_lockd) goto out; } + /* + * For each dm name, compare it to each lv in each lockd vg. + */ + do { names = (struct dm_names *)((char *) names + next); + + dm_uuid = get_dm_uuid(names->name); + if (!dm_uuid) + goto next_dmname; + vgname = NULL; lvname = NULL; layer = NULL; @@ -4590,31 +4654,34 @@ static int remove_inactive_lvs(struct list_head *vg_lockd) dm_split_lvm_name(NULL, NULL, &vgname, &lvname, &layer); + log_debug("adopt remove_inactive dm name %s dm uuid %s vgname %s lvname %s", + names->name, dm_uuid, vgname, lvname); + if (!vgname || !lvname) { log_debug("dm name %s invalid split vg %s lv %s layer %s", names->name, vgname ? vgname : "", lvname ? lvname : "", layer ? layer : ""); - goto skip; + goto next_dmname; } list_for_each_entry(ls, vg_lockd, list) { if (strcmp(vgname, ls->vg_name)) continue; - log_debug("lockd vg %s has dm name %s", vgname, lvname); + if (!strcmp(lvname, "lvmlock")) + continue; list_for_each_entry(r, &ls->resources, list) { - if (strcmp(lvname, r->name)) - continue; - - if (!is_lvm_device(names->name)) + if (!match_dm_uuid(dm_uuid, r->name)) continue; /* Found an active LV in a lockd VG. */ - log_debug("lockd vg %s has active lv %s to adopt", ls->vg_name, r->name); + log_debug("dm device %s adopt in vg %s lv %s", + names->name, ls->vg_name, r->name); r->adopt = 1; + goto next_dmname; } } -skip: +next_dmname: next = names->next; } while (next); @@ -4716,7 +4783,7 @@ static void adopt_locks(void) ls->vg_name, lm_str(ls->lm_type), ls->vg_args); list_for_each_entry(r, &ls->resources, list) - log_debug("adopt lv %s/%s", ls->vg_name, r->name); + log_debug("adopt lv %s %s", ls->vg_name, r->name); } /* @@ -4933,14 +5000,14 @@ static void adopt_locks(void) act->client_id = ADOPT_CLIENT_ID; act->lm_type = ls->lm_type; strncpy(act->vg_name, ls->vg_name, MAX_NAME); - strncpy(act->lv_name, r->name, MAX_NAME); + strncpy(act->lv_uuid, r->name, MAX_NAME); strncpy(act->lv_args, r->lv_args, MAX_ARGS); - log_debug("adopt lock for lv %s/%s", act->vg_name, act->lv_name); + log_debug("adopt lock for lv %s %s", act->vg_name, act->lv_uuid); rv = add_lock_action(act); if (rv < 0) { - log_error("adopt add_lock_action lv %s/%s error %d", act->vg_name, act->lv_name, rv); + log_error("adopt add_lock_action lv %s %s error %d", act->vg_name, act->lv_uuid, rv); count_adopt_fail++; free_action(act); } else { @@ -5065,8 +5132,8 @@ static void adopt_locks(void) if (act->rt == LD_RT_LV) { /* Unexpected, we should have found an orphan. */ - log_error("Failed to adopt LV lock for %s/%s error %d", - act->vg_name, act->lv_name, act->result); + log_error("Failed to adopt LV lock for %s %s error %d", + act->vg_name, act->lv_uuid, act->result); count_adopt_fail++; } else { /* Normal, no GL/VG lock was orphaned. */ @@ -5083,7 +5150,7 @@ static void adopt_locks(void) */ log_error("adopt lock rt %s vg %s lv %s error %d", - rt_str(act->rt), act->vg_name, act->lv_name, act->result); + rt_str(act->rt), act->vg_name, act->lv_uuid, act->result); count_adopt_fail++; count_adopt_done++; free_action(act); @@ -5094,7 +5161,7 @@ static void adopt_locks(void) */ if (act->rt == LD_RT_LV) { - log_debug("adopt success lv %s/%s %s", act->vg_name, act->lv_name, mode_str(act->mode)); + log_debug("adopt success lv %s %s %s", act->vg_name, act->lv_uuid, mode_str(act->mode)); free_action(act); } else if (act->rt == LD_RT_VG) { log_debug("adopt success vg %s %s", act->vg_name, mode_str(act->mode)); diff --git a/daemons/lvmlockd/lvmlockd-internal.h b/daemons/lvmlockd/lvmlockd-internal.h index da7567e6a..81e0ff9c5 100644 --- a/daemons/lvmlockd/lvmlockd-internal.h +++ b/daemons/lvmlockd/lvmlockd-internal.h @@ -125,6 +125,7 @@ struct action { char vg_uuid[64]; char vg_name[MAX_NAME+1]; char lv_name[MAX_NAME+1]; + char lv_uuid[MAX_NAME+1]; char vg_args[MAX_ARGS]; char lv_args[MAX_ARGS]; char vg_sysid[MAX_NAME+1]; diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c index b5cfa5f40..be894cb2e 100644 --- a/lib/locking/lvmlockd.c +++ b/lib/locking/lvmlockd.c @@ -224,6 +224,7 @@ static int _lockd_request(struct cmd_context *cmd, const char *vg_lock_type, const char *vg_lock_args, const char *lv_name, + const char *lv_uuid, const char *lv_lock_args, const char *mode, const char *opts, @@ -258,6 +259,7 @@ static int _lockd_request(struct cmd_context *cmd, "opts = %s", opts ?: "none", "vg_name = %s", vg_name, "lv_name = %s", lv_name, + "lv_uuid = %s", lv_uuid, "vg_lock_type = %s", vg_lock_type ?: "none", "vg_lock_args = %s", vg_lock_args ?: "none", "lv_lock_args = %s", lv_lock_args ?: "none", @@ -673,7 +675,7 @@ static int _free_vg_dlm(struct cmd_context *cmd, struct volume_group *vg) /* Equivalent to a standard unlock. */ ret = _lockd_request(cmd, "lock_vg", - vg->name, NULL, NULL, NULL, NULL, "un", NULL, + vg->name, NULL, NULL, NULL, NULL, NULL, "un", NULL, &result, &lockd_flags); if (!ret || result < 0) { @@ -1114,7 +1116,7 @@ int lockd_gl_create(struct cmd_context *cmd, const char *def_mode, const char *v req: if (!_lockd_request(cmd, "lock_gl", - NULL, vg_lock_type, NULL, NULL, NULL, mode, NULL, + NULL, vg_lock_type, NULL, NULL, NULL, NULL, mode, NULL, &result, &lockd_flags)) { /* No result from lvmlockd, it is probably not running. */ log_error("Locking failed for global lock"); @@ -1308,7 +1310,7 @@ int lockd_gl(struct cmd_context *cmd, const char *def_mode, uint32_t flags) req: if (!_lockd_request(cmd, "lock_gl", - NULL, NULL, NULL, NULL, NULL, mode, opts, + NULL, NULL, NULL, NULL, NULL, NULL, mode, opts, &result, &lockd_flags)) { /* No result from lvmlockd, it is probably not running. */ @@ -1540,7 +1542,7 @@ int lockd_vg(struct cmd_context *cmd, const char *vg_name, const char *def_mode, req: if (!_lockd_request(cmd, "lock_vg", - vg_name, NULL, NULL, NULL, NULL, mode, NULL, + vg_name, NULL, NULL, NULL, NULL, NULL, mode, NULL, &result, &lockd_flags)) { /* * No result from lvmlockd, it is probably not running. @@ -1735,9 +1737,10 @@ int lockd_vg_update(struct volume_group *vg) */ int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_args, - const char *def_mode, uint32_t flags) + const char *lv_name, struct id *lv_id, + const char *lock_args, const char *def_mode, uint32_t flags) { + char lv_uuid[64] __attribute__((aligned(8))); const char *mode = NULL; const char *opts = NULL; uint32_t lockd_flags; @@ -1747,6 +1750,8 @@ int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg, if (cmd->lockd_lv_disable) return 1; + id_write_format(lv_id, lv_uuid, sizeof(lv_uuid)); + /* * For lvchange/vgchange activation, def_mode is "sh" or "ex" * according to the specific -a{e,s}y mode designation. @@ -1792,7 +1797,7 @@ int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg, retry: if (!_lockd_request(cmd, "lock_lv", vg->name, vg->lock_type, vg->lock_args, - lv_name, lock_args, mode, opts, + lv_name, lv_uuid, lock_args, mode, opts, &result, &lockd_flags)) { /* No result from lvmlockd, it is probably not running. */ log_error("Locking failed for LV %s/%s", vg->name, lv_name); @@ -1870,8 +1875,8 @@ static int _lockd_lv_thin(struct cmd_context *cmd, struct logical_volume *lv, flags |= LDLV_MODE_NO_SH; - return lockd_lv_name(cmd, pool_lv->vg, pool_lv->name, pool_lv->lock_args, - def_mode, flags); + return lockd_lv_name(cmd, pool_lv->vg, pool_lv->name, &pool_lv->lvid.id[1], + pool_lv->lock_args, def_mode, flags); } /* @@ -1921,12 +1926,15 @@ int lockd_lv(struct cmd_context *cmd, struct logical_volume *lv, flags |= LDLV_MODE_NO_SH; } - return lockd_lv_name(cmd, lv->vg, lv->name, lv->lock_args, def_mode, flags); + return lockd_lv_name(cmd, lv->vg, lv->name, &lv->lvid.id[1], + lv->lock_args, def_mode, flags); } static int _init_lv_sanlock(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char **lock_args_ret) + const char *lv_name, struct id *lv_id, + const char **lock_args_ret) { + char lv_uuid[64] __attribute__((aligned(8))); daemon_reply reply; const char *reply_str; const char *lv_lock_args = NULL; @@ -1940,11 +1948,13 @@ static int _init_lv_sanlock(struct cmd_context *cmd, struct volume_group *vg, if (!_lvmlockd_connected) return 0; + id_write_format(lv_id, lv_uuid, sizeof(lv_uuid)); retry: reply = _lockd_send("init_lv", "pid = %d", getpid(), "vg_name = %s", vg->name, "lv_name = %s", lv_name, + "lv_uuid = %s", lv_uuid, "vg_lock_type = %s", "sanlock", "vg_lock_args = %s", vg->lock_args, NULL); @@ -2004,8 +2014,9 @@ out: } static int _free_lv_sanlock(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_args) + const char *lv_name, struct id *lv_id, const char *lock_args) { + char lv_uuid[64] __attribute__((aligned(8))); daemon_reply reply; int result; int ret; @@ -2015,10 +2026,13 @@ static int _free_lv_sanlock(struct cmd_context *cmd, struct volume_group *vg, if (!_lvmlockd_connected) return 0; + id_write_format(lv_id, lv_uuid, sizeof(lv_uuid)); + reply = _lockd_send("free_lv", "pid = %d", getpid(), "vg_name = %s", vg->name, "lv_name = %s", lv_name, + "lv_uuid = %s", lv_uuid, "vg_lock_type = %s", "sanlock", "vg_lock_args = %s", vg->lock_args, "lv_lock_args = %s", lock_args ?: "none", @@ -2039,47 +2053,13 @@ static int _free_lv_sanlock(struct cmd_context *cmd, struct volume_group *vg, return ret; } -/* - * The lock managers have max name lengths lower than lvm; - * 64 for dlm and 48 for sanlock. Check for name collisions - * within this limit. (It's much easier to check for this here - * where the vg metadata is available than in lvmlockd.) - */ - -#define MAX_LVNAME_SANLOCK 48 -#define MAX_LVNAME_DLM 64 - int lockd_init_lv_args(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_type, const char **lock_args) + const char *lv_name, struct id *lv_id, + const char *lock_type, const char **lock_args) { - struct lv_list *lvl; - int maxname; - - switch (lock_type_to_num(vg->lock_type)) { - case LOCK_TYPE_SANLOCK: - maxname = MAX_LVNAME_SANLOCK; - break; - case LOCK_TYPE_DLM: - maxname = MAX_LVNAME_DLM; - break; - default: - return 1; - } - - dm_list_iterate_items(lvl, &vg->lvs) { - /* An exact match is the lv itself. */ - if (!strcmp(lvl->lv->name, lv_name)) - continue; - if (!strncmp(lvl->lv->name, lv_name, maxname)) { - log_error("LV name %s matches existing LV %s within %s character limit %d", - lv_name, lvl->lv->name, vg->lock_type, maxname); - return 0; - } - } - /* sanlock is the only lock type that sets per-LV lock_args. */ if (!strcmp(lock_type, "sanlock")) - return _init_lv_sanlock(cmd, vg, lv_name, lock_args); + return _init_lv_sanlock(cmd, vg, lv_name, lv_id, lock_args); return 1; } @@ -2102,7 +2082,8 @@ int lockd_init_lv_args(struct cmd_context *cmd, struct volume_group *vg, */ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, struct lvcreate_params *lp) + const char *lv_name, struct id *lv_id, + struct lvcreate_params *lp) { const char *lv_name_lock; int lock_type_num = lock_type_to_num(lp->lock_type); @@ -2195,13 +2176,14 @@ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, lv_name_lock = lv_name; } - return lockd_init_lv_args(cmd, vg, lv_name_lock, lp->lock_type, &lp->lock_args); + return lockd_init_lv_args(cmd, vg, lv_name_lock, lv_id, + lp->lock_type, &lp->lock_args); } /* lvremove */ int lockd_free_lv(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_args) + const char *lv_name, struct id *lv_id, const char *lock_args) { if (cmd->lock_lv_mode && !strcmp(cmd->lock_lv_mode, "na")) return 1; @@ -2212,7 +2194,7 @@ int lockd_free_lv(struct cmd_context *cmd, struct volume_group *vg, case LOCK_TYPE_DLM: return 1; case LOCK_TYPE_SANLOCK: - return _free_lv_sanlock(cmd, vg, lv_name, lock_args); + return _free_lv_sanlock(cmd, vg, lv_name, lv_id, lock_args); default: log_error("lockd_free_lv: unknown lock_type."); return 0; diff --git a/lib/locking/lvmlockd.h b/lib/locking/lvmlockd.h index c2635fc10..8fe31c098 100644 --- a/lib/locking/lvmlockd.h +++ b/lib/locking/lvmlockd.h @@ -128,20 +128,20 @@ int lockd_vg(struct cmd_context *cmd, const char *vg_name, const char *def_mode, int lockd_vg_update(struct volume_group *vg); int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_args, - const char *def_mode, uint32_t flags); + const char *lv_name, struct id *lv_id, + const char *lock_args, const char *def_mode, uint32_t flags); int lockd_lv(struct cmd_context *cmd, struct logical_volume *lv, const char *def_mode, uint32_t flags); /* lvcreate/lvremove use init/free */ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, struct lvcreate_params *lp); + const char *lv_name, struct id *lv_id, struct lvcreate_params *lp); int lockd_free_lv(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_args); + const char *lv_name, struct id *lv_id, const char *lock_args); int lockd_init_lv_args(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_type, const char **lock_args); + const char *lv_name, struct id *lv_id, const char *lock_type, const char **lock_args); const char *lockd_running_lock_type(struct cmd_context *cmd); @@ -230,8 +230,8 @@ static inline int lockd_vg_update(struct volume_group *vg) } static inline int lockd_lv_name(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_args, - const char *def_mode, uint32_t flags) + const char *lv_name, struct id *lv_id, + const char *lock_args, const char *def_mode, uint32_t flags) { return 1; } @@ -243,19 +243,19 @@ static inline int lockd_lv(struct cmd_context *cmd, struct logical_volume *lv, } static inline int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, struct lvcreate_params *lp) + const char *lv_name, struct id *lv_id, struct lvcreate_params *lp) { return 0; } static inline int lockd_free_lv(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_args) + const char *lv_name, struct id *lv_id, const char *lock_args) { return 0; } static inline int lockd_init_lv_args(struct cmd_context *cmd, struct volume_group *vg, - const char *lv_name, const char *lock_type, const char **lock_args) + const char *lv_name, struct id *lv_id, const char *lock_type, const char **lock_args) { return 0; } diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 921bba93e..c88c247ed 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -4228,58 +4228,7 @@ 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) { - 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); - - /* - * When the LV has a lock_type, renaming takes more - * work because the LV name is a part of the lock - * name itself. This means creating and acquiring - * a new lock with the new name, then releasing and - * removing the lock with the old name. - */ - - 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; + return lv_rename_update(cmd, lv, new_name, 1); } /* @@ -5893,7 +5842,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv, lockd_lv(cmd, lock_lv, "un", LDLV_PERSISTENT | LDLV_MODE_NOARG); if (lv->lock_type) - lockd_free_lv(cmd, vg, lv->name, lv->lock_args); + lockd_free_lv(cmd, vg, lv->name, &lv->lvid.id[1], lv->lock_args); if (!suppress_remove_message && visible) log_print_unless_silent("Logical volume \"%s\" successfully removed", lv->name); @@ -7281,18 +7230,18 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg, * lockd_init_lv clears lp lock_type if this LV does not use its own lock. * TODO: use lockd_free_lv if lv_extend fails below. */ - if (lp->lock_type && !lockd_init_lv(vg->cmd, vg, lv->name, lp)) + if (lp->lock_type && !lockd_init_lv(vg->cmd, vg, lv->name, &lv->lvid.id[1], lp)) return_NULL; if (lp->lock_type && !(lv->lock_type = dm_pool_strdup(cmd->mem, lp->lock_type))) { log_error("Failed to allocate lock_type"); - lockd_free_lv(vg->cmd, vg, lp->lv_name, lp->lock_args); + lockd_free_lv(vg->cmd, vg, lp->lv_name, &lv->lvid.id[1], lp->lock_args); return NULL; } if (lp->lock_args && !(lv->lock_args = dm_pool_strdup(cmd->mem, lp->lock_args))) { log_error("Failed to allocate lock_args"); - lockd_free_lv(vg->cmd, vg, lp->lv_name, lp->lock_args); + lockd_free_lv(vg->cmd, vg, lp->lv_name, &lv->lvid.id[1], lp->lock_args); return NULL; } @@ -7604,7 +7553,7 @@ deactivate_and_revert_new_lv: revert_new_lv: if (lp->lock_type) - lockd_free_lv(vg->cmd, vg, lp->lv_name, lp->lock_args); + lockd_free_lv(vg->cmd, vg, lp->lv_name, &lv->lvid.id[1], lp->lock_args); /* FIXME Better to revert to backup of metadata? */ if (!lv_remove(lv) || !vg_write(vg) || !vg_commit(vg)) diff --git a/tools/lvconvert.c b/tools/lvconvert.c index 3270ace83..0effd0d44 100644 --- a/tools/lvconvert.c +++ b/tools/lvconvert.c @@ -2645,6 +2645,8 @@ static int _lvconvert_pool(struct cmd_context *cmd, const char *old_name; const char *lock_free_meta_name = NULL; const char *lock_free_data_name = NULL; + struct id *lock_free_meta_id; + struct id *lock_free_data_id; struct lv_segment *seg; struct volume_group *vg = pool_lv->vg; struct logical_volume *data_lv; @@ -2995,10 +2997,13 @@ static int _lvconvert_pool(struct cmd_context *cmd, lock_free_meta_name = c + 1; else lock_free_meta_name = lp->pool_metadata_name; + + lock_free_meta_id = &lp->pool_metadata_lv->lvid.id[1]; } if (segtype_is_cache_pool(lp->segtype)) { lock_free_data_name = pool_lv->name; + lock_free_data_id = &pool_lv->lvid.id[1]; pool_lv->lock_type = NULL; pool_lv->lock_args = NULL; } else { @@ -3071,19 +3076,19 @@ out: "cache" : "thin"); if (lock_free_meta_name) { - if (!lockd_lv_name(cmd, pool_lv->vg, lock_free_meta_name, NULL, "un", LDLV_PERSISTENT)) { + if (!lockd_lv_name(cmd, pool_lv->vg, lock_free_meta_name, lock_free_meta_id, NULL, "un", LDLV_PERSISTENT)) { log_error("Failed to unlock pool metadata LV %s/%s", pool_lv->vg->name, lock_free_meta_name); } - lockd_free_lv(cmd, pool_lv->vg, lock_free_meta_name, NULL); + lockd_free_lv(cmd, pool_lv->vg, lock_free_meta_name, lock_free_meta_id, NULL); } if (lock_free_data_name) { - if (!lockd_lv_name(cmd, pool_lv->vg, lock_free_data_name, NULL, "un", LDLV_PERSISTENT)) { + if (!lockd_lv_name(cmd, pool_lv->vg, lock_free_data_name, lock_free_data_id, NULL, "un", LDLV_PERSISTENT)) { log_error("Failed to unlock pool data LV %s/%s", pool_lv->vg->name, lock_free_data_name); } - lockd_free_lv(cmd, pool_lv->vg, lock_free_data_name, NULL); + lockd_free_lv(cmd, pool_lv->vg, lock_free_data_name, lock_free_data_id, NULL); } return r; diff --git a/tools/vgchange.c b/tools/vgchange.c index b2c6218b2..62667f5d1 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -686,7 +686,7 @@ static int _vgchange_locktype(struct cmd_context *cmd, lv_is_cache_pool_metadata(lv)) continue; - if (!lockd_init_lv_args(cmd, vg, lv->name, lock_type, &lock_args)) { + if (!lockd_init_lv_args(cmd, vg, lv->name, &lv->lvid.id[1], lock_type, &lock_args)) { log_error("Failed to init %s lock args LV %s/%s", lock_type, vg->name, lv->name); return 0; |