uint32_t ceph_get_cap_return_timeout(ceph_mount_info *cmount)
void ceph_set_uuid(ceph_mount_info *cmount, const char *uuid)
void ceph_set_session_timeout(ceph_mount_info *cmount, unsigned timeout)
+ int ceph_get_file_layout(ceph_mount_info *cmount, int fh, int *stripe_unit, int *stripe_count, int *object_size, int *pg_pool)
+ int ceph_get_file_pool_name(ceph_mount_info *cmount, int fh, char *buf, size_t buflen)
+ int ceph_get_default_data_pool_name(ceph_mount_info *cmount, char *buf, size_t buflen)
class Error(Exception):
with nogil:
ceph_set_session_timeout(self.cluster, _timeout)
+
+ def get_layout(self, fd):
+ """
+ Set ceph client session timeout. Must be called before mount.
+
+ :param fd: file descriptor of the file/directory for which to get the layout
+ """
+
+ if not isinstance(fd, int):
+ raise TypeError('fd must be an int')
+
+ cdef:
+ int _fd = fd
+ int stripe_unit
+ int stripe_count
+ int object_size
+ int pool_id
+ char *buf = NULL
+ int buflen = 256
+ dict_result = dict()
+
+ with nogil:
+ ret = ceph_get_file_layout(self.cluster, _fd, &stripe_unit, &stripe_count, &object_size, &pool_id)
+ if ret < 0:
+ raise make_ex(stripe_unit, "error in get_file_layout")
+ dict_result["stripe_unit"] = stripe_unit
+ dict_result["stripe_count"] = stripe_count
+ dict_result["object_size"] = object_size
+ dict_result["pool_id"] = pool_id
+
+ try:
+ while True:
+ buf = <char *>realloc_chk(buf, buflen)
+ with nogil:
+ ret = ceph_get_file_pool_name(self.cluster, _fd, buf, buflen)
+ if ret > 0:
+ dict_result["pool_name"] = decode_cstr(buf)
+ return dict_result
+ elif ret == -errno.ERANGE:
+ buflen = buflen * 2
+ else:
+ raise make_ex(ret, "error in get_file_pool_name")
+ finally:
+ free(buf)
+
+
+ def get_default_pool(self):
+ """
+ Get the default pool name and id of cephfs. This returns dict{pool_name, pool_id}.
+ """
+
+ cdef:
+ char *buf = NULL
+ int buflen = 256
+ dict_result = dict()
+
+ try:
+ while True:
+ buf = <char *>realloc_chk(buf, buflen)
+ with nogil:
+ ret = ceph_get_default_data_pool_name(self.cluster, buf, buflen)
+ if ret > 0:
+ dict_result["pool_name"] = decode_cstr(buf)
+ break
+ elif ret == -errno.ERANGE:
+ buflen = buflen * 2
+ else:
+ raise make_ex(ret, "error in get_default_data_pool_name")
+
+ with nogil:
+ ret = ceph_get_pool_id(self.cluster, buf)
+ if ret < 0:
+ raise make_ex(ret, "error in get_pool_id")
+ dict_result["pool_id"] = ret
+ return dict_result
+
+ finally:
+ free(buf)
assert_equal(10, st1["size"])
cephfs.close(fd)
cephfs.unlink(b'file-fsetattrx')
+
+@with_setup(setup_test)
+def test_get_layout():
+ fd = cephfs.open(b'file-get-layout', 'w', 0o755)
+ cephfs.write(fd, b"1111", 0)
+ assert_raises(TypeError, cephfs.get_layout, "fd")
+ l_dict = cephfs.get_layout(fd)
+ assert('stripe_unit' in l_dict.keys())
+ assert('stripe_count' in l_dict.keys())
+ assert('object_size' in l_dict.keys())
+ assert('pool_id' in l_dict.keys())
+ assert('pool_name' in l_dict.keys())
+
+ cephfs.close(fd)
+ cephfs.unlink(b'file-get-layout')
+
+@with_setup(setup_test)
+def test_get_default_pool():
+ dp_dict = cephfs.get_default_pool()
+ assert('pool_id' in dp_dict.keys())
+ assert('pool_name' in dp_dict.keys())
+
+@with_setup(setup_test)
+def test_get_pool():
+ dp_dict = cephfs.get_default_pool()
+ assert('pool_id' in dp_dict.keys())
+ assert('pool_name' in dp_dict.keys())
+ assert_equal(cephfs.get_pool_id(dp_dict["pool_name"]), dp_dict["pool_id"])
+ get_rep_cnt_cmd = "ceph osd pool get " + dp_dict["pool_name"] + " size"
+ s=os.popen(get_rep_cnt_cmd).read().strip('\n')
+ size=int(s.split(" ")[-1])
+ assert_equal(cephfs.get_pool_replication(dp_dict["pool_id"]), size)