qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com
Subject: [Qemu-devel] [PATCH v2 18/18] qemu-io: add blocksize argument to open
Date: Thu, 26 Jan 2012 18:22:49 +0100	[thread overview]
Message-ID: <1327598569-5199-19-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1327598569-5199-1-git-send-email-pbonzini@redhat.com>

Make it possible to test the alignment code using qemu-io.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-io.c |   33 ++++++++++++++++++++++++++++-----
 1 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/qemu-io.c b/qemu-io.c
index 7c446b6..268db89 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1594,7 +1594,7 @@ static const cmdinfo_t close_cmd = {
     .oneline    = "close the current open file",
 };
 
-static int openfile(char *name, int flags, int growable)
+static int openfile(char *name, int flags, int growable, int blocksize)
 {
     if (bs) {
         fprintf(stderr, "file open already, try 'help close'\n");
@@ -1615,6 +1615,17 @@ static int openfile(char *name, int flags, int growable)
             bs = NULL;
             return 1;
         }
+        if (blocksize) {
+            if (blocksize < bs->host_block_size && (flags & BDRV_O_NOCACHE)) {
+                fprintf(stderr, "%s: block size cannot be smaller than the actual size\n", progname);
+            } else {
+                if (blocksize > 512) {
+                    /* Always go through the RMW logic.  */
+                    bs->open_flags |= BDRV_O_NOCACHE;
+                }
+                bs->host_block_size = blocksize;
+            }
+        }
     }
 
     return 0;
@@ -1633,7 +1644,8 @@ static void open_help(void)
 " -r, -- open file read-only\n"
 " -s, -- use snapshot file\n"
 " -n, -- disable host cache\n"
-" -g, -- allow file to grow (only applies to protocols)"
+" -g, -- allow file to grow (only applies to protocols)\n"
+" -bSIZE, -- behave as if the host block size was SIZE\n"
 "\n");
 }
 
@@ -1656,9 +1668,11 @@ static int open_f(int argc, char **argv)
     int flags = 0;
     int readonly = 0;
     int growable = 0;
+    long blocksize = 0;
+    char *endptr = NULL;
     int c;
 
-    while ((c = getopt(argc, argv, "snrg")) != EOF) {
+    while ((c = getopt(argc, argv, "snrgb:")) != EOF) {
         switch (c) {
         case 's':
             flags |= BDRV_O_SNAPSHOT;
@@ -1672,6 +1686,15 @@ static int open_f(int argc, char **argv)
         case 'g':
             growable = 1;
             break;
+        case 'b':
+            blocksize = strtol(optarg, &endptr, 0);
+            if (blocksize < 512 || blocksize > 65536 ||
+                (blocksize & (blocksize - 1)) || *endptr != '\0') {
+                printf("The block size must be a power of two "
+                       "between 512 and 65536.\n");
+                return -1;
+            }
+            break;
         default:
             return command_usage(&open_cmd);
         }
@@ -1685,7 +1708,7 @@ static int open_f(int argc, char **argv)
         return command_usage(&open_cmd);
     }
 
-    return openfile(argv[optind], flags, growable);
+    return openfile(argv[optind], flags, growable, blocksize);
 }
 
 static int init_args_command(int index)
@@ -1825,7 +1848,7 @@ int main(int argc, char **argv)
     }
 
     if ((argc - optind) == 1) {
-        openfile(argv[optind], flags, growable);
+        openfile(argv[optind], flags, growable, 0);
     }
     command_loop();
 
-- 
1.7.7.6

      parent reply	other threads:[~2012-01-26 17:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-26 17:22 [Qemu-devel] [PATCH v2 00/18] Support mismatched host and guest logical block sizes Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 01/18] block: do not rely on open_flags for bdrv_is_snapshot Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 02/18] block: store actual flags in bs->open_flags Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 03/18] block: pass protocol flags up to the format Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 04/18] block: non-raw protocols never cache Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 05/18] block: remove enable_write_cache Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 06/18] block: move flag bits together Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 07/18] raw: remove the aligned_buf Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 08/18] block: rename buffer_alignment to guest_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 09/18] block: add host_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 10/18] raw: probe host_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 11/18] iscsi: save host block size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 12/18] block: allow waiting only for overlapping writes Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 13/18] block: allow waiting at arbitrary granularity Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 14/18] block: protect against "torn reads" for guest_block_size > host_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 15/18] block: align and serialize I/O when guest_block_size < host_block_size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 16/18] block: default physical block size to host block size Paolo Bonzini
2012-01-26 17:22 ` [Qemu-devel] [PATCH v2 17/18] block: default min_io_size to host block size when doing rmw Paolo Bonzini
2012-01-26 17:22 ` Paolo Bonzini [this message]

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=1327598569-5199-19-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).