diff options
author | Brian Foster <bfoster@redhat.com> | 2013-09-18 07:03:07 -0400 |
---|---|---|
committer | Anand Avati <avati@redhat.com> | 2013-11-10 23:02:37 -0800 |
commit | 0826f9073a93c6d499f3d2077695455854d0fa7f (patch) | |
tree | 3d29ab1f7c8414c307b52eff411063a74177d675 /xlators/features/qemu-block/src/bdrv-xlator.c | |
parent | c8fef37c5d566c906728b5f6f27baaa9a8d2a20d (diff) |
features/qemu-block: add qemu backing image support (clone)
Add basic backing image support to the block-format mechanism. This
is a functionality checkpoint that enables the raw mechanism
required to support client driven "snapshot" and "clone" requests.
This change enhances the block-format setxattr command to support
an additional and optional backing image reference. For example:
setxattr -n trusted.glusterfs.block-format -v "qcow2:10GB:<bimg>" ./newimage
... where <bimg> refers to the backing image for unallocated blocks
in newimage. <bimg> can be provided in one of two formats:
- a gfid string in the following format (assuming a valid gfid):
<gfid:00000000-0000-0000-0000-000000000000>
- or a filename that must be resident in the same directory as the
new clone file being formatted. E.g.,
setxattr -n trusted.glusterfs.block-format -v "qcow2:10GB:baseimg" ./newimage
This latter format is more restrictive, simply provided for
convenience or until something more refined is available.
This change makes no assumptions about the backing image file and
affords no additional protection. It is up to the user/client to
recognize the relationship between the files and manage them
appropriately (i.e., no writes to the backing image, etc.).
BUG: 986775
Change-Id: I7aff7bdc59b85a6459001a6bfeae4db6bf74f703
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-on: http://review.gluster.org/5967
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'xlators/features/qemu-block/src/bdrv-xlator.c')
-rw-r--r-- | xlators/features/qemu-block/src/bdrv-xlator.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/xlators/features/qemu-block/src/bdrv-xlator.c b/xlators/features/qemu-block/src/bdrv-xlator.c index 145f7c79d5e..106c5977535 100644 --- a/xlators/features/qemu-block/src/bdrv-xlator.c +++ b/xlators/features/qemu-block/src/bdrv-xlator.c @@ -69,10 +69,13 @@ static int qemu_gluster_open (BlockDriverState *bs, QDict *options, int bdrv_flags) { inode_t *inode = NULL; - BDRVGlusterState *s = NULL; + BDRVGlusterState *s = bs->opaque; QemuOpts *opts = NULL; Error *local_err = NULL; const char *filename = NULL; + char gfid_str[128]; + int ret; + qb_conf_t *conf = THIS->private; opts = qemu_opts_create_nofail(&runtime_opts); qemu_opts_absorb_qdict(opts, options, &local_err); @@ -84,12 +87,40 @@ qemu_gluster_open (BlockDriverState *bs, QDict *options, int bdrv_flags) filename = qemu_opt_get(opts, "filename"); - inode = qb_inode_from_filename (filename); - if (!inode) - return -EINVAL; + /* + * gfid:<gfid> format means we're opening a backing image. + */ + ret = sscanf(filename, "gluster://gfid:%s", gfid_str); + if (ret) { + loc_t loc = {0,}; + struct iatt buf = {0,}; + uuid_t gfid; - s = bs->opaque; - s->inode = inode_ref (inode); + uuid_parse(gfid_str, gfid); + + loc.inode = inode_find(conf->root_inode->table, gfid); + if (!loc.inode) { + loc.inode = inode_new(conf->root_inode->table); + uuid_copy(loc.inode->gfid, gfid); + } + + uuid_copy(loc.gfid, loc.inode->gfid); + ret = syncop_lookup(FIRST_CHILD(THIS), &loc, NULL, &buf, NULL, + NULL); + if (ret) { + loc_wipe(&loc); + return -errno; + } + + s->inode = inode_ref(loc.inode); + loc_wipe(&loc); + } else { + inode = qb_inode_from_filename (filename); + if (!inode) + return -EINVAL; + + s->inode = inode_ref(inode); + } return 0; } |