コード例 #1
0
    def attach(dbg, uri, domain, cb):
        sr, key = _parse_uri(uri)
        opq = cb.volumeStartOperations(sr, 'r')

        meta_path = cb.volumeMetadataGetPath(opq)
        db = VHDMetabase(meta_path)
        with db.write_context():
            vdi = db.get_vdi_by_id(key)
        # activate LVs chain here
        db.close()

        vol_path = cb.volumeGetPath(opq, str(vdi.vhd.id))

        if vdi.vhd.parent_id is not None and vdi_enable_intellicache:
            parent_vhd_path = cb.volumeGetPath(opq, str(vdi.vhd.parent_id))
            block_device = IntelliCache.attach(
                dbg,
                vol_path,
                parent_vhd_path
            )
        else:
            tap = tapdisk.create(dbg)
            tapdisk.save_tapdisk_metadata(dbg, vol_path, tap)
            block_device = tap.block_device()

        cb.volumeStopOperations(opq)

        return {
            'domain_uuid': '0',
            'implementation': ['Tapdisk3', block_device],
        }
コード例 #2
0
 def attach(self, dbg, uri, domain):
     u = urlparse.urlparse(uri)
     tap = tapdisk.create(dbg)
     tapdisk.save_tapdisk_metadata(dbg, u.path, tap)
     return {
         'domain_uuid': '0',
         'implementation': ['Tapdisk3', tap.block_device()],
     }
コード例 #3
0
 def attach(self, dbg, uri, domain):
     u = urlparse.urlparse(uri)
     tap = tapdisk.create(dbg)
     tapdisk.save_tapdisk_metadata(dbg, u.path, tap)
     return {
         'domain_uuid': '0',
         'implementation': ['Tapdisk3', tap.block_device()],
     }
コード例 #4
0
def attach(dbg, uri, domain, cb):
    sr,name = parse_datapath_uri(uri)
    opq = cb.volumeStartOperations(sr, 'r')
    # activate LVs chain here
    vol_path = cb.volumeGetPath(opq, name)
    tap = tapdisk.create(dbg)
    tapdisk.save_tapdisk_metadata(dbg, vol_path, tap)
    return {
        'domain_uuid': '0',
        'implementation': ['Tapdisk3', tap.block_device()],
        }
コード例 #5
0
    def attach_internal(dbg, opq, vdi, vol_path, cb):
        if vdi.volume.parent_id is not None and vdi_enable_intellicache:
            parent_cow_path = cb.volumeGetPath(opq, str(vdi.volume.parent_id))
            IntelliCache.attach(dbg, vol_path, parent_cow_path)
        else:
            tap = tapdisk.create(dbg)
            tapdisk.save_tapdisk_metadata(
                dbg, cb.get_data_metadata_path(opq, vdi.uuid), tap)

        return [[
            'XenDisk', {
                'backend_type': 'vbd3',
                'params': tap.block_device(),
                'extra': {}
            }
        ], ['BlockDevice', {
            'path': tap.block_device()
        }]]
コード例 #6
0
    def attach(dbg, vhd_path, parent_vhd_path):
        log.debug("parent_vhd_path: {}".format(parent_vhd_path))

        parent_vhd_cache_path = os.path.join(
            IntelliCache.ROOT_PATH,
            parent_vhd_path[20:] # remove /var/run/sr-mount, but keep the rest
        ) # TODO: 20 should be 18; the path starts with 2 extra slashes!!
        log.debug("parent_vhd_cache_path: {}".format(parent_vhd_cache_path))

        try:
            os.makedirs(parent_vhd_cache_path.rsplit('/', 1)[0])
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                raise

        # Only snapshot parent if it doesn't exist
        if not os.path.isfile(parent_vhd_cache_path):
            # ['/usr/bin/vhd-util', 'snapshot', '--debug',
            # '-n', '/var/run/sr-mount/ext3_sr/base_img.vhdcache',
            # '-p', '/var/run/sr-mount/nfs_sr/base_img.vhd']
            log.debug("parent cache does not exist; snapshotting")
            VHDUtil.snapshot(dbg, parent_vhd_cache_path, parent_vhd_path, False)
        else:
            log.debug("parent cache exists; no action")

        leaf_vhd_cache_path = os.path.join(
            IntelliCache.ROOT_PATH,
            vhd_path[20:]
        )
        log.debug("leaf_vhd_cache_path: {}".format(leaf_vhd_cache_path))

        try:
            os.makedirs(leaf_vhd_cache_path.rsplit('/', 1)[0])
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                raise

        try:
            # Maybe deleting is redundant?
            os.unlink(leaf_vhd_cache_path)
            log.debug("leaf cache exists; deleting")
        except OSError as exc:
            if exc.errno == errno.ENOENT:
                log.debug("leaf cache does not exist")
            else:
                raise

        # ['/usr/bin/vhd-util', 'snapshot', '--debug',
        # '-n', '/var/run/sr-mount/ext3_sr/leaf.vhdcache',
        # '-p', '/var/run/sr-mount/ext3_sr/base_img.vhdcache',
        # '-S', '24576', '-e']
        log.debug("snapshotting leaf cache")
        VHDUtil.snapshot(dbg, leaf_vhd_cache_path, parent_vhd_cache_path, True)

        # HANDLE VDI RESIZING

        try:
            # See if 'parent_vhd_cache_path' exists
            tapdisk.load_tapdisk_metadata('', parent_vhd_cache_path)
        except IOError as exc:
            if exc.errno == errno.ENOENT:
                parent_cache_tap = tapdisk.create(
                    "create 'parent_cache_tap' tapdisk"
                )
                tapdisk.save_tapdisk_metadata(
                    '',
                    parent_vhd_cache_path,
                    parent_cache_tap
                )
            else:
                raise

        try:
            # This should not exist
            tapdisk.load_tapdisk_metadata('', leaf_vhd_cache_path)
        except IOError as exc:
            if exc.errno == errno.ENOENT:
                leaf_cache_tap = tapdisk.create(
                    "create 'leaf_cache_tap' tapdisk"
                )
                tapdisk.save_tapdisk_metadata(
                    '',
                    leaf_vhd_cache_path,
                    leaf_cache_tap
                )
            else:
                raise
        else:
            raise RuntimeError(
                "Tapdisk metadata file for '{}' exists; Aborting".format(
                    leaf_vhd_cache_path
                )
            )

        return leaf_cache_tap.block_device()
