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 10, 2017
1 parent fce8d83 commit 8d844f7
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/cls/rbd/cls_rbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 (set<string>::const_iterator it = keys.begin();
it != keys.end(); ++it) {
if ((*it).find(RBD_SNAP_KEY_PREFIX) != 0)
break;
snapid_t snap_id = snap_id_from_key(*it);
snap_ids.push_back(snap_id);
}
if (!keys.empty())
last_read = *(keys.rbegin());
} while (more);

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

if (new_limit == UINT64_MAX) {
CLS_LOG(20, "remove snapshot limit\n");
rc = cls_cxx_map_remove_key(hctx, "snap_limit");
Expand Down Expand Up @@ -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,
snapshot_set_limit, &h_snapshot_set_limit);

/* methods for the rbd_children object */
Expand Down

0 comments on commit 8d844f7

Please sign in to comment.