From 8e8755319c8a8848b8bcd830a6341eccf750f798 Mon Sep 17 00:00:00 2001 From: David Teigland Date: Thu, 14 Sep 2017 12:20:29 -0500 Subject: [PATCH] lvcreate: use cmd defs to deny unspported lockd cases In a shared VG, lvconvert must be used to create thin pools and cache pools, not the lvcreate variants of those commands. Deny these cases early in lvcreate using the new command defs. Denying these cases deeper in the code was missing some cleanup of the partially completed command. --- lib/locking/lvmlockd.c | 7 +++++++ tools/lvcreate.c | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c index f4047d9d7..058d4b5c9 100644 --- a/lib/locking/lvmlockd.c +++ b/lib/locking/lvmlockd.c @@ -2385,6 +2385,10 @@ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, struct logic return 1; } else if (seg_is_cache(lp) || seg_is_cache_pool(lp)) { + /* + * This should not happen because the command defs are + * checked and excluded for shared VGs early in lvcreate. + */ log_error("Use lvconvert for cache with lock type %s", vg->lock_type); return 0; @@ -2440,6 +2444,9 @@ int lockd_init_lv(struct cmd_context *cmd, struct volume_group *vg, struct logic /* * Creating a thin pool and a thin lv in it. We could * probably make this work. + * + * This should not happen because the command defs are + * checked and excluded for shared VGs early in lvcreate. */ log_error("Create thin pool and thin LV separately with lock type %s", vg->lock_type); diff --git a/tools/lvcreate.c b/tools/lvcreate.c index d2199f5ce..8aa16f24a 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -1634,8 +1634,18 @@ static int _lvcreate_single(struct cmd_context *cmd, const char *vg_name, lp->snapshot ? " as snapshot of " : "", lp->snapshot ? lp->origin_name : "", lp->segtype->name); - if (is_lockd_type(vg->lock_type)) + if (is_lockd_type(vg->lock_type)) { + if (cmd->command->command_enum == lvcreate_thin_vol_and_thinpool_CMD || + cmd->command->command_enum == lvcreate_cachepool_CMD || + cmd->command->command_enum == lvcreate_cache_vol_with_new_origin_CMD || + cmd->command->command_enum == lvcreate_thin_vol_with_thinpool_or_sparse_snapshot_CMD || + cmd->command->command_enum == lvcreate_cache_vol_with_new_origin_or_convert_to_cache_vol_with_cachepool_CMD) { + log_error("Use lvconvert to create thin pools and cache pools in a shared VG."); + goto out; + } + lp->needs_lockd_init = 1; + } if (!lv_create_single(vg, lp)) goto_out;