Skip to contentSkip to conversation

xen-blkfront: remove type check from blkfront_setup_discard

PATCH Superseded Olaf Hering 4 participants 23 messages Jan 10, 2014 – Jan 23, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen-blkfront: remove type check from blkfront_setup_discard

In its initial implementation a check for "type" was added, but only phy and file are handled. This breaks advertised discard support for other type values such as qdisk.

Fix and simplify this function: If the backend advertises discard support it is supposed to implement it properly, so enable feature_discard unconditionally. If the backend advertises the need for a certain granularity and alignment then propagate both properties to the blocklayer. The discard-secure property is a boolean, update the code to reflect that.

---
 drivers/block/xen-blkfront.c | 40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)
drivers/block/xen-blkfront.c +14 -26
index c4a4c90..c9e96b9 100644
@@ -1635,36 +1635,24 @@ blkfront_closing(struct blkfront_info *info)
 static void blkfront_setup_discard(struct blkfront_info *info)
 {
 	int err;
-	char *type;
 	unsigned int discard_granularity;
 	unsigned int discard_alignment;
 	unsigned int discard_secure;
 
-	type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL);
-	if (IS_ERR(type))
-		return;
-
-	info->feature_secdiscard = 0;
-	if (strncmp(type, "phy", 3) == 0) {
-		err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
-			"discard-granularity", "%u", &discard_granularity,
-			"discard-alignment", "%u", &discard_alignment,
-			NULL);
-		if (!err) {
-			info->feature_discard = 1;
-			info->discard_granularity = discard_granularity;
-			info->discard_alignment = discard_alignment;
-		}
-		err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
-			    "discard-secure", "%d", &discard_secure,
-			    NULL);
-		if (!err)
-			info->feature_secdiscard = discard_secure;
-
-	} else if (strncmp(type, "file", 4) == 0)
-		info->feature_discard = 1;
-
-	kfree(type);
+	info->feature_discard = 1;
+	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+		"discard-granularity", "%u", &discard_granularity,
+		"discard-alignment", "%u", &discard_alignment,
+		NULL);
+	if (!err) {
+		info->discard_granularity = discard_granularity;
+		info->discard_alignment = discard_alignment;
+	}
+	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+		    "discard-secure", "%d", &discard_secure,
+		    NULL);
+	if (!err)
+		info->feature_secdiscard = !!discard_secure;
 }
 
 static int blkfront_setup_indirect(struct blkfront_info *info)
#1 lore raw
Quoted 45 lines · Olaf Hering

In its initial implementation a check for "type" was added, but only phy and file are handled. This breaks advertised discard support for other type values such as qdisk.

Fix and simplify this function: If the backend advertises discard support it is supposed to implement it properly, so enable feature_discard unconditionally. If the backend advertises the need for a certain granularity and alignment then propagate both properties to the blocklayer. The discard-secure property is a boolean, update the code to reflect that.

---
  drivers/block/xen-blkfront.c | 40 ++++++++++++++--------------------------
  1 file changed, 14 insertions(+), 26 deletions(-)
drivers/block/xen-blkfront.c +0 -17
index c4a4c90..c9e96b9 100644
@@ -1635,36 +1635,24 @@ blkfront_closing(struct blkfront_info *info)
  static void blkfront_setup_discard(struct blkfront_info *info)
  {
  	int err;
-	char *type;
  	unsigned int discard_granularity;
  	unsigned int discard_alignment;
  	unsigned int discard_secure;
 
-	type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL);
-	if (IS_ERR(type))
-		return;
-
-	info->feature_secdiscard = 0;
-	if (strncmp(type, "phy", 3) == 0) {
-		err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
-			"discard-granularity", "%u", &discard_granularity,
-			"discard-alignment", "%u", &discard_alignment,
-			NULL);
-		if (!err) {
-			info->feature_discard = 1;
-			info->discard_granularity = discard_granularity;
-			info->discard_alignment = discard_alignment;
-		}
-		err = xenbus_gather(XBT_NIL, info->xbdev->otherend,

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

Quoted 10 lines
drivers/block/xen-blkfront.c +1 -9
-			    "discard-secure", "%d", &discard_secure,
-			    NULL);
-		if (!err)
-			info->feature_secdiscard = discard_secure;
-
-	} else if (strncmp(type, "file", 4) == 0)
-		info->feature_discard = 1;
-
-	kfree(type);
+	info->feature_discard = 1;

