xen-blkback: use bdev_discard_alignment

Use bdev_discard_alignment to calculate the correct discard alignment
offset even for partitions instead of just looking at the queue limit.

Also switch to use bdev_discard_granularity to get rid of the last direct
queue reference in xen_blkbk_discard.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20220418045314.360785-12-hch@lst.de
[axboe: fold in 'q' removal as it's now unused]
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig 2022-04-18 06:53:14 +02:00 committed by Jens Axboe
parent 18292faa89
commit 0000f2f720

View File

@ -575,7 +575,6 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info
int err; int err;
int state = 0; int state = 0;
struct block_device *bdev = be->blkif->vbd.bdev; struct block_device *bdev = be->blkif->vbd.bdev;
struct request_queue *q = bdev_get_queue(bdev);
if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1)) if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1))
return; return;
@ -583,14 +582,14 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info
if (bdev_max_discard_sectors(bdev)) { if (bdev_max_discard_sectors(bdev)) {
err = xenbus_printf(xbt, dev->nodename, err = xenbus_printf(xbt, dev->nodename,
"discard-granularity", "%u", "discard-granularity", "%u",
q->limits.discard_granularity); bdev_discard_granularity(bdev));
if (err) { if (err) {
dev_warn(&dev->dev, "writing discard-granularity (%d)", err); dev_warn(&dev->dev, "writing discard-granularity (%d)", err);
return; return;
} }
err = xenbus_printf(xbt, dev->nodename, err = xenbus_printf(xbt, dev->nodename,
"discard-alignment", "%u", "discard-alignment", "%u",
q->limits.discard_alignment); bdev_discard_alignment(bdev));
if (err) { if (err) {
dev_warn(&dev->dev, "writing discard-alignment (%d)", err); dev_warn(&dev->dev, "writing discard-alignment (%d)", err);
return; return;