From patchwork Thu May 12 14:35:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9082641 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DC4D19F1C3 for ; Thu, 12 May 2016 15:04:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 380E720221 for ; Thu, 12 May 2016 15:04:00 +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 64B102020F for ; Thu, 12 May 2016 15:03:59 +0000 (UTC) Received: from localhost ([::1]:58112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0s9e-0003RO-Gy for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 May 2016 11:03:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0rja-000613-If for qemu-devel@nongnu.org; Thu, 12 May 2016 10:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0rjY-00049n-0q for qemu-devel@nongnu.org; Thu, 12 May 2016 10:37:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39953) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0rjQ-00045o-TL; Thu, 12 May 2016 10:36:53 -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 6F2F62FF; Thu, 12 May 2016 14:36:52 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4CEZp9N028730; Thu, 12 May 2016 10:36:51 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 12 May 2016 16:35:25 +0200 Message-Id: <1463063749-2201-46-git-send-email-kwolf@redhat.com> In-Reply-To: <1463063749-2201-1-git-send-email-kwolf@redhat.com> References: <1463063749-2201-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 12 May 2016 14:36:52 +0000 (UTC) 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] [PULL 45/69] 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: kwolf@redhat.com, qemu-devel@nongnu.org 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 From: Eric Blake Sector-based blk_write() should die; switch to byte-based blk_pwrite() instead. Likewise for blk_read(). Signed-off-by: Eric Blake Signed-off-by: Kevin Wolf --- qemu-img.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 76430a8..491a460 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1088,7 +1088,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)); @@ -1301,7 +1302,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, @@ -1309,7 +1311,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), @@ -1522,7 +1525,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; } @@ -1577,7 +1582,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; } @@ -3024,7 +3030,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; @@ -3038,7 +3045,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; @@ -3054,8 +3062,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));