Commit 65bdd16f authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe
Browse files

loop: cleanup loop_config_discard



Initialize the local variables for the discard max sectors and
granularity to zero as a sensible default, and then merge the
calls assigning them to the queue limits.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarKeith Busch <kbusch@kernel.org>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
Reviewed-by: default avatarDamien Le Moal <dlemoal@kernel.org>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20240213073425.1621680-14-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 8b837256
Loading
Loading
Loading
Loading
+8 −19
Original line number Diff line number Diff line
@@ -755,7 +755,8 @@ static void loop_config_discard(struct loop_device *lo)
	struct file *file = lo->lo_backing_file;
	struct inode *inode = file->f_mapping->host;
	struct request_queue *q = lo->lo_queue;
	u32 granularity, max_discard_sectors;
	u32 granularity = 0, max_discard_sectors = 0;
	struct kstatfs sbuf;

	/*
	 * If the backing device is a block device, mirror its zeroing
@@ -775,29 +776,17 @@ static void loop_config_discard(struct loop_device *lo)
	 * We use punch hole to reclaim the free space used by the
	 * image a.k.a. discard.
	 */
	} else if (!file->f_op->fallocate) {
		max_discard_sectors = 0;
		granularity = 0;

	} else {
		struct kstatfs sbuf;

	} else if (file->f_op->fallocate && !vfs_statfs(&file->f_path, &sbuf)) {
		max_discard_sectors = UINT_MAX >> 9;
		if (!vfs_statfs(&file->f_path, &sbuf))
		granularity = sbuf.f_bsize;
		else
			max_discard_sectors = 0;
	}

	if (max_discard_sectors) {
		q->limits.discard_granularity = granularity;
	blk_queue_max_discard_sectors(q, max_discard_sectors);
	blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
	} else {
	if (max_discard_sectors)
		q->limits.discard_granularity = granularity;
	else
		q->limits.discard_granularity = 0;
		blk_queue_max_discard_sectors(q, 0);
		blk_queue_max_write_zeroes_sectors(q, 0);
	}
}

struct loop_worker {