diff mbox

[(trivial)] no need to use bdrv_pread() in format guessing code when we can use bdrv_read() directly

Message ID 1331655771-10868-1-git-send-email-mjt@msgid.tls.msk.ru
State New
Headers show

Commit Message

Michael Tokarev March 13, 2012, 4:22 p.m. UTC
[Sorry - sent the wrong patch, should have been
BDRV_SECTOR_SIZE, not BDRV_BLOCK_SIZE....]

block.c:find_image_format() calls bdrv_pread() to read first 2048
bytes from the device to guess its format.  This function can use
bdrv_read() directly since the the read is done on sector boundary.

Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
 block.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Stefan Hajnoczi March 14, 2012, 9:25 a.m. UTC | #1
On Tue, Mar 13, 2012 at 4:22 PM, Michael Tokarev <mjt@tls.msk.ru> wrote:
> [Sorry - sent the wrong patch, should have been
> BDRV_SECTOR_SIZE, not BDRV_BLOCK_SIZE....]
>
> block.c:find_image_format() calls bdrv_pread() to read first 2048
> bytes from the device to guess its format.  This function can use
> bdrv_read() directly since the the read is done on sector boundary.
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
>  block.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/block.c b/block.c
> index b88ee90..b3af1f6 100644
> --- a/block.c
> +++ b/block.c
> @@ -469,7 +469,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv)
>         return ret;
>     }
>
> -    ret = bdrv_pread(bs, 0, buf, sizeof(buf));
> +    ret = bdrv_read(bs, 0, buf, sizeof(buf) / BDRV_SECTOR_SIZE);

Why do this?  The code is nicer to read without the sector division
and there's no real difference at execution time.

Stefan
diff mbox

Patch

diff --git a/block.c b/block.c
index b88ee90..b3af1f6 100644
--- a/block.c
+++ b/block.c
@@ -469,7 +469,7 @@  static int find_image_format(const char *filename, BlockDriver **pdrv)
         return ret;
     }
 
-    ret = bdrv_pread(bs, 0, buf, sizeof(buf));
+    ret = bdrv_read(bs, 0, buf, sizeof(buf) / BDRV_SECTOR_SIZE);
     bdrv_delete(bs);
     if (ret < 0) {
         *pdrv = NULL;