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.
16 #include "cls_cephfs_client.h"
17 #include "include/rados/librados.hpp"
18 #include "mds/CInode.h"
20 #define XATTR_CEILING "scan_ceiling"
21 #define XATTR_MAX_MTIME "scan_max_mtime"
22 #define XATTR_MAX_SIZE "scan_max_size"
24 int ClsCephFSClient::accumulate_inode_metadata(
27 const uint64_t obj_index,
28 const uint64_t obj_size,
39 // Generate 0th object name, where we will accumulate sizes/mtimes
40 object_t zeroth_object = InodeStore::get_object_name(inode_no, frag_t(), "");
42 // Construct a librados operation invoking our class method
43 librados::ObjectReadOperation op;
46 op.exec("cephfs", "accumulate_inode_metadata", inbl);
50 return ctx.operate(zeroth_object.name, &op, &outbl);
53 int ClsCephFSClient::delete_inode_accumulate_result(
55 const std::string &oid)
57 librados::ObjectWriteOperation op;
59 // Remove xattrs from object
61 op.rmxattr(XATTR_CEILING);
62 op.rmxattr(XATTR_MAX_SIZE);
63 op.rmxattr(XATTR_MAX_MTIME);
65 return (ctx.operate(oid, &op));
68 int ClsCephFSClient::fetch_inode_accumulate_result(
70 const std::string &oid,
71 inode_backtrace_t *backtrace,
72 file_layout_t *layout,
73 AccumulateResult *result)
75 assert(backtrace != NULL);
76 assert(result != NULL);
78 librados::ObjectReadOperation op;
80 int scan_ceiling_r = 0;
81 bufferlist scan_ceiling_bl;
82 op.getxattr(XATTR_CEILING, &scan_ceiling_bl, &scan_ceiling_r);
84 int scan_max_size_r = 0;
85 bufferlist scan_max_size_bl;
86 op.getxattr(XATTR_MAX_SIZE, &scan_max_size_bl, &scan_max_size_r);
88 int scan_max_mtime_r = 0;
89 bufferlist scan_max_mtime_bl;
90 op.getxattr(XATTR_MAX_MTIME, &scan_max_mtime_bl, &scan_max_mtime_r);
94 op.getxattr("parent", &parent_bl, &parent_r);
95 op.set_op_flags2(librados::OP_FAILOK);
99 op.getxattr("layout", &layout_bl, &layout_r);
100 op.set_op_flags2(librados::OP_FAILOK);
103 int r = ctx.operate(oid, &op, &op_bl);
110 bufferlist::iterator scan_ceiling_bl_iter = scan_ceiling_bl.begin();
112 ceiling.decode(scan_ceiling_bl_iter);
113 result->ceiling_obj_index = ceiling.id;
114 result->ceiling_obj_size = ceiling.size;
115 } catch (const buffer::error &err) {
116 //dout(4) << "Invalid size attr on '" << oid << "'" << dendl;
120 // Load scan_max_size
122 bufferlist::iterator scan_max_size_bl_iter = scan_max_size_bl.begin();
123 ::decode(result->max_obj_size, scan_max_size_bl_iter);
124 } catch (const buffer::error &err) {
125 //dout(4) << "Invalid size attr on '" << oid << "'" << dendl;
129 // Load scan_max_mtime
131 bufferlist::iterator scan_max_mtime_bl_iter = scan_max_mtime_bl.begin();
132 ::decode(result->max_mtime, scan_max_mtime_bl_iter);
133 } catch (const buffer::error &err) {
134 //dout(4) << "Invalid size attr on '" << oid << "'" << dendl;
138 // Deserialize backtrace
139 if (parent_bl.length()) {
141 bufferlist::iterator q = parent_bl.begin();
142 backtrace->decode(q);
143 } catch (buffer::error &e) {
144 //dout(4) << "Corrupt backtrace on '" << oid << "': " << e << dendl;
149 // Deserialize layout
150 if (layout_bl.length()) {
152 bufferlist::iterator q = layout_bl.begin();
153 ::decode(*layout, q);
154 } catch (buffer::error &e) {
162 void ClsCephFSClient::build_tag_filter(
163 const std::string &scrub_tag,
166 assert(out_bl != NULL);
168 // Leading part of bl is un-versioned string naming the filter
169 ::encode(std::string("cephfs.inode_tag"), *out_bl);
171 // Filter-specific part of the bl: in our case this is a versioned structure
172 InodeTagFilterArgs args;
173 args.scrub_tag = scrub_tag;
174 args.encode(*out_bl);