summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2016-12-09 10:55:39 -0600
committerDavid Teigland <teigland@redhat.com>2016-12-09 10:55:39 -0600
commitfe1d4e6a086b854cb4666f263967f64e34ba1abf (patch)
tree0dd6628f156a1d8c081035b94d94ff307dabea1b
parent2023297736cde3c7491f5e65fba8050f980b9d8e (diff)
downloadlvm2-fe1d4e6a086b854cb4666f263967f64e34ba1abf.tar.gz
lvconvert: use command defs for split cachepool
-rw-r--r--tools/command-lines.in2
-rw-r--r--tools/lvconvert.c116
-rw-r--r--tools/lvmcmdline.c4
-rw-r--r--tools/tools.h1
4 files changed, 90 insertions, 33 deletions
diff --git a/tools/command-lines.in b/tools/command-lines.in
index ac4b4011b..adf0db0b6 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -474,7 +474,7 @@ DESC: Separate and keep the cache pool from a cache LV.
lvconvert --uncache LV_cache_thinpool
OO: OO_LVCONVERT
-ID: lvconvert_split_and_delete_cachepool
+ID: lvconvert_split_and_remove_cachepool
DESC: Separate and delete the cache pool from a cache LV.
---
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 6d3e949bc..d6676f8c0 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1955,14 +1955,12 @@ static int _lvconvert_splitsnapshot(struct cmd_context *cmd, struct logical_volu
return 1;
}
-
-static int _lvconvert_split_cached(struct cmd_context *cmd,
- struct logical_volume *lv)
+static int _lvconvert_split_and_keep_cachepool(struct cmd_context *cmd,
+ struct logical_volume *lv,
+ struct logical_volume *cachepool_lv)
{
- struct logical_volume *cache_pool_lv = first_seg(lv)->pool_lv;
-
- log_debug("Detaching cache pool %s from cached LV %s.",
- display_lvname(cache_pool_lv), display_lvname(lv));
+ log_debug("Detaching cache pool %s from cache LV %s.",
+ display_lvname(cachepool_lv), display_lvname(lv));
if (!archive(lv->vg))
return_0;
@@ -1976,27 +1974,18 @@ static int _lvconvert_split_cached(struct cmd_context *cmd,
backup(lv->vg);
log_print_unless_silent("Logical volume %s is not cached and cache pool %s is unused.",
- display_lvname(lv), display_lvname(cache_pool_lv));
+ display_lvname(lv), display_lvname(cachepool_lv));
return 1;
}
-static int _lvconvert_uncache(struct cmd_context *cmd,
- struct logical_volume *lv,
- struct lvconvert_params *lp)
+static int _lvconvert_split_and_remove_cachepool(struct cmd_context *cmd,
+ struct logical_volume *lv,
+ struct logical_volume *cachepool_lv)
{
struct lv_segment *seg;
struct logical_volume *remove_lv;
- if (lv_is_thin_pool(lv))
- lv = seg_lv(first_seg(lv), 0); /* cached _tdata ? */
-
- if (!lv_is_cache(lv)) {
- log_error("Cannot uncache non-cached logical volume %s.",
- display_lvname(lv));
- return 0;
- }
-
seg = first_seg(lv);
if (lv_is_partial(seg_lv(seg, 0))) {
@@ -2017,7 +2006,7 @@ static int _lvconvert_uncache(struct cmd_context *cmd,
/* TODO: Check for failed cache as well to get prompting? */
if (lv_is_partial(lv)) {
if (first_seg(seg->pool_lv)->cache_mode != CACHE_MODE_WRITETHROUGH) {
- if (!lp->force) {
+ if (!arg_count(cmd, force_ARG)) {
log_error("Conversion aborted.");
log_error("Cannot uncache writethrough cache volume %s without --force.",
display_lvname(lv));
@@ -2027,14 +2016,12 @@ static int _lvconvert_uncache(struct cmd_context *cmd,
display_lvname(lv));
}
- if (!lp->yes &&
+ if (!arg_count(cmd, yes_ARG) &&
yes_no_prompt("Do you really want to uncache %s with missing LVs? [y/n]: ",
display_lvname(lv)) == 'n') {
log_error("Conversion aborted.");
return 0;
}
- cmd->handles_missing_pvs = 1;
- cmd->partial_activation = 1;
}
if (lvremove_single(cmd, remove_lv, NULL) != ECMD_PROCESSED)
@@ -4143,7 +4130,8 @@ static int _convert_thin_pool_splitcache(struct cmd_context *cmd, struct logical
return 0;
}
- return _lvconvert_split_cached(cmd, sublv1);
+ /* return _lvconvert_split_cached(cmd, sublv1); */
+ return 0;
}
/*
@@ -4162,7 +4150,8 @@ static int _convert_thin_pool_uncache(struct cmd_context *cmd, struct logical_vo
return 0;
}
- return _lvconvert_uncache(cmd, sublv1, lp);
+ /* return _lvconvert_uncache(cmd, sublv1, lp); */
+ return 0;
}
/*
@@ -4211,7 +4200,8 @@ static int _convert_thin_pool_swapmetadata(struct cmd_context *cmd, struct logic
static int _convert_cache_volume_splitcache(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- return _lvconvert_split_cached(cmd, lv);
+ /* return _lvconvert_split_cached(cmd, lv); */
+ return 0;
}
/*
@@ -4221,7 +4211,8 @@ static int _convert_cache_volume_splitcache(struct cmd_context *cmd, struct logi
static int _convert_cache_volume_uncache(struct cmd_context *cmd, struct logical_volume *lv,
struct lvconvert_params *lp)
{
- return _lvconvert_uncache(cmd, lv, lp);
+ /* return _lvconvert_uncache(cmd, lv, lp); */
+ return 0;
}
/*
@@ -4288,7 +4279,8 @@ static int _convert_cache_pool_splitcache(struct cmd_context *cmd, struct logica
return 0;
}
- return _lvconvert_split_cached(cmd, sublv1);
+ /* return _lvconvert_split_cached(cmd, sublv1); */
+ return 0;
}
/*
@@ -6094,3 +6086,69 @@ int lvconvert_merge_thin_cmd(struct cmd_context *cmd, int argc, char **argv)
NULL, NULL, &_lvconvert_merge_thin_single);
}
+static int _lvconvert_split_cachepool_single(struct cmd_context *cmd,
+ struct logical_volume *lv,
+ struct processing_handle *handle)
+{
+ struct logical_volume *cache_lv = NULL;
+ struct logical_volume *cachepool_lv = NULL;
+ struct lv_segment *seg;
+ int ret;
+
+ if (lv_is_cache(lv)) {
+ cache_lv = lv;
+ cachepool_lv = first_seg(cache_lv)->pool_lv;
+
+ } else if (lv_is_cache_pool(lv)) {
+ cachepool_lv = lv;
+
+ if ((dm_list_size(&cachepool_lv->segs_using_this_lv) == 1) &&
+ (seg = get_only_segment_using_this_lv(cachepool_lv)) &&
+ seg_is_cache(seg))
+ cache_lv = seg->lv;
+
+ } else if (lv_is_thin_pool(lv)) {
+ cache_lv = seg_lv(first_seg(lv), 0); /* cached _tdata */
+ cachepool_lv = first_seg(cache_lv)->pool_lv;
+ }
+
+ if (!cache_lv) {
+ log_error("Cannot find cache LV from %s.", display_lvname(lv));
+ return ECMD_FAILED;
+ }
+
+ if (!cachepool_lv) {
+ log_error("Cannot find cache pool LV from %s.", display_lvname(lv));
+ return ECMD_FAILED;
+ }
+
+ switch (cmd->command->command_line_enum) {
+ case lvconvert_split_and_keep_cachepool_CMD:
+ ret = _lvconvert_split_and_keep_cachepool(cmd, cache_lv, cachepool_lv);
+ break;
+
+ case lvconvert_split_and_remove_cachepool_CMD:
+ ret = _lvconvert_split_and_remove_cachepool(cmd, cache_lv, cachepool_lv);
+ break;
+ default:
+ log_error(INTERNAL_ERROR "Unknown cache pool split.");
+ ret = 0;
+ }
+
+ if (!ret)
+ return ECMD_FAILED;
+
+ return ECMD_PROCESSED;
+}
+
+int lvconvert_split_cachepool_cmd(struct cmd_context *cmd, int argc, char **argv)
+{
+ if (cmd->command->command_line_enum == lvconvert_split_and_remove_cachepool_CMD) {
+ cmd->handles_missing_pvs = 1;
+ cmd->partial_activation = 1;
+ }
+
+ return process_each_lv(cmd, 1, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
+ NULL, NULL, &_lvconvert_split_cachepool_single);
+}
+
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 91178014a..7c1e26727 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -145,10 +145,8 @@ struct command_function command_functions[COMMAND_ID_COUNT] = {
{ lvconvert_swap_pool_metadata_CMD, lvconvert_swap_pool_metadata_cmd },
{ lvconvert_swap_pool_metadata_deprecated_CMD, lvconvert_swap_pool_metadata_cmd },
{ lvconvert_merge_thin_CMD, lvconvert_merge_thin_cmd },
-#if 0
{ lvconvert_split_and_keep_cachepool_CMD, lvconvert_split_cachepool_cmd },
- { lvconvert_split_and_delete_cachepool_CMD, lvconvert_split_cachepool_cmd },
-#endif
+ { lvconvert_split_and_remove_cachepool_CMD, lvconvert_split_cachepool_cmd },
};
#if 0
diff --git a/tools/tools.h b/tools/tools.h
index e3094b2f4..f9979aa75 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -266,5 +266,6 @@ int lvconvert_to_cache_vol_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_to_thin_with_external_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_swap_pool_metadata_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_merge_thin_cmd(struct cmd_context *cmd, int argc, char **argv);
+int lvconvert_split_cachepool_cmd(struct cmd_context *cmd, int argc, char **argv);
#endif