All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] erofs: clean up erofs_iget()
@ 2023-01-13  6:52 ` Gao Xiang
  0 siblings, 0 replies; 13+ messages in thread
From: Gao Xiang @ 2023-01-13  6:52 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu; +Cc: Gao Xiang, LKML

Move inode hash function into inode.c and simplify erofs_iget().

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/inode.c    | 40 +++++++++++++++++++++-------------------
 fs/erofs/internal.h |  9 ---------
 2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index d3b8736fa124..57328691582e 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -308,47 +308,49 @@ static int erofs_fill_inode(struct inode *inode)
 }
 
 /*
- * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
- * we should do more for 32-bit platform to find the right inode.
+ * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
+ * so that it will fit.
  */
-static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
+static ino_t erofs_squash_ino(erofs_nid_t nid)
 {
-	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
+	ino_t ino = (ino_t)nid;
+
+	if (sizeof(ino_t) < sizeof(erofs_nid_t))
+		ino ^= nid >> (sizeof(erofs_nid_t) - sizeof(ino_t)) * 8;
+	return ino;
+}
 
-	return EROFS_I(inode)->nid == nid;
+static int erofs_iget5_eq(struct inode *inode, void *opaque)
+{
+	return EROFS_I(inode)->nid == *(erofs_nid_t *)opaque;
 }
 
-static int erofs_iget_set_actor(struct inode *inode, void *opaque)
+static int erofs_iget5_set(struct inode *inode, void *opaque)
 {
 	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
 
-	inode->i_ino = erofs_inode_hash(nid);
+	inode->i_ino = erofs_squash_ino(nid);
+	EROFS_I(inode)->nid = nid;
 	return 0;
 }
 
 struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid)
 {
-	const unsigned long hashval = erofs_inode_hash(nid);
 	struct inode *inode;
 
-	inode = iget5_locked(sb, hashval, erofs_ilookup_test_actor,
-		erofs_iget_set_actor, &nid);
+	inode = iget5_locked(sb, erofs_squash_ino(nid), erofs_iget5_eq,
+			     erofs_iget5_set, &nid);
 	if (!inode)
 		return ERR_PTR(-ENOMEM);
 
 	if (inode->i_state & I_NEW) {
-		int err;
-		struct erofs_inode *vi = EROFS_I(inode);
-
-		vi->nid = nid;
+		int err = erofs_fill_inode(inode);
 
-		err = erofs_fill_inode(inode);
-		if (!err) {
-			unlock_new_inode(inode);
-		} else {
+		if (err) {
 			iget_failed(inode);
-			inode = ERR_PTR(err);
+			return ERR_PTR(err);
 		}
+		unlock_new_inode(inode);
 	}
 	return inode;
 }
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index bb8501c0ff5b..168c21f16383 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -480,15 +480,6 @@ int erofs_map_blocks(struct inode *inode,
 		     struct erofs_map_blocks *map, int flags);
 
 /* inode.c */
-static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
-{
-#if BITS_PER_LONG == 32
-	return (nid >> 32) ^ (nid & 0xffffffff);
-#else
-	return nid;
-#endif
-}
-
 extern const struct inode_operations erofs_generic_iops;
 extern const struct inode_operations erofs_symlink_iops;
 extern const struct inode_operations erofs_fast_symlink_iops;
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 1/2] erofs: clean up erofs_iget()
@ 2023-01-13  6:52 ` Gao Xiang
  0 siblings, 0 replies; 13+ messages in thread
From: Gao Xiang @ 2023-01-13  6:52 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu; +Cc: LKML, Gao Xiang

Move inode hash function into inode.c and simplify erofs_iget().

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/inode.c    | 40 +++++++++++++++++++++-------------------
 fs/erofs/internal.h |  9 ---------
 2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index d3b8736fa124..57328691582e 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -308,47 +308,49 @@ static int erofs_fill_inode(struct inode *inode)
 }
 
 /*
- * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
- * we should do more for 32-bit platform to find the right inode.
+ * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
+ * so that it will fit.
  */
