From 7fe1c57846a42443f0258fd877d7166f33fd596f Mon Sep 17 00:00:00 2001 From: Xiubo Li Date: Sun, 27 Sep 2020 11:53:55 +0800 Subject: [PATCH] mds: add "fscrypt" flag support for inode_t If the client has set the "encryption.ctx" attribute, the MDS side will set the "fscrypt" flag to truth, false as default. The clients could use this flag to get to know whether the current inodes are under enscrypted or not. Fixes: https://tracker.ceph.com/issues/47162 Signed-off-by: Xiubo Li --- src/client/Client.cc | 1 + src/client/Inode.h | 2 ++ src/mds/CInode.cc | 3 ++- src/mds/Server.cc | 2 ++ src/mds/mdstypes.h | 14 ++++++++++++-- src/messages/MClientReply.h | 7 ++++++- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 96f6fd02b45..a21e65ec6dd 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -1012,6 +1012,7 @@ Inode * Client::add_update_inode(InodeStat *st, utime_t from, in->snap_caps |= st->cap.caps; } + in->fscrypt = st->fscrypt; return in; } diff --git a/src/client/Inode.h b/src/client/Inode.h index 66fc0411a31..4fa9c693855 100644 --- a/src/client/Inode.h +++ b/src/client/Inode.h @@ -166,6 +166,8 @@ struct Inode { version_t inline_version; bufferlist inline_data; + bool fscrypt = false; // fscrypt enabled ? + bool is_root() const { return ino == MDS_INO_ROOT; } bool is_symlink() const { return (mode & S_IFMT) == S_IFLNK; } bool is_dir() const { return (mode & S_IFMT) == S_IFDIR; } diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 1aab7637569..4b159355e17 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -3996,7 +3996,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(5, 1, bl); + ENCODE_START(6, 1, bl); encode(oi->ino, bl); encode(snapid, bl); encode(oi->rdev, bl); @@ -4041,6 +4041,7 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session, encode(snap_btime, bl); encode(file_i->rstat.rsnaps, bl); encode(snap_metadata, bl); + encode(file_i->fscrypt, bl); ENCODE_FINISH(bl); } else { diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 36d5f250110..4fc87db9124 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -6090,6 +6090,8 @@ void Server::handle_client_setxattr(MDRequestRef& mdr) pi.inode->ctime = mdr->get_op_stamp(); if (mdr->get_op_stamp() > pi.inode->rstat.rctime) pi.inode->rstat.rctime = mdr->get_op_stamp(); + if (name == "encryption.ctx"sv) + pi.inode->fscrypt = true; pi.inode->change_attr++; pi.inode->xattr_version++; diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 3d95bacebcd..158a447d96a 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -627,6 +627,8 @@ struct inode_t { std::basic_string,Allocator> stray_prior_path; //stores path before unlink + bool fscrypt = false; // fscrypt enabled ? + private: bool older_is_consistent(const inode_t &other) const; }; @@ -635,7 +637,7 @@ private: template class Allocator> void inode_t::encode(ceph::buffer::list &bl, uint64_t features) const { - ENCODE_START(16, 6, bl); + ENCODE_START(17, 6, bl); encode(ino, bl); encode(rdev, bl); @@ -690,13 +692,15 @@ void inode_t::encode(ceph::buffer::list &bl, uint64_t features) const encode(export_ephemeral_random_pin, bl); encode(export_ephemeral_distributed_pin, bl); + encode(fscrypt, bl); + ENCODE_FINISH(bl); } template class Allocator> void inode_t::decode(ceph::buffer::list::const_iterator &p) { - DECODE_START_LEGACY_COMPAT_LEN(16, 6, 6, p); + DECODE_START_LEGACY_COMPAT_LEN(17, 6, 6, p); decode(ino, p); decode(rdev, p); @@ -794,6 +798,12 @@ void inode_t::decode(ceph::buffer::list::const_iterator &p) export_ephemeral_distributed_pin = false; } + if (struct_v >= 17) { + decode(fscrypt, p); + } else { + fscrypt = 0; + } + DECODE_FINISH(p); } diff --git a/src/messages/MClientReply.h b/src/messages/MClientReply.h index 4fb8c19d8d0..dca000a59bf 100644 --- a/src/messages/MClientReply.h +++ b/src/messages/MClientReply.h @@ -137,6 +137,8 @@ struct InodeStat { mds_rank_t dir_pin; std::map snap_metadata; + bool fscrypt = false; // fscrypt enabled ? + public: InodeStat() {} InodeStat(ceph::buffer::list::const_iterator& p, const uint64_t features) { @@ -146,7 +148,7 @@ struct InodeStat { void decode(ceph::buffer::list::const_iterator &p, const uint64_t features) { using ceph::decode; if (features == (uint64_t)-1) { - DECODE_START(5, p); + DECODE_START(6, p); decode(vino.ino, p); decode(vino.snapid, p); decode(rdev, p); @@ -200,6 +202,9 @@ struct InodeStat { if (struct_v >= 5) { decode(snap_metadata, p); } + if (struct_v >= 6) { + decode(fscrypt, p); + } DECODE_FINISH(p); } else { -- 2.39.5