Example #1
0
    def create(self, sr_uuid, vdi_uuid, size):
        if not self.sr.isMaster:
            util.SMlog('vdi_create blocked for non-master')
            raise xs_errors.XenError('LVMMaster')

        try:
            mb = 1024L * 1024L
            size_mb = (long(size) + mb - 1L) / mb # round up
            # Rather than bailing out for small sizes, just round up to 1 MiB. The
            # LVM code will round up to the nearest PE size anyway (probably 4 MiB)
            if size_mb == 0:
                size_mb = 1
            
            if lvutil._checkLV(self.path):
                raise xs_errors.XenError('VDIExists')

            # Verify there's sufficient space for the VDI
            stats = lvutil._getVGstats(self.sr.vgname)
            freespace = stats['physical_size'] - stats['physical_utilisation']
            if freespace < long(size):
                raise xs_errors.XenError('SRNoSpace')              

            cmd = ["lvcreate", "-n", self.lvname, "-L", str(size_mb), \
                   self.sr.vgname]
            text = util.pread2(cmd)

            cmd = ["lvchange", "-an", self.path]
            text = util.pread2(cmd)

            self.size = lvutil._getLVsize(self.path)
            self.utilisation = self.size
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMCreate', \
                  opterr='lv operation failed error is %d' % inst.code)
Example #2
0
def do_trim(session, args):
    """Attempt to trim the given LVHDSR"""
    util.SMlog("do_trim: %s" % args)
    sr_uuid = args["sr_uuid"]
    os.environ['LVM_SYSTEM_DIR'] = MASTER_LVM_CONF

    if TRIM_CAP not in util.sr_get_capability(sr_uuid):
        util.SMlog("Trim command ignored on unsupported SR %s" % sr_uuid)
        err_msg = {
            ERROR_CODE_KEY: 'UnsupportedSRForTrim',
            ERROR_MSG_KEY: 'Trim on [%s] not supported' % sr_uuid
        }
        return to_xml(err_msg)

    # Lock SR, get vg empty space details
    sr_lock = lock.Lock(vhdutil.LOCK_TYPE_SR, sr_uuid)
    got_lock = False
    for i in range(LOCK_RETRY_ATTEMPTS):
        got_lock = sr_lock.acquireNoblock()
        if got_lock:
            break
        time.sleep(LOCK_RETRY_INTERVAL)

    if got_lock:
        try:
            vg_name = _vg_by_sr_uuid(sr_uuid)
            lv_name = sr_uuid + TRIM_LV_TAG
            lv_path = _lvpath_by_vg_lv_name(vg_name, lv_name)

            # Clean trim LV in case the previous trim attemp failed
            if lvutil.exists(lv_path):
                lvutil.remove(lv_path)

            #Check if VG limits are enough for creating LV.
            stats = lvutil._getVGstats(vg_name)
            if (stats['freespace'] < lvutil.LVM_SIZE_INCREMENT):
                util.SMlog("No space to claim on a full SR %s" % sr_uuid)
                err_msg = {
                    ERROR_CODE_KEY: 'Trim failed on full SR',
                    ERROR_MSG_KEY: 'No space to claim on a full SR'
                }
                result = to_xml(err_msg)
            else:
                # Perform a lvcreate, blkdiscard and lvremove to
                # trigger trim on the array
                lvutil.create(lv_name, 0, vg_name, size_in_percentage="100%F")
                cmd = ["/usr/sbin/blkdiscard", "-v", lv_path]
                stdout = util.pread2(cmd)
                util.SMlog("Stdout is %s" % stdout)
                util.SMlog("Trim on SR: %s complete. " % sr_uuid)
                result = str(True)
        except util.CommandException, e:
            err_msg = {
                ERROR_CODE_KEY: 'TrimException',
                ERROR_MSG_KEY: e.reason
            }
            result = to_xml(err_msg)
        except:
Example #3
0
File: EXTSR.py Project: stormi/sm
    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(',')))
