From 8679521a0377a8f78a64ed79eaca6cf62216742c Mon Sep 17 00:00:00 2001 From: Dongsheng Yang Date: Thu, 13 Oct 2016 07:00:33 -0400 Subject: [PATCH] rbd: import/export image_order. Signed-off-by: Dongsheng Yang --- src/tools/rbd/Utils.h | 3 +++ src/tools/rbd/action/Export.cc | 13 +++++++++++++ src/tools/rbd/action/Import.cc | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/src/tools/rbd/Utils.h b/src/tools/rbd/Utils.h index 54250f1702130..f1819abed2808 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 6c07440ee16e3..b269f36ad6c4d 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 b72689d454d0d..b64f8ca63eb94 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); -- 2.39.5