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

Conversation

Songweibin
Copy link
Contributor

@Songweibin Songweibin commented Feb 27, 2018

Fixes: http://tracker.ceph.com/issues/23038
@dillaman I'm not sure if this is the most correct way to fix it, please help to have a look.
Thank you in advance.

Signed-off-by: songweibin song.weibin@zte.com.cn

Copy link

@dillaman dillaman left a comment

Choose a reason for hiding this comment

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

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

auto protect = boost::lexical_cast<std::string>(is_protected);
len = protect.length() + 4;
encode(len, bl);
encode(protect, bl);

Choose a reason for hiding this comment

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

Nit: just encode the is_protected boolean instead of a string of true / false

@Songweibin
Copy link
Contributor Author

@dillaman Updated, thanks.

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

Choose a reason for hiding this comment

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

Nit: bools are encoded as u8 integer (0 for false, 1 for true)

static int get_snap_protection_status(ImportDiffContext *idiffctx, bool *is_protected)
{
int r;
char buf[sizeof(bool)];

Choose a reason for hiding this comment

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

Nit: sizeof(bool) -> sizeof(u8)

return r;
}

bufferlist bl;

Choose a reason for hiding this comment

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

Probably a bit overkill for a single bit -- perhaps just *is_protected = (buf[0] != 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dillaman Updated, thank you.

@@ -400,6 +418,8 @@ int do_import_diff_fd(librados::Rados &rados, librbd::Image &image, int fd,
r = (r < 0) ? r : temp_r; // preserve original error
if (r == 0 && tosnap.length()) {
idiffctx.image->snap_create(tosnap.c_str());
if (is_protected)
Copy link

Choose a reason for hiding this comment

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

Nit: Sorry just noticed that the error code isn't propagated. Can you modify the snap_create line above to store the return value in r, change this to if (r == 0 && is_protected), and change the line below to r = ...snap_protect?

@Songweibin
Copy link
Contributor Author

@dillaman Done, please have a look, thanks.

r = idiffctx.image->snap_protect(tosnap.c_str());
if (r < 0)
return r;
} else if (r < 0) {
Copy link

Choose a reason for hiding this comment

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

Nit: no need since it finishes the context and returns the result below.

if (r == 0 && is_protected) {
r = idiffctx.image->snap_protect(tosnap.c_str());
if (r < 0)
return r;
Copy link

Choose a reason for hiding this comment

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

Nit: no need

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, already dropped. Thanks.

Copy link

@dillaman dillaman left a comment

Choose a reason for hiding this comment

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

lgtm

@dillaman dillaman merged commit f91753d into ceph:master Mar 1, 2018
@Songweibin Songweibin deleted the wip-23038 branch March 2, 2018 00:36
@yangdongsheng
Copy link
Contributor

Hi @Songweibin , sorry for the late, but please consider to add a case in https://github.com/ceph/ceph/blob/master/qa/workunits/rbd/import_export.sh for this.

@Songweibin
Copy link
Contributor Author

@yangdongsheng Fine, will add later. Thanks.

@Songweibin
Copy link
Contributor Author

Songweibin commented Mar 2, 2018

rbd/test: add snap protection test for ex/import: #20689

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants