Skip to content

Commit a09cd55

Browse files
author
Al Viro
committed
Merge branch 'misc.erofs' into work.bdev
2 parents 2638c20 + 958b9f8 commit a09cd55

File tree

7 files changed

+33
-44
lines changed

7 files changed

+33
-44
lines changed

fs/erofs/data.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ void erofs_put_metabuf(struct erofs_buf *buf)
2929
* Derive the block size from inode->i_blkbits to make compatible with
3030
* anonymous inode in fscache mode.
3131
*/
32-
void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr,
32+
void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset,
3333
enum erofs_kmap_type type)
3434
{
35-
struct inode *inode = buf->inode;
36-
erofs_off_t offset = (erofs_off_t)blkaddr << inode->i_blkbits;
3735
pgoff_t index = offset >> PAGE_SHIFT;
3836
struct page *page = buf->page;
3937
struct folio *folio;
@@ -43,7 +41,7 @@ void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr,
4341
erofs_put_metabuf(buf);
4442

4543
nofs_flag = memalloc_nofs_save();
46-
folio = read_cache_folio(inode->i_mapping, index, NULL, NULL);
44+
folio = read_cache_folio(buf->mapping, index, NULL, NULL);
4745
memalloc_nofs_restore(nofs_flag);
4846
if (IS_ERR(folio))
4947
return folio;
@@ -68,16 +66,16 @@ void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr,
6866
void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb)
6967
{
7068
if (erofs_is_fscache_mode(sb))
71-
buf->inode = EROFS_SB(sb)->s_fscache->inode;
69+
buf->mapping = EROFS_SB(sb)->s_fscache->inode->i_mapping;
7270
else
73-
buf->inode = sb->s_bdev->bd_inode;
71+
buf->mapping = sb->s_bdev->bd_inode->i_mapping;
7472
}
7573

7674
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
7775
erofs_blk_t blkaddr, enum erofs_kmap_type type)
7876
{
7977
erofs_init_metabuf(buf, sb);
80-
return erofs_bread(buf, blkaddr, type);
78+
return erofs_bread(buf, erofs_pos(sb, blkaddr), type);
8179
}
8280

8381
static int erofs_map_blocks_flatmode(struct inode *inode,

fs/erofs/dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
5858
int err = 0;
5959
bool initial = true;
6060

61-
buf.inode = dir;
61+
buf.mapping = dir->i_mapping;
6262
while (ctx->pos < dirsize) {
6363
struct erofs_dirent *de;
6464
unsigned int nameoff, maxsize;
6565

66-
de = erofs_bread(&buf, i, EROFS_KMAP);
66+
de = erofs_bread(&buf, erofs_pos(sb, i), EROFS_KMAP);
6767
if (IS_ERR(de)) {
6868
erofs_err(sb, "fail to readdir of logical block %u of nid %llu",
6969
i, EROFS_I(dir)->nid);

fs/erofs/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ enum erofs_kmap_type {
223223
};
224224

225225
struct erofs_buf {
226-
struct inode *inode;
226+
struct address_space *mapping;
227227
struct page *page;
228228
void *base;
229229
enum erofs_kmap_type kmap_type;
@@ -409,7 +409,7 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
409409
erofs_off_t *offset, int *lengthp);
410410
void erofs_unmap_metabuf(struct erofs_buf *buf);
411411
void erofs_put_metabuf(struct erofs_buf *buf);
412-
void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr,
412+
void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset,
413413
enum erofs_kmap_type type);
414414
void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb);
415415
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,

fs/erofs/namei.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ static void *erofs_find_target_block(struct erofs_buf *target,
9999
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
100100
struct erofs_dirent *de;
101101

102-
buf.inode = dir;
103-
de = erofs_bread(&buf, mid, EROFS_KMAP);
102+
buf.mapping = dir->i_mapping;
103+
de = erofs_bread(&buf, erofs_pos(dir->i_sb, mid), EROFS_KMAP);
104104
if (!IS_ERR(de)) {
105105
const int nameoff = nameoff_from_disk(de->nameoff, bsz);
106106
const int ndirents = nameoff / sizeof(*de);
@@ -171,7 +171,7 @@ int erofs_namei(struct inode *dir, const struct qstr *name, erofs_nid_t *nid,
171171

172172
qn.name = name->name;
173173
qn.end = name->name + name->len;
174-
buf.inode = dir;
174+
buf.mapping = dir->i_mapping;
175175

176176
ndirents = 0;
177177
de = erofs_find_target_block(&buf, dir, &qn, &ndirents);

fs/erofs/super.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
132132
int len, i, cnt;
133133

134134
*offset = round_up(*offset, 4);
135-
ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP);
135+
ptr = erofs_bread(buf, *offset, EROFS_KMAP);
136136
if (IS_ERR(ptr))
137137
return ptr;
138138

139-
len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(sb, *offset)]);
139+
len = le16_to_cpu(*(__le16 *)ptr);
140140
if (!len)
141141
len = U16_MAX + 1;
142142
buffer = kmalloc(len, GFP_KERNEL);
@@ -148,12 +148,12 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
148148
for (i = 0; i < len; i += cnt) {
149149
cnt = min_t(int, sb->s_blocksize - erofs_blkoff(sb, *offset),
150150
len - i);
151-
ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP);
151+
ptr = erofs_bread(buf, *offset, EROFS_KMAP);
152152
if (IS_ERR(ptr)) {
153153
kfree(buffer);
154154
return ptr;
155155
}
156-
memcpy(buffer + i, ptr + erofs_blkoff(sb, *offset), cnt);
156+
memcpy(buffer + i, ptr, cnt);
157157
*offset += cnt;
158158
}
159159
return buffer;