コード例 #7
0
    def attach(dbg, cow_path, parent_cow_path):
        log.debug("parent_cow_path: {}".format(parent_cow_path))

        parent_cow_cache_path = os.path.join(
            IntelliCache.ROOT_PATH,
            parent_cow_path[20:]  # remove /var/run/sr-mount, but keep the rest
        )  # TODO: 20 should be 18; the path starts with 2 extra slashes!!
        log.debug("parent_cow_cache_path: {}".format(parent_cow_cache_path))

        try:
            os.makedirs(parent_cow_cache_path.rsplit('/', 1)[0])
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                raise

        # Only snapshot parent if it doesn't exist
        if not os.path.isfile(parent_cow_cache_path):
            # ['/usr/bin/vhd-util', 'snapshot', '--debug',
            # '-n', '/var/run/sr-mount/ext3_sr/base_img.vhdcache',
            # '-p', '/var/run/sr-mount/nfs_sr/base_img.vhd']
            log.debug("parent cache does not exist; snapshotting")
            COWUtil.snapshot(dbg, parent_cow_cache_path, parent_cow_path,
                             False)
        else:
            log.debug("parent cache exists; no action")

        leaf_cow_cache_path = os.path.join(IntelliCache.ROOT_PATH,
                                           cow_path[20:])
        log.debug("leaf_cow_cache_path: {}".format(leaf_cow_cache_path))

        try:
            os.makedirs(leaf_cow_cache_path.rsplit('/', 1)[0])
        except OSError as exc:
            if exc.errno != errno.EEXIST:
                raise

        try:
            # Maybe deleting is redundant?
            os.unlink(leaf_cow_cache_path)
            log.debug("leaf cache exists; deleting")
        except OSError as exc:
            if exc.errno == errno.ENOENT:
                log.debug("leaf cache does not exist")
            else:
                raise

        # ['/usr/bin/vhd-util', 'snapshot', '--debug',
        # '-n', '/var/run/sr-mount/ext3_sr/leaf.vhdcache',
        # '-p', '/var/run/sr-mount/ext3_sr/base_img.vhdcache',
        # '-S', '24576', '-e']
        log.debug("snapshotting leaf cache")
        COWUtil.snapshot(dbg, leaf_cow_cache_path, parent_cow_cache_path, True)

        # HANDLE VDI RESIZING

        try:
            # See if 'parent_cow_cache_path' exists
            tapdisk.load_tapdisk_metadata('', parent_cow_cache_path)
        except IOError as exc:
            if exc.errno == errno.ENOENT:
                parent_cache_tap = tapdisk.create(
                    "create 'parent_cache_tap' tapdisk")
                tapdisk.save_tapdisk_metadata('', parent_cow_cache_path,
                                              parent_cache_tap)
            else:
                raise

        try:
            # This should not exist
            tapdisk.load_tapdisk_metadata('', leaf_cow_cache_path)
        except IOError as exc:
            if exc.errno == errno.ENOENT:
                leaf_cache_tap = tapdisk.create(
                    "create 'leaf_cache_tap' tapdisk")
                tapdisk.save_tapdisk_metadata('', leaf_cow_cache_path,
                                              leaf_cache_tap)
            else:
                raise
        else:
            raise RuntimeError(
                "Tapdisk metadata file for '{}' exists; Aborting".format(
                    leaf_cow_cache_path))

        return leaf_cache_tap.block_device()