2023-01-14 13:13:33

by Gao Xiang

[permalink] [raw]
Subject: [PATCH 2/2] erofs: simplify iloc()

From: Gao Xiang <[email protected]>

Actually we could pass in inodes directly to clean up all callers.
Also rename iloc() as erofs_iloc().

Signed-off-by: Gao Xiang <[email protected]>
---
fs/erofs/data.c | 9 +++------
fs/erofs/inode.c | 2 +-
fs/erofs/internal.h | 16 +++++++++-------
fs/erofs/xattr.c | 20 +++++++-------------
fs/erofs/zmap.c | 13 +++++--------
5 files changed, 25 insertions(+), 35 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index f57f921683d7..2713257ee718 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -91,11 +91,8 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la;
map->m_plen = blknr_to_addr(lastblk) - offset;
} else if (tailendpacking) {
- /* 2 - inode inline B: inode, [xattrs], inline last blk... */
- struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
-
- map->m_pa = iloc(sbi, vi->nid) + vi->inode_isize +
- vi->xattr_isize + erofs_blkoff(map->m_la);
+ map->m_pa = erofs_iloc(inode) + vi->inode_isize +
+ vi->xattr_isize + erofs_blkoff(offset);
map->m_plen = inode->i_size - offset;

/* inline data should be located in the same meta block */
@@ -150,7 +147,7 @@ int erofs_map_blocks(struct inode *inode,
unit = EROFS_BLOCK_MAP_ENTRY_SIZE; /* block map */

chunknr = map->m_la >> vi->chunkbits;
- pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize +
+ pos = ALIGN(erofs_iloc(inode) + vi->inode_isize +
vi->xattr_isize, unit) + unit * chunknr;

kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP);
diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index 57328691582e..d7e87d41f7bf 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -14,7 +14,7 @@ static void *erofs_read_inode(struct erofs_buf *buf,
struct super_block *sb = inode->i_sb;
struct erofs_sb_info *sbi = EROFS_SB(sb);
struct erofs_inode *vi = EROFS_I(inode);
- const erofs_off_t inode_loc = iloc(sbi, vi->nid);
+ const erofs_off_t inode_loc = erofs_iloc(inode);

erofs_blk_t blkaddr, nblks = 0;
void *kaddr;
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index b4cc40fa3803..b7291691be68 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -270,11 +270,6 @@ struct erofs_buf {
#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ)
#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ)

-static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
-{
- return blknr_to_addr(sbi->meta_blkaddr) + (nid << sbi->islotbits);
-}
-
#define EROFS_FEATURE_FUNCS(name, compat, feature) \
static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
{ \
@@ -339,8 +334,15 @@ struct erofs_inode {
struct inode vfs_inode;
};

-#define EROFS_I(ptr) \
- container_of(ptr, struct erofs_inode, vfs_inode)
+#define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode)
+
+static inline erofs_off_t erofs_iloc(struct inode *inode)
+{
+ struct erofs_sb_info *sbi = EROFS_I_SB(sbi);
+
+ return blknr_to_addr(sbi->meta_blkaddr) +
+ (EROFS_I(nid) << sbi->islotbits);
+}

static inline unsigned long erofs_inode_datablocks(struct inode *inode)
{
diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c
index a62fb8a3318a..60729b1220b6 100644
--- a/fs/erofs/xattr.c
+++ b/fs/erofs/xattr.c
@@ -22,8 +22,7 @@ static int init_inode_xattrs(struct inode *inode)
struct xattr_iter it;
unsigned int i;
struct erofs_xattr_ibody_header *ih;
- struct super_block *sb;
- struct erofs_sb_info *sbi;
+ struct super_block *sb = inode->i_sb;
int ret = 0;

/* the most case is that xattrs of this inode are initialized. */
@@ -52,15 +51,14 @@ static int init_inode_xattrs(struct inode *inode)
* undefined right now (maybe use later with some new sb feature).
*/
if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) {
- erofs_err(inode->i_sb,
+ erofs_err(sb,
"xattr_isize %d of nid %llu is not supported yet",
vi->xattr_isize, vi->nid);
ret = -EOPNOTSUPP;
goto out_unlock;
} else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) {
if (vi->xattr_isize) {
- erofs_err(inode->i_sb,
- "bogus xattr ibody @ nid %llu", vi->nid);
+ erofs_err(sb, "bogus xattr ibody @ nid %llu", vi->nid);
DBG_BUGON(1);
ret = -EFSCORRUPTED;
goto out_unlock; /* xattr ondisk layout error */
@@ -69,11 +67,9 @@ static int init_inode_xattrs(struct inode *inode)
goto out_unlock;
}

- sb = inode->i_sb;
- sbi = EROFS_SB(sb);
it.buf = __EROFS_BUF_INITIALIZER;
- it.blkaddr = erofs_blknr(iloc(sbi, vi->nid) + vi->inode_isize);
- it.ofs = erofs_blkoff(iloc(sbi, vi->nid) + vi->inode_isize);
+ it.blkaddr = erofs_blknr(erofs_iloc(inode) + vi->inode_isize);
+ it.ofs = erofs_blkoff(erofs_iloc(inode) + vi->inode_isize);

/* read in shared xattr array (non-atomic, see kmalloc below) */
it.kaddr = erofs_read_metabuf(&it.buf, sb, it.blkaddr, EROFS_KMAP);
@@ -159,7 +155,6 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
struct inode *inode)
{
struct erofs_inode *const vi = EROFS_I(inode);
- struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb);
unsigned int xattr_header_sz, inline_xattr_ofs;

xattr_header_sz = inlinexattr_header_size(inode);
@@ -170,9 +165,8 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,

inline_xattr_ofs = vi->inode_isize + xattr_header_sz;

- it->blkaddr = erofs_blknr(iloc(sbi, vi->nid) + inline_xattr_ofs);
- it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs);
-
+ it->blkaddr = erofs_blknr(erofs_iloc(inode) + inline_xattr_ofs);
+ it->ofs = erofs_blkoff(erofs_iloc(inode) + inline_xattr_ofs);
it->kaddr = erofs_read_metabuf(&it->buf, inode->i_sb, it->blkaddr,
EROFS_KMAP);
if (IS_ERR(it->kaddr))
diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
index 98fb90b9af71..3aeffc762b2f 100644
--- a/fs/erofs/zmap.c
+++ b/fs/erofs/zmap.c
@@ -55,8 +55,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags))
goto out_unlock;

- pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize +
- vi->xattr_isize, 8);
+ pos = ALIGN(erofs_iloc(inode) + vi->inode_isize + vi->xattr_isize, 8);
kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP);
if (IS_ERR(kaddr)) {
err = PTR_ERR(kaddr);
@@ -169,10 +168,9 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
{
struct inode *const inode = m->inode;
struct erofs_inode *const vi = EROFS_I(inode);
- const erofs_off_t ibase = iloc(EROFS_I_SB(inode), vi->nid);
const erofs_off_t pos =
- Z_EROFS_VLE_LEGACY_INDEX_ALIGN(ibase + vi->inode_isize +
- vi->xattr_isize) +
+ Z_EROFS_VLE_LEGACY_INDEX_ALIGN(erofs_iloc(inode) +
+ vi->inode_isize + vi->xattr_isize) +
lcn * sizeof(struct z_erofs_vle_decompressed_index);
struct z_erofs_vle_decompressed_index *di;
unsigned int advise, type;
@@ -372,9 +370,8 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
struct inode *const inode = m->inode;
struct erofs_inode *const vi = EROFS_I(inode);
const unsigned int lclusterbits = vi->z_logical_clusterbits;
- const erofs_off_t ebase = ALIGN(iloc(EROFS_I_SB(inode), vi->nid) +
- vi->inode_isize + vi->xattr_isize, 8) +
- sizeof(struct z_erofs_map_header);
+ const erofs_off_t ebase = sizeof(struct z_erofs_map_header) +
+ ALIGN(erofs_iloc(inode) + vi->inode_isize + vi->xattr_isize, 8);
const unsigned int totalidx = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
unsigned int compacted_4b_initial, compacted_2b;
unsigned int amortizedshift;
--
2.30.2


2023-01-14 15:10:07

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 2/2] erofs: simplify iloc()

Hi Gao,

I love your patch! Yet something to improve:

[auto build test ERROR on xiang-erofs/dev-test]
[also build test ERROR 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-simplify-iloc/20230114-205836
base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
patch link: https://lore.kernel.org/r/20230114125746.399253-2-xiang%40kernel.org
patch subject: [PATCH 2/2] erofs: simplify iloc()
config: i386-randconfig-a003
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/5bb46a259e46bff4dbe228e70e5446d450c396f6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Gao-Xiang/erofs-simplify-iloc/20230114-205836
git checkout 5bb46a259e46bff4dbe228e70e5446d450c396f6
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash fs/

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

All errors (new ones prefixed by >>):

In file included from fs/erofs/xattr.h:9,
from fs/erofs/super.c:16:
fs/erofs/internal.h: In function 'erofs_iloc':
>> fs/erofs/internal.h:177:59: error: 'struct erofs_sb_info' has no member named 'i_sb'
177 | #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
| ^~
fs/erofs/internal.h:341:37: note: in expansion of macro 'EROFS_I_SB'
341 | struct erofs_sb_info *sbi = EROFS_I_SB(sbi);
| ^~~~~~~~~~
In file included from include/linux/list.h:5,
from include/linux/module.h:12,
from fs/erofs/super.c:7:
>> fs/erofs/internal.h:344:26: error: 'nid' undeclared (first use in this function); did you mean 'fid'?
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~
include/linux/container_of.h:19:33: note: in definition of macro 'container_of'
19 | void *__mptr = (void *)(ptr); \
| ^~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
fs/erofs/internal.h:344:26: note: each undeclared identifier is reported only once for each function it appears in
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~
include/linux/container_of.h:19:33: note: in definition of macro 'container_of'
19 | void *__mptr = (void *)(ptr); \
| ^~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
In file included from include/linux/container_of.h:5,
from include/linux/list.h:5,
from include/linux/module.h:12,
from fs/erofs/super.c:7:
>> include/linux/compiler_types.h:299:27: error: expression in static assertion is not an integer
299 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:20:23: note: in expansion of macro '__same_type'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
fs/erofs/internal.h:337:25: note: in expansion of macro 'container_of'
337 | #define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode)
| ^~~~~~~~~~~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
In file included from fs/erofs/xattr.h:9,
from fs/erofs/super.c:16:
>> fs/erofs/internal.h:344:31: error: invalid operands to binary << (have 'struct erofs_inode *' and 'int')
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~ ~~~~~~~~~~~~~~
| |
| unsigned char
In file included from include/trace/define_trace.h:102,
from include/trace/events/erofs.h:256,
from fs/erofs/super.c:19:
include/trace/events/erofs.h: In function 'trace_event_raw_event_erofs_fill_inode':
>> include/trace/events/erofs.h:69:55: error: implicit declaration of function 'iloc' [-Werror=implicit-function-declaration]
69 | __entry->blkaddr = erofs_blknr(iloc(EROFS_I_SB(inode), __entry->nid));
| ^~~~
include/trace/trace_events.h:402:11: note: in definition of macro 'DECLARE_EVENT_CLASS'
402 | { assign; } \
| ^~~~~~
include/trace/trace_events.h:44:30: note: in expansion of macro 'PARAMS'
44 | PARAMS(assign), \
| ^~~~~~
include/trace/events/erofs.h:55:1: note: in expansion of macro 'TRACE_EVENT'
55 | TRACE_EVENT(erofs_fill_inode,
| ^~~~~~~~~~~
include/trace/events/erofs.h:66:9: note: in expansion of macro 'TP_fast_assign'
66 | TP_fast_assign(
| ^~~~~~~~~~~~~~
include/trace/events/erofs.h:69:43: note: in expansion of macro 'erofs_blknr'
69 | __entry->blkaddr = erofs_blknr(iloc(EROFS_I_SB(inode), __entry->nid));
| ^~~~~~~~~~~
cc1: some warnings being treated as errors
--
In file included from fs/erofs/xattr.h:9,
from fs/erofs/inode.c:7:
fs/erofs/internal.h: In function 'erofs_iloc':
>> fs/erofs/internal.h:177:59: error: 'struct erofs_sb_info' has no member named 'i_sb'
177 | #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
| ^~
fs/erofs/internal.h:341:37: note: in expansion of macro 'EROFS_I_SB'
341 | struct erofs_sb_info *sbi = EROFS_I_SB(sbi);
| ^~~~~~~~~~
In file included from include/linux/list.h:5,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from fs/erofs/internal.h:10,
from fs/erofs/xattr.h:9,
from fs/erofs/inode.c:7:
fs/erofs/internal.h:344:26: error: 'nid' undeclared (first use in this function); did you mean 'pid'?
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~
include/linux/container_of.h:19:33: note: in definition of macro 'container_of'
19 | void *__mptr = (void *)(ptr); \
| ^~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
fs/erofs/internal.h:344:26: note: each undeclared identifier is reported only once for each function it appears in
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~
include/linux/container_of.h:19:33: note: in definition of macro 'container_of'
19 | void *__mptr = (void *)(ptr); \
| ^~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
In file included from include/linux/container_of.h:5,
from include/linux/list.h:5,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from fs/erofs/internal.h:10,
from fs/erofs/xattr.h:9,
from fs/erofs/inode.c:7:
>> include/linux/compiler_types.h:299:27: error: expression in static assertion is not an integer
299 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:20:23: note: in expansion of macro '__same_type'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
fs/erofs/internal.h:337:25: note: in expansion of macro 'container_of'
337 | #define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode)
| ^~~~~~~~~~~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
In file included from fs/erofs/xattr.h:9,
from fs/erofs/inode.c:7:
>> fs/erofs/internal.h:344:31: error: invalid operands to binary << (have 'struct erofs_inode *' and 'int')
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~ ~~~~~~~~~~~~~~
| |
| unsigned char
fs/erofs/internal.h:345:1: error: control reaches end of non-void function [-Werror=return-type]
345 | }
| ^
cc1: some warnings being treated as errors
--
In file included from fs/erofs/xattr.h:9,
from fs/erofs/namei.c:7:
fs/erofs/internal.h: In function 'erofs_iloc':
>> fs/erofs/internal.h:177:59: error: 'struct erofs_sb_info' has no member named 'i_sb'
177 | #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
| ^~
fs/erofs/internal.h:341:37: note: in expansion of macro 'EROFS_I_SB'
341 | struct erofs_sb_info *sbi = EROFS_I_SB(sbi);
| ^~~~~~~~~~
In file included from include/linux/list.h:5,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from fs/erofs/internal.h:10,
from fs/erofs/xattr.h:9,
from fs/erofs/namei.c:7:
fs/erofs/internal.h:344:26: error: 'nid' undeclared (first use in this function); did you mean 'pid'?
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~
include/linux/container_of.h:19:33: note: in definition of macro 'container_of'
19 | void *__mptr = (void *)(ptr); \
| ^~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
fs/erofs/internal.h:344:26: note: each undeclared identifier is reported only once for each function it appears in
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~
include/linux/container_of.h:19:33: note: in definition of macro 'container_of'
19 | void *__mptr = (void *)(ptr); \
| ^~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
In file included from include/linux/container_of.h:5,
from include/linux/list.h:5,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from fs/erofs/internal.h:10,
from fs/erofs/xattr.h:9,
from fs/erofs/namei.c:7:
>> include/linux/compiler_types.h:299:27: error: expression in static assertion is not an integer
299 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:20:9: note: in expansion of macro 'static_assert'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:20:23: note: in expansion of macro '__same_type'
20 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
fs/erofs/internal.h:337:25: note: in expansion of macro 'container_of'
337 | #define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode)
| ^~~~~~~~~~~~
fs/erofs/internal.h:344:18: note: in expansion of macro 'EROFS_I'
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~~~~~~
In file included from fs/erofs/xattr.h:9,
from fs/erofs/namei.c:7:
>> fs/erofs/internal.h:344:31: error: invalid operands to binary << (have 'struct erofs_inode *' and 'int')
344 | (EROFS_I(nid) << sbi->islotbits);
| ^~ ~~~~~~~~~~~~~~
| |
| unsigned char


vim +177 fs/erofs/internal.h

bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 175
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 176 #define EROFS_SB(sb) ((struct erofs_sb_info *)(sb)->s_fs_info)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 @177 #define EROFS_I_SB(inode) ((struct erofs_sb_info *)(inode)->i_sb->s_fs_info)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 178
b17500a0fdbae1 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 179 /* Mount flags set via mount options or defaults */
b17500a0fdbae1 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 180 #define EROFS_MOUNT_XATTR_USER 0x00000010
b17500a0fdbae1 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 181 #define EROFS_MOUNT_POSIX_ACL 0x00000020
06252e9ce05b94 fs/erofs/internal.h Gao Xiang 2021-08-05 182 #define EROFS_MOUNT_DAX_ALWAYS 0x00000040
06252e9ce05b94 fs/erofs/internal.h Gao Xiang 2021-08-05 183 #define EROFS_MOUNT_DAX_NEVER 0x00000080
b17500a0fdbae1 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 184
e62424651f43cb fs/erofs/internal.h Gao Xiang 2021-10-07 185 #define clear_opt(opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option)
e62424651f43cb fs/erofs/internal.h Gao Xiang 2021-10-07 186 #define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)
e62424651f43cb fs/erofs/internal.h Gao Xiang 2021-10-07 187 #define test_opt(opt, option) ((opt)->mount_opt & EROFS_MOUNT_##option)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 188
93b856bb5f66ae fs/erofs/internal.h Jeffle Xu 2022-04-25 189 static inline bool erofs_is_fscache_mode(struct super_block *sb)
93b856bb5f66ae fs/erofs/internal.h Jeffle Xu 2022-04-25 190 {
93b856bb5f66ae fs/erofs/internal.h Jeffle Xu 2022-04-25 191 return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && !sb->s_bdev;
93b856bb5f66ae fs/erofs/internal.h Jeffle Xu 2022-04-25 192 }
93b856bb5f66ae fs/erofs/internal.h Jeffle Xu 2022-04-25 193
4279f3f9889f26 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 194 enum {
4279f3f9889f26 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 195 EROFS_ZIP_CACHE_DISABLED,
4279f3f9889f26 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 196 EROFS_ZIP_CACHE_READAHEAD,
4279f3f9889f26 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 197 EROFS_ZIP_CACHE_READAROUND
4279f3f9889f26 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 198 };
4279f3f9889f26 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 199
14f362b4f40580 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 200 #define EROFS_LOCKED_MAGIC (INT_MIN | 0xE0F510CCL)
14f362b4f40580 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 201
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 202 /* basic unit of the workstation of a super_block */
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 203 struct erofs_workgroup {
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 204 /* the workgroup index in the workstation */
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 205 pgoff_t index;
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 206
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 207 /* overall workgroup reference count */
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 208 atomic_t refcount;
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 209 };
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 210
73f5c66df3e26a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 211 static inline bool erofs_workgroup_try_to_freeze(struct erofs_workgroup *grp,
73f5c66df3e26a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 212 int val)
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 213 {
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 214 preempt_disable();
73f5c66df3e26a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 215 if (val != atomic_cmpxchg(&grp->refcount, val, EROFS_LOCKED_MAGIC)) {
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 216 preempt_enable();
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 217 return false;
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 218 }
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 219 return true;
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 220 }
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 221
73f5c66df3e26a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 222 static inline void erofs_workgroup_unfreeze(struct erofs_workgroup *grp,
73f5c66df3e26a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 223 int orig_val)
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 224 {
948bbdb1818b7a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 225 /*
948bbdb1818b7a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 226 * other observers should notice all modifications
948bbdb1818b7a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 227 * in the freezing period.
948bbdb1818b7a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 228 */
948bbdb1818b7a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 229 smp_mb();
73f5c66df3e26a drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 230 atomic_set(&grp->refcount, orig_val);
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 231 preempt_enable();
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 232 }
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 233
df134b8d17b90c drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 234 static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
df134b8d17b90c drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 235 {
df134b8d17b90c drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 236 return atomic_cond_read_relaxed(&grp->refcount,
df134b8d17b90c drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 237 VAL != EROFS_LOCKED_MAGIC);
df134b8d17b90c drivers/staging/erofs/internal.h Gao Xiang 2018-11-23 238 }
e7e9a307be9d75 drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 239
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 240 /* we strictly follow PAGE_SIZE and no buffer head yet */
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 241 #define LOG_BLOCK_SIZE PAGE_SHIFT
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 242
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 243 #undef LOG_SECTORS_PER_BLOCK
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 244 #define LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 245
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 246 #undef SECTORS_PER_BLOCK
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 247 #define SECTORS_PER_BLOCK (1 << SECTORS_PER_BLOCK)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 248
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 249 #define EROFS_BLKSIZ (1 << LOG_BLOCK_SIZE)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 250
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 251 #if (EROFS_BLKSIZ % 4096 || !EROFS_BLKSIZ)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 252 #error erofs cannot be used in this platform
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 253 #endif
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 254
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 255 enum erofs_kmap_type {
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 256 EROFS_NO_KMAP, /* don't map the buffer */
927e5010ff5bd7 fs/erofs/internal.h Gao Xiang 2022-10-18 257 EROFS_KMAP, /* use kmap_local_page() to map the buffer */
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 258 };
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 259
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 260 struct erofs_buf {
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 261 struct page *page;
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 262 void *base;
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 263 enum erofs_kmap_type kmap_type;
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 264 };
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 265 #define __EROFS_BUF_INITIALIZER ((struct erofs_buf){ .page = NULL })
fdf80a4793021c fs/erofs/internal.h Gao Xiang 2022-01-02 266
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 267 #define ROOT_NID(sb) ((sb)->root_nid)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 268
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 269 #define erofs_blknr(addr) ((addr) / EROFS_BLKSIZ)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 270 #define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 271 #define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 272
de06a6a375414b fs/erofs/internal.h Gao Xiang 2021-03-29 273 #define EROFS_FEATURE_FUNCS(name, compat, feature) \
de06a6a375414b fs/erofs/internal.h Gao Xiang 2021-03-29 274 static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
de06a6a375414b fs/erofs/internal.h Gao Xiang 2021-03-29 275 { \
de06a6a375414b fs/erofs/internal.h Gao Xiang 2021-03-29 276 return sbi->feature_##compat & EROFS_FEATURE_##feature; \
de06a6a375414b fs/erofs/internal.h Gao Xiang 2021-03-29 277 }
de06a6a375414b fs/erofs/internal.h Gao Xiang 2021-03-29 278
7e508f2ca8bbda fs/erofs/internal.h Huang Jianan 2021-11-13 279 EROFS_FEATURE_FUNCS(zero_padding, incompat, INCOMPAT_ZERO_PADDING)
14373711dd54be fs/erofs/internal.h Gao Xiang 2021-03-29 280 EROFS_FEATURE_FUNCS(compr_cfgs, incompat, INCOMPAT_COMPR_CFGS)
5404c33010cb8e fs/erofs/internal.h Gao Xiang 2021-04-07 281 EROFS_FEATURE_FUNCS(big_pcluster, incompat, INCOMPAT_BIG_PCLUSTER)
168e9a76200c54 fs/erofs/internal.h Huang Jianan 2021-12-01 282 EROFS_FEATURE_FUNCS(chunked_file, incompat, INCOMPAT_CHUNKED_FILE)
dfeab2e95a75a4 fs/erofs/internal.h Gao Xiang 2021-10-14 283 EROFS_FEATURE_FUNCS(device_table, incompat, INCOMPAT_DEVICE_TABLE)
168e9a76200c54 fs/erofs/internal.h Huang Jianan 2021-12-01 284 EROFS_FEATURE_FUNCS(compr_head2, incompat, INCOMPAT_COMPR_HEAD2)
ab92184ff8f129 fs/erofs/internal.h Yue Hu 2021-12-28 285 EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING)
b15b2e307c3a19 fs/erofs/internal.h Yue Hu 2022-09-23 286 EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS)
5c2a64252c5dc4 fs/erofs/internal.h Gao Xiang 2022-09-23 287 EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE)
de06a6a375414b fs/erofs/internal.h Gao Xiang 2021-03-29 288 EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
de06a6a375414b fs/erofs/internal.h Gao Xiang 2021-03-29 289
62dc45979f3f8c drivers/staging/erofs/internal.h Gao Xiang 2019-02-18 290 /* atomic flag definitions */
a5876e24f13f13 fs/erofs/internal.h Gao Xiang 2019-09-04 291 #define EROFS_I_EA_INITED_BIT 0
a5876e24f13f13 fs/erofs/internal.h Gao Xiang 2019-09-04 292 #define EROFS_I_Z_INITED_BIT 1
62dc45979f3f8c drivers/staging/erofs/internal.h Gao Xiang 2019-02-18 293
62dc45979f3f8c drivers/staging/erofs/internal.h Gao Xiang 2019-02-18 294 /* bitlock definitions (arranged in reverse order) */
a5876e24f13f13 fs/erofs/internal.h Gao Xiang 2019-09-04 295 #define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1)
a5876e24f13f13 fs/erofs/internal.h Gao Xiang 2019-09-04 296 #define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2)
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 297
a5876e24f13f13 fs/erofs/internal.h Gao Xiang 2019-09-04 298 struct erofs_inode {
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 299 erofs_nid_t nid;
62dc45979f3f8c drivers/staging/erofs/internal.h Gao Xiang 2019-02-18 300
62dc45979f3f8c drivers/staging/erofs/internal.h Gao Xiang 2019-02-18 301 /* atomic flags (including bitlocks) */
62dc45979f3f8c drivers/staging/erofs/internal.h Gao Xiang 2019-02-18 302 unsigned long flags;
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 303
8a76568225deae fs/erofs/internal.h Gao Xiang 2019-09-04 304 unsigned char datalayout;
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 305 unsigned char inode_isize;
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 306 unsigned short xattr_isize;
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 307
e82a9a17d49c52 drivers/staging/erofs/internal.h Pratik Shinde 2019-07-15 308 unsigned int xattr_shared_count;
e82a9a17d49c52 drivers/staging/erofs/internal.h Pratik Shinde 2019-07-15 309 unsigned int *xattr_shared_xattrs;
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 310
152a333a589560 drivers/staging/erofs/internal.h Gao Xiang 2019-06-24 311 union {
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 312 erofs_blk_t raw_blkaddr;
c5aa903a59db27 fs/erofs/internal.h Gao Xiang 2021-08-20 313 struct {
c5aa903a59db27 fs/erofs/internal.h Gao Xiang 2021-08-20 314 unsigned short chunkformat;
c5aa903a59db27 fs/erofs/internal.h Gao Xiang 2021-08-20 315 unsigned char chunkbits;
c5aa903a59db27 fs/erofs/internal.h Gao Xiang 2021-08-20 316 };
152a333a589560 drivers/staging/erofs/internal.h Gao Xiang 2019-06-24 317 #ifdef CONFIG_EROFS_FS_ZIP
152a333a589560 drivers/staging/erofs/internal.h Gao Xiang 2019-06-24 318 struct {
152a333a589560 drivers/staging/erofs/internal.h Gao Xiang 2019-06-24 319 unsigned short z_advise;
152a333a589560 drivers/staging/erofs/internal.h Gao Xiang 2019-06-24 320 unsigned char z_algorithmtype[2];
152a333a589560 drivers/staging/erofs/internal.h Gao Xiang 2019-06-24 321 unsigned char z_logical_clusterbits;
ab92184ff8f129 fs/erofs/internal.h Yue Hu 2021-12-28 322 unsigned long z_tailextent_headlcn;
b15b2e307c3a19 fs/erofs/internal.h Yue Hu 2022-09-23 323 union {
b15b2e307c3a19 fs/erofs/internal.h Yue Hu 2022-09-23 324 struct {
22ba5e99b96f1c fs/erofs/internal.h Gao Xiang 2022-02-22 325 erofs_off_t z_idataoff;
ab92184ff8f129 fs/erofs/internal.h Yue Hu 2021-12-28 326 unsigned short z_idata_size;
152a333a589560 drivers/staging/erofs/internal.h Gao Xiang 2019-06-24 327 };
b15b2e307c3a19 fs/erofs/internal.h Yue Hu 2022-09-23 328 erofs_off_t z_fragmentoff;
b15b2e307c3a19 fs/erofs/internal.h Yue Hu 2022-09-23 329 };
b15b2e307c3a19 fs/erofs/internal.h Yue Hu 2022-09-23 330 };
14f362b4f40580 drivers/staging/erofs/internal.h Gao Xiang 2019-07-31 331 #endif /* CONFIG_EROFS_FS_ZIP */
152a333a589560 drivers/staging/erofs/internal.h Gao Xiang 2019-06-24 332 };
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 333 /* the corresponding vfs inode */
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 334 struct inode vfs_inode;
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 335 };
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 336
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 @337 #define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode)
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 338
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 339 static inline erofs_off_t erofs_iloc(struct inode *inode)
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 340 {
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 341 struct erofs_sb_info *sbi = EROFS_I_SB(sbi);
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 342
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 343 return blknr_to_addr(sbi->meta_blkaddr) +
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 @344 (EROFS_I(nid) << sbi->islotbits);
5bb46a259e46bf fs/erofs/internal.h Gao Xiang 2023-01-14 345 }
bfb8674dc0447d drivers/staging/erofs/internal.h Gao Xiang 2018-07-26 346

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


