2 # Lets a user loopback-mount a private fs of a given type.
3 # To use, configure the following vsys-attributes in addition to setting the vsys tag for the slice
4 # - vsys_privatefs_list -> comma-separated list of desired filesystems, e.g. xfs,btrfs
5 # - vsys_privatefs_size -> desired size in megabytes
11 vsys_config_dir = "/etc/planetlab/vsys-attributes"
13 sliceroot='/vservers/%s'%slicename
15 private_fs_config=os.path.join(vsys_config_dir,slicename,"vsys_privatefs_list")
16 private_fs_size_config=os.path.join(vsys_config_dir,slicename,"vsys_privatefs_size")
18 private_fs_str = open(private_fs_config).read().rstrip()
20 nonamespace_path = '/etc/vservers/%s/nonamespace'%slicename
21 if (not os.path.isfile(nonamespace_path)):
23 open(nonamespace_path,'w').close()
25 os.system('vserver %s stop'%slicename)
26 os.system('vserver %s start'%slicename)
27 print 'Reconfiguring slice for private mounts'
30 fs_lst = private_fs_str.split(',')
32 private_fs_size_str = open(private_fs_size_config).read().rstrip()
33 fs_size = int(private_fs_size_str)
39 print >>sys.stderr, "Please configure your private filesystems at PLC."
43 # XXX There's a race condition here. You could
44 # intervene between the creation of the image
45 # and the mount operation to replace the empty image
46 # with a rogue volume.
48 fs_file = '%s/pvtfs-%s'%(sliceroot,fs)
49 os.system('umount %s 2>&1>/dev/null'%fs_file)
51 sanity_check_cmd = 'cat /proc/mounts | grep %s | wc -l'%fs_file
52 sanity_check = os.popen(sanity_check_cmd).read().rstrip()
53 if int(sanity_check)!=0:
54 print 'Private fs could not be remounted. Please contact support.'
56 os.system('mkdir -p %s'%fs_file)
58 # This is the critical step
59 if (os.system('dd if=/dev/zero of=%s.img bs=1000000 count=%d'%(fs_file,fs_size))):
60 print 'Could not recycle private fs. Please contact support.'
63 os.system('mkfs.%s %s.img'%(fs,fs_file))
64 os.system('mount -o loop -t %s %s.img %s'%(fs, fs_file, fs_file))