summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2017-10-31 20:51:11 +0100
committerZdenek Kabelac <zkabelac@redhat.com>2017-11-01 00:55:24 +0100
commit0ba393954296ee9521fffc83fbf4507060f08ffd (patch)
treecf7258b800b92348b0283a2082c2450f752d7bb0
parentbc29785d098ea0d663a07705e07eac27522c164d (diff)
downloadlvm2-0ba393954296ee9521fffc83fbf4507060f08ffd.tar.gz
pvmove: simplify name generation
-rw-r--r--tools/pvmove.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/tools/pvmove.c b/tools/pvmove.c
index 09ce54bc8..aa06d0224 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -154,8 +154,8 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
const char *lv_name,
struct dm_list *trim_list)
{
- char *idx, *suffix, *sublv_name;
- size_t len;
+ char *idx, *suffix;
+ char sublv_name[NAME_LEN];
struct logical_volume *sublv;
struct dm_list untrim_list, *pvh1, *pvh2;
struct pv_list *pvl1, *pvl2;
@@ -172,18 +172,18 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
if (!(suffix = first_substring(lv_name, "_rimage_", "_rmeta_", NULL)))
return 0;
- if (!(idx = strstr(suffix + 1, "_")))
+ if (!(idx = strchr(suffix + 1, '_'))) {
+ log_error("Can't find '_' after suffix %s.", suffix);
return 0;
+ }
idx++;
- /* + 2 for the longer rimage string */
- if (!(sublv_name = dm_pool_alloc(lv->vg->cmd->mem, strlen(lv_name + 2))))
- return_0;
-
/* Create the siblings name (e.g. "raidlv_rmeta_N" -> "raidlv_rimage_N" */
- len = suffix - lv_name;
- strncpy(sublv_name, lv_name, len);
- sprintf(sublv_name + len, strstr(suffix, "_rimage_") ? "_rmeta_%s" : "_rimage_%s", idx);
+ if (dm_snprintf(sublv_name, sizeof(sublv_name), "%s_r%s_%s", lv_name,
+ strstr(suffix, "_rimage_") ? "meta" : "image", idx) < 0) {
+ log_error("Raid sublv for name %s too long.", lv_name);
+ return 0;
+ }
if (!(sublv = find_lv(lv->vg, sublv_name))) {
log_error("Can't find sub LV %s?", sublv_name);