Exemplo n.º 1
0
    def create(self, sr_uuid, vdi_uuid, size):
        if util.ioretry(lambda: util.pathexists(self.path)):
            raise xs_errors.XenError('VDIExists')

        overhead = 0
        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            overhead = vhdutil.calcOverheadFull(long(size))

        # Test the amount of actual disk space
        if ENFORCE_VIRT_ALLOC:
            self.sr._loadvdis()
            reserved = self.sr.virtual_allocation
            sr_size = self.sr._getsize()
            if (sr_size - reserved) < (long(size) + overhead):
                raise xs_errors.XenError('SRNoSpace')

        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            try:
                size = vhdutil.validate_and_round_vhd_size(long(size))
                mb = 1024L * 1024L
                size_mb = long(size) / mb
                util.ioretry(lambda: self._create(str(size_mb), self.path))
                self.size = util.ioretry(lambda: self._query_v(self.path))
            except util.CommandException, inst:
                raise xs_errors.XenError('VDICreate',
                        opterr='error %d' % inst.code)
Exemplo n.º 2
0
    def create(self, sr_uuid, vdi_uuid, size):
        if util.ioretry(lambda: util.pathexists(self.path)):
            raise xs_errors.XenError('VDIExists')

        overhead = 0
        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            overhead = vhdutil.calcOverheadFull(long(size))

        # Test the amount of actual disk space
        if ENFORCE_VIRT_ALLOC:
            self.sr._loadvdis()
            reserved = self.sr.virtual_allocation
            sr_size = self.sr._getsize()
            if (sr_size - reserved) < (long(size) + overhead):
                raise xs_errors.XenError('SRNoSpace')

        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            try:
                size = vhdutil.validate_and_round_vhd_size(long(size))
                mb = 1024L * 1024L
                size_mb = long(size) / mb
                util.ioretry(lambda: self._create(str(size_mb), self.path))
                self.size = util.ioretry(lambda: self._query_v(self.path))
            except util.CommandException, inst:
                raise xs_errors.XenError('VDICreate',
                        opterr='error %d' % inst.code)
Exemplo n.º 3
0
    def create(self, sr_uuid, vdi_uuid, size):
        """
        :param sr_uuid:
        :param vdi_uuid:
        :param size:
        :return:
        """
        if VERBOSE:
            util.SMlog(
                "rbdsr_vhd.RBDVHDVDI.create: sr_uuid = %s, vdi_uuid = %s, size = %s"
                % (sr_uuid, vdi_uuid, size))

        size = vhdutil.validate_and_round_vhd_size(long(size))

        if self.sr.provision == "thin":
            rbd_size = lvhdutil.calcSizeVHDLV(long(size))
        elif self.sr.provision == "thick":
            rbd_size = lvhdutil.calcSizeVHDLV(long(size))

        retval = super(RBDVHDVDI, self).create(sr_uuid, vdi_uuid, rbd_size)
        self._create_vhd_over_rbd(vdi_uuid, size, rbd_size)

        self.size = size
        self.session.xenapi.VDI.set_virtual_size(self.ref, str(size))
        self.session.xenapi.VDI.set_physical_utilisation(self.ref, str(size))

        return retval
Exemplo n.º 4
0
    def resize_online(self, sr_uuid, vdi_uuid, size):
        if not self.exists:
            raise xs_errors.XenError('VDIUnavailable', \
                  opterr='VDI %s unavailable %s' % (vdi_uuid, self.path))

        if self.vdi_type != vhdutil.VDI_TYPE_VHD:
            raise xs_errors.XenError('Unimplemented')

        if self.hidden:
            raise xs_errors.XenError('VDIUnavailable', opterr='hidden VDI')

        if size < self.size:
            util.SMlog('vdi_resize: shrinking not supported: ' + \
                    '(current size: %d, new size: %d)' % (self.size, size))
            raise xs_errors.XenError('VDISize', opterr='shrinking not allowed')

        if size == self.size:
            return VDI.VDI.get_params(self)

        # We already checked it is a VDI_TYPE_VHD
        size = vhdutil.validate_and_round_vhd_size(long(size))
        overhead = vhdutil.calcOverheadFull(long(size))

        # Test the amount of actual disk space
        if ENFORCE_VIRT_ALLOC:
            self.sr._loadvdis()
            reserved = self.sr.virtual_allocation
            sr_size = self.sr._getsize()
            delta = long(size - self.size)
            if (sr_size - reserved) < delta:
                raise xs_errors.XenError('SRNoSpace')
        jFile = JOURNAL_FILE_PREFIX + self.uuid
        try:
            vhdutil.setSizeVirt(self.path, size, jFile)
        except:
            # Revert the operation
            vhdutil.revert(self.path, jFile)
            raise xs_errors.XenError('VDISize',
                                     opterr='resize operation failed')

        old_size = self.size
        self.size = vhdutil.getSizeVirt(self.path)
        st = util.ioretry(lambda: os.stat(self.path))
        self.utilisation = long(st.st_size)

        self._db_update()
        self.sr._update(self.sr.uuid, self.size - old_size)
        super(FileVDI, self).resize_cbt(self.sr.uuid, self.uuid, self.size)
        return VDI.VDI.get_params(self)