-static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
+static ino_t erofs_squash_ino(erofs_nid_t nid)
 {
-	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
+	ino_t ino = (ino_t)nid;
+
+	if (sizeof(ino_t) < sizeof(erofs_nid_t))
+		ino ^= nid >> (sizeof(erofs_nid_t) - sizeof(ino_t)) * 8;
+	return ino;
+}
 
-	return EROFS_I(inode)->nid == nid;
+static int erofs_iget5_eq(struct inode *inode, void *opaque)
+{
+	return EROFS_I(inode)->nid == *(erofs_nid_t *)opaque;
 }
 
-static int erofs_iget_set_actor(struct inode *inode, void *opaque)
+static int erofs_iget5_set(struct inode *inode, void *opaque)
 {
 	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
 
-	inode->i_ino = erofs_inode_hash(nid);
+	inode->i_ino = erofs_squash_ino(nid);
+	EROFS_I(inode)->nid = nid;
 	return 0;
 }
 
 struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid)
 {
-	const unsigned long hashval = erofs_inode_hash(nid);
 	struct inode *inode;
 
-	inode = iget5_locked(sb, hashval, erofs_ilookup_test_actor,
-		erofs_iget_set_actor, &nid);
+	inode = iget5_locked(sb, erofs_squash_ino(nid), erofs_iget5_eq,
+			     erofs_iget5_set, &nid);
 	if (!inode)
 		return ERR_PTR(-ENOMEM);
 
 	if (inode->i_state & I_NEW) {
-		int err;
-		struct erofs_inode *vi = EROFS_I(inode);
-
-		vi->nid = nid;
+		int err = erofs_fill_inode(inode);
 
-		err = erofs_fill_inode(inode);
-		if (!err) {
-			unlock_new_inode(inode);
-		} else {
+		if (err) {
 			iget_failed(inode);
-			inode = ERR_PTR(err);
+			return ERR_PTR(err);
 		}
+		unlock_new_inode(inode);
 	}
 	return inode;
 }
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index bb8501c0ff5b..168c21f16383 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -480,15 +480,6 @@ int erofs_map_blocks(struct inode *inode,
 		     struct erofs_map_blocks *map, int flags);
 
 /* inode.c */
-static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
-{
-#if BITS_PER_LONG == 32
-	return (nid >> 32) ^ (nid & 0xffffffff);
-#else
-	return nid;
-#endif
-}
-
 extern const struct inode_operations erofs_generic_iops;
 extern const struct inode_operations erofs_symlink_iops;
 extern const struct inode_operations erofs_fast_symlink_iops;
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/2] erofs: remove linux/buffer_head.h dependency
  2023-01-13  6:52 ` Gao Xiang
@ 2023-01-13  6:52   ` Gao Xiang
  -1 siblings, 0 replies; 13+ messages in thread
From: Gao Xiang @ 2023-01-13  6:52 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu; +Cc: Gao Xiang, LKML

EROFS actually never uses buffer heads, therefore just get rid of
BH_xxx definitions and linux/buffer_head.h inclusive.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/internal.h | 20 ++++++--------------
 fs/erofs/super.c    |  1 -
 2 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 168c21f16383..b4cc40fa3803 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -12,7 +12,6 @@
 #include <linux/mm.h>
 #include <linux/pagemap.h>
 #include <linux/bio.h>
-#include <linux/buffer_head.h>
 #include <linux/magic.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
@@ -388,25 +387,18 @@ extern struct file_system_type erofs_fs_type;
 extern const struct address_space_operations erofs_raw_access_aops;
 extern const struct address_space_operations z_erofs_aops;
 
-enum {
-	BH_Encoded = BH_PrivateStart,
-	BH_FullMapped,
-	BH_Fragment,
-	BH_Partialref,
-};
-
 /* Has a disk mapping */
-#define EROFS_MAP_MAPPED	(1 << BH_Mapped)
+#define EROFS_MAP_MAPPED	0x0001
 /* Located in metadata (could be copied from bd_inode) */
-#define EROFS_MAP_META		(1 << BH_Meta)
+#define EROFS_MAP_META		0x0002
 /* The extent is encoded */
