]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: encode optmetadata in InodeStat sent to clients
authorPatrick Donnelly <pdonnell@ibm.com>
Wed, 23 Oct 2024 18:00:35 +0000 (14:00 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Thu, 27 Feb 2025 18:41:55 +0000 (13:41 -0500)
Deliberately do not dump the entire struct. Some metadata may not be
appropriate to share to clients.

Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
Fixes: https://tracker.ceph.com/issues/66373
src/mds/CInode.cc
src/messages/MClientReply.h

index e83b562a1f96a84704f01f7e8617307d4ad685a9..57041fcce8ab3f34d7c97e574655ba6e96d23ca2 100644 (file)
@@ -3956,7 +3956,24 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
   } else {
     xattr_version = 0;
   }
-  
+
+  bufferlist optmdbl;
+  {
+    decltype(InodeStat::optmetadata) optmetadata;
+    using kind_t = decltype(optmetadata)::optkind_t;
+
+    auto* csp = get_charmap();
+    if (csp) {
+      dout(25) << *csp << dendl;
+      auto& opt = optmetadata.get_or_create_opt(kind_t::CHARMAP);
+      auto& cs = opt.template get_meta< charmap_md_t >();
+      cs = *csp;
+      dout(25) << "cs now " << cs << dendl;
+    }
+
+    encode(optmetadata, optmdbl);
+  }
+
   // do we have room?
   if (max_bytes) {
     unsigned bytes =
@@ -3970,6 +3987,7 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
       sizeof(struct ceph_dir_layout) // dir_layout
       + 4 + file_i->fscrypt_auth.size() // len + data
       + 4 + file_i->fscrypt_file.size() // len + data
+      + optmdbl.length()
       ;
 
     if (xattr_version) {
@@ -4124,7 +4142,7 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
    * note: encoding matches MClientReply::InodeStat
    */
   if (session->info.has_feature(CEPHFS_FEATURE_REPLY_ENCODING)) {
-    ENCODE_START(7, 1, bl);
+    ENCODE_START(8, 1, bl);
     encode(std::tuple{
       oi->ino,
       snapid,
@@ -4176,6 +4194,8 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
     encode(!file_i->fscrypt_auth.empty(), bl);
     encode(file_i->fscrypt_auth, bl);
     encode(file_i->fscrypt_file, bl);
+    encode_nohead(optmdbl, bl);
+    // encode inodestat
     ENCODE_FINISH(bl);
   }
   else {
index a18c595edb175716a91293c842c72dd1dd540baf..be34e8d4f7cc2027e3f87e5590062a74abaf770b 100644 (file)
@@ -115,6 +115,8 @@ struct DirStat {
 };
 
 struct InodeStat {
+  using optmetadata_singleton_client_t = optmetadata_singleton<optmetadata_client_t<std::allocator>,std::allocator>;
+
   vinodeno_t vino;
   uint32_t rdev = 0;
   version_t version = 0;
@@ -149,12 +151,18 @@ struct InodeStat {
   std::vector<uint8_t> fscrypt_auth;
   std::vector<uint8_t> fscrypt_file;
 
+  optmetadata_multiton<optmetadata_singleton_client_t,std::allocator> optmetadata;
+
  public:
   InodeStat() {}
   InodeStat(ceph::buffer::list::const_iterator& p, const uint64_t features) {
     decode(p, features);
   }
 
+  void print(std::ostream& os) const {
+    os << "InodeStat(... " << optmetadata << ")";
+  }
+
   void decode(ceph::buffer::list::const_iterator &p, const uint64_t features) {
     using ceph::decode;
     if (features == (uint64_t)-1) {
@@ -221,6 +229,9 @@ struct InodeStat {
         decode(fscrypt_auth, p);
         decode(fscrypt_file, p);
       }
+      if (struct_v >= 8) {
+        decode(optmetadata, p);
+      }
       DECODE_FINISH(p);
     }
     else {