Exemplo n.º 5
0
    def resize_online(self, sr_uuid, vdi_uuid, size):
        if not self.exists:
            raise xs_errors.XenError('VDIUnavailable', \
                  opterr='VDI %s unavailable %s' % (vdi_uuid, self.path))

        if self.vdi_type != vhdutil.VDI_TYPE_VHD:
            raise xs_errors.XenError('Unimplemented')

        if self.hidden:
            raise xs_errors.XenError('VDIUnavailable', opterr='hidden VDI')
        
        if size < self.size:
            util.SMlog('vdi_resize: shrinking not supported: ' + \
                    '(current size: %d, new size: %d)' % (self.size, size))
            raise xs_errors.XenError('VDISize', opterr='shrinking not allowed')
        
        if size == self.size:
            return VDI.VDI.get_params(self)

        # We already checked it is a VDI_TYPE_VHD
        size = vhdutil.validate_and_round_vhd_size(long(size))
        overhead = vhdutil.calcOverheadFull(long(size))

        # Test the amount of actual disk space
        if ENFORCE_VIRT_ALLOC:
            self.sr._loadvdis()
            reserved = self.sr.virtual_allocation
            sr_size = self.sr._getsize()
            delta = long(size - self.size)
            if (sr_size - reserved) < delta:
                raise xs_errors.XenError('SRNoSpace')
        jFile = JOURNAL_FILE_PREFIX + self.uuid
        try:
            vhdutil.setSizeVirt(self.path, size, jFile)
        except:
            # Revert the operation
            vhdutil.revert(self.path, jFile)
            raise xs_errors.XenError('VDISize', opterr='resize operation failed')
        
        old_size = self.size
        self.size = vhdutil.getSizeVirt(self.path)
        st = util.ioretry(lambda: os.stat(self.path))
        self.utilisation = long(st.st_size)
        
        self._db_update()
        self.sr._update(self.sr.uuid, self.size - old_size)
        super(FileVDI, self).resize_cbt(self.sr.uuid, self.uuid, self.size)
        return VDI.VDI.get_params(self)
Exemplo n.º 6
0
Arquivo: FileSR.py Projeto: xcp-ng/sm
    def create(self, sr_uuid, vdi_uuid, size):
        if util.ioretry(lambda: util.pathexists(self.path)):
            raise xs_errors.XenError('VDIExists')

        overhead = 0
        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            overhead = vhdutil.calcOverheadFull(long(size))

        # Test the amount of actual disk space
        if ENFORCE_VIRT_ALLOC:
            self.sr._loadvdis()
            reserved = self.sr.virtual_allocation
            sr_size = self.sr._getsize()
            if (sr_size - reserved) < (long(size) + overhead):
                raise xs_errors.XenError('SRNoSpace')

        if self.vdi_type == vhdutil.VDI_TYPE_VHD:
            try:
                size = vhdutil.validate_and_round_vhd_size(long(size))
                mb = 1024 * 1024
                size_mb = long(size) / mb
                util.ioretry(lambda: self._create(str(size_mb), self.path))
                self.size = util.ioretry(lambda: self._query_v(self.path))
            except util.CommandException as inst:
                raise xs_errors.XenError('VDICreate',
                                         opterr='error %d' % inst.code)
        else:
            f = open(self.path, 'w')
            f.truncate(long(size))
            f.close()
            self.size = size

        self.sr.added_vdi(self)

        st = util.ioretry(lambda: os.stat(self.path))
        self.utilisation = long(st.st_size)
        if self.vdi_type == vhdutil.VDI_TYPE_RAW:
            self.sm_config = {"type": self.PARAM_RAW}

        self._db_introduce()
        self.sr._update(self.sr.uuid, self.size)
        return super(FileVDI, self).get_params()
Exemplo n.º 7
0
    def test_validate_and_round_odd_size_up_to_next_boundary(self):
        size = vhdutil.validate_and_round_vhd_size(vhdutil.MAX_VHD_SIZE - 1)

        self.assertTrue(size == vhdutil.MAX_VHD_SIZE)
Exemplo n.º 8
0
    def test_validate_and_round_max_size(self):
        size = vhdutil.validate_and_round_vhd_size(vhdutil.MAX_VHD_SIZE)

        self.assertTrue(size == vhdutil.MAX_VHD_SIZE)
