lvmanip: handle second-segment failures
authorGreg Price <price@mit.edu>
Wed, 25 Mar 2009 23:23:45 +0000 (19:23 -0400)
committerGreg Price <price@mit.edu>
Wed, 25 Mar 2009 23:23:45 +0000 (19:23 -0400)
svn path=/trunk/scripts/pv-fixup/; revision=2274

lvmanip

diff --git a/lvmanip b/lvmanip
index aad381f..0bd06af 100644 (file)
--- a/lvmanip
+++ b/lvmanip
@@ -20,6 +20,10 @@ getfirstblock () {
 lvinfo () {
   perl -ne 'print if ( /^(\s*)'"$1"' \{/ ... /^$1\}/ )' $ARCHIVE
 }
 lvinfo () {
   perl -ne 'print if ( /^(\s*)'"$1"' \{/ ... /^$1\}/ )' $ARCHIVE
 }
+segment2 () {
+  perl -ne 'print if ( /^(\s*)segment2 \{/ ... /^$1\}/ )'
+}
+
 
 # Generate a dd command to copy the LV data to /dev/xenvg/$lv
 # Only works for single-segment LVs.
 
 # Generate a dd command to copy the LV data to /dev/xenvg/$lv
 # Only works for single-segment LVs.
@@ -40,3 +44,23 @@ ddlv () {
       skip=$(( $offset * 64 + 3 )) bs=64K count=$(( $length * 64 ))
   fi
 }
       skip=$(( $offset * 64 + 3 )) bs=64K count=$(( $length * 64 ))
   fi
 }
+
+# Generate a dd command to copy the LV data for the second segment.
+ddlv2 () {
+  lvname="$1"
+  if ! lvinfo $lvname | grep -q 'segment_count = 2'; then
+    echo "# WARNING: LV $lvname has other than two segments, skipping" >&2
+    return 1
+  fi
+  offset=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/"pv0", ([0-9]+)/)')
+  length=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/extent_count = ([0-9]+)/)')
+  seek=$(lvinfo $lvname | segment2 | perl -lne 'print $1 if (/start_extent = ([0-9]+)/)')
+
+  if [ -z "$offset" ]; then
+    echo "# WARNING: LV $lvname not found";
+  else
+    echo "# Extracting $lvname segment 2 from offset $offset PEs with length $length PEs"
+    echo dd if=$DISK of=/dev/xenvg/$lvname bs=64K \
+      skip=$(($offset*64 + 3)) count=$(($length*64)) seek=$(($seek*64))
+  fi
+}