If the call below fails, is it safe to continue using discard feature? At the least, are discard_granularity and discard_alignment guaranteed to have sane/safe values?

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

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

Quoted 10 lines
drivers/block/xen-blkfront.c +9 -0
+	if (!err) {
+		info->discard_granularity = discard_granularity;
+		info->discard_alignment = discard_alignment;
+	}
+	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+		    "discard-secure", "%d", &discard_secure,
+		    NULL);
+	if (!err)
+		info->feature_secdiscard = !!discard_secure;
  }

err variable is not really necessary so you can drop it.

-boris

Quoted 2 lines
drivers/block/xen-blkfront.c +0 -0
  static int blkfront_setup_indirect(struct blkfront_info *info)
#2 lore raw
Quoted 3 lines · Boris Ostrovsky

If the call below fails, is it safe to continue using discard feature? At the least, are discard_granularity and discard_alignment guaranteed to have sane/safe values?

Its up to the toolstack to provide sane values. In the worst case discard fails. In this specific case the three values are optional, so the calls can fail. I do not know what happens if the backend device actually needs the values, but the frontend can not send proper discard requests. Hopefully it will not damage the hardware..

Olaf

#3 lore raw
In reply to Boris Ostrovsky
Quoted 3 lines · Boris Ostrovsky

If the call below fails, is it safe to continue using discard feature? At the least, are discard_granularity and discard_alignment guaranteed to have sane/safe values?

Its up to the toolstack to provide sane values. In the worst case discard fails. In this specific case the three values are optional, so the calls can fail. I do not know what happens if the backend device actually needs the values, but the frontend can not send proper discard requests. Hopefully it will not damage the hardware..

Olaf

#4 lore raw
Quoted 10 lines · Olaf Hering
Quoted 3 lines · Boris Ostrovsky

If the call below fails, is it safe to continue using discard feature? At the least, are discard_granularity and discard_alignment guaranteed to have sane/safe values?

Its up to the toolstack to provide sane values. In the worst case discard fails. In this specific case the three values are optional, so the calls can fail. I do not know what happens if the backend device actually needs the values, but the frontend can not send proper discard requests. Hopefully it will not damage the hardware..

I don't know discard code works but it seems to me that if you pass, for example, zero as discard_granularity (which may happen if xenbus_gather() fails) then blkdev_issue_discard() in the backend will set granularity to 1 and continue with discard. This may not be what the the guest admin requested. And he won't know about this since no error message is printed anywhere.

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

I think we should at clear feature_discard and print an error in the log if *either* of xenbus_gather() calls fail.

-boris

#5 lore raw
Quoted 2 lines · Boris Ostrovsky

I think we should at clear feature_discard and print an error in the log if *either* of xenbus_gather() calls fail.

Are you sure about that? AFAIK many other properties are optional as well. I dont think there is a formal spec about the discard related properties. Should every backend be required to provide all four properties?

Olaf

#6 lore raw
In reply to Boris Ostrovsky
Quoted 2 lines · Boris Ostrovsky

I think we should at clear feature_discard and print an error in the log if *either* of xenbus_gather() calls fail.

Are you sure about that? AFAIK many other properties are optional as well. I dont think there is a formal spec about the discard related properties. Should every backend be required to provide all four properties?

Olaf

#7 lore raw
Quoted 8 lines · Olaf Hering
Quoted 2 lines · Boris Ostrovsky

I think we should at clear feature_discard and print an error in the log if *either* of xenbus_gather() calls fail.

Are you sure about that? AFAIK many other properties are optional as well. I dont think there is a formal spec about the discard related properties. Should every backend be required to provide all four properties?

It's not whether the properties are required or not. It's that they may have been set by the admin but we ignored them. I am particularly concerned about security setting.

Can you determine from the error whether the call failed or the property wasn't available?

Alternatively, we may have to require the toolstack that if feature-discard is provided then all three of these are provided as well. And then you disable discard on any error.

-boris

#8 lore raw
In reply to Olaf Hering
Quoted 8 lines · Olaf Hering
Quoted 2 lines · Boris Ostrovsky

I think we should at clear feature_discard and print an error in the log if *either* of xenbus_gather() calls fail.

Are you sure about that? AFAIK many other properties are optional as well. I dont think there is a formal spec about the discard related properties. Should every backend be required to provide all four properties?

