From patchwork Tue Jun 21 09:21:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9190035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E05E06075E for ; Tue, 21 Jun 2016 09:26:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE6DA28047 for ; Tue, 21 Jun 2016 09:26:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2A1728066; Tue, 21 Jun 2016 09:26:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 9207C28047 for ; Tue, 21 Jun 2016 09:26:55 +0000 (UTC) Received: from localhost ([::1]:50071 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFHxO-0000kF-MH for patchwork-qemu-devel@patchwork.kernel.org; Tue, 21 Jun 2016 05:26:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFHsb-0002ra-G1 for qemu-devel@nongnu.org; Tue, 21 Jun 2016 05:22:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFHsZ-0000DU-7d for qemu-devel@nongnu.org; Tue, 21 Jun 2016 05:21:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFHsO-00009U-7v; Tue, 21 Jun 2016 05:21:44 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 CAD29C0467E5; Tue, 21 Jun 2016 09:21:43 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-68.ams2.redhat.com [10.36.116.68]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5L9LdJ5020173; Tue, 21 Jun 2016 05:21:42 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 21 Jun 2016 11:21:18 +0200 Message-Id: <1466500894-9710-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1466500894-9710-1-git-send-email-kwolf@redhat.com> References: <1466500894-9710-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 21 Jun 2016 09:21:43 +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] [PATCH 01/17] vvfat: Use BdrvChild for s->qcow 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, famz@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP vvfat uses a temporary qcow file to cache written data in read-write mode. In order to do things properly, this should show up in the BDS graph and I/O should go through BdrvChild like for every other node. Signed-off-by: Kevin Wolf --- block/vvfat.c | 66 ++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 6d2e21c..2eb2536 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -344,9 +344,8 @@ typedef struct BDRVVVFATState { unsigned int current_cluster; /* write support */ - BlockDriverState* write_target; char* qcow_filename; - BlockDriverState* qcow; + BdrvChild* qcow; void* fat2; char* used_clusters; array_t commits; @@ -984,7 +983,7 @@ static int init_directories(BDRVVVFATState* s, static BDRVVVFATState *vvv = NULL; #endif -static int enable_write_target(BDRVVVFATState *s, Error **errp); +static int enable_write_target(BlockDriverState *bs, Error **errp); static int is_consistent(BDRVVVFATState *s); static QemuOptsList runtime_opts = { @@ -1162,7 +1161,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, /* read only is the default for safety */ bs->read_only = 1; - s->qcow = s->write_target = NULL; + s->qcow = NULL; s->qcow_filename = NULL; s->fat2 = NULL; s->downcase_short_names = 1; @@ -1173,7 +1172,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags, s->sector_count = cyls * heads * secs - (s->first_sectors_number - 1); if (qemu_opt_get_bool(opts, "rw", false)) { - ret = enable_write_target(s, errp); + ret = enable_write_target(bs, errp); if (ret < 0) { goto fail; } @@ -1390,9 +1389,10 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num, return -1; if (s->qcow) { int n; - if (bdrv_is_allocated(s->qcow, sector_num, nb_sectors-i, &n)) { -DLOG(fprintf(stderr, "sectors %d+%d allocated\n", (int)sector_num, n)); - if (bdrv_read(s->qcow, sector_num, buf + i*0x200, n)) { + if (bdrv_is_allocated(s->qcow->bs, sector_num, nb_sectors-i, &n)) { + DLOG(fprintf(stderr, "sectors %d+%d allocated\n", + (int)sector_num, n)); + if (bdrv_read(s->qcow->bs, sector_num, buf + i*0x200, n)) { return -1; } i += n - 1; @@ -1668,12 +1668,15 @@ static inline int cluster_was_modified(BDRVVVFATState* s, uint32_t cluster_num) int was_modified = 0; int i, dummy; - if (s->qcow == NULL) - return 0; + if (s->qcow == NULL) { + return 0; + } - for (i = 0; !was_modified && i < s->sectors_per_cluster; i++) - was_modified = bdrv_is_allocated(s->qcow, - cluster2sector(s, cluster_num) + i, 1, &dummy); + for (i = 0; !was_modified && i < s->sectors_per_cluster; i++) { + was_modified = bdrv_is_allocated(s->qcow->bs, + cluster2sector(s, cluster_num) + i, + 1, &dummy); + } return was_modified; } @@ -1822,11 +1825,17 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, vvfat_close_current_file(s); for (i = 0; i < s->sectors_per_cluster; i++) { - if (!bdrv_is_allocated(s->qcow, offset + i, 1, &dummy)) { - if (vvfat_read(s->bs, offset, s->cluster_buffer, 1)) { + int res; + + res = bdrv_is_allocated(s->qcow->bs, offset + i, 1, &dummy); + if (!res) { + res = vvfat_read(s->bs, offset, s->cluster_buffer, 1); + if (res) { return -1; } - if (bdrv_write(s->qcow, offset, s->cluster_buffer, 1)) { + res = bdrv_write(s->qcow->bs, offset, + s->cluster_buffer, 1); + if (res) { return -2; } } @@ -2782,8 +2791,8 @@ static int do_commit(BDRVVVFATState* s) return ret; } - if (s->qcow->drv->bdrv_make_empty) { - s->qcow->drv->bdrv_make_empty(s->qcow); + if (s->qcow->bs->drv->bdrv_make_empty) { + s->qcow->bs->drv->bdrv_make_empty(s->qcow->bs); } memset(s->used_clusters, 0, sector2cluster(s, s->sector_count)); @@ -2879,7 +2888,7 @@ DLOG(checkpoint()); * Use qcow backend. Commit later. */ DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, nb_sectors)); - ret = bdrv_write(s->qcow, sector_num, buf, nb_sectors); + ret = bdrv_write(s->qcow->bs, sector_num, buf, nb_sectors); if (ret < 0) { fprintf(stderr, "Error writing to qcow backend\n"); return ret; @@ -2949,7 +2958,7 @@ write_target_commit(BlockDriverState *bs, uint64_t offset, uint64_t bytes, static void write_target_close(BlockDriverState *bs) { BDRVVVFATState* s = *((BDRVVVFATState**) bs->opaque); - bdrv_unref(s->qcow); + bdrv_unref_child(NULL, s->qcow); g_free(s->qcow_filename); } @@ -2959,8 +2968,19 @@ static BlockDriver vvfat_write_target = { .bdrv_close = write_target_close, }; -static int enable_write_target(BDRVVVFATState *s, Error **errp) +static void vvfat_qcow_options(int *child_flags, QDict *child_options, + int parent_flags, QDict *parent_options) { + *child_flags = BDRV_O_RDWR | BDRV_O_NO_FLUSH; +} + +const BdrvChildRole child_vvfat_qcow = { + .inherit_options = vvfat_qcow_options, +}; + +static int enable_write_target(BlockDriverState *bs, Error **errp) +{ + BDRVVVFATState *s = bs->opaque; BlockDriver *bdrv_qcow = NULL; BlockDriverState *backing; QemuOpts *opts = NULL; @@ -2999,8 +3019,8 @@ static int enable_write_target(BDRVVVFATState *s, Error **errp) options = qdict_new(); qdict_put(options, "driver", qstring_from_str("qcow")); - s->qcow = bdrv_open(s->qcow_filename, NULL, options, - BDRV_O_RDWR | BDRV_O_NO_FLUSH, errp); + s->qcow = bdrv_open_child(s->qcow_filename, options, "qcow", bs, + &child_vvfat_qcow, false, errp); if (!s->qcow) { ret = -EINVAL; goto err;