Skip to contentSkip to conversation

xen_disk: cope with missing xenstore "params" node

PATCH Superseded [email protected] 4 participants 10 messages Jun 24, 2011 – Jun 30, 2011

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen_disk: cope with missing xenstore "params" node

From: Stefano Stabellini <[email protected]>

When disk is a cdrom and the drive is empty the "params" node in xenstore might be missing completely: cope with it instead of segfaulting.

---
 hw/xen_disk.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
hw/xen_disk.c +11 -5
index 096d1c9..801da58 100644
@@ -616,11 +616,13 @@ static int blk_init(struct XenDevice *xendev)
 {
     struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
     int index, qflags, have_barriers, info = 0;
-    char *h;
+    char *h = NULL;
 
     /* read xenstore entries */
     if (blkdev->params == NULL) {
         blkdev->params = xenstore_read_be_str(&blkdev->xendev, "params");
+        if (blkdev->params != NULL)
+            h = strchr(blkdev->params, ':');
         h = strchr(blkdev->params, ':');
         if (h != NULL) {
             blkdev->fileproto = blkdev->params;
@@ -672,11 +674,15 @@ static int blk_init(struct XenDevice *xendev)
         /* setup via xenbus -> create new block driver instance */
         xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
         blkdev->bs = bdrv_new(blkdev->dev);
-        if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
-                      bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
-            bdrv_delete(blkdev->bs);
-            return -1;
+        if (blkdev->bs) {
+            if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
+                        bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
+                bdrv_delete(blkdev->bs);
+                blkdev->bs = NULL;
+            }
         }
+        if (!blkdev->bs)
+            return -1;
     } else {
         /* setup via qemu cmdline -> already setup for us */
         xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/1 xen_disk: treat "aio" as "raw"

From: Stefano Stabellini <[email protected]>

Sometimes the toolstack uses "aio" without an additional format identifier, in such cases use "raw".

---
 hw/xen_disk.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/xen_disk.c +2 -0
index 801da58..745127d 100644
@@ -633,6 +633,8 @@ static int blk_init(struct XenDevice *xendev)
             blkdev->filename  = blkdev->params;
         }
     }
+    if (!strcmp("aio", blkdev->fileproto))
+        blkdev->fileproto = "raw";
     if (blkdev->mode == NULL) {
         blkdev->mode = xenstore_read_be_str(&blkdev->xendev, "mode");
     }
Signature · 1 line
1.7.2.3
#2 lore raw

Re: [Qemu-devel] [PATCH] xen_disk: treat "aio" as "raw"

Quoted 4 lines · On 06/24/2011 04:50 PM, [email protected] wrote:

From: Stefano Stabellini<[email protected]>

Sometimes the toolstack uses "aio" without an additional format identifier, in such cases use "raw".

Shouldn't this rather be a patch to the toolstack then? We do automatic file format recognition as default. I find magical "aio equals raw" subtleties rather unintuitive.

Quoted 10 lines
---
  hw/xen_disk.c |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)
hw/xen_disk.c +0 -0
index 801da58..745127d 100644

hw/xen_disk.c static int blk_init(struct XenDevice *xendev) · line 637

Quoted 5 lines
hw/xen_disk.c +2 -0
@@ -633,6 +633,8 @@ static int blk_init(struct XenDevice *xendev)
              blkdev->filename  = blkdev->params;
          }
      }
+    if (!strcmp("aio", blkdev->fileproto))
+        blkdev->fileproto = "raw";

Braces

hw/xen_disk.c static int blk_init(struct XenDevice *xendev) · line 640

Quoted 3 lines
hw/xen_disk.c +0 -0
      if (blkdev->mode == NULL) {
          blkdev->mode = xenstore_read_be_str(&blkdev->xendev, "mode");
      }

Alex

#3 lore raw

Re: [Qemu-devel] [PATCH] xen_disk: treat "aio" as "raw"

Am 30.06.2011 13:47, schrieb Alexander Graf:

Quoted 9 lines · On 06/24/2011 04:50 PM, [email protected] wrote:
Quoted 4 lines

From: Stefano Stabellini<[email protected]>

Sometimes the toolstack uses "aio" without an additional format identifier, in such cases use "raw".