-#define EROFS_MAP_ENCODED	(1 << BH_Encoded)
+#define EROFS_MAP_ENCODED	0x0004
 /* The length of extent is full */
-#define EROFS_MAP_FULL_MAPPED	(1 << BH_FullMapped)
+#define EROFS_MAP_FULL_MAPPED	0x0008
 /* Located in the special packed inode */
-#define EROFS_MAP_FRAGMENT	(1 << BH_Fragment)
+#define EROFS_MAP_FRAGMENT	0x0010
 /* The extent refers to partial decompressed data */
-#define EROFS_MAP_PARTIAL_REF	(1 << BH_Partialref)
+#define EROFS_MAP_PARTIAL_REF	0x0020
 
 struct erofs_map_blocks {
 	struct erofs_buf buf;
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 481788c24a68..36b795f1ad44 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -5,7 +5,6 @@
  * Copyright (C) 2021, Alibaba Cloud
  */
 #include <linux/module.h>
-#include <linux/buffer_head.h>
 #include <linux/statfs.h>
 #include <linux/parser.h>
 #include <linux/seq_file.h>
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/2] erofs: remove linux/buffer_head.h dependency
@ 2023-01-13  6:52   ` Gao Xiang
  0 siblings, 0 replies; 13+ messages in thread
From: Gao Xiang @ 2023-01-13  6:52 UTC (permalink / raw)
  To: linux-erofs, Chao Yu, Yue Hu, Jeffle Xu; +Cc: LKML, Gao Xiang

EROFS actually never uses buffer heads, therefore just get rid of
BH_xxx definitions and linux/buffer_head.h inclusive.

Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/internal.h | 20 ++++++--------------
 fs/erofs/super.c    |  1 -
 2 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 168c21f16383..b4cc40fa3803 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -12,7 +12,6 @@
 #include <linux/mm.h>
 #include <linux/pagemap.h>
 #include <linux/bio.h>
-#include <linux/buffer_head.h>
 #include <linux/magic.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
@@ -388,25 +387,18 @@ extern struct file_system_type erofs_fs_type;
 extern const struct address_space_operations erofs_raw_access_aops;
 extern const struct address_space_operations z_erofs_aops;
 
-enum {
-	BH_Encoded = BH_PrivateStart,
-	BH_FullMapped,
-	BH_Fragment,
-	BH_Partialref,
-};
-
 /* Has a disk mapping */
-#define EROFS_MAP_MAPPED	(1 << BH_Mapped)
+#define EROFS_MAP_MAPPED	0x0001
 /* Located in metadata (could be copied from bd_inode) */
-#define EROFS_MAP_META		(1 << BH_Meta)
+#define EROFS_MAP_META		0x0002
 /* The extent is encoded */
-#define EROFS_MAP_ENCODED	(1 << BH_Encoded)
+#define EROFS_MAP_ENCODED	0x0004
 /* The length of extent is full */
-#define EROFS_MAP_FULL_MAPPED	(1 << BH_FullMapped)
+#define EROFS_MAP_FULL_MAPPED	0x0008
 /* Located in the special packed inode */
-#define EROFS_MAP_FRAGMENT	(1 << BH_Fragment)
+#define EROFS_MAP_FRAGMENT	0x0010
 /* The extent refers to partial decompressed data */
-#define EROFS_MAP_PARTIAL_REF	(1 << BH_Partialref)
+#define EROFS_MAP_PARTIAL_REF	0x0020
 
 struct erofs_map_blocks {
 	struct erofs_buf buf;
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 481788c24a68..36b795f1ad44 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -5,7 +5,6 @@
  * Copyright (C) 2021, Alibaba Cloud
  */
 #include <linux/module.h>
-#include <linux/buffer_head.h>
 #include <linux/statfs.h>
 #include <linux/parser.h>
 #include <linux/seq_file.h>
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] erofs: clean up erofs_iget()
  2023-01-13  6:52 ` Gao Xiang
