Re: [PATCH v2] squashfs: cache partial compressed blocks

Christoph Hellwig
2023-05-15T10:05:23Z

On Fri, May 12, 2023 at 03:18:05PM +0200, Vincent Whitchurch wrote:
> +static int squashfs_bio_read_cached(struct bio *fullbio, struct address_space *cache_mapping,
> + u64 index, int length, u64 read_start, u64 read_end,
> + int page_count)

Please avoid the unreadable formatting and do something like:

static int squashfs_bio_read_cached(struct bio *fullbio,
struct address_space *cache_mapping, u64 index, int length,
u64 read_start, u64 read_end, int page_count)

> + if (!bio || idx != prev_io_idx + 1) {
> + unsigned int remaining_pages;
> + unsigned int this_nr_pages;
> +
> +submit_and_retry:
> + remaining_pages = page_count - idx;
> + this_nr_pages = min(remaining_pages, BIO_MAX_VECS);
> + bio = blk_next_bio(bio, bdev, this_nr_pages, REQ_OP_READ,
> + GFP_NOIO);
> + bio->bi_iter.bi_sector = fullbio->bi_iter.bi_sector +
> + idx * (PAGE_SIZE / SECTOR_SIZE);
> + }
> +
> + retlen = bio_add_page(bio, bv->bv_page, bv->bv_len, bv->bv_offset);
> + if (retlen != bv->bv_len)
> + goto submit_and_retry;

Adding data payload to a bio while passing full bio_vec is usually
a sign that instead you should do a (partial) clone of the bio instead.
I think this is such a case.

> static int squashfs_bio_read(struct super_block *sb, u64 index, int length,
> struct bio **biop, int *block_offset)
> {
> struct squashfs_sb_info *msblk = sb->s_fs_info;
> + struct inode *cache_inode = msblk->cache_inode;
> + struct address_space *cache_mapping = cache_inode ? cache_inode->i_mapping : NULL;

Unless I'm badly misreading the squashfs_fill_super changes,
cache_inode can't ever be NULL here or anywhere else in the I/O
code.