From patchwork Fri Sep 23 11:25:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 116042 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 46F33B6F8B for ; Fri, 23 Sep 2011 21:25:27 +1000 (EST) Received: from localhost ([::1]:42216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R73sh-00058J-QI for incoming@patchwork.ozlabs.org; Fri, 23 Sep 2011 07:25:23 -0400 Received: from eggs.gnu.org ([140.186.70.92]:51526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R73sc-00057f-6K for qemu-devel@nongnu.org; Fri, 23 Sep 2011 07:25:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R73sa-00013D-U8 for qemu-devel@nongnu.org; Fri, 23 Sep 2011 07:25:18 -0400 Received: from mail-gx0-f173.google.com ([209.85.161.173]:36110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R73sa-00012l-OU for qemu-devel@nongnu.org; Fri, 23 Sep 2011 07:25:16 -0400 Received: by gxk25 with SMTP id 25so3096600gxk.4 for ; Fri, 23 Sep 2011 04:25:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=AUS9c/Mp7YzjYJS+tWJ3JAVrVCPhiJMJP95uW/tTW4w=; b=RrgV0OOY8NE55TAq7S2uY6nn4o5i2ruSHj7bHNsx+mIc7sJpca38f5Vu5/wTF4ybg3 9TT/4Dq4wuSHqMAfVeIoEhe/Qv9ZWTzueFKs/WdqKK540CCJ3QZ4l0iToxxp91fIkKwe 2Vi+GTz7g0Ird3h4lfQJ5hPhXlBJMNm4Ls4y4= Received: by 10.68.71.193 with SMTP id x1mr9536428pbu.132.1316777115629; Fri, 23 Sep 2011 04:25:15 -0700 (PDT) Received: from obol602.omnitel.it (tor-exit-readme-2wh2.kromyon.net. [209.236.66.137]) by mx.google.com with ESMTPS id n10sm37490998pbe.4.2011.09.23.04.25.08 (version=SSLv3 cipher=OTHER); Fri, 23 Sep 2011 04:25:14 -0700 (PDT) From: Frediano Ziglio To: kwolf@redhat.com Date: Fri, 23 Sep 2011 13:25:56 +0200 Message-Id: <1316777156-21477-1-git-send-email-freddy77@gmail.com> X-Mailer: git-send-email 1.7.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.161.173 Cc: qemu-devel@nongnu.org, Frediano Ziglio Subject: [Qemu-devel] [PATCH] qcow2: fix 028 iotest 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 This fix bound check bug accessing last cluster if image size is not cluster aligned caused by "Unlock during COW" patch. Signed-off-by: Frediano Ziglio --- block/qcow2-cluster.c | 8 ++++++-- block/qcow2.c | 2 +- block/qcow2.h | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index c9a1b1c..78e1b49 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -295,16 +295,20 @@ static int copy_sectors(BlockDriverState *bs, uint64_t start_sect, BDRVQcowState *s = bs->opaque; int n, ret; void *buf; + QEMUIOVector qiov; + struct iovec iov; n = n_end - n_start; if (n <= 0) { return 0; } - buf = qemu_blockalign(bs, n * BDRV_SECTOR_SIZE); + iov.iov_base = buf = qemu_blockalign(bs, n * BDRV_SECTOR_SIZE); + iov.iov_len = n * BDRV_SECTOR_SIZE; + qemu_iovec_init_external(&qiov, &iov, 1); BLKDBG_EVENT(bs->file, BLKDBG_COW_READ); - ret = bdrv_read(bs, start_sect + n_start, buf, n); + ret = qcow2_co_readv(bs, start_sect + n_start, n, &qiov); if (ret < 0) { goto out; } diff --git a/block/qcow2.c b/block/qcow2.c index 510ff68..fd90881 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -376,7 +376,7 @@ int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, return n1; } -static int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num, +int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num, int remaining_sectors, QEMUIOVector *qiov) { BDRVQcowState *s = bs->opaque; diff --git a/block/qcow2.h b/block/qcow2.h index 531af39..7f5ff42 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -176,6 +176,8 @@ static inline int64_t align_offset(int64_t offset, int n) /* qcow2.c functions */ int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov, int64_t sector_num, int nb_sectors); +int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num, + int remaining_sectors, QEMUIOVector *qiov); /* qcow2-refcount.c functions */ int qcow2_refcount_init(BlockDriverState *bs);