]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/libcephfs/reclaim.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Tests for Ceph delegation handling
6 * (c) 2017, Jeff Layton <jlayton@redhat.com>
9 #include "gtest/gtest.h"
10 #include "include/cephfs/libcephfs.h"
11 #include "include/stat.h"
15 #include <sys/types.h>
18 #include <sys/xattr.h>
33 #define CEPHFS_RECLAIM_TIMEOUT 60
35 static int dying_client(int argc
, char **argv
)
37 struct ceph_mount_info
*cmount
;
39 /* Caller must pass in the uuid */
43 if (ceph_create(&cmount
, nullptr) != 0)
46 if (ceph_conf_read_file(cmount
, nullptr) != 0)
49 if (ceph_conf_parse_env(cmount
, nullptr) != 0)
52 if (ceph_init(cmount
) != 0)
55 ceph_set_session_timeout(cmount
, CEPHFS_RECLAIM_TIMEOUT
);
57 if (ceph_start_reclaim(cmount
, argv
[1], CEPH_RECLAIM_RESET
) != -ENOENT
)
60 ceph_set_uuid(cmount
, argv
[1]);
62 if (ceph_mount(cmount
, "/") != 0)
66 if (ceph_ll_lookup_root(cmount
, &root
) != 0)
70 struct ceph_statx stx
;
71 UserPerm
*perms
= ceph_mount_perms(cmount
);
73 if (ceph_ll_create(cmount
, root
, argv
[1], 0666, O_RDWR
|O_CREAT
|O_EXCL
,
74 &file
, &fh
, &stx
, 0, 0, perms
) != 0)
80 TEST(LibCephFS
, ReclaimReset
) {
83 const char *exe
= "/proc/self/exe";
85 sprintf(uuid
, "simplereclaim:%x", getpid());
91 execl(exe
, exe
, uuid
, nullptr);
92 /* It won't be zero of course, which is sort of the point... */
96 /* parent - wait for child to exit */
98 pid_t wp
= wait(&ret
);
100 ASSERT_EQ(WIFEXITED(ret
), true);
101 ASSERT_EQ(WEXITSTATUS(ret
), 0);
103 struct ceph_mount_info
*cmount
;
104 ASSERT_EQ(ceph_create(&cmount
, nullptr), 0);
105 ASSERT_EQ(ceph_conf_read_file(cmount
, nullptr), 0);
106 ASSERT_EQ(0, ceph_conf_parse_env(cmount
, nullptr));
107 ASSERT_EQ(ceph_init(cmount
), 0);
108 ceph_set_session_timeout(cmount
, CEPHFS_RECLAIM_TIMEOUT
);
109 ASSERT_EQ(ceph_start_reclaim(cmount
, uuid
, CEPH_RECLAIM_RESET
), 0);
110 ceph_set_uuid(cmount
, uuid
);
111 ASSERT_EQ(ceph_mount(cmount
, "/"), 0);
114 ASSERT_EQ(ceph_ll_lookup_root(cmount
, &root
), 0);
115 UserPerm
*perms
= ceph_mount_perms(cmount
);
116 struct ceph_statx stx
;
117 ASSERT_EQ(ceph_ll_lookup(cmount
, root
, uuid
, &file
, &stx
, 0, 0, perms
), 0);
119 ASSERT_EQ(ceph_ll_open(cmount
, file
, O_WRONLY
, &fh
, perms
), 0);
121 ceph_unmount(cmount
);
122 ceph_release(cmount
);
125 static int update_root_mode()
127 struct ceph_mount_info
*admin
;
128 int r
= ceph_create(&admin
, nullptr);
131 ceph_conf_read_file(admin
, nullptr);
132 ceph_conf_parse_env(admin
, nullptr);
133 ceph_conf_set(admin
, "client_permissions", "false");
134 r
= ceph_mount(admin
, "/");
137 r
= ceph_chmod(admin
, "/", 01777);
139 ceph_shutdown(admin
);
143 int main(int argc
, char **argv
)
145 int r
= update_root_mode();
149 ::testing::InitGoogleTest(&argc
, argv
);
152 return dying_client(argc
, argv
);
156 return RUN_ALL_TESTS();