Skip to contentSkip to conversation

block/get_block_status: avoid redundant callouts on raw devices

PATCH Applied Peter Lieven 3 participants 3 messages Oct 8, 2013 – Oct 9, 2013 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 block/get_block_status: avoid redundant callouts on raw devices

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.

---
v6: made the result of raw_co_get_block_status valid by
adding BDRV_BLOCK_DATA and setting *pnum to nb_sectors and calling bdrv_get_block_status on bs->file with the offset and *pnum returned in the first callout.

v5: add a generic get_lba_status function in the raw driver which
adds the BDRV_BLOCK_RAW flag. bdrv_co_get_block_status will handle the callout to bs->file then.

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

 block.c               |    6 ++++++
 block/raw_bsd.c       |    4 +++-
 include/block/block.h |    4 ++++
 3 files changed, 13 insertions(+), 1 deletion(-)
block.c +6 -0
index 93e113a..826eff0 100644
@@ -3147,6 +3147,12 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
         return ret;
     }
 
+    if (ret & BDRV_BLOCK_RAW) {
+        assert(ret & BDRV_BLOCK_OFFSET_VALID);
+        return bdrv_get_block_status(bs->file, ret >> BDRV_SECTOR_BITS,
+                                     *pnum, pnum);
+    }
+
     if (!(ret & BDRV_BLOCK_DATA)) {
         if (bdrv_has_zero_init(bs)) {
             ret |= BDRV_BLOCK_ZERO;
block/raw_bsd.c +3 -1
index d4ace60..d61906b 100644
@@ -62,7 +62,9 @@ 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);
+    *pnum = nb_sectors;
+    return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA |
+           (sector_num << BDRV_SECTOR_BITS);
 }
 
 static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs,
include/block/block.h +4 -0
index f808550..003699e 100644
@@ -84,6 +84,9 @@ 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 answered by the raw driver and that one
+ *                 should look in bs->file directly.
  *
  * 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 +108,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 {
Signature · 1 line
1.7.9.5
Reviewed-by on v6 1/1
#1 lore raw
Quoted 6 lines · Peter Lieven

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.

---

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Applied
#2 lore raw

Am 08.10.2013 um 20:11 hat Eric Blake geschrieben:

Quoted 9 lines · Peter Lieven
Quoted 6 lines

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.

---

Thanks, applied to the block branch.

Kevin