From: Haomai Wang Date: Fri, 24 Apr 2015 15:37:13 +0000 (+0800) Subject: pycephfs: Add rename, rmdir and getxattr support X-Git-Tag: v9.0.2~227^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=940b4f0284053a685707fac4ebae4d19c8ce4a2b;p=ceph.git pycephfs: Add rename, rmdir and getxattr support Signed-off-by: Haomai Wang --- diff --git a/src/pybind/cephfs.py b/src/pybind/cephfs.py index 9f977d12bff7..b3a00e2edc50 100644 --- a/src/pybind/cephfs.py +++ b/src/pybind/cephfs.py @@ -360,6 +360,14 @@ class LibCephFS(object): if ret < 0: raise make_ex(ret, "error in mkdirs '%s'" % path) + def rmdir(self, path): + self.require_state("mounted") + if not isinstance(path, str): + raise TypeError('path must be a string') + ret = self.libcephfs.ceph_rmdir(self.cluster, c_char_p(path)) + if ret < 0: + raise make_ex(ret, "error in rmdir '%s'" % path) + def open(self, path, flags, mode): self.require_state("mounted") if not isinstance(path, str): @@ -379,6 +387,20 @@ class LibCephFS(object): if ret < 0: raise make_ex(ret, "error in close") + def getxattr(self, path, name): + if not isinstance(path, str): + raise TypeError('path must be a string') + if not isinstance(name, str): + raise TypeError('name must be a string') + + l = 255 + buf = create_string_buffer(l) + actual_l = self.libcephfs.ceph_getxattr(self.cluster, path, name, buf, c_int(l)) + if actual_l > l: + buf = create_string_buffer(actual_) + self.libcephfs.ceph_getxattr(path, name, new_buf, actual_l) + return buf.value + def setxattr(self, path, name, value, flags): if not isinstance(path, str): raise TypeError('path must be a string') @@ -424,6 +446,14 @@ class LibCephFS(object): if ret < 0: raise make_ex(ret, "error in unlink: %s" % path) + def rename(self, src, dst): + self.require_state("mounted") + if not isinstance(src, str) or not isinstance(dst, str): + raise TypeError('source and destination must be a string') + ret = self.libcephfs.ceph_rename(self.cluster, c_char_p(src), c_char_p(dst)) + if ret < 0: + raise make_ex(ret, "error in rename '%s' to '%s'" % (src, dst)) + def mds_command(self, mds_spec, args, input_data): """ :return 3-tuple of output status int, output status string, output data