Exemplo n.º 9
0
    def test_validate_and_round_min_size(self):
        size = vhdutil.validate_and_round_vhd_size(2 * 1024 * 1024)

        self.assertTrue(size == 2 * 1024 * 1024)
Exemplo n.º 10
0
    def test_validate_and_round_max_size(self):
        size = vhdutil.validate_and_round_vhd_size(MAX_VHD_SIZE)

        self.assertTrue(size == MAX_VHD_SIZE)
Exemplo n.º 11
0
    def resize(self, sr_uuid, vdi_uuid, size, online=False):
        """
        Resize the given VDI to size <size>. Size can be any valid disk size greater than [or smaller than] the current
        value.
        :param sr_uuid:
        :param vdi_uuid:
        :param size:
        :param online:
        :return:
        """
        if VERBOSE:
            util.SMlog(
                "rbdsr_vhd.RBDVHDVDI.resize: sr_uuid=%s, vdi_uuid=%s, size=%s"
                % (sr_uuid, vdi_uuid, size))

        vdi_ref = self.session.xenapi.VDI.get_by_uuid(vdi_uuid)
        sm_config = self.session.xenapi.VDI.get_sm_config(vdi_ref)
        vdi_hostRefs = self._get_vdi_hostRefs(vdi_uuid)
        local_host_uuid = inventory.get_localhost_uuid()

        if 'attached' in sm_config and online is False:
            online = True
            raise xs_errors.XenError(
                'VDIResize',
                opterr='Online resize is not supported in VHD mode')

        size = vhdutil.validate_and_round_vhd_size(long(size))

        if self.sr.provision == "thin":
            rbdSizeNew = lvhdutil.calcSizeVHDLV(size)
        elif self.sr.provision == "thick":
            rbdSizeNew = lvhdutil.calcSizeVHDLV(size)

        if online:
            retval = super(RBDVHDVDI,
                           self).resize_online(sr_uuid, vdi_uuid, rbdSizeNew)
        else:
            retval = super(RBDVHDVDI, self).resize(sr_uuid, vdi_uuid,
                                                   rbdSizeNew)

        if not online:
            # self._map_rbd(vdi_uuid, rbdSizeNew, norefcount=True)
            self.attach(sr_uuid, vdi_uuid, host_uuid=local_host_uuid)
        else:
            if local_host_uuid not in vdi_hostRefs:
                self.attach(sr_uuid, vdi_uuid, host_uuid=local_host_uuid)

        vhdutil.setSizePhys(self.path, size, False)
        vhdutil.setSizeVirtFast(self.path, size)

        if online:
            if not blktap2.VDI.tap_refresh(self.session, self.sr.uuid,
                                           vdi_uuid, True):
                raise util.SMException("failed to refresh VDI %s" % vdi_uuid)

        if not online:
            # self._unmap_rbd(vdi_uuid, rbdSizeNew, norefcount=True)
            self.detach(sr_uuid, vdi_uuid, host_uuid=local_host_uuid)
        else:
            if local_host_uuid not in vdi_hostRefs:
                self.detach(sr_uuid, vdi_uuid, host_uuid=local_host_uuid)

        self.size = size
        self.session.xenapi.VDI.set_virtual_size(vdi_ref, str(size))
        self.session.xenapi.VDI.set_physical_utilisation(vdi_ref, str(size))

        return retval
Exemplo n.º 12
0
 def test_validate_and_round_too_large(self, context):
     context.setup_error_codes()
     with self.assertRaises(SR.SROSError):
         vhdutil.validate_and_round_vhd_size(MAX_VHD_SIZE + 1)
Exemplo n.º 13
0
 def test_validate_and_round_negative(self, context):
     context.setup_error_codes()
     with self.assertRaises(SR.SROSError):
         vhdutil.validate_and_round_vhd_size(-1)
Exemplo n.º 14
0
    def test_validate_and_round_odd_size_up_to_next_boundary(self):
        size = vhdutil.validate_and_round_vhd_size(MAX_VHD_SIZE - 1)

        self.assertTrue(size == MAX_VHD_SIZE)
Exemplo n.º 15
0
 def test_validate_and_round_negative(self, context):
     context.setup_error_codes()
     with self.assertRaises(SR.SROSError):
         vhdutil.validate_and_round_vhd_size(-1)
Exemplo n.º 16
0
 def test_validate_and_round_too_large(self, context):
     context.setup_error_codes()
     with self.assertRaises(SR.SROSError):
         vhdutil.validate_and_round_vhd_size(vhdutil.MAX_VHD_SIZE + 1)
Exemplo n.º 17
0
    def test_validate_and_round_min_size(self):
        size = vhdutil.validate_and_round_vhd_size(2 * 1024 * 1024)

        self.assertTrue(size == 2 * 1024 * 1024)