From 705098d132a46d5fe8d5aafd179444b54225a200 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Tue, 6 Dec 2022 17:49:40 +0000 Subject: [PATCH] cls/cephfs: extend accumulate_inode_metadata client method to store pool id (in scan_pool_id xattr) Signed-off-by: Mykola Golub --- src/cls/cephfs/cls_cephfs.h | 5 ++++- src/cls/cephfs/cls_cephfs_client.cc | 35 ++++++++++++++++++++++++----- src/cls/cephfs/cls_cephfs_client.h | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/cls/cephfs/cls_cephfs.h b/src/cls/cephfs/cls_cephfs.h index 37d656f113a3d..8a595ae1f1178 100644 --- a/src/cls/cephfs/cls_cephfs.h +++ b/src/cls/cephfs/cls_cephfs.h @@ -137,11 +137,14 @@ public: uint64_t ceiling_obj_size; // Largest object seen uint64_t max_obj_size; + // Non-default object pool id seen + int64_t obj_pool_id; // Highest mtime seen int64_t max_mtime; AccumulateResult() - : ceiling_obj_index(0), ceiling_obj_size(0), max_obj_size(0), max_mtime(0) + : ceiling_obj_index(0), ceiling_obj_size(0), max_obj_size(0), + obj_pool_id(-1), max_mtime(0) {} }; diff --git a/src/cls/cephfs/cls_cephfs_client.cc b/src/cls/cephfs/cls_cephfs_client.cc index ecfb5957b5919..00c57cc48657c 100644 --- a/src/cls/cephfs/cls_cephfs_client.cc +++ b/src/cls/cephfs/cls_cephfs_client.cc @@ -25,12 +25,14 @@ using ceph::decode; #define XATTR_CEILING "scan_ceiling" #define XATTR_MAX_MTIME "scan_max_mtime" #define XATTR_MAX_SIZE "scan_max_size" +#define XATTR_POOL_ID "scan_pool_id" int ClsCephFSClient::accumulate_inode_metadata( librados::IoCtx &ctx, inodeno_t inode_no, const uint64_t obj_index, const uint64_t obj_size, + const int64_t obj_pool_id, const time_t mtime) { AccumulateArgs args( @@ -45,14 +47,19 @@ int ClsCephFSClient::accumulate_inode_metadata( object_t zeroth_object = InodeStore::get_object_name(inode_no, frag_t(), ""); // Construct a librados operation invoking our class method - librados::ObjectReadOperation op; + librados::ObjectWriteOperation op; bufferlist inbl; args.encode(inbl); op.exec("cephfs", "accumulate_inode_metadata", inbl); + if (obj_pool_id != -1) { + bufferlist bl; + encode(obj_pool_id, bl); + op.setxattr(XATTR_POOL_ID, bl); + } + // Execute op - bufferlist outbl; - return ctx.operate(zeroth_object.name, &op, &outbl); + return ctx.operate(zeroth_object.name, &op); } int ClsCephFSClient::delete_inode_accumulate_result( @@ -66,6 +73,8 @@ int ClsCephFSClient::delete_inode_accumulate_result( op.rmxattr(XATTR_CEILING); op.rmxattr(XATTR_MAX_SIZE); op.rmxattr(XATTR_MAX_MTIME); + op.rmxattr(XATTR_POOL_ID); + op.set_op_flags2(librados::OP_FAILOK); return (ctx.operate(oid, &op)); } @@ -95,6 +104,11 @@ int ClsCephFSClient::fetch_inode_accumulate_result( bufferlist scan_max_mtime_bl; op.getxattr(XATTR_MAX_MTIME, &scan_max_mtime_bl, &scan_max_mtime_r); + int scan_pool_id_r = 0; + bufferlist scan_pool_id_bl; + op.getxattr(XATTR_POOL_ID, &scan_pool_id_bl, &scan_pool_id_r); + op.set_op_flags2(librados::OP_FAILOK); + int parent_r = 0; bufferlist parent_bl; op.getxattr("parent", &parent_bl, &parent_r); @@ -124,7 +138,7 @@ int ClsCephFSClient::fetch_inode_accumulate_result( result->ceiling_obj_index = ceiling.id; result->ceiling_obj_size = ceiling.size; } catch (const ceph::buffer::error &err) { - //dout(4) << "Invalid size attr on '" << oid << "'" << dendl; + //dout(4) << "Invalid ceiling attr on '" << oid << "'" << dendl; return -EINVAL; } @@ -137,12 +151,23 @@ int ClsCephFSClient::fetch_inode_accumulate_result( return -EINVAL; } + // Load scan_pool_id + if (scan_pool_id_bl.length()) { + try { + auto scan_pool_id_bl_iter = scan_pool_id_bl.cbegin(); + decode(result->obj_pool_id, scan_pool_id_bl_iter); + } catch (const ceph::buffer::error &err) { + //dout(4) << "Invalid pool_id attr on '" << oid << "'" << dendl; + return -EINVAL; + } + } + // Load scan_max_mtime try { auto scan_max_mtime_bl_iter = scan_max_mtime_bl.cbegin(); decode(result->max_mtime, scan_max_mtime_bl_iter); } catch (const ceph::buffer::error &err) { - //dout(4) << "Invalid size attr on '" << oid << "'" << dendl; + //dout(4) << "Invalid mtime attr on '" << oid << "'" << dendl; return -EINVAL; } diff --git a/src/cls/cephfs/cls_cephfs_client.h b/src/cls/cephfs/cls_cephfs_client.h index a5d5481ca2122..5c33f77f21f87 100644 --- a/src/cls/cephfs/cls_cephfs_client.h +++ b/src/cls/cephfs/cls_cephfs_client.h @@ -15,6 +15,7 @@ class ClsCephFSClient inodeno_t inode_no, const uint64_t obj_index, const uint64_t obj_size, + const int64_t obj_pool_id, const time_t mtime); static int fetch_inode_accumulate_result( -- 2.39.5