From patchwork Fri Apr 22 23:40:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 8916381 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B80EDBF29F for ; Fri, 22 Apr 2016 23:50:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 109F120212 for ; Fri, 22 Apr 2016 23:50:32 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 45BB52020F for ; Fri, 22 Apr 2016 23:50:31 +0000 (UTC) Received: from localhost ([::1]:41820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atkqE-0005xN-Lp for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Apr 2016 19:50:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atkhe-0003rt-71 for qemu-devel@nongnu.org; Fri, 22 Apr 2016 19:41:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1atkhc-0005QD-VA for qemu-devel@nongnu.org; Fri, 22 Apr 2016 19:41:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55278) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1atkhZ-0005NC-Kk; Fri, 22 Apr 2016 19:41:33 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 43824C062CE5; Fri, 22 Apr 2016 23:41:33 +0000 (UTC) Received: from red.redhat.com (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3MNfHX7028475; Fri, 22 Apr 2016 19:41:32 -0400 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 22 Apr 2016 17:40:26 -0600 Message-Id: <1461368452-10389-19-git-send-email-eblake@redhat.com> In-Reply-To: <1461368452-10389-1-git-send-email-eblake@redhat.com> References: <1461368452-10389-1-git-send-email-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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 v3 18/44] qemu-img: 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 , alex@alex.org.uk, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sector-based blk_write() should die; switch to byte-based blk_pwrite() instead. Likewise for blk_read(). Signed-off-by: Eric Blake --- qemu-img.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 1697762..2e4646e 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1092,7 +1092,8 @@ static int check_empty_sectors(BlockBackend *blk, int64_t sect_num, uint8_t *buffer, bool quiet) { int pnum, ret = 0; - ret = blk_read(blk, sect_num, buffer, sect_count); + ret = blk_pread(blk, sect_num << BDRV_SECTOR_BITS, buffer, + sect_count << BDRV_SECTOR_BITS); if (ret < 0) { error_report("Error while reading offset %" PRId64 " of %s: %s", sectors_to_bytes(sect_num), filename, strerror(-ret)); @@ -1307,7 +1308,8 @@ static int img_compare(int argc, char **argv) nb_sectors = MIN(pnum1, pnum2); } else if (allocated1 == allocated2) { if (allocated1) { - ret = blk_read(blk1, sector_num, buf1, nb_sectors); + ret = blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, buf1, + nb_sectors << BDRV_SECTOR_BITS); if (ret < 0) { error_report("Error while reading offset %" PRId64 " of %s:" " %s", sectors_to_bytes(sector_num), filename1, @@ -1315,7 +1317,8 @@ static int img_compare(int argc, char **argv) ret = 4; goto out; } - ret = blk_read(blk2, sector_num, buf2, nb_sectors); + ret = blk_pread(blk2, sector_num << BDRV_SECTOR_BITS, buf2, + nb_sectors << BDRV_SECTOR_BITS); if (ret < 0) { error_report("Error while reading offset %" PRId64 " of %s: %s", sectors_to_bytes(sector_num), @@ -1528,7 +1531,9 @@ static int convert_read(ImgConvertState *s, int64_t sector_num, int nb_sectors, bs_sectors = s->src_sectors[s->src_cur]; n = MIN(nb_sectors, bs_sectors - (sector_num - s->src_cur_offset)); - ret = blk_read(blk, sector_num - s->src_cur_offset, buf, n); + ret = blk_pread(blk, + (sector_num - s->src_cur_offset) << BDRV_SECTOR_BITS, + buf, n << BDRV_SECTOR_BITS); if (ret < 0) { return ret; } @@ -1583,7 +1588,8 @@ static int convert_write(ImgConvertState *s, int64_t sector_num, int nb_sectors, if (!s->min_sparse || is_allocated_sectors_min(buf, n, &n, s->min_sparse)) { - ret = blk_write(s->target, sector_num, buf, n); + ret = blk_pwrite(s->target, sector_num << BDRV_SECTOR_BITS, + buf, n << BDRV_SECTOR_BITS, 0); if (ret < 0) { return ret; } @@ -3036,7 +3042,8 @@ static int img_rebase(int argc, char **argv) n = old_backing_num_sectors - sector; } - ret = blk_read(blk_old_backing, sector, buf_old, n); + ret = blk_pread(blk_old_backing, sector << BDRV_SECTOR_BITS, + buf_old, n << BDRV_SECTOR_BITS); if (ret < 0) { error_report("error while reading from old backing file"); goto out; @@ -3050,7 +3057,8 @@ static int img_rebase(int argc, char **argv) n = new_backing_num_sectors - sector; } - ret = blk_read(blk_new_backing, sector, buf_new, n); + ret = blk_pread(blk_new_backing, sector << BDRV_SECTOR_BITS, + buf_new, n << BDRV_SECTOR_BITS); if (ret < 0) { error_report("error while reading from new backing file"); goto out; @@ -3066,8 +3074,10 @@ static int img_rebase(int argc, char **argv) if (compare_sectors(buf_old + written * 512, buf_new + written * 512, n - written, &pnum)) { - ret = blk_write(blk, sector + written, - buf_old + written * 512, pnum); + ret = blk_pwrite(blk, + (sector + written) << BDRV_SECTOR_BITS, + buf_old + written * 512, + pnum << BDRV_SECTOR_BITS, 0); if (ret < 0) { error_report("Error while writing to COW image: %s", strerror(-ret));