: Skip refresh_total_sectors() for scsi-generic devices
PATCH 2/2 : Skip refresh_total_sectors() for scsi-generic devices
From: Nicholas Bellinger <[email protected]>
This patch adds a BlockDriverState->sg check in block.c:bdrv_common_open() to skip the new refresh_total_sectors() call once we know we are working with a scsi-generic device.
We go ahead and skip this call for scsi-generic devices because block/raw-posix.c:raw_getlength() -> lseek() will return -ESPIPE.
--- block.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
block.c +9 -4
@@ -444,10 +444,15 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, } bs->keep_read_only = bs->read_only = !(open_flags &BDRV_O_RDWR ); - - ret =refresh_total_sectors (bs, bs->total_sectors); -if (ret <0 ) { - goto free_and_fail; +/* +* For scsi-generic devices, do not call refresh_total_sectors() -> raw_getlength() +* because lseek() will return -ESPIPE. +*/ +if (!(bs->sg)) { + ret =refresh_total_sectors (bs, bs->total_sectors); +if (ret <0 ) { + goto free_and_fail; + } }#ifndef _WIN32
Signature · 1 line
1.5.6.5
Quoted 8 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
This patch adds a
BlockDriverState->sgcheck in block.c:bdrv_common_open() to skip the newrefresh_total_sectors()call once we know we are working with a scsi-generic device.We go ahead and skip this call for scsi-generic devices because block/raw-posix.c:raw_getlength() ->
lseek()will return-ESPIPE.
How about moving that check into refresh_total_sectors?
Quoted 11 lines · Christoph Hellwig
Quoted 8 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
This patch adds a
BlockDriverState->sgcheck in block.c:bdrv_common_open() to skip the newrefresh_total_sectors()call once we know we are working with a scsi-generic device.We go ahead and skip this call for scsi-generic devices because block/raw-posix.c:raw_getlength() ->
lseek()will return-ESPIPE.How about moving that check into
refresh_total_sectors?
Sounds good, attached is updated patch #2:
[PATCH 2/2] [block]: Add SG_IO device check in refresh_total_sectors()
Also, I am using the options in .vimrc to follow QEMU's indent style:
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
I assume this is what should be used when sending QEMU patches, yes..?
Best,
--nab
Quoted 1 line
From
8f4cbec758867e51839d2f3f270fc06907a97dd5Mon Sep 17 00:00:00 2001
From: Nicholas Bellinger <[email protected]>
Date: Sun, 16 May 2010 18:28:35 -0700
Subject: [PATCH 2/2] [block]: Add SG_IO device check in refresh_total_sectors()
This patch adds a special case check for scsi-generic devices in refresh_total_sectors() to skip the subsequent BlockDriver->bdrv_getlength() that will be returning -ESPIPE from block/raw-posic.c:raw_getlength() for BlockDriverState->sg=1 devices.
--- block.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
block.c +4 -0
@@ -364,6 +364,10 @@ static int refresh_total_sectors(BlockDriverState *bs, int64_t hint) {BlockDriver *drv = bs->drv; +/* Do not attempt drv->bdrv_getlength() on scsi-generic devices */ +if (bs->sg) +return 0 ; +/* query actual device if possible, otherwise just trust the hint */ if (drv->bdrv_getlength) {int64_t length = drv->bdrv_getlength (bs);
Signature · 1 line
1.5.6.5