fs/erofs/xattr.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ static int erofs_init_inode_xattrs(struct inode *inode)
8181
it.pos = erofs_iloc(inode) + vi->inode_isize;
8282

8383
/* read in shared xattr array (non-atomic, see kmalloc below) */
84-
it.kaddr = erofs_bread(&it.buf, erofs_blknr(sb, it.pos), EROFS_KMAP);
84+
it.kaddr = erofs_bread(&it.buf, it.pos, EROFS_KMAP);
8585
if (IS_ERR(it.kaddr)) {
8686
ret = PTR_ERR(it.kaddr);
8787
goto out_unlock;
8888
}
8989

90-
ih = it.kaddr + erofs_blkoff(sb, it.pos);
90+
ih = it.kaddr;
9191
vi->xattr_name_filter = le32_to_cpu(ih->h_name_filter);
9292
vi->xattr_shared_count = ih->h_shared_count;
9393
vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count,
@@ -102,16 +102,14 @@ static int erofs_init_inode_xattrs(struct inode *inode)
102102
it.pos += sizeof(struct erofs_xattr_ibody_header);
103103

104104
for (i = 0; i < vi->xattr_shared_count; ++i) {
105-
it.kaddr = erofs_bread(&it.buf, erofs_blknr(sb, it.pos),
106-
EROFS_KMAP);
105+
it.kaddr = erofs_bread(&it.buf, it.pos, EROFS_KMAP);
107106
if (IS_ERR(it.kaddr)) {
108107
kfree(vi->xattr_shared_xattrs);
109108
vi->xattr_shared_xattrs = NULL;
110109
ret = PTR_ERR(it.kaddr);
111110
goto out_unlock;
112111
}
113-
vi->xattr_shared_xattrs[i] = le32_to_cpu(*(__le32 *)
114-
(it.kaddr + erofs_blkoff(sb, it.pos)));
112+
vi->xattr_shared_xattrs[i] = le32_to_cpu(*(__le32 *)it.kaddr);
115113
it.pos += sizeof(__le32);
116114
}
117115
erofs_put_metabuf(&it.buf);
@@ -185,12 +183,11 @@ static int erofs_xattr_copy_to_buffer(struct erofs_xattr_iter *it,
185183
void *src;
186184

187185
for (processed = 0; processed < len; processed += slice) {
188-
it->kaddr = erofs_bread(&it->buf, erofs_blknr(sb, it->pos),
189-
EROFS_KMAP);
186+
it->kaddr = erofs_bread(&it->buf, it->pos, EROFS_KMAP);
190187
if (IS_ERR(it->kaddr))
191188
return PTR_ERR(it->kaddr);
192189

193-
src = it->kaddr + erofs_blkoff(sb, it->pos);
190+
src = it->kaddr;
194191
slice = min_t(unsigned int, sb->s_blocksize -
195192
erofs_blkoff(sb, it->pos), len - processed);
196193
memcpy(it->buffer + it->buffer_ofs, src, slice);
@@ -208,8 +205,7 @@ static int erofs_listxattr_foreach(struct erofs_xattr_iter *it)
208205
int err;
209206

210207
/* 1. handle xattr entry */
211-
entry = *(struct erofs_xattr_entry *)
212-
(it->kaddr + erofs_blkoff(it->sb, it->pos));
208+
entry = *(struct erofs_xattr_entry *)it->kaddr;
213209
it->pos += sizeof(struct erofs_xattr_entry);
214210

215211
base_index = entry.e_name_index;
@@ -259,8 +255,7 @@ static int erofs_getxattr_foreach(struct erofs_xattr_iter *it)
259255
unsigned int slice, processed, value_sz;
260256

261257
/* 1. handle xattr entry */
262-
entry = *(struct erofs_xattr_entry *)
263-
(it->kaddr + erofs_blkoff(sb, it->pos));
258+
entry = *(struct erofs_xattr_entry *)it->kaddr;
264259
it->pos += sizeof(struct erofs_xattr_entry);
265260
value_sz = le16_to_cpu(entry.e_value_size);
266261

@@ -291,16 +286,15 @@ static int erofs_getxattr_foreach(struct erofs_xattr_iter *it)
291286

292287
/* 2. handle xattr name */
293288
for (processed = 0; processed < entry.e_name_len; processed += slice) {
294-
it->kaddr = erofs_bread(&it->buf, erofs_blknr(sb, it->pos),
295-
EROFS_KMAP);
289+
it->kaddr = erofs_bread(&it->buf, it->pos, EROFS_KMAP);
296290
if (IS_ERR(it->kaddr))
297291
return PTR_ERR(it->kaddr);
298292

299293
slice = min_t(unsigned int,
300294
sb->s_blocksize - erofs_blkoff(sb, it->pos),
301295
entry.e_name_len - processed);
302296
if (memcmp(it->name.name + it->infix_len + processed,
303-
it->kaddr + erofs_blkoff(sb, it->pos), slice))
297+
it->kaddr, slice))
304298
return -ENOATTR;
305299
it->pos += slice;
306300
}
@@ -336,13 +330,11 @@ static int erofs_xattr_iter_inline(struct erofs_xattr_iter *it,
336330
it->pos = erofs_iloc(inode) + vi->inode_isize + xattr_header_sz;
337331

338332
while (remaining) {
339-
it->kaddr = erofs_bread(&it->buf, erofs_blknr(it->sb, it->pos),
340-
EROFS_KMAP);
333+
it->kaddr = erofs_bread(&it->buf, it->pos, EROFS_KMAP);
341334
if (IS_ERR(it->kaddr))
342335
return PTR_ERR(it->kaddr);
343336

344-
entry_sz = erofs_xattr_entry_size(it->kaddr +
345-
erofs_blkoff(it->sb, it->pos));
337+
entry_sz = erofs_xattr_entry_size(it->kaddr);
346338
/* xattr on-disk corruption: xattr entry beyond xattr_isize */
347339
if (remaining < entry_sz) {
348340
DBG_BUGON(1);
@@ -375,8 +367,7 @@ static int erofs_xattr_iter_shared(struct erofs_xattr_iter *it,
375367
for (i = 0; i < vi->xattr_shared_count; ++i) {
376368
it->pos = erofs_pos(sb, sbi->xattr_blkaddr) +
377369
vi->xattr_shared_xattrs[i] * sizeof(__le32);
378-
it->kaddr = erofs_bread(&it->buf, erofs_blknr(sb, it->pos),
379-
EROFS_KMAP);
370+
it->kaddr = erofs_bread(&it->buf, it->pos, EROFS_KMAP);
380371
if (IS_ERR(it->kaddr))
381372
return PTR_ERR(it->kaddr);
382373

@@ -492,7 +483,7 @@ int erofs_xattr_prefixes_init(struct super_block *sb)
492483
return -ENOMEM;
493484

494485
if (sbi->packed_inode)
495-
buf.inode = sbi->packed_inode;
486+
buf.mapping = sbi->packed_inode->i_mapping;
496487
else
497488
erofs_init_metabuf(&buf, sb);
498489

fs/erofs/zdata.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,16 +936,16 @@ static int z_erofs_read_fragment(struct super_block *sb, struct page *page,
936936
if (!packed_inode)
937937
return -EFSCORRUPTED;
938938

939-
buf.inode = packed_inode;
939+
buf.mapping = packed_inode->i_mapping;
940940
for (; cur < end; cur += cnt, pos += cnt) {
941941
cnt = min_t(unsigned int, end - cur,
942942
sb->s_blocksize - erofs_blkoff(sb, pos));
943-
src = erofs_bread(&buf, erofs_blknr(sb, pos), EROFS_KMAP);
943+
src = erofs_bread(&buf, pos, EROFS_KMAP);
944944
if (IS_ERR(src)) {
945945
erofs_put_metabuf(&buf);
946946
return PTR_ERR(src);
947947
}
948-
memcpy_to_page(page, cur, src + erofs_blkoff(sb, pos), cnt);
948+
memcpy_to_page(page, cur, src, cnt);
949949
}
950950
erofs_put_metabuf(&buf);
951951
return 0;

0 commit comments

Comments
 (0)