Skip to content

Commit

Permalink
Merge pull request #1159 from ceph/wip-rbd-rm-watchers
Browse files Browse the repository at this point in the history
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
  • Loading branch information
jdurgin committed Jan 30, 2014
2 parents 15c0dd0 + e78f756 commit 7b17911
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
25 changes: 21 additions & 4 deletions src/librbd/internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1353,15 +1353,31 @@ namespace librbd {
if (r < 0) {
ldout(cct, 2) << "error opening image: " << cpp_strerror(-r) << dendl;
} else {
string header_oid = ictx->header_oid;
old_format = ictx->old_format;
unknown_format = false;
id = ictx->id;

if (ictx->snaps.size()) {
lderr(cct) << "image has snapshots - not removing" << dendl;
close_image(ictx);
return -ENOTEMPTY;
}
string header_oid = ictx->header_oid;
old_format = ictx->old_format;
unknown_format = false;
id = ictx->id;

std::list<obj_watch_t> watchers;
r = io_ctx.list_watchers(header_oid, &watchers);
if (r < 0) {
lderr(cct) << "error listing watchers" << dendl;
close_image(ictx);
return r;
}
if (watchers.size() > 1) {
lderr(cct) << "image has watchers - not removing" << dendl;
close_image(ictx);
return -EBUSY;
}
assert(watchers.size() == 1);

ictx->md_lock.get_read();
trim_image(ictx, 0, prog_ctx);
ictx->md_lock.put_read();
Expand All @@ -1375,6 +1391,7 @@ namespace librbd {
parent_info.spec, id);
if (r < 0 && r != -ENOENT) {
lderr(cct) << "error removing child from children list" << dendl;
close_image(ictx);
return r;
}
close_image(ictx);
Expand Down
20 changes: 16 additions & 4 deletions src/pybind/cephfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ class cephfs_stat(Structure):
('__unused2', c_long),
('__unused3', c_long) ]

def load_libcephfs():
"""
Load the libcephfs shared library.
"""
libcephfs_path = find_library('cephfs')
if libcephfs_path:
return CDLL(libcephfs_path)

# try harder, find_library() doesn't search LD_LIBRARY_PATH
# in addition, it doesn't seem work on centos 6.4 (see e46d2ca067b5)
try:
return CDLL('libcephfs.so.1')
except OSError:
raise EnvironmentError("Unable to find libcephfs")

class LibCephFS(object):
"""libcephfs python wrapper"""
def require_state(self, *args):
Expand All @@ -125,10 +140,7 @@ def require_state(self, *args):
"CephFS object in state %s." % (self.state))

def __init__(self, conf=None, conffile=None):
libcephfs_path = find_library('cephfs')
if not libcephfs_path:
raise EnvironmentError("Unable to find libcephfs")
self.libcephfs = CDLL(libcephfs_path)
self.libcephfs = load_libcephfs()
self.cluster = c_void_p()

if conffile is not None and not isinstance(conffile, str):
Expand Down
10 changes: 8 additions & 2 deletions src/pybind/rbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ def load_librbd():
Load the librbd shared library.
"""
librbd_path = find_library('rbd')
if not librbd_path:
if librbd_path:
return CDLL(librbd_path)

# try harder, find_library() doesn't search LD_LIBRARY_PATH
# in addition, it doesn't seem work on centos 6.4 (see e46d2ca067b5)
try:
return CDLL('librbd.so.1')
except OSError:
raise EnvironmentError("Unable to find librbd")
return CDLL(librbd_path)

class RBD(object):
"""
Expand Down
4 changes: 4 additions & 0 deletions src/test/pybind/test_rbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ def test_remove_with_snap(self):
self.image.remove_snap('snap1')

def test_remove_with_watcher(self):
data = rand_data(256)
self.image.write(data, 0)
assert_raises(ImageBusy, remove_image)
read = self.image.read(0, 256)
eq(read, data)

def test_rollback_to_snap(self):
self.image.write('\0' * 256, 0)
Expand Down
3 changes: 1 addition & 2 deletions src/test/run-rbd-tests
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ run_cli_tests() {
run_api_tests() {
recreate_pool rbd
# skip many_snaps since it takes several minutes
# skip remove_with_watcher until #2533 is fixed
nosetests -v test_rbd -e '.*many_snaps' -e '.*remove_with_watcher'
nosetests -v test_rbd -e '.*many_snaps'
# ceph_test_librbd creates its own pools
ceph_test_librbd
}
Expand Down

0 comments on commit 7b17911

Please sign in to comment.