master - memlock: Make malloc reserve more robust against glibc tricks.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=cf37c04347c6b6...
Commit: cf37c04347c6b6209420764da43127a96445af0e
Parent: 542b03ee007d50cd8aa6dbd582b79369a38919b0
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Sep 30 10:56:59 2014 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Tue Nov 18 03:17:27 2014 +0100
memlock: Make malloc reserve more robust against glibc tricks.
---
lib/mm/memlock.c | 48 ++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/lib/mm/memlock.c b/lib/mm/memlock.c
index 547fb46..e771075 100644
--- a/lib/mm/memlock.c
+++ b/lib/mm/memlock.c
@@ -25,6 +25,7 @@
#include <sys/mman.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <malloc.h>
#ifndef DEVMAPPER_SUPPORT
@@ -133,9 +134,11 @@ static void _touch_memory(void *mem, size_t size)
static void _allocate_memory(void)
{
#ifndef VALGRIND_POOL
- /* With Valgrind don't waste time in with preallocating memory */
void *stack_mem, *temp_malloc_mem;
struct rlimit limit;
+ int i, area = 0, missing = _size_malloc_tmp, max_areas = 32, hblks;
+ char *areas[max_areas];
+
/* Check if we could preallocate requested stack */
if ((getrlimit (RLIMIT_STACK, &limit) == 0) &&
@@ -144,13 +147,50 @@ static void _allocate_memory(void)
_touch_memory(stack_mem, _size_stack);
/* FIXME else warn user setting got ignored */
- if ((temp_malloc_mem = malloc(_size_malloc_tmp)))
- _touch_memory(temp_malloc_mem, _size_malloc_tmp);
+ /*
+ * When a brk() fails due to fragmented address space (which sometimes
+ * happens when we try to grab 8M or so), glibc will make a new
+ * arena. In this arena, the rules for using “direct” mmap are relaxed,
+ * circumventing the MAX_MMAPs and MMAP_THRESHOLD settings. We can,
+ * however, detect when this happens with mallinfo() and try to co-opt
+ * malloc into using MMAP as a MORECORE substitute instead of returning
+ * MMAP'd memory directly. Since MMAP-as-MORECORE does not munmap the
+ * memory on free(), this is good enough for our purposes.
+ */
+ while (missing > 0) {
+ struct mallinfo inf = mallinfo();
+ hblks = inf.hblks;
+
+ if ((areas[area] = malloc(_size_malloc_tmp)))
+ _touch_memory(areas[area], _size_malloc_tmp);
+
+ inf = mallinfo();
+
+ if (hblks < inf.hblks) {
+ /* malloc cheated and used mmap, even though we told it
+ not to; we try with twice as many areas, each half
+ the size, to circumvent the faulty logic in glibc */
+ free(areas[area]);
+ _size_malloc_tmp /= 2;
+ } else {
+ ++ area;
+ missing -= _size_malloc_tmp;
+ }
+
+ if (area == max_areas && missing > 0) {
+ /* Too bad. Warn the user and proceed, as things are
+ * most likely going to work out anyway. */
+ log_warn("WARNING: Failed to reserve memory, %d bytes missing.", missing);
+ break;
+ }
+ }
if ((_malloc_mem = malloc(_size_malloc)))
_touch_memory(_malloc_mem, _size_malloc);
- free(temp_malloc_mem);
+ /* free up the reserves so subsequent malloc's can use that memory */
+ for (i = 0; i < area; ++i)
+ free(areas[i]);
#endif
}
9 years, 5 months
master - tests: deactivate repaired before swap
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=542b03ee007d50...
Commit: 542b03ee007d50cd8aa6dbd582b79369a38919b0
Parent: 740fcdae7d44ae2398ea427f91fc87195e449d42
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 17 08:44:53 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 17 08:44:53 2014 +0100
tests: deactivate repaired before swap
---
test/shell/lvconvert-repair-thin.sh | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/test/shell/lvconvert-repair-thin.sh b/test/shell/lvconvert-repair-thin.sh
index 4732efc..8e35ad1 100644
--- a/test/shell/lvconvert-repair-thin.sh
+++ b/test/shell/lvconvert-repair-thin.sh
@@ -70,6 +70,8 @@ not "$LVM_TEST_THIN_DUMP_CMD" "$DM_DEV_DIR/$vg/repair" | tee dump
"$LVM_TEST_THIN_CHECK_CMD" "$DM_DEV_DIR/$vg/fixed"
+lvchange -an $vg
+
# Swap repaired metadata back
lvconvert -y -f --poolmetadata $vg/fixed --thinpool $vg/pool
9 years, 5 months
master - tests: thin repair testing
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=740fcdae7d44ae...
Commit: 740fcdae7d44ae2398ea427f91fc87195e449d42
Parent: 3a1c609ac49852b50d45a4dd292a61b7cbb9c25f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 17 00:41:33 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 17 00:41:33 2014 +0100
tests: thin repair testing
More checks for thin related tools.
Add same functionality for cache related tools.
---
test/Makefile.in | 17 ++++++++
test/api/thin_percent.sh | 3 -
test/lib/aux.sh | 59 +++++++++++++++++++-------
test/shell/lvconvert-repair-thin.sh | 77 +++++++++++++----------------------
4 files changed, 89 insertions(+), 67 deletions(-)
diff --git a/test/Makefile.in b/test/Makefile.in
index 9774f6c..1aec88b 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -30,6 +30,11 @@ export LVM_TEST_THIN_DUMP_CMD?=@THIN_DUMP_CMD@
export LVM_TEST_THIN_REPAIR_CMD?=@THIN_REPAIR_CMD@
export LVM_TEST_THIN_RESTORE_CMD?=@THIN_RESTORE_CMD@
+export LVM_TEST_CACHE_CHECK_CMD?=@CACHE_CHECK_CMD@
+export LVM_TEST_CACHE_DUMP_CMD?=@CACHE_DUMP_CMD@
+export LVM_TEST_CACHE_REPAIR_CMD?=@CACHE_REPAIR_CMD@
+export LVM_TEST_CACHE_RESTORE_CMD?=@CACHE_RESTORE_CMD@
+
SUBDIRS = api unit
SOURCES = lib/not.c lib/harness.c
@@ -79,6 +84,10 @@ help:
@echo " LVM_TEST_THIN_DUMP_CMD Command for thin_dump [$(LVM_TEST_THIN_DUMP_CMD)]."
@echo " LVM_TEST_THIN_REPAIR_CMD Command for thin_repair [$(LVM_TEST_THIN_REPAIR_CMD)]."
@echo " LVM_TEST_THIN_RESTORE_CMD Command for thin_restore [$(LVM_TEST_THIN_RESTORE_CMD)]."
+ @echo " LVM_TEST_CACHE_CHECK_CMD Command for cache_check [$(LVM_TEST_CACHE_CHECK_CMD)]."
+ @echo " LVM_TEST_CACHE_DUMP_CMD Command for cache_dump [$(LVM_TEST_CACHE_DUMP_CMD)]."
+ @echo " LVM_TEST_CACHE_REPAIR_CMD Command for cache_repair [$(LVM_TEST_CACHE_REPAIR_CMD)]."
+ @echo " LVM_TEST_CACHE_RESTORE_CMD Command for cache_restore [$(LVM_TEST_CACHE_RESTORE_CMD)]."
@echo " LVM_TEST_UNLIMITED Set to get unlimited test log (>32MB)"
@echo " LVM_VALGRIND Enable valgrind testing (1,2,3) execs $$"VALGRIND
@echo " LVM_VALGRIND_CLVMD Enable valgrind testing of clvmd (1)."
@@ -153,6 +162,14 @@ lib/paths: $(srcdir)/Makefile.in .lib-dir-stamp Makefile
echo 'export LVMETAD_PIDFILE="@LVMETAD_PIDFILE@"' >> $@-t
echo 'export DMEVENTD_PIDFILE="@DMEVENTD_PIDFILE@"' >> $@-t
echo 'export CLVMD_PIDFILE="@CLVMD_PIDFILE@"' >> $@-t
+ echo 'export LVM_TEST_THIN_CHECK_CMD=$${LVM_TEST_THIN_CHECK_CMD:-@THIN_CHECK_CMD@}' >> $@-t
+ echo 'export LVM_TEST_THIN_DUMP_CMD=$${LVM_TEST_THIN_DUMP_CMD:-@THIN_DUMP_CMD@}' >> $@-t
+ echo 'export LVM_TEST_THIN_REPAIR_CMD=$${LVM_TEST_THIN_REPAIR_CMD:-@THIN_REPAIR_CMD@}' >> $@-t
+ echo 'export LVM_TEST_THIN_RESTORE_CMD=$${LVM_TEST_THIN_RESTORE_CMD:-@THIN_RESTORE_CMD@}' >> $@-t
+ echo 'export LVM_TEST_CACHE_CHECK_CMD=$${LVM_TEST_CACHE_CHECK_CMD:-@CACHE_CHECK_CMD@}' >> $@-t
+ echo 'export LVM_TEST_CACHE_DUMP_CMD=$${LVM_TEST_CACHE_DUMP_CMD:-@CACHE_DUMP_CMD@}' >> $@-t
+ echo 'export LVM_TEST_CACHE_REPAIR_CMD=$${LVM_TEST_CACHE_REPAIR_CMD:-@CACHE_REPAIR_CMD@}' >> $@-t
+ echo 'export LVM_TEST_CACHE_RESTORE_CMD=$${LVM_TEST_CACHE_RESTORE_CMD:-@CACHE_RESTORE_CMD@}' >> $@-t
mv $@-t $@
LIB = lib/not lib/invalid lib/fail lib/should lib/harness \
diff --git a/test/api/thin_percent.sh b/test/api/thin_percent.sh
index 5335655..f93bd15 100644
--- a/test/api/thin_percent.sh
+++ b/test/api/thin_percent.sh
@@ -15,9 +15,6 @@
aux have_thin 1 0 0 || skip
-# disable thin_check if not present in system
-which thin_check || aux lvmconf 'global/thin_check_executable = ""'
-
aux prepare_devs 2
vgcreate -s 64k $vg $(cat DEVICES)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 8da834c..58b71c6 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -767,6 +767,27 @@ can_use_16T() {
test "$(getconf LONG_BIT)" -eq 64
}
+# Check if major.minor.revision' string is 'at_least'
+version_at_least() {
+ local major
+ local minor
+ local revision
+ IFS=. read -r major minor revision <<< "$1"
+ shift
+
+ test -z "$1" && return 0
+ test -n "$major" || return 1
+ test "$major" -gt "$1" && return 0
+ test "$major" -eq "$1" || return 1
+
+ test -z "$2" && return 0
+ test -n "$minor" || return 1
+ test "$minor" -gt "$2" && return 0
+ test "$minor" -eq "$2" || return 1
+
+ test -z "$3" && return 0
+ test "$revision" -ge "$3" 2>/dev/null || return 1
+}
#
# Check wheter kernel [dm module] target exist
# at least in expected version
@@ -790,21 +811,7 @@ target_at_least() {
version=${version##* v}
shift
- local major=$(echo "$version" | cut -d. -f1)
- test -z "$1" && return 0
- test -n "$major" || return 1
- test "$major" -gt "$1" && return 0
- test "$major" -eq "$1" || return 1
-
- test -z "$2" && return 0
- local minor=$(echo "$version" | cut -d. -f2)
- test -n "$minor" || return 1
- test "$minor" -gt "$2" && return 0
- test "$minor" -eq "$2" || return 1
-
- test -z "$3" && return 0
- local revision=$(echo "$version" | cut -d. -f3)
- test "$revision" -ge "$3" 2>/dev/null || return 1
+ version_at_least "$version" "$@"
}
have_thin() {
@@ -812,7 +819,12 @@ have_thin() {
target_at_least dm-thin-pool "$@" || return 1
# disable thin_check if not present in system
- which thin_check || lvmconf 'global/thin_check_executable = ""'
+ test -x "$LVM_TEST_THIN_CHECK_CMD" || LVM_TEST_THIN_CHECK_CMD=""
+ test -x "$LVM_TEST_THIN_DUMP_CMD" || LVM_TEST_THIN_DUMP_CMD=""
+ test -x "$LVM_TEST_THIN_REPAIR_CMD" || LVM_TEST_THIN_REPAIR_CMD=""
+ lvmconf "global/thin_check_executable = \"$LVM_TEST_THIN_CHECK_CMD\"" \
+ "global/thin_dump_executable = \"$LVM_TEST_THIN_DUMP_CMD\"" \
+ "global/thin_repair_executable = \"$LVM_TEST_THIN_REPAIR_CMD\""
}
have_raid() {
@@ -823,6 +835,21 @@ have_raid() {
have_cache() {
test "$CACHE" = shared -o "$CACHE" = internal || return 1
target_at_least dm-cache "$@"
+
+ test -x "$LVM_TEST_CACHE_CHECK_CMD" || LVM_TEST_CACHE_CHECK_CMD=""
+ test -x "$LVM_TEST_CACHE_DUMP_CMD" || LVM_TEST_CACHE_DUMP_CMD=""
+ test -x "$LVM_TEST_CACHE_REPAIR_CMD" || LVM_TEST_CACHE_REPAIR_CMD=""
+ lvmconf "global/cache_check_executable = \"$LVM_TEST_CACHE_CHECK_CMD\"" \
+ "global/cache_dump_executable = \"$LVM_TEST_CACHE_DUMP_CMD\"" \
+ "global/cache_repair_executable = \"$LVM_TEST_CACHE_REPAIR_CMD\""
+}
+
+have_tool_at_least() {
+ local version=$($1 -V 2>/dev/null)
+ version=${version%%-*}
+ shift
+
+ version_at_least "$version" "$@"
}
# check if lvm shell is build-in (needs readline)
diff --git a/test/shell/lvconvert-repair-thin.sh b/test/shell/lvconvert-repair-thin.sh
index 6aa5590..4732efc 100644
--- a/test/shell/lvconvert-repair-thin.sh
+++ b/test/shell/lvconvert-repair-thin.sh
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2013-2014 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
@@ -16,13 +16,6 @@
which mkfs.ext2 || skip
-# By default use tools from configuration (exported through Makefile)
-# Allow user to override location of binaries to take tools from different laces
-# Maybe check also version of the tools here?
-test -n "$LVM_TEST_THIN_CHECK_CMD" || LVM_TEST_THIN_CHECK_CMD=$(which thin_check) || skip
-test -n "$LVM_TEST_THIN_DUMP_CMD" || LVM_TEST_THIN_DUMP_CMD=$(which thin_dump) || skip
-test -n "$LVM_TEST_THIN_REPAIR_CMD" || LVM_TEST_THIN_REPAIR_CMD=$(which thin_repair) || skip
-
#
# Main
#
@@ -43,73 +36,61 @@ lvcreate -L2 -n fixed $vg
lvs -a -o+seg_pe_ranges $vg
#aux error_dev "$dev2" 2050:1
-# Make some repairable metadata damage??
vgchange -an $vg
lvconvert --repair $vg/pool
lvs -a $vg
+# Manual repair steps:
# Test swapping - swap out thin-pool's metadata with our repair volume
lvconvert -y -f --poolmetadata $vg/repair --thinpool $vg/pool
-lvchange -aey $vg/repair $vg/fixed
+#
+# To continue this test - we need real tools available
+# When they are not present mark test as skipped, but still
+# let proceed initial part which should work even without tools
+#
+aux have_tool_at_least "$LVM_TEST_THIN_CHECK_CMD" 0 3 1 || skip
+aux have_tool_at_least "$LVM_TEST_THIN_DUMP_CMD" 0 3 1 || skip
+aux have_tool_at_least "$LVM_TEST_THIN_REPAIR_CMD" 0 3 1 || skip
-#dd if="$DM_DEV_DIR/$vg/repair" of=back bs=1M
+lvchange -aey $vg/repair $vg/fixed
# Make some 'repairable' damage??
dd if=/dev/zero of="$DM_DEV_DIR/$vg/repair" bs=1 seek=40960 count=1
-#dd if="$DM_DEV_DIR/$vg/repair" of=back_trashed bs=1M
-#not vgchange -ay $vg
-
-#lvconvert --repair $vg/pool
-
-# Using now SHOULD - since thin tools currently do not seem to work
-should not "$THIN_CHECK" "$DM_DEV_DIR/$vg/repair"
+not "$LVM_TEST_THIN_CHECK_CMD" "$DM_DEV_DIR/$vg/repair"
-should not "$LVM_TEST_THIN_DUMP_CMD" "$DM_DEV_DIR/$vg/repair" | tee dump
+not "$LVM_TEST_THIN_DUMP_CMD" "$DM_DEV_DIR/$vg/repair" | tee dump
-should "$LVM_TEST_THIN_REPAIR_CMD" -i "$DM_DEV_DIR/$vg/repair" -o "$DM_DEV_DIR/$vg/fixed"
+"$LVM_TEST_THIN_REPAIR_CMD" -i "$DM_DEV_DIR/$vg/repair" -o "$DM_DEV_DIR/$vg/fixed"
-should "$LVM_TEST_THIN_DUMP_CMD" --repair "$DM_DEV_DIR/$vg/repair" | tee repaired_xml
+"$LVM_TEST_THIN_DUMP_CMD" --repair "$DM_DEV_DIR/$vg/repair" | tee repaired_xml
-should "$LVM_TEST_THIN_CHECK_CMD" "$DM_DEV_DIR/$vg/fixed"
+"$LVM_TEST_THIN_CHECK_CMD" "$DM_DEV_DIR/$vg/fixed"
# Swap repaired metadata back
lvconvert -y -f --poolmetadata $vg/fixed --thinpool $vg/pool
# Activate pool - this should now work
-should vgchange -ay $vg
+vgchange -ay $vg
-lvs -a -o+devices $vg
-dmsetup table
-dmsetup info -c
-dmsetup ls --tree
-
-lvchange -an $vg
-
-# FIXME: Currently in deep troubles - we can't remove thin volume from broken pool
-should lvremove -ff $vg
+vgchange -an $vg
-# let's not block PVs with openned _tdata/_tmeta devices
-aux dmsetup remove $vg-pool_tdata || true
-aux dmsetup remove $vg-pool_tmeta || true
+# Put back 'broken' metadata
+lvconvert -y -f --poolmetadata $vg/repair --thinpool $vg/pool
-dmsetup table
+# Check --repair usage
+lvconvert -v --repair $vg/pool
-# FIXME: needs also --yes with double force
-pvremove --yes -ff "$dev1"
-pvremove --yes -ff "$dev2"
+# Check repaired pool could be activated
+lvchange -ay $vg/pool
-# FIXME: pv1 & pv2 are removed so pv3 & pv4 have no real LVs,
-# yet vgremove is refusing to do its jobs and suggest --partial??
-should vgremove -ff $vg
+lvchange -an $vg
-# FIXME: stressing even more - there are no pool PV, we do not pass...
-should vgreduce --removemissing -f $vg
-should vgremove -ff $vg
+# Restore damaged metadata
+lvconvert -y -f --poolmetadata $vg/pool_meta1 --thinpool $vg/pool
-# Let's do a final forced cleanup
-pvremove --yes -ff "$dev3"
-pvremove --yes -ff "$dev4"
+# Check lvremove -ff works even with damaged pool
+lvremove -ff $vg
9 years, 5 months
master - tests: reduce number of sync waiting
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3a1c609ac49852...
Commit: 3a1c609ac49852b50d45a4dd292a61b7cbb9c25f
Parent: 776934aa0811727405434698ab25b2c1e7722fa6
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 17 00:34:44 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 17 00:34:44 2014 +0100
tests: reduce number of sync waiting
Lets assume faster systems, if we have too big raid arrays,
reduce them.
---
test/lib/aux.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 1c168f0..8da834c 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -753,7 +753,7 @@ udev_wait() {
# wait_for_sync <VG/LV>
wait_for_sync() {
local i
- for i in {1..3000} ; do
+ for i in {1..100} ; do
check in_sync $1 $2 && return
sleep .2
done
9 years, 5 months
master - tests: skip another older kernel from raid456
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=776934aa081172...
Commit: 776934aa0811727405434698ab25b2c1e7722fa6
Parent: b622a7fe3ffa89e763577c3176a2cc2f1b1e2cdd
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 17 00:32:49 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Nov 17 00:32:49 2014 +0100
tests: skip another older kernel from raid456
---
test/lib/aux.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index dcc86ed..1c168f0 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -733,7 +733,7 @@ raid456_replace_works() {
3.9.*.fc19.i686*|3.9.*.fc19.x86_64) return 1 ;;
3.1[0123].*.fc18.i686*|3.1[0123].*.fc18.x86_64) return 1 ;;
3.1[01234].*.fc19.i686*|3.1[01234].*.fc19.x86_64) return 1 ;;
- 3.13.*.fc20.i686*|3.13.*.fc20.x86_64) return 1 ;;
+ 3.1[123].*.fc20.i686*|3.1[123].*.fc20.x86_64) return 1 ;;
3.14.*.fc21.i686*|3.14.*.fc21.x86_64) return 1 ;;
3.15.*rc6*.fc21.i686*|3.15.*rc6*.fc21.x86_64) return 1 ;;
3.16.*rc4*.fc21.i686*|3.16.*rc4*.fc21.x86_64) return 1 ;;
9 years, 5 months
master - toollib: fixes and cleanup of recent changes
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b622a7fe3ffa89...
Commit: b622a7fe3ffa89e763577c3176a2cc2f1b1e2cdd
Parent: 513105c6aca5f8159b8345e3c252bf1ced40b92f
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Nov 14 15:00:35 2014 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Nov 14 16:58:09 2014 -0600
toollib: fixes and cleanup of recent changes
- Fix problems with recent changes related to skipping in:
. _process_vgnameid_list
. _process_pvs_in_vgs
- Undo unnecessary changes to the code structure and readability.
- Preserve valid but minor changes:
. testing FAILED bit values in ignore_vg
. using "skip" value from ignore_vg instead of "ret" value
. applying the sigint check to the start of all loops
. setting stack backtrace when ECMD_PROCESSED is not returned,
i.e. apply the following pattern:
ret = process_foo();
if (ret != ECMD_PROCESSED)
stack;
if (ret > ret_max)
ret_max = ret;
---
tools/toollib.c | 174 ++++++++++++++++++++++++++++++++++---------------------
1 files changed, 107 insertions(+), 67 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 2b08249..8eb434d 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -157,7 +157,17 @@ const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
}
/*
- * Returns 1 if VG should be ignored.
+ * Three possible results:
+ * a) return 0, skip 0: take the VG, and cmd will end in success
+ * b) return 0, skip 1: skip the VG, and cmd will end in success
+ * c) return 1, skip *: skip the VG, and cmd will end in failure
+ *
+ * Case b is the special case, and includes the following:
+ * . The VG is inconsistent, and the command allows for inconsistent VGs.
+ * . The VG is clustered, the host cannot access clustered VG's,
+ * and the command option has been used to ignore clustered vgs.
+ *
+ * Case c covers the other errors returned when reading the VG.
*/
int ignore_vg(struct volume_group *vg, const char *vg_name, int allow_inconsistent, int *skip)
{
@@ -195,17 +205,24 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
int ret;
struct pv_segment _free_pv_segment = { .pv = pv };
- if (!dm_list_empty(&pv->segments)) {
+ if (dm_list_empty(&pv->segments)) {
+ ret = process_single_pvseg(cmd, NULL, &_free_pv_segment, handle);
+ if (ret != ECMD_PROCESSED)
+ stack;
+ if (ret > ret_max)
+ ret_max = ret;
+ } else {
dm_list_iterate_items(pvseg, &pv->segments) {
if (sigint_caught())
return_ECMD_FAILED;
- if ((ret = process_single_pvseg(cmd, vg, pvseg, handle)) != ECMD_PROCESSED)
+
+ ret = process_single_pvseg(cmd, vg, pvseg, handle);
+ if (ret != ECMD_PROCESSED)
stack;
if (ret > ret_max)
ret_max = ret;
}
- } else if ((ret_max = process_single_pvseg(cmd, NULL, &_free_pv_segment, handle)) != ECMD_PROCESSED)
- stack;
+ }
return ret_max;
}
@@ -220,12 +237,11 @@ int process_each_segment_in_lv(struct cmd_context *cmd,
int ret;
dm_list_iterate_items(seg, &lv->segments) {
- if (sigint_caught()) {
- stack;
- ret_max = ECMD_FAILED;
- break;
- }
- if ((ret = process_single_seg(cmd, seg, handle)) != ECMD_PROCESSED)
+ if (sigint_caught())
+ return_ECMD_FAILED;
+
+ ret = process_single_seg(cmd, seg, handle);
+ if (ret != ECMD_PROCESSED)
stack;
if (ret > ret_max)
ret_max = ret;
@@ -1458,7 +1474,8 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
const char *vg_name;
const char *vg_uuid;
int ret_max = ECMD_PROCESSED;
- int ret, skip;
+ int ret;
+ int skip;
int process_all = 0;
/*
@@ -1473,28 +1490,35 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
vg_name = vgnl->vg_name;
vg_uuid = vgnl->vgid;
+ skip = 0;
vg = vg_read(cmd, vg_name, vg_uuid, flags);
if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &skip)) {
stack;
- ret = ECMD_FAILED;
- } else if (skip)
- ret = ECMD_PROCESSED;
- else {
- /* Process this VG? */
- if (process_all ||
- (!dm_list_empty(arg_vgnames) && str_list_match_item(arg_vgnames, vg_name)) ||
- (!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL))) {
- if ((ret = process_single_vg(cmd, vg_name, vg, handle)) != ECMD_PROCESSED)
- stack;
- } else
- ret = ECMD_PROCESSED;
- unlock_vg(cmd, vg_name);
+ ret_max = ECMD_FAILED;
+ release_vg(vg);
+ continue;
+ }
+ if (skip) {
+ release_vg(vg);
+ continue;
}
- release_vg(vg);
- if (ret > ret_max)
- ret_max = ret;
+ /* Process this VG? */
+ if (process_all ||
+ (!dm_list_empty(arg_vgnames) && str_list_match_item(arg_vgnames, vg_name)) ||
+ (!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL))) {
+ ret = process_single_vg(cmd, vg_name, vg, handle);
+ if (ret != ECMD_PROCESSED)
+ stack;
+ if (ret > ret_max)
+ ret_max = ret;
+ }
+
+ if (vg_read_error(vg))
+ release_vg(vg);
+ else
+ unlock_and_release_vg(cmd, vg, vg_name);
}
return ret_max;
@@ -1659,9 +1683,9 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
log_very_verbose("Processing LV %s in VG %s.", lvl->lv->name, vg->name);
- if ((ret = process_single_lv(cmd, lvl->lv, handle)) != ECMD_PROCESSED)
+ ret = process_single_lv(cmd, lvl->lv, handle);
+ if (ret != ECMD_PROCESSED)
stack;
-
if (ret > ret_max)
ret_max = ret;
@@ -1816,6 +1840,7 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
vg_name = vgnl->vg_name;
vg_uuid = vgnl->vgid;
+ skip = 0;
/*
* arg_lvnames contains some elements that are just "vgname"
@@ -1850,19 +1875,24 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
vg = vg_read(cmd, vg_name, vg_uuid, flags);
if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &skip)) {
stack;
- ret = ECMD_FAILED;
- } else if (skip)
- ret = ECMD_PROCESSED;
- else {
- if ((ret = process_each_lv_in_vg(cmd, vg, &lvnames, tags_arg, 0,
- handle, process_single_lv)) != ECMD_PROCESSED)
- stack;
- unlock_vg(cmd, vg_name);
+ ret_max = ECMD_FAILED;
+ release_vg(vg);
+ continue;
+
+ }
+ if (skip) {
+ release_vg(vg);
+ continue;
}
- release_vg(vg);
+ ret = process_each_lv_in_vg(cmd, vg, &lvnames, tags_arg, 0,
+ handle, process_single_lv);
+ if (ret != ECMD_PROCESSED)
+ stack;
if (ret > ret_max)
ret_max = ret;
+
+ unlock_and_release_vg(cmd, vg, vg_name);
}
return ret_max;
@@ -2111,9 +2141,9 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
}
if (!skip) {
- if ((ret = process_single_pv(cmd, vg, pv, handle)) != ECMD_PROCESSED)
+ ret = process_single_pv(cmd, vg, pv, handle);
+ if (ret != ECMD_PROCESSED)
stack;
-
if (ret > ret_max)
ret_max = ret;
}
@@ -2155,9 +2185,9 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t flags,
struct dm_str_list *sl;
const char *vg_name;
const char *vg_uuid;
- int skip;
int ret_max = ECMD_PROCESSED;
int ret;
+ int skip;
dm_list_iterate_items(vgnl, all_vgnameids) {
if (sigint_caught())
@@ -2165,24 +2195,31 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t flags,
vg_name = vgnl->vg_name;
vg_uuid = vgnl->vgid;
+ skip = 0;
vg = vg_read(cmd, vg_name, vg_uuid, flags | READ_WARN_INCONSISTENT);
if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &skip)) {
stack;
ret = ECMD_FAILED;
- } else {
- if ((ret = _process_pvs_in_vg(cmd, vg, all_devices, arg_pvnames, arg_tags,
- process_all, skip, handle,
- process_single_pv)) != ECMD_PROCESSED)
- stack;
- if (!skip)
- unlock_vg(cmd, vg->name);
- }
- release_vg(vg);
+ skip = 1;
- if (ret > ret_max)
+ /* Only continue if no vg was returned. */
+ if (!vg)
+ continue;
+ }
+
+ ret = _process_pvs_in_vg(cmd, vg, all_devices, arg_pvnames, arg_tags,
+ process_all, skip, handle, process_single_pv);
+ if (ret != ECMD_PROCESSED)
+ stack;
+ if (ret > ret_max)
ret_max = ret;
+ if (skip)
+ release_vg(vg);
+ else
+ unlock_and_release_vg(cmd, vg, vg->name);
+
/* Quit early when possible. */
if (!process_all && dm_list_empty(arg_tags) && dm_list_empty(arg_pvnames))
return ret_max;
@@ -2210,7 +2247,7 @@ int process_each_pv(struct cmd_context *cmd,
struct dm_list all_devices; /* device_list */
int process_all_pvs;
int process_all_devices;
- int ret_max;
+ int ret_max = ECMD_PROCESSED;
int ret;
dm_list_init(&arg_tags);
@@ -2247,21 +2284,23 @@ int process_each_pv(struct cmd_context *cmd,
return ret;
}
- /* Here 'ret' could be only ECMD_PROCESSED */
- if ((ret_max = _process_pvs_in_vgs(cmd, flags, &all_vgnameids, &all_devices,
- &arg_pvnames, &arg_tags, process_all_pvs,
- handle, process_single_pv)) != ECMD_PROCESSED)
+ ret = _process_pvs_in_vgs(cmd, flags, &all_vgnameids, &all_devices,
+ &arg_pvnames, &arg_tags, process_all_pvs,
+ handle, process_single_pv);
+ if (ret != ECMD_PROCESSED)
stack;
+ if (ret > ret_max)
+ ret_max = ret;
- if (process_all_devices) {
- if ((ret = _process_device_list(cmd, &all_devices, handle,
- process_single_pv)) != ECMD_PROCESSED)
- stack;
-
- if (ret > ret_max)
- ret_max = ret;
- }
+ if (!process_all_devices)
+ goto out;
+ ret = _process_device_list(cmd, &all_devices, handle, process_single_pv);
+ if (ret != ECMD_PROCESSED)
+ stack;
+ if (ret > ret_max)
+ ret_max = ret;
+out:
return ret_max;
}
@@ -2275,9 +2314,10 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
dm_list_iterate_items(pvl, &vg->pvs) {
if (sigint_caught())
return_ECMD_FAILED;
- if ((ret = process_single_pv(cmd, vg, pvl->pv, handle)) != ECMD_PROCESSED)
- stack;
+ ret = process_single_pv(cmd, vg, pvl->pv, handle);
+ if (ret != ECMD_PROCESSED)
+ stack;
if (ret > ret_max)
ret_max = ret;
}
9 years, 5 months
master - toollib: ignore_vg() with skip is not locked
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=513105c6aca5f8...
Commit: 513105c6aca5f8159b8345e3c252bf1ced40b92f
Parent: 27182e1ddb21d3a90559b7a848c422eb2a443cfd
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 14 19:32:03 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 14 19:32:03 2014 +0100
toollib: ignore_vg() with skip is not locked
Extend/fix d8923457b82456ebee3e333b3fcc26087483cd01 commit.
'skip'-ed VG is not holding any lock - so don't unlock such VG.
At the same time simplify the code around and relase VG at a single
place and unlock only not skiped and not ignored VGs.
---
tools/toollib.c | 43 ++++++++++++++++++++++++-------------------
1 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 5a17b5d..2b08249 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1478,19 +1478,20 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &skip)) {
stack;
ret = ECMD_FAILED;
- release_vg(vg);
- } else {
+ } else if (skip)
+ ret = ECMD_PROCESSED;
+ else {
/* Process this VG? */
- if (!skip &&
- (process_all ||
- (!dm_list_empty(arg_vgnames) && str_list_match_item(arg_vgnames, vg_name)) ||
- (!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL)))) {
+ if (process_all ||
+ (!dm_list_empty(arg_vgnames) && str_list_match_item(arg_vgnames, vg_name)) ||
+ (!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL))) {
if ((ret = process_single_vg(cmd, vg_name, vg, handle)) != ECMD_PROCESSED)
stack;
} else
ret = ECMD_PROCESSED;
- unlock_and_release_vg(cmd, vg, vg_name);
+ unlock_vg(cmd, vg_name);
}
+ release_vg(vg);
if (ret > ret_max)
ret_max = ret;
@@ -1850,15 +1851,15 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t flags,
if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &skip)) {
stack;
ret = ECMD_FAILED;
- release_vg(vg);
- } else {
- if (skip)
- ret = ECMD_PROCESSED;
- else if ((ret = process_each_lv_in_vg(cmd, vg, &lvnames, tags_arg, 0,
- handle, process_single_lv)) != ECMD_PROCESSED)
+ } else if (skip)
+ ret = ECMD_PROCESSED;
+ else {
+ if ((ret = process_each_lv_in_vg(cmd, vg, &lvnames, tags_arg, 0,
+ handle, process_single_lv)) != ECMD_PROCESSED)
stack;
- unlock_and_release_vg(cmd, vg, vg_name);
+ unlock_vg(cmd, vg_name);
}
+ release_vg(vg);
if (ret > ret_max)
ret_max = ret;
@@ -2169,14 +2170,15 @@ static int _process_pvs_in_vgs(struct cmd_context *cmd, uint32_t flags,
if (ignore_vg(vg, vg_name, flags & READ_ALLOW_INCONSISTENT, &skip)) {
stack;
ret = ECMD_FAILED;
- release_vg(vg);
} else {
if ((ret = _process_pvs_in_vg(cmd, vg, all_devices, arg_pvnames, arg_tags,
process_all, skip, handle,
process_single_pv)) != ECMD_PROCESSED)
stack;
- unlock_and_release_vg(cmd, vg, vg->name);
+ if (!skip)
+ unlock_vg(cmd, vg->name);
}
+ release_vg(vg);
if (ret > ret_max)
ret_max = ret;
@@ -2208,7 +2210,7 @@ int process_each_pv(struct cmd_context *cmd,
struct dm_list all_devices; /* device_list */
int process_all_pvs;
int process_all_devices;
- int ret_max = ECMD_PROCESSED;
+ int ret_max;
int ret;
dm_list_init(&arg_tags);
@@ -2245,6 +2247,7 @@ int process_each_pv(struct cmd_context *cmd,
return ret;
}
+ /* Here 'ret' could be only ECMD_PROCESSED */
if ((ret_max = _process_pvs_in_vgs(cmd, flags, &all_vgnameids, &all_devices,
&arg_pvnames, &arg_tags, process_all_pvs,
handle, process_single_pv)) != ECMD_PROCESSED)
@@ -2259,7 +2262,6 @@ int process_each_pv(struct cmd_context *cmd,
ret_max = ret;
}
-out:
return ret_max;
}
@@ -2273,7 +2275,10 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
dm_list_iterate_items(pvl, &vg->pvs) {
if (sigint_caught())
return_ECMD_FAILED;
- if ((ret = process_single_pv(cmd, vg, pvl->pv, handle)) > ret_max)
+ if ((ret = process_single_pv(cmd, vg, pvl->pv, handle)) != ECMD_PROCESSED)
+ stack;
+
+ if (ret > ret_max)
ret_max = ret;
}
9 years, 5 months
master - tests: explicit raid sync
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=27182e1ddb21d3...
Commit: 27182e1ddb21d3a90559b7a848c422eb2a443cfd
Parent: fd32bb1991d8323d655361d19a636e29c6aa62c3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 13 21:52:02 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 14 18:12:44 2014 +0100
tests: explicit raid sync
---
test/shell/lvconvert-cache-raid.sh | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/test/shell/lvconvert-cache-raid.sh b/test/shell/lvconvert-cache-raid.sh
index 1fcd0fe..faab251 100644
--- a/test/shell/lvconvert-cache-raid.sh
+++ b/test/shell/lvconvert-cache-raid.sh
@@ -46,6 +46,7 @@ lvremove -f $vg
lvcreate -n cpool_meta -m 1 --type raid1 -l 10 $vg
lvcreate -n cpool -m 1 --type raid1 -l 10 $vg
+aux wait_for_sync $vg cpool_meta
aux wait_for_sync $vg cpool
lvs -a -o+seg_pe_ranges $vg
lvconvert --yes --type cache-pool --poolmetadata $vg/cpool_meta $vg/cpool
@@ -62,6 +63,8 @@ not lvconvert --splitmirrors 1 --name split_cmeta $vg/cpool_cmeta "$dev1"
not lvconvert --splitmirrors 1 --name split_cdata $vg/cpool_cdata "$dev1"
# but allow manipulating existing LVs with reserved names
+aux wait_for_sync $vg cpool_cmeta
+aux wait_for_sync $vg cpool_cdata
lvconvert --splitmirrors 1 --name split_meta $vg/cpool_cmeta "$dev1"
lvconvert --splitmirrors 1 --name split_data $vg/cpool_cdata "$dev1"
9 years, 5 months
master - debug: switch to verbose
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fd32bb1991d832...
Commit: fd32bb1991d8323d655361d19a636e29c6aa62c3
Parent: b6f921e5cb1877263ef5561d6f96141022ff3c6f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 14 16:11:43 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 14 18:12:44 2014 +0100
debug: switch to verbose
When there is no real error from the function - avoid using log_error().
---
tools/toollib.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index e6573fb..5a17b5d 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1569,7 +1569,7 @@ int process_each_vg(struct cmd_context *cmd, int argc, char **argv,
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */
- log_error("No volume groups found");
+ log_verbose("No volume groups found.");
return ECMD_PROCESSED;
}
@@ -1909,7 +1909,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv, uint32_t fla
if (dm_list_empty(&arg_vgnames) && dm_list_empty(&vgnameids_on_system)) {
/* FIXME Should be log_print, but suppressed for reporting cmds */
- log_error("No volume groups found");
+ log_verbose("No volume groups found.");
return ECMD_PROCESSED;
}
9 years, 5 months
master - debug: better message for pool zeroing state
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b6f921e5cb1877...
Commit: b6f921e5cb1877263ef5561d6f96141022ff3c6f
Parent: 38200c2000e5499a6421f477305464f9772b8d57
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 14 16:11:16 2014 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 14 18:12:35 2014 +0100
debug: better message for pool zeroing state
---
tools/toollib.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 02a1bbf..e6573fb 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -980,7 +980,7 @@ int get_pool_params(struct cmd_context *cmd,
if (arg_is_set(cmd, zero_ARG)) {
*passed_args |= PASS_ARG_ZERO;
*zero = arg_int_value(cmd, zero_ARG, 1);
- log_very_verbose("Setting pool zeroing: %u", *zero);
+ log_very_verbose("%s pool zeroing.", *zero ? "Enabling" : "Disabling");
}
if (arg_is_set(cmd, discards_ARG)) {
*passed_args |= PASS_ARG_DISCARDS;
9 years, 5 months