@ 2023-01-13  7:38   ` Yue Hu
  -1 siblings, 0 replies; 13+ messages in thread
From: Yue Hu @ 2023-01-13  7:38 UTC (permalink / raw)
  To: Gao Xiang; +Cc: linux-erofs, LKML, zhangwen

On Fri, 13 Jan 2023 14:52:25 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:

> Move inode hash function into inode.c and simplify erofs_iget().
> 
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Yue Hu <huyue2@coolpad.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] erofs: clean up erofs_iget()
@ 2023-01-13  7:38   ` Yue Hu
  0 siblings, 0 replies; 13+ messages in thread
From: Yue Hu @ 2023-01-13  7:38 UTC (permalink / raw)
  To: Gao Xiang; +Cc: linux-erofs, Chao Yu, Jeffle Xu, LKML, zhangwen

On Fri, 13 Jan 2023 14:52:25 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:

> Move inode hash function into inode.c and simplify erofs_iget().
> 
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Yue Hu <huyue2@coolpad.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] erofs: clean up erofs_iget()
  2023-01-13  6:52 ` Gao Xiang
                   ` (2 preceding siblings ...)
  (?)
@ 2023-01-13  7:41 ` Jingbo Xu
  2023-01-13  7:46   ` Xiang Gao
  -1 siblings, 1 reply; 13+ messages in thread
From: Jingbo Xu @ 2023-01-13  7:41 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, Chao Yu, Yue Hu; +Cc: LKML



On 1/13/23 2:52 PM, Gao Xiang wrote:
> Move inode hash function into inode.c and simplify erofs_iget().
> 
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---
>  fs/erofs/inode.c    | 40 +++++++++++++++++++++-------------------
>  fs/erofs/internal.h |  9 ---------
>  2 files changed, 21 insertions(+), 28 deletions(-)
> 
> diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
> index d3b8736fa124..57328691582e 100644
> --- a/fs/erofs/inode.c
> +++ b/fs/erofs/inode.c
> @@ -308,47 +308,49 @@ static int erofs_fill_inode(struct inode *inode)
>  }
>  
>  /*
> - * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
> - * we should do more for 32-bit platform to find the right inode.
> + * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
> + * so that it will fit.
>   */
> -static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
> +static ino_t erofs_squash_ino(erofs_nid_t nid)
>  {
> -	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
> +	ino_t ino = (ino_t)nid;
> +
> +	if (sizeof(ino_t) < sizeof(erofs_nid_t))
> +		ino ^= nid >> (sizeof(erofs_nid_t) - sizeof(ino_t)) * 8;

Shouldn't we do:

	ino ^= nid >> sizeof(ino_t) * 8
?


-- 
Thanks,
Jingbo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] erofs: remove linux/buffer_head.h dependency
  2023-01-13  6:52   ` Gao Xiang
@ 2023-01-13  7:44     ` Yue Hu
  -1 siblings, 0 replies; 13+ messages in thread
From: Yue Hu @ 2023-01-13  7:44 UTC (permalink / raw)
  To: Gao Xiang; +Cc: linux-erofs, Chao Yu, Jeffle Xu, LKML, zhangwen

On Fri, 13 Jan 2023 14:52:26 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:

> EROFS actually never uses buffer heads, therefore just get rid of
> BH_xxx definitions and linux/buffer_head.h inclusive.
> 
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Yue Hu <huyue2@coolpad.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] erofs: remove linux/buffer_head.h dependency
@ 2023-01-13  7:44     ` Yue Hu
  0 siblings, 0 replies; 13+ messages in thread
From: Yue Hu @ 2023-01-13  7:44 UTC (permalink / raw)
  To: Gao Xiang; +Cc: linux-erofs, LKML, zhangwen

On Fri, 13 Jan 2023 14:52:26 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:

> EROFS actually never uses buffer heads, therefore just get rid of
> BH_xxx definitions and linux/buffer_head.h inclusive.
> 
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Yue Hu <huyue2@coolpad.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] erofs: clean up erofs_iget()
  2023-01-13  7:41 ` Jingbo Xu
