3 # Copyright (c) 2003 Intel Corporation
6 # Copyright (c) 2004-2006 The Trustees of Princeton University
11 import InstallPartitionDisks
12 from Exceptions import *
21 Find any new large block devices we can add to the vservers volume group
23 Expect the following variables to be set:
24 SYSIMG_PATH the path where the system image will be mounted
25 BOOT_CD_VERSION A tuple of the current bootcd version
26 MINIMUM_DISK_SIZE any disks smaller than this size, in GB, are not used
28 Set the following variables upon successfully running:
29 ROOT_MOUNTED the node root file system is mounted
32 log.write( "\n\nStep: Checking for unused disks to add to LVM.\n" )
34 # make sure we have the variables we need
36 BOOT_CD_VERSION= vars["BOOT_CD_VERSION"]
37 if BOOT_CD_VERSION == "":
38 raise ValueError, "BOOT_CD_VERSION"
40 SYSIMG_PATH= vars["SYSIMG_PATH"]
42 raise ValueError, "SYSIMG_PATH"
44 MINIMUM_DISK_SIZE= int(vars["MINIMUM_DISK_SIZE"])
46 PARTITIONS= vars["PARTITIONS"]
47 if PARTITIONS == None:
48 raise ValueError, "PARTITIONS"
51 raise BootManagerException, "Missing variable in vars: %s\n" % var
52 except ValueError, var:
53 raise BootManagerException, "Variable in vars, shouldn't be: %s\n" % var
55 all_devices= systeminfo.get_block_device_list(vars, log)
57 # find out if there are unused disks in all_devices that are greater
58 # than old cds need extra utilities to run lvm
59 if BOOT_CD_VERSION[0] == 2:
60 compatibility.setup_lvm_2x_cd( vars, log )
62 # will contain the new devices to add to the volume group
65 # total amount of new space in gb
68 for device in all_devices.keys():
70 (major,minor,blocks,gb_size,readonly)= all_devices[device]
72 if device[:14] == "/dev/planetlab":
73 log.write( "Skipping device %s in volume group.\n" % device )
77 log.write( "Skipping read only device %s\n" % device )
80 if gb_size < MINIMUM_DISK_SIZE:
81 log.write( "Skipping too small device %s (%4.2f)\n" %
85 log.write( "Checking device %s to see if it is part " \
86 "of the volume group.\n" % device )
88 # this is the lvm partition, if it exists on that device
89 lvm_partition= "%s1" % device
90 cciss_lvm_partition= "%sp1" % device
91 cmd = "pvdisplay %s | grep -q 'planetlab'"
93 already_added= utils.sysexec_noerr(cmd % lvm_partition, log)
94 cciss_already_added= utils.sysexec_noerr(cmd % cciss_lvm_partition, log)
96 if already_added or cciss_already_added:
97 log.write( "It appears %s is part of the volume group, continuing.\n" %
101 # just to be extra paranoid, ignore the device if it already has
102 # an lvm partition on it (new disks won't have this, and that is
103 # what this code is for, so it should be ok).
104 cmd = "sfdisk -l %s | grep -q 'Linux LVM'" % device
105 has_lvm= utils.sysexec_noerr(cmd, log)
107 log.write( "It appears %s has lvm already setup on it.\n" % device)
110 log.write("To paranoid to add %s to vservers lvm.\n" % device)
113 log.write( "Attempting to add %s to the volume group\n" % device )
115 if not InstallPartitionDisks.single_partition_device( device, vars, log ):
116 log.write( "Unable to partition %s, not using it.\n" % device )
119 log.write( "Successfully initialized %s\n" % device )
121 part_path= InstallPartitionDisks.get_partition_path_from_device( device,
123 if not InstallPartitionDisks.create_lvm_physical_volume( part_path,
125 log.write( "Unable to create lvm physical volume %s, not using it.\n" %
129 log.write( "Adding %s to list of devices to add to " \
130 "planetlab volume group.\n" % device )
132 extended_gb_size= extended_gb_size + gb_size
133 new_devices.append( part_path )
136 if len(new_devices) > 0:
138 log.write( "Extending planetlab volume group.\n" )
140 log.write( "Unmounting disks.\n" )
142 # backwards compat, though, we should never hit this case post PL 3.2
143 os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
144 utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
148 # umount in order to extend disk size
149 utils.sysexec_noerr( "umount %s/proc" % SYSIMG_PATH, log )
150 utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
151 utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
152 utils.sysexec( "vgchange -an", log )
154 vars['ROOT_MOUNTED']= 0
157 cmd = "vgextend planetlab %s" % string.join(new_devices," ")
158 if not utils.sysexec_noerr( cmd, log ):
159 log.write( "Failed to add physical volumes %s to " \
160 "volume group, continuing.\n" % string.join(new_devices," "))
164 # now, get the number of unused extents, and extend the vserver
165 # logical volume by that much.
167 InstallPartitionDisks.get_remaining_extents_on_vg( vars, log )
169 log.write( "Extending vservers logical volume.\n" )
170 utils.sysexec( "vgchange -ay", log )
171 cmd = "lvextend -l +%s %s" % (remaining_extents, PARTITIONS["vservers"])
172 if not utils.sysexec_noerr(cmd, log):
173 log.write( "Failed to extend vservers logical volume, continuing\n" )
177 log.write( "making the ext3 filesystem match new logical volume size.\n" )
178 if BOOT_CD_VERSION[0] == 2:
179 cmd = "resize2fs %s" % PARTITIONS["vservers"]
180 resize = utils.sysexec_noerr(cmd,log)
181 elif BOOT_CD_VERSION[0] == 3:
182 vars['ROOT_MOUNTED']= 1
183 cmd = "mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH)
184 utils.sysexec_noerr( cmd, log )
185 cmd = "mount %s %s/vservers" % \
186 (PARTITIONS["vservers"],SYSIMG_PATH)
187 utils.sysexec_noerr( cmd, log )
188 cmd = "ext2online %s/vservers" % SYSIMG_PATH
189 resize = utils.sysexec_noerr(cmd,log)
190 utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
191 utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
192 vars['ROOT_MOUNTED']= 0
194 utils.sysexec( "vgchange -an", log )
197 log.write( "Failed to resize vservers partition, continuing.\n" )
201 log.write( "Extended vservers partition by %4.2f GB\n" %
207 log.write( "No new disk devices to add to volume group.\n" )