From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=42437 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OD9bC-0007vH-T9 for qemu-devel@nongnu.org; Sat, 15 May 2010 01:07:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OD9bB-0008Gu-HI for qemu-devel@nongnu.org; Sat, 15 May 2010 01:07:42 -0400 Received: from smtp128.sbc.mail.sp1.yahoo.com ([69.147.65.187]:26892) by eggs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OD9bB-0008Gp-7m for qemu-devel@nongnu.org; Sat, 15 May 2010 01:07:41 -0400 From: "Nicholas A. Bellinger" Date: Sat, 15 May 2010 06:30:59 -0700 Message-Id: <1273930259-12694-1-git-send-email-nab@linux-iscsi.org> Subject: [Qemu-devel] [PATCH 2/2] [block]: Skip refresh_total_sectors() for scsi-generic devices List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , Christoph Hellwig , Gerd Hoffmann , Hannes Reinecke , kvm-devel , qemu-devel Cc: Nicholas Bellinger From: Nicholas Bellinger 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. Signed-off-by: Nicholas A. Bellinger --- block.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 02a22f6..1053161 100644 --- a/block.c +++ b/block.c @@ -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 -- 1.5.6.5