It's not whether the properties are required or not. It's that they may have been set by the admin but we ignored them. I am particularly concerned about security setting.

Can you determine from the error whether the call failed or the property wasn't available?

Alternatively, we may have to require the toolstack that if feature-discard is provided then all three of these are provided as well. And then you disable discard on any error.

-boris

#9 lore raw
In reply to Boris Ostrovsky
Quoted 6 lines · Boris Ostrovsky

I don't know discard code works but it seems to me that if you pass, for example, zero as discard_granularity (which may happen if xenbus_gather() fails) then blkdev_issue_discard() in the backend will set granularity to 1 and continue with discard. This may not be what the the guest admin requested. And he won't know about this since no error message is printed anywhere.

If I understand the code using granularity/alignment correctly, both are optional properties. So if the granularity is just 1 it means byte ranges, which is fine if the backend uses FALLOC_FL_PUNCH_HOLE. Also both properties are not admin controlled, for phy the blkbk drivers just passes on what it gets from the underlying hardware.

Quoted 3 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

There are no security implications, if the backend does not advertise it then its not present.

After poking around some more it seems that blkif.h is the spec, it does not say anything that the three properties are optional. Also the backend drivers in sles11sp2 and mainline create all three properties unconditionally. So I think a better change is to expect all three properties in the frontend. I will send another version of the patch.

Olaf

#10 lore raw
In reply to Boris Ostrovsky
Quoted 6 lines · Boris Ostrovsky

I don't know discard code works but it seems to me that if you pass, for example, zero as discard_granularity (which may happen if xenbus_gather() fails) then blkdev_issue_discard() in the backend will set granularity to 1 and continue with discard. This may not be what the the guest admin requested. And he won't know about this since no error message is printed anywhere.

If I understand the code using granularity/alignment correctly, both are optional properties. So if the granularity is just 1 it means byte ranges, which is fine if the backend uses FALLOC_FL_PUNCH_HOLE. Also both properties are not admin controlled, for phy the blkbk drivers just passes on what it gets from the underlying hardware.

Quoted 3 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

There are no security implications, if the backend does not advertise it then its not present.

After poking around some more it seems that blkif.h is the spec, it does not say anything that the three properties are optional. Also the backend drivers in sles11sp2 and mainline create all three properties unconditionally. So I think a better change is to expect all three properties in the frontend. I will send another version of the patch.

Olaf

#11 lore raw
Quoted 14 lines · Olaf Hering
Quoted 6 lines · Boris Ostrovsky

I don't know discard code works but it seems to me that if you pass, for example, zero as discard_granularity (which may happen if xenbus_gather() fails) then blkdev_issue_discard() in the backend will set granularity to 1 and continue with discard. This may not be what the the guest admin requested. And he won't know about this since no error message is printed anywhere.

If I understand the code using granularity/alignment correctly, both are optional properties. So if the granularity is just 1 it means byte ranges, which is fine if the backend uses FALLOC_FL_PUNCH_HOLE. Also both properties are not admin controlled, for phy the blkbk drivers just passes on what it gets from the underlying hardware.

Quoted 5 lines
Quoted 3 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

There are no security implications, if the backend does not advertise it then its not present.

Right. But my questions was what if the backend does advertise it and wants the frontent to use it but xenbus_gather() in the frontend fails. Do we want to silently continue without discard-secure? Is this safe?

-boris

Quoted 9 lines

After poking around some more it seems that blkif.h is the spec, it does not say anything that the three properties are optional. Also the backend drivers in sles11sp2 and mainline create all three properties unconditionally. So I think a better change is to expect all three properties in the frontend. I will send another version of the patch.

Olaf

#12 lore raw
Quoted 25 lines · Boris Ostrovsky
Quoted 3 lines · Olaf Hering
Quoted 1 line · Boris Ostrovsky

I don't know discard code works but it seems to me that if you pass,

for

Quoted 1 line
Quoted 1 line

example, zero as discard_granularity (which may happen if

xenbus_gather()

Quoted 1 line
Quoted 1 line

fails) then blkdev_issue_discard() in the backend will set

granularity to 1

Quoted 2 lines
Quoted 2 lines

and continue with discard. This may not be what the the guest admin requested. And he won't know about this since no error message is

printed

Quoted 2 lines
Quoted 1 line

anywhere.

If I understand the code using granularity/alignment correctly, both

are

Quoted 3 lines

