Skip to contentSkip to conversation

xen-blkfront: don't make discard-alignment mandatory

PATCH In review Roger Pau Monne 2 participants 5 messages Jan 18, 2021 – Jan 19, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen-blkfront: don't make discard-alignment mandatory

Don't require the discard-alignment xenstore node to be present in order to correctly setup the feature. This can happen with versions of QEMU that only write the discard-granularity but not the discard-alignment node.

Assume discard-alignment is 0 if not present. While there also fix the logic to not enable the discard feature if discard-granularity is not present.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Arthur Borsboom <[email protected]>

---
 drivers/block/xen-blkfront.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/block/xen-blkfront.c +13 -12
index 5265975b3fba..5a93f7cc2939 100644
@@ -2179,22 +2179,23 @@ static void blkfront_closing(struct blkfront_info *info)
 
 static void blkfront_setup_discard(struct blkfront_info *info)
 {
-	int err;
-	unsigned int discard_granularity;
-	unsigned int discard_alignment;
+	unsigned int discard_granularity = 0;
+	unsigned int discard_alignment = 0;
+	unsigned int discard_secure = 0;
 
-	info->feature_discard = 1;
-	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+	xenbus_gather(XBT_NIL, info->xbdev->otherend,
 		"discard-granularity", "%u", &discard_granularity,
 		"discard-alignment", "%u", &discard_alignment,
+		"discard-secure", "%u", &discard_secure,
 		NULL);
-	if (!err) {
-		info->discard_granularity = discard_granularity;
-		info->discard_alignment = discard_alignment;
-	}
-	info->feature_secdiscard =
-		!!xenbus_read_unsigned(info->xbdev->otherend, "discard-secure",
-				       0);
+
+	if (!discard_granularity)
+		return;
+
+	info->feature_discard = 1;
+	info->discard_granularity = discard_granularity;
+	info->discard_alignment = discard_alignment;
+	info->feature_secdiscard = !!discard_secure;
 }
 
 static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
Signature · 1 line
2.29.2
maintainer
#1 lore raw
Quoted 37 lines · Roger Pau Monne

Don't require the discard-alignment xenstore node to be present in order to correctly setup the feature. This can happen with versions of QEMU that only write the discard-granularity but not the discard-alignment node.

Assume discard-alignment is 0 if not present. While there also fix the logic to not enable the discard feature if discard-granularity is not present.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Arthur Borsboom <[email protected]>

---
  drivers/block/xen-blkfront.c | 25 +++++++++++++------------
  1 file changed, 13 insertions(+), 12 deletions(-)
