Skip to content

Commit

Permalink
Merge pull request ceph#5398 from mingyuez/master
Browse files Browse the repository at this point in the history
rbd:If the image has any protected snaps,'rbd snap purge image' will return failure without removing any snaps.

Reviewed-by: Josh During <[email protected]>
Reviewed-by: Haomai Wang <[email protected]>
  • Loading branch information
yuyuyu101 committed Jul 31, 2015
2 parents d5142ba + 8a7a52d commit 1a2f290
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/rbd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -790,23 +790,37 @@ static int do_purge_snaps(librbd::Image& image)
{
MyProgressContext pc("Removing all snapshots");
std::vector<librbd::snap_info_t> snaps;
bool is_protected = false;
int r = image.snap_list(snaps);
if (r < 0) {
pc.fail();
return r;
}

for (size_t i = 0; i < snaps.size(); ++i) {
r = image.snap_remove(snaps[i].name.c_str());
if (r < 0) {
pc.fail();
return r;
} else if (0 == snaps.size()) {
return 0;
} else {
for (size_t i = 0; i < snaps.size(); ++i) {
r = image.snap_is_protected(snaps[i].name.c_str(), &is_protected);
if (r < 0) {
pc.fail();
return r;
} else if (is_protected == true) {
pc.fail();
cerr << "\r" <<snaps[i].name.c_str()<< " is a protected snap."<< std::endl;
return -EBUSY;
}
}
for (size_t i = 0; i < snaps.size(); ++i) {
r = image.snap_remove(snaps[i].name.c_str());
if (r < 0) {
pc.fail();
return r;
}
pc.update_progress(i + 1, snaps.size());
}
pc.update_progress(i + 1, snaps.size());
}

pc.finish();
return 0;
pc.finish();
return 0;
}
}

static int do_protect_snap(librbd::Image& image, const char *snapname)
Expand Down

0 comments on commit 1a2f290

Please sign in to comment.