optional properties. So if the granularity is just 1 it means byte ranges, which is fine if the backend uses FALLOC_FL_PUNCH_HOLE. Also both properties are not admin controlled, for phy the blkbk drivers

just

Quoted 3 lines

passes on what it gets from the underlying hardware.

Quoted 1 line

Similarly, if xenbug_gather("discard-secure") fails, I think the

code will

Quoted 2 lines
Quoted 2 lines

assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

Quoted 9 lines
Quoted 1 line

There are no security implications, if the backend does not advertise

it

Quoted 1 line

then its not present.

Right. But my questions was what if the backend does advertise it and wants the frontent to use it but xenbus_gather() in the frontend fails.

Do we want to silently continue without discard-secure? Is this safe?

Yes

Quoted 13 lines

-boris

Quoted 2 lines

After poking around some more it seems that blkif.h is the spec, it

does

Quoted 7 lines

not say anything that the three properties are optional. Also the backend drivers in sles11sp2 and mainline create all three properties unconditionally. So I think a better change is to expect all three properties in the frontend. I will send another version of the patch.

Olaf

#13 lore raw
In reply to Boris Ostrovsky
Quoted 10 lines · Boris Ostrovsky
Quoted 5 lines · Olaf Hering
Quoted 3 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

There are no security implications, if the backend does not advertise it then its not present.

Right. But my questions was what if the backend does advertise it and wants the frontent to use it but xenbus_gather() in the frontend fails. Do we want to silently continue without discard-secure? Is this safe?

The frontend can not know that the backend advertised discard-secure because the frontend just failed to read the property which indicates discard-secure should be enabled.

Olaf

#14 lore raw
In reply to Boris Ostrovsky
Quoted 10 lines · Boris Ostrovsky
Quoted 5 lines · Olaf Hering
Quoted 3 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

There are no security implications, if the backend does not advertise it then its not present.

Right. But my questions was what if the backend does advertise it and wants the frontent to use it but xenbus_gather() in the frontend fails. Do we want to silently continue without discard-secure? Is this safe?

The frontend can not know that the backend advertised discard-secure because the frontend just failed to read the property which indicates discard-secure should be enabled.

Olaf

#15 lore raw
Quoted 6 lines · Olaf Hering
Quoted 4 lines · Boris Ostrovsky
Quoted 3 lines · Olaf Hering
Quoted 3 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

There are no security implications, if the backend does not advertise it then its not present.

Right. But my questions was what if the backend does advertise it and wants the frontent to use it but xenbus_gather() in the frontend fails. Do we want to silently continue without discard-secure? Is this safe?

The frontend can not know that the backend advertised discard-secure because the frontend just failed to read the property which indicates discard-secure should be enabled.

And is it OK for the frontend not to know about this?

I don't understand what the use model for this feature is. Is it just that the backend advertises its capability and it's up to the frontend to use it or not -or- is it that the user/admin created the storage with expectations that it will be used in "secure" manner.

I think if it's the former then losing information about storage features is OK but if it's the latter then I am not so sure.

Or perhaps it's neither of these two and I am completely missing the point of this feature.

-boris

#16 lore raw
Quoted 16 lines · Boris Ostrovsky
Quoted 15 lines · Olaf Hering
Quoted 13 lines · Boris Ostrovsky
Quoted 7 lines · Olaf Hering
Quoted 4 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will
assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

There are no security implications, if the backend does not advertise it
then its not present.

Right. But my questions was what if the backend does advertise it and wants
the frontent to use it but xenbus_gather() in the frontend fails. Do we want
to silently continue without discard-secure? Is this safe?

Quoted 5 lines
Quoted 3 lines

The frontend can not know that the backend advertised discard-secure because the frontend just failed to read the property which indicates discard-secure should be enabled.

And is it OK for the frontend not to know about this?

Yes.

Quoted 4 lines

I don't understand what the use model for this feature is. Is it just that the backend advertises its capability and it's up to the frontend to use it or not -or- is it that the user/admin created the storage with expectations that it will be used in "secure" manner.

The creator of the data (i.e., the guest) is the one who knows whether the data is security sensitive. The backend is simply providing the facility which the guest may or may not make use of.

David

#17 lore raw
In reply to Boris Ostrovsky
Quoted 16 lines · Boris Ostrovsky
Quoted 15 lines · Olaf Hering
Quoted 13 lines · Boris Ostrovsky
Quoted 7 lines · Olaf Hering
Quoted 4 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will
assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

