]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test: add a new program for testing ino_release_cb
authorJeff Layton <jlayton@redhat.com>
Tue, 28 Apr 2020 18:00:13 +0000 (14:00 -0400)
committerNathan Cutler <ncutler@suse.com>
Thu, 4 Jun 2020 13:03:50 +0000 (15:03 +0200)
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 <jlayton@redhat.com>
(cherry picked from commit c0db8a01f0a04cf9e10f3715bfb802d619bc32b9)

qa/suites/fs/bugs/client_trim_caps/tasks/trim-i22073.yaml
src/test/fs/CMakeLists.txt
src/test/fs/test_ino_release_cb.cc [new file with mode: 0644]

index f0ed3366c7575c7d72a9affbfcd9739f3a834408..a86e918e656c215f260001725fafde31e62908c3 100644 (file)
@@ -17,3 +17,4 @@ tasks:
 - exec:
     client.0:
     - ceph_test_trim_caps
+    - ceph_test_ino_release_cb
index df47e74fff176805bb55555218efa6330df437a9..70ff64afdce7f944e86dcd53f394cc5c0a0cb3ee 100644 (file)
@@ -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 (file)
index 0000000..4294698
--- /dev/null
@@ -0,0 +1,77 @@
+#include <string>
+#include <include/fs_types.h>
+#include <mds/mdstypes.h>
+#include <include/cephfs/libcephfs.h>
+
+#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;
+}