Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbd: import with option --export-format fails to protect snapshot #20613

Merged
merged 1 commit into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion doc/dev/rbd-export.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,21 @@ End


Diffs records
~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~

Record the all snapshots and the HEAD in this section.

Snap Protection status
----------------------

Record the snapshot's protection status if `--export-format=2`.
- u8: 'p'
- le64: length of appending data (8)
- u8: snap protection status (0 for false, 1 for true)

Others
------

- le64: number of diffs
- Diffs ...

Expand Down
2 changes: 2 additions & 0 deletions src/tools/rbd/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static const std::string RBD_DIFF_BANNER_V2 ("rbd diff v2\n");
#define RBD_DIFF_ZERO 'z'
#define RBD_DIFF_END 'e'

#define RBD_SNAP_PROTECTION_STATUS 'p'

#define RBD_EXPORT_IMAGE_ORDER 'O'
#define RBD_EXPORT_IMAGE_FEATURES 'T'
#define RBD_EXPORT_IMAGE_STRIPE_UNIT 'U'
Expand Down
17 changes: 15 additions & 2 deletions src/tools/rbd/action/Export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,25 @@ int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
encode(tag, bl);
std::string to(endsnapname);
if (export_format == 2) {
len = to.length() + 4;
encode(len, bl);
len = to.length() + 4;
encode(len, bl);
}
encode(to, bl);
}

if (endsnapname && export_format == 2) {
tag = RBD_SNAP_PROTECTION_STATUS;
encode(tag, bl);
bool is_protected = false;
r = image.snap_is_protected(endsnapname, &is_protected);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: return error code if r < 0

if (r < 0) {
return r;
}
len = 8;
encode(len, bl);
encode(is_protected, bl);
}

tag = RBD_DIFF_IMAGE_SIZE;
encode(tag, bl);
uint64_t endsize = info.size;
Expand Down
23 changes: 22 additions & 1 deletion src/tools/rbd/action/Import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ static int do_image_snap_to(ImportDiffContext *idiffctx, std::string *tosnap)
return 0;
}

static int get_snap_protection_status(ImportDiffContext *idiffctx, bool *is_protected)
{
int r;
char buf[sizeof(__u8)];
r = safe_read_exact(idiffctx->fd, buf, sizeof(buf));
if (r < 0) {
return r;
}

*is_protected = (buf[0] != 0);
idiffctx->update_progress();

return 0;
}

static int do_image_resize(ImportDiffContext *idiffctx)
{
int r;
Expand Down Expand Up @@ -371,6 +386,7 @@ int do_import_diff_fd(librados::Rados &rados, librbd::Image &image, int fd,

// begin image import
std::string tosnap;
bool is_protected = false;
ImportDiffContext idiffctx(&image, fd, size, no_progress);
while (r == 0) {
__u8 tag;
Expand All @@ -385,6 +401,8 @@ int do_import_diff_fd(librados::Rados &rados, librbd::Image &image, int fd,
r = do_image_snap_from(&idiffctx);
} else if (tag == RBD_DIFF_TO_SNAP) {
r = do_image_snap_to(&idiffctx, &tosnap);
} else if (tag == RBD_SNAP_PROTECTION_STATUS) {
r = get_snap_protection_status(&idiffctx, &is_protected);
} else if (tag == RBD_DIFF_IMAGE_SIZE) {
r = do_image_resize(&idiffctx);
} else if (tag == RBD_DIFF_WRITE || tag == RBD_DIFF_ZERO) {
Expand All @@ -399,7 +417,10 @@ int do_import_diff_fd(librados::Rados &rados, librbd::Image &image, int fd,
int temp_r = idiffctx.throttle.wait_for_ret();
r = (r < 0) ? r : temp_r; // preserve original error
if (r == 0 && tosnap.length()) {
idiffctx.image->snap_create(tosnap.c_str());
r = idiffctx.image->snap_create(tosnap.c_str());
if (r == 0 && is_protected) {
r = idiffctx.image->snap_protect(tosnap.c_str());
}
}

idiffctx.finish(r);
Expand Down