@ 2023-01-13  7:46   ` Xiang Gao
  0 siblings, 0 replies; 13+ messages in thread
From: Xiang Gao @ 2023-01-13  7:46 UTC (permalink / raw)
  To: Jingbo Xu, linux-erofs, Chao Yu, Yue Hu; +Cc: LKML



On 2023/1/13 15:41, Jingbo Xu wrote:
> 
> 
> On 1/13/23 2:52 PM, Gao Xiang wrote:
>> Move inode hash function into inode.c and simplify erofs_iget().
>>
>> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>> ---
>>   fs/erofs/inode.c    | 40 +++++++++++++++++++++-------------------
>>   fs/erofs/internal.h |  9 ---------
>>   2 files changed, 21 insertions(+), 28 deletions(-)
>>
>> diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
>> index d3b8736fa124..57328691582e 100644
>> --- a/fs/erofs/inode.c
>> +++ b/fs/erofs/inode.c
>> @@ -308,47 +308,49 @@ static int erofs_fill_inode(struct inode *inode)
>>   }
>>   
>>   /*
>> - * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
>> - * we should do more for 32-bit platform to find the right inode.
>> + * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
>> + * so that it will fit.
>>    */
>> -static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
>> +static ino_t erofs_squash_ino(erofs_nid_t nid)
>>   {
>> -	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
>> +	ino_t ino = (ino_t)nid;
>> +
>> +	if (sizeof(ino_t) < sizeof(erofs_nid_t))
>> +		ino ^= nid >> (sizeof(erofs_nid_t) - sizeof(ino_t)) * 8;
> 
> Shouldn't we do:
> 
> 	ino ^= nid >> sizeof(ino_t) * 8
Actually I copied it from fuse, for 64-bit erofs_nid_t it has no difference
though. I will also update it as your suggestion in v2.

Thanks,
Gao Xiang


> ?
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/2] erofs: remove linux/buffer_head.h dependency
  2023-01-13  6:52   ` Gao Xiang
  (?)
  (?)
@ 2023-01-13  8:04   ` Jingbo Xu
  -1 siblings, 0 replies; 13+ messages in thread
From: Jingbo Xu @ 2023-01-13  8:04 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, Chao Yu, Yue Hu; +Cc: LKML



On 1/13/23 2:52 PM, Gao Xiang wrote:
> EROFS actually never uses buffer heads, therefore just get rid of
> BH_xxx definitions and linux/buffer_head.h inclusive.
> 
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com>


-- 
Thanks,
Jingbo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] erofs: clean up erofs_iget()
  2023-01-13  6:52 ` Gao Xiang
                   ` (3 preceding siblings ...)
  (?)
@ 2023-01-14  8:21 ` Jingbo Xu
  -1 siblings, 0 replies; 13+ messages in thread
From: Jingbo Xu @ 2023-01-14  8:21 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, Chao Yu, Yue Hu; +Cc: LKML



On 1/13/23 2:52 PM, Gao Xiang wrote:
> Move inode hash function into inode.c and simplify erofs_iget().
> 
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Since the v2 triggers the compiling error, this v1 is also acceptable
for me.

Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com>

