Commit 469ad583 authored by Al Viro's avatar Al Viro

erofs: switch erofs_bread() to passing offset instead of block number

Callers are happier that way, especially since we no longer need to
play with splitting offset into block number and offset within block,
passing the former to erofs_bread(), then adding the latter...

erofs_bread() always reads entire pages, anyway.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 39cd87c4
...@@ -29,11 +29,10 @@ void erofs_put_metabuf(struct erofs_buf *buf) ...@@ -29,11 +29,10 @@ void erofs_put_metabuf(struct erofs_buf *buf)
* Derive the block size from inode->i_blkbits to make compatible with * Derive the block size from inode->i_blkbits to make compatible with
* anonymous inode in fscache mode. * anonymous inode in fscache mode.
*/ */
void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset,
enum erofs_kmap_type type) enum erofs_kmap_type type)
{ {
struct inode *inode = buf->inode; struct inode *inode = buf->inode;
erofs_off_t offset = (erofs_off_t)blkaddr << inode->i_blkbits;
pgoff_t index = offset >> PAGE_SHIFT; pgoff_t index = offset >> PAGE_SHIFT;
struct page *page = buf->page; struct page *page = buf->page;
struct folio *folio; struct folio *folio;
...@@ -77,7 +76,7 @@ void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, ...@@ -77,7 +76,7 @@ void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
erofs_blk_t blkaddr, enum erofs_kmap_type type) erofs_blk_t blkaddr, enum erofs_kmap_type type)
{ {
erofs_init_metabuf(buf, sb); erofs_init_metabuf(buf, sb);
return erofs_bread(buf, blkaddr, type); return erofs_bread(buf, erofs_pos(sb, blkaddr), type);
} }
static int erofs_map_blocks_flatmode(struct inode *inode, static int erofs_map_blocks_flatmode(struct inode *inode,
......
...@@ -63,7 +63,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx) ...@@ -63,7 +63,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
struct erofs_dirent *de; struct erofs_dirent *de;
unsigned int nameoff, maxsize; unsigned int nameoff, maxsize;
de = erofs_bread(&buf, i, EROFS_KMAP); de = erofs_bread(&buf, erofs_pos(sb, i), EROFS_KMAP);
if (IS_ERR(de)) { if (IS_ERR(de)) {
erofs_err(sb, "fail to readdir of logical block %u of nid %llu", erofs_err(sb, "fail to readdir of logical block %u of nid %llu",
i, EROFS_I(dir)->nid); i, EROFS_I(dir)->nid);
......
...@@ -409,7 +409,7 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, ...@@ -409,7 +409,7 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
erofs_off_t *offset, int *lengthp); erofs_off_t *offset, int *lengthp);
void erofs_unmap_metabuf(struct erofs_buf *buf); void erofs_unmap_metabuf(struct erofs_buf *buf);
void erofs_put_metabuf(struct erofs_buf *buf); void erofs_put_metabuf(struct erofs_buf *buf);
void *erofs_bread(struct erofs_buf *buf, erofs_blk_t blkaddr, void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset,
enum erofs_kmap_type type); enum erofs_kmap_type type);
void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb); void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb);
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb, void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
......
...@@ -100,7 +100,7 @@ static void *erofs_find_target_block(struct erofs_buf *target, ...@@ -100,7 +100,7 @@ static void *erofs_find_target_block(struct erofs_buf *target,
struct erofs_dirent *de; struct erofs_dirent *de;
buf.inode = dir; buf.inode = dir;
de = erofs_bread(&buf, mid, EROFS_KMAP); de = erofs_bread(&buf, erofs_pos(dir->i_sb, mid), EROFS_KMAP);
if (!IS_ERR(de)) { if (!IS_ERR(de)) {
const int nameoff = nameoff_from_disk(de->nameoff, bsz); const int nameoff = nameoff_from_disk(de->nameoff, bsz);
const int ndirents = nameoff / sizeof(*de); const int ndirents = nameoff / sizeof(*de);
......
...@@ -132,11 +132,11 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, ...@@ -132,11 +132,11 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
int len, i, cnt; int len, i, cnt;
*offset = round_up(*offset, 4); *offset = round_up(*offset, 4);
ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP); ptr = erofs_bread(buf, *offset, EROFS_KMAP);
if (IS_ERR(ptr)) if (IS_ERR(ptr))
return ptr; return ptr;
len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(sb, *offset)]); len = le16_to_cpu(*(__le16 *)ptr);
if (!len) if (!len)
len = U16_MAX + 1; len = U16_MAX + 1;
buffer = kmalloc(len, GFP_KERNEL); buffer = kmalloc(len, GFP_KERNEL);
...@@ -148,12 +148,12 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf, ...@@ -148,12 +148,12 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
for (i = 0; i < len; i += cnt) { for (i = 0; i < len; i += cnt) {
cnt = min_t(int, sb->s_blocksize - erofs_blkoff(sb, *offset), cnt = min_t(int, sb->s_blocksize - erofs_blkoff(sb, *offset),
len - i); len - i);
ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP); ptr = erofs_bread(buf, *offset, EROFS_KMAP);
if (IS_ERR(ptr)) { if (IS_ERR(ptr)) {
kfree(buffer); kfree(buffer);
return ptr; return ptr;
} }
memcpy(buffer + i, ptr + erofs_blkoff(sb, *offset), cnt); memcpy(buffer + i, ptr, cnt);
*offset += cnt; *offset += cnt;
} }
return buffer; return buffer;
......
...@@ -81,13 +81,13 @@ static int erofs_init_inode_xattrs(struct inode *inode) ...@@ -81,13 +81,13 @@ static int erofs_init_inode_xattrs(struct inode *inode)
it.pos = erofs_iloc(inode) + vi->inode_isize; it.pos = erofs_iloc(inode) + vi->inode_isize;
/* read in shared xattr array (non-atomic, see kmalloc below) */ /* read in shared xattr array (non-atomic, see kmalloc below) */
it.kaddr = erofs_bread(&it.buf, erofs_blknr(sb, it.pos), EROFS_KMAP); it.kaddr = erofs_bread(&it.buf, it.pos, EROFS_KMAP);
if (IS_ERR(it.kaddr)) { if (IS_ERR(it.kaddr)) {
ret = PTR_ERR(it.kaddr); ret = PTR_ERR(it.kaddr);
goto out_unlock; goto out_unlock;
} }
ih = it.kaddr + erofs_blkoff(sb, it.pos); ih = it.kaddr;
vi->xattr_name_filter = le32_to_cpu(ih->h_name_filter); vi->xattr_name_filter = le32_to_cpu(ih->h_name_filter);
vi->xattr_shared_count = ih->h_shared_count; vi->xattr_shared_count = ih->h_shared_count;
vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count, vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count,
...@@ -102,16 +102,14 @@ static int erofs_init_inode_xattrs(struct inode *inode) ...@@ -102,16 +102,14 @@ static int erofs_init_inode_xattrs(struct inode *inode)
it.pos += sizeof(struct erofs_xattr_ibody_header); it.pos += sizeof(struct erofs_xattr_ibody_header);
for (i = 0; i < vi->xattr_shared_count; ++i) { for (i = 0; i < vi->xattr_shared_count; ++i) {
it.kaddr = erofs_bread(&it.buf, erofs_blknr(sb, it.pos), it.kaddr = erofs_bread(&it.buf, it.pos, EROFS_KMAP);
EROFS_KMAP);
if (IS_ERR(it.kaddr)) { if (IS_ERR(it.kaddr)) {
kfree(vi->xattr_shared_xattrs); kfree(vi->xattr_shared_xattrs);
vi->xattr_shared_xattrs = NULL; vi->xattr_shared_xattrs = NULL;
ret = PTR_ERR(it.kaddr); ret = PTR_ERR(it.kaddr);
goto out_unlock; goto out_unlock;
} }
vi->xattr_shared_xattrs[i] = le32_to_cpu(*(__le32 *) vi->xattr_shared_xattrs[i] = le32_to_cpu(*(__le32 *)it.kaddr);
(it.kaddr + erofs_blkoff(sb, it.pos)));
it.pos += sizeof(__le32); it.pos += sizeof(__le32);
} }
erofs_put_metabuf(&it.buf); erofs_put_metabuf(&it.buf);
...@@ -185,12 +183,11 @@ static int erofs_xattr_copy_to_buffer(struct erofs_xattr_iter *it, ...@@ -185,12 +183,11 @@ static int erofs_xattr_copy_to_buffer(struct erofs_xattr_iter *it,
void *src; void *src;
for (processed = 0; processed < len; processed += slice) { for (processed = 0; processed < len; processed += slice) {
it->kaddr = erofs_bread(&it->buf, erofs_blknr(sb, it->pos), it->kaddr = erofs_bread(&it->buf, it->pos, EROFS_KMAP);
EROFS_KMAP);
if (IS_ERR(it->kaddr)) if (IS_ERR(it->kaddr))
return PTR_ERR(it->kaddr); return PTR_ERR(it->kaddr);
src = it->kaddr + erofs_blkoff(sb, it->pos); src = it->kaddr;
slice = min_t(unsigned int, sb->s_blocksize - slice = min_t(unsigned int, sb->s_blocksize -
erofs_blkoff(sb, it->pos), len - processed); erofs_blkoff(sb, it->pos), len - processed);
memcpy(it->buffer + it->buffer_ofs, src, slice); memcpy(it->buffer + it->buffer_ofs, src, slice);
...@@ -208,8 +205,7 @@ static int erofs_listxattr_foreach(struct erofs_xattr_iter *it) ...@@ -208,8 +205,7 @@ static int erofs_listxattr_foreach(struct erofs_xattr_iter *it)
int err; int err;
/* 1. handle xattr entry */ /* 1. handle xattr entry */
entry = *(struct erofs_xattr_entry *) entry = *(struct erofs_xattr_entry *)it->kaddr;
(it->kaddr + erofs_blkoff(it->sb, it->pos));
it->pos += sizeof(struct erofs_xattr_entry); it->pos += sizeof(struct erofs_xattr_entry);
base_index = entry.e_name_index; base_index = entry.e_name_index;
...@@ -259,8 +255,7 @@ static int erofs_getxattr_foreach(struct erofs_xattr_iter *it) ...@@ -259,8 +255,7 @@ static int erofs_getxattr_foreach(struct erofs_xattr_iter *it)
unsigned int slice, processed, value_sz; unsigned int slice, processed, value_sz;
/* 1. handle xattr entry */ /* 1. handle xattr entry */
entry = *(struct erofs_xattr_entry *) entry = *(struct erofs_xattr_entry *)it->kaddr;
(it->kaddr + erofs_blkoff(sb, it->pos));
it->pos += sizeof(struct erofs_xattr_entry); it->pos += sizeof(struct erofs_xattr_entry);
value_sz = le16_to_cpu(entry.e_value_size); value_sz = le16_to_cpu(entry.e_value_size);
...@@ -291,8 +286,7 @@ static int erofs_getxattr_foreach(struct erofs_xattr_iter *it) ...@@ -291,8 +286,7 @@ static int erofs_getxattr_foreach(struct erofs_xattr_iter *it)
/* 2. handle xattr name */ /* 2. handle xattr name */
for (processed = 0; processed < entry.e_name_len; processed += slice) { for (processed = 0; processed < entry.e_name_len; processed += slice) {
it->kaddr = erofs_bread(&it->buf, erofs_blknr(sb, it->pos), it->kaddr = erofs_bread(&it->buf, it->pos, EROFS_KMAP);
EROFS_KMAP);
if (IS_ERR(it->kaddr)) if (IS_ERR(it->kaddr))
return PTR_ERR(it->kaddr); return PTR_ERR(it->kaddr);
...@@ -300,7 +294,7 @@ static int erofs_getxattr_foreach(struct erofs_xattr_iter *it) ...@@ -300,7 +294,7 @@ static int erofs_getxattr_foreach(struct erofs_xattr_iter *it)
sb->s_blocksize - erofs_blkoff(sb, it->pos), sb->s_blocksize - erofs_blkoff(sb, it->pos),
entry.e_name_len - processed); entry.e_name_len - processed);
if (memcmp(it->name.name + it->infix_len + processed, if (memcmp(it->name.name + it->infix_len + processed,
it->kaddr + erofs_blkoff(sb, it->pos), slice)) it->kaddr, slice))
return -ENOATTR; return -ENOATTR;
it->pos += slice; it->pos += slice;
} }
...@@ -336,13 +330,11 @@ static int erofs_xattr_iter_inline(struct erofs_xattr_iter *it, ...@@ -336,13 +330,11 @@ static int erofs_xattr_iter_inline(struct erofs_xattr_iter *it,
it->pos = erofs_iloc(inode) + vi->inode_isize + xattr_header_sz; it->pos = erofs_iloc(inode) + vi->inode_isize + xattr_header_sz;
while (remaining) { while (remaining) {
it->kaddr = erofs_bread(&it->buf, erofs_blknr(it->sb, it->pos), it->kaddr = erofs_bread(&it->buf, it->pos, EROFS_KMAP);
EROFS_KMAP);
if (IS_ERR(it->kaddr)) if (IS_ERR(it->kaddr))
return PTR_ERR(it->kaddr); return PTR_ERR(it->kaddr);
entry_sz = erofs_xattr_entry_size(it->kaddr + entry_sz = erofs_xattr_entry_size(it->kaddr);
erofs_blkoff(it->sb, it->pos));
/* xattr on-disk corruption: xattr entry beyond xattr_isize */ /* xattr on-disk corruption: xattr entry beyond xattr_isize */
if (remaining < entry_sz) { if (remaining < entry_sz) {
DBG_BUGON(1); DBG_BUGON(1);
...@@ -375,8 +367,7 @@ static int erofs_xattr_iter_shared(struct erofs_xattr_iter *it, ...@@ -375,8 +367,7 @@ static int erofs_xattr_iter_shared(struct erofs_xattr_iter *it,
for (i = 0; i < vi->xattr_shared_count; ++i) { for (i = 0; i < vi->xattr_shared_count; ++i) {
it->pos = erofs_pos(sb, sbi->xattr_blkaddr) + it->pos = erofs_pos(sb, sbi->xattr_blkaddr) +
vi->xattr_shared_xattrs[i] * sizeof(__le32); vi->xattr_shared_xattrs[i] * sizeof(__le32);
it->kaddr = erofs_bread(&it->buf, erofs_blknr(sb, it->pos), it->kaddr = erofs_bread(&it->buf, it->pos, EROFS_KMAP);
EROFS_KMAP);
if (IS_ERR(it->kaddr)) if (IS_ERR(it->kaddr))
return PTR_ERR(it->kaddr); return PTR_ERR(it->kaddr);
......
...@@ -940,12 +940,12 @@ static int z_erofs_read_fragment(struct super_block *sb, struct page *page, ...@@ -940,12 +940,12 @@ static int z_erofs_read_fragment(struct super_block *sb, struct page *page,
for (; cur < end; cur += cnt, pos += cnt) { for (; cur < end; cur += cnt, pos += cnt) {
cnt = min_t(unsigned int, end - cur, cnt = min_t(unsigned int, end - cur,
sb->s_blocksize - erofs_blkoff(sb, pos)); sb->s_blocksize - erofs_blkoff(sb, pos));
src = erofs_bread(&buf, erofs_blknr(sb, pos), EROFS_KMAP); src = erofs_bread(&buf, pos, EROFS_KMAP);
if (IS_ERR(src)) { if (IS_ERR(src)) {
erofs_put_metabuf(&buf); erofs_put_metabuf(&buf);
return PTR_ERR(src); return PTR_ERR(src);
} }
memcpy_to_page(page, cur, src + erofs_blkoff(sb, pos), cnt); memcpy_to_page(page, cur, src, cnt);
} }
erofs_put_metabuf(&buf); erofs_put_metabuf(&buf);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment