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

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
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -29,11 +29,10 @@ void erofs_put_metabuf(struct erofs_buf *buf)
 * Derive the block size from inode->i_blkbits to make compatible with
 * 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)
{
	struct inode *inode = buf->inode;
	erofs_off_t offset = (erofs_off_t)blkaddr << inode->i_blkbits;
	pgoff_t index = offset >> PAGE_SHIFT;
	struct page *page = buf->page;
	struct folio *folio;
@@ -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_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,
+1 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
		struct erofs_dirent *de;
		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)) {
			erofs_err(sb, "fail to readdir of logical block %u of nid %llu",
				  i, EROFS_I(dir)->nid);
+1 −1
Original line number Diff line number Diff line
@@ -409,7 +409,7 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
			  erofs_off_t *offset, int *lengthp);
void erofs_unmap_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);
void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb);
void *erofs_read_metabuf(struct erofs_buf *buf, struct super_block *sb,
+1 −1
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ static void *erofs_find_target_block(struct erofs_buf *target,
		struct erofs_dirent *de;

		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)) {
			const int nameoff = nameoff_from_disk(de->nameoff, bsz);
			const int ndirents = nameoff / sizeof(*de);
+4 −4
Original line number Diff line number Diff line
@@ -132,11 +132,11 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
	int len, i, cnt;

	*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))
		return ptr;

	len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(sb, *offset)]);
	len = le16_to_cpu(*(__le16 *)ptr);
	if (!len)
		len = U16_MAX + 1;
	buffer = kmalloc(len, GFP_KERNEL);
@@ -148,12 +148,12 @@ void *erofs_read_metadata(struct super_block *sb, struct erofs_buf *buf,
	for (i = 0; i < len; i += cnt) {
		cnt = min_t(int, sb->s_blocksize - erofs_blkoff(sb, *offset),
			    len - i);
		ptr = erofs_bread(buf, erofs_blknr(sb, *offset), EROFS_KMAP);
		ptr = erofs_bread(buf, *offset, EROFS_KMAP);
		if (IS_ERR(ptr)) {
			kfree(buffer);
			return ptr;
		}
		memcpy(buffer + i, ptr + erofs_blkoff(sb, *offset), cnt);
		memcpy(buffer + i, ptr, cnt);
		*offset += cnt;
	}
	return buffer;
Loading