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
Conversation
src/tools/rbd/action/Snap.cc
Outdated
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/tools/rbd/action/Snap.cc
Outdated
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change has been made
There was a problem hiding this 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
thx...and for some reason, I'll come back to solve this one week later |
There was a problem hiding this 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
8d844f7
to
a72ff0d
Compare
@dillaman sorry for late, please help to review this again |
src/cls/rbd/cls_rbd.cc
Outdated
|
||
if(new_limit < snap_ids.size()) { | ||
CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str()); | ||
return -EINVAL; |
There was a problem hiding this comment.
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
src/cls/rbd/cls_rbd.cc
Outdated
@@ -2807,6 +2807,33 @@ int snapshot_set_limit(cls_method_context_t hctx, bufferlist *in, | |||
return -EINVAL; | |||
} | |||
|
|||
int max_read = RBD_MAX_KEYS_READ; |
There was a problem hiding this comment.
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
src/cls/rbd/cls_rbd.cc
Outdated
if (rc < 0) | ||
return rc; | ||
|
||
for (set<string>::const_iterator it = keys.begin(); |
There was a problem hiding this comment.
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) {
src/cls/rbd/cls_rbd.cc
Outdated
@@ -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; |
There was a problem hiding this comment.
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
src/cls/rbd/cls_rbd.cc
Outdated
@@ -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, |
There was a problem hiding this comment.
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
fd606e2
to
9038d30
Compare
updated, please help to review this @yangdongsheng @dillaman |
src/cls/rbd/cls_rbd.cc
Outdated
} while (more); | ||
|
||
if (new_limit < snap_count){ | ||
CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str()); |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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.
There was a problem hiding this 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)?
src/cls/rbd/cls_rbd.cc
Outdated
|
||
if (new_limit < snap_count){ | ||
rc = -ERANGE; | ||
CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str()); |
There was a problem hiding this comment.
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".
src/cls/rbd/cls_rbd.cc
Outdated
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) { |
There was a problem hiding this comment.
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.
ok, do it right now |
a213806
to
f36692c
Compare
@PCzhangPC The two new unit tests failed |
@dillaman i'm woring on this, thx |
@dillaman now i use two different logic to handle v1 and v2 format, please help to review this |
eccd9da
to
928046b
Compare
src/cls/rbd/cls_rbd.cc
Outdated
if (!keys.empty()) | ||
last_read = *(keys.rbegin()); | ||
} while (more); | ||
} else { |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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>
@dillaman update already, please help to review this if convenient for you, thx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Snap limit shouldn't be set smaller than the number of existing snaps.
Signed-off-by: PCzhangPC pengcheng.zhang@easystack.cn