Attachments:
(No filename) (33.51 kB)
config (162.40 kB)
Download all attachments

2023-01-14 15:19:50

by Gao Xiang

[permalink] [raw]
Subject: [PATCH v2 2/2] erofs: simplify iloc()

From: Gao Xiang <[email protected]>

Actually we could pass in inodes directly to clean up all callers.
Also rename iloc() as erofs_iloc().

Signed-off-by: Gao Xiang <[email protected]>
---
changes since v1:
- fix compile errors reported by intel lkp.

fs/erofs/data.c | 9 +++------
fs/erofs/inode.c | 2 +-
fs/erofs/internal.h | 16 +++++++++-------
fs/erofs/xattr.c | 20 +++++++-------------
fs/erofs/zmap.c | 13 +++++--------
include/trace/events/erofs.h | 4 ++--
6 files changed, 27 insertions(+), 37 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index f57f921683d7..2713257ee718 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -91,11 +91,8 @@ static int erofs_map_blocks_flatmode(struct inode *inode,
map->m_pa = blknr_to_addr(vi->raw_blkaddr) + map->m_la;
map->m_plen = blknr_to_addr(lastblk) - offset;
} else if (tailendpacking) {
- /* 2 - inode inline B: inode, [xattrs], inline last blk... */
- struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
-
- map->m_pa = iloc(sbi, vi->nid) + vi->inode_isize +
- vi->xattr_isize + erofs_blkoff(map->m_la);
+ map->m_pa = erofs_iloc(inode) + vi->inode_isize +
+ vi->xattr_isize + erofs_blkoff(offset);
map->m_plen = inode->i_size - offset;

/* inline data should be located in the same meta block */
@@ -150,7 +147,7 @@ int erofs_map_blocks(struct inode *inode,
unit = EROFS_BLOCK_MAP_ENTRY_SIZE; /* block map */

chunknr = map->m_la >> vi->chunkbits;
- pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize +
+ pos = ALIGN(erofs_iloc(inode) + vi->inode_isize +
vi->xattr_isize, unit) + unit * chunknr;

kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP);
diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index 57328691582e..d7e87d41f7bf 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -14,7 +14,7 @@ static void *erofs_read_inode(struct erofs_buf *buf,
struct super_block *sb = inode->i_sb;
struct erofs_sb_info *sbi = EROFS_SB(sb);
struct erofs_inode *vi = EROFS_I(inode);
- const erofs_off_t inode_loc = iloc(sbi, vi->nid);
+ const erofs_off_t inode_loc = erofs_iloc(inode);

erofs_blk_t blkaddr, nblks = 0;
void *kaddr;
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index b4cc40fa3803..08ba817d6551 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -270,11 +270,6 @@ struct erofs_buf {
#define erofs_blkoff(addr) ((addr) % EROFS_BLKSIZ)
#define blknr_to_addr(nr) ((erofs_off_t)(nr) * EROFS_BLKSIZ)

-static inline erofs_off_t iloc(struct erofs_sb_info *sbi, erofs_nid_t nid)
-{
- return blknr_to_addr(sbi->meta_blkaddr) + (nid << sbi->islotbits);
-}
-
#define EROFS_FEATURE_FUNCS(name, compat, feature) \
static inline bool erofs_sb_has_##name(struct erofs_sb_info *sbi) \
{ \
@@ -339,8 +334,15 @@ struct erofs_inode {
struct inode vfs_inode;
};

-#define EROFS_I(ptr) \
- container_of(ptr, struct erofs_inode, vfs_inode)
+#define EROFS_I(ptr) container_of(ptr, struct erofs_inode, vfs_inode)
+
+static inline erofs_off_t erofs_iloc(struct inode *inode)
+{
+ struct erofs_sb_info *sbi = EROFS_I_SB(inode);
+
+ return blknr_to_addr(sbi->meta_blkaddr) +
+ (EROFS_I(inode)->nid << sbi->islotbits);
+}

static inline unsigned long erofs_inode_datablocks(struct inode *inode)
{
diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c
index a62fb8a3318a..60729b1220b6 100644
--- a/fs/erofs/xattr.c
+++ b/fs/erofs/xattr.c
@@ -22,8 +22,7 @@ static int init_inode_xattrs(struct inode *inode)
struct xattr_iter it;
unsigned int i;
struct erofs_xattr_ibody_header *ih;
- struct super_block *sb;
- struct erofs_sb_info *sbi;
+ struct super_block *sb = inode->i_sb;
int ret = 0;

/* the most case is that xattrs of this inode are initialized. */
@@ -52,15 +51,14 @@ static int init_inode_xattrs(struct inode *inode)
* undefined right now (maybe use later with some new sb feature).
*/
if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) {
- erofs_err(inode->i_sb,
+ erofs_err(sb,
"xattr_isize %d of nid %llu is not supported yet",
vi->xattr_isize, vi->nid);
ret = -EOPNOTSUPP;
goto out_unlock;
} else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) {
if (vi->xattr_isize) {
- erofs_err(inode->i_sb,
- "bogus xattr ibody @ nid %llu", vi->nid);
+ erofs_err(sb, "bogus xattr ibody @ nid %llu", vi->nid);
DBG_BUGON(1);
ret = -EFSCORRUPTED;
goto out_unlock; /* xattr ondisk layout error */
@@ -69,11 +67,9 @@ static int init_inode_xattrs(struct inode *inode)
goto out_unlock;
}

- sb = inode->i_sb;
- sbi = EROFS_SB(sb);
it.buf = __EROFS_BUF_INITIALIZER;
- it.blkaddr = erofs_blknr(iloc(sbi, vi->nid) + vi->inode_isize);
- it.ofs = erofs_blkoff(iloc(sbi, vi->nid) + vi->inode_isize);
+ it.blkaddr = erofs_blknr(erofs_iloc(inode) + vi->inode_isize);
+ it.ofs = erofs_blkoff(erofs_iloc(inode) + vi->inode_isize);

/* read in shared xattr array (non-atomic, see kmalloc below) */
it.kaddr = erofs_read_metabuf(&it.buf, sb, it.blkaddr, EROFS_KMAP);
@@ -159,7 +155,6 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
struct inode *inode)
{
struct erofs_inode *const vi = EROFS_I(inode);
- struct erofs_sb_info *const sbi = EROFS_SB(inode->i_sb);
unsigned int xattr_header_sz, inline_xattr_ofs;

xattr_header_sz = inlinexattr_header_size(inode);
@@ -170,9 +165,8 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,

inline_xattr_ofs = vi->inode_isize + xattr_header_sz;

- it->blkaddr = erofs_blknr(iloc(sbi, vi->nid) + inline_xattr_ofs);
- it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs);
-
+ it->blkaddr = erofs_blknr(erofs_iloc(inode) + inline_xattr_ofs);
+ it->ofs = erofs_blkoff(erofs_iloc(inode) + inline_xattr_ofs);
it->kaddr = erofs_read_metabuf(&it->buf, inode->i_sb, it->blkaddr,
EROFS_KMAP);
if (IS_ERR(it->kaddr))
diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
index 98fb90b9af71..3aeffc762b2f 100644
--- a/fs/erofs/zmap.c
+++ b/fs/erofs/zmap.c
@@ -55,8 +55,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode)
if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags))
goto out_unlock;

- pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize +
- vi->xattr_isize, 8);
+ pos = ALIGN(erofs_iloc(inode) + vi->inode_isize + vi->xattr_isize, 8);
kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP);
if (IS_ERR(kaddr)) {
err = PTR_ERR(kaddr);
@@ -169,10 +168,9 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
{
struct inode *const inode = m->inode;
struct erofs_inode *const vi = EROFS_I(inode);
- const erofs_off_t ibase = iloc(EROFS_I_SB(inode), vi->nid);
const erofs_off_t pos =
- Z_EROFS_VLE_LEGACY_INDEX_ALIGN(ibase + vi->inode_isize +
- vi->xattr_isize) +
+ Z_EROFS_VLE_LEGACY_INDEX_ALIGN(erofs_iloc(inode) +
+ vi->inode_isize + vi->xattr_isize) +
lcn * sizeof(struct z_erofs_vle_decompressed_index);
struct z_erofs_vle_decompressed_index *di;
unsigned int advise, type;
@@ -372,9 +370,8 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
struct inode *const inode = m->inode;
struct erofs_inode *const vi = EROFS_I(inode);
const unsigned int lclusterbits = vi->z_logical_clusterbits;
- const erofs_off_t ebase = ALIGN(iloc(EROFS_I_SB(inode), vi->nid) +
- vi->inode_isize + vi->xattr_isize, 8) +
- sizeof(struct z_erofs_map_header);
+ const erofs_off_t ebase = sizeof(struct z_erofs_map_header) +
+ ALIGN(erofs_iloc(inode) + vi->inode_isize + vi->xattr_isize, 8);
const unsigned int totalidx = DIV_ROUND_UP(inode->i_size, EROFS_BLKSIZ);
unsigned int compacted_4b_initial, compacted_2b;
unsigned int amortizedshift;
diff --git a/include/trace/events/erofs.h b/include/trace/events/erofs.h
index 4f4c44ea3a65..e095d36db939 100644
--- a/include/trace/events/erofs.h
+++ b/include/trace/events/erofs.h
@@ -66,8 +66,8 @@ TRACE_EVENT(erofs_fill_inode,
TP_fast_assign(
__entry->dev = inode->i_sb->s_dev;
__entry->nid = EROFS_I(inode)->nid;
- __entry->blkaddr = erofs_blknr(iloc(EROFS_I_SB(inode), __entry->nid));
- __entry->ofs = erofs_blkoff(iloc(EROFS_I_SB(inode), __entry->nid));
+ __entry->blkaddr = erofs_blknr(erofs_iloc(inode));
+ __entry->ofs = erofs_blkoff(erofs_iloc(inode));
),

TP_printk("dev = (%d,%d), nid = %llu, blkaddr %u ofs %u",
--
2.30.2

2023-01-16 01:54:26

by Yue Hu

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] erofs: simplify iloc()

On Sat, 14 Jan 2023 23:08:23 +0800
Gao Xiang <[email protected]> wrote:

> From: Gao Xiang <[email protected]>
>
> Actually we could pass in inodes directly to clean up all callers.
> Also rename iloc() as erofs_iloc().
>
> Signed-off-by: Gao Xiang <[email protected]>

Reviewed-by: Yue Hu <[email protected]>

2023-01-16 02:42:23

by Jingbo Xu

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] erofs: simplify iloc()



On 1/14/23 11:08 PM, Gao Xiang wrote:
> From: Gao Xiang <[email protected]>
>
> Actually we could pass in inodes directly to clean up all callers.
> Also rename iloc() as erofs_iloc().
>
> Signed-off-by: Gao Xiang <[email protected]>

Reviewed-by: Jingbo Xu <[email protected]>

--
Thanks,
Jingbo

2023-02-14 13:47:12

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] erofs: simplify iloc()

On 2023/1/14 23:08, Gao Xiang wrote:
> From: Gao Xiang <[email protected]>
>
> Actually we could pass in inodes directly to clean up all callers.
> Also rename iloc() as erofs_iloc().
>
> Signed-off-by: Gao Xiang <[email protected]>

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

Thanks,