Shouldn't this rather be a patch to the toolstack then? We do automatic file format recognition as default. I find magical "aio equals raw" subtleties rather unintuitive.

The asynchronous raw blktap driver is (was?) called "aio", so I guess it's to stay compatible with that. Has always been this way in Xen (and has always been confusing). As long as it stays in xen_disk.c, I don't really mind...

Kevin

#4 lore raw

Re: [Qemu-devel] [PATCH] xen_disk: treat "aio" as "raw"

Quoted 6 lines · Kevin Wolf

Am 30.06.2011 13:47, schrieb Alexander Graf:

Quoted 5 lines · On 06/24/2011 04:50 PM, [email protected] wrote:
Quoted 4 lines

From: Stefano Stabellini<[email protected]>

Sometimes the toolstack uses "aio" without an additional format identifier, in such cases use "raw".

Quoted 7 lines
Quoted 3 lines

Shouldn't this rather be a patch to the toolstack then? We do automatic file format recognition as default. I find magical "aio equals raw" subtleties rather unintuitive.

The asynchronous raw blktap driver is (was?) called "aio", so I guess it's to stay compatible with that. Has always been this way in Xen (and has always been confusing). As long as it stays in xen_disk.c, I don't really mind...

Is there a realistic chance of changing the toolstack here? I'd really prefer not to drag this legacy around :).

Alex

#5 lore raw

Re: [Qemu-devel] [PATCH] xen_disk: treat "aio" as "raw"

Quoted 10 lines · Alexander Graf
Quoted 9 lines · Kevin Wolf

Am 30.06.2011 13:47, schrieb Alexander Graf:

Quoted 8 lines · On 06/24/2011 04:50 PM, [email protected] wrote:
Quoted 4 lines

From: Stefano Stabellini<[email protected]>

Sometimes the toolstack uses "aio" without an additional format identifier, in such cases use "raw".

Shouldn't this rather be a patch to the toolstack then? We do automatic file format recognition as default. I find magical "aio equals raw" subtleties rather unintuitive.

Quoted 7 lines
Quoted 4 lines

The asynchronous raw blktap driver is (was?) called "aio", so I guess it's to stay compatible with that. Has always been this way in Xen (and has always been confusing). As long as it stays in xen_disk.c, I don't really mind...

Is there a realistic chance of changing the toolstack here? I'd really prefer not to drag this legacy around :).

We could change the toolstack but it would mean introducing an incompatibility between the qdisk backend and the blktap backend. Considering that qdisk was written to replace blktap in the first place I don't think is such a good idea. Besides all xen toolstacks have always written "aio" for "raw" even before qdisk came along...

#6 lore raw

Re: [Qemu-devel] [PATCH] xen_disk: treat "aio" as "raw"

Quoted 15 lines · Stefano Stabellini
Quoted 14 lines · Alexander Graf
Quoted 13 lines · Kevin Wolf

Am 30.06.2011 13:47, schrieb Alexander Graf:

Quoted 8 lines · On 06/24/2011 04:50 PM, [email protected] wrote:
Quoted 4 lines

From: Stefano Stabellini<[email protected]>

Sometimes the toolstack uses "aio" without an additional format identifier, in such cases use "raw".

Shouldn't this rather be a patch to the toolstack then? We do automatic file format recognition as default. I find magical "aio equals raw" subtleties rather unintuitive.

The asynchronous raw blktap driver is (was?) called "aio", so I guess it's to stay compatible with that. Has always been this way in Xen (and has always been confusing). As long as it stays in xen_disk.c, I don't really mind...

Quoted 7 lines
Quoted 2 lines

Is there a realistic chance of changing the toolstack here? I'd really prefer not to drag this legacy around :).

We could change the toolstack but it would mean introducing an incompatibility between the qdisk backend and the blktap backend. Considering that qdisk was written to replace blktap in the first place I don't think is such a good idea. Besides all xen toolstacks have always written "aio" for "raw" even before qdisk came along...

Hrm. Ok. Please resend with braces then :).

Alex

#7 lore raw

Re: [Qemu-devel] [PATCH] xen_disk: treat "aio" as "raw"

Quoted 18 lines · Alexander Graf
Quoted 17 lines · Stefano Stabellini
Quoted 16 lines · Alexander Graf
Quoted 6 lines · Kevin Wolf

