1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 Red Hat
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.
17 #include "include/rados/librados.hpp"
18 #include "mds/CInode.h"
20 #include "cls_cephfs_client.h"
22 #define XATTR_CEILING "scan_ceiling"
23 #define XATTR_MAX_MTIME "scan_max_mtime"
24 #define XATTR_MAX_SIZE "scan_max_size"
26 int ClsCephFSClient::accumulate_inode_metadata(
29 const uint64_t obj_index
,
30 const uint64_t obj_size
,
41 // Generate 0th object name, where we will accumulate sizes/mtimes
42 object_t zeroth_object
= InodeStore::get_object_name(inode_no
, frag_t(), "");
44 // Construct a librados operation invoking our class method
45 librados::ObjectReadOperation op
;
48 op
.exec("cephfs", "accumulate_inode_metadata", inbl
);
52 return ctx
.operate(zeroth_object
.name
, &op
, &outbl
);
55 int ClsCephFSClient::delete_inode_accumulate_result(
57 const std::string
&oid
)
59 librados::ObjectWriteOperation op
;
61 // Remove xattrs from object
63 op
.rmxattr(XATTR_CEILING
);
64 op
.rmxattr(XATTR_MAX_SIZE
);
65 op
.rmxattr(XATTR_MAX_MTIME
);
67 return (ctx
.operate(oid
, &op
));
70 int ClsCephFSClient::fetch_inode_accumulate_result(
72 const std::string
&oid
,
73 inode_backtrace_t
*backtrace
,
74 file_layout_t
*layout
,
75 AccumulateResult
*result
)
77 ceph_assert(backtrace
!= NULL
);
78 ceph_assert(result
!= NULL
);
80 librados::ObjectReadOperation op
;
82 int scan_ceiling_r
= 0;
83 bufferlist scan_ceiling_bl
;
84 op
.getxattr(XATTR_CEILING
, &scan_ceiling_bl
, &scan_ceiling_r
);
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
);
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
);
96 op
.getxattr("parent", &parent_bl
, &parent_r
);
97 op
.set_op_flags2(librados::OP_FAILOK
);
100 bufferlist layout_bl
;
101 op
.getxattr("layout", &layout_bl
, &layout_r
);
102 op
.set_op_flags2(librados::OP_FAILOK
);
105 int r
= ctx
.operate(oid
, &op
, &op_bl
);
112 auto scan_ceiling_bl_iter
= scan_ceiling_bl
.cbegin();
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;
122 // Load scan_max_size
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;
131 // Load scan_max_mtime
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;
140 // Deserialize backtrace
141 if (parent_bl
.length()) {
143 auto q
= parent_bl
.cbegin();
144 backtrace
->decode(q
);
145 } catch (buffer::error
&e
) {
146 //dout(4) << "Corrupt backtrace on '" << oid << "': " << e << dendl;
151 // Deserialize layout
152 if (layout_bl
.length()) {
154 auto q
= layout_bl
.cbegin();
156 } catch (buffer::error
&e
) {
164 void ClsCephFSClient::build_tag_filter(
165 const std::string
&scrub_tag
,
168 ceph_assert(out_bl
!= NULL
);
170 // Leading part of bl is un-versioned string naming the filter
171 encode(std::string("cephfs.inode_tag"), *out_bl
);
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
);