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 <xiubli@redhat.com>
This commit is contained in:
Xiubo Li 2020-09-27 11:53:55 +08:00 committed by Patrick Donnelly
parent 39f3440e36
commit 7fe1c57846
No known key found for this signature in database
GPG Key ID: 3A2A7E25BEA8AADB
6 changed files with 25 additions and 4 deletions

View File

@ -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;
}

View File

@ -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; }

View File

@ -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 {

View File

@ -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++;

View File

@ -627,6 +627,8 @@ struct inode_t {
std::basic_string<char,std::char_traits<char>,Allocator<char>> 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<template<typename> class Allocator>
void inode_t<Allocator>::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<Allocator>::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<template<typename> class Allocator>
void inode_t<Allocator>::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<Allocator>::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);
}

View File

@ -137,6 +137,8 @@ struct InodeStat {
mds_rank_t dir_pin;
std::map<std::string,std::string> 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 {