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: snap limit should't be set smaller than the number of existing snaps #16597

Merged
merged 1 commit into from Sep 7, 2017

Conversation

PCzhangPC
Copy link

@PCzhangPC PCzhangPC commented Jul 26, 2017

Snap limit shouldn't be set smaller than the number of existing snaps.

Signed-off-by: PCzhangPC pengcheng.zhang@easystack.cn

return image.snap_set_limit(limit);
int r = image.snap_set_limit(limit);
if (r == -EINVAL)
std::cerr << "rbd: the image now has more snaps than the limit you set " << std::endl;
Copy link
Member

Choose a reason for hiding this comment

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

Looks Good.

Nit:
What about changing the error text to rbd: the image has more snaps than the new limit set to avoid you ?

Copy link
Author

Choose a reason for hiding this comment

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

sounds good , and the change has been made

Copy link
Member

@joscollin joscollin left a comment

Choose a reason for hiding this comment

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

LGTM

return image.snap_set_limit(limit);
int r = image.snap_set_limit(limit);
if (r == -EINVAL)
std::cerr << "rbd: the image has more snaps than the new limit set " << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't print this message for all -EINVAL. because we would get EINVAL in other cases, such as image.old_format == 1.

Copy link
Author

Choose a reason for hiding this comment

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

what about -EBADF, bad file number?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, EINVAL is a good choice. but the error message should not printed here. move it into snap_set_limit.

Copy link
Author

Choose a reason for hiding this comment

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

change has been made

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.

This should probably be solved in cls_rbd::snapshot_set_limit otherwise it's just a race condition [1]

[1] https://github.com/ceph/ceph/blob/master/src/cls/rbd/cls_rbd.cc#L2791

@PCzhangPC
Copy link
Author

thx...and for some reason, I'll come back to solve this one week later

@dillaman dillaman removed the needs-qa label Jul 31, 2017
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.

Please move logic to cls_rbd

@PCzhangPC
Copy link
Author

@dillaman sorry for late, please help to review this again


if(new_limit < snap_ids.size()) {
CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str());
return -EINVAL;

Choose a reason for hiding this comment

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

Nit: perhaps -ERANGE and then add op_event->ignore_error_codes = {-ERANGE}; to https://github.com/ceph/ceph/blob/master/src/librbd/journal/Replay.cc#L774

@@ -2807,6 +2807,33 @@ int snapshot_set_limit(cls_method_context_t hctx, bufferlist *in,
return -EINVAL;
}

int max_read = RBD_MAX_KEYS_READ;

Choose a reason for hiding this comment

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

Nit: move max_read and snap_ids into loop

if (rc < 0)
return rc;

for (set<string>::const_iterator it = keys.begin();

Choose a reason for hiding this comment

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

Nit: you can just use for (auto& key : keys) {

@@ -2807,6 +2807,33 @@ int snapshot_set_limit(cls_method_context_t hctx, bufferlist *in,
return -EINVAL;
}

int max_read = RBD_MAX_KEYS_READ;
vector<snapid_t> snap_ids;

Choose a reason for hiding this comment

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

Nit: use a size_t snap_count = 0; instead and increment

@@ -5305,7 +5332,7 @@ CLS_INIT(rbd)
CLS_METHOD_RD,
snapshot_get_limit, &h_snapshot_get_limit);
cls_register_cxx_method(h_class, "snapshot_set_limit",
CLS_METHOD_WR,
CLS_METHOD_WR | CLS_METHOD_RD,

Choose a reason for hiding this comment

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

Nit: for consistency, _RD before _WR

@PCzhangPC
Copy link
Author

updated, please help to review this @yangdongsheng @dillaman

} while (more);

if (new_limit < snap_count){
CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str());
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, rc should be 0. so cpp_strerror(rc) does not make sense. what about:

 if (new_limit < snap_count){
   rc = -ERANGE;
   CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str());
   return rc;
}

Copy link
Author

@PCzhangPC PCzhangPC Aug 11, 2017

Choose a reason for hiding this comment

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

oh,yes. And because there is a "return rc" after this if-condition, i remove the return here.

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.

Can you also update the cls_rbd and/or librbd unit tests to ensure this logic works as intended (and isn't broken in the future)?


if (new_limit < snap_count){
rc = -ERANGE;
CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str());

Choose a reason for hiding this comment

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

The error log should really be on line 2819 (text adjusted to "error retrieving snapshots") -- this should just be a debug log message saying "snapshot limit is less than the number of snapshots".

if (new_limit < snap_count){
rc = -ERANGE;
CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str());
} else if (new_limit == UINT64_MAX) {

Choose a reason for hiding this comment

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

Nit: no need to count the number of existing snapshots if the limit is being cleared.

@PCzhangPC
Copy link
Author

ok, do it right now

@dillaman
Copy link

@PCzhangPC The two new unit tests failed

@PCzhangPC
Copy link
Author

@dillaman i'm woring on this, thx

@PCzhangPC
Copy link
Author

@dillaman now i use two different logic to handle v1 and v2 format, please help to review this

if (!keys.empty())
last_read = *(keys.rbegin());
} while (more);
} else {
Copy link

@dillaman dillaman Aug 17, 2017

Choose a reason for hiding this comment

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

Nit: I would keep the v1 logic together -- so move this block up. I would also test for a failure to read the header:

if (rc < 0 && rc != -EINVAL) {
 ... error
} else if (rc >= 0) {
  .. v1 logic
} else {
  .. v2 logic
}

Copy link
Author

Choose a reason for hiding this comment

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

ok, will be updated next monday

new snap limit must be bigger than the num of existing snaps

Signed-off-by: PCzhangPC <pengcheng.zhang@easystack.cn>
@PCzhangPC
Copy link
Author

@dillaman update already, please help to review this if convenient for you, thx

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 dfb8139 into ceph:master Sep 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants