2 exit 1 #Not actually a script.
5 DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489
8 TMPDEV=/dev/mapper/$TMPDM
10 TMPDEV2=/dev/mapper/$TMPDM2
13 # - pvresize the old PV to half the space
14 pvresize --setphysicalvolumesize=${HALFSIZETiB}t $DISK
16 # - dmsetup create a device in the latter half
17 dmstart=$(python -c "print int(($HALFSIZETiB + 0.01) * 1024 * 1024 * 1024 * 2)")
18 dmlen=$(python -c "print int(($HALFSIZETiB - 0.03) * 1024 * 1024 * 1024 * 2)")
20 dmsetup create $TMPDM --table "0 $dmlen linear $DISK $dmstart"
23 # - pvcreate a temporary PV on the new device
26 # - vgextend with the temporary PV
29 # - pvmove all the LVs to the temporary PV
34 mm = yaml.load(sys.stdin.read())
35 for m in sorted(mm.iterkeys()): print m'
39 perl -pe 's/^/d_/;s/$/_hda/'
43 # handy for estimating time; output in GiB; pipe in a list of LVs
44 perl -pe 's.^.xenvg/.' \
45 | xargs lvs -o size --units=g \
46 | perl -lne '$total += $_; END { print $total; }'
50 lvs -o name,devices $VG \
51 | perl -lane "print \$F[0] if (\$F[1] =~ m|$DISK|)"
55 echo pvmoving $VG/$1...
56 pvmove -i 10 -n $VG/$1 $2
59 ssh root@xvm remctl remote web listvms \
62 LVM_SYSTEM_DIR=/root/lvm lvsleft \
64 | grep -v -xf <(vmstolvs <runningvms) \
66 for lv in $(offvmlvs); do
67 LVM_SYSTEM_DIR=/root/lvm movelv $lv $DISK
70 for lv in $(invirt-listvms | yamlkeys | vmstolvs \
71 | grep -xf <(LVM_SYSTEM_DIR=/root/lvm lvsleft)); do
72 LVM_SYSTEM_DIR=/root/lvm movelv $lv $DISK
76 ssh root@xvm remctl remote web listvms \
77 | perl -lne 'print if (s/^ cdrom: //)' \
79 LVM_SYSTEM_DIR=/root/lvm lvsleft \
81 | grep -v -xf <(perl -pe "s|/dev/$VG/||" usedcdroms) \
83 for lv in $(offcdlvs); do
84 LVM_SYSTEM_DIR=/root/lvm movelv $lv $DISK
87 # deal with $(cat usedcdroms)
89 # deal with any remaining $(lvsleft)
94 # - pvremove the old PV
95 LVM_SYSTEM_DIR=lvm vgreduce $VG $DISK
96 dmsetup create $TMPDM2 --table "0 $((2 * 1024 * 20)) linear $DISK 0"
99 # - pvcreate a new PV in the old space,
100 # with --setphysicalvolumesize <half size>
101 # and with --metadatasize <huge> (the point of this exercise)
102 shortsize=$(python -c "print $HALFSIZETiB - 0.01")t
103 pvcreate $TMPDEV2 --setphysicalvolumesize $shortsize --metadatasize $METADATASIZE
104 dmsetup remove $TMPDM2
106 LVM_SYSTEM_DIR=lvm vgextend $VG $DISK
108 # - pvmove all the LVs back
110 # Doing this part with CLVM again.
113 lvs -o name,devices $VG \
114 | perl -lane "print \$F[0] if (\$F[1] =~ m|$TMPDEV|)"
118 echo pvmoving $VG/$1...
120 pvmove -i 10 -n $VG/$1 $2
127 echo MOVING: $lv >>/var/log/lvm2.log
135 for lv in $(lvsleft); do
136 echo MOVING: $lv >>/var/log/lvm2.log
143 #set logging in /etc/lvm/lvm.conf
145 echo MARK: $(date) >>/var/log/lvm2.log
147 lvsleft | grep -xf <(invirt-listvms | yamlkeys | vmstolvs) \
148 | movestuff >>/root/lvm/movelv.log 2>&1
149 moveall >>/root/lvm/movelv.log 2>&1
152 sh -x status.sh 2>&1 | zwrite -c xvm-auto -i pvmove -O auto
157 #suffix=.return-1; mv /var/log/lvm2.log lvm/lvm2.$suffix.log; mv lvm/movelv{,.$suffix}.log
160 lvs $VG -o lv_name,devices | grep $TMPDEV
161 # if not, do some more movelv
163 # - pvremove the temporary PV
167 dmsetup remove $TMPDM
170 # - pvresize the new PV to use the whole space