From 55c1d98bd047cf5da5ac7017e101530c469c2486 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Wed, 22 Feb 2012 14:12:56 +0100
Subject: [PATCH 100/109] block: Add SG_IO device check in
 refresh_total_sectors()

RH-Author: Paolo Bonzini <pbonzini@redhat.com>
Message-id: <1329919979-20948-100-git-send-email-pbonzini@redhat.com>
Patchwork-id: 37579
O-Subject: [RHEL 6.3 qemu-kvm PATCH v2 099/102] block: Add SG_IO device check in refresh_total_sectors()
Bugzilla: 782029
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>

From: Nicholas Bellinger <nab@linux-iscsi.org>

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.

Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from 396759ad4ad5289623eb7e1993c433ad4e7b13a1)
---
 block.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

Signed-off-by: Michal Novotny <minovotn@redhat.com>
---
 block.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index bd10941..4cb512e 100644
--- a/block.c
+++ b/block.c
@@ -402,6 +402,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);
-- 
1.7.7.6

