[2239] | 1 | #!/bin/sh |
---|
| 2 | exit 1 #Not actually a script. |
---|
| 3 | |
---|
| 4 | VG=xenvg |
---|
[2240] | 5 | DISK=/dev/mapper/36090a028407d6e2b2589a45cdb971489 |
---|
| 6 | HALFSIZETiB=5.23 |
---|
[2239] | 7 | TMPDM=tmpfoo |
---|
| 8 | TMPDEV=/dev/mapper/$TMPDM |
---|
| 9 | TMPDM2=tmpbar |
---|
| 10 | TMPDEV2=/dev/mapper/$TMPDM2 |
---|
| 11 | METADATASIZE=3.5m |
---|
| 12 | |
---|
| 13 | # - pvresize the old PV to half the space |
---|
| 14 | pvresize --setphysicalvolumesize=${HALFSIZETiB}t $DISK |
---|
| 15 | |
---|
| 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.02) * 1024 * 1024 * 1024 * 2)") |
---|
| 19 | #foreach host: |
---|
| 20 | dmsetup create $TMPDM --table "0 $dmlen linear $DISK $dmstart" |
---|
| 21 | #done |
---|
| 22 | |
---|
| 23 | # - pvcreate a temporary PV on the new device |
---|
| 24 | pvcreate $TMPDEV |
---|
| 25 | |
---|
| 26 | # - vgextend with the temporary PV |
---|
| 27 | vgextend $VG $TMPDEV |
---|
| 28 | |
---|
| 29 | # - pvmove all the LVs to the temporary PV |
---|
| 30 | # (something like |
---|
| 31 | # for lv in $(LVs for running VMs on this host); do |
---|
| 32 | # #some lvchange -a commands |
---|
| 33 | # pvmove -n $lv <oldpv> <newpv> |
---|
| 34 | # #possibly more lvchange -a to restore old state |
---|
| 35 | # done) |
---|
| 36 | |
---|
| 37 | movelv () { |
---|
| 38 | echo pvmoving $1... |
---|
| 39 | lvchange -an $1 |
---|
| 40 | pvmove -i 10 -n $1 $2 |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | #FOREACH host: |
---|
| 44 | for lv in $(lvs -o lv_name --noheadings $VG); do |
---|
| 45 | movelv $VG/$lv $DISK |
---|
| 46 | done |
---|
| 47 | #done |
---|
| 48 | |
---|
| 49 | # hopefully empty: |
---|
| 50 | lvs $VG -o lv_name,devices | grep $DISK |
---|
| 51 | # if not, do some more movelv |
---|
| 52 | |
---|
| 53 | # This is possible if some LVs were used on more than one host during |
---|
| 54 | # migration. |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | # - pvremove the old PV |
---|
| 58 | vgreduce $VG $DISK |
---|
| 59 | pvremove $DISK |
---|
| 60 | |
---|
| 61 | # - pvcreate a new PV in the old space, |
---|
| 62 | # with --setphysicalvolumesize <half size> |
---|
| 63 | # and with --metadatasize <huge> (the point of this exercise) |
---|
| 64 | shortsize=$(python -c "print $HALFSIZETiB - 0.01")t |
---|
| 65 | dmsetup create $TMPDM2 --table "0 $((2 * 1024 * 4)) linear $DISK 0" |
---|
| 66 | pvcreate $TMPDEV2 --setphysicalvolumesize $shortsize --metadatasize $METADATASIZE |
---|
| 67 | dmsetup remove $TMPDM2 |
---|
| 68 | pvscan |
---|
| 69 | vgextend $VG $DISK |
---|
| 70 | |
---|
| 71 | # - pvmove all the LVs back |
---|
| 72 | |
---|
| 73 | #FOREACH host: |
---|
| 74 | for lv in $(lvs -o lv_name --noheadings $VG); do |
---|
| 75 | movelv $VG/$lv $TMPDEV |
---|
| 76 | done |
---|
| 77 | #done |
---|
| 78 | |
---|
| 79 | # hopefully empty: |
---|
| 80 | lvs $VG -o lv_name,devices | grep $TMPDEV |
---|
| 81 | # if not, do some more movelv |
---|
| 82 | |
---|
| 83 | # - pvremove the temporary PV |
---|
| 84 | vgreduce $VG $TMPDEV |
---|
| 85 | pvremove $TMPDEV |
---|
| 86 | dmsetup remove $TMPDM |
---|
| 87 | |
---|
| 88 | # - pvresize the new PV to use the whole space |
---|
| 89 | pvresize $DISK |
---|