Example #4
0
def do_trim(session, args):
    """Attempt to trim the given LVHDSR"""
    util.SMlog("do_trim: %s" % args)
    sr_uuid = args["sr_uuid"]
    os.environ['LVM_SYSTEM_DIR'] = MASTER_LVM_CONF

    if TRIM_CAP not in util.sr_get_capability(sr_uuid):
        util.SMlog("Trim command ignored on unsupported SR %s" % sr_uuid)
        err_msg = {ERROR_CODE_KEY: 'UnsupportedSRForTrim',
                   ERROR_MSG_KEY: 'Trim on [%s] not supported' % sr_uuid}
        return to_xml(err_msg)

    # Lock SR, get vg empty space details
    sr_lock = lock.Lock(vhdutil.LOCK_TYPE_SR, sr_uuid)
    got_lock = False
    for i in range(LOCK_RETRY_ATTEMPTS):
        got_lock = sr_lock.acquireNoblock()
        if got_lock:
            break
        time.sleep(LOCK_RETRY_INTERVAL)

    if got_lock:
        try:
            vg_name = _vg_by_sr_uuid(sr_uuid)
            lv_name = sr_uuid + TRIM_LV_TAG
            lv_path = _lvpath_by_vg_lv_name(vg_name, lv_name)

            # Clean trim LV in case the previous trim attemp failed
            if lvutil.exists(lv_path):
               lvutil.remove(lv_path)

            #Check if VG limits are enough for creating LV.
            stats = lvutil._getVGstats(vg_name)
            if (stats['freespace'] < lvutil.LVM_SIZE_INCREMENT):
                util.SMlog("No space to claim on a full SR %s" % sr_uuid)
                err_msg = {ERROR_CODE_KEY: 'Trim failed on full SR',
                           ERROR_MSG_KEY: 'No space to claim on a full SR'}
                result = to_xml(err_msg)
            else:
                # Perform a lvcreate, blkdiscard and lvremove to
                # trigger trim on the array
                lvutil.create(lv_name, 0, vg_name, size_in_percentage="100%F")
                cmd = ["/usr/sbin/blkdiscard", "-v", lv_path]
                stdout = util.pread2(cmd)
                util.SMlog("Stdout is %s" % stdout)
                util.SMlog("Trim on SR: %s complete. " % sr_uuid)
                result = str(True)
        except util.CommandException, e:
            err_msg = {
                ERROR_CODE_KEY: 'TrimException',
                ERROR_MSG_KEY: e.reason
            }
            result = to_xml(err_msg)
        except:
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    def scan(self, sr_uuid):
        if not self.isMaster:
            util.SMlog('sr_scan blocked for non-master')
            raise xs_errors.XenError('LVMMaster')

        self._loadbuffer()
        self._loadvdis()
        stats = lvutil._getVGstats(self.vgname)
        self.physical_size = stats['physical_size']
        self.physical_utilisation = stats['physical_utilisation']
        self.virtual_allocation = self.physical_utilisation
        # Update the SR record
        self._db_update()
        # Synchronise the VDIs
        scanrecord = SR.ScanRecord(self)
        # XXX: never forget VDI records to work around glitch where some
        # volumes temporarily disappeared
        scanrecord.synchronise_new()
        scanrecord.synchronise_existing()
Example #8
0
    def resize(self, sr_uuid, vdi_uuid, size):
        if not self.sr.isMaster:
            util.SMlog('vdi_resize blocked for non-master')
            raise xs_errors.XenError('LVMMaster')

        try:
            self.size = lvutil._getLVsize(self.path)
        except:
            raise xs_errors.XenError('VDIUnavailable', \
                  opterr='no such VDI %s' % self.path)

        size_mb = long(size) / (1024 * 1024)
        try:
            assert(size_mb >= self.size/(1024 * 1024))
            if size == self.size:
                self.size = lvutil._getLVsize(self.path)
                self.utilisation = self.size
                return super(LVMVDI, self).get_params()

            # Verify there's sufficient space for the VDI
            stats = lvutil._getVGstats(self.sr.vgname)
            freespace = stats['physical_size'] - stats['physical_utilisation']
            if freespace < long(size) - self.size:
                raise xs_errors.XenError('SRNoSpace')
            
            cmd = ["lvresize", "-L", str(size_mb), self.path]
            text = util.pread2(cmd)
            
            self.size = lvutil._getLVsize(self.path)
            self.utilisation = self.size
            self._db_update()
            
            return super(LVMVDI, self).get_params()
        
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMResize', \
                  opterr='lvresize failed error is %d' % inst.code)
Example #9
0
            for dev in self.root.split(',')[1:]:
                try:
                    cmd = ["vgextend", self.vgname, dev]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    # One of the PV args failed, delete SR
                    try:
                        cmd = ["vgremove", self.vgname]
                        util.pread2(cmd)                   
                    except:
                        pass
                    raise xs_errors.XenError('LVMGroupCreate')
        if lvutil._checkLV(self.remotepath):
            raise xs_errors.XenError('SRExists')
        try:
            stats = lvutil._getVGstats(self.vgname)
            size_mb = stats['freespace'] / (1024 * 1024)
            assert(size_mb > 0)
            cmd = ["lvcreate", "-n", sr_uuid, "-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)
        except AssertionError:
            raise xs_errors.XenError('SRNoSpace', \
                  opterr='Insufficient space in VG %s' % self.vgname)
Example #10
0
            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)
        except AssertionError:
            raise xs_errors.XenError('SRNoSpace', \
                  opterr='Insufficient space in VG %s' % self.vgname)

        try: