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 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 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)