]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/fs/test_ino_release_cb.cc
688f9ad7f67e84cf650676ab2e5cf34a74f893ed
[ceph.git] / ceph / src / test / fs / test_ino_release_cb.cc
1 #include <string>
2 #include <unistd.h>
3 #include <include/fs_types.h>
4 #include <mds/mdstypes.h>
5 #include <include/cephfs/libcephfs.h>
6
7 #define MAX_CEPH_FILES 1000
8 #define DIRNAME "ino_release_cb"
9
10 static std::atomic<bool> cb_done = false;
11
12 static void cb(void *hdl, vinodeno_t vino)
13 {
14 cb_done = true;
15 }
16
17 int main(int argc, char *argv[])
18 {
19 inodeno_t inos[MAX_CEPH_FILES];
20 struct ceph_mount_info *cmount = NULL;
21
22 ceph_create(&cmount, "admin");
23 ceph_conf_read_file(cmount, NULL);
24 ceph_init(cmount);
25
26 [[maybe_unused]] int ret = ceph_mount(cmount, NULL);
27 assert(ret >= 0);
28 ret = ceph_mkdir(cmount, DIRNAME, 0755);
29 assert(ret >= 0);
30 ret = ceph_chdir(cmount, DIRNAME);
31 assert(ret >= 0);
32
33 /* Create a bunch of files, get their inode numbers and close them */
34 int i;
35 for (i = 0; i < MAX_CEPH_FILES; ++i) {
36 int fd;
37 struct ceph_statx stx;
38
39 string name = std::to_string(i);
40
41 fd = ceph_open(cmount, name.c_str(), O_RDWR|O_CREAT, 0644);
42 assert(fd >= 0);
43
44 ret = ceph_fstatx(cmount, fd, &stx, CEPH_STATX_INO, 0);
45 assert(ret >= 0);
46
47 inos[i] = stx.stx_ino;
48 ceph_close(cmount, fd);
49 }
50
51 /* Remount */
52 ceph_unmount(cmount);
53 ceph_release(cmount);
54 ceph_create(&cmount, "admin");
55 ceph_conf_read_file(cmount, NULL);
56 ceph_init(cmount);
57
58 struct ceph_client_callback_args args = { 0 };
59 args.ino_release_cb = cb;
60 ceph_ll_register_callbacks(cmount, &args);
61
62 ret = ceph_mount(cmount, NULL);
63 assert(ret >= 0);
64
65 Inode *inodes[MAX_CEPH_FILES];
66
67 for (i = 0; i < MAX_CEPH_FILES; ++i) {
68 /* We can stop if we got a callback */
69 if (cb_done)
70 break;
71
72 ret = ceph_ll_lookup_inode(cmount, inos[i], &inodes[i]);
73 assert(ret >= 0);
74 }
75 sleep(45);
76
77 assert(cb_done);
78 ceph_unmount(cmount);
79 ceph_release(cmount);
80 return 0;
81 }