From e8669311698fa0ddc5e4b3bdb0384b2b0d9a205c Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Wed, 14 Mar 2012 17:12:05 +0000 Subject: [PATCH] Improve thin_check option passing Update a way we handle option passing - so we now support path and options with space inside. Fix dm name usage for thin pools with '-' in name. Use new lvm.conf option thin_check_options to pass in options as string array. --- WHATS_NEW | 1 + doc/example.conf.in | 6 ++++- lib/activate/dev_manager.c | 46 +++++++++++++++++++++++++------------- lib/config/defaults.h | 2 +- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index d506f9d97..f04ebc3a8 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.96 - ================================ + Improve thin_check option passing and use configured path. Add --with-thin-check configure option for path to thin_check. Detect lvm binary path in lvmetad udev rules. Fix error message when pvmove LV activation fails with name already in use. diff --git a/doc/example.conf.in b/doc/example.conf.in index 72421acb6..278b4c769 100644 --- a/doc/example.conf.in +++ b/doc/example.conf.in @@ -658,7 +658,11 @@ activation { # The thin tools are available as part of the device-mapper-persistent-data # package from https://github.com/jthornber/thin-provisioning-tools. # - thin_check_executable = "/sbin/thin_check -q" + thin_check_executable = "@THIN_CHECK_CMD@" + + # String with options passed with thin_check command. By default, + # option '-q' is for quite output. + thin_check_options = [ "-q", 121e321 ] # While activating devices, I/O to devices being (re)configured is # suspended, and as a precaution against deadlocks, LVM2 needs to pin diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index 4c6799774..607b4dbd7 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -1205,39 +1205,55 @@ static int _thin_pool_callback(struct dm_tree_node *node, int ret, status; const struct thin_cb_data *data = cb_data; const char *dmdir = dm_dir(); + const struct dm_config_node *cn; + const struct dm_config_value *cv; const char *thin_check = find_config_tree_str_allow_empty(data->pool_lv->vg->cmd, "global/thin_check_executable", - DEFAULT_THIN_CHECK_EXECUTABLE); + THIN_CHECK_CMD); const struct logical_volume *mlv = first_seg(data->pool_lv)->metadata_lv; - size_t len = strlen(dmdir) + strlen(mlv->vg->name) + strlen(mlv->name) + 3; + size_t len = strlen(dmdir) + 2 * (strlen(mlv->vg->name) + strlen(mlv->name)) + 3; char meta_path[len]; - int args; - char *argv[19]; /* Max supported 15 args */ - char *split; + int args = 0; + const char *argv[19]; /* Max supported 15 args */ + char *split, *dm_name; if (!thin_check[0]) return 1; /* Checking disabled */ - if (dm_snprintf(meta_path, len, "%s/%s-%s", dmdir, - mlv->vg->name, mlv->name) < 0) { + if (!(dm_name = dm_build_dm_name(data->dm->mem, mlv->vg->name, + mlv->name, NULL)) || + (dm_snprintf(meta_path, len, "%s/%s", dmdir, dm_name) < 0)) { log_error("Failed to build thin metadata path."); return 0; } - if (!(split = dm_pool_strdup(data->dm->mem, thin_check))) { - log_error("Failed to duplicate thin check string."); - return 0; + if ((cn = find_config_tree_node(mlv->vg->cmd, "global/thin_check_options"))) { + for (cv = cn->v; cv && args < 16; cv = cv->next) { + if (cv->type != DM_CFG_STRING) { + log_error("Invalid string in config file: " + "global/thin_check_options"); + return 0; + } + argv[++args] = cv->v.str; + } + } else { + /* Use default options (no support for options with spaces) */ + if (!(split = dm_pool_strdup(data->dm->mem, DEFAULT_THIN_CHECK_OPTIONS))) { + log_error("Failed to duplicate thin check string."); + return 0; + } + args = dm_split_words(split, 16, 0, (char**) argv + 1); } - args = dm_split_words(split, 16, 0, argv); - if (args == 16) { log_error("Too many options for thin check command."); return 0; } - argv[args++] = meta_path; - argv[args] = NULL; + + argv[0] = thin_check; + argv[++args] = meta_path; + argv[++args] = NULL; if (!(ret = exec_cmd(data->pool_lv->vg->cmd, (const char * const *)argv, &status, 0))) { @@ -1262,7 +1278,7 @@ static int _thin_pool_callback(struct dm_tree_node *node, */ } - dm_pool_free(data->dm->mem, split); + dm_pool_free(data->dm->mem, dm_name); return ret; } diff --git a/lib/config/defaults.h b/lib/config/defaults.h index 4eb2f485c..bee3d5632 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -64,7 +64,7 @@ #define DEFAULT_DMEVENTD_MONITOR 1 #define DEFAULT_BACKGROUND_POLLING 1 -#define DEFAULT_THIN_CHECK_EXECUTABLE "/sbin/thin_check -q" +#define DEFAULT_THIN_CHECK_OPTIONS "-q" #define DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS 0 #define DEFAULT_THIN_POOL_MAX_METADATA_SIZE (16 * 1024 * 1024) /* KB */ #define DEFAULT_THIN_POOL_MIN_METADATA_SIZE 2048 /* KB */ -- 2.43.5