From: John Spray Date: Mon, 29 Feb 2016 10:26:22 +0000 (+0000) Subject: pybind: fix error handling on getxattr X-Git-Tag: v10.1.0~270^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7f03c0e5b2b4da3e4c1534eefbedede3ce51de26;p=ceph.git pybind: fix error handling on getxattr The ctypes bindings returned empty string instead of raising exception. This was a bug, because it made it impossible to detect the difference between missing xattr and empty xattr. Signed-off-by: John Spray --- diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 95413fce0a6c..712163671b98 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -703,16 +703,23 @@ cdef class LibCephFS(object): char *ret_buf = NULL try: - while True: - ret_buf = realloc_chk(ret_buf, ret_length) + ret_buf = realloc_chk(ret_buf, ret_length) + with nogil: + ret = ceph_getxattr(self.cluster, _path, _name, ret_buf, + ret_length) + + if ret < 0: + raise make_ex(ret, "error in getxattr") + + if ret > ret_length: + ret_buf = realloc_chk(ret_buf, ret) with nogil: - ret = ceph_getxattr(self.cluster, _path, _name, ret_buf, ret_length) + ret = ceph_getxattr(self.cluster, _path, _name, ret_buf, + ret) if ret < 0: raise make_ex(ret, "error in getxattr") - elif ret > ret_length: - ret_length = ret - else: - return ret_buf[:ret] + + return ret_buf[:ret] finally: free(ret_buf)