Re: [PATCH v2] block: Discard page cache of zone reset target range

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mar 10, 2021 / 08:45, Christoph Hellwig wrote:
> >  	switch (cmd) {
> >  	case BLKRESETZONE:
> >  		op = REQ_OP_ZONE_RESET;
> > +
> > +		capacity = get_capacity(bdev->bd_disk);
> > +		if (zrange.sector + zrange.nr_sectors <= zrange.sector ||
> > +		    zrange.sector + zrange.nr_sectors > capacity)
> > +			/* Out of range */
> > +			return -EINVAL;
> > +
> > +		start = zrange.sector << SECTOR_SHIFT;
> > +		end = ((zrange.sector + zrange.nr_sectors) << SECTOR_SHIFT) - 1;
> > +
> > +		/* Invalidate the page cache, including dirty pages. */
> > +		ret = truncate_bdev_range(bdev, mode, start, end);
> > +		if (ret)
> > +			return ret;
> 
> Can we factor this out into a truncate_zone_range() helper?

Yes, we can. The helper will be as follows. I will rework the patch and send v3.

static int blkdev_truncate_zone_range(struct block_device *bdev, fmode_t mode,
				      const struct blk_zone_range *zrange)
{
	loff_t start, end;

	if (zrange->sector + zrange->nr_sectors <= zrange->sector ||
	    zrange->sector + zrange->nr_sectors > get_capacity(bdev->bd_disk))
		/* Out of range */
		return -EINVAL;

	start = zrange->sector << SECTOR_SHIFT;
	end = ((zrange->sector + zrange->nr_sectors) << SECTOR_SHIFT) - 1;

	return truncate_bdev_range(bdev, mode, start, end);
}

-- 
Best Regards,
Shin'ichiro Kawasaki



[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux