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 <cephfs/libcephfs.h> |
14 |
|
15 |
int main(int argc, char *argv[]) |
16 |
{ |
17 |
char buf;
|
18 |
int pipefd[2]; |
19 |
pipe(pipefd); |
20 |
|
21 |
pid_t pid = fork(); |
22 |
assert(pid >= 0);
|
23 |
if (pid == 0) |
24 |
close(pipefd[1]);
|
25 |
else
|
26 |
close(pipefd[0]);
|
27 |
|
28 |
struct ceph_mount_info *cmount = NULL; |
29 |
|
30 |
ceph_create(&cmount, "admin");
|
31 |
ceph_conf_read_file(cmount, "/etc/ceph/ceph.conf");
|
32 |
|
33 |
int ret = ceph_mount(cmount, NULL); |
34 |
assert(ret >= 0);
|
35 |
|
36 |
if (pid == 0) { |
37 |
ret = read(pipefd[0], &buf, 1); |
38 |
assert(ret == 1);
|
39 |
|
40 |
ret = ceph_rename(cmount, "1", "3"); |
41 |
assert(ret >= 0);
|
42 |
|
43 |
ret = ceph_rename(cmount, "2", "1"); |
44 |
assert(ret >= 0);
|
45 |
|
46 |
ceph_unmount(cmount); |
47 |
printf("child exits\n");
|
48 |
} else {
|
49 |
ret = ceph_mkdirs(cmount, "1/2", 0755); |
50 |
assert(ret >= 0);
|
51 |
|
52 |
struct ceph_statx stx;
|
53 |
ret = ceph_statx(cmount, "1", &stx, 0, 0); |
54 |
assert(ret >= 0);
|
55 |
uint64_t orig_ino = stx.stx_ino; |
56 |
|
57 |
|
58 |
ret = ceph_mkdir(cmount, "2", 0755); |
59 |
assert(ret >= 0);
|
60 |
|
61 |
ret = write(pipefd[1], &buf, 1); |
62 |
assert(ret == 1);
|
63 |
|
64 |
int wstatus;
|
65 |
ret = waitpid(pid, &wstatus, 0);
|
66 |
assert(ret >= 0);
|
67 |
assert(wstatus == 0);
|
68 |
|
69 |
// make origin '1' no parent dentry
|
70 |
ret = ceph_statx(cmount, "1", &stx, 0, 0); |
71 |
assert(ret >= 0);
|
72 |
assert(orig_ino != stx.stx_ino); |
73 |
|
74 |
// move root inode's cap_item to tail of session->caps
|
75 |
ret = ceph_statx(cmount, ".", &stx, 0, 0); |
76 |
assert(ret >= 0);
|
77 |
|
78 |
printf("waiting for crash\n");
|
79 |
pause(); |
80 |
} |
81 |
return 0; |
82 |
} |
83 |
|