From patchwork Tue Dec 13 12:37:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 131079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6E8451007D4 for ; Wed, 14 Dec 2011 00:20:09 +1100 (EST) Received: from localhost ([::1]:51648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaSH8-0005j8-Km for incoming@patchwork.ozlabs.org; Tue, 13 Dec 2011 08:20:06 -0500 Received: from eggs.gnu.org ([140.186.70.92]:44801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaRca-0005Qc-SL for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:38:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaRcP-0004Lf-G5 for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:38:07 -0500 Received: from mail-yx0-f173.google.com ([209.85.213.173]:36775) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaRcP-0004GM-Cp for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:38:01 -0500 Received: by mail-yx0-f173.google.com with SMTP id m6so6316748yen.4 for ; Tue, 13 Dec 2011 04:38:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=eUvkscuYtvMdDuW3vqYIVouovBGMysSkBEAspyt83yY=; b=RhTkwTMUQjmBoHxtjQVNzRZj9+bB9JrASUdgncTDlXt8UxqisOr8t6SF9QQz7Uk1SY mNKcJ8Odv027Akrpz3cmqIU+dQ5ohNQe8kHg/5AfFTwbTh7VFW13JElPcCU882Wohy9z TxNt1Ovxm22gYt/sl0pN12XRNqHflj0OLBkXQ= Received: by 10.236.153.42 with SMTP id e30mr3438419yhk.10.1323779881187; Tue, 13 Dec 2011 04:38:01 -0800 (PST) Received: from localhost.localdomain (93-34-178-147.ip50.fastwebnet.it. [93.34.178.147]) by mx.google.com with ESMTPS id i50sm35972917yhk.11.2011.12.13.04.37.59 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 13 Dec 2011 04:38:00 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 13 Dec 2011 13:37:20 +0100 Message-Id: <1323779840-4235-18-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.1 In-Reply-To: <1323779840-4235-1-git-send-email-pbonzini@redhat.com> References: <1323779840-4235-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.213.173 Subject: [Qemu-devel] [PATCH 17/17] qemu-io: add blocksize argument to open X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Make it possible to test the alignment code using qemu-io. Signed-off-by: Paolo Bonzini --- qemu-io.c | 33 ++++++++++++++++++++++++++++----- 1 files changed, 28 insertions(+), 5 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index ffa62fb..f866eb3 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();