From patchwork Fri Apr 29 20:08:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 616954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qxPzs2Hpwz9t4b for ; Sat, 30 Apr 2016 06:14:17 +1000 (AEST) Received: from localhost ([::1]:56162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1awEnk-0004y8-7L for incoming@patchwork.ozlabs.org; Fri, 29 Apr 2016 16:14:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1awEjL-0004Jy-2p for qemu-devel@nongnu.org; Fri, 29 Apr 2016 16:09:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1awEj8-0001nq-S1 for qemu-devel@nongnu.org; Fri, 29 Apr 2016 16:09:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33153) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1awEip-0001Hm-NF; Fri, 29 Apr 2016 16:09:07 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 508447822B; Fri, 29 Apr 2016 20:08:51 +0000 (UTC) Received: from red.redhat.com (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3TK8fKV011165; Fri, 29 Apr 2016 16:08:50 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 29 Apr 2016 14:08:33 -0600 Message-Id: <1461960516-4717-12-git-send-email-eblake@redhat.com> In-Reply-To: <1461960516-4717-1-git-send-email-eblake@redhat.com> References: <1461960516-4717-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 11/14] qemu-io: Switch to byte-based block access X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" blk_write() and blk_read() are now very simple wrappers around blk_pwrite() and blk_pread(). There's no reason to require the user to pass in aligned numbers. Keep 'read -p' and 'write -p' so that I don't have to hunt down and update all users of qemu-io, but make the default 'read' and 'write' now do the same behavior that used to require -p. Signed-off-by: Eric Blake --- qemu-io-cmds.c | 75 +++++++++++++--------------------------------------------- 1 file changed, 16 insertions(+), 59 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index e26e543..4184fb8 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -419,40 +419,6 @@ fail: return buf; } -static int do_read(BlockBackend *blk, char *buf, int64_t offset, int64_t count, - int64_t *total) -{ - int ret; - - if (count >> 9 > INT_MAX) { - return -ERANGE; - } - - ret = blk_read(blk, offset >> 9, (uint8_t *)buf, count >> 9); - if (ret < 0) { - return ret; - } - *total = count; - return 1; -} - -static int do_write(BlockBackend *blk, char *buf, int64_t offset, int64_t count, - int64_t *total) -{ - int ret; - - if (count >> 9 > INT_MAX) { - return -ERANGE; - } - - ret = blk_write(blk, offset >> 9, (uint8_t *)buf, count >> 9); - if (ret < 0) { - return ret; - } - *total = count; - return 1; -} - static int do_pread(BlockBackend *blk, char *buf, int64_t offset, int64_t count, int64_t *total) { @@ -671,7 +637,7 @@ static void read_help(void) " -b, -- read from the VM state rather than the virtual disk\n" " -C, -- report statistics in a machine parsable format\n" " -l, -- length for pattern verification (only with -P)\n" -" -p, -- use blk_pread to read the file\n" +" -p, -- ignored for back-compat\n" " -P, -- use a pattern to verify read data\n" " -q, -- quiet mode, do not show I/O statistics\n" " -s, -- start offset for pattern verification (only with -P)\n" @@ -687,7 +653,7 @@ static const cmdinfo_t read_cmd = { .cfunc = read_f, .argmin = 2, .argmax = -1, - .args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len", + .args = "[-abCqv] [-P pattern [-s off] [-l len]] off len", .oneline = "reads a number of bytes at a specified offset", .help = read_help, }; @@ -695,7 +661,7 @@ static const cmdinfo_t read_cmd = { static int read_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; - int Cflag = 0, pflag = 0, qflag = 0, vflag = 0; + int Cflag = 0, qflag = 0, vflag = 0; int Pflag = 0, sflag = 0, lflag = 0, bflag = 0; int c, cnt; char *buf; @@ -723,7 +689,7 @@ static int read_f(BlockBackend *blk, int argc, char **argv) } break; case 'p': - pflag = 1; + /* Ignored for back-compat */ break; case 'P': Pflag = 1; @@ -755,11 +721,6 @@ static int read_f(BlockBackend *blk, int argc, char **argv) return qemuio_command_usage(&read_cmd); } - if (bflag && pflag) { - printf("-b and -p cannot be specified at the same time\n"); - return 0; - } - offset = cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); @@ -790,7 +751,7 @@ static int read_f(BlockBackend *blk, int argc, char **argv) return 0; } - if (!pflag) { + if (bflag) { if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n", offset); @@ -806,12 +767,10 @@ static int read_f(BlockBackend *blk, int argc, char **argv) buf = qemu_io_alloc(blk, count, 0xab); gettimeofday(&t1, NULL); - if (pflag) { - cnt = do_pread(blk, buf, offset, count, &total); - } else if (bflag) { + if (bflag) { cnt = do_load_vmstate(blk, buf, offset, count, &total); } else { - cnt = do_read(blk, buf, offset, count, &total); + cnt = do_pread(blk, buf, offset, count, &total); } gettimeofday(&t2, NULL); @@ -991,7 +950,7 @@ static void write_help(void) " filled with a set pattern (0xcdcdcdcd).\n" " -b, -- write to the VM state rather than the virtual disk\n" " -c, -- write compressed data with blk_write_compressed\n" -" -p, -- use blk_pwrite to write the file\n" +" -p, -- ignored for back-compat\n" " -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" " -q, -- quiet mode, do not show I/O statistics\n" @@ -1007,7 +966,7 @@ static const cmdinfo_t write_cmd = { .cfunc = write_f, .argmin = 2, .argmax = -1, - .args = "[-bcCpqz] [-P pattern ] off len", + .args = "[-bcCqz] [-P pattern ] off len", .oneline = "writes a number of bytes at a specified offset", .help = write_help, }; @@ -1015,7 +974,7 @@ static const cmdinfo_t write_cmd = { static int write_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; - int Cflag = 0, pflag = 0, qflag = 0, bflag = 0, Pflag = 0, zflag = 0; + int Cflag = 0, qflag = 0, bflag = 0, Pflag = 0, zflag = 0; int cflag = 0; int c, cnt; char *buf = NULL; @@ -1037,7 +996,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv) Cflag = 1; break; case 'p': - pflag = 1; + /* Ignored for back-compat */ break; case 'P': Pflag = 1; @@ -1061,8 +1020,8 @@ static int write_f(BlockBackend *blk, int argc, char **argv) return qemuio_command_usage(&write_cmd); } - if (bflag + pflag + zflag > 1) { - printf("-b, -p, or -z cannot be specified at the same time\n"); + if (bflag + zflag > 1) { + printf("-b and -z cannot be specified at the same time\n"); return 0; } @@ -1088,7 +1047,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv) return 0; } - if (!pflag) { + if (bflag || cflag || zflag) { if (offset & 0x1ff) { printf("offset %" PRId64 " is not sector aligned\n", offset); @@ -1107,16 +1066,14 @@ static int write_f(BlockBackend *blk, int argc, char **argv) } gettimeofday(&t1, NULL); - if (pflag) { - cnt = do_pwrite(blk, buf, offset, count, &total); - } else if (bflag) { + if (bflag) { cnt = do_save_vmstate(blk, buf, offset, count, &total); } else if (zflag) { cnt = do_co_write_zeroes(blk, offset, count, &total); } else if (cflag) { cnt = do_write_compressed(blk, buf, offset, count, &total); } else { - cnt = do_write(blk, buf, offset, count, &total); + cnt = do_pwrite(blk, buf, offset, count, &total); } gettimeofday(&t2, NULL);