Example #1
0
File: VDI.py Project: chandrikas/sm
def VDIMetadataSize(type, virtualsize):
    size = 0
    if type == 'vhd':
        size_mb = virtualsize / (1024 * 1024)
        #Footer + footer copy + header + possible CoW parent locator fields
        size = 3 * 1024

        # BAT 4 Bytes per block segment
        size += (size_mb / 2) * 4
        size = util.roundup(512, size)

        # BATMAP 1 bit per block segment
        size += (size_mb / 2) / 8
        size = util.roundup(4096, size)

        # Segment bitmaps + Page align offsets
        size += (size_mb / 2) * 4096
    elif type == 'qcow':
        # Header + extended header
        size = 46 + 17
        size = util.roundup(512, size)

        # L1 table
        size += (size_mb / 2) * 8
        size = util.roundup(4096, size)

        # L2 tables
        size += (size_mb / 2) * 4096
    return size
Example #2
0
def VDIMetadataSize(type, virtualsize):
    size = 0
    if type == 'vhd':
        size_mb = virtualsize / (1024 * 1024)
        #Footer + footer copy + header + possible CoW parent locator fields
        size = 3 * 1024

        # BAT 4 Bytes per block segment
        size += (size_mb / 2) * 4
        size = util.roundup(512, size)

        # BATMAP 1 bit per block segment
        size += (size_mb / 2) / 8
        size = util.roundup(4096, size)

        # Segment bitmaps + Page align offsets
        size += (size_mb / 2) * 4096
    elif type == 'qcow':
        # Header + extended header
        size = 46 + 17
        size = util.roundup(512, size)

        # L1 table
        size += (size_mb / 2) * 8
        size = util.roundup(4096, size)

        # L2 tables
        size += (size_mb / 2) * 4096
    return size
Example #3
0
 def cmd_write(self, ui,args):
   """write to flash"""
   x = util.file_mem_args(ui, args, self.device)
   if x is None:
     return
   (name, adr, n) = x
   # check the file
   filesize = util.file_arg(ui, name)
   if filesize is None:
     return
   # round up the filesize - the io object will return 0xff for any bytes beyond EOF
   filesize = util.roundup(filesize, 32)
   if n is None:
     # no length on the command line - program the filesize
     n = filesize
   if n >= filesize:
     # region is bigger than the file - program the filesize
     n = filesize
   else:
     # region is smaller than the file - truncate the file
     ui.put('%s is larger than target memory: %d > %d bytes (truncating)\n' % (name, filesize, n))
   # make sure the target region in flash is suitable
   mr = mem.region(None, adr, n)
   msg = self.driver.check_region(mr)
   if msg is not None:
     ui.put('%s\n' % msg)
     return
   # read from file, write to memory
   mf = iobuf.read_file(ui, 'writing %s (%d bytes):' % (name, n), name, n)
   self.driver.write(mr, mf)
   mf.close(rate = True)
Example #4
0
File: FileSR.py Project: falaa/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:
                mb = 1024L * 1024L
                size_mb = util.roundup(VHD_SIZE_INC, long(size)) / mb
                if size_mb < 1 or (size_mb + (overhead / mb)) >= MAX_DISK_MB:
                    raise xs_errors.XenError('VDISize', opterr='VDI size ' + \
                            'must be between 1 MB and %d MB' % \
                            ((MAX_DISK_MB - MAX_DISK_METADATA) - 1))
                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)
Example #5
0
File: mem.py Project: deadsy/pycs
 def cmd_verify(self, ui, args):
   """verify memory against file"""
   x = util.file_mem_args(ui, args, self.cpu.device)
   if x is None:
     return
   (name, adr, size) = x
   # check the file
   filesize = util.file_arg(ui, name)
   if filesize is None:
     return
   # round up the filesize - the io object will return 0xff for any bytes beyond EOF
   filesize = util.roundup(filesize, 32)
   if size is None:
     # no length on the command line - verify the filesize
     size = filesize
   if size > filesize:
     # region is larger than file - just verify the filesize
     size = filesize
   # adjust the address and length
   adr = util.align(adr, 32)
   n = util.nbytes_to_nwords(size, 32)
   # read memory, verify against file object
   mf = iobuf.verify_file(ui, 'verify %s (%d bytes):' % (name, n * 4), name, n * 4)
   self.cpu.rdmem32(adr, n, mf)
   mf.close()
    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:
                mb = 1024L * 1024L
                size_mb = util.roundup(VHD_SIZE_INC, long(size)) / mb
                if size_mb < 1 or (size_mb + (overhead / mb)) >= MAX_DISK_MB:
                    raise xs_errors.XenError('VDISize', opterr='VDI size ' + \
                            'must be between 1 MB and %d MB' % \
                            ((MAX_DISK_MB - MAX_DISK_METADATA) - 1))
                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)
