2023-01-14 02:12:22

by Gao Xiang

[permalink] [raw]
Subject: [PATCH v2 1/2] erofs: cleanup erofs_iget()

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

Reviewed-by: Yue Hu <[email protected]>
Signed-off-by: Gao Xiang <[email protected]>
---
changes since v1:
- use ino ^= nid >> sizeof(ino_t) * 8 as suggested by Jingbo.

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..f3b6782c6c53 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(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


2023-01-14 02:12:32

by Gao Xiang

[permalink] [raw]
Subject: [PATCH v2 2/2] erofs: remove linux/buffer_head.h dependency

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

Reviewed-by: Yue Hu <[email protected]>
Reviewed-by: Jingbo Xu <[email protected]>
Signed-off-by: Gao Xiang <[email protected]>
---
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

2023-01-14 04:11:35

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] erofs: cleanup erofs_iget()

Hi Gao,

I love your patch! Perhaps something to improve:

[auto build test WARNING on xiang-erofs/dev-test]
[also build test WARNING on xiang-erofs/dev xiang-erofs/fixes linus/master v6.2-rc3 next-20230113]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Gao-Xiang/erofs-remove-linux-buffer_head-h-dependency/20230114-100018
base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
patch link: https://lore.kernel.org/r/20230114015812.96836-1-hsiangkao%40linux.alibaba.com
patch subject: [PATCH v2 1/2] erofs: cleanup erofs_iget()
config: ia64-allyesconfig
compiler: ia64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/ede350f68141cc6bdc88c627e0f8f992f1b26307
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Gao-Xiang/erofs-remove-linux-buffer_head-h-dependency/20230114-100018
git checkout ede350f68141cc6bdc88c627e0f8f992f1b26307
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash fs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

fs/erofs/inode.c: In function 'erofs_squash_ino':
>> fs/erofs/inode.c:319:28: warning: right shift count >= width of type [-Wshift-count-overflow]
319 | ino ^= nid >> sizeof(ino_t) * 8;
| ^~


vim +319 fs/erofs/inode.c

309
310 /*
311 * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
312 * so that it will fit.
313 */
314 static ino_t erofs_squash_ino(erofs_nid_t nid)
315 {
316 ino_t ino = (ino_t)nid;
317
318 if (sizeof(ino_t) < sizeof(erofs_nid_t))
> 319 ino ^= nid >> sizeof(ino_t) * 8;
320 return ino;
321 }
322

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests


Attachments:
(No filename) (2.55 kB)
config (330.72 kB)
Download all attachments

2023-01-14 04:36:14

by Gao Xiang

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] erofs: cleanup erofs_iget()

On Sat, Jan 14, 2023 at 11:59:41AM +0800, kernel test robot wrote:
> Hi Gao,
>
> I love your patch! Perhaps something to improve:
>
> [auto build test WARNING on xiang-erofs/dev-test]
> [also build test WARNING on xiang-erofs/dev xiang-erofs/fixes linus/master v6.2-rc3 next-20230113]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Gao-Xiang/erofs-remove-linux-buffer_head-h-dependency/20230114-100018
> base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
> patch link: https://lore.kernel.org/r/20230114015812.96836-1-hsiangkao%40linux.alibaba.com
> patch subject: [PATCH v2 1/2] erofs: cleanup erofs_iget()
> config: ia64-allyesconfig
> compiler: ia64-linux-gcc (GCC) 12.1.0
> reproduce (this is a W=1 build):
> wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> # https://github.com/intel-lab-lkp/linux/commit/ede350f68141cc6bdc88c627e0f8f992f1b26307
> git remote add linux-review https://github.com/intel-lab-lkp/linux
> git fetch --no-tags linux-review Gao-Xiang/erofs-remove-linux-buffer_head-h-dependency/20230114-100018
> git checkout ede350f68141cc6bdc88c627e0f8f992f1b26307
> # save the config file
> mkdir build_dir && cp config build_dir/.config
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 olddefconfig
> COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash fs/
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <[email protected]>
>
> All warnings (new ones prefixed by >>):
>
> fs/erofs/inode.c: In function 'erofs_squash_ino':
> >> fs/erofs/inode.c:319:28: warning: right shift count >= width of type [-Wshift-count-overflow]
> 319 | ino ^= nid >> sizeof(ino_t) * 8;
> | ^~

Okay, I think I have to stick to v1 since v2 causes a
compile warning.

Thanks,
Gao Xiang

2023-02-14 13:40:29

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] erofs: remove linux/buffer_head.h dependency

On 2023/1/14 9:58, Gao Xiang wrote:
> EROFS actually never uses buffer heads, therefore just get rid of
> BH_xxx definitions and linux/buffer_head.h inclusive.
>
> Reviewed-by: Yue Hu <[email protected]>
> Reviewed-by: Jingbo Xu <[email protected]>
> Signed-off-by: Gao Xiang <[email protected]>

Reviewed-by: Chao Yu <[email protected]>

Thanks,