]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/cephfs/cls_cephfs_client.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / cls / cephfs / cls_cephfs_client.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) 2015 Red Hat
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
16
17 #include "include/rados/librados.hpp"
18 #include "mds/CInode.h"
19
20 #include "cls_cephfs_client.h"
21
22 #define XATTR_CEILING "scan_ceiling"
23 #define XATTR_MAX_MTIME "scan_max_mtime"
24 #define XATTR_MAX_SIZE "scan_max_size"
25
26 int ClsCephFSClient::accumulate_inode_metadata(
27 librados::IoCtx &ctx,
28 inodeno_t inode_no,
29 const uint64_t obj_index,
30 const uint64_t obj_size,
31 const time_t mtime)
32 {
33 AccumulateArgs args(
34 obj_index,
35 obj_size,
36 mtime,
37 XATTR_CEILING,
38 XATTR_MAX_MTIME,
39 XATTR_MAX_SIZE);
40
41 // Generate 0th object name, where we will accumulate sizes/mtimes
42 object_t zeroth_object = InodeStore::get_object_name(inode_no, frag_t(), "");
43
44 // Construct a librados operation invoking our class method
45 librados::ObjectReadOperation op;
46 bufferlist inbl;
47 args.encode(inbl);
48 op.exec("cephfs", "accumulate_inode_metadata", inbl);
49
50 // Execute op
51 bufferlist outbl;
52 return ctx.operate(zeroth_object.name, &op, &outbl);
53 }
54
55 int ClsCephFSClient::delete_inode_accumulate_result(
56 librados::IoCtx &ctx,
57 const std::string &oid)
58 {
59 librados::ObjectWriteOperation op;
60
61 // Remove xattrs from object
62 //
63 op.rmxattr(XATTR_CEILING);
64 op.rmxattr(XATTR_MAX_SIZE);
65 op.rmxattr(XATTR_MAX_MTIME);
66
67 return (ctx.operate(oid, &op));
68 }
69
70 int ClsCephFSClient::fetch_inode_accumulate_result(
71 librados::IoCtx &ctx,
72 const std::string &oid,
73 inode_backtrace_t *backtrace,
74 file_layout_t *layout,
75 AccumulateResult *result)
76 {
77 ceph_assert(backtrace != NULL);
78 ceph_assert(result != NULL);
79
80 librados::ObjectReadOperation op;
81
82 int scan_ceiling_r = 0;
83 bufferlist scan_ceiling_bl;
84 op.getxattr(XATTR_CEILING, &scan_ceiling_bl, &scan_ceiling_r);
85
86 int scan_max_size_r = 0;
87 bufferlist scan_max_size_bl;
88 op.getxattr(XATTR_MAX_SIZE, &scan_max_size_bl, &scan_max_size_r);
89
90 int scan_max_mtime_r = 0;
91 bufferlist scan_max_mtime_bl;
92 op.getxattr(XATTR_MAX_MTIME, &scan_max_mtime_bl, &scan_max_mtime_r);
93
94 int parent_r = 0;
95 bufferlist parent_bl;
96 op.getxattr("parent", &parent_bl, &parent_r);
97 op.set_op_flags2(librados::OP_FAILOK);
98
99 int layout_r = 0;
100 bufferlist layout_bl;
101 op.getxattr("layout", &layout_bl, &layout_r);
102 op.set_op_flags2(librados::OP_FAILOK);
103
104 bufferlist op_bl;
105 int r = ctx.operate(oid, &op, &op_bl);
106 if (r < 0) {
107 return r;
108 }
109
110 // Load scan_ceiling
111 try {
112 auto scan_ceiling_bl_iter = scan_ceiling_bl.cbegin();
113 ObjCeiling ceiling;
114 ceiling.decode(scan_ceiling_bl_iter);
115 result->ceiling_obj_index = ceiling.id;
116 result->ceiling_obj_size = ceiling.size;
117 } catch (const buffer::error &err) {
118 //dout(4) << "Invalid size attr on '" << oid << "'" << dendl;
119 return -EINVAL;
120 }
121
122 // Load scan_max_size
123 try {
124 auto scan_max_size_bl_iter = scan_max_size_bl.cbegin();
125 decode(result->max_obj_size, scan_max_size_bl_iter);
126 } catch (const buffer::error &err) {
127 //dout(4) << "Invalid size attr on '" << oid << "'" << dendl;
128 return -EINVAL;
129 }
130
131 // Load scan_max_mtime
132 try {
133 auto scan_max_mtime_bl_iter = scan_max_mtime_bl.cbegin();
134 decode(result->max_mtime, scan_max_mtime_bl_iter);
135 } catch (const buffer::error &err) {
136 //dout(4) << "Invalid size attr on '" << oid << "'" << dendl;
137 return -EINVAL;
138 }
139
140 // Deserialize backtrace
141 if (parent_bl.length()) {
142 try {
143 auto q = parent_bl.cbegin();
144 backtrace->decode(q);
145 } catch (buffer::error &e) {
146 //dout(4) << "Corrupt backtrace on '" << oid << "': " << e << dendl;
147 return -EINVAL;
148 }
149 }
150
151 // Deserialize layout
152 if (layout_bl.length()) {
153 try {
154 auto q = layout_bl.cbegin();
155 decode(*layout, q);
156 } catch (buffer::error &e) {
157 return -EINVAL;
158 }
159 }
160
161 return 0;
162 }
163
164 void ClsCephFSClient::build_tag_filter(
165 const std::string &scrub_tag,
166 bufferlist *out_bl)
167 {
168 ceph_assert(out_bl != NULL);
169
170 // Leading part of bl is un-versioned string naming the filter
171 encode(std::string("cephfs.inode_tag"), *out_bl);
172
173 // Filter-specific part of the bl: in our case this is a versioned structure
174 InodeTagFilterArgs args;
175 args.scrub_tag = scrub_tag;
176 args.encode(*out_bl);
177 }