[PATCH 2/3] ext4: add helper to check if flag is changed by ctx

From: Baokun Li
Date: Thu Mar 16 2023 - 07:29:58 EST


Add helper to check if flag will be changed, return 1 means it will be
set, -1 means it will be cleared, 0 means it will not be changed.

Signed-off-by: Baokun Li <libaokun1@xxxxxxxxxx>
---
fs/ext4/super.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 5b4a323c218b..fefcd42f34ea 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2042,13 +2042,26 @@ ctx_test_##name(struct ext4_fs_context *ctx, unsigned long flag) \
return (ctx->vals_s_##name & flag); \
}

+#define EXT4_CHANGED_CTX(name) \
+static inline int \
+ctx_changed_##name(struct ext4_fs_context *ctx, unsigned long flag) \
+{ \
+ if (ctx->vals_s_##name & flag) \
+ return 1; \
+ if (ctx->mask_s_##name & flag) \
+ return -1; \
+ return 0; \
+}
+
EXT4_SET_CTX(flags); /* set only */
EXT4_SET_CTX(mount_opt);
EXT4_CLEAR_CTX(mount_opt);
EXT4_TEST_CTX(mount_opt);
+EXT4_CHANGED_CTX(mount_opt);
EXT4_SET_CTX(mount_opt2);
EXT4_CLEAR_CTX(mount_opt2);
EXT4_TEST_CTX(mount_opt2);
+EXT4_CHANGED_CTX(mount_opt2);

static inline void ctx_set_mount_flag(struct ext4_fs_context *ctx, int bit)
{
@@ -2537,9 +2550,7 @@ static int ext4_check_quota_consistency(struct fs_context *fc,

quota_flags = EXT4_MOUNT_QUOTA | EXT4_MOUNT_USRQUOTA |
EXT4_MOUNT_GRPQUOTA | EXT4_MOUNT_PRJQUOTA;
- if (quota_loaded &&
- ctx->mask_s_mount_opt & quota_flags &&
- !ctx_test_mount_opt(ctx, quota_flags))
+ if (quota_loaded && (ctx_changed_mount_opt(ctx, quota_flags) < 0))
goto err_quota_change;

if (ctx->spec & EXT4_SPEC_JQUOTA) {
--
2.31.1