qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven <pl@kamp.de>,
	stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 1.8 5/6] qemu-img: add option to align writes to cluster_sectors during convert
Date: Mon, 25 Nov 2013 14:57:19 +0100	[thread overview]
Message-ID: <1385387840-17307-6-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1385387840-17307-1-git-send-email-pl@kamp.de>

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 qemu-img-cmds.hx |    4 ++--
 qemu-img.c       |   37 +++++++++++++++++++++++++------------
 qemu-img.texi    |    5 ++++-
 3 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index e0b8ab4..266cdf3 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -34,9 +34,9 @@ STEXI
 ETEXI
 
 DEF("convert", img_convert,
-    "convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] [-m iobuf_size] filename [filename2 [...]] output_filename")
+    "convert [-c] [-p] [-q] [-n] [-a] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] [-m iobuf_size] filename [filename2 [...]] output_filename")
 STEXI
-@item convert [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] [-m @var{iobuf_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
+@item convert [-c] [-p] [-q] [-n] [-a] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] [-m @var{iobuf_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
 ETEXI
 
 DEF("info", img_info,
diff --git a/qemu-img.c b/qemu-img.c
index 0ce5d14..9fa8fd4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -109,6 +109,7 @@ static void help(void)
            "  '--output' takes the format in which the output must be done (human or json)\n"
            "  '-n' skips the target volume creation (useful if the volume is created\n"
            "       prior to running qemu-img)\n"
+           "  '-a' align write requests to cluster size if possible\n"
            "\n"
            "Parameters to check subcommand:\n"
            "  '-r' tries to repair any inconsistencies that are found during the check.\n"
@@ -1125,8 +1126,7 @@ out3:
 
 static int img_convert(int argc, char **argv)
 {
-    int c, n, n1, bs_n, bs_i, compress, cluster_size,
-        cluster_sectors, skip_create;
+    int c, n, n1, bs_n, bs_i, compress, cluster_sectors, skip_create;
     int64_t ret = 0;
     int progress = 0, flags;
     const char *fmt, *out_fmt, *cache, *out_baseimg, *out_filename;
@@ -1144,7 +1144,7 @@ static int img_convert(int argc, char **argv)
     char *options = NULL;
     const char *snapshot_name = NULL;
     int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
-    bool quiet = false;
+    bool quiet = false, align = false;
     Error *local_err = NULL;
 
     fmt = NULL;
@@ -1154,7 +1154,7 @@ static int img_convert(int argc, char **argv)
     compress = 0;
     skip_create = 0;
     for(;;) {
-        c = getopt(argc, argv, "f:O:B:s:hce6o:pS:m:t:qn");
+        c = getopt(argc, argv, "f:O:B:s:hcae6o:pS:m:t:qn");
         if (c == -1) {
             break;
         }
@@ -1175,6 +1175,9 @@ static int img_convert(int argc, char **argv)
         case 'c':
             compress = 1;
             break;
+        case 'a':
+            align = true;
+            break;
         case 'e':
             error_report("option -e is deprecated, please use \'-o "
                   "encryption\' instead!");
@@ -1402,19 +1405,21 @@ static int img_convert(int argc, char **argv)
         }
     }
 
+    cluster_sectors = 0;
+    ret = bdrv_get_info(out_bs, &bdi);
+    if (ret < 0 && compress) {
+        error_report("could not get block driver info");
+        goto out;
+    } else {
+        cluster_sectors = bdi.cluster_size / BDRV_SECTOR_SIZE;
+    }
+
     if (compress) {
-        ret = bdrv_get_info(out_bs, &bdi);
-        if (ret < 0) {
-            error_report("could not get block driver info");
-            goto out;
-        }
-        cluster_size = bdi.cluster_size;
-        if (cluster_size <= 0 || cluster_size > bufsectors * BDRV_SECTOR_SIZE) {
+        if (cluster_sectors <= 0 || cluster_sectors > bufsectors) {
             error_report("invalid cluster size");
             ret = -1;
             goto out;
         }
-        cluster_sectors = cluster_size >> 9;
         sector_num = 0;
 
         nb_sectors = total_sectors;
@@ -1552,6 +1557,14 @@ static int img_convert(int argc, char **argv)
                 n = nb_sectors;
             }
 
+            if (align && cluster_sectors > 0) {
+                int64_t next_aligned_sector = (sector_num + cluster_sectors);
+                next_aligned_sector -= next_aligned_sector % cluster_sectors;
+                if (sector_num + n > next_aligned_sector) {
+                    n = next_aligned_sector - sector_num;
+                }
+            }
+
             if (n > bs_offset + bs_sectors - sector_num) {
                 n = bs_offset + bs_sectors - sector_num;
             }
diff --git a/qemu-img.texi b/qemu-img.texi
index 87f9d0f..9b1720f 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -179,11 +179,14 @@ Error on reading data
 
 @end table
 
-@item convert [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] [-m @var{iobuf_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
+@item convert [-c] [-p] [-n] [-a] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] [-m @var{iobuf_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
 
 Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to disk image @var{output_filename}
 using format @var{output_fmt}. It can be optionally compressed (@code{-c}
 option) or use any format specific options like encryption (@code{-o} option).
+If the @code{-a} option is specified write requests will be aligned
+to the cluster size of the output image if possible. This is the default
+for compressed images.
 
 Only the formats @code{qcow} and @code{qcow2} support compression. The
 compression is read-only. It means that if a compressed sector is
-- 
1.7.9.5

  parent reply	other threads:[~2013-11-25 13:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-25 13:57 [Qemu-devel] [PATCH 1.8 0/6] qemu-img convert optimizations Peter Lieven
2013-11-25 13:57 ` [Qemu-devel] [PATCH 1.8 1/6] qemu-img: add support for skipping zeroes in input during convert Peter Lieven
2013-11-25 13:57 ` [Qemu-devel] [PATCH 1.8 2/6] qemu-img: fix usage instruction for qemu-img convert Peter Lieven
2013-11-25 17:21   ` Eric Blake
2013-11-26  7:01     ` Peter Lieven
2013-11-25 13:57 ` [Qemu-devel] [PATCH 1.8 3/6] qemu-img: add option to specify alternate iobuffer size Peter Lieven
2013-11-25 14:54   ` Paolo Bonzini
2013-11-25 15:01     ` Peter Lieven
2013-11-25 15:07     ` Peter Lieven
2013-11-25 15:14       ` Paolo Bonzini
2013-11-25 15:24         ` Peter Lieven
2013-11-25 15:48           ` Paolo Bonzini
2013-11-25 15:56             ` Peter Lieven
2013-11-25 13:57 ` [Qemu-devel] [PATCH 1.8 4/6] block/iscsi: set bdi->cluster_size Peter Lieven
2013-11-25 14:51   ` Paolo Bonzini
2013-11-25 15:02   ` Paolo Bonzini
2013-11-25 13:57 ` Peter Lieven [this message]
2013-11-25 15:11   ` [Qemu-devel] [PATCH 1.8 5/6] qemu-img: add option to align writes to cluster_sectors during convert Paolo Bonzini
2013-11-25 15:32     ` Peter Lieven
2013-11-25 15:50       ` Paolo Bonzini
2013-11-25 15:55         ` Peter Lieven
2013-11-25 16:02           ` Paolo Bonzini
2013-11-25 16:11     ` Peter Lieven
2013-11-25 16:34       ` Paolo Bonzini
2013-11-25 13:57 ` [Qemu-devel] [PATCH 1.8 6/6] qemu-img: add option to show progress in sectors Peter Lieven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1385387840-17307-6-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).