Skip to contentSkip to conversation

vgimportclone: script to import SAN snapshots and clones

PATCH New Mike Snitzer 3 participants 4 messages May 13, 2009 – May 14, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vgimportclone: script to import SAN snapshots and clones

Revised vgimportclone that should _hopefully_ be ready for inclussion in the LVM2 tree. Is installed as 'vgimportclone' and a man page is provided.

NOTE: this script will need to be adjusted slightly if it is to be married with older versions of LVM (which use the 'cache' config value rather than 'cache_dir').

--

 WHATS_NEW                |    1 +
 man/Makefile.in          |    4 +-
 man/lvm.8.in             |    3 +
 man/vgimportclone.8.in   |   56 ++++++++
 scripts/Makefile.in      |    2 +
 scripts/vgimportclone.sh |  326 ++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 390 insertions(+), 2 deletions(-)
WHATS_NEW +1 -0
index 7b5d249..5036b60 100644
@@ -1,5 +1,6 @@
 Version 2.02.46 - 
 ================================
+  Add vgimportclone and install it and the man page by default.
   Force max_lv restriction only for newly created LV.
   Remove unneeded import parameter from lv_create_empty.
   Merge lv_is_displayable and lv_is_visible functions.
man/Makefile.in +2 -2
index 1406dd9..4fde75b 100644
@@ -29,8 +29,8 @@ MAN8=lvchange.8 lvconvert.8 lvcreate.8 lvdisplay.8 lvextend.8 lvm.8 \
 	lvscan.8 pvchange.8 pvck.8 pvcreate.8 pvdisplay.8 pvmove.8 pvremove.8 \
 	pvresize.8 pvs.8 pvscan.8 vgcfgbackup.8 vgcfgrestore.8 vgchange.8 \
 	vgck.8 vgcreate.8 vgconvert.8 vgdisplay.8 vgexport.8 vgextend.8 \
-	vgimport.8 vgmerge.8 vgmknodes.8 vgreduce.8 vgremove.8 vgrename.8 \
-	vgs.8 vgscan.8 vgsplit.8 $(FSADMMAN)
+	vgimport.8 vgimportclone.8 vgmerge.8 vgmknodes.8 vgreduce.8 vgremove.8 \
+	vgrename.8 vgs.8 vgscan.8 vgsplit.8 $(FSADMMAN)
 MAN8CLUSTER=clvmd.8
 MAN8DM=dmsetup.8
 MAN5DIR=${mandir}/man5
