diff mbox

[v2] Don't allow multiwrites against a block device without underlying medium

Message ID 20110307160104.GW23238@us.ibm.com
State New
Headers show

Commit Message

Ryan Harper March 7, 2011, 4:01 p.m. UTC
If the block device has been closed, we no longer have a medium to submit
IO against, check for this before submitting io.  This prevents a segfault
further in the code where we dereference elements of the block driver.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
---
v1->v2:
    - move bs->drv check to top of function to match other bdrv_
    functions
    - fill out reqs response with error code before
      returning -1.

 block.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

Comments

Stefan Hajnoczi March 7, 2011, 4:26 p.m. UTC | #1
On Mon, Mar 7, 2011 at 4:01 PM, Ryan Harper <ryanh@us.ibm.com> wrote:
> If the block device has been closed, we no longer have a medium to submit
> IO against, check for this before submitting io.  This prevents a segfault
> further in the code where we dereference elements of the block driver.
>
> Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
> ---
> v1->v2:
>    - move bs->drv check to top of function to match other bdrv_
>    functions
>    - fill out reqs response with error code before
>      returning -1.
>
>  block.c |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Stefan Hajnoczi March 7, 2011, 4:27 p.m. UTC | #2
I meant:
Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Kevin Wolf March 8, 2011, 3:06 p.m. UTC | #3
Am 07.03.2011 17:01, schrieb Ryan Harper:
> If the block device has been closed, we no longer have a medium to submit
> IO against, check for this before submitting io.  This prevents a segfault
> further in the code where we dereference elements of the block driver.
> 
> Signed-off-by: Ryan Harper <ryanh@us.ibm.com>

Thanks, applied to the block branch.

Kevin
Markus Armbruster March 30, 2011, 7:34 a.m. UTC | #4
I think this (commit 301db7c2) should be cherry-picked into stable-0.14.

Ryan Harper <ryanh@us.ibm.com> writes:

> If the block device has been closed, we no longer have a medium to submit
> IO against, check for this before submitting io.  This prevents a segfault
> further in the code where we dereference elements of the block driver.
>
> Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
diff mbox

Patch

diff --git a/block.c b/block.c
index f7d91a2..1544d81 100644
--- a/block.c
+++ b/block.c
@@ -2398,6 +2398,14 @@  int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs, int num_reqs)
     MultiwriteCB *mcb;
     int i;
 
+    /* don't submit writes if we don't have a medium */
+    if (bs->drv == NULL) {
+        for (i = 0; i < num_reqs; i++) {
+            reqs[i].error = -ENOMEDIUM;
+        }
+        return -1;
+    }
+
     if (num_reqs == 0) {
         return 0;
     }