master - test: vgcfgbackup-lvm1
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fa130722cbe3f7...
Commit: fa130722cbe3f7ac7f80fce4bcd3c3dc12d6897e
Parent: f194d5f169f6977eb0e4ffeb4924cdcb6c8dcf77
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Apr 26 12:21:49 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
test: vgcfgbackup-lvm1
The lvm1 part of vgcfgbackup-usage.
---
test/shell/vgcfgbackup-lvm1.sh | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/test/shell/vgcfgbackup-lvm1.sh b/test/shell/vgcfgbackup-lvm1.sh
new file mode 100644
index 0000000..4a7f32a
--- /dev/null
+++ b/test/shell/vgcfgbackup-lvm1.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Copyright (C) 2008-2013 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
+# of the GNU General Public License v.2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+SKIP_WITH_LVMLOCKD=1
+SKIP_WITH_LVMPOLLD=1
+
+. lib/inittest
+
+aux prepare_pvs 4
+
+if test -n "$LVM_TEST_LVM1" ; then
+
+pvcreate --metadatacopies 0 "$dev4"
+
+# No automatic backup
+aux lvmconf "backup/backup = 0"
+
+# vgcfgbackup correctly stores metadata LVM1 with missing PVs
+
+pvcreate -M1 $(cat DEVICES)
+vgcreate -M1 -c n $vg $(cat DEVICES)
+lvcreate -l1 -n $lv1 $vg "$dev1"
+pvremove -ff -y "$dev2"
+not lvcreate -l1 -n $lv1 $vg "$dev3"
+vgcfgbackup -f "backup.$$" $vg
+
+fi
+
6 years, 10 months
master - test: vgcfgbackup-usage
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f194d5f169f697...
Commit: f194d5f169f6977eb0e4ffeb4924cdcb6c8dcf77
Parent: 4c5ad5a04c2d28920e1f5abb72d88e3af49fb2f0
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Apr 26 12:20:09 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
test: vgcfgbackup-usage
Split the lvm1 part into a separate test.
---
test/shell/vgcfgbackup-usage.sh | 14 --------------
1 files changed, 0 insertions(+), 14 deletions(-)
diff --git a/test/shell/vgcfgbackup-usage.sh b/test/shell/vgcfgbackup-usage.sh
index 31b0a6f..f923049 100644
--- a/test/shell/vgcfgbackup-usage.sh
+++ b/test/shell/vgcfgbackup-usage.sh
@@ -74,17 +74,3 @@ vgcfgrestore -f "backup.$$1" $vg
vgchange -an $vg
vgremove -f $vg
-
-# vgcfgbackup correctly stores metadata LVM1 with missing PVs
-# FIXME: clvmd seems to have problem with metadata format change here
-# fix it and remove this vgscan
-if test -n "$LVM_TEST_LVM1" ; then
-vgscan
-pvcreate -M1 $(cat DEVICES)
-vgcreate -M1 -c n $vg $(cat DEVICES)
-lvcreate -l1 -n $lv1 $vg "$dev1"
-pvremove -ff -y "$dev2"
-not lvcreate -l1 -n $lv1 $vg "$dev3"
-vgcfgbackup -f "backup.$$" $vg
-fi
-
6 years, 10 months
master - test: vgsplit-usage
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4c5ad5a04c2d28...
Commit: 4c5ad5a04c2d28920e1f5abb72d88e3af49fb2f0
Parent: 29a8012724071fb07b72ef7ba2abd4e17d324a4c
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Apr 25 14:22:42 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
test: vgsplit-usage
Restart clvmd between testing each mdatype to
avoid a problem with dev state being kept from
one test to the next.
---
test/shell/vgsplit-usage.sh | 15 ++++++++++++++-
1 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/test/shell/vgsplit-usage.sh b/test/shell/vgsplit-usage.sh
index 4f5c6d4..f404a5b 100644
--- a/test/shell/vgsplit-usage.sh
+++ b/test/shell/vgsplit-usage.sh
@@ -152,8 +152,22 @@ lvcreate -l 4 -n $lv2 $vg1
vgchange -an $vg1
not vgsplit $vg1 $vg2 "$dev3" 2>err;
vgremove -f $vg2 $vg1
+
+# Restart clvm because using the same
+# devs as lvm1 and then lvm2 causes problems.
+if test -e LOCAL_CLVMD ; then
+ kill $(< LOCAL_CLVMD)
+ for i in $(seq 1 100) ; do
+ test $i -eq 100 && die "Shutdown of clvmd is too slow."
+ pgrep clvmd || break
+ sleep .1
+ done # wait for the pid removal
+ aux prepare_clvmd
+fi
+
done
+if test -z "$LVM_TEST_LVM1" ; then
# ONLY LVM2 metadata
# setup PVs" '
pvcreate --metadatacopies 0 "$dev5"
@@ -168,7 +182,6 @@ check pvlv_counts $vg1 2 1 0
vgremove -f $vg1
# vgsplit rejects split because metadata types differ
-if test -n "$LVM_TEST_LVM1" ; then
pvcreate -ff -M1 "$dev3" "$dev4"
pvcreate -ff "$dev1" "$dev2"
vgcreate -M1 $vg1 "$dev3" "$dev4"
6 years, 10 months
master - test: lvmetad-ambiguous
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=29a8012724071f...
Commit: 29a8012724071fb07b72ef7ba2abd4e17d324a4c
Parent: d4d1d5ac3ebc88f48e7d959cff9ab9c59ba92ba0
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Apr 22 16:11:01 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
test: lvmetad-ambiguous
update for duplicate changes
---
test/shell/lvmetad-ambiguous.sh | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/test/shell/lvmetad-ambiguous.sh b/test/shell/lvmetad-ambiguous.sh
index ffcbdd3..52f2928 100644
--- a/test/shell/lvmetad-ambiguous.sh
+++ b/test/shell/lvmetad-ambiguous.sh
@@ -26,11 +26,11 @@ dmsetup create -u TEST-${PREFIX}pv1 ${PREFIX}pv1 ${PREFIX}pv1.table
aux finish_udev_transaction
# re-scan them
-pvscan --cache "$dev1"
-pvscan --cache "$dev2"
+pvscan --cache "$dev1" || true
+pvscan --cache "$dev2" || true
# expect both to be there
-pvs | tee pvs.txt
-grep "$dev1" pvs.txt
-grep "$dev2" pvs.txt
+pvs -a -o name | tee out
+grep "$dev1" out
+grep "$dev2" out
6 years, 10 months
master - test: pv-duplicate-uuid
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d4d1d5ac3ebc88...
Commit: d4d1d5ac3ebc88f48e7d959cff9ab9c59ba92ba0
Parent: 708eca39eac23af1a4a889de40d69151168d18f1
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Apr 21 15:53:15 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
test: pv-duplicate-uuid
update for duplicate changes
---
test/shell/pv-duplicate-uuid.sh | 34 ++++++++++++++++++++++++++++------
1 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/test/shell/pv-duplicate-uuid.sh b/test/shell/pv-duplicate-uuid.sh
index bd54f5f..c846a50 100644
--- a/test/shell/pv-duplicate-uuid.sh
+++ b/test/shell/pv-duplicate-uuid.sh
@@ -19,13 +19,35 @@ aux prepare_devs 3
pvcreate "$dev1"
UUID1=$(get pv_field "$dev1" uuid)
-pvcreate --config "devices{filter=[\"a|$dev2|\",\"r|.*|\"]}" -u "$UUID1" --norestorefile "$dev2"
-pvcreate --config "devices{filter=[\"a|$dev3|\",\"r|.*|\"]}" -u "$UUID1" --norestorefile "$dev3"
+pvcreate --config "devices{filter=[\"a|$dev2|\",\"r|.*|\"]} global/use_lvmetad=0" -u "$UUID1" --norestorefile "$dev2"
+pvcreate --config "devices{filter=[\"a|$dev3|\",\"r|.*|\"]} global/use_lvmetad=0" -u "$UUID1" --norestorefile "$dev3"
+
+pvscan --cache 2>&1 | tee out
+
+if test -e LOCAL_LVMETAD; then
+ grep "was already found" out
+ grep "WARNING: Disabling lvmetad cache which does not support duplicate PVs." out
+fi
pvs -o+uuid 2>&1 | tee out
-COUNT=$(should grep --count "Found duplicate" out)
-# FIXME lvmetad is not able to serve properly this case
-should [ "$COUNT" -eq 2 ]
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+test $(grep $UUID1 main | wc -l) -eq 1
+
+COUNT=$(grep --count "was already found" warn)
+[ "$COUNT" -eq 2 ]
+
+pvs -o+uuid --config "devices{filter=[\"a|$dev2|\",\"r|.*|\"]}" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+not grep "$dev1" main
+grep "$dev2" main
+not grep "$dev3" main
+
+not grep "was already found" warn
-pvs -o+uuid --config "devices{filter=[\"a|$dev2|\",\"r|.*|\"]}"
6 years, 10 months
master - test: process-each-duplicate-pvs
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=708eca39eac23a...
Commit: 708eca39eac23af1a4a889de40d69151168d18f1
Parent: e84fb639f03b018b7b6f09778f863c50a7f9e045
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Apr 20 16:45:53 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
test: process-each-duplicate-pvs
Update for new duplicate processing.
---
test/shell/process-each-duplicate-pvs.sh | 590 ++++++++++++++++++++++++------
1 files changed, 476 insertions(+), 114 deletions(-)
diff --git a/test/shell/process-each-duplicate-pvs.sh b/test/shell/process-each-duplicate-pvs.sh
index 47e1043..41d844d 100644
--- a/test/shell/process-each-duplicate-pvs.sh
+++ b/test/shell/process-each-duplicate-pvs.sh
@@ -9,130 +9,492 @@ test_description='Test duplicate PVs'
SKIP_WITH_LVMLOCKD=1
SKIP_WITH_LVMPOLLD=1
+SKIP_WITH_CLVMD=1
. lib/inittest
-aux prepare_devs 2
+aux prepare_devs 6 16
+
+aux lvmconf 'devices/allow_changes_with_duplicate_pvs = 0'
pvcreate "$dev1"
+pvcreate "$dev2"
vgcreate $vg1 "$dev1"
+vgcreate $vg2 "$dev2"
+pvresize --setphysicalvolumesize 8m "$dev2"
+lvcreate -an -l1 -n $lv1 $vg1
+
+# Both devs are shown and used by the VG
+
+pvs 2>&1 | tee out
+
+grep "$dev1" out
+grep "$dev2" out
+grep "$dev1" out | grep $vg1
+grep "$dev2" out | grep $vg2
+check pv_field "$dev1" pv_allocatable "allocatable"
+check pv_field "$dev2" pv_allocatable "allocatable"
+not grep WARNING out
+
+UUID1=$(pvs --noheadings -o uuid $dev1 | xargs)
+UUID2=$(pvs --noheadings -o uuid $dev2 | xargs)
+
+SIZE1=$(pvs --noheadings -o dev_size $dev1)
+SIZE2=$(pvs --noheadings -o dev_size $dev2)
+
+MINOR1=$(pvs --noheadings -o minor $dev1)
+MINOR2=$(pvs --noheadings -o minor $dev2)
+
+check pv_field "$dev1" dev_size $SIZE1
+check pv_field "$dev2" dev_size $SIZE2
+
+# Copy dev1 over dev2.
+dd if="$dev1" of="$dev2" bs=1M iflag=direct oflag=direct,sync
+pvscan --cache
+
+# The single preferred dev is shown from 'pvs'.
+pvs -o+uuid,duplicate 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+# Don't know yet if dev1 or dev2 is preferred, so count just one is.
+test $(grep $vg1 main | wc -l) -eq 1
+test $(grep $UUID1 main | wc -l) -eq 1
+not grep duplicate main
+not grep $vg2 main
+not grep $UUID2 main
+
+grep "was already found on" warn
+grep "prefers device" warn
+
+# Find which is the preferred dev and which is the duplicate.
+PV=$(pvs --noheadings -o name -S uuid=$UUID1)
+if [ $PV == "$dev1" ]; then
+ DUP=$dev2
+else
+ DUP=$dev1
+fi
+
+echo PV is $PV
+echo DUP is $DUP
+
+grep $PV main
+not grep $DUP main
+
+# Repeat above checking preferred/dup in output
+pvs 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep $PV main
+not grep $DUP main
+
+# The duplicate dev is included in 'pvs -a'
+pvs -a -o+uuid,duplicate 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep "$dev1" main
+grep "$dev2" main
+grep $PV main
+grep $DUP main
+test $(grep duplicate main | wc -l) -eq 1
+grep $DUP main | grep duplicate
+not grep $vg2 main
+not grep $UUID2 main
+grep "$dev1" main | grep $vg1
+grep "$dev2" main | grep $vg1
+grep "$dev1" main | grep $UUID1
+grep "$dev2" main | grep $UUID1
+
+grep "was already found on" warn
+grep "prefers device" warn
+
+#
+# Passing a dev name arg always includes that dev.
+#
+
+pvs -o+uuid "$dev1" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep "$dev1" main
+not grep "$dev2" main
+grep $UUID1 main
+grep $vg1 main
+grep "was already found on" warn
+grep "prefers device" warn
+
+pvs -o+uuid "$dev2" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep "$dev2" main
+not grep "$dev1" main
+grep $UUID1 main
+grep $vg1 main
+grep "was already found on" warn
+grep "prefers device" warn
-# Clone the PV
-dd if="$dev1" of="$dev2" bs=256K count=1 iflag=direct oflag=direct
-aux notify_lvmetad "$dev2"
+pvs -o+uuid,duplicate "$dev1" "$dev2" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep "$dev1" main
+grep "$dev2" main
+grep "$dev1" main | grep $vg1
+grep "$dev2" main | grep $vg1
+grep "$dev1" main | grep $UUID1
+grep "$dev2" main | grep $UUID1
+test $(grep duplicate main | wc -l) -eq 1
+grep $DUP main | grep duplicate
-# When there are cloned devices (same pvid), one will be referenced in
-# lvmcache as pv->dev, and the other will not be referenced from lvmcache,
-# it'll only be in device cache. The one referenced by lvmcache is
-# referred to as the "preferred" one, and is the one that is printed by a
-# standard 'pvs' command.
#
-# We don't know if dev1 or dev2 will be preferred, so we first check that
-# and save it as PV1, the other as PV2.
+# Test specific report fields for each dev.
#
-# The rules that 'pvs' follows to choose which PVs to display are
-# somewhat strange and seem arbitrary from a user perspective;
-# the choice is driven largely by what's most practical in the code,
-# but also by what vgimportclone needs.
+
+pvs --noheadings -o vg_name,vg_uuid "$dev1" 2>&1 | tee out1
+pvs --noheadings -o vg_name,vg_uuid "$dev2" 2>&1 | tee out2
+
+grep -v WARNING out1 > main1 || true
+grep -v WARNING out2 > main2 || true
+diff main1 main2
+rm out1 out2 main1 main2 || true
+
+check pv_field "$dev1" pv_in_use "used"
+check pv_field "$dev2" pv_in_use "used"
+
+check pv_field $PV pv_allocatable "allocatable"
+check pv_field $DUP pv_allocatable ""
+
+check pv_field $PV pv_duplicate ""
+check pv_field $DUP pv_duplicate "duplicate"
+
+pvs --noheadings -o name,pv_allocatable "$dev1" "$dev2" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep $PV main
+grep $DUP main
+grep $dev1 main
+grep $dev2 main
+test $(grep allocatable main | wc -l) -eq 1
+
+pvs --noheadings -o name,pv_duplicate "$dev1" "$dev2" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep $PV main
+grep $DUP main
+grep $dev1 main
+grep $dev2 main
+test $(grep duplicate main | wc -l) -eq 1
+
#
-# Some of the rules that process_each_pv is using:
-# - When no pv arg is specified, print the one preferred dev.
-# - When pv args are specified, print one line per specified arg,
-# i.e. don't print all duplicate pvs when one is specified.
-# - Always print the preferred duplicate, even if it was not the
-# one specified, e.g. If there are two duplicates on A and B,
-# and A is the preferred device, then 'pvs A' will show A and
-# 'pvs B' will show A.
-# - If multiple duplicates are specified, then print each, e.g.
-# 'pvs A B' will show both A and B.
-# - If three duplicates exist on A, B, C, and the preferred is A,
-# and the command 'pvs B C' is run, then the A will be printed
-# first since we always print the preferred device, and then
-# either B or C will be printed. 'pvs A B C' will print all.
-# - 'pvs -a' should print all the duplicates and should show
-# the same VG for each.
-# - 'pvs -o+size ...' should show the correct size of the
-# devices being printed if they differ among the duplicates.
-# - By using 'pvs --config' with a filter, you can filter out
-# the duplicate devs you don't want so that pvs will
-# print the devs you do want to see.
+# A filter can be used to show only one.
#
-# The tests below check these behaviors on up to two duplicates,
-# so if the process_each_pv logic changes regarding which
-# duplicates are chosen, then this test will need adjusting.
-
-# Verify that there is only one PV printed, i.e. the preferred
-pvs --noheading | tee out
-test $(wc -l < out) -eq 1
-
-# Set PV1 to the perferred/cached PV, and PV2 to the other.
-# Cannot use pvs -o pv_name because that command goes to
-# disk and does not represent what lvmetad thinks.
-PV1=$(pvs --noheading | awk '{ print $1 }')
-echo PV1 is $PV1
-if [ $PV1 == $dev1 ]; then
- PV2=$dev2
-else
- PV2=$dev1
-fi
-echo PV2 is $PV2
-
-# check listed pvs
-pvs --noheading | tee out
-grep $PV1 out
-not grep $PV2 out
-
-# check error messages
-pvs --noheading 2>&1 | tee out
-grep "Found duplicate" out >err
-grep "using $PV1 not $PV2" err
-
-# check listed pvs
-pvs --noheading "$dev1" | tee out
-grep $PV1 out
-not grep $PV2 out
-
-# check error messages
-pvs --noheading "$dev1" 2>&1 | tee out
-grep "Found duplicate" out >err
-grep "using $PV1 not $PV2" err
-
-# check listed pvs
-pvs --noheading "$dev2" | tee out
-grep $PV1 out
-not grep $PV2 out
-
-# check error messages
-pvs --noheading "$dev2" 2>&1 | tee out
-grep "Found duplicate" out >err
-grep "using $PV1 not $PV2" err
-
-# check listed pvs
-pvs --noheading "$dev1" "$dev2" | tee out
-grep $PV1 out
-grep $PV2 out
-
-# check error messages
-pvs --noheading "$dev1" "$dev2" 2>&1 | tee out
-grep "Found duplicate" out >err
-grep "using $PV1 not $PV2" err
-
-# check listed pvs
-pvs --noheading -a | tee out
-grep $PV1 out
-grep $PV2 out
-grep $PV1 out | grep $vg1
-grep $PV2 out | grep $vg1
-
-# check error messages
-pvs --noheading -a 2>&1 | tee out
-grep "Found duplicate" out >err
-grep "using $PV1 not $PV2" err
-
-
-# TODO: I'd like to test that a subsystem device is preferred
-# over a non-subsystem device, but all the devices used here
-# are DM devices, i.e. they are already subsystem devices,
-# so I can't just wrap a standard block device with a DM
-# identity mapping.
+
+pvs --config "devices { filter=[ \"a|$dev2|\", \"r|.*|\" ] }" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+not grep $dev1 main
+grep $dev2 main
+
+not grep "was already found on" warn
+not grep "prefers device" warn
+
+
+pvs --config "devices { filter=[ \"a|$dev1|\", \"r|.*|\"] }" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep $dev1 main
+not grep $dev2 main
+
+not grep "was already found on" warn
+not grep "prefers device" warn
+
+# PV size and minor is still reported correctly for each.
+
+check pv_field "$dev1" dev_size $SIZE1
+check pv_field "$dev2" dev_size $SIZE2
+
+check pv_field "$dev1" minor $MINOR1
+check pv_field "$dev2" minor $MINOR2
+
+# With allow_changes_with_duplicate_pvs=0, a VG with duplicate devs
+# cannot be modified or activated.
+
+not lvcreate -an -l1 -n $lv2 $vg1
+not lvremove $vg1/$lv1
+not lvchange -ay $vg1/$lv1
+not vgremove $vg1
+
+
+# With allow_changes_with_duplicate_pvs=1, changes above are permitted.
+
+aux lvmconf 'devices/allow_changes_with_duplicate_pvs = 1'
+
+lvcreate -an -l1 -n $lv2 $vg1
+lvremove $vg1/$lv1
+lvchange -ay $vg1/$lv2
+lvchange -an $vg1/$lv2
+lvremove $vg1/$lv2
+vgremove -f $vg1
+pvremove -ff -y "$dev1"
+pvremove -ff -y "$dev2"
+
+
+# dev3 and dev4 are copies, orphans
+
+pvcreate "$dev3"
+pvcreate "$dev4"
+pvresize --setphysicalvolumesize 8m "$dev4"
+
+UUID3=$(pvs --noheadings -o uuid $dev3 | xargs)
+UUID4=$(pvs --noheadings -o uuid $dev4 | xargs)
+
+SIZE3=$(pvs --noheadings -o dev_size $dev3)
+SIZE4=$(pvs --noheadings -o dev_size $dev4)
+
+check pv_field "$dev3" dev_size $SIZE3
+check pv_field "$dev4" dev_size $SIZE4
+
+pvs 2>&1 | tee out
+
+grep "$dev3" out
+grep "$dev4" out
+
+dd if="$dev3" of="$dev4" bs=1M iflag=direct oflag=direct,sync
+pvscan --cache
+
+# One appears with 'pvs'
+
+pvs -o+uuid 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+test $(grep $UUID3 main | wc -l) -eq 1
+not grep $UUID4 main
+
+grep "was already found on" warn
+grep "prefers device" warn
+
+# Both appear with 'pvs -a'
+
+pvs -a -o+uuid 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+test $(grep $UUID3 main | wc -l) -eq 2
+
+grep "$dev3" main
+grep "$dev4" main
+
+grep $UUID3 main
+not grep $UUID4 main
+
+grep "was already found on" warn
+grep "prefers device" warn
+
+# Show each dev individually and both together
+
+pvs -o+uuid "$dev3" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep "$dev3" main
+not grep "$dev4" main
+
+grep "was already found on" warn
+grep "prefers device" warn
+
+pvs -o+uuid "$dev4" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+not grep "$dev3" main
+grep "$dev4" main
+
+grep "was already found on" warn
+grep "prefers device" warn
+
+pvs -o+uuid "$dev3" "$dev4" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep "$dev3" main
+grep "$dev4" main
+
+grep "was already found on" warn
+grep "prefers device" warn
+
+# Same sizes shown.
+
+check pv_field "$dev3" dev_size $SIZE3
+check pv_field "$dev4" dev_size $SIZE4
+
+# Verify that devs being used by an active LV are
+# preferred over duplicates that are not used by an LV.
+
+dd if=/dev/zero of="$dev3" bs=1M oflag=direct,sync || true
+dd if=/dev/zero of="$dev4" bs=1M oflag=direct,sync || true
+pvscan --cache
+
+vgcreate $vg2 $dev3 $dev4
+lvcreate -l1 -n $lv1 $vg2 "$dev3"
+lvcreate -l1 -n $lv2 $vg2 "$dev4"
+
+dd if="$dev3" of="$dev5" bs=1M iflag=direct oflag=direct,sync
+dd if="$dev4" of="$dev6" bs=1M iflag=direct oflag=direct,sync
+pvscan --cache
+
+pvs -o+uuid,duplicate 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep "$dev3" main
+grep "$dev4" main
+not grep duplicate main
+check pv_field "$dev3" pv_duplicate ""
+check pv_field "$dev4" pv_duplicate ""
+check pv_field "$dev5" pv_duplicate "duplicate"
+check pv_field "$dev6" pv_duplicate "duplicate"
+
+grep "prefers device $dev3" warn
+grep "prefers device $dev4" warn
+not grep "prefers device $dev5" warn
+not grep "prefers device $dev6" warn
+
+pvs -a -o+uuid,duplicate 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+test $(grep duplicate main | wc -l) -eq 2
+grep "$dev3" main
+grep "$dev4" main
+grep "$dev5" main
+grep "$dev6" main
+
+grep "prefers device $dev3" warn
+grep "prefers device $dev4" warn
+not grep "prefers device $dev5" warn
+not grep "prefers device $dev6" warn
+
+pvs -o+uuid,duplicate "$dev3" "$dev4" "$dev5" "$dev6" 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+test $(grep duplicate main | wc -l) -eq 2
+grep "$dev3" main
+grep "$dev4" main
+grep "$dev5" main
+grep "$dev6" main
+
+grep "prefers device $dev3" warn
+grep "prefers device $dev4" warn
+not grep "prefers device $dev5" warn
+not grep "prefers device $dev6" warn
+
+
+dd if=/dev/zero of="$dev5" bs=1M oflag=direct,sync || true
+dd if=/dev/zero of="$dev6" bs=1M oflag=direct,sync || true
+pvscan --cache
+
+lvremove -y $vg2/$lv1
+lvremove -y $vg2/$lv2
+vgremove $vg2
+pvremove -ff -y "$dev3"
+pvremove -ff -y "$dev4"
+
+dd if=/dev/zero of="$dev3" bs=1M oflag=direct,sync || true
+dd if=/dev/zero of="$dev4" bs=1M oflag=direct,sync || true
+pvscan --cache
+
+# Reverse devs in the previous in case dev3/dev4 would be
+# preferred even without an active LV using them.
+
+vgcreate $vg2 "$dev5" "$dev6"
+lvcreate -l1 -n $lv1 $vg2 "$dev5"
+lvcreate -l1 -n $lv2 $vg2 "$dev6"
+
+dd if="$dev5" of="$dev3" bs=1M iflag=direct oflag=direct,sync
+dd if="$dev6" of="$dev4" bs=1M iflag=direct oflag=direct,sync
+pvscan --cache
+
+pvs -o+uuid,duplicate 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+grep "$dev5" main
+grep "$dev6" main
+not grep duplicate main
+check pv_field "$dev5" pv_duplicate ""
+check pv_field "$dev6" pv_duplicate ""
+check pv_field "$dev3" pv_duplicate "duplicate"
+check pv_field "$dev4" pv_duplicate "duplicate"
+
+pvs -a -o+uuid,duplicate 2>&1 | tee out
+
+rm warn main || true
+grep WARNING out > warn || true
+grep -v WARNING out > main || true
+
+test $(grep duplicate main | wc -l) -eq 2
+grep "$dev3" main
+grep "$dev4" main
+grep "$dev5" main
+grep "$dev6" main
+
+grep "prefers device $dev5" warn
+grep "prefers device $dev6" warn
+not grep "prefers device $dev3" warn
+not grep "prefers device $dev4" warn
+
+dd if=/dev/zero of="$dev3" bs=1M oflag=direct,sync || true
+dd if=/dev/zero of="$dev4" bs=1M oflag=direct,sync || true
+pvscan --cache
+
+lvremove -y $vg2/$lv1
+lvremove -y $vg2/$lv2
+vgremove $vg2
6 years, 10 months
master - lvmetad: add duplicate resolution advice
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e84fb639f03b01...
Commit: e84fb639f03b018b7b6f09778f863c50a7f9e045
Parent: b1ea27b1e210274dfb9c7100cf0f9714397eec3b
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue May 3 15:56:34 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
lvmetad: add duplicate resolution advice
---
tools/lvmcmdline.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index e6c82cf..fa9cd8f 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1677,6 +1677,13 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
if (lvmetad_used() && lvmetad_is_disabled(cmd, &reason)) {
log_warn("WARNING: Not using lvmetad because %s.", reason);
lvmetad_make_unused(cmd);
+
+ if (strstr(reason, "duplicate")) {
+ log_warn("WARNING: Use multipath or vgimportclone to resolve duplicate PVs?");
+ if (!find_config_tree_bool(cmd, devices_multipath_component_detection_CFG, NULL))
+ log_warn("WARNING: Set multipath_component_detection=1 to hide multipath duplicates.");
+ log_warn("WARNING: After duplicates are resolved, run \"pvscan --cache\" to enable lvmetad.");
+ }
}
}
6 years, 10 months
master - lvmetad: disable if device scan fails
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b1ea27b1e21027...
Commit: b1ea27b1e210274dfb9c7100cf0f9714397eec3b
Parent: 49d9582bed338dc555b616bcc9de20fafd00ce2d
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Apr 15 14:19:46 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
lvmetad: disable if device scan fails
If a command begins repopulating the lvmetad cache,
and fails part way through, it should set the disabled
state in lvmetad so other commands don't use bad data.
If a subsequent scan succeeds, the disabled state is
cleared.
---
daemons/lvmetad/lvmetad-client.h | 1 +
daemons/lvmetad/lvmetad-core.c | 10 +++++++---
lib/cache/lvmetad.c | 27 +++++++++++++++------------
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/daemons/lvmetad/lvmetad-client.h b/daemons/lvmetad/lvmetad-client.h
index dce8a7e..1376e6b 100644
--- a/daemons/lvmetad/lvmetad-client.h
+++ b/daemons/lvmetad/lvmetad-client.h
@@ -22,6 +22,7 @@
#define LVMETAD_DISABLE_REASON_DIRECT "DIRECT"
#define LVMETAD_DISABLE_REASON_LVM1 "LVM1"
#define LVMETAD_DISABLE_REASON_DUPLICATES "DUPLICATES"
+#define LVMETAD_DISABLE_REASON_SCANERROR "SCANERROR"
struct volume_group;
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 188c9b9..54ecd4a 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -202,8 +202,9 @@ struct vg_info {
#define GLFL_DISABLE_REASON_DIRECT 0x00000004
#define GLFL_DISABLE_REASON_LVM1 0x00000008
#define GLFL_DISABLE_REASON_DUPLICATES 0x00000010
+#define GLFL_DISABLE_REASON_SCANERROR 0x00000020
-#define GLFL_DISABLE_REASON_ALL (GLFL_DISABLE_REASON_DIRECT | GLFL_DISABLE_REASON_LVM1 | GLFL_DISABLE_REASON_DUPLICATES)
+#define GLFL_DISABLE_REASON_ALL (GLFL_DISABLE_REASON_DIRECT | GLFL_DISABLE_REASON_LVM1 | GLFL_DISABLE_REASON_DUPLICATES | GLFL_DISABLE_REASON_SCANERROR)
#define VGFL_INVALID 0x00000001
@@ -2512,6 +2513,8 @@ static response set_global_info(lvmetad_state *s, request r)
reason_flags |= GLFL_DISABLE_REASON_LVM1;
if (strstr(reason, LVMETAD_DISABLE_REASON_DUPLICATES))
reason_flags |= GLFL_DISABLE_REASON_DUPLICATES;
+ if (strstr(reason, LVMETAD_DISABLE_REASON_SCANERROR))
+ reason_flags |= GLFL_DISABLE_REASON_SCANERROR;
}
if (global_invalid != -1) {
@@ -2565,10 +2568,11 @@ static response get_global_info(lvmetad_state *s, request r)
memset(reason, 0, sizeof(reason));
if (s->flags & GLFL_DISABLE) {
- snprintf(reason, REASON_BUF_SIZE - 1, "%s%s%s",
+ snprintf(reason, REASON_BUF_SIZE - 1, "%s%s%s%s",
(s->flags & GLFL_DISABLE_REASON_DIRECT) ? LVMETAD_DISABLE_REASON_DIRECT "," : "",
(s->flags & GLFL_DISABLE_REASON_LVM1) ? LVMETAD_DISABLE_REASON_LVM1 "," : "",
- (s->flags & GLFL_DISABLE_REASON_DUPLICATES) ? LVMETAD_DISABLE_REASON_DUPLICATES "," : "");
+ (s->flags & GLFL_DISABLE_REASON_DUPLICATES) ? LVMETAD_DISABLE_REASON_DUPLICATES "," : "",
+ (s->flags & GLFL_DISABLE_REASON_SCANERROR) ? LVMETAD_DISABLE_REASON_SCANERROR "," : "");
}
if (!reason[0])
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 86ccd59..391cbc4 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -1700,11 +1700,6 @@ int lvmetad_pvscan_single(struct cmd_context *cmd, struct device *dev,
if (!baton.vg)
lvmcache_fmt(info)->ops->destroy_instance(baton.fid);
- /*
- * NB. If this command failed and we are relying on lvmetad to have an
- * *exact* image of the system, the lvmetad instance that went out of
- * sync needs to be killed.
- */
if (!lvmetad_pv_found((const struct id *) &dev->pvid, dev, lvmcache_fmt(info),
label->sector, baton.vg, handler)) {
release_vg(baton.vg);
@@ -1749,13 +1744,13 @@ static int _lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler
struct dev_iter *iter;
struct device *dev;
daemon_reply reply;
- int r = 1;
char *future_token;
const char *reason;
int was_silent;
int replacing_other_update = 0;
int replaced_update = 0;
int retries = 0;
+ int ret = 1;
if (!lvmetad_used()) {
log_error("Cannot proceed since lvmetad is not active.");
@@ -1813,7 +1808,7 @@ static int _lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler
log_debug_lvmetad("Telling lvmetad to clear its cache");
reply = _lvmetad_send(cmd, "pv_clear_all", NULL);
if (!_lvmetad_handle_reply(reply, "pv_clear_all", "", NULL))
- r = 0;
+ ret = 0;
daemon_reply_destroy(reply);
was_silent = silent_mode();
@@ -1821,33 +1816,38 @@ static int _lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler
while ((dev = dev_iter_get(iter))) {
if (sigint_caught()) {
- r = 0;
+ ret = 0;
stack;
break;
}
if (!lvmetad_pvscan_single(cmd, dev, handler, ignore_obsolete))
- r = 0;
+ ret = 0;
}
init_silent(was_silent);
dev_iter_destroy(iter);
+ if (!ret)
+ lvmetad_set_disabled(cmd, LVMETAD_DISABLE_REASON_SCANERROR);
+
_lvmetad_token = future_token;
- if (!_token_update(NULL))
+ if (!_token_update(NULL)) {
+ log_error("Failed to update lvmetad token after device scan.");
return 0;
+ }
/*
* If lvmetad is disabled, and no lvm1 metadata was seen and no
* duplicate PVs were seen, then re-enable lvmetad.
*/
- if (lvmetad_is_disabled(cmd, &reason) &&
+ if (ret && lvmetad_is_disabled(cmd, &reason) &&
!lvmcache_found_duplicate_pvs() && !_found_lvm1_metadata) {
log_debug_lvmetad("Enabling lvmetad which was previously disabled.");
lvmetad_clear_disabled(cmd);
}
- return r;
+ return ret;
}
int lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler handler, int do_wait)
@@ -2451,6 +2451,9 @@ int lvmetad_is_disabled(struct cmd_context *cmd, const char **reason)
} else if (strstr(reply_reason, LVMETAD_DISABLE_REASON_DUPLICATES)) {
*reason = "duplicate PVs were found";
+ } else if (strstr(reply_reason, LVMETAD_DISABLE_REASON_SCANERROR)) {
+ *reason = "scanning devices failed";
+
} else {
*reason = "<unknown>";
}
6 years, 10 months
master - lvmcache: use active LVs and device sizes to choose between duplicates
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=49d9582bed338d...
Commit: 49d9582bed338dc555b616bcc9de20fafd00ce2d
Parent: d4e434d1e6082ff4d448f4fbc03962c6f0926da4
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Mar 29 13:29:39 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
lvmcache: use active LVs and device sizes to choose between duplicates
If duplicate devices exist for a PV, and one device's
size matches the PV size, but the other doesn't, then
prefer the matching device.
If one device is used by an active LV, prefer that device.
---
lib/cache/lvmcache.c | 90 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 76 insertions(+), 14 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index f04f7ea..fe2ad07 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -816,15 +816,19 @@ static void _choose_preferred_devs(struct cmd_context *cmd,
struct dm_list *add_cache_devs)
{
char uuid[64] __attribute__((aligned(8)));
+ const char *reason = "none";
struct dm_list altdevs;
struct dev_types *dt = cmd->dev_types;
struct device_list *devl, *devl_safe, *alt, *del;
struct lvmcache_info *info;
struct device *dev1, *dev2;
uint32_t dev1_major, dev1_minor, dev2_major, dev2_minor;
+ uint64_t info_size, dev1_size, dev2_size;
int in_subsys1, in_subsys2;
int is_dm1, is_dm2;
int has_fs1, has_fs2;
+ int has_lv1, has_lv2;
+ int same_size1, same_size2;
int change;
/*
@@ -880,6 +884,14 @@ next:
dev2_major = MAJOR(dev2->dev);
dev2_minor = MINOR(dev2->dev);
+ if (!dev_get_size(dev1, &dev1_size))
+ dev1_size = 0;
+ if (!dev_get_size(dev2, &dev2_size))
+ dev2_size = 0;
+
+ has_lv1 = (dev1->flags & DEV_USED_FOR_LV) ? 1 : 0;
+ has_lv2 = (dev2->flags & DEV_USED_FOR_LV) ? 1 : 0;
+
in_subsys1 = dev_subsystem_part_major(dt, dev1);
in_subsys2 = dev_subsystem_part_major(dt, dev2);
@@ -889,44 +901,94 @@ next:
has_fs1 = dm_device_has_mounted_fs(dev1_major, dev1_minor);
has_fs2 = dm_device_has_mounted_fs(dev2_major, dev2_minor);
- log_debug_cache("PV %s compare duplicates %s and %s",
- devl->dev->pvid, dev_name(dev1), dev_name(dev2));
-
- log_debug_cache("dup dev1 %s subsys %d dm %d fs %d",
- dev_name(dev1), in_subsys1, is_dm1, has_fs1);
- log_debug_cache("dup dev2 %s subsys %d dm %d fs %d",
- dev_name(dev2), in_subsys2, is_dm2, has_fs2);
+ info_size = info->device_size >> SECTOR_SHIFT;
+ same_size1 = (dev1_size == info_size);
+ same_size2 = (dev2_size == info_size);
+
+ log_debug_cache("PV %s compare duplicates: %s %u:%u. %s %u:%u.",
+ devl->dev->pvid,
+ dev_name(dev1), dev1_major, dev1_minor,
+ dev_name(dev2), dev2_major, dev2_minor);
+
+ log_debug_cache("PV %s: wants size %llu. %s is %llu. %s is %llu.",
+ devl->dev->pvid,
+ (unsigned long long)info_size,
+ dev_name(dev1), (unsigned long long)dev1_size,
+ dev_name(dev2), (unsigned long long)dev2_size);
+
+ log_debug_cache("PV %s: %s %s subsystem. %s %s subsystem.",
+ devl->dev->pvid,
+ dev_name(dev1), in_subsys1 ? "is in" : "is not in",
+ dev_name(dev2), in_subsys2 ? "is in" : "is not in");
+
+ log_debug_cache("PV %s: %s %s dm. %s %s dm.",
+ devl->dev->pvid,
+ dev_name(dev1), is_dm1 ? "is" : "is not",
+ dev_name(dev2), is_dm2 ? "is" : "is not");
+
+ log_debug_cache("PV %s: %s %s mounted fs. %s %s mounted fs.",
+ devl->dev->pvid,
+ dev_name(dev1), has_fs1 ? "has" : "has no",
+ dev_name(dev2), has_fs2 ? "has" : "has no");
+
+ log_debug_cache("PV %s: %s %s LV. %s %s LV.",
+ devl->dev->pvid,
+ dev_name(dev1), has_lv1 ? "is used for" : "is not used for",
+ dev_name(dev2), has_lv2 ? "is used for" : "is not used for");
change = 0;
- if (has_fs1 && !has_fs2) {
+ if (has_lv1 && !has_lv2) {
/* keep 1 */
+ reason = "device is used by LV";
+ } else if (has_lv2 && !has_lv1) {
+ /* change to 2 */
+ change = 1;
+ reason = "device is used by LV";
+ } else if (same_size1 && !same_size2) {
+ /* keep 1 */
+ reason = "device size is correct";
+ } else if (same_size2 && !same_size1) {
+ /* change to 2 */
+ change = 1;
+ reason = "device size is correct";
+ } else if (has_fs1 && !has_fs2) {
+ /* keep 1 */
+ reason = "device has fs mounted";
} else if (has_fs2 && !has_fs1) {
/* change to 2 */
change = 1;
+ reason = "device has fs mounted";
} else if (is_dm1 && !is_dm2) {
/* keep 1 */
+ reason = "device is in dm subsystem";
} else if (is_dm2 && !is_dm1) {
/* change to 2 */
change = 1;
+ reason = "device is in dm subsystem";
} else if (in_subsys1 && !in_subsys2) {
/* keep 1 */
+ reason = "device is in subsystem";
} else if (in_subsys2 && !in_subsys1) {
/* change to 2 */
change = 1;
+ reason = "device is in subsystem";
+ } else {
+ reason = "device was seen first";
}
if (change) {
dev1 = dev2;
alt = devl;
}
- }
- id_write_format((const struct id *)info->dev->pvid, uuid, sizeof(uuid));
+ id_write_format((const struct id *)dev1->pvid, uuid, sizeof(uuid));
+ log_warn("WARNING: PV %s prefers device %s because %s.", uuid, dev_name(dev1), reason);
+ }
if (dev1 != info->dev) {
- log_warn("PV %s is using preferred device %s, changed from %s",
- uuid, dev_name(dev1), dev_name(info->dev));
+ log_debug_cache("PV %s: switching to device %s instead of device %s.",
+ dev1->pvid, dev_name(dev1), dev_name(info->dev));
/*
* Move the preferred device from altdevs to add_cache_devs.
* Create a del_cache_devs entry for the current lvmcache
@@ -939,9 +1001,9 @@ next:
del->dev = info->dev;
dm_list_add(del_cache_devs, &del->list);
}
+
} else {
- log_warn("PV %s is using preferred device %s",
- uuid, dev_name(info->dev));
+ log_debug_cache("PV %s: keeping current device %s.", dev1->pvid, dev_name(info->dev));
}
/*
6 years, 10 months
master - pvs: new attr and field for unchosen duplicate device
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d4e434d1e6082f...
Commit: d4e434d1e6082ff4d448f4fbc03962c6f0926da4
Parent: d3d13e134af15611c3f12107aa1627b12110a974
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Apr 29 14:42:14 2016 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 6 09:00:00 2016 -0500
pvs: new attr and field for unchosen duplicate device
When there are duplicate devices for a PV, one device
is preferred and chosen to exist in the VG. The other
devices are not used by lvm, but are displayed by pvs
with a new PV attr "d", indicating that they are
unchosen duplicate PVs.
The "duplicate" reporting field is set to "duplicate"
when the PV is an unchosen duplicate, and that field
is blank for the chosen PV.
---
lib/cache/lvmcache.c | 11 +++++++++++
lib/cache/lvmcache.h | 2 ++
lib/metadata/pv.c | 11 ++++++++++-
lib/report/columns.h | 1 +
lib/report/properties.c | 2 ++
lib/report/report.c | 10 ++++++++++
lib/report/values.h | 1 +
man/pvs.8.in | 4 ++--
8 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index ba87312..f04f7ea 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -782,6 +782,17 @@ int vg_has_duplicate_pvs(struct volume_group *vg)
return 0;
}
+int lvmcache_dev_is_unchosen_duplicate(struct device *dev)
+{
+ struct device_list *devl;
+
+ dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ if (devl->dev == dev)
+ return 1;
+ }
+ return 0;
+}
+
/*
* Compare _found_duplicate_devs entries with the corresponding duplicate dev
* in lvmcache. There may be multiple duplicates in _found_duplicate_devs for
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index 9b3c67b..45318b9 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -209,4 +209,6 @@ int lvmcache_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const ch
void lvmcache_lock_ordering(int enable);
+int lvmcache_dev_is_unchosen_duplicate(struct device *dev);
+
#endif
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 7ea993f..7169f31 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -236,6 +236,7 @@ char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv)
{
char *repstr;
int used = is_used_pv(pv);
+ int duplicate = lvmcache_dev_is_unchosen_duplicate(pv->dev);
if (!(repstr = dm_pool_zalloc(mem, 4))) {
log_error("dm_pool_alloc failed");
@@ -245,7 +246,15 @@ char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv)
/*
* An allocatable PV is always used, so we don't need to show 'u'.
*/
- repstr[0] = (pv->status & ALLOCATABLE_PV) ? 'a' : (used > 0) ? 'u' : '-';
+ if (duplicate)
+ repstr[0] = 'd';
+ else if (pv->status & ALLOCATABLE_PV)
+ repstr[0] = 'a';
+ else if (used > 0)
+ repstr[0] = 'u';
+ else
+ repstr[0] = '-';
+
repstr[1] = (pv->status & EXPORTED_VG) ? 'x' : '-';
repstr[2] = (pv->status & MISSING_PV) ? 'm' : '-';
diff --git a/lib/report/columns.h b/lib/report/columns.h
index b31b3f1..a17b3eb 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -148,6 +148,7 @@ FIELD(PVS, pv, NUM, "#PMdaUse", id, 0, pvmdasused, pv_mda_used_count, "Number of
FIELD(PVS, pv, SIZ, "BA Start", ba_start, 0, size64, pv_ba_start, "Offset to the start of PV Bootloader Area on the underlying device in current units.", 0)
FIELD(PVS, pv, SIZ, "BA Size", ba_size, 0, size64, pv_ba_size, "Size of PV Bootloader Area in current units.", 0)
FIELD(PVS, pv, BIN, "PInUse", id, 0, pvinuse, pv_in_use, "Set if PV is used.", 0)
+FIELD(PVS, pv, BIN, "Duplicate", id, 0, pvduplicate, pv_duplicate, "Set if PV is an unchosen duplicate.", 0)
FIELD(VGS, vg, STR, "Fmt", cmd, 0, vgfmt, vg_fmt, "Type of metadata.", 0)
FIELD(VGS, vg, STR, "VG UUID", id, 38, uuid, vg_uuid, "Unique identifier.", 0)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index 234712c..46f58be 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -194,6 +194,8 @@ GET_PV_NUM_PROPERTY_FN(pv_ba_size, SECTOR_SIZE * pv->ba_size)
#define _pv_ext_vsn_set prop_not_implemented_set
#define _pv_in_use_get prop_not_implemented_get
#define _pv_in_use_set prop_not_implemented_set
+#define _pv_duplicate_get prop_not_implemented_get
+#define _pv_duplicate_set prop_not_implemented_set
#define _pv_major_get prop_not_implemented_get
#define _pv_major_set prop_not_implemented_set
#define _pv_minor_get prop_not_implemented_get
diff --git a/lib/report/report.c b/lib/report/report.c
index 016d41d..3a58cee 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -3111,6 +3111,16 @@ static int _pvinuse_disp(struct dm_report *rh, struct dm_pool *mem,
return _binary_disp(rh, mem, field, used, GET_FIRST_RESERVED_NAME(pv_in_use_y), private);
}
+static int _pvduplicate_disp(struct dm_report *rh, struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private)
+{
+ const struct physical_volume *pv = (const struct physical_volume *) data;
+ int duplicate = lvmcache_dev_is_unchosen_duplicate(pv->dev);
+
+ return _binary_disp(rh, mem, field, duplicate, GET_FIRST_RESERVED_NAME(pv_duplicate_y), private);
+}
+
static int _vgpermissions_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
diff --git a/lib/report/values.h b/lib/report/values.h
index 4a6c235..652689b 100644
--- a/lib/report/values.h
+++ b/lib/report/values.h
@@ -53,6 +53,7 @@ FIELD_RESERVED_BINARY_VALUE(pv_allocatable, pv_allocatable, "", "allocatable")
FIELD_RESERVED_BINARY_VALUE(pv_exported, pv_exported, "", "exported")
FIELD_RESERVED_BINARY_VALUE(pv_missing, pv_missing, "", "missing")
FIELD_RESERVED_BINARY_VALUE(pv_in_use, pv_in_use, "", "used", "in use")
+FIELD_RESERVED_BINARY_VALUE(pv_duplicate, pv_duplicate, "", "duplicate")
/* Reserved values for VG fields */
FIELD_RESERVED_BINARY_VALUE(vg_extendable, vg_extendable, "", "extendable")
diff --git a/man/pvs.8.in b/man/pvs.8.in
index 0e0ad92..24d16fb 100644
--- a/man/pvs.8.in
+++ b/man/pvs.8.in
@@ -85,8 +85,8 @@ pv_mda_used_count, pvseg_start, and pvseg_size
.IP
With \fB\-\-segments\fP, any "pvseg_" prefixes are optional; otherwise any
"pv_" prefixes are optional. Columns mentioned in \fBvgs\fP(8) can also
-be chosen. The pv_attr bits are: (a)llocatable, e(x)ported, (m)issing and
-(u)sed (but not allocatable).
+be chosen. The pv_attr bits are: (a)llocatable, e(x)ported, (m)issing,
+(u)sed (but not allocatable), (d)uplicate.
.TP
.B \-\-segments
Produces one line of output for each contiguous allocation of space on each
6 years, 10 months