]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/libcephfs/newops.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / test / libcephfs / newops.cc
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 "include/fs_types.h"
23 #include "mds/mdstypes.h"
24 #include "include/stat.h"
25 #include <errno.h>
26 #include <fcntl.h>
27 #include <unistd.h>
28 #include <string.h>
29
30 #ifdef __linux__
31 #include <limits.h>
32 #include <sys/xattr.h>
33 #endif
34
35 #include <fmt/format.h>
36 #include <map>
37 #include <vector>
38 #include <thread>
39 #include <regex>
40 #include <string>
41
42 using ::testing::AnyOf;
43 using ::testing::Gt;
44 using ::testing::Eq;
45 using namespace std;
46
47 /*
48 * Test this with different ceph versions
49 */
50
51 TEST(LibCephFS, NewOPs)
52 {
53 struct ceph_mount_info *cmount;
54 ASSERT_EQ(0, ceph_create(&cmount, NULL));
55 ASSERT_EQ(0, ceph_conf_read_file(cmount, NULL));
56 ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
57 ASSERT_EQ(0, ceph_mount(cmount, "/"));
58
59 const char *test_path = "test_newops_dir";
60
61 ASSERT_EQ(0, ceph_mkdirs(cmount, test_path, 0777));
62
63 {
64 char value[1024] = "";
65 int r = ceph_getxattr(cmount, test_path, "ceph.dir.pin.random", (void*)value, sizeof(value));
66 // Clients will return -CEPHFS_ENODATA if new getvxattr op not support yet.
67 EXPECT_THAT(r, AnyOf(Gt(0), Eq(-CEPHFS_ENODATA)));
68 }
69
70 {
71 double val = (double)1.0/(double)128.0;
72 std::stringstream ss;
73 ss << val;
74 int r = ceph_setxattr(cmount, test_path, "ceph.dir.pin.random", (void*)ss.str().c_str(), strlen(ss.str().c_str()), XATTR_CREATE);
75 // Old cephs will return -CEPHFS_EINVAL if not support "ceph.dir.pin.random" yet.
76 EXPECT_THAT(r, AnyOf(Eq(0), Eq(-CEPHFS_EINVAL)));
77
78 char value[1024] = "";
79 r = ceph_getxattr(cmount, test_path, "ceph.dir.pin.random", (void*)value, sizeof(value));
80 // Clients will return -CEPHFS_ENODATA if new getvxattr op not support yet.
81 EXPECT_THAT(r, AnyOf(Gt(0), Eq(-CEPHFS_ENODATA)));
82 }
83
84 ASSERT_EQ(0, ceph_rmdir(cmount, test_path));
85
86 ceph_shutdown(cmount);
87 }