All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 20/37] block: Fail requests to empty BlockBackend
Date: Fri, 23 Oct 2015 19:01:07 +0200	[thread overview]
Message-ID: <1445619684-18216-21-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1445619684-18216-1-git-send-email-kwolf@redhat.com>

From: Max Reitz <mreitz@redhat.com>

If there is no BlockDriverState in a BlockBackend or if the tray of the
guest device is open, fail all requests (where that is possible) with
-ENOMEDIUM.

The reason the status of the guest device is taken into account is
because once the guest device's tray is opened, any request on the same
BlockBackend as the guest uses should fail. If the BDS tree is supposed
to be usable even after ejecting it from the guest, a different
BlockBackend must be used.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/block-backend.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index d790870..2779c22 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -529,7 +529,7 @@ static int blk_check_byte_request(BlockBackend *blk, int64_t offset,
         return -EIO;
     }
 
-    if (!blk_is_inserted(blk)) {
+    if (!blk_is_available(blk)) {
         return -ENOMEDIUM;
     }
 
@@ -668,6 +668,10 @@ int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count)
 
 int64_t blk_getlength(BlockBackend *blk)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_getlength(blk->bs);
 }
 
@@ -678,6 +682,10 @@ void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr)
 
 int64_t blk_nb_sectors(BlockBackend *blk)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_nb_sectors(blk->bs);
 }
 
@@ -708,6 +716,10 @@ BlockAIOCB *blk_aio_writev(BlockBackend *blk, int64_t sector_num,
 BlockAIOCB *blk_aio_flush(BlockBackend *blk,
                           BlockCompletionFunc *cb, void *opaque)
 {
+    if (!blk_is_available(blk)) {
+        return abort_aio_request(blk, cb, opaque, -ENOMEDIUM);
+    }
+
     return bdrv_aio_flush(blk->bs, cb, opaque);
 }
 
@@ -749,12 +761,20 @@ int blk_aio_multiwrite(BlockBackend *blk, BlockRequest *reqs, int num_reqs)
 
 int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_ioctl(blk->bs, req, buf);
 }
 
 BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
                           BlockCompletionFunc *cb, void *opaque)
 {
+    if (!blk_is_available(blk)) {
+        return abort_aio_request(blk, cb, opaque, -ENOMEDIUM);
+    }
+
     return bdrv_aio_ioctl(blk->bs, req, buf, cb, opaque);
 }
 
@@ -770,11 +790,19 @@ int blk_co_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors)
 
 int blk_co_flush(BlockBackend *blk)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_co_flush(blk->bs);
 }
 
 int blk_flush(BlockBackend *blk)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_flush(blk->bs);
 }
 
@@ -908,6 +936,11 @@ void blk_set_enable_write_cache(BlockBackend *blk, bool wce)
 
 void blk_invalidate_cache(BlockBackend *blk, Error **errp)
 {
+    if (!blk->bs) {
+        error_setg(errp, "Device '%s' has no medium", blk->name);
+        return;
+    }
+
     bdrv_invalidate_cache(blk->bs, errp);
 }
 
@@ -1063,6 +1096,10 @@ int blk_write_compressed(BlockBackend *blk, int64_t sector_num,
 
 int blk_truncate(BlockBackend *blk, int64_t offset)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_truncate(blk->bs, offset);
 }
 
@@ -1079,21 +1116,37 @@ int blk_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors)
 int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
                      int64_t pos, int size)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_save_vmstate(blk->bs, buf, pos, size);
 }
 
 int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_load_vmstate(blk->bs, buf, pos, size);
 }
 
 int blk_probe_blocksizes(BlockBackend *blk, BlockSizes *bsz)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_probe_blocksizes(blk->bs, bsz);
 }
 
 int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo)
 {
+    if (!blk_is_available(blk)) {
+        return -ENOMEDIUM;
+    }
+
     return bdrv_probe_geometry(blk->bs, geo);
 }
 
-- 
1.8.3.1

  parent reply	other threads:[~2015-10-23 17:02 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-23 17:00 [Qemu-devel] [PULL 00/37] Block layer patches Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 01/37] block: Remove host floppy support Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 02/37] block: Set BDRV_O_INCOMING in bdrv_fill_options() Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 03/37] blockdev: Allow creation of BDS trees without BB Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 04/37] iotests: Only create BB if necessary Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 05/37] block: Make bdrv_is_inserted() return a bool Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 06/37] block: Add blk_is_available() Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 07/37] block: Make bdrv_is_inserted() recursive Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 08/37] block/raw_bsd: Drop raw_is_inserted() Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 09/37] block: Invoke change media CB before NULLing drv Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 10/37] hw/block/fdc: Implement tray status Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 11/37] hw/usb-storage: Check whether BB is inserted Kevin Wolf
2015-10-23 17:00 ` [Qemu-devel] [PULL 12/37] block: Fix BB AIOCB AioContext without BDS Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 13/37] block: Move guest_block_size into BlockBackend Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 14/37] block: Remove wr_highest_sector from BlockAcctStats Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 15/37] block: Move BlockAcctStats into BlockBackend Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 16/37] block: Move I/O status and error actions into BB Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 17/37] block/throttle-groups: Make incref/decref public Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 18/37] block: Add BlockBackendRootState Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 19/37] block: Make some BB functions fall back to BBRS Kevin Wolf
2015-10-23 17:01 ` Kevin Wolf [this message]
2015-10-23 17:01 ` [Qemu-devel] [PULL 21/37] block: Prepare remaining BB functions for NULL BDS Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 22/37] block: Add blk_insert_bs() Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 23/37] block: Prepare for NULL BDS Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 24/37] blockdev: Do not create BDS for empty drive Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 25/37] blockdev: Pull out blockdev option extraction Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 26/37] blockdev: Allow more options for BB-less BDS tree Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 27/37] throttle: Remove throttle_group_lock/unlock() Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 28/37] aio: Add "is_external" flag for event handlers Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 29/37] nbd: Mark fd handlers client type as "external" Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 30/37] dataplane: Mark host notifiers' " Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 31/37] aio: introduce aio_{disable, enable}_external Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 32/37] block: Introduce "drained begin/end" API Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 33/37] block: Add "drained begin/end" for transactional external snapshot Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 34/37] block: Add "drained begin/end" for transactional backup Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 35/37] block: Add "drained begin/end" for transactional blockdev-backup Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 36/37] block: Add "drained begin/end" for internal snapshot Kevin Wolf
2015-10-23 17:01 ` [Qemu-devel] [PULL 37/37] tests: Add test case for aio_disable_external Kevin Wolf
2015-10-26  9:44 ` [Qemu-devel] [PULL 00/37] Block layer patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445619684-18216-21-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.