qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, ronniesahlberg@gmail.com,
	Peter Lieven <pl@kamp.de>,
	stefanha@redhat.com, anthony@codemonkey.ws, pbonzini@redhat.com
Subject: [Qemu-devel] [PATCHv4] block/get_block_status: avoid redundant callouts on raw devices
Date: Wed,  2 Oct 2013 16:20:36 +0200	[thread overview]
Message-ID: <1380723636-18456-1-git-send-email-pl@kamp.de> (raw)

if a raw device like an iscsi target or host device is used
the current implementation makes a second call out to get
the block status of bs->file. however, the raw driver already
has called bdrv_get_block_status on bs->file.

v4: use a flag to detect the raw driver instead of the strncmp
    hack.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block.c               |    4 ++--
 block/raw_bsd.c       |    6 +++++-
 include/block/block.h |    3 +++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 93e113a..7fa2e43 100644
--- a/block.c
+++ b/block.c
@@ -3161,7 +3161,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
 
     if (bs->file &&
         (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
-        (ret & BDRV_BLOCK_OFFSET_VALID)) {
+        (ret & BDRV_BLOCK_OFFSET_VALID) && !(ret & BDRV_BLOCK_RAW)) {
         ret2 = bdrv_co_get_block_status(bs->file, ret >> BDRV_SECTOR_BITS,
                                         *pnum, pnum);
         if (ret2 >= 0) {
@@ -3172,7 +3172,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
         }
     }
 
-    return ret;
+    return ret & ~BDRV_BLOCK_RAW;
 }
 
 /* Coroutine wrapper for bdrv_get_block_status() */
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index d4ace60..a9e0209 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -62,7 +62,11 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
                                             int64_t sector_num,
                                             int nb_sectors, int *pnum)
 {
-    return bdrv_get_block_status(bs->file, sector_num, nb_sectors, pnum);
+    int64_t ret = bdrv_get_block_status(bs->file, sector_num, nb_sectors, pnum);
+    if (ret < 0) {
+        return ret;
+    }
+    return ret | BDRV_BLOCK_RAW;
 }
 
 static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
diff --git a/include/block/block.h b/include/block/block.h
index f808550..cb7019b 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -84,6 +84,8 @@ typedef struct BlockDevOps {
 /* BDRV_BLOCK_DATA: data is read from bs->file or another file
  * BDRV_BLOCK_ZERO: sectors read as zero
  * BDRV_BLOCK_OFFSET_VALID: sector stored in bs->file as raw data
+ * BDRV_BLOCK_RAW: used internally to indicate that the request
+ *                 was piped through the raw driver
  *
  * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 represent the offset in
  * bs->file where sector data can be read from as raw data.
@@ -105,6 +107,7 @@ typedef struct BlockDevOps {
 #define BDRV_BLOCK_DATA         1
 #define BDRV_BLOCK_ZERO         2
 #define BDRV_BLOCK_OFFSET_VALID 4
+#define BDRV_BLOCK_RAW          8
 #define BDRV_BLOCK_OFFSET_MASK  BDRV_SECTOR_MASK
 
 typedef enum {
-- 
1.7.9.5

             reply	other threads:[~2013-10-02 14:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-02 14:20 Peter Lieven [this message]
2013-10-02 15:06 ` [Qemu-devel] [PATCHv4] block/get_block_status: avoid redundant callouts on raw devices Stefan Hajnoczi
2013-10-02 15:13   ` Paolo Bonzini
2013-10-02 15:34     ` Peter Lieven
2013-10-02 16:02     ` Peter Lieven
2013-10-02 15:08 ` Eric Blake

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=1380723636-18456-1-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=anthony@codemonkey.ws \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).