From 4c9a2e37b618e80e4a585e6129c5611c5b0b1fbb Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Tue, 28 Apr 2020 14:00:13 -0400 Subject: [PATCH] test: add a new program for testing ino_release_cb Create a bunch of files and get their inode numbers. Remount, look them all up by inode number and hold references. Stop looking up inodes as soon as we get a callback from libcephfs. If we got the callback, return success. Fail otherwise. Since this has the same cluster setup as the other client_trim_caps testcase, we can piggyback onto that task. Signed-off-by: Jeff Layton (cherry picked from commit c0db8a01f0a04cf9e10f3715bfb802d619bc32b9) --- .../client_trim_caps/tasks/trim-i22073.yaml | 1 + src/test/fs/CMakeLists.txt | 6 +- src/test/fs/test_ino_release_cb.cc | 77 +++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/test/fs/test_ino_release_cb.cc diff --git a/qa/suites/fs/bugs/client_trim_caps/tasks/trim-i22073.yaml b/qa/suites/fs/bugs/client_trim_caps/tasks/trim-i22073.yaml index f0ed3366c757..a86e918e656c 100644 --- a/qa/suites/fs/bugs/client_trim_caps/tasks/trim-i22073.yaml +++ b/qa/suites/fs/bugs/client_trim_caps/tasks/trim-i22073.yaml @@ -17,3 +17,4 @@ tasks: - exec: client.0: - ceph_test_trim_caps + - ceph_test_ino_release_cb diff --git a/src/test/fs/CMakeLists.txt b/src/test/fs/CMakeLists.txt index df47e74fff17..70ff64afdce7 100644 --- a/src/test/fs/CMakeLists.txt +++ b/src/test/fs/CMakeLists.txt @@ -1,5 +1,4 @@ if(${WITH_CEPHFS}) - # unittest_mds_types add_executable(unittest_mds_types mds_types.cc @@ -13,4 +12,9 @@ if(${WITH_CEPHFS}) target_link_libraries(ceph_test_trim_caps ceph-common cephfs) install(TARGETS ceph_test_trim_caps DESTINATION ${CMAKE_INSTALL_BINDIR}) + add_executable(ceph_test_ino_release_cb + test_ino_release_cb.cc + ) + target_link_libraries(ceph_test_ino_release_cb ceph-common cephfs) + install(TARGETS ceph_test_ino_release_cb DESTINATION ${CMAKE_INSTALL_BINDIR}) endif(${WITH_CEPHFS}) diff --git a/src/test/fs/test_ino_release_cb.cc b/src/test/fs/test_ino_release_cb.cc new file mode 100644 index 000000000000..4294698a46d1 --- /dev/null +++ b/src/test/fs/test_ino_release_cb.cc @@ -0,0 +1,77 @@ +#include +#include +#include +#include + +#define MAX_CEPH_FILES 1000 +#define DIRNAME "ino_release_cb" + +static volatile bool cb_done = false; + +static void cb(void *hdl, vinodeno_t vino) +{ + cb_done = true; +} + +int main(int argc, char *argv[]) +{ + inodeno_t inos[MAX_CEPH_FILES]; + struct ceph_mount_info *cmount = NULL; + + ceph_create(&cmount, "admin"); + ceph_conf_read_file(cmount, NULL); + ceph_init(cmount); + + int ret = ceph_mount(cmount, NULL); + assert(ret >= 0); + ret = ceph_mkdir(cmount, DIRNAME, 0755); + assert(ret >= 0); + ret = ceph_chdir(cmount, DIRNAME); + assert(ret >= 0); + + /* Create a bunch of files, get their inode numbers and close them */ + int i; + for (i = 0; i < MAX_CEPH_FILES; ++i) { + int fd; + struct ceph_statx stx; + + string name = std::to_string(i); + + fd = ceph_open(cmount, name.c_str(), O_RDWR|O_CREAT, 0644); + assert(fd >= 0); + + ret = ceph_fstatx(cmount, fd, &stx, CEPH_STATX_INO, 0); + assert(ret >= 0); + + inos[i] = stx.stx_ino; + ceph_close(cmount, fd); + } + + /* Remount */ + ceph_unmount(cmount); + ceph_release(cmount); + ceph_create(&cmount, "admin"); + ceph_conf_read_file(cmount, NULL); + ceph_init(cmount); + + struct ceph_client_callback_args args = { 0 }; + args.ino_release_cb = cb; + ceph_ll_register_callbacks(cmount, &args); + + ret = ceph_mount(cmount, NULL); + assert(ret >= 0); + + Inode *inodes[MAX_CEPH_FILES]; + + for (i = 0; i < MAX_CEPH_FILES; ++i) { + /* We can stop if we got a callback */ + if (cb_done) + break; + + ret = ceph_ll_lookup_inode(cmount, inos[i], &inodes[i]); + assert(ret >= 0); + } + + assert(cb_done); + return 0; +} -- 2.47.3