def create(self, sr_uuid, size): if self._checkmount(): raise xs_errors.XenError('SRExists') # Check none of the devices already in use by other PBDs if util.test_hostPBD_devs(self.session, sr_uuid, self.root): raise xs_errors.XenError('SRInUse') # Check serial number entry in SR records for dev in self.root.split(','): if util.test_scsiserial(self.session, dev): raise xs_errors.XenError('SRInUse') if not lvutil._checkVG(self.vgname): lvutil.createVG(self.root, self.vgname) if lvutil._checkLV(self.remotepath): raise xs_errors.XenError('SRExists') try: numdevs = len(self.root.split(',')) cmd = ["lvcreate", "-n", sr_uuid] if numdevs > 1: lowest = -1 for dev in self.root.split(','): stats = lvutil._getPVstats(dev) if lowest < 0 or stats['freespace'] < lowest: lowest = stats['freespace'] size_mb = (lowest / (1024 * 1024)) * numdevs # Add stripe parameter to command cmd += ["-i", str(numdevs), "-I", "2048"] else: stats = lvutil._getVGstats(self.vgname) size_mb = stats['freespace'] / (1024 * 1024) assert (size_mb > 0) cmd += ["-L", str(size_mb), self.vgname] text = util.pread(cmd) cmd = ["lvchange", "-ay", self.remotepath] text = util.pread(cmd) except util.CommandException as inst: raise xs_errors.XenError('LVMCreate', \ opterr='lv operation, error %d' % inst.code) except AssertionError: raise xs_errors.XenError('SRNoSpace', \ opterr='Insufficient space in VG %s' % self.vgname) try: util.pread2(["mkfs.ext4", "-F", self.remotepath]) except util.CommandException as inst: raise xs_errors.XenError('LVMFilesystem', \ opterr='mkfs failed error %d' % inst.code) #Update serial number string scsiutil.add_serial_record(self.session, self.sr_ref, \ scsiutil.devlist_to_serialstring(self.root.split(',')))
def create(self, sr_uuid, size): if self._checkmount(): raise xs_errors.XenError('SRExists') # Check none of the devices already in use by other PBDs if util.test_hostPBD_devs(self.session, self.root): raise xs_errors.XenError('SRInUse') # Check serial number entry in SR records for dev in self.root.split(','): if util.test_scsiserial(self.session, dev): raise xs_errors.XenError('SRInUse') if not lvutil._checkVG(self.vgname): systemroot = util.getrootdev() rootdev = self.root.split(',')[0] # Create PVs for each device for dev in self.root.split(','): if dev in [systemroot, '%s1'%systemroot, '%s2'%systemroot]: raise xs_errors.XenError('Rootdev', \ opterr=('Device %s contains core system files, ' \ + 'please use another device') % dev) if not os.path.exists(dev): raise xs_errors.XenError('InvalidDev', \ opterr=('Device %s does not exist') % dev) try: f = os.open("%s" % dev, os.O_RDWR | os.O_EXCL) except: raise xs_errors.XenError('SRInUse') os.close(f) try: # Overwrite the disk header, try direct IO first cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M", \ "count=100","oflag=direct"] util.pread2(cmd) except util.CommandException, inst: if inst.code == errno.EPERM: try: cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M", \ "count=100"] util.pread2(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMWrite', opterr='disk %s, error %d' % (dev, inst.code)) else: raise xs_errors.XenError('LVMWrite', opterr='disk %s, error %d' % (dev, inst.code)) if not lvutil._checkPV(dev): try: cmd = ["pvcreate", "--metadatasize", "10M", dev] util.pread2(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMPartCreate', opterr='disk %s, error %d' % (dev, inst.code))
def _runTests(vgName): """Unit testing""" print "Running unit tests..." if not vgName: print "Error: missing VG name param" return 1 if not lvutil._checkVG(vgName): print "Error: VG %s not found" % vgName return 1 j = Journaler(lvmcache.LVMCache(vgName)) if j.get("clone", "1"): print "get non-existing failed" return 1 j.create("clone", "1", "a") val = j.get("clone", "1") if val != "a": print "create-get failed" return 1 j.remove("clone", "1") if j.get("clone", "1"): print "remove failed" return 1 j.create("modify", "X", "831_3") j.create("modify", "Z", "831_4") j.create("modify", "Y", "53_0") val = j.get("modify", "X") if val != "831_3": print "create underscore_val failed" return 1 val = j.get("modify", "Y") if val != "53_0": print "create multiple id's failed" return 1 entries = j.getAll("modify") if not entries.get("X") or not entries.get("Y") or \ entries["X"] != "831_3" or entries["Y"] != "53_0": print "getAll failed: %s" % entries return 1 j.remove("modify", "X") val = j.getAll("modify") if val.get("X") or not val.get("Y") or val["Y"] != "53_0": print "remove(X) failed" return 1 j.remove("modify", "Y") j.remove("modify", "Z") if j.get("modify", "Y"): print "remove(Y) failed" return 1 if j.get("modify", "Z"): print "remove(Z) failed" return 1 print "All tests passed" return 0
def create(self, sr_uuid, size): if not self.isMaster: util.SMlog('sr_create blocked for non-master') raise xs_errors.XenError('LVMMaster') if lvutil._checkVG(self.vgname): raise xs_errors.XenError('SRExists') # Check none of the devices already in use by other PBDs if util.test_hostPBD_devs(self.session, self.root): raise xs_errors.XenError('SRInUse') # Check serial number entry in SR records for dev in self.root.split(','): if util.test_scsiserial(self.session, dev): raise xs_errors.XenError('SRInUse') systemroot = util.getrootdev() rootdev = self.root.split(',')[0] # Create PVs for each device for dev in self.root.split(','): if dev in [systemroot, '%s1'%systemroot, '%s2'%systemroot]: raise xs_errors.XenError('Rootdev', \ opterr=('Device %s contains core system files, ' \ + 'please use another device') % dev) if not os.path.exists(dev): raise xs_errors.XenError('InvalidDev', \ opterr=('Device %s does not exist') % dev) try: f = os.open("%s" % dev, os.O_RDWR | os.O_EXCL) except: raise xs_errors.XenError('SRInUse', \ opterr=('Device %s in use, please check your existing ' \ + 'SRs for an instance of this device') % dev) os.close(f) try: # Overwrite the disk header, try direct IO first cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M","count=100", \ "oflag=direct"] util.pread2(cmd) except util.CommandException, inst: if inst.code == errno.EPERM: try: # Overwrite the disk header, try normal IO cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M", \ "count=100"] util.pread2(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMWrite', \ opterr='device %s' % dev) else: raise xs_errors.XenError('LVMWrite', \ opterr='device %s' % dev)
def detach(self, sr_uuid): if not lvutil._checkVG(self.vgname): return # Deactivate any active LVs try: cmd = ["vgchange", "-an", self.SRmaster, self.vgname] util.pread2(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMUnMount', \ opterr='deactivating VG failed, VDIs in use?')
def create(self, sr_uuid, size): # THIS DRIVER IS DEPRECATED. RAISE. raise Exception( 'The `ext4` SR type is deprecated since XCP-ng 8.1.\n' 'Use the main `ext` driver instead. It will create an EXT4 filesystem now, ' 'not EXT3 anymore as it used to.') if self._checkmount(): raise xs_errors.XenError('SRExists') # Check none of the devices already in use by other PBDs if util.test_hostPBD_devs(self.session, sr_uuid, self.root): raise xs_errors.XenError('SRInUse') # Check serial number entry in SR records for dev in self.root.split(','): if util.test_scsiserial(self.session, dev): raise xs_errors.XenError('SRInUse') if not lvutil._checkVG(self.vgname): lvutil.createVG(self.root, self.vgname) if lvutil._checkLV(self.remotepath): raise xs_errors.XenError('SRExists') try: numdevs = len(self.root.split(',')) cmd = ["lvcreate", "-n", sr_uuid] if numdevs > 1: lowest = -1 for dev in self.root.split(','): stats = lvutil._getPVstats(dev) if lowest < 0 or stats['freespace'] < lowest: lowest = stats['freespace'] size_mb = (lowest / (1024 * 1024)) * numdevs # Add stripe parameter to command cmd += ["-i", str(numdevs), "-I", "2048"] else: stats = lvutil._getVGstats(self.vgname) size_mb = stats['freespace'] / (1024 * 1024) assert (size_mb > 0) cmd += ["-L", str(size_mb), self.vgname] text = util.pread(cmd) cmd = ["lvchange", "-ay", self.remotepath] text = util.pread(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMCreate', \ opterr='lv operation, error %d' % inst.code)
def create(self, sr_uuid, size): if self._checkmount(): raise xs_errors.XenError('SRExists') # Check none of the devices already in use by other PBDs if util.test_hostPBD_devs(self.session, sr_uuid, self.root): raise xs_errors.XenError('SRInUse') # Check serial number entry in SR records for dev in self.root.split(','): if util.test_scsiserial(self.session, dev): raise xs_errors.XenError('SRInUse') if not lvutil._checkVG(self.vgname): lvutil.createVG(self.root, self.vgname) if lvutil._checkLV(self.remotepath): raise xs_errors.XenError('SRExists') try: numdevs = len(self.root.split(',')) cmd = ["lvcreate", "-n", sr_uuid] if numdevs > 1: lowest = -1 for dev in self.root.split(','): stats = lvutil._getPVstats(dev) if lowest < 0 or stats['freespace'] < lowest: lowest = stats['freespace'] size_mb = (lowest / (1024 * 1024)) * numdevs # Add stripe parameter to command cmd += ["-i", str(numdevs), "-I", "2048"] else: stats = lvutil._getVGstats(self.vgname) size_mb = stats['freespace'] / (1024 * 1024) assert(size_mb > 0) cmd += ["-L", str(size_mb), self.vgname] text = util.pread(cmd) cmd = ["lvchange", "-ay", self.remotepath] text = util.pread(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMCreate', \ opterr='lv operation, error %d' % inst.code)
def attach(self, sr_uuid): if not util.match_uuid(sr_uuid) or not lvutil._checkVG(self.vgname): raise xs_errors.XenError('SRUnavailable', \ opterr='no such volume group: %s' % self.vgname) if self.isMaster: #Update SCSIid string util.SMlog("Calling devlist_to_serial") scsiutil.add_serial_record(self.session, self.sr_ref, \ scsiutil.devlist_to_serialstring(self.root.split(','))) # Set the block scheduler try: self.other_config = self.session.xenapi.SR.get_other_config(self.sr_ref) if self.other_config.has_key('scheduler') and self.other_config['scheduler'] != self.sched: self.sched = self.other_config['scheduler'] for dev in self.root.split(','): realdev = os.path.realpath(dev)[5:] util.set_scheduler(realdev, self.sched) except: pass