Am 30.06.2011 13:47, schrieb Alexander Graf:

Quoted 5 lines · On 06/24/2011 04:50 PM, [email protected] wrote:
Quoted 4 lines

From: Stefano Stabellini<[email protected]>

Sometimes the toolstack uses "aio" without an additional format identifier, in such cases use "raw".

Quoted 7 lines
Quoted 3 lines

Shouldn't this rather be a patch to the toolstack then? We do automatic file format recognition as default. I find magical "aio equals raw" subtleties rather unintuitive.

The asynchronous raw blktap driver is (was?) called "aio", so I guess it's to stay compatible with that. Has always been this way in Xen (and has always been confusing). As long as it stays in xen_disk.c, I don't really mind...

Is there a realistic chance of changing the toolstack here? I'd really prefer not to drag this legacy around :).

Quoted 7 lines
Quoted 5 lines

We could change the toolstack but it would mean introducing an incompatibility between the qdisk backend and the blktap backend. Considering that qdisk was written to replace blktap in the first place I don't think is such a good idea. Besides all xen toolstacks have always written "aio" for "raw" even before qdisk came along...

Hrm. Ok. Please resend with braces then :).

I'll do :)

#8 lore raw
In reply to [email protected]
Quoted 6 lines · On 24 June 2011 15:50, <[email protected]> wrote:

    /* read xenstore entries */
    if (blkdev->params == NULL) {
        blkdev->params = xenstore_read_be_str(&blkdev->xendev, "params");
+        if (blkdev->params != NULL)
+            h = strchr(blkdev->params, ':');
        h = strchr(blkdev->params, ':');

This adds the if () statement but it looks like you forgot to remove the strchr that is outside the if(), so this will still segfault... (Also, coding style demands braces.)

You could also make that "char *h" local to this 'if' block.

Quoted 7 lines
hw/xen_disk.c +0 -3
@@ -672,11 +674,15 @@ static int blk_init(struct XenDevice *xendev)
         /* setup via xenbus -> create new block driver instance */
         xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
         blkdev->bs = bdrv_new(blkdev->dev);
-        if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
-                      bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
-            bdrv_delete(blkdev->bs);

hw/xen_disk.c static int blk_init(struct XenDevice *xendev) · line 685

Quoted 10 lines
hw/xen_disk.c +8 -1
-            return -1;
+        if (blkdev->bs) {
+            if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
+                        bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
+                bdrv_delete(blkdev->bs);
+                blkdev->bs = NULL;
+            }
         }
+        if (!blkdev->bs)
+            return -1;

Doesn't this error return leak the strings allocated by xenstore_read_be_str() ?

-- PMM

#9 lore raw
Quoted 8 lines · Peter Maydell
Quoted 6 lines · On 24 June 2011 15:50, <[email protected]> wrote:

    /* read xenstore entries */
    if (blkdev->params == NULL) {
        blkdev->params = xenstore_read_be_str(&blkdev->xendev, "params");
+        if (blkdev->params != NULL)
+            h = strchr(blkdev->params, ':');
        h = strchr(blkdev->params, ':');

Quoted 5 lines

This adds the if () statement but it looks like you forgot to remove the strchr that is outside the if(), so this will still segfault... (Also, coding style demands braces.)

You could also make that "char *h" local to this 'if' block.

Thank you very much for the review, I'll make the changes.

Quoted 13 lines
Quoted 13 lines
hw/xen_disk.c +4 -4
@@ -672,11 +674,15 @@ static int blk_init(struct XenDevice *xendev)
         /* setup via xenbus -> create new block driver instance */
         xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
         blkdev->bs = bdrv_new(blkdev->dev);
-        if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
-                      bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
-            bdrv_delete(blkdev->bs);
-            return -1;
+        if (blkdev->bs) {
+            if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
+                        bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
+                bdrv_delete(blkdev->bs);
Quoted 8 lines

hw/xen_disk.c static int blk_init(struct XenDevice *xendev) · line 685

Quoted 5 lines
hw/xen_disk.c +4 -0
+                blkdev->bs = NULL;
+            }
         }
+        if (!blkdev->bs)
+            return -1;

Doesn't this error return leak the strings allocated by xenstore_read_be_str() ?

Another very good point, I'll introduce an out_error label and free everything there.