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= InstallPartitionDisks.get_partition_path_from_device( device, vars, log )
90 cmd = "pvdisplay %s | grep -q 'planetlab'" % lvm_partition
91 already_added= utils.sysexec_noerr(cmd, log)
94 log.write( "It appears %s is part of the volume group, continuing.\n" %
98 # just to be extra paranoid, ignore the device if it already has
99 # an lvm partition on it (new disks won't have this, and that is
100 # what this code is for, so it should be ok).
101 cmd = "sfdisk -l %s | grep -q 'Linux LVM'" % device
102 has_lvm= utils.sysexec_noerr(cmd, log)
104 log.write( "It appears %s has lvm already setup on it.\n" % device)
107 log.write("To paranoid to add %s to vservers lvm.\n" % device)
110 log.write( "Attempting to add %s to the volume group\n" % device )
112 if not InstallPartitionDisks.single_partition_device( device, vars, log ):
113 log.write( "Unable to partition %s, not using it.\n" % device )
116 log.write( "Successfully initialized %s\n" % device )
118 part_path= InstallPartitionDisks.get_partition_path_from_device( device,
120 if not InstallPartitionDisks.create_lvm_physical_volume( part_path,
122 log.write( "Unable to create lvm physical volume %s, not using it.\n" %
126 log.write( "Adding %s to list of devices to add to " \
127 "planetlab volume group.\n" % device )
129 extended_gb_size= extended_gb_size + gb_size
130 new_devices.append( part_path )
133 if len(new_devices) > 0:
135 log.write( "Extending planetlab volume group.\n" )
137 log.write( "Unmounting disks.\n" )
139 # backwards compat, though, we should never hit this case post PL 3.2
140 os.stat("%s/rcfs/taskclass"%SYSIMG_PATH)
141 utils.sysexec_noerr( "chroot %s umount /rcfs" % SYSIMG_PATH, log )
145 # umount in order to extend disk size
146 utils.sysexec_noerr( "umount %s/proc" % SYSIMG_PATH, log )
147 utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
148 utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
149 utils.sysexec( "vgchange -an", log )
151 vars['ROOT_MOUNTED']= 0
154 cmd = "vgextend planetlab %s" % string.join(new_devices," ")
155 if not utils.sysexec_noerr( cmd, log ):
156 log.write( "Failed to add physical volumes %s to " \
157 "volume group, continuing.\n" % string.join(new_devices," "))
161 # now, get the number of unused extents, and extend the vserver
162 # logical volume by that much.
164 InstallPartitionDisks.get_remaining_extents_on_vg( vars, log )
166 log.write( "Extending vservers logical volume.\n" )
167 utils.sysexec( "vgchange -ay", log )
168 cmd = "lvextend -l +%s %s" % (remaining_extents, PARTITIONS["vservers"])
169 if not utils.sysexec_noerr(cmd, log):
170 log.write( "Failed to extend vservers logical volume, continuing\n" )
174 log.write( "making the ext3 filesystem match new logical volume size.\n" )
175 if BOOT_CD_VERSION[0] == 2:
176 cmd = "resize2fs %s" % PARTITIONS["vservers"]
177 resize = utils.sysexec_noerr(cmd,log)
178 elif BOOT_CD_VERSION[0] == 3:
179 vars['ROOT_MOUNTED']= 1
180 cmd = "mount %s %s" % (PARTITIONS["root"],SYSIMG_PATH)
181 utils.sysexec_noerr( cmd, log )
182 cmd = "mount %s %s/vservers" % \
183 (PARTITIONS["vservers"],SYSIMG_PATH)
184 utils.sysexec_noerr( cmd, log )
185 cmd = "ext2online %s/vservers" % SYSIMG_PATH
186 resize = utils.sysexec_noerr(cmd,log)
187 utils.sysexec_noerr( "umount %s/vservers" % SYSIMG_PATH, log )
188 utils.sysexec_noerr( "umount %s" % SYSIMG_PATH, log )
189 vars['ROOT_MOUNTED']= 0
191 utils.sysexec( "vgchange -an", log )
194 log.write( "Failed to resize vservers partition, continuing.\n" )
198 log.write( "Extended vservers partition by %4.2f GB\n" %
204 log.write( "No new disk devices to add to volume group.\n" )