From: Dongsheng Yang Date: Thu, 13 Oct 2016 11:00:33 +0000 (-0400) Subject: rbd: import/export image_order. X-Git-Tag: v12.0.1~342^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8679521a0377a8f78a64ed79eaca6cf62216742c;p=ceph.git rbd: import/export image_order. Signed-off-by: Dongsheng Yang --- diff --git a/src/tools/rbd/Utils.h b/src/tools/rbd/Utils.h index 54250f17021..f1819abed28 100644 --- a/src/tools/rbd/Utils.h +++ b/src/tools/rbd/Utils.h @@ -27,6 +27,9 @@ static const std::string RBD_DIFF_BANNER_V2 ("rbd diff v2\n"); #define RBD_DIFF_ZERO 'z' #define RBD_DIFF_END 'e' +#define RBD_EXPORT_IMAGE_ORDER 'O' +#define RBD_EXPORT_IMAGE_END 'E' + enum SnapshotPresence { SNAPSHOT_PRESENCE_NONE, SNAPSHOT_PRESENCE_PERMITTED, diff --git a/src/tools/rbd/action/Export.cc b/src/tools/rbd/action/Export.cc index 6c07440ee16..b269f36ad6c 100644 --- a/src/tools/rbd/action/Export.cc +++ b/src/tools/rbd/action/Export.cc @@ -400,6 +400,19 @@ static int do_export(librbd::Image& image, const char *path, bool no_progress, i uint64_t size = info.size; ::encode(size, bl); + // TODO add more priorities here, such as image_feature... + __u8 tag; + + // encode order + tag = RBD_EXPORT_IMAGE_ORDER; + ::encode(tag, bl); + ::encode(uint64_t(info.order), bl); + + // encode end tag + tag = RBD_EXPORT_IMAGE_END; + ::encode(tag, bl); + + // write bl to fd. r = bl.write_fd(fd); if (r < 0) { goto out; diff --git a/src/tools/rbd/action/Import.cc b/src/tools/rbd/action/Import.cc index b72689d454d..b64f8ca63eb 100644 --- a/src/tools/rbd/action/Import.cc +++ b/src/tools/rbd/action/Import.cc @@ -387,6 +387,38 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx, if (r < 0) { goto done; } + + // As V1 format for image is already deprecated, import image in V2 by default. + uint64_t image_format = 2; + if (opts.get(RBD_IMAGE_OPTION_FORMAT, &image_format) != 0) { + opts.set(RBD_IMAGE_OPTION_FORMAT, image_format); + } + + while (1) { + __u8 tag; + r = safe_read_exact(fd, &tag, 1); + if (r < 0) { + goto done; + } + + if (tag == RBD_EXPORT_IMAGE_END) { + break; + } else if (tag == RBD_EXPORT_IMAGE_ORDER) { + uint64_t order = 0; + r = safe_read_exact(fd, &order, 8); + if (r < 0) { + goto done; + } + if (opts.get(RBD_IMAGE_OPTION_ORDER, &order) != 0) { + opts.set(RBD_IMAGE_OPTION_ORDER, order); + } + } else { + std::cerr << "rbd: invalid tag in image priority zone: " << tag << std::endl; + r = -EINVAL; + goto done; + } + //TODO, set the image options according flags and appending data. + } } r = rbd.create4(io_ctx, imgname, size, opts);