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