man/lvm.8.in +3 -0
index 6bad5fc..d541fb5 100644
@@ -95,6 +95,8 @@ The following commands implement the core LVM functionality.
 .TP
 \fBvgimport\fP \(em Make exported volume groups known to the system.
 .TP
+\fBvgimportclone\fP \(em Rename VG and change associated VG and PV UUIDs.
+.TP
 \fBvgmerge\fP \(em Merge two volume groups.
 .TP
 \fBvgmknodes\fP \(em Recreate volume group directory and logical volume special files
@@ -307,6 +309,7 @@ All tools return a status code of zero on success or non-zero on failure.
 .BR vgdisplay (8),
 .BR vgextend (8),
 .BR vgimport (8),
+.BR vgimportclone (8),
 .BR vgmerge (8),
 .BR vgmknodes (8),
 .BR vgreduce (8),
man/vgimportclone.8.in new file +56 -0

56 lines not on this page · raw message

scripts/Makefile.in +2 -0
index 8a03500..e845cca 100644
@@ -20,6 +20,8 @@ include $(top_srcdir)/make.tmpl
 install:
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) lvm_dump.sh \
 		$(sbindir)/lvmdump
+	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) vgimportclone.sh \
+		$(sbindir)/vgimportclone
 ifeq ("@FSADM@", "yes")
 	$(INSTALL) -D $(OWNER) $(GROUP) -m 555 $(STRIP) fsadm.sh \
 		$(sbindir)/fsadm
scripts/vgimportclone.sh new file +326 -0

326 lines not on this page · raw message

#1 lore raw

PATCH v2 1/1 vgimportclone: script to import SAN snapshots and clones

Quoted 1 line · Mike Snitzer

+\fBvgimportclone\fP \(em Rename VG and change associated VG and PV UUIDs.

Can you find a way to say why without adding many more characters? I think this description should concentrate more on the 'why'.
Import & rename duplicated volume group (e.g. a hardware snapshot).

Quoted 1 line

+vgimportclone \- rename VG and change associated VG and PV UUIDs.

Ditto.

man/vgimportclone.8.in line 14

Quoted 4 lines
man/vgimportclone.8.in new file +4 -0
+is used to rename the VG associated with the specified PV(s) and change the
+associated VG and PV UUIDs.  These changes avoid duplicate VG(s) and
+PV(s) once the origin and snapshots are active simultaneously.  The primary
+application being HW snapshot restore.

Reorder the ideas there to introduce them in a more logical order?

hardware snapshot (for example)...duplicate name/uuids not permitted...so change and rename

The word 'restore' here makes no sense to me, I'm afraid.

man/vgimportclone.8.in line 21

Quoted 4 lines

+.I \-n|\-\-basevgname VolumeGroupName

man/vgimportclone.8.in new file +3 -0
+By default the snapshot VG will be renamed to the original name plus a
+numeric suffix to avoid duplicate naming (e.g. 'test_vg' would be renamed
+to 'test_vg.1').  This option will override the base VG name that is

I'm not keen on the dot in there. We don't put dots in any other names. I'm not keen on names like /dev/test_vg.1/lvol01

scripts/vgimportclone.sh line 83

Quoted 9 lines
scripts/vgimportclone.sh new file +9 -0
+    echo "Usage: ${SCRIPTNAME} [options] disk1 [disk2 ...]"
+    echo "    -n|--basevgname - Base name for the new volume group(s)"
+    echo "    -i|--import     - Import any exported volume group(s)"
+    echo "    -t|--test       - Run in test mode"
+    echo "    --quiet         - Suppress output"
+    echo "    -v|--verbose    - Set verbose level"
+    echo "    -d|--debug      - Set debug level"
+    echo "    --version       - Display version information"
+    echo "    -h|--help       - Display this help message"

Can you standardise this a bit?
Not disk1 but PhysicalVolumePath or PhysicalVolume (we're already inconsistent) (If we prefer PhysicalVolumePath1 [PhysicalVolumePath2] - I'm not sure - then we should change it everywhere in the tree.)

Quoted 1 line

+ "$RM" -r -- "${TMP_LVM_SYSTEM_DIR}"

(I suppose that's OK without -f.)

scripts/vgimportclone.sh line 231

Quoted 6 lines

+"$LVM" dumpconfig ${LVM_OPTS} | \
+"$AWK" -v DEV=${TMP_LVM_SYSTEM_DIR} -v CACHE=${TMP_LVM_SYSTEM_DIR}/cache \

scripts/vgimportclone.sh new file +4 -0
+                   '/^[[:space:]]*filter/{print ENVIRON["FILTER"];next} \
+                    /^[[:space:]]*scan/{print "scan = [ \"" DEV "\" ]";next} \
+                    /^[[:space:]]*cache_dir/{print "cache_dir = \"" CACHE "\"";next} \
+                    {print $0}' > ${LVMCONF}

Tools do still support the old 'cache' setting but it doesn't really matter if new stuff doesn't if it's not easy to do.

I hate to go on about security, but have you tested that the script does not misbehave even when you give it a PV with the nastiest set of characters you can imagine in it?

Might as well check this in now, anyway, and deal with any more things people file in-tree.

Alasdair

#2 lore raw
Quoted 7 lines · Alasdair G Kergon

man/vgimportclone.8.in line 21

Quoted 4 lines

+.I \-n|\-\-basevgname VolumeGroupName

man/vgimportclone.8.in new file +3 -0
+By default the snapshot VG will be renamed to the original name plus a
+numeric suffix to avoid duplicate naming (e.g. 'test_vg' would be renamed
+to 'test_vg.1').  This option will override the base VG name that is

I'm not keen on the dot in there. We don't put dots in any other names. I'm not keen on names like /dev/test_vg.1/lvol01

I just went with what Chris provided; didn't have strong feelings but I agree the dot is somewhat awkward. I'll drop the dot.

The dot aside; the getvgname() function needs some help as it lacks self-understanding of the fact that it produces ${BASE}$I names; and testvg1 will match testvg11 so testvg2 will be tried, testvg2 will match testvg26 so testvg3 will be tried, etc.

In the expected sequential case of 'vgimportclone'ing N clones it wouldn't be a problem but...

Quoted 3 lines

I hate to go on about security, but have you tested that the script does not misbehave even when you give it a PV with the nastiest set of characters you can imagine in it?

I have not personally tested with nasty names but Chris did based on my feedback that PV names like the following are technically valid:
pv_ugly="__\"!@#\$%^&*,()|@||'\\\"__pv1"

Chris contributed the code that symlinks the specified PV to $TMP_LVM_SYSTEM_DIR/vgimportX.

But I'll go over it. Are you concerned about security or functionality? Or both?

Chris anything to add here?

Quoted 2 lines

Might as well check this in now, anyway, and deal with any more things people file in-tree.

OK, I'll fix the other things you mentioned and do so.

Mike

#3 lore raw
Quoted 11 lines
Quoted 6 lines

I hate to go on about security, but have you tested that the script does not misbehave even when you give it a PV with the nastiest set of characters you can imagine in it?

I have not personally tested with nasty names but Chris did based on my feedback that PV names like the following are technically valid:
pv_ugly="__\"!@#\$%^&*,()|@||'\\\"__pv1"

Quoted 7 lines

Chris contributed the code that symlinks the specified PV to $TMP_LVM_SYSTEM_DIR/vgimportX.

But I'll go over it. Are you concerned about security or functionality? Or both?

Chris anything to add here?

Only that I've actually tried:
/dev/"__\"!@#\$%^&*,()|@||\\\""
/dev/*
/dev/''* (with trailing space and single quotes)
/dev/$* ^"

(and probably some others I've forgotten) as pv names and it handled them without issue. It only actually uses the pv names while it create symlinks from more sensible names (the $TMP_LVM_SYSTEM_DIR/vgimportX names) which lvm.conf can handle, so functionalitywise I don't see a problem. Securitywise, well I thought using /tmp/lvm/lvm.conf was safe so what do I know.

chris