Re: [PATCH 11/20] block, blksnap: functions and structures for performing block I/O operations

From: Christoph Hellwig
Date: Thu Jul 07 2022 - 13:33:33 EST


> +#define SECTORS_IN_PAGE (PAGE_SIZE / SECTOR_SIZE)

This can use PAGE_SECTORS from blk_types.h

> +
> +struct bio_set diff_io_bioset = { 0 };

No need to initialize global variables to 0.

> + // Allocate both bios
> + opf = diff_io->is_write ? REQ_OP_WRITE : REQ_OP_READ;
> + gfp = GFP_NOIO | (is_nowait ? GFP_NOWAIT : 0);
> +
> + bio = bio_alloc_bioset(diff_region->bdev, nr_iovecs,
> + opf | REQ_SYNC | REQ_IDLE | REQ_FUA,

REQ_FUA on reads does not make sense.

> + submit_bio_noacct(bio);
> +
> + // Submit flush bio
> + bio_set_flag(flush_bio, BIO_FILTERED);
> + flush_bio->bi_end_io = diff_io_endio;
> + flush_bio->bi_private = diff_io;
> + flush_bio->bi_iter.bi_sector = 0;
> + submit_bio_noacct(flush_bio);

And a separate flush for reads seems odd and probably wrong here.
And for writes REQ_FUA already ensuresyour write went to disk.
Do you also need to flush all previous data? In which case you
probably want a single bio with REQ_PREFLUSH and REQ_FUA instead
of submitting two separate bios here.