]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/fs/test_trim_caps.cc
update sources to 12.2.7
[ceph.git] / ceph / src / test / fs / test_trim_caps.cc
1 #define _FILE_OFFSET_BITS 64
2 #include <features.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <sys/wait.h>
6 #include <fcntl.h>
7 #include <time.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <errno.h>
11 #include <assert.h>
12 #include <unistd.h>
13 #include <include/cephfs/libcephfs.h>
14
15 int main(int argc, char *argv[])
16 {
17 char buf;
18 int pipefd[2];
19 int rc = pipe(pipefd);
20 assert(rc >= 0);
21
22 pid_t pid = fork();
23 assert(pid >= 0);
24 if (pid == 0)
25 close(pipefd[1]);
26 else
27 close(pipefd[0]);
28
29 struct ceph_mount_info *cmount = NULL;
30
31 ceph_create(&cmount, "admin");
32 ceph_conf_read_file(cmount, NULL);
33
34 int ret = ceph_mount(cmount, NULL);
35 assert(ret >= 0);
36
37 if (pid == 0) {
38 ret = read(pipefd[0], &buf, 1);
39 assert(ret == 1);
40
41 ret = ceph_rename(cmount, "1", "3");
42 assert(ret >= 0);
43
44 ret = ceph_rename(cmount, "2", "1");
45 assert(ret >= 0);
46
47 ceph_unmount(cmount);
48 printf("child exits\n");
49 } else {
50 ret = ceph_mkdirs(cmount, "1/2", 0755);
51 assert(ret >= 0);
52
53 struct ceph_statx stx;
54 ret = ceph_statx(cmount, "1", &stx, 0, 0);
55 assert(ret >= 0);
56 uint64_t orig_ino = stx.stx_ino;
57
58
59 ret = ceph_mkdir(cmount, "2", 0755);
60 assert(ret >= 0);
61
62 ret = write(pipefd[1], &buf, 1);
63 assert(ret == 1);
64
65 int wstatus;
66 ret = waitpid(pid, &wstatus, 0);
67 assert(ret >= 0);
68 assert(wstatus == 0);
69
70 // make origin '1' no parent dentry
71 ret = ceph_statx(cmount, "1", &stx, 0, 0);
72 assert(ret >= 0);
73 assert(orig_ino != stx.stx_ino);
74
75 // move root inode's cap_item to tail of session->caps
76 ret = ceph_statx(cmount, ".", &stx, 0, 0);
77 assert(ret >= 0);
78
79 printf("waiting for crash\n");
80 sleep(60);
81 }
82 return 0;
83 }