Skip to content

Commit 7d6e01e

Browse files
roygergregkh
authored andcommitted
xen-blkfront: allow discard-* nodes to be optional
commit 0549cd6 upstream. This is inline with the specification described in blkif.h: * discard-granularity: should be set to the physical block size if node is not present. * discard-alignment, discard-secure: should be set to 0 if node not present. This was detected as QEMU would only create the discard-granularity node but not discard-alignment, and thus the setup done in blkfront_setup_discard would fail. Fix blkfront_setup_discard to not fail on missing nodes, and also fix blkif_set_queue_limits to set the discard granularity to the physical block size if none is specified in xenbus. Fixes: ed30bf3 ('xen-blkfront: Handle discard requests.') Reported-by: Arthur Borsboom <arthurborsboom@gmail.com> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com> Reviewed-by: Juergen Gross <jgross@suse.com> Tested-By: Arthur Borsboom <arthurborsboom@gmail.com> Link: https://lore.kernel.org/r/20210119105727.95173-1-roger.pau@citrix.com Signed-off-by: Juergen Gross <jgross@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a164789 commit 7d6e01e

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

‎drivers/block/xen-blkfront.c‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,8 @@ static void blkif_set_queue_limits(struct blkfront_info *info)
945945
if (info->feature_discard) {
946946
blk_queue_flag_set(QUEUE_FLAG_DISCARD, rq);
947947
blk_queue_max_discard_sectors(rq, get_capacity(gd));
948-
rq->limits.discard_granularity = info->discard_granularity;
948+
rq->limits.discard_granularity = info->discard_granularity ?:
949+
info->physical_sector_size;
949950
rq->limits.discard_alignment = info->discard_alignment;
950951
if (info->feature_secdiscard)
951952
blk_queue_flag_set(QUEUE_FLAG_SECERASE, rq);
@@ -2179,19 +2180,12 @@ static void blkfront_closing(struct blkfront_info *info)
21792180

21802181
static void blkfront_setup_discard(struct blkfront_info *info)
21812182
{
2182-
int err;
2183-
unsigned int discard_granularity;
2184-
unsigned int discard_alignment;
2185-
21862183
info->feature_discard = 1;
2187-
err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
2188-
"discard-granularity", "%u", &discard_granularity,
2189-
"discard-alignment", "%u", &discard_alignment,
2190-
NULL);
2191-
if (!err) {
2192-
info->discard_granularity = discard_granularity;
2193-
info->discard_alignment = discard_alignment;
2194-
}
2184+
info->discard_granularity = xenbus_read_unsigned(info->xbdev->otherend,
2185+
"discard-granularity",
2186+
0);
2187+
info->discard_alignment = xenbus_read_unsigned(info->xbdev->otherend,
2188+
"discard-alignment", 0);
21952189
info->feature_secdiscard =
21962190
!!xenbus_read_unsigned(info->xbdev->otherend, "discard-secure",
21972191
0);

0 commit comments

Comments
 (0)