Example #7
0
 def cmd_verify(self, ui, args):
     """verify memory against file"""
     x = util.file_mem_args(ui, args, self.cpu.device)
     if x is None:
         return
     (name, adr, size) = x
     # check the file
     filesize = util.file_arg(ui, name)
     if filesize is None:
         return
     # round up the filesize - the io object will return 0xff for any bytes beyond EOF
     filesize = util.roundup(filesize, 32)
     if size is None:
         # no length on the command line - verify the filesize
         size = filesize
     if size > filesize:
         # region is larger than file - just verify the filesize
         size = filesize
     # adjust the address and length
     adr = util.align(adr, 32)
     n = util.nbytes_to_nwords(size, 32)
     # read memory, verify against file object
     mf = iobuf.verify_file(ui, 'verify %s (%d bytes):' % (name, n * 4),
                            name, n * 4)
     self.cpu.rdmem32(adr, n, mf)
     mf.close()
Example #8
0
def calcOverheadEmpty(virtual_size):
    """Calculate the VHD space overhead (metadata size) for an empty VDI of
    size virtual_size"""
    overhead = 0
    size_mb = virtual_size / (1024 * 1024)

    # Footer + footer copy + header + possible CoW parent locator fields
    overhead = 3 * 1024

    # BAT 4 Bytes per block segment
    overhead += (size_mb / 2) * 4
    overhead = util.roundup(512, overhead)

    # BATMAP 1 bit per block segment
    overhead += (size_mb / 2) / 8
    overhead = util.roundup(4096, overhead)

    return overhead
def calcOverheadEmpty(virtual_size):
    """Calculate the VHD space overhead (metadata size) for an empty VDI of
    size virtual_size"""
    overhead = 0
    size_mb = virtual_size / (1024 * 1024)

    # Footer + footer copy + header + possible CoW parent locator fields
    overhead = 3 * 1024

    # BAT 4 Bytes per block segment
    overhead += (size_mb / 2) * 4
    overhead = util.roundup(512, overhead)

    # BATMAP 1 bit per block segment
    overhead += (size_mb / 2) / 8
    overhead = util.roundup(4096, overhead)

    return overhead
