source: trunk/scripts/pv-fixup/pv-fixup @ 2266

Last change on this file since 2266 was 2266, checked in by price, 15 years ago

pv-fixup: update for non-clustered operation

File size: 2.9 KB
Line 
1#!/bin/sh
2exit #Not actually a script.
3
4VG=xenvg
5DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489
6HALFSIZETiB=5.23
7TMPDM=tmpfoo
8TMPDEV=/dev/mapper/$TMPDM
9TMPDM2=tmpbar
10TMPDEV2=/dev/mapper/$TMPDM2
11METADATASIZE=3.5m
12
13#  - pvresize the old PV to half the space
14pvresize --setphysicalvolumesize=${HALFSIZETiB}t $DISK
15
16#  - dmsetup create a device in the latter half
17dmstart=$(python -c "print int(($HALFSIZETiB + 0.01) * 1024 * 1024 * 1024 * 2)")
18dmlen=$(python -c "print int(($HALFSIZETiB - 0.03) * 1024 * 1024 * 1024 * 2)")
19#Foreach host:
20dmsetup create $TMPDM --table "0 $dmlen linear $DISK $dmstart"
21#done
22
23#  - pvcreate a temporary PV on the new device
24pvcreate $TMPDEV
25
26#  - vgextend with the temporary PV
27vgextend $VG $TMPDEV
28
29#  - pvmove all the LVs to the temporary PV
30
31yamlkeys () {
32  python -c 'if 1:
33    import yaml, sys
34    mm = yaml.load(sys.stdin.read())
35    for m in sorted(mm.iterkeys()): print m'
36}
37
38lvsleft () {
39  lvs -o name,devices xenvg \
40    | perl -lane "print \$F[0] if (\$F[1] =~ m|$DISK|)"
41}
42
43vmstolvs () {
44  perl -pe 's/^/d_/;s/$/_hda/'
45}
46
47totalsize () {
48  # handy for estimating time; output in GiB; pipe in a list of LVs
49  perl -pe 's.^.xenvg/.' \
50   | xargs lvs -o size --units=g \
51   | perl -lne '$total += $_; END { print $total; }'
52}
53
54movelv () {
55  echo pvmoving $1...
56  pvmove -i 10 -n $1 $2
57}
58
59ssh root@xvm remctl remote web listvms \
60 | yamlkeys
61 > runningvms
62LVM_SYSTEM_DIR=/root/lvm lvsleft \
63 | grep '^d_.*_hda$' \
64 | grep -v -xf <(vmstolvs <runningvms) \
65 > offvmlvs
66for lv in $(offvmlvs); do
67  LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
68done
69#FOREACH host:
70for lv in $(invirt-listvms | yamlkeys | vmstolvs); do
71  LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
72done
73#done
74
75ssh root@xvm remctl remote web listvms \
76 | perl -lne 'print if (s/^  cdrom: //)' \
77 > usedcdroms
78LVM_SYSTEM_DIR=/root/lvm lvsleft \
79 | grep ^image_ \
80 | grep -v -xf <(perl -pe "s|/dev/$VG/||" usedcdroms) \
81 > offcdlvs
82for lv in $(offcdlvs); do
83  LVM_SYSTEM_DIR=/root/lvm movelv $VG/$lv $DISK
84done
85
86# deal with $(cat usedcdroms)
87# deal with s_* LVs
88# deal with any remaining $(lvsleft)
89
90[ -z $(lvsleft) ]
91
92
93#  - pvremove the old PV
94vgreduce $VG $DISK
95pvremove $DISK
96
97#  - pvcreate a new PV in the old space,
98#     with --setphysicalvolumesize <half size>
99#     and with --metadatasize <huge>    (the point of this exercise)
100shortsize=$(python -c "print $HALFSIZETiB - 0.01")t
101dmsetup create $TMPDM2 --table "0 $((2 * 1024 * 4)) linear $DISK 0"
102pvcreate $TMPDEV2 --setphysicalvolumesize $shortsize --metadatasize $METADATASIZE
103dmsetup remove $TMPDM2
104pvscan
105vgextend $VG $DISK
106
107#  - pvmove all the LVs back
108
109#FOREACH host:
110for lv in $(lvs -o lv_name --noheadings $VG); do
111  movelv $VG/$lv $TMPDEV
112done
113#done
114
115# hopefully empty:
116lvs $VG -o lv_name,devices | grep $TMPDEV
117# if not, do some more movelv
118
119#  - pvremove the temporary PV
120vgreduce $VG $TMPDEV
121pvremove $TMPDEV
122dmsetup remove $TMPDM
123
124#  - pvresize the new PV to use the whole space
125pvresize $DISK
Note: See TracBrowser for help on using the repository browser.