master - testsuite: Fix problem when checking RAID4/5/6 for mismatches.
by Jonathan Brassow
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9e8dec2f387d8eaf481...
Commit: 9e8dec2f387d8eaf48195ef38ab7699d4a8385ed
Parent: 50130328450d1f624d30438ca835d40e0d4f942d
Author: Jonathan Brassow <jbrassow(a)redhat.com>
AuthorDate: Thu Nov 2 09:49:35 2017 -0500
Committer: Jonathan Brassow <jbrassow(a)redhat.com>
CommitterDate: Thu Nov 2 09:49:35 2017 -0500
testsuite: Fix problem when checking RAID4/5/6 for mismatches.
The lvchange-raid[456].sh test checks that mismatches can be detected
properly. It does this by writing garbage to the back half of one of
the legs directly. When performing a "check" or "repair" of mismatches,
MD does a good job going directly to disk and bypassing any buffers that
may prevent it from seeing mismatches. However, in the case of RAID4/5/6
we have the stripe cache to contend with and this is not bypassed. Thus,
mismatches which have /just/ happened to an area that now populates the
stripe cache may be overlooked. This isn't a serious issue, however,
because the stripe cache is short-lived and reasonably small. So, while
there may be a small window of time between the disk changing underneath
the RAID array and when you run a "check"/"repair" - causing a mismatch
to be missed - that would be no worse than if a user had simply run a
"check" a few seconds before the disk changed. IOW, it simply isn't worth
making a fuss over dropping the stripe cache before beginning a "check" or
"repair" (which we actually did attempt to do a while back).
So, to get the test running smoothly, we simply deactivate and reactivate
the LV to force the stripe cache to be dropped and then proceed. We could
just as easily wait a few seconds for the stripe cache to empty also.
---
test/shell/lvchange-raid.sh | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/test/shell/lvchange-raid.sh b/test/shell/lvchange-raid.sh
index 8c22481..604b7f7 100644
--- a/test/shell/lvchange-raid.sh
+++ b/test/shell/lvchange-raid.sh
@@ -43,6 +43,9 @@ run_writemostly_check() {
printf "#\n#\n#\n# %s/%s (%s): run_writemostly_check\n#\n#\n#\n" \
$vg $lv $segtype
+
+ # I've seen this sync fail. when it does, it looks like sync
+ # thread has not been started... haven't repo'ed yet.
aux wait_for_sync $vg $lv
# No writemostly flag should be there yet.
@@ -169,6 +172,14 @@ run_syncaction_check() {
dd if=/dev/urandom of="$device" bs=1k count=$size seek=$seek
sync
+ # Cycle the LV so we don't grab stripe cache buffers instead
+ # of reading disk. This can happen with RAID 4/5/6. You
+ # may think this is bad because those buffers could prevent
+ # us from seeing bad disk blocks, however, the stripe cache
+ # is not long lived. (RAID1/10 are immediately checked.)
+ lvchange -an $vg/$lv
+ lvchange -ay $vg/$lv
+
# "check" should find discrepancies but not change them
# 'lvs' should show results
lvchange --syncaction check $vg/$lv
6 years, 5 months
master - testsuite: Add and document a 'should' for "idle" -> "recover" RAID test
by Jonathan Brassow
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=50130328450d1f624d3...
Commit: 50130328450d1f624d30438ca835d40e0d4f942d
Parent: 58b763c99cb7620b1cc2313a9f0dccd98def53db
Author: Jonathan Brassow <jbrassow(a)redhat.com>
AuthorDate: Thu Nov 2 08:53:48 2017 -0500
Committer: Jonathan Brassow <jbrassow(a)redhat.com>
CommitterDate: Thu Nov 2 08:53:48 2017 -0500
testsuite: Add and document a 'should' for "idle" -> "recover" RAID test
When a "recover" is just starting for a RAID LV, it is possible to get
"idle" for the sync action if the status is issued quickly enough. This
is fine, the MD thread just hasn't gotten things going yet. However,
the /need/ for a "recover" should be marked in md->recovery and it would
be simple enough to fix the kernel so this doesn't happen. May eventually
want a separate bug for this, but for now it fits with RHBZ 1507719.
---
test/shell/lvconvert-raid-status-validation.sh | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/test/shell/lvconvert-raid-status-validation.sh b/test/shell/lvconvert-raid-status-validation.sh
index 9ffaaf3..3e91d23 100644
--- a/test/shell/lvconvert-raid-status-validation.sh
+++ b/test/shell/lvconvert-raid-status-validation.sh
@@ -83,7 +83,12 @@ while true; do
# If the sync operation ("recover" in this case) is not
# finished, then it better be as follows:
[ "${a[5]}" = "Aa" ]
- [ "${a[7]}" = "recover" ]
+
+ # Might be transitioning from "idle" to "recover".
+ # Kernel could check mddev->recovery for the intent to
+ # begin a "recover" and report that... probably would be
+ # better. RHBZ 1507719
+ should [ "${a[7]}" = "recover" ]
else
# Tough to tell the INVALID case,
# Before starting sync thread: "Aa X/X recover"
6 years, 5 months
master - systemd: remove Install sections from socket-activated services
by Peter Rajnoha
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=58b763c99cb7620b1cc...
Commit: 58b763c99cb7620b1cc2313a9f0dccd98def53db
Parent: 7a394575fbb11aad1ad61f4caa8f16584ae45102
Author: Bastian Blank <waldi(a)debian.org>
AuthorDate: Wed Nov 1 15:25:54 2017 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 1 15:37:19 2017 +0100
systemd: remove Install sections from socket-activated services
We always preferred and recommended socket activation for our services
so remove the Install section in related .service units which are unused
in this case and keep only the Install section in associated .socket
units.
Signed-off-by: Bastian Blank <waldi(a)debian.org>
---
WHATS_NEW | 1 +
WHATS_NEW_DM | 1 +
scripts/dm_event_systemd_red_hat.service.in | 3 ---
scripts/lvm2_lvmetad_systemd_red_hat.service.in | 3 ---
scripts/lvm2_lvmpolld_systemd_red_hat.service.in | 3 ---
5 files changed, 2 insertions(+), 9 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index ab4f656..ac4053a 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.176 -
===================================
+ Keep Install section only in lvm2-{lvmetad,lvmpolld}.socket systemd unit.
liblvm: Fix segfault in lvm_pv_remove. (2.02.173)
Do not allow storing VG metadata with LV without any segment.
Fix printed message when thin snapshot was already merged.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 6475fbd..12cd7f8 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.145 -
===================================
+ Keep Install section only in dm-event.socket systemd unit.
Issue a specific error with dmsetup status if device is unknown.
Fix RT_LIBS reference in generated libdevmapper.pc for pkg-config
diff --git a/scripts/dm_event_systemd_red_hat.service.in b/scripts/dm_event_systemd_red_hat.service.in
index de9aa52..d2c4cf1 100644
--- a/scripts/dm_event_systemd_red_hat.service.in
+++ b/scripts/dm_event_systemd_red_hat.service.in
@@ -13,6 +13,3 @@ ExecStart=@SBINDIR@/dmeventd -f
Environment=SD_ACTIVATION=1
PIDFile=@DMEVENTD_PIDFILE@
OOMScoreAdjust=-1000
-
-[Install]
-WantedBy=sysinit.target
diff --git a/scripts/lvm2_lvmetad_systemd_red_hat.service.in b/scripts/lvm2_lvmetad_systemd_red_hat.service.in
index af34d82..92e6d69 100644
--- a/scripts/lvm2_lvmetad_systemd_red_hat.service.in
+++ b/scripts/lvm2_lvmetad_systemd_red_hat.service.in
@@ -13,6 +13,3 @@ ExecStart=@SBINDIR@/lvmetad -f
Environment=SD_ACTIVATION=1
Restart=on-abort
PIDFile=@LVMETAD_PIDFILE@
-
-[Install]
-WantedBy=sysinit.target
diff --git a/scripts/lvm2_lvmpolld_systemd_red_hat.service.in b/scripts/lvm2_lvmpolld_systemd_red_hat.service.in
index 66fbd91..4ad4e61 100644
--- a/scripts/lvm2_lvmpolld_systemd_red_hat.service.in
+++ b/scripts/lvm2_lvmpolld_systemd_red_hat.service.in
@@ -12,6 +12,3 @@ NonBlocking=true
ExecStart=@SBINDIR@/lvmpolld -t 60 -f
Environment=SD_ACTIVATION=1
PIDFile=@LVMPOLLD_PIDFILE@
-
-[Install]
-WantedBy=sysinit.target
6 years, 5 months
master - cleanup: use segtype_is_raid_with_meta
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7a394575fbb11aad1ad...
Commit: 7a394575fbb11aad1ad61f4caa8f16584ae45102
Parent: 7a28b243faf4fc57466beb138fe1017608bfa7b2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 31 23:16:13 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Nov 1 00:59:22 2017 +0100
cleanup: use segtype_is_raid_with_meta
Replace with common macro.
---
lib/metadata/lv_manip.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index c4c2fdf..41b52ec 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -941,8 +941,7 @@ struct lv_segment *alloc_lv_segment(const struct segment_type *segtype,
return_NULL;
}
- if (segtype_is_raid(segtype) &&
- !segtype_is_raid0(segtype) &&
+ if (segtype_is_raid_with_meta(segtype) &&
!(seg->meta_areas = dm_pool_zalloc(mem, areas_sz))) {
dm_pool_free(mem, seg); /* frees everything alloced since seg */
return_NULL;
@@ -3923,7 +3922,7 @@ static int _lv_insert_empty_sublvs(struct logical_volume *lv,
return_0;
/* Metadata LVs for raid */
- if (segtype_is_raid(segtype) && !segtype_is_raid0(segtype)) {
+ if (segtype_is_raid_with_meta(segtype)) {
if (dm_snprintf(img_name, sizeof(img_name), "%s_rmeta_%u",
lv->name, i) < 0)
goto_bad;
@@ -4144,7 +4143,7 @@ int lv_extend(struct logical_volume *lv,
else if (segtype_is_raid0_meta(segtype))
/* Extend raid0 metadata LVs too */
log_count = stripes;
- else if (segtype_is_raid(segtype) && !segtype_is_raid0(segtype))
+ else if (segtype_is_raid_with_meta(segtype))
log_count = mirrors * stripes;
}
/* FIXME log_count should be 1 for mirrors */
@@ -4171,7 +4170,7 @@ int lv_extend(struct logical_volume *lv,
return_0;
new_extents = ah->new_extents;
- if (segtype_is_raid(segtype) && !segtype_is_raid0(segtype))
+ if (segtype_is_raid_with_meta(segtype))
new_extents -= ah->log_len * ah->area_multiple;
if (segtype_is_pool(segtype)) {
6 years, 5 months
master - cleanup: pvmove messages
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7a28b243faf4fc57466...
Commit: 7a28b243faf4fc57466beb138fe1017608bfa7b2
Parent: 373372c8ab3749bc76ced37cec04b00aae6e5979
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 31 20:50:51 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Nov 1 00:58:31 2017 +0100
cleanup: pvmove messages
Just add some dots to messages and remove unneeded
stack trace from return after log_error.
---
tools/pvmove.c | 58 ++++++++++++++++++++++++++++---------------------------
1 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/tools/pvmove.c b/tools/pvmove.c
index aa06d02..0f54a50 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -88,18 +88,18 @@ static const char *_extract_lvname(struct cmd_context *cmd, const char *vgname,
while (*lvname == '/')
lvname++;
if (!strchr(lvname, '/')) {
- log_error("--name takes a logical volume name");
+ log_error("--name takes a logical volume name.");
return NULL;
}
if (strncmp(vgname, lvname, strlen(vgname)) ||
(lvname += strlen(vgname), *lvname != '/')) {
- log_error("Named LV and old PV must be in the same VG");
+ log_error("Named LV and old PV must be in the same VG.");
return NULL;
}
while (*lvname == '/')
lvname++;
if (!*lvname) {
- log_error("Incomplete LV name supplied with --name");
+ log_error("Incomplete LV name supplied with --name.");
return NULL;
}
return lvname;
@@ -137,7 +137,7 @@ static struct dm_list *_get_allocatable_pvs(struct cmd_context *cmd, int argc,
}
if (dm_list_empty(allocatable_pvs)) {
- log_error("No extents available for allocation");
+ log_error("No extents available for allocation.");
return NULL;
}
@@ -169,8 +169,10 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
dm_list_init(&untrim_list);
- if (!(suffix = first_substring(lv_name, "_rimage_", "_rmeta_", NULL)))
+ if (!(suffix = first_substring(lv_name, "_rimage_", "_rmeta_", NULL))) {
+ log_error("Can't find rimage or rmeta suffix.");
return 0;
+ }
if (!(idx = strchr(suffix + 1, '_'))) {
log_error("Can't find '_' after suffix %s.", suffix);
@@ -186,12 +188,12 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
}
if (!(sublv = find_lv(lv->vg, sublv_name))) {
- log_error("Can't find sub LV %s?", sublv_name);
+ log_error("Can't find sub LV %s.", sublv_name);
return 0;
}
if (!get_pv_list_for_lv(lv->vg->cmd->mem, sublv, &untrim_list)) {
- log_error("Can't find PVs for sub LV %s?", sublv_name);
+ log_error("Can't find PVs for sub LV %s.", sublv_name);
return 0;
}
@@ -202,7 +204,7 @@ static int _remove_sibling_pvs_from_trim_list(struct logical_volume *lv,
pvl2 = dm_list_item(pvh2, struct pv_list);
if (pvl1->pv == pvl2->pv) {
- log_debug("Removing PV %s from trim list",
+ log_debug("Removing PV %s from trim list.",
pvl2->pv->dev->pvid);
dm_list_del(&pvl2->list);
break;
@@ -230,7 +232,7 @@ static int _trim_allocatable_pvs(struct dm_list *alloc_list,
struct pv_list *pvl, *trim_pvl;
if (!alloc_list) {
- log_error(INTERNAL_ERROR "alloc_list is NULL");
+ log_error(INTERNAL_ERROR "alloc_list is NULL.");
return 0;
}
@@ -280,9 +282,9 @@ static int _insert_pvmove_mirrors(struct cmd_context *cmd,
if (lv_mirr->le_count - prev_le_count) {
lv->status |= LOCKED;
- log_verbose("Moving %u extents of logical volume %s/%s",
+ log_verbose("Moving %u extents of logical volume %s.",
lv_mirr->le_count - prev_le_count,
- lv->vg->name, lv->name);
+ display_lvname(lv));
}
return 1;
@@ -361,14 +363,14 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
if (!(lv_mirr = lv_create_empty("pvmove%d", NULL,
LVM_READ | LVM_WRITE,
ALLOC_CONTIGUOUS, vg))) {
- log_error("Creation of temporary pvmove LV failed");
+ log_error("Creation of temporary pvmove LV failed.");
return NULL;
}
lv_mirr->status |= (PVMOVE | LOCKED);
if (!(*lvs_changed = dm_pool_alloc(cmd->mem, sizeof(**lvs_changed)))) {
- log_error("lvs_changed list struct allocation failed");
+ log_error("lvs_changed list struct allocation failed.");
return NULL;
}
@@ -410,7 +412,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
continue;
if (lv_is_converting(lv) || lv_is_merging(lv)) {
- log_error("Unable to pvmove when %s volumes are present",
+ log_error("Unable to pvmove when %s volumes are present.",
lv_is_converting(lv) ?
"converting" : "merging");
return NULL;
@@ -460,7 +462,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
continue;
if (lv_is_cache_type(lv)) {
- log_print_unless_silent("Skipping %s LV, %s",
+ log_print_unless_silent("Skipping %s LV, %s.",
lv_is_cache(lv) ? "cache" :
lv_is_cache_pool(lv) ?
"cache-pool" : "cache-related",
@@ -471,7 +473,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
if (_parent_lv_is_cache_type(lv)) {
log_print_unless_silent("Skipping %s because a parent"
- " is of cache type", lv->name);
+ " is of cache type.", lv->name);
lv_skipped = 1;
continue;
}
@@ -483,7 +485,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
if ((vg_is_clustered(vg) || is_lockd_type(vg->lock_type)) &&
(lv_is_origin(lv) || lv_is_cow(lv) ||
lv_is_thin_type(lv) || lv_is_raid_type(lv))) {
- log_print_unless_silent("Skipping %s LV %s",
+ log_print_unless_silent("Skipping %s LV %s.",
lv_is_origin(lv) ? "origin" :
lv_is_cow(lv) ?
"snapshot-related" :
@@ -513,7 +515,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
if (lv_is_locked(lv)) {
lv_skipped = 1;
- log_print_unless_silent("Skipping locked LV %s", lv->name);
+ log_print_unless_silent("Skipping locked LV %s.", lv->name);
continue;
}
@@ -549,7 +551,7 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
log_error("All data on source PV skipped. "
"It contains locked, hidden or "
"non-top level LVs only.");
- log_error("No data to move for %s", vg->name);
+ log_error("No data to move for %s.", vg->name);
return NULL;
}
@@ -576,13 +578,13 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
allocatable_pvs, alloc,
(arg_is_set(cmd, atomic_ARG)) ?
MIRROR_BY_SEGMENTED_LV : MIRROR_BY_SEG)) {
- log_error("Failed to convert pvmove LV to mirrored");
- return_NULL;
+ log_error("Failed to convert pvmove LV to mirrored.");
+ return NULL;
}
if (!split_parent_segments_for_layer(cmd, lv_mirr)) {
- log_error("Failed to split segments being moved");
- return_NULL;
+ log_error("Failed to split segments being moved.");
+ return NULL;
}
return lv_mirr;
@@ -710,7 +712,7 @@ static int _pvmove_setup_single(struct cmd_context *cmd,
}
if (!validate_name(lv_name)) {
- log_error("Logical volume name %s is invalid", lv_name);
+ log_error("Logical volume name %s is invalid.", lv_name);
pp->setup_result = EINVALID_CMD_LINE;
return ECMD_FAILED;
}
@@ -746,12 +748,12 @@ static int _pvmove_setup_single(struct cmd_context *cmd,
exclusive = _pvmove_is_exclusive(cmd, vg);
if ((lv_mirr = find_pvmove_lv(vg, pv_dev(pv), PVMOVE))) {
- log_print_unless_silent("Detected pvmove in progress for %s", pv_name);
+ log_print_unless_silent("Detected pvmove in progress for %s.", pv_name);
if (pp->pv_count || lv_name)
- log_error("Ignoring remaining command line arguments");
+ log_warn("WARNING: Ignoring remaining command line arguments.");
if (!(lvs_changed = lvs_using_lv(cmd, vg, lv_mirr))) {
- log_error("ABORTING: Failed to generate list of moving LVs");
+ log_error("ABORTING: Failed to generate list of moving LVs.");
goto out;
}
@@ -898,7 +900,7 @@ int pvmove(struct cmd_context *cmd, int argc, char **argv)
/* dm raid1 target must be present in every case */
if (!_pvmove_target_present(cmd, 0)) {
log_error("Required device-mapper target(s) not "
- "detected in your kernel");
+ "detected in your kernel.");
return ECMD_FAILED;
}
6 years, 5 months
master - lv_manip: hide layered LV temporarily
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=373372c8ab3749bc76c...
Commit: 373372c8ab3749bc76ced37cec04b00aae6e5979
Parent: 0ba393954296ee9521fffc83fbf4507060f08ffd
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Nov 1 00:51:39 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Nov 1 00:55:24 2017 +0100
lv_manip: hide layered LV temporarily
Since vg_validate() now rejects LVs without segments and
insert_layer_for_segments_on_pv() gets just created
'layer_lv' without segment, it needs to be hidden
from vg->lvs during processing of _align_segment_boundary_to_pe_range()
as this function calls lv_validate() and now requires
vg to be consistent. LV is then put back into vg->lvs.
---
lib/metadata/lv_manip.c | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index f0e492b..c4c2fdf 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -7054,9 +7054,19 @@ int insert_layer_for_segments_on_pv(struct cmd_context *cmd,
layer_lv->name, lv_where->name,
pvl ? pv_dev_name(pvl->pv) : "any");
+ /* Temporarily hide layer_lv from vg->lvs list
+ * so the lv_split_segment() passes vg_validate()
+ * since here layer_lv has empty segment list */
+ if (!(lvl = find_lv_in_vg(lv_where->vg, layer_lv->name)))
+ return_0;
+ dm_list_del(&lvl->list);
+
if (!_align_segment_boundary_to_pe_range(lv_where, pvl))
return_0;
+ /* Put back layer_lv in vg->lv */
+ dm_list_add(&lv_where->vg->lvs, &lvl->list);
+
/* Work through all segments on the supplied PV */
dm_list_iterate_items(seg, &lv_where->segments) {
for (s = 0; s < seg->area_count; s++) {
6 years, 5 months
master - pvmove: simplify name generation
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0ba393954296ee9521f...
Commit: 0ba393954296ee9521fffc83fbf4507060f08ffd
Parent: bc29785d098ea0d663a07705e07eac27522c164d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 31 20:51:11 2017 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed Nov 1 00:55:24 2017 +0100
pvmove: simplify name generation
---
tools/pvmove.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/tools/pvmove.c b/tools/pvmove.c
index 09ce54b..aa06d02 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);
6 years, 5 months