From: Xiubo Li Date: Sun, 27 Sep 2020 03:53:55 +0000 (+0800) Subject: mds: add "fscrypt" flag support for inode_t X-Git-Tag: v16.1.0~9^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7fe1c57846a42443f0258fd877d7166f33fd596f;p=ceph.git 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 --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 96f6fd02b45d..a21e65ec6dd9 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 66fc0411a319..4fa9c6938558 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 1aab7637569a..4b159355e17f 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 36d5f2501106..4fc87db91242 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 3d95bacebcdf..158a447d96aa 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 4fb8c19d8d07..dca000a59bff 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 {