> ---
>  fs/erofs/inode.c    | 40 +++++++++++++++++++++-------------------
>  fs/erofs/internal.h |  9 ---------
>  2 files changed, 21 insertions(+), 28 deletions(-)
> 
> diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
> index d3b8736fa124..57328691582e 100644
> --- a/fs/erofs/inode.c
> +++ b/fs/erofs/inode.c
> @@ -308,47 +308,49 @@ static int erofs_fill_inode(struct inode *inode)
>  }
>  
>  /*
> - * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
> - * we should do more for 32-bit platform to find the right inode.
> + * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
> + * so that it will fit.
>   */
> -static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
> +static ino_t erofs_squash_ino(erofs_nid_t nid)
>  {
> -	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
> +	ino_t ino = (ino_t)nid;
> +
> +	if (sizeof(ino_t) < sizeof(erofs_nid_t))
> +		ino ^= nid >> (sizeof(erofs_nid_t) - sizeof(ino_t)) * 8;
> +	return ino;
> +}
>  
> -	return EROFS_I(inode)->nid == nid;
> +static int erofs_iget5_eq(struct inode *inode, void *opaque)
> +{
> +	return EROFS_I(inode)->nid == *(erofs_nid_t *)opaque;
>  }
>  
> -static int erofs_iget_set_actor(struct inode *inode, void *opaque)
> +static int erofs_iget5_set(struct inode *inode, void *opaque)
>  {
>  	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
>  
> -	inode->i_ino = erofs_inode_hash(nid);
> +	inode->i_ino = erofs_squash_ino(nid);
> +	EROFS_I(inode)->nid = nid;
>  	return 0;
>  }
>  
>  struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid)
>  {
> -	const unsigned long hashval = erofs_inode_hash(nid);
>  	struct inode *inode;
>  
> -	inode = iget5_locked(sb, hashval, erofs_ilookup_test_actor,
> -		erofs_iget_set_actor, &nid);
> +	inode = iget5_locked(sb, erofs_squash_ino(nid), erofs_iget5_eq,
> +			     erofs_iget5_set, &nid);
>  	if (!inode)
>  		return ERR_PTR(-ENOMEM);
>  
>  	if (inode->i_state & I_NEW) {
> -		int err;
> -		struct erofs_inode *vi = EROFS_I(inode);
> -
> -		vi->nid = nid;
> +		int err = erofs_fill_inode(inode);
>  
> -		err = erofs_fill_inode(inode);
> -		if (!err) {
> -			unlock_new_inode(inode);
> -		} else {
> +		if (err) {
>  			iget_failed(inode);
> -			inode = ERR_PTR(err);
> +			return ERR_PTR(err);
>  		}
> +		unlock_new_inode(inode);
>  	}
>  	return inode;
>  }
> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
> index bb8501c0ff5b..168c21f16383 100644
> --- a/fs/erofs/internal.h
> +++ b/fs/erofs/internal.h
> @@ -480,15 +480,6 @@ int erofs_map_blocks(struct inode *inode,
>  		     struct erofs_map_blocks *map, int flags);
>  
>  /* inode.c */
> -static inline unsigned long erofs_inode_hash(erofs_nid_t nid)
> -{
> -#if BITS_PER_LONG == 32
> -	return (nid >> 32) ^ (nid & 0xffffffff);
> -#else
> -	return nid;
> -#endif
> -}
> -
>  extern const struct inode_operations erofs_generic_iops;
>  extern const struct inode_operations erofs_symlink_iops;
>  extern const struct inode_operations erofs_fast_symlink_iops;

-- 
Thanks,
Jingbo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/2] erofs: clean up erofs_iget()
  2023-01-13  6:52 ` Gao Xiang
                   ` (4 preceding siblings ...)
  (?)
@ 2023-02-14 13:38 ` Chao Yu
  -1 siblings, 0 replies; 13+ messages in thread
From: Chao Yu @ 2023-02-14 13:38 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, Yue Hu, Jeffle Xu; +Cc: LKML

On 2023/1/13 14:52, Gao Xiang wrote:
> Move inode hash function into inode.c and simplify erofs_iget().
> 
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-02-14 13:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-13  6:52 [PATCH 1/2] erofs: clean up erofs_iget() Gao Xiang
2023-01-13  6:52 ` Gao Xiang
2023-01-13  6:52 ` [PATCH 2/2] erofs: remove linux/buffer_head.h dependency Gao Xiang
2023-01-13  6:52   ` Gao Xiang
2023-01-13  7:44   ` Yue Hu
2023-01-13  7:44     ` Yue Hu
2023-01-13  8:04   ` Jingbo Xu
2023-01-13  7:38 ` [PATCH 1/2] erofs: clean up erofs_iget() Yue Hu
2023-01-13  7:38   ` Yue Hu
2023-01-13  7:41 ` Jingbo Xu
2023-01-13  7:46   ` Xiang Gao
2023-01-14  8:21 ` Jingbo Xu
2023-02-14 13:38 ` Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.