9ae3a8
From 1c16f135463077e596b9156439d2482a1a8aa9b8 Mon Sep 17 00:00:00 2001
9ae3a8
From: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Date: Fri, 18 Oct 2013 08:14:29 +0200
9ae3a8
Subject: [PATCH 04/81] block: keep bs->total_sectors up to date even for growable block devices
9ae3a8
9ae3a8
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Message-id: <1382084091-16636-5-git-send-email-pbonzini@redhat.com>
9ae3a8
Patchwork-id: 54986
9ae3a8
O-Subject: [RHEL 7.0 qemu-kvm PATCH 04/26] block: keep bs->total_sectors up to date even for growable block devices
9ae3a8
Bugzilla: 989646
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
9ae3a8
If a BlockDriverState is growable, after every write we need to
9ae3a8
check if bs->total_sectors might have changed.  With this change,
9ae3a8
bdrv_getlength does not need anymore a system call.
9ae3a8
9ae3a8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
(cherry picked from commit df2a6f29a5019707d69f6eeb30cf792841cae5aa)
9ae3a8
---
9ae3a8
 block.c | 5 ++++-
9ae3a8
 1 file changed, 4 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block.c |    5 ++++-
9ae3a8
 1 files changed, 4 insertions(+), 1 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index 2ba9a0a..d5aeff7 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -2703,6 +2703,9 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
9ae3a8
     if (bs->wr_highest_sector < sector_num + nb_sectors - 1) {
9ae3a8
         bs->wr_highest_sector = sector_num + nb_sectors - 1;
9ae3a8
     }
9ae3a8
+    if (bs->growable && ret >= 0) {
9ae3a8
+        bs->total_sectors = MAX(bs->total_sectors, sector_num + nb_sectors);
9ae3a8
+    }
9ae3a8
 
9ae3a8
     tracked_request_end(&req;;
9ae3a8
 
9ae3a8
@@ -2777,7 +2780,7 @@ int64_t bdrv_getlength(BlockDriverState *bs)
9ae3a8
     if (!drv)
9ae3a8
         return -ENOMEDIUM;
9ae3a8
 
9ae3a8
-    if (bs->growable || bdrv_dev_has_removable_media(bs)) {
9ae3a8
+    if (bdrv_dev_has_removable_media(bs)) {
9ae3a8
         if (drv->bdrv_getlength) {
9ae3a8
             return drv->bdrv_getlength(bs);
9ae3a8
         }
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8