Example #10
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 = util.roundup(VHD_SIZE_INC, long(size))
        overhead = vhdutil.calcOverheadFull(long(size))

        # Check we are within the limits
        mb = 1024L * 1024L
        if size < mb or (size / mb) >= MAX_VHD_SIZE:
            raise xs_errors.XenError('VDISize',
                                     opterr='VDI size ' +
                                     'must be between 1 MB and %d MB' %
                                     (MAX_VHD_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)
        return VDI.VDI.get_params(self)
Example #11
0
File: FileSR.py Project: falaa/sm
    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 = util.roundup(VHD_SIZE_INC, long(size))
        overhead = vhdutil.calcOverheadFull(long(size))

        # Check we are within the limits
        mb = 1024L * 1024L
        if size < mb or (size / mb) >= MAX_VHD_SIZE:
            raise xs_errors.XenError('VDISize', opterr='VDI size ' +
                      'must be between 1 MB and %d MB' %(MAX_VHD_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)
        return VDI.VDI.get_params(self)
Example #12
0
    def validate_size(self, size):
        if self.exists:
            raise xs_errors.XenError('VDIExists')

        if size / 1024 / 1024 > self.MAX_VDI_SIZE_MB:
            raise xs_errors.XenError('VDISize',
                    opterr="VDI size cannot exceed %d MB" % \
                            self.MAX_VDI_SIZE_MB)

        if size < self.MIN_VIRT_SIZE:
            size = self.MIN_VIRT_SIZE

        return util.roundup(self.VHD_SIZE_INC, size)
Example #13
0
def validate_and_round_vhd_size(size):
    """ Take the supplied vhd size, in bytes, and check it is positive and less
    that the maximum supported size, rounding up to the next block boundary
    """
    if (size < 0 or size > MAX_VHD_SIZE):
        raise xs_errors.XenError('VDISize', opterr='VDI size ' + \
                                     'must be between 1 MB and %d MB' % \
                                     (MAX_VHD_SIZE / 1024 / 1024))

    if (size < MIN_VHD_SIZE):
        size = MIN_VHD_SIZE

    size = util.roundup(VHD_BLOCK_SIZE, size)

    return size
Example #14
0
def validate_and_round_vhd_size(size):
    """ Take the supplied vhd size, in bytes, and check it is positive and less
    that the maximum supported size, rounding up to the next block boundary
    """
    if (size < 0 or size > MAX_VHD_SIZE):
        raise xs_errors.XenError('VDISize', opterr='VDI size ' + \
                                     'must be between 1 MB and %d MB' % \
                                     (MAX_VHD_SIZE / 1024 / 1024))

    if (size < MIN_VHD_SIZE):
        size = MIN_VHD_SIZE

    size = util.roundup(VHD_BLOCK_SIZE, size)

    return size
Example #15
0
def create(size, path):
    assert (type(size) == type(0L))

    overhead = calcOverheadFull(size)

    mb = 1024L * 1024L
    size_mb = util.roundup(VHD_SIZE_INC, size) / mb
    if size_mb < 1 or (size_mb + (overhead / mb)) >= MAX_DISK_MB:
        raise 'VDI size must be between 1 MB and %d MB' % ((MAX_DISK_MB - MAX_DISK_METADATA) - 1)

    cmd = [TAPDISK_UTIL, "create", "vhd", str(size_mb), path]
    ioretry(cmd)

    cmd = [TAPDISK_UTIL, "query", "vhd", "-v", path]
    return long(ioretry(cmd)) * mb
Example #16
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.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)

        size = util.roundup(VHD_SIZE_INC, 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)
        return VDI.VDI.get_params(self)
Example #17
0
    def create(self, sr_uuid, vdi_uuid, size):
        if util.ioretry(lambda: util.pathexists(self.path)):
            raise xs_errors.XenError('VDIExists')

        # 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) + vhdutil.calcOverheadFull(long(size))):
                raise xs_errors.XenError('SRNoSpace')

        try:
            mb = 1024L * 1024L
            size_mb = util.roundup(VHD_SIZE_INC, long(size)) / mb # round up            
            metasize = vhdutil.calcOverheadFull(long(size))
            assert(size_mb > 0)
            assert((size_mb + (metasize/(1024*1024))) < MAX_DISK_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)
Example #18
0
    def resize(self, sr_uuid, vdi_uuid, size):
        # Updates the size in the DB
        log("Calling VDI RESIZE")

        util.SMlog("LUVDI.resize for %s" % self.uuid)

        if size / 1024 / 1024 > self.MAX_VDI_SIZE_MB:
            raise xs_errors.XenError('VDISize',
                                     opterr="VDI size cannot exceed %d MB" % \
                                            self.MAX_VDI_SIZE_MB)

        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)

        size = util.roundup(self.VHD_SIZE_INC, size)
        old_size = self.size

        if not self.attached:
            self.attach(sr_uuid, vdi_uuid)

        vhdutil.setSizeVirtFast(self.path, size)
        self.size = vhdutil.getSizeVirt(self.path)
        self.utilisation = self.size

        vdi_ref = self.sr.srcmd.params['vdi_ref']
        self.session.xenapi.VDI.set_virtual_size(vdi_ref, str(self.size))
        self.session.xenapi.VDI.set_physical_utilisation(vdi_ref, str(self.size))
        self.sr._updateStats(self.sr.uuid, self.size - old_size)

        self.detach(sr_uuid, vdi_uuid)

        return VDI.VDI.get_params(self)
Example #19
0
def calcSizeLV(sizeVHD):
    return util.roundup(LVM_SIZE_INCREMENT, sizeVHD)
Example #20
0
 def getSizeLV(size):
     """ Rounds up the size."""
     return util.roundup(lvutil.LVM_SIZE_INCREMENT, size)
Example #21
0
def calcSizeLV(sizeVHD):
    return util.roundup(LVM_SIZE_INCREMENT, sizeVHD)
 def getSizeLV(size):
     return util.roundup(lvutil.LVM_SIZE_INCREMENT, size)