rbd: import/export image stripe_unit and stripe_count.

Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
This commit is contained in:
Dongsheng Yang 2016-10-13 22:38:30 -04:00
parent 912ff4d2ae
commit d7479a09b6
3 changed files with 33 additions and 0 deletions

View File

@ -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 {

View File

@ -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);

View File

@ -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;