From d7479a09b6d5357f9153464f1a51899d9abd41a9 Mon Sep 17 00:00:00 2001 From: Dongsheng Yang Date: Thu, 13 Oct 2016 22:38:30 -0400 Subject: [PATCH] rbd: import/export image stripe_unit and stripe_count. Signed-off-by: Dongsheng Yang --- src/tools/rbd/Utils.h | 2 ++ src/tools/rbd/action/Export.cc | 13 +++++++++++++ src/tools/rbd/action/Import.cc | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/tools/rbd/Utils.h b/src/tools/rbd/Utils.h index b885631544e7f..9ecb21eecc61d 100644 --- a/src/tools/rbd/Utils.h +++ b/src/tools/rbd/Utils.h @@ -29,6 +29,8 @@ static const std::string RBD_DIFF_BANNER_V2 ("rbd diff v2\n"); #define RBD_EXPORT_IMAGE_ORDER 'O' #define RBD_EXPORT_IMAGE_FEATURES 'T' +#define RBD_EXPORT_IMAGE_STRIPEUNIT 'U' +#define RBD_EXPORT_IMAGE_STRIPECOUNT 'C' #define RBD_EXPORT_IMAGE_END 'E' enum SnapshotPresence { diff --git a/src/tools/rbd/action/Export.cc b/src/tools/rbd/action/Export.cc index bac84cf619c25..7fada5442ca75 100644 --- a/src/tools/rbd/action/Export.cc +++ b/src/tools/rbd/action/Export.cc @@ -415,6 +415,19 @@ static int do_export(librbd::Image& image, const char *path, bool no_progress, i ::encode(tag, bl); ::encode(features, bl); + // encode stripe_unit and stripe_count + tag = RBD_EXPORT_IMAGE_STRIPEUNIT; + uint64_t stripe_unit; + stripe_unit = image.get_stripe_unit(); + ::encode(tag, bl); + ::encode(stripe_unit, bl); + + tag = RBD_EXPORT_IMAGE_STRIPECOUNT; + uint64_t stripe_count; + stripe_count = image.get_stripe_count(); + ::encode(tag, bl); + ::encode(stripe_count, bl); + // encode end tag tag = RBD_EXPORT_IMAGE_END; ::encode(tag, bl); diff --git a/src/tools/rbd/action/Import.cc b/src/tools/rbd/action/Import.cc index 8945bb94c00b6..453bf5e35dec3 100644 --- a/src/tools/rbd/action/Import.cc +++ b/src/tools/rbd/action/Import.cc @@ -420,6 +420,24 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx, if (opts.get(RBD_IMAGE_OPTION_FEATURES, &features) != 0) { opts.set(RBD_IMAGE_OPTION_FEATURES, features); } + } else if (tag == RBD_EXPORT_IMAGE_STRIPEUNIT) { + uint64_t stripe_unit = 0; + r = safe_read_exact(fd, &stripe_unit, 8); + if (r < 0) { + goto done; + } + if (opts.get(RBD_IMAGE_OPTION_STRIPE_UNIT, &stripe_unit) != 0) { + opts.set(RBD_IMAGE_OPTION_STRIPE_UNIT, stripe_unit); + } + } else if (tag == RBD_EXPORT_IMAGE_STRIPECOUNT) { + uint64_t stripe_count = 0; + r = safe_read_exact(fd, &stripe_count, 8); + if (r < 0) { + goto done; + } + if (opts.get(RBD_IMAGE_OPTION_STRIPE_COUNT, &stripe_count) != 0) { + opts.set(RBD_IMAGE_OPTION_STRIPE_COUNT, stripe_count); + } } else { std::cerr << "rbd: invalid tag in image priority zone: " << tag << std::endl; r = -EINVAL; -- 2.39.5