There are no security implications, if the backend does not advertise it
then its not present.

Right. But my questions was what if the backend does advertise it and wants
the frontent to use it but xenbus_gather() in the frontend fails. Do we want
to silently continue without discard-secure? Is this safe?

Quoted 5 lines
Quoted 3 lines

The frontend can not know that the backend advertised discard-secure because the frontend just failed to read the property which indicates discard-secure should be enabled.

And is it OK for the frontend not to know about this?

Yes.

Quoted 4 lines

I don't understand what the use model for this feature is. Is it just that the backend advertises its capability and it's up to the frontend to use it or not -or- is it that the user/admin created the storage with expectations that it will be used in "secure" manner.

The creator of the data (i.e., the guest) is the one who knows whether the data is security sensitive. The backend is simply providing the facility which the guest may or may not make use of.

David

#18 lore raw
In reply to Olaf Hering
Quoted 6 lines · Olaf Hering
Quoted 4 lines · Boris Ostrovsky
Quoted 3 lines · Olaf Hering
Quoted 3 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

There are no security implications, if the backend does not advertise it then its not present.

Right. But my questions was what if the backend does advertise it and wants the frontent to use it but xenbus_gather() in the frontend fails. Do we want to silently continue without discard-secure? Is this safe?

The frontend can not know that the backend advertised discard-secure because the frontend just failed to read the property which indicates discard-secure should be enabled.

And is it OK for the frontend not to know about this?

I don't understand what the use model for this feature is. Is it just that the backend advertises its capability and it's up to the frontend to use it or not -or- is it that the user/admin created the storage with expectations that it will be used in "secure" manner.

I think if it's the former then losing information about storage features is OK but if it's the latter then I am not so sure.

Or perhaps it's neither of these two and I am completely missing the point of this feature.

-boris

#19 lore raw
In reply to Boris Ostrovsky
Quoted 25 lines · Boris Ostrovsky
Quoted 3 lines · Olaf Hering
Quoted 1 line · Boris Ostrovsky

I don't know discard code works but it seems to me that if you pass,

for

Quoted 1 line
Quoted 1 line

example, zero as discard_granularity (which may happen if

xenbus_gather()

Quoted 1 line
Quoted 1 line

fails) then blkdev_issue_discard() in the backend will set

granularity to 1

Quoted 2 lines
Quoted 2 lines

and continue with discard. This may not be what the the guest admin requested. And he won't know about this since no error message is

printed

Quoted 2 lines
Quoted 1 line

anywhere.

If I understand the code using granularity/alignment correctly, both

are

Quoted 3 lines

optional properties. So if the granularity is just 1 it means byte ranges, which is fine if the backend uses FALLOC_FL_PUNCH_HOLE. Also both properties are not admin controlled, for phy the blkbk drivers

just

Quoted 3 lines

passes on what it gets from the underlying hardware.

Quoted 1 line

Similarly, if xenbug_gather("discard-secure") fails, I think the

code will

Quoted 2 lines
Quoted 2 lines

assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

Quoted 9 lines
Quoted 1 line

There are no security implications, if the backend does not advertise

it

Quoted 1 line

then its not present.

Right. But my questions was what if the backend does advertise it and wants the frontent to use it but xenbus_gather() in the frontend fails.

Do we want to silently continue without discard-secure? Is this safe?

Yes

Quoted 13 lines

-boris

Quoted 2 lines

After poking around some more it seems that blkif.h is the spec, it

does

Quoted 7 lines

not say anything that the three properties are optional. Also the backend drivers in sles11sp2 and mainline create all three properties unconditionally. So I think a better change is to expect all three properties in the frontend. I will send another version of the patch.

Olaf

#20 lore raw
In reply to Olaf Hering
Quoted 14 lines · Olaf Hering
Quoted 6 lines · Boris Ostrovsky

I don't know discard code works but it seems to me that if you pass, for example, zero as discard_granularity (which may happen if xenbus_gather() fails) then blkdev_issue_discard() in the backend will set granularity to 1 and continue with discard. This may not be what the the guest admin requested. And he won't know about this since no error message is printed anywhere.

If I understand the code using granularity/alignment correctly, both are optional properties. So if the granularity is just 1 it means byte ranges, which is fine if the backend uses FALLOC_FL_PUNCH_HOLE. Also both properties are not admin controlled, for phy the blkbk drivers just passes on what it gets from the underlying hardware.

