yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qemu-img-round-down-request-length-to-an-aligned-sec.patch.patch

9ae3a8
From 070f95bad47e0d0f1884b93184369b3c9322cd4c Mon Sep 17 00:00:00 2001
9ae3a8
Message-Id: <070f95bad47e0d0f1884b93184369b3c9322cd4c.1389014116.git.minovotn@redhat.com>
9ae3a8
In-Reply-To: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
9ae3a8
References: <c8cc35838d42aa286242772d97e3a9be7bb786ba.1389014116.git.minovotn@redhat.com>
9ae3a8
From: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Date: Mon, 9 Dec 2013 14:09:37 +0100
9ae3a8
Subject: [PATCH 49/50] qemu-img: round down request length to an aligned
9ae3a8
 sector
9ae3a8
9ae3a8
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Message-id: <1386598178-11845-52-git-send-email-pbonzini@redhat.com>
9ae3a8
Patchwork-id: 56088
9ae3a8
O-Subject: [RHEL 7.0 qemu-kvm PATCH 51/52] qemu-img: round down request length to an aligned sector
9ae3a8
Bugzilla: 1039557
9ae3a8
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
9ae3a8
From: Peter Lieven <pl@kamp.de>
9ae3a8
9ae3a8
this patch shortens requests to end at an aligned sector so that
9ae3a8
the next request starts aligned.
9ae3a8
9ae3a8
[Squashed Peter's fix for bdrv_get_info() failure discussed on the
9ae3a8
mailing list.
9ae3a8
--Stefan]
9ae3a8
9ae3a8
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Signed-off-by: Peter Lieven <pl@kamp.de>
9ae3a8
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
9ae3a8
(cherry picked from commit 24f833cd43dbfb5f8ae99e8a6d3691671622d3ea)
9ae3a8
---
9ae3a8
 qemu-img.c | 32 ++++++++++++++++++++++++--------
9ae3a8
 1 file changed, 24 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
---
9ae3a8
 qemu-img.c | 32 ++++++++++++++++++++++++--------
9ae3a8
 1 file changed, 24 insertions(+), 8 deletions(-)
9ae3a8
9ae3a8
diff --git a/qemu-img.c b/qemu-img.c
9ae3a8
index 6890bb1..55bb82c 100644
9ae3a8
--- a/qemu-img.c
9ae3a8
+++ b/qemu-img.c
9ae3a8
@@ -1122,8 +1122,7 @@ out3:
9ae3a8
 
9ae3a8
 static int img_convert(int argc, char **argv)
9ae3a8
 {
9ae3a8
-    int c, n, n1, bs_n, bs_i, compress, cluster_size,
9ae3a8
-        cluster_sectors, skip_create;
9ae3a8
+    int c, n, n1, bs_n, bs_i, compress, cluster_sectors, skip_create;
9ae3a8
     int64_t ret = 0;
9ae3a8
     int progress = 0, flags;
9ae3a8
     const char *fmt, *out_fmt, *cache, *out_baseimg, *out_filename;
9ae3a8
@@ -1395,19 +1394,23 @@ static int img_convert(int argc, char **argv)
9ae3a8
         }
9ae3a8
     }
9ae3a8
 
9ae3a8
-    if (compress) {
9ae3a8
-        ret = bdrv_get_info(out_bs, &bdi;;
9ae3a8
-        if (ret < 0) {
9ae3a8
+    cluster_sectors = 0;
9ae3a8
+    ret = bdrv_get_info(out_bs, &bdi;;
9ae3a8
+    if (ret < 0) {
9ae3a8
+        if (compress) {
9ae3a8
             error_report("could not get block driver info");
9ae3a8
             goto out;
9ae3a8
         }
9ae3a8
-        cluster_size = bdi.cluster_size;
9ae3a8
-        if (cluster_size <= 0 || cluster_size > bufsectors * BDRV_SECTOR_SIZE) {
9ae3a8
+    } else {
9ae3a8
+        cluster_sectors = bdi.cluster_size / BDRV_SECTOR_SIZE;
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    if (compress) {
9ae3a8
+        if (cluster_sectors <= 0 || cluster_sectors > bufsectors) {
9ae3a8
             error_report("invalid cluster size");
9ae3a8
             ret = -1;
9ae3a8
             goto out;
9ae3a8
         }
9ae3a8
-        cluster_sectors = cluster_size >> 9;
9ae3a8
         sector_num = 0;
9ae3a8
 
9ae3a8
         nb_sectors = total_sectors;
9ae3a8
@@ -1540,6 +1543,19 @@ static int img_convert(int argc, char **argv)
9ae3a8
             }
9ae3a8
 
9ae3a8
             n = MIN(nb_sectors, bufsectors);
9ae3a8
+
9ae3a8
+            /* round down request length to an aligned sector, but
9ae3a8
+             * do not bother doing this on short requests. They happen
9ae3a8
+             * when we found an all-zero area, and the next sector to
9ae3a8
+             * write will not be sector_num + n. */
9ae3a8
+            if (cluster_sectors > 0 && n >= cluster_sectors) {
9ae3a8
+                int64_t next_aligned_sector = (sector_num + n);
9ae3a8
+                next_aligned_sector -= next_aligned_sector % cluster_sectors;
9ae3a8
+                if (sector_num + n > next_aligned_sector) {
9ae3a8
+                    n = next_aligned_sector - sector_num;
9ae3a8
+                }
9ae3a8
+            }
9ae3a8
+
9ae3a8
             n = MIN(n, bs_sectors - (sector_num - bs_offset));
9ae3a8
             n1 = n;
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.11.7
9ae3a8