[v3,18/19] block: add default get_block_status implementation for protocols

Submitted by Paolo Bonzini on July 25, 2013, 2:23 p.m.

Details

Message ID 1374762197-7261-19-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini July 25, 2013, 2:23 p.m.
Protocols return raw data, so you can assume the offsets to pass
through unchanged.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Kevin Wolf July 31, 2013, 9:12 a.m.
Am 25.07.2013 um 16:23 hat Paolo Bonzini geschrieben:
> Protocols return raw data, so you can assume the offsets to pass
> through unchanged.
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Not really objecting, but is this useful?

In formats, BDRV_BLOCK_OFFSET_VALID means that the given offset is valid
for bs->file, which is something that protocols simply don't have. You
can do it like you do here, but actually this information is redundant.

Do you make use of it for anything?

Kevin
Paolo Bonzini July 31, 2013, 12:49 p.m.
----- Original Message -----
> From: "Kevin Wolf" <kwolf@redhat.com>
> To: "Paolo Bonzini" <pbonzini@redhat.com>
> Cc: qemu-devel@nongnu.org, stefanha@redhat.com, eblake@redhat.com, pl@kamp.de
> Sent: Wednesday, July 31, 2013 11:12:27 AM
> Subject: Re: [PATCH v3 18/19] block: add default get_block_status implementation for protocols
> 
> Am 25.07.2013 um 16:23 hat Paolo Bonzini geschrieben:
> > Protocols return raw data, so you can assume the offsets to pass
> > through unchanged.
> > 
> > Reviewed-by: Eric Blake <eblake@redhat.com>
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> Not really objecting, but is this useful?
> 
> In formats, BDRV_BLOCK_OFFSET_VALID means that the given offset is valid
> for bs->file, which is something that protocols simply don't have. You
> can do it like you do here, but actually this information is redundant.
> 
> Do you make use of it for anything?

It is used by format=raw.  I could do it in raw.c, but some protocols
are opened directly without the "raw" veneer on top.

Paolo

Patch hide | download patch | download mbox

diff --git a/block.c b/block.c
index fc1da56..8738937 100644
--- a/block.c
+++ b/block.c
@@ -3005,7 +3005,11 @@  static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
 
     if (!bs->drv->bdrv_co_get_block_status) {
         *pnum = nb_sectors;
-        return BDRV_BLOCK_DATA;
+        ret = BDRV_BLOCK_DATA;
+        if (bs->drv->protocol_name) {
+            ret |= BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_SIZE);
+        }
+        return ret;
     }
 
     ret = bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, pnum);