Quoted 5 lines
Quoted 3 lines

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

There are no security implications, if the backend does not advertise it then its not present.

Right. But my questions was what if the backend does advertise it and wants the frontent to use it but xenbus_gather() in the frontend fails. Do we want to silently continue without discard-secure? Is this safe?

-boris

Quoted 9 lines

After poking around some more it seems that blkif.h is the spec, it does not say anything that the three properties are optional. Also the backend drivers in sles11sp2 and mainline create all three properties unconditionally. So I think a better change is to expect all three properties in the frontend. I will send another version of the patch.

Olaf

#21 lore raw
In reply to Olaf Hering
Quoted 10 lines · Olaf Hering
Quoted 3 lines · Boris Ostrovsky

If the call below fails, is it safe to continue using discard feature? At the least, are discard_granularity and discard_alignment guaranteed to have sane/safe values?

Its up to the toolstack to provide sane values. In the worst case discard fails. In this specific case the three values are optional, so the calls can fail. I do not know what happens if the backend device actually needs the values, but the frontend can not send proper discard requests. Hopefully it will not damage the hardware..

I don't know discard code works but it seems to me that if you pass, for example, zero as discard_granularity (which may happen if xenbus_gather() fails) then blkdev_issue_discard() in the backend will set granularity to 1 and continue with discard. This may not be what the the guest admin requested. And he won't know about this since no error message is printed anywhere.

Similarly, if xenbug_gather("discard-secure") fails, I think the code will assume that secure discard has not been requested. I don't know what security implications this will have but it sounds bad to me.

I think we should at clear feature_discard and print an error in the log if *either* of xenbus_gather() calls fail.

-boris

#22 lore raw
In reply to Olaf Hering
Quoted 45 lines · Olaf Hering

In its initial implementation a check for "type" was added, but only phy and file are handled. This breaks advertised discard support for other type values such as qdisk.

Fix and simplify this function: If the backend advertises discard support it is supposed to implement it properly, so enable feature_discard unconditionally. If the backend advertises the need for a certain granularity and alignment then propagate both properties to the blocklayer. The discard-secure property is a boolean, update the code to reflect that.

---
  drivers/block/xen-blkfront.c | 40 ++++++++++++++--------------------------
  1 file changed, 14 insertions(+), 26 deletions(-)
drivers/block/xen-blkfront.c +0 -17
index c4a4c90..c9e96b9 100644
@@ -1635,36 +1635,24 @@ blkfront_closing(struct blkfront_info *info)
  static void blkfront_setup_discard(struct blkfront_info *info)
  {
  	int err;
-	char *type;
  	unsigned int discard_granularity;
  	unsigned int discard_alignment;
  	unsigned int discard_secure;
 
-	type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL);
-	if (IS_ERR(type))
-		return;
-
-	info->feature_secdiscard = 0;
-	if (strncmp(type, "phy", 3) == 0) {
-		err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
-			"discard-granularity", "%u", &discard_granularity,
-			"discard-alignment", "%u", &discard_alignment,
-			NULL);
-		if (!err) {
-			info->feature_discard = 1;
-			info->discard_granularity = discard_granularity;
-			info->discard_alignment = discard_alignment;
-		}
-		err = xenbus_gather(XBT_NIL, info->xbdev->otherend,

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

Quoted 10 lines
drivers/block/xen-blkfront.c +1 -9
-			    "discard-secure", "%d", &discard_secure,
-			    NULL);
-		if (!err)
-			info->feature_secdiscard = discard_secure;
-
-	} else if (strncmp(type, "file", 4) == 0)
-		info->feature_discard = 1;
-
-	kfree(type);
+	info->feature_discard = 1;

If the call below fails, is it safe to continue using discard feature? At the least, are discard_granularity and discard_alignment guaranteed to have sane/safe values?

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

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

Quoted 10 lines
drivers/block/xen-blkfront.c +9 -0
+	if (!err) {
+		info->discard_granularity = discard_granularity;
+		info->discard_alignment = discard_alignment;
+	}
+	err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
+		    "discard-secure", "%d", &discard_secure,
+		    NULL);
+	if (!err)
+		info->feature_secdiscard = !!discard_secure;
  }

err variable is not really necessary so you can drop it.

-boris

Quoted 2 lines
drivers/block/xen-blkfront.c +0 -0
  static int blkfront_setup_indirect(struct blkfront_info *info)