drivers/block/xen-blkfront.c +1 -3
index 5265975b3fba..5a93f7cc2939 100644
@@ -2179,22 +2179,23 @@ static void blkfront_closing(struct blkfront_info *info)
 
  static void blkfront_setup_discard(struct blkfront_info *info)
  {
-	int err;
-	unsigned int discard_granularity;
-	unsigned int discard_alignment;
+	unsigned int discard_granularity = 0;

drivers/block/xen-blkfront.c static void blkfront_closing(struct blkfront_info *info) · line 2190

Quoted 10 lines
drivers/block/xen-blkfront.c +4 -2
+	unsigned int discard_alignment = 0;
+	unsigned int discard_secure = 0;
 
-	info->feature_discard = 1;
-	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+	xenbus_gather(XBT_NIL, info->xbdev->otherend,
  		"discard-granularity", "%u", &discard_granularity,
  		"discard-alignment", "%u", &discard_alignment,
+		"discard-secure", "%u", &discard_secure,
  		NULL);

This would mean that "discard-secure" will be evaluated only if the other two items are set in Xenstore. From blkif.h I can't see this is required, and your patch is modifying today's behavior in this regard.

You might want to have three xenbus_read_unsigned() calls instead.

Juergen

#2 lore raw
Quoted 51 lines · Jürgen Groß
Quoted 35 lines · Roger Pau Monne

Don't require the discard-alignment xenstore node to be present in order to correctly setup the feature. This can happen with versions of QEMU that only write the discard-granularity but not the discard-alignment node.

Assume discard-alignment is 0 if not present. While there also fix the logic to not enable the discard feature if discard-granularity is not present.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Arthur Borsboom <[email protected]>

---
  drivers/block/xen-blkfront.c | 25 +++++++++++++------------
  1 file changed, 13 insertions(+), 12 deletions(-)
drivers/block/xen-blkfront.c +0 -3
index 5265975b3fba..5a93f7cc2939 100644
@@ -2179,22 +2179,23 @@ static void blkfront_closing(struct blkfront_info *info)
  static void blkfront_setup_discard(struct blkfront_info *info)
  {
-	int err;
-	unsigned int discard_granularity;
-	unsigned int discard_alignment;

drivers/block/xen-blkfront.c static void blkfront_closing(struct blkfront_info *info) · line 2188

Quoted 10 lines
drivers/block/xen-blkfront.c +5 -2
+	unsigned int discard_granularity = 0;
+	unsigned int discard_alignment = 0;
+	unsigned int discard_secure = 0;
-	info->feature_discard = 1;
-	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+	xenbus_gather(XBT_NIL, info->xbdev->otherend,
  		"discard-granularity", "%u", &discard_granularity,
  		"discard-alignment", "%u", &discard_alignment,
+		"discard-secure", "%u", &discard_secure,
  		NULL);

This would mean that "discard-secure" will be evaluated only if the other two items are set in Xenstore. From blkif.h I can't see this is required, and your patch is modifying today's behavior in this regard.

Quoted 1 line

You might want to have three xenbus_read_unsigned() calls instead.

You are right, discard-secure should be fetched regardless of whether discard-alignment exists.

I can fetch discard-granularity and discard-alignment using xenbus_gather and keep discard-secure using xenbus_read_unsigned. Let me send a new version.

Thanks, Roger.

maintainer
#3 lore raw
Quoted 52 lines · Roger Pau Monné
Quoted 51 lines · Jürgen Groß
Quoted 35 lines · Roger Pau Monne

Don't require the discard-alignment xenstore node to be present in order to correctly setup the feature. This can happen with versions of QEMU that only write the discard-granularity but not the discard-alignment node.

Assume discard-alignment is 0 if not present. While there also fix the logic to not enable the discard feature if discard-granularity is not present.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Arthur Borsboom <[email protected]>

---
   drivers/block/xen-blkfront.c | 25 +++++++++++++------------
   1 file changed, 13 insertions(+), 12 deletions(-)
drivers/block/xen-blkfront.c +0 -3
index 5265975b3fba..5a93f7cc2939 100644
@@ -2179,22 +2179,23 @@ static void blkfront_closing(struct blkfront_info *info)
   static void blkfront_setup_discard(struct blkfront_info *info)
   {
-	int err;
-	unsigned int discard_granularity;
-	unsigned int discard_alignment;

drivers/block/xen-blkfront.c static void blkfront_closing(struct blkfront_info *info) · line 2188

Quoted 10 lines
drivers/block/xen-blkfront.c +5 -2
+	unsigned int discard_granularity = 0;
+	unsigned int discard_alignment = 0;
+	unsigned int discard_secure = 0;
-	info->feature_discard = 1;
-	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+	xenbus_gather(XBT_NIL, info->xbdev->otherend,
   		"discard-granularity", "%u", &discard_granularity,
   		"discard-alignment", "%u", &discard_alignment,
+		"discard-secure", "%u", &discard_secure,
   		NULL);

This would mean that "discard-secure" will be evaluated only if the other two items are set in Xenstore. From blkif.h I can't see this is required, and your patch is modifying today's behavior in this regard.

Quoted 8 lines
Quoted 1 line

You might want to have three xenbus_read_unsigned() calls instead.

You are right, discard-secure should be fetched regardless of whether discard-alignment exists.

I can fetch discard-granularity and discard-alignment using xenbus_gather and keep discard-secure using xenbus_read_unsigned. Let me send a new version.

I'm still not convinced this is correct. blkif.h doesn't mention that discard-alignment will be valid only with discard-granularity being present.

Juergen

#4 lore raw
Quoted 58 lines · Jürgen Groß
Quoted 57 lines · Roger Pau Monné
Quoted 51 lines · Jürgen Groß
Quoted 35 lines · Roger Pau Monne

Don't require the discard-alignment xenstore node to be present in order to correctly setup the feature. This can happen with versions of QEMU that only write the discard-granularity but not the discard-alignment node.

Assume discard-alignment is 0 if not present. While there also fix the logic to not enable the discard feature if discard-granularity is not present.

---
Cc: Boris Ostrovsky <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Arthur Borsboom <[email protected]>

---
   drivers/block/xen-blkfront.c | 25 +++++++++++++------------
   1 file changed, 13 insertions(+), 12 deletions(-)
drivers/block/xen-blkfront.c +0 -3
index 5265975b3fba..5a93f7cc2939 100644
@@ -2179,22 +2179,23 @@ static void blkfront_closing(struct blkfront_info *info)
   static void blkfront_setup_discard(struct blkfront_info *info)
   {
-	int err;
-	unsigned int discard_granularity;
-	unsigned int discard_alignment;

drivers/block/xen-blkfront.c static void blkfront_closing(struct blkfront_info *info) · line 2188

Quoted 10 lines
drivers/block/xen-blkfront.c +5 -2
+	unsigned int discard_granularity = 0;
+	unsigned int discard_alignment = 0;
+	unsigned int discard_secure = 0;
-	info->feature_discard = 1;
-	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+	xenbus_gather(XBT_NIL, info->xbdev->otherend,
   		"discard-granularity", "%u", &discard_granularity,
   		"discard-alignment", "%u", &discard_alignment,
+		"discard-secure", "%u", &discard_secure,
   		NULL);

This would mean that "discard-secure" will be evaluated only if the other two items are set in Xenstore. From blkif.h I can't see this is required, and your patch is modifying today's behavior in this regard.

Quoted 1 line

You might want to have three xenbus_read_unsigned() calls instead.

You are right, discard-secure should be fetched regardless of whether discard-alignment exists.

Quoted 7 lines
Quoted 3 lines

I can fetch discard-granularity and discard-alignment using xenbus_gather and keep discard-secure using xenbus_read_unsigned. Let me send a new version.

I'm still not convinced this is correct. blkif.h doesn't mention that discard-alignment will be valid only with discard-granularity being present.

No, in fact I think I need to rework this a little further. Just having feature-discard = 1 should enable the discard functionality, by setting discard-granularity = physical block size and discard-alignment = 0.

Roger.