Skip to content

Commit

Permalink
rbd:snap limit should't be set smaller than the num of existing snaps
Browse files Browse the repository at this point in the history
new snap limit must be bigger than the num of existing snaps

Signed-off-by: PCzhangPC <pengcheng.zhang@easystack.cn>
  • Loading branch information
PCzhangPC committed Aug 11, 2017
1 parent fce8d83 commit 9038d30
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/cls/rbd/cls_rbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2807,7 +2807,29 @@ int snapshot_set_limit(cls_method_context_t hctx, bufferlist *in,
return -EINVAL;
}

if (new_limit == UINT64_MAX) {
int max_read = RBD_MAX_KEYS_READ;
size_t snap_count = 0;
string last_read = RBD_SNAP_KEY_PREFIX;
bool more;

do {
set<string> keys;
rc = cls_cxx_map_get_keys(hctx, last_read, max_read, &keys, &more);
if (rc < 0)
return rc;
for (auto& key : keys) {
if (key.find(RBD_SNAP_KEY_PREFIX) != 0)
break;
snap_count++;
}
if (!keys.empty())
last_read = *(keys.rbegin());
} while (more);

if (new_limit < snap_count){
CLS_ERR("error setting snapshot limit: %s", cpp_strerror(rc).c_str());
return -ERANGE;
} else if (new_limit == UINT64_MAX) {
CLS_LOG(20, "remove snapshot limit\n");
rc = cls_cxx_map_remove_key(hctx, "snap_limit");
} else {
Expand Down Expand Up @@ -5305,7 +5327,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_RD | CLS_METHOD_WR,
snapshot_set_limit, &h_snapshot_set_limit);

/* methods for the rbd_children object */
Expand Down
2 changes: 2 additions & 0 deletions src/librbd/journal/Replay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ void Replay<I>::handle_event(const journal::SnapLimitEvent &event,
event,
on_op_complete));

op_event->ignore_error_codes = {-ERANGE};

on_ready->complete(0);
}

Expand Down

0 comments on commit 9038d30

Please sign in to comment.