diff mbox series

[32/42] lustre: enc: S_ENCRYPTED flag on OST objects for enc files

Message ID 1674514855-15399-33-git-send-email-jsimmons@infradead.org (mailing list archive)
State New, archived
Headers show
Series lustre: sync to OpenSFS tree as of Jan 22 2023 | expand

Commit Message

James Simmons Jan. 23, 2023, 11 p.m. UTC
From: Sebastien Buisson <sbuisson@ddn.com>

Add a dumb encryption context on OST objects being created, when the
LUSTRE_ENCRYPT_FL flag gets set in the LMA, for ldiskfs backend
targets. This leads ldiskfs to internally set the LDISKFS_ENCRYPT_FL
flag on the on-disk inode. Also, it makes e2fsprogs happy to see an
enc ctx for an inode that has the LDISKFS_ENCRYPT_FL flag.

Add a dumb encryption context on OST objects being opened, if there is
not already one, for ldiskfs backend targets. This is done by adding
the LUSTRE_ENCRYPT_FL flag if necessary, at the same time as atime
gets updated. It is some sort of live self-check that fixes OST
objects created with an older Lustre version.

WC-bug-id: https://jira.whamcloud.com/browse/LU-16091
Lustre-commit: 348446d6370b3f63f ("LU-16091 enc: S_ENCRYPTED flag on OST objects for enc files")
Signed-off-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48198
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 fs/lustre/include/obd_support.h |  1 +
 fs/lustre/llite/file.c          |  5 +++++
 fs/lustre/llite/llite_lib.c     |  5 +++++
 fs/lustre/osc/osc_request.c     | 10 ++++++++++
 4 files changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/fs/lustre/include/obd_support.h b/fs/lustre/include/obd_support.h
index b58c1df4b538..a2930c800736 100644
--- a/fs/lustre/include/obd_support.h
+++ b/fs/lustre/include/obd_support.h
@@ -509,6 +509,7 @@  extern char obd_jobid_var[];
 #define OBD_FAIL_LFSCK_NO_DOUBLESCAN			0x160c
 #define OBD_FAIL_LFSCK_INVALID_PFID			0x1619
 #define OBD_FAIL_LFSCK_BAD_NAME_HASH			0x1628
+#define OBD_FAIL_LFSCK_NO_ENCFLAG			0x1632
 
 /* UPDATE */
 #define OBD_FAIL_UPDATE_OBJ_NET				0x1700
diff --git a/fs/lustre/llite/file.c b/fs/lustre/llite/file.c
index dac829fb977e..e343fc83d707 100644
--- a/fs/lustre/llite/file.c
+++ b/fs/lustre/llite/file.c
@@ -5338,6 +5338,11 @@  int ll_getattr_dentry(struct dentry *de, struct kstat *stat, u32 request_mask,
 	stat->attributes_mask |= STATX_ATTR_ENCRYPTED;
 #endif
 	stat->attributes |= ll_inode_to_ext_flags(inode->i_flags);
+	/* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
+	 * ext4 equivalent to please statx
+	 */
+	if (stat->attributes & LUSTRE_ENCRYPT_FL)
+		stat->attributes |= STATX_ATTR_ENCRYPTED;
 	stat->result_mask &= request_mask;
 
 	ll_stats_ops_tally(sbi, LPROC_LL_GETATTR,
diff --git a/fs/lustre/llite/llite_lib.c b/fs/lustre/llite/llite_lib.c
index 4bc91dddb6a7..30056a6e26b2 100644
--- a/fs/lustre/llite/llite_lib.c
+++ b/fs/lustre/llite/llite_lib.c
@@ -2873,6 +2873,11 @@  int ll_iocontrol(struct inode *inode, struct file *file,
 		body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
 
 		flags = body->mbo_flags;
+		/* if Lustre specific LUSTRE_ENCRYPT_FL flag is set, also set
+		 * ext4 equivalent to please lsattr and other e2fsprogs tools
+		 */
+		if (flags & LUSTRE_ENCRYPT_FL)
+			flags |= STATX_ATTR_ENCRYPTED;
 
 		ptlrpc_req_finished(req);
 
diff --git a/fs/lustre/osc/osc_request.c b/fs/lustre/osc/osc_request.c
index fb0facc8ddd1..bd294c5085d8 100644
--- a/fs/lustre/osc/osc_request.c
+++ b/fs/lustre/osc/osc_request.c
@@ -1792,6 +1792,16 @@  static int osc_brw_prep_request(int cmd, struct client_obd *cli,
 	else /* short i/o */
 		ioobj_max_brw_set(ioobj, 0);
 
+	if (inode && IS_ENCRYPTED(inode) &&
+	    fscrypt_has_encryption_key(inode) &&
+	    !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_ENCFLAG)) {
+		if ((body->oa.o_valid & OBD_MD_FLFLAGS) == 0) {
+			body->oa.o_valid |= OBD_MD_FLFLAGS;
+			body->oa.o_flags = 0;
+		}
+		body->oa.o_flags |= LUSTRE_ENCRYPT_FL;
+	}
+
 	if (short_io_size != 0) {
 		if ((body->oa.o_valid & OBD_MD_FLFLAGS) == 0) {
 			body->oa.o_valid |= OBD_MD_FLFLAGS;