Example #1
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 #2
0
    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
Example #3
0
File: EXTSR.py Project: stormi/sm
    def attach(self, sr_uuid):
        if not self._checkmount():
            try:
                #Activate LV
                cmd = ['lvchange', '-ay', self.remotepath]
                util.pread2(cmd)

                # make a mountpoint:
                if not os.path.isdir(self.path):
                    os.makedirs(self.path)
            except util.CommandException as inst:
                raise xs_errors.XenError('LVMMount', \
                      opterr='Unable to activate LV. Errno is %d' % inst.code)

            try:
                util.pread(["fsck", "-a", self.remotepath])
            except util.CommandException as inst:
                if inst.code == 1:
                    util.SMlog(
                        "FSCK detected and corrected FS errors. Not fatal.")
                else:
                    raise xs_errors.XenError('LVMMount', \
                         opterr='FSCK failed on %s. Errno is %d' % (self.remotepath,inst.code))

            try:
                util.pread(["mount", self.remotepath, self.path])
            except util.CommandException as inst:
                raise xs_errors.XenError('LVMMount', \
                      opterr='Failed to mount FS. Errno is %d' % inst.code)

        self.attached = True

        #Update SCSIid string
        scsiutil.add_serial_record(self.session, self.sr_ref, \
                scsiutil.devlist_to_serialstring(self.root.split(',')))

        # Set the block scheduler
        for dev in self.root.split(','):
            self.block_setscheduler(dev)
Example #4
0
                if inst.code == 1:
                    util.SMlog("FSCK detected and corrected FS errors. Not fatal.")
                else:
                    raise xs_errors.XenError('LVMMount', \
                         opterr='FSCK failed on %s. Errno is %d' % (self.remotepath,inst.code))

            try:
                util.pread(["mount", self.remotepath, self.path])
            except util.CommandException, inst:
                raise xs_errors.XenError('LVMMount', \
                      opterr='Failed to mount FS. Errno is %d' % inst.code)

        self.attached = True

        #Update SCSIid string
        scsiutil.add_serial_record(self.session, self.sr_ref, \
                scsiutil.devlist_to_serialstring(self.root.split(',')))
        
        # Set the block scheduler
        for dev in self.root.split(','): self.block_setscheduler(dev)

    def detach(self, sr_uuid):
        super(EXTSR, self).detach(sr_uuid)
        try:
            # deactivate SR
            cmd = ["lvchange", "-an", self.remotepath]
            util.pread2(cmd)
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMUnMount', \
                  opterr='lvm -an failed errno is %d' % inst.code)

    def probe(self):
Example #5
0
                    util.SMlog(
                        "FSCK detected and corrected FS errors. Not fatal.")
                else:
                    raise xs_errors.XenError('LVMMount', \
                         opterr='FSCK failed on %s. Errno is %d' % (self.remotepath,inst.code))

            try:
                util.pread(["mount", self.remotepath, self.path])
            except util.CommandException, inst:
                raise xs_errors.XenError('LVMMount', \
                      opterr='Failed to mount FS. Errno is %d' % inst.code)

        self.attached = True

        #Update SCSIid string
        scsiutil.add_serial_record(self.session, self.sr_ref, \
                scsiutil.devlist_to_serialstring(self.root.split(',')))

        # Set the block scheduler
        for dev in self.root.split(','):
            self.block_setscheduler(dev)

    def detach(self, sr_uuid):
        super(EXTSR, self).detach(sr_uuid)
        try:
            # deactivate SR
            cmd = ["lvchange", "-an", self.remotepath]
            util.pread2(cmd)
        except util.CommandException, inst:
            raise xs_errors.XenError('LVMUnMount', \
                  opterr='lvm -an failed errno is %d' % inst.code)