Skip to content

Commit

Permalink
rbd: import/export image_order.
Browse files Browse the repository at this point in the history
Signed-off-by: Dongsheng Yang <[email protected]>
  • Loading branch information
yangdongsheng committed Feb 19, 2017
1 parent 55edd81 commit 8679521
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tools/rbd/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/tools/rbd/action/Export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
32 changes: 32 additions & 0 deletions src/tools/rbd/action/Import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8679521

Please sign in to comment.