]>
Commit | Line | Data |
---|---|---|
39ae355f TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2021 Red Hat Inc. | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include "gmock/gmock.h" | |
16 | #include "gtest/gtest.h" | |
17 | #include "gtest/gtest-spi.h" | |
18 | #include "gmock/gmock-matchers.h" | |
19 | #include "gmock/gmock-more-matchers.h" | |
20 | #include "include/compat.h" | |
21 | #include "include/cephfs/libcephfs.h" | |
22 | #include "mds/mdstypes.h" | |
23 | #include "include/stat.h" | |
24 | #include <errno.h> | |
25 | #include <fcntl.h> | |
26 | #include <unistd.h> | |
27 | #include <string.h> | |
28 | ||
29 | #ifdef __linux__ | |
30 | #include <limits.h> | |
31 | #include <sys/xattr.h> | |
32 | #endif | |
33 | ||
34 | #include <fmt/format.h> | |
35 | #include <map> | |
36 | #include <vector> | |
37 | #include <thread> | |
38 | #include <regex> | |
39 | #include <string> | |
40 | ||
41 | using ::testing::AnyOf; | |
42 | using ::testing::Gt; | |
43 | using ::testing::Eq; | |
44 | using namespace std; | |
45 | ||
46 | /* | |
47 | * Test this with different ceph versions | |
48 | */ | |
49 | ||
50 | TEST(LibCephFS, NewOPs) | |
51 | { | |
52 | struct ceph_mount_info *cmount; | |
53 | ASSERT_EQ(0, ceph_create(&cmount, NULL)); | |
54 | ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL)); | |
55 | ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL)); | |
56 | ASSERT_EQ(0, ceph_mount(cmount, "/")); | |
57 | ||
58 | const char *test_path = "test_newops_dir"; | |
59 | ||
60 | ASSERT_EQ(0, ceph_mkdirs(cmount, test_path, 0777)); | |
61 | ||
62 | { | |
63 | char value[1024] = ""; | |
64 | int r = ceph_getxattr(cmount, test_path, "ceph.dir.pin.random", (void*)value, sizeof(value)); | |
65 | // Clients will return -ENODATA if new getvxattr op not support yet. | |
66 | EXPECT_THAT(r, AnyOf(Gt(0), Eq(-ENODATA))); | |
67 | } | |
68 | ||
69 | { | |
70 | double val = (double)1.0/(double)128.0; | |
71 | std::stringstream ss; | |
72 | ss << val; | |
73 | int r = ceph_setxattr(cmount, test_path, "ceph.dir.pin.random", (void*)ss.str().c_str(), strlen(ss.str().c_str()), XATTR_CREATE); | |
74 | // Old cephs will return -EINVAL if not support "ceph.dir.pin.random" yet. | |
75 | EXPECT_THAT(r, AnyOf(Eq(0), Eq(-EINVAL))); | |
76 | ||
77 | char value[1024] = ""; | |
78 | r = ceph_getxattr(cmount, test_path, "ceph.dir.pin.random", (void*)value, sizeof(value)); | |
79 | // Clients will return -ENODATA if new getvxattr op not support yet. | |
80 | EXPECT_THAT(r, AnyOf(Gt(0), Eq(-ENODATA))); | |
81 | } | |
82 | ||
83 | ASSERT_EQ(0, ceph_rmdir(cmount, test_path)); | |
84 | ||
85 | ceph_shutdown(cmount); | |
86 | } |