1 # shared funcs for both blockd and filed
3 import os, sys, shutil, glob, argparse
5 XSEG_HOME="/root/archip/xseg/"
7 XSEGBD_SYSFS="/sys/bus/xsegbd/"
8 DEVICE_PREFIX="/dev/xsegbd"
9 BLOCKD_LOGS="/root/archip_logs/"
15 print "name\t\t\t\tsize"
17 for f in glob.glob(IMAGES + '*'):
18 print "%s\t\t\t\t%dM" % (os.path.basename(f), os.stat(f).st_size / 1024 / 1024)
21 except Exception, reason:
22 print >> sys.stderr, reason
25 def vlmc_create(args):
30 if size == None and snap == None:
31 print >> sys.stderr, "At least one of the size/snap args must be provided"
49 if snap != None and size < os.stat(snap).st_size:
50 print >> sys.stderr, "Given size smaller than snapshot volume size"
54 shutil.copy(snap, name)
56 f = os.open(name, os.O_WRONLY)
58 f = os.open(name, os.O_CREAT | os.O_WRONLY, 0755)
61 os.lseek(f, size - 1, os.SEEK_SET)
67 except Exception, reason:
68 print >> sys.stderr, reason
71 def vlmc_remove(args):
81 print "file doesn't exist"
85 os.unlink(IMAGES + '/' + name)
89 except Exception, reason:
90 print >> sys.stderr, reason
95 os.stat("/sys/bus/xsegbd")
96 except Exception, reason:
97 print >> sys.stderr, reason
100 def vlmc_resize(args):
105 old_dir = os.getcwd()
110 f = os.open(name, os.O_WRONLY, 0755)
111 if size >= os.stat(name).st_size:
112 os.lseek(f, size - 1, os.SEEK_SET)
115 os.ftruncate(f, size)
120 for f in os.listdir(XSEGBD_SYSFS + "devices/"):
121 d_id = open(XSEGBD_SYSFS + "devices/" + f + "/id").read().strip()
122 d_name = open(XSEGBD_SYSFS + "devices/"+ f + "/name").read().strip()
124 fd = os.open(XSEGBD_SYSFS + "devices/" + d_id +"/refresh", os.O_WRONLY)
129 except Exception, reason:
130 print >> sys.stderr, reason
137 execfile(os.path.expanduser("~/.xsegrc"), globals())
139 execfile(rc, globals())