diff mbox series

[06/21] split d_flags calculation out of d_set_d_op()

Message ID 20250224212051.1756517-6-viro@zeniv.linux.org.uk (mailing list archive)
State New
Headers show
Series [01/21] procfs: kill ->proc_dops | expand

Commit Message

Al Viro Feb. 24, 2025, 9:20 p.m. UTC
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 fs/dcache.c | 53 ++++++++++++++++++++++++++++++-----------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

Comments

Christian Brauner Feb. 26, 2025, 8:31 a.m. UTC | #1
On Mon, Feb 24, 2025 at 09:20:36PM +0000, Al Viro wrote:
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---

Reviewed-by: Christian Brauner <brauner@kernel.org>

>  fs/dcache.c | 53 ++++++++++++++++++++++++++++++-----------------------
>  1 file changed, 30 insertions(+), 23 deletions(-)
> 
> diff --git a/fs/dcache.c b/fs/dcache.c
> index cd5e5139ca4c..1201149e1e2c 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -1811,33 +1811,40 @@ struct dentry *d_alloc_name(struct dentry *parent, const char *name)
>  }
>  EXPORT_SYMBOL(d_alloc_name);
>  
> +#define DCACHE_OP_FLAGS \
> +	(DCACHE_OP_HASH | DCACHE_OP_COMPARE | DCACHE_OP_REVALIDATE | \
> +	 DCACHE_OP_WEAK_REVALIDATE | DCACHE_OP_DELETE | DCACHE_OP_REAL)
> +
> +static unsigned int d_op_flags(const struct dentry_operations *op)
> +{
> +	unsigned int flags = 0;
> +	if (op) {
> +		if (op->d_hash)
> +			flags |= DCACHE_OP_HASH;
> +		if (op->d_compare)
> +			flags |= DCACHE_OP_COMPARE;
> +		if (op->d_revalidate)
> +			flags |= DCACHE_OP_REVALIDATE;
> +		if (op->d_weak_revalidate)
> +			flags |= DCACHE_OP_WEAK_REVALIDATE;
> +		if (op->d_delete)
> +			flags |= DCACHE_OP_DELETE;
> +		if (op->d_prune)
> +			flags |= DCACHE_OP_PRUNE;
> +		if (op->d_real)
> +			flags |= DCACHE_OP_REAL;
> +	}
> +	return flags;
> +}
> +
>  void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
>  {
> +	unsigned int flags = d_op_flags(op);
>  	WARN_ON_ONCE(dentry->d_op);
> -	WARN_ON_ONCE(dentry->d_flags & (DCACHE_OP_HASH	|
> -				DCACHE_OP_COMPARE	|
> -				DCACHE_OP_REVALIDATE	|
> -				DCACHE_OP_WEAK_REVALIDATE	|
> -				DCACHE_OP_DELETE	|
> -				DCACHE_OP_REAL));
> +	WARN_ON_ONCE(dentry->d_flags & DCACHE_OP_FLAGS);
>  	dentry->d_op = op;
> -	if (!op)
> -		return;
> -	if (op->d_hash)
> -		dentry->d_flags |= DCACHE_OP_HASH;
> -	if (op->d_compare)
> -		dentry->d_flags |= DCACHE_OP_COMPARE;
> -	if (op->d_revalidate)
> -		dentry->d_flags |= DCACHE_OP_REVALIDATE;
> -	if (op->d_weak_revalidate)
> -		dentry->d_flags |= DCACHE_OP_WEAK_REVALIDATE;
> -	if (op->d_delete)
> -		dentry->d_flags |= DCACHE_OP_DELETE;
> -	if (op->d_prune)
> -		dentry->d_flags |= DCACHE_OP_PRUNE;
> -	if (op->d_real)
> -		dentry->d_flags |= DCACHE_OP_REAL;
> -
> +	if (flags)
> +		dentry->d_flags |= flags;
>  }
>  EXPORT_SYMBOL(d_set_d_op);
>  
> -- 
> 2.39.5
>
diff mbox series

Patch

diff --git a/fs/dcache.c b/fs/dcache.c
index cd5e5139ca4c..1201149e1e2c 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1811,33 +1811,40 @@  struct dentry *d_alloc_name(struct dentry *parent, const char *name)
 }
 EXPORT_SYMBOL(d_alloc_name);
 
+#define DCACHE_OP_FLAGS \
+	(DCACHE_OP_HASH | DCACHE_OP_COMPARE | DCACHE_OP_REVALIDATE | \
+	 DCACHE_OP_WEAK_REVALIDATE | DCACHE_OP_DELETE | DCACHE_OP_REAL)
+
+static unsigned int d_op_flags(const struct dentry_operations *op)
+{
+	unsigned int flags = 0;
+	if (op) {
+		if (op->d_hash)
+			flags |= DCACHE_OP_HASH;
+		if (op->d_compare)
+			flags |= DCACHE_OP_COMPARE;
+		if (op->d_revalidate)
+			flags |= DCACHE_OP_REVALIDATE;
+		if (op->d_weak_revalidate)
+			flags |= DCACHE_OP_WEAK_REVALIDATE;
+		if (op->d_delete)
+			flags |= DCACHE_OP_DELETE;
+		if (op->d_prune)
+			flags |= DCACHE_OP_PRUNE;
+		if (op->d_real)
+			flags |= DCACHE_OP_REAL;
+	}
+	return flags;
+}
+
 void d_set_d_op(struct dentry *dentry, const struct dentry_operations *op)
 {
+	unsigned int flags = d_op_flags(op);
 	WARN_ON_ONCE(dentry->d_op);
-	WARN_ON_ONCE(dentry->d_flags & (DCACHE_OP_HASH	|
-				DCACHE_OP_COMPARE	|
-				DCACHE_OP_REVALIDATE	|
-				DCACHE_OP_WEAK_REVALIDATE	|
-				DCACHE_OP_DELETE	|
-				DCACHE_OP_REAL));
+	WARN_ON_ONCE(dentry->d_flags & DCACHE_OP_FLAGS);
 	dentry->d_op = op;
-	if (!op)
-		return;
-	if (op->d_hash)
-		dentry->d_flags |= DCACHE_OP_HASH;
-	if (op->d_compare)
-		dentry->d_flags |= DCACHE_OP_COMPARE;
-	if (op->d_revalidate)
-		dentry->d_flags |= DCACHE_OP_REVALIDATE;
-	if (op->d_weak_revalidate)
-		dentry->d_flags |= DCACHE_OP_WEAK_REVALIDATE;
-	if (op->d_delete)
-		dentry->d_flags |= DCACHE_OP_DELETE;
-	if (op->d_prune)
-		dentry->d_flags |= DCACHE_OP_PRUNE;
-	if (op->d_real)
-		dentry->d_flags |= DCACHE_OP_REAL;
-
+	if (flags)
+		dentry->d_flags |= flags;
 }
 EXPORT_SYMBOL(d_set_d_op);