From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387624847608.022844474229; Tue, 18 Jul 2017 07:20:24 -0700 (PDT) Received: from localhost ([::1]:56782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTMN-000273-HN for importer@patchew.org; Tue, 18 Jul 2017 10:20:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKO-0000JX-9u for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKN-0007WW-7L for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47047) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKJ-0007SA-Tf; Tue, 18 Jul 2017 10:18:16 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD9F4C0587C4; Tue, 18 Jul 2017 14:18:14 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2CCA6F940; Tue, 18 Jul 2017 14:18:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DD9F4C0587C4 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DD9F4C0587C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:46 +0200 Message-Id: <1500387486-5469-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Jul 2017 14:18:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 01/21] commit: Add NULL check for overlay_bs 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" I can't see how overlay_bs could become NULL with the current code, but other code in this function already checks it and we can make Coverity happy with this check, so let's add it. Cc: qemu-stable@nongnu.org Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- block/commit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/commit.c b/block/commit.c index 1314360..5cc910f 100644 --- a/block/commit.c +++ b/block/commit.c @@ -90,7 +90,9 @@ static void commit_complete(BlockJob *job, void *opaque) =20 /* Make sure overlay_bs and top stay around until bdrv_set_backing_hd(= ) */ bdrv_ref(top); - bdrv_ref(overlay_bs); + if (overlay_bs) { + bdrv_ref(overlay_bs); + } =20 /* Remove base node parent that still uses BLK_PERM_WRITE/RESIZE before * the normal backing chain can be restored. */ --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387626008295.32198952457156; Tue, 18 Jul 2017 07:20:26 -0700 (PDT) Received: from localhost ([::1]:56781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTMJ-0001zr-Tm for importer@patchew.org; Tue, 18 Jul 2017 10:20:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKQ-0000L0-0N for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKO-0007Y0-KK for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKL-0007TT-9k; Tue, 18 Jul 2017 10:18:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4927B7A160; Tue, 18 Jul 2017 14:18:16 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A3916F940; Tue, 18 Jul 2017 14:18:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4927B7A160 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4927B7A160 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:47 +0200 Message-Id: <1500387486-5469-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 18 Jul 2017 14:18:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 02/21] block: add clock_type field to ThrottleGroup 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis Clock type in throttling is currently inferred by the ThrottleTimer's clock type even though it is a per-ThrottleGroup property; it doesn't make sense to have different clock types in the same group. Moving this to a field in ThrottleGroup can simplify some of the throttle functions. Signed-off-by: Manos Pitsidianakis Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/throttle-groups.c | 20 ++++++++++---------- fsdev/qemu-fsdev-throttle.c | 2 +- include/qemu/throttle.h | 1 + tests/test-throttle.c | 4 ++-- util/throttle.c | 4 +++- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index da2b490..71af3f7 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -61,6 +61,7 @@ typedef struct ThrottleGroup { QLIST_HEAD(, BlockBackendPublic) head; BlockBackend *tokens[2]; bool any_timer_armed[2]; + QEMUClockType clock_type; =20 /* These two are protected by the global throttle_groups_lock */ unsigned refcount; @@ -98,6 +99,12 @@ ThrottleState *throttle_group_incref(const char *name) if (!tg) { tg =3D g_new0(ThrottleGroup, 1); tg->name =3D g_strdup(name); + tg->clock_type =3D QEMU_CLOCK_REALTIME; + + if (qtest_enabled()) { + /* For testing block IO throttling only */ + tg->clock_type =3D QEMU_CLOCK_VIRTUAL; + } qemu_mutex_init(&tg->lock); throttle_init(&tg->ts); QLIST_INIT(&tg->head); @@ -310,7 +317,7 @@ static void schedule_next_request(BlockBackend *blk, bo= ol is_write) token =3D blk; } else { ThrottleTimers *tt =3D &blk_get_public(token)->throttle_timers; - int64_t now =3D qemu_clock_get_ns(tt->clock_type); + int64_t now =3D qemu_clock_get_ns(tg->clock_type); timer_mod(tt->timers[is_write], now); tg->any_timer_armed[is_write] =3D true; } @@ -430,7 +437,7 @@ void throttle_group_config(BlockBackend *blk, ThrottleC= onfig *cfg) if (timer_pending(tt->timers[1])) { tg->any_timer_armed[1] =3D false; } - throttle_config(ts, tt, cfg); + throttle_config(ts, tg->clock_type, tt, cfg); qemu_mutex_unlock(&tg->lock); =20 throttle_group_restart_blk(blk); @@ -497,13 +504,6 @@ void throttle_group_register_blk(BlockBackend *blk, co= nst char *groupname) BlockBackendPublic *blkp =3D blk_get_public(blk); ThrottleState *ts =3D throttle_group_incref(groupname); ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); - int clock_type =3D QEMU_CLOCK_REALTIME; - - if (qtest_enabled()) { - /* For testing block IO throttling only */ - clock_type =3D QEMU_CLOCK_VIRTUAL; - } - blkp->throttle_state =3D ts; =20 qemu_mutex_lock(&tg->lock); @@ -518,7 +518,7 @@ void throttle_group_register_blk(BlockBackend *blk, con= st char *groupname) =20 throttle_timers_init(&blkp->throttle_timers, blk_get_aio_context(blk), - clock_type, + tg->clock_type, read_timer_cb, write_timer_cb, blk); diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 7ae4e86..453fb1e 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -86,7 +86,7 @@ void fsdev_throttle_init(FsThrottle *fst) fsdev_throttle_read_timer_cb, fsdev_throttle_write_timer_cb, fst); - throttle_config(&fst->ts, &fst->tt, &fst->cfg); + throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->tt, &fst->cfg= ); qemu_co_queue_init(&fst->throttled_reqs[0]); qemu_co_queue_init(&fst->throttled_reqs[1]); } diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 9109657..8d2fd77 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -139,6 +139,7 @@ bool throttle_enabled(ThrottleConfig *cfg); bool throttle_is_valid(ThrottleConfig *cfg, Error **errp); =20 void throttle_config(ThrottleState *ts, + QEMUClockType clock_type, ThrottleTimers *tt, ThrottleConfig *cfg); =20 diff --git a/tests/test-throttle.c b/tests/test-throttle.c index a9201b1..2d9cd46 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -228,7 +228,7 @@ static void test_config_functions(void) read_timer_cb, write_timer_cb, &ts); /* structure reset by throttle_init previous_leak should be null */ g_assert(!ts.previous_leak); - throttle_config(&ts, &tt, &orig_cfg); + throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &orig_cfg); =20 /* has previous leak been initialized by throttle_config ? */ g_assert(ts.previous_leak); @@ -486,7 +486,7 @@ static bool do_test_accounting(bool is_ops, /* are we t= esting bps or ops */ throttle_init(&ts); throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, read_timer_cb, write_timer_cb, &ts); - throttle_config(&ts, &tt, &cfg); + throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &cfg); =20 /* account a read */ throttle_account(&ts, false, size); diff --git a/util/throttle.c b/util/throttle.c index 3570ed2..3e94807 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -399,10 +399,12 @@ static void throttle_cancel_timer(QEMUTimer *timer) /* Used to configure the throttle * * @ts: the throttle state we are working on + * @clock_type: the group's clock_type * @tt: the throttle timers we use in this aio context * @cfg: the config to set */ void throttle_config(ThrottleState *ts, + QEMUClockType clock_type, ThrottleTimers *tt, ThrottleConfig *cfg) { @@ -414,7 +416,7 @@ void throttle_config(ThrottleState *ts, throttle_fix_bucket(&ts->cfg.buckets[i]); } =20 - ts->previous_leak =3D qemu_clock_get_ns(tt->clock_type); + ts->previous_leak =3D qemu_clock_get_ns(clock_type); =20 for (i =3D 0; i < 2; i++) { throttle_cancel_timer(tt->timers[i]); --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387636702460.1921745006198; Tue, 18 Jul 2017 07:20:36 -0700 (PDT) Received: from localhost ([::1]:56784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTMV-0002E8-D4 for importer@patchew.org; Tue, 18 Jul 2017 10:20:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKR-0000MB-0z for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKP-0007Yk-Ji for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKM-0007Uz-JV; Tue, 18 Jul 2017 10:18:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 984B67F3E4; Tue, 18 Jul 2017 14:18:17 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8947C7EF5F; Tue, 18 Jul 2017 14:18:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 984B67F3E4 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 984B67F3E4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:48 +0200 Message-Id: <1500387486-5469-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 18 Jul 2017 14:18:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 03/21] block: remove timer canceling in throttle_config() 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Manos Pitsidianakis throttle_config() cancels the timers of the calling BlockBackend. This doesn't make sense because other BlockBackends in the group remain untouched. There's no need to cancel the timers in the one specific BlockBackend so let's not do that. Throttled requests will run as scheduled and future requests will follow the new configuration. This also allows a throttle group's configuration to be changed even when it has no members. Signed-off-by: Manos Pitsidianakis Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/throttle-groups.c | 10 +--------- fsdev/qemu-fsdev-throttle.c | 2 +- include/qemu/throttle.h | 1 - tests/test-throttle.c | 4 ++-- util/throttle.c | 14 -------------- 5 files changed, 4 insertions(+), 27 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 71af3f7..890bfde 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -426,18 +426,10 @@ void throttle_group_restart_blk(BlockBackend *blk) void throttle_group_config(BlockBackend *blk, ThrottleConfig *cfg) { BlockBackendPublic *blkp =3D blk_get_public(blk); - ThrottleTimers *tt =3D &blkp->throttle_timers; ThrottleState *ts =3D blkp->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); qemu_mutex_lock(&tg->lock); - /* throttle_config() cancels the timers */ - if (timer_pending(tt->timers[0])) { - tg->any_timer_armed[0] =3D false; - } - if (timer_pending(tt->timers[1])) { - tg->any_timer_armed[1] =3D false; - } - throttle_config(ts, tg->clock_type, tt, cfg); + throttle_config(ts, tg->clock_type, cfg); qemu_mutex_unlock(&tg->lock); =20 throttle_group_restart_blk(blk); diff --git a/fsdev/qemu-fsdev-throttle.c b/fsdev/qemu-fsdev-throttle.c index 453fb1e..49eebb5 100644 --- a/fsdev/qemu-fsdev-throttle.c +++ b/fsdev/qemu-fsdev-throttle.c @@ -86,7 +86,7 @@ void fsdev_throttle_init(FsThrottle *fst) fsdev_throttle_read_timer_cb, fsdev_throttle_write_timer_cb, fst); - throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->tt, &fst->cfg= ); + throttle_config(&fst->ts, QEMU_CLOCK_REALTIME, &fst->cfg); qemu_co_queue_init(&fst->throttled_reqs[0]); qemu_co_queue_init(&fst->throttled_reqs[1]); } diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h index 8d2fd77..d056008 100644 --- a/include/qemu/throttle.h +++ b/include/qemu/throttle.h @@ -140,7 +140,6 @@ bool throttle_is_valid(ThrottleConfig *cfg, Error **err= p); =20 void throttle_config(ThrottleState *ts, QEMUClockType clock_type, - ThrottleTimers *tt, ThrottleConfig *cfg); =20 void throttle_get_config(ThrottleState *ts, ThrottleConfig *cfg); diff --git a/tests/test-throttle.c b/tests/test-throttle.c index 2d9cd46..768f11d 100644 --- a/tests/test-throttle.c +++ b/tests/test-throttle.c @@ -228,7 +228,7 @@ static void test_config_functions(void) read_timer_cb, write_timer_cb, &ts); /* structure reset by throttle_init previous_leak should be null */ g_assert(!ts.previous_leak); - throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &orig_cfg); + throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &orig_cfg); =20 /* has previous leak been initialized by throttle_config ? */ g_assert(ts.previous_leak); @@ -486,7 +486,7 @@ static bool do_test_accounting(bool is_ops, /* are we t= esting bps or ops */ throttle_init(&ts); throttle_timers_init(&tt, ctx, QEMU_CLOCK_VIRTUAL, read_timer_cb, write_timer_cb, &ts); - throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &tt, &cfg); + throttle_config(&ts, QEMU_CLOCK_VIRTUAL, &cfg); =20 /* account a read */ throttle_account(&ts, false, size); diff --git a/util/throttle.c b/util/throttle.c index 3e94807..b2a52b8 100644 --- a/util/throttle.c +++ b/util/throttle.c @@ -388,24 +388,14 @@ static void throttle_unfix_bucket(LeakyBucket *bkt) } } =20 -/* take care of canceling a timer */ -static void throttle_cancel_timer(QEMUTimer *timer) -{ - assert(timer !=3D NULL); - - timer_del(timer); -} - /* Used to configure the throttle * * @ts: the throttle state we are working on * @clock_type: the group's clock_type - * @tt: the throttle timers we use in this aio context * @cfg: the config to set */ void throttle_config(ThrottleState *ts, QEMUClockType clock_type, - ThrottleTimers *tt, ThrottleConfig *cfg) { int i; @@ -417,10 +407,6 @@ void throttle_config(ThrottleState *ts, } =20 ts->previous_leak =3D qemu_clock_get_ns(clock_type); - - for (i =3D 0; i < 2; i++) { - throttle_cancel_timer(tt->timers[i]); - } } =20 /* used to get config --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387815446498.508629854638; Tue, 18 Jul 2017 07:23:35 -0700 (PDT) Received: from localhost ([::1]:56809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTPO-0004nR-5l for importer@patchew.org; Tue, 18 Jul 2017 10:23:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKR-0000NE-RQ for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKQ-0007a6-O7 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59464) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKN-0007Wh-V2; Tue, 18 Jul 2017 10:18:20 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E154FC04D294; Tue, 18 Jul 2017 14:18:18 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA0DD7EF5F; Tue, 18 Jul 2017 14:18:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E154FC04D294 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E154FC04D294 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:49 +0200 Message-Id: <1500387486-5469-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Jul 2017 14:18:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 04/21] block/vmdk: Report failures in vmdk_read_cid() 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell The function vmdk_read_cid() can fail if the read on the underlying block device fails, or if there's a format error in the VMDK file. However its API doesn't provide a mechanism to report these errors, and in some cases we were returning a CID of 0 and in some cases a CID of 0xffffffff, either of which might potentially be valid values. Change the function to return 0 on success or a negative errno, and return the CID via a uint32_t* argument. Update the callsites to handle and propagate the error appropriately. This fixes in passing a Coverity-spotted issue (CID 1350038) where we weren't checking the return value from sscanf(). Signed-off-by: Peter Maydell Reviewed-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/vmdk.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 24d71b5..0fc9739 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -242,10 +242,11 @@ static void vmdk_free_last_extent(BlockDriverState *b= s) s->extents =3D g_renew(VmdkExtent, s->extents, s->num_extents); } =20 -static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent) +/* Return -ve errno, or 0 on success and write CID into *pcid. */ +static int vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid) { char *desc; - uint32_t cid =3D 0xffffffff; + uint32_t cid; const char *p_name, *cid_str; size_t cid_str_size; BDRVVmdkState *s =3D bs->opaque; @@ -254,8 +255,7 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int= parent) desc =3D g_malloc0(DESC_SIZE); ret =3D bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE); if (ret < 0) { - g_free(desc); - return 0; + goto out; } =20 if (parent) { @@ -268,13 +268,21 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, i= nt parent) =20 desc[DESC_SIZE - 1] =3D '\0'; p_name =3D strstr(desc, cid_str); - if (p_name !=3D NULL) { - p_name +=3D cid_str_size; - sscanf(p_name, "%" SCNx32, &cid); + if (p_name =3D=3D NULL) { + ret =3D -EINVAL; + goto out; } + p_name +=3D cid_str_size; + if (sscanf(p_name, "%" SCNx32, &cid) !=3D 1) { + ret =3D -EINVAL; + goto out; + } + *pcid =3D cid; + ret =3D 0; =20 +out: g_free(desc); - return cid; + return ret; } =20 static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid) @@ -322,7 +330,10 @@ static int vmdk_is_cid_valid(BlockDriverState *bs) if (!s->cid_checked && bs->backing) { BlockDriverState *p_bs =3D bs->backing->bs; =20 - cur_pcid =3D vmdk_read_cid(p_bs, 0); + if (vmdk_read_cid(p_bs, 0, &cur_pcid) !=3D 0) { + /* read failure: report as not valid */ + return 0; + } if (s->parent_cid !=3D cur_pcid) { /* CID not valid */ return 0; @@ -975,8 +986,14 @@ static int vmdk_open(BlockDriverState *bs, QDict *opti= ons, int flags, if (ret) { goto fail; } - s->cid =3D vmdk_read_cid(bs, 0); - s->parent_cid =3D vmdk_read_cid(bs, 1); + ret =3D vmdk_read_cid(bs, 0, &s->cid); + if (ret) { + goto fail; + } + ret =3D vmdk_read_cid(bs, 1, &s->parent_cid); + if (ret) { + goto fail; + } qemu_co_mutex_init(&s->lock); =20 /* Disable migration when VMDK images are used */ @@ -2008,8 +2025,11 @@ static int vmdk_create(const char *filename, QemuOpt= s *opts, Error **errp) ret =3D -EINVAL; goto exit; } - parent_cid =3D vmdk_read_cid(blk_bs(blk), 0); + ret =3D vmdk_read_cid(blk_bs(blk), 0, &parent_cid); blk_unref(blk); + if (ret) { + goto exit; + } snprintf(parent_desc_line, BUF_SIZE, "parentFileNameHint=3D\"%s\"", backing_file); } --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387786919371.04078928663944; Tue, 18 Jul 2017 07:23:06 -0700 (PDT) Received: from localhost ([::1]:56804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTOx-0004Q7-Ot for importer@patchew.org; Tue, 18 Jul 2017 10:23:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKV-0000Rn-RG for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKS-0007br-P4 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40774) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKP-0007YI-NZ; Tue, 18 Jul 2017 10:18:21 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6531F2F86C4; Tue, 18 Jul 2017 14:18:20 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EFE97EF7F; Tue, 18 Jul 2017 14:18:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6531F2F86C4 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6531F2F86C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:50 +0200 Message-Id: <1500387486-5469-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 18 Jul 2017 14:18:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 05/21] block/vpc.c: Handle write failures in get_image_offset() 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell Coverity (CID 1355236) points out that get_image_offset() doesn't check that it actually succeeded in writing the updated block bitmap to the file. Check the error return from bdrv_pwrite_sync() and propagate an error response back up to the function which calls get_image_offset() for a write so that it can return the error to its caller. get_sector_offset() is only used for reads, but we move it to the same API for consistency. Signed-off-by: Peter Maydell Signed-off-by: Kevin Wolf --- block/vpc.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index 8057d42..10e6519 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -460,17 +460,23 @@ static int vpc_reopen_prepare(BDRVReopenState *state, /* * Returns the absolute byte offset of the given sector in the image file. * If the sector is not allocated, -1 is returned instead. + * If an error occurred trying to write an updated block bitmap back to + * the file, -2 is returned, and the error value is written to *err. + * This can only happen for a write operation. * * The parameter write must be 1 if the offset will be used for a write * operation (the block bitmaps is updated then), 0 otherwise. + * If write is true then err must not be NULL. */ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offs= et, - bool write) + bool write, int *err) { BDRVVPCState *s =3D bs->opaque; uint64_t bitmap_offset, block_offset; uint32_t pagetable_index, offset_in_block; =20 + assert(!(write && err =3D=3D NULL)); + pagetable_index =3D offset / s->block_size; offset_in_block =3D offset % s->block_size; =20 @@ -487,10 +493,15 @@ static inline int64_t get_image_offset(BlockDriverSta= te *bs, uint64_t offset, correctness. */ if (write && (s->last_bitmap_offset !=3D bitmap_offset)) { uint8_t bitmap[s->bitmap_size]; + int r; =20 s->last_bitmap_offset =3D bitmap_offset; memset(bitmap, 0xff, s->bitmap_size); - bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size); + r =3D bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_= size); + if (r < 0) { + *err =3D r; + return -2; + } } =20 return block_offset; @@ -561,7 +572,7 @@ static int64_t alloc_block(BlockDriverState* bs, int64_= t offset) if (ret < 0) goto fail; =20 - return get_image_offset(bs, offset, false); + return get_image_offset(bs, offset, false, NULL); =20 fail: s->free_data_block_offset -=3D (s->block_size + s->bitmap_size); @@ -601,7 +612,7 @@ vpc_co_preadv(BlockDriverState *bs, uint64_t offset, ui= nt64_t bytes, qemu_iovec_init(&local_qiov, qiov->niov); =20 while (bytes > 0) { - image_offset =3D get_image_offset(bs, offset, false); + image_offset =3D get_image_offset(bs, offset, false, NULL); n_bytes =3D MIN(bytes, s->block_size - (offset % s->block_size)); =20 if (image_offset =3D=3D -1) { @@ -650,7 +661,11 @@ vpc_co_pwritev(BlockDriverState *bs, uint64_t offset, = uint64_t bytes, qemu_iovec_init(&local_qiov, qiov->niov); =20 while (bytes > 0) { - image_offset =3D get_image_offset(bs, offset, true); + image_offset =3D get_image_offset(bs, offset, true, &ret); + if (image_offset =3D=3D -2) { + /* Failed to write block bitmap: can't proceed with write */ + goto fail; + } n_bytes =3D MIN(bytes, s->block_size - (offset % s->block_size)); =20 if (image_offset =3D=3D -1) { @@ -702,7 +717,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(Blo= ckDriverState *bs, =20 qemu_co_mutex_lock(&s->lock); =20 - offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, false); + offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, false,= NULL); start =3D offset; allocated =3D (offset !=3D -1); *pnum =3D 0; @@ -727,7 +742,8 @@ static int64_t coroutine_fn vpc_co_get_block_status(Blo= ckDriverState *bs, if (nb_sectors =3D=3D 0) { break; } - offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, fa= lse); + offset =3D get_image_offset(bs, sector_num << BDRV_SECTOR_BITS, fa= lse, + NULL); } while (offset =3D=3D -1); =20 qemu_co_mutex_unlock(&s->lock); --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387935358604.8002819751019; Tue, 18 Jul 2017 07:25:35 -0700 (PDT) Received: from localhost ([::1]:56820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTRN-0006pP-0w for importer@patchew.org; Tue, 18 Jul 2017 10:25:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKW-0000T1-SW for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKS-0007cB-W6 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45708) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKQ-0007Zd-Pc; Tue, 18 Jul 2017 10:18:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C37D0C058EBF; Tue, 18 Jul 2017 14:18:21 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9626E7EF5F; Tue, 18 Jul 2017 14:18:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C37D0C058EBF Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C37D0C058EBF From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:51 +0200 Message-Id: <1500387486-5469-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Jul 2017 14:18:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 06/21] block: Make blk_get_attached_dev_id() public 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow --- block/block-backend.c | 3 +-- include/sysemu/block-backend.h | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index fe3542b..8171270 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -83,7 +83,6 @@ static const AIOCBInfo block_backend_aiocb_info =3D { =20 static void drive_info_del(DriveInfo *dinfo); static BlockBackend *bdrv_first_blk(BlockDriverState *bs); -static char *blk_get_attached_dev_id(BlockBackend *blk); =20 /* All BlockBackends */ static QTAILQ_HEAD(, BlockBackend) block_backends =3D @@ -726,7 +725,7 @@ void *blk_get_attached_dev(BlockBackend *blk) =20 /* Return the qdev ID, or if no ID is assigned the QOM path, of the block * device attached to the BlockBackend. */ -static char *blk_get_attached_dev_id(BlockBackend *blk) +char *blk_get_attached_dev_id(BlockBackend *blk) { DeviceState *dev; =20 diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index d9ea0cd..fe47799 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -126,6 +126,7 @@ int blk_attach_dev(BlockBackend *blk, DeviceState *dev); void blk_attach_dev_legacy(BlockBackend *blk, void *dev); void blk_detach_dev(BlockBackend *blk, void *dev); void *blk_get_attached_dev(BlockBackend *blk); +char *blk_get_attached_dev_id(BlockBackend *blk); BlockBackend *blk_by_dev(void *dev); BlockBackend *blk_by_qdev_id(const char *id, Error **errp); void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaq= ue); --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388115809813.4627713233548; Tue, 18 Jul 2017 07:28:35 -0700 (PDT) Received: from localhost ([::1]:56835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTUH-0001Ub-Aj for importer@patchew.org; Tue, 18 Jul 2017 10:28:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKY-0000Ud-By for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKX-0007fm-56 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKS-0007aa-5f; Tue, 18 Jul 2017 10:18:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 181262F86D3; Tue, 18 Jul 2017 14:18:23 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C7496F940; Tue, 18 Jul 2017 14:18:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 181262F86D3 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 181262F86D3 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:52 +0200 Message-Id: <1500387486-5469-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 18 Jul 2017 14:18:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/21] block/qapi: Add qdev device name to query-block 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With -blockdev/-device, users can indirectly create anonymous BlockBackends, while the state of such backends is still of interest. As a preparation for making such BBs visible in query-block, make sure that they can be identified even without a name by adding the ID/QOM path of their qdev device to BlockInfo. Signed-off-by: Kevin Wolf Reviewed-by: John Snow --- block/qapi.c | 10 ++++++++++ hmp.c | 3 +++ qapi/block-core.json | 9 ++++++++- tests/qemu-iotests/067.out | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/block/qapi.c b/block/qapi.c index 080eb8f..c8a45ec 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -322,11 +322,21 @@ static void bdrv_query_info(BlockBackend *blk, BlockI= nfo **p_info, { BlockInfo *info =3D g_malloc0(sizeof(*info)); BlockDriverState *bs =3D blk_bs(blk); + char *qdev; + info->device =3D g_strdup(blk_name(blk)); info->type =3D g_strdup("unknown"); info->locked =3D blk_dev_is_medium_locked(blk); info->removable =3D blk_dev_has_removable_media(blk); =20 + qdev =3D blk_get_attached_dev_id(blk); + if (qdev && *qdev) { + info->has_qdev =3D true; + info->qdev =3D qdev; + } else { + g_free(qdev); + } + if (blk_dev_has_tray(blk)) { info->has_tray_open =3D true; info->tray_open =3D blk_dev_is_tray_open(blk); diff --git a/hmp.c b/hmp.c index b42ae59..0e57f47 100644 --- a/hmp.c +++ b/hmp.c @@ -425,6 +425,9 @@ static void print_block_info(Monitor *mon, BlockInfo *i= nfo, } =20 if (info) { + if (info->has_qdev) { + monitor_printf(mon, " Attached to: %s\n", info->qdev); + } if (info->has_io_status && info->io_status !=3D BLOCK_DEVICE_IO_ST= ATUS_OK) { monitor_printf(mon, " I/O status: %s\n", BlockDeviceIoStatus_lookup[info->io_status]); diff --git a/qapi/block-core.json b/qapi/block-core.json index c437aa5..ff8e2ba 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -457,6 +457,9 @@ # # @device: The device name associated with the virtual device. # +# @qdev: The qdev ID, or if no ID is assigned, the QOM path of the block +# device. (since 2.10) +# # @type: This field is returned only for compatibility reasons, it should # not be used (always returns 'unknown') # @@ -482,7 +485,7 @@ # Since: 0.14.0 ## { 'struct': 'BlockInfo', - 'data': {'device': 'str', 'type': 'str', 'removable': 'bool', + 'data': {'device': 'str', '*qdev': 'str', 'type': 'str', 'removable': 'b= ool', 'locked': 'bool', '*inserted': 'BlockDeviceInfo', '*tray_open': 'bool', '*io-status': 'BlockDeviceIoStatus', '*dirty-bitmaps': ['BlockDirtyInfo'] } } @@ -577,6 +580,7 @@ # } # } # }, +# "qdev": "ide_disk", # "type":"unknown" # }, # { @@ -584,12 +588,15 @@ # "device":"ide1-cd0", # "locked":false, # "removable":true, +# "qdev": "/machine/unattached/device[23]", +# "tray_open": false, # "type":"unknown" # }, # { # "device":"floppy0", # "locked":false, # "removable":true, +# "qdev": "/machine/unattached/device[20]", # "type":"unknown" # }, # { diff --git a/tests/qemu-iotests/067.out b/tests/qemu-iotests/067.out index 782eae2..e3c4496 100644 --- a/tests/qemu-iotests/067.out +++ b/tests/qemu-iotests/067.out @@ -57,6 +57,7 @@ Testing: -drive file=3DTEST_DIR/t.qcow2,format=3Dqcow2,if= =3Dnone,id=3Ddisk -device virti "file": "TEST_DIR/t.qcow2", "encryption_key_missing": false }, + "qdev": "/machine/peripheral/virtio0/virtio-backend", "type": "unknown" } ] --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387959029380.2211672498397; Tue, 18 Jul 2017 07:25:59 -0700 (PDT) Received: from localhost ([::1]:56822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTRk-0007HX-Ms for importer@patchew.org; Tue, 18 Jul 2017 10:25:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKX-0000U1-U2 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKW-0007fP-Sm for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30822) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKT-0007cF-LJ; Tue, 18 Jul 2017 10:18:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FD54C0587F1; Tue, 18 Jul 2017 14:18:24 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DCA47EF5F; Tue, 18 Jul 2017 14:18:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9FD54C0587F1 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9FD54C0587F1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:53 +0200 Message-Id: <1500387486-5469-9-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Jul 2017 14:18:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 08/21] block: Make blk_all_next() public 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow --- block/block-backend.c | 2 +- include/sysemu/block-backend.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index 8171270..968438c 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -342,7 +342,7 @@ void blk_unref(BlockBackend *blk) * Behaves similarly to blk_next() but iterates over all BlockBackends, ev= en the * ones which are hidden (i.e. are not referenced by the monitor). */ -static BlockBackend *blk_all_next(BlockBackend *blk) +BlockBackend *blk_all_next(BlockBackend *blk) { return blk ? QTAILQ_NEXT(blk, link) : QTAILQ_FIRST(&block_backends); diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index fe47799..4a37305 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -100,6 +100,7 @@ void blk_remove_all_bs(void); const char *blk_name(const BlockBackend *blk); BlockBackend *blk_by_name(const char *name); BlockBackend *blk_next(BlockBackend *blk); +BlockBackend *blk_all_next(BlockBackend *blk); bool monitor_add_blk(BlockBackend *blk, const char *name, Error **errp); void monitor_remove_blk(BlockBackend *blk); =20 --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387813194152.74280536448236; Tue, 18 Jul 2017 07:23:33 -0700 (PDT) Received: from localhost ([::1]:56807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTPO-0004nG-VS for importer@patchew.org; Tue, 18 Jul 2017 10:23:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKX-0000U3-W5 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKX-0007fe-3Z for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37678) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKU-0007dG-V1; Tue, 18 Jul 2017 10:18:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E63C061E51; Tue, 18 Jul 2017 14:18:25 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF4CD7EF5F; Tue, 18 Jul 2017 14:18:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E63C061E51 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E63C061E51 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:54 +0200 Message-Id: <1500387486-5469-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Jul 2017 14:18:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/21] block/qapi: Use blk_all_next() for query-block 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch replaces the blk_next() loop in query-block by a blk_all_next() one so that we also get access to BlockBackends that aren't owned by the monitor. For now, the next thing we do is check whether each BB has a name, so there is no semantic difference. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow --- block/qapi.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index c8a45ec..164dd2b 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -472,8 +472,14 @@ BlockInfoList *qmp_query_block(Error **errp) BlockBackend *blk; Error *local_err =3D NULL; =20 - for (blk =3D blk_next(NULL); blk; blk =3D blk_next(blk)) { - BlockInfoList *info =3D g_malloc0(sizeof(*info)); + for (blk =3D blk_all_next(NULL); blk; blk =3D blk_all_next(blk)) { + BlockInfoList *info; + + if (!*blk_name(blk)) { + continue; + } + + info =3D g_malloc0(sizeof(*info)); bdrv_query_info(blk, &info->value, &local_err); if (local_err) { error_propagate(errp, local_err); --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388093516612.6254779980117; Tue, 18 Jul 2017 07:28:13 -0700 (PDT) Received: from localhost ([::1]:56833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTTs-00016Q-1q for importer@patchew.org; Tue, 18 Jul 2017 10:28:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKd-0000dH-EZ for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKY-0007hF-PF for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41158) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKW-0007e0-9F; Tue, 18 Jul 2017 10:18:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24FE41C13DF; Tue, 18 Jul 2017 14:18:27 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 322F17EF5F; Tue, 18 Jul 2017 14:18:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 24FE41C13DF Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 24FE41C13DF From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:55 +0200 Message-Id: <1500387486-5469-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 18 Jul 2017 14:18:27 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/21] block: List anonymous device BBs in query-block 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Instead of listing only monitor-owned BlockBackends in query-block, also add those anonymous BlockBackends that are owned by a qdev device and as such under the control of the user. This allows using query-block to inspect BlockBackends for the modern configuration syntax with -blockdev and -device. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow --- block/qapi.c | 2 +- hmp.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/block/qapi.c b/block/qapi.c index 164dd2b..95b2e2d 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -475,7 +475,7 @@ BlockInfoList *qmp_query_block(Error **errp) for (blk =3D blk_all_next(NULL); blk; blk =3D blk_all_next(blk)) { BlockInfoList *info; =20 - if (!*blk_name(blk)) { + if (!*blk_name(blk) && !blk_get_attached_dev(blk)) { continue; } =20 diff --git a/hmp.c b/hmp.c index 0e57f47..bf1de74 100644 --- a/hmp.c +++ b/hmp.c @@ -401,16 +401,16 @@ static void print_block_info(Monitor *mon, BlockInfo = *info, =20 assert(!info || !info->has_inserted || info->inserted =3D=3D inserted); =20 - if (info) { + if (info && *info->device) { monitor_printf(mon, "%s", info->device); if (inserted && inserted->has_node_name) { monitor_printf(mon, " (%s)", inserted->node_name); } } else { - assert(inserted); + assert(info || inserted); monitor_printf(mon, "%s", - inserted->has_node_name - ? inserted->node_name + inserted && inserted->has_node_name ? inserted->nod= e_name + : info && info->has_qdev ? info->qdev : ""); } =20 --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387969922746.7899792193797; Tue, 18 Jul 2017 07:26:09 -0700 (PDT) Received: from localhost ([::1]:56823 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTRv-0007QR-A6 for importer@patchew.org; Tue, 18 Jul 2017 10:26:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKa-0000Wf-Bq for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKZ-0007ho-Ew for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54194) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKX-0007f9-9v; Tue, 18 Jul 2017 10:18:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 51B417C851; Tue, 18 Jul 2017 14:18:28 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 639E27EF5F; Tue, 18 Jul 2017 14:18:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51B417C851 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 51B417C851 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:56 +0200 Message-Id: <1500387486-5469-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 18 Jul 2017 14:18:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 11/21] ide: bdrv_attach_dev() for empty CD-ROM 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If no drive=3D... option is passed (for an empty drive), we don't only lack the BlockBackend normally created by parse_drive(), but we also need to manually call blk_attach_dev(). IDE does not support hot unplug, but if it did, qdev would take care to call the matching blk_detach_dev() on unplug. This fixes at least the bug that such devices didn't show up in query-block, and probably some more problems. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow --- hw/ide/qdev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c index 299e592..cc2f5bd 100644 --- a/hw/ide/qdev.c +++ b/hw/ide/qdev.c @@ -164,6 +164,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind = kind) IDEBus *bus =3D DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus); IDEState *s =3D bus->ifs + dev->unit; Error *err =3D NULL; + int ret; =20 if (!dev->conf.blk) { if (kind !=3D IDE_CD) { @@ -172,6 +173,8 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind = kind) } else { /* Anonymous BlockBackend for an empty drive */ dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); + ret =3D blk_attach_dev(dev->conf.blk, &dev->qdev); + assert(ret =3D=3D 0); } } =20 --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388117603518.0400994995549; Tue, 18 Jul 2017 07:28:37 -0700 (PDT) Received: from localhost ([::1]:56836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTUI-0001Ug-Bb for importer@patchew.org; Tue, 18 Jul 2017 10:28:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKe-0000hD-IS for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKb-0007jG-9M for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKZ-0007h0-19; Tue, 18 Jul 2017 10:18:31 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 143AAC04D2A4; Tue, 18 Jul 2017 14:18:30 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92E1E7EF5F; Tue, 18 Jul 2017 14:18:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 143AAC04D2A4 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 143AAC04D2A4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:57 +0200 Message-Id: <1500387486-5469-13-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Jul 2017 14:18:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/21] scsi-disk: bdrv_attach_dev() for empty CD-ROM 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If no drive=3D... option is passed (for an empty drive), we don't only lack the BlockBackend normally created by parse_drive(), but we also need to manually call blk_attach_dev(). This fixes at least a segfault when unplugging such devices, the bug that they didn't show up in query-block, and probably some more problems. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow --- hw/scsi/scsi-disk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index a53f058..5f1e5e8 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2384,9 +2384,14 @@ static void scsi_hd_realize(SCSIDevice *dev, Error *= *errp) static void scsi_cd_realize(SCSIDevice *dev, Error **errp) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, dev); + int ret; =20 if (!dev->conf.blk) { + /* Anonymous BlockBackend for an empty drive. As we put it into + * dev->conf, qdev takes care of detaching on unplug. */ dev->conf.blk =3D blk_new(0, BLK_PERM_ALL); + ret =3D blk_attach_dev(dev->conf.blk, &dev->qdev); + assert(ret =3D=3D 0); } =20 s->qdev.blocksize =3D 2048; --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388445289719.4586401959632; Tue, 18 Jul 2017 07:34:05 -0700 (PDT) Received: from localhost ([::1]:56872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTZa-0006PW-NU for importer@patchew.org; Tue, 18 Jul 2017 10:34:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKk-0000tk-GQ for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKh-0007oD-82 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2388) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKa-0007i8-CS; Tue, 18 Jul 2017 10:18:32 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 60B547CB9E; Tue, 18 Jul 2017 14:18:31 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5690C7EF5F; Tue, 18 Jul 2017 14:18:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 60B547CB9E Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 60B547CB9E From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:58 +0200 Message-Id: <1500387486-5469-14-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Jul 2017 14:18:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 13/21] qemu-iotests: Test 'info block' 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This test makes sure that all block devices show up on 'info block', with all of the expected information, in different configurations. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow --- tests/qemu-iotests/186 | 147 ++++++++++++++ tests/qemu-iotests/186.out | 489 +++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/group | 1 + 3 files changed, 637 insertions(+) create mode 100755 tests/qemu-iotests/186 create mode 100644 tests/qemu-iotests/186.out diff --git a/tests/qemu-iotests/186 b/tests/qemu-iotests/186 new file mode 100755 index 0000000..ab83ee4 --- /dev/null +++ b/tests/qemu-iotests/186 @@ -0,0 +1,147 @@ +#!/bin/bash +# +# Test 'info block' with all kinds of configurations +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dkwolf@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +if [ "$QEMU_DEFAULT_MACHINE" !=3D "pc" ]; then + _notrun "Requires a PC machine" +fi + +function do_run_qemu() +{ + echo Testing: "$@" + + ( + if ! test -t 0; then + while read cmd; do + echo $cmd + done + fi + echo quit + ) | $QEMU -S -nodefaults -display none -device virtio-scsi-pci -monito= r stdio "$@" + echo +} + +function check_info_block() +{ + echo "info block" | + QEMU_OPTIONS=3D"" do_run_qemu "$@" | _filter_win32 | _filter_hmp | + _filter_qemu | _filter_generated_node_ids +} + + +size=3D64M +_make_test_img $size + +removable=3D"floppy ide-cd scsi-cd" +fixed=3D"ide-hd scsi-hd virtio-blk-pci" + +echo +echo "=3D=3D=3D Empty drives =3D=3D=3D" +echo + +for dev in $removable; do + check_info_block -device $dev + check_info_block -device $dev,id=3Dqdev_id +done + +echo +echo "=3D=3D=3D -blockdev/-device=3D =3D=3D=3D" +echo + +for dev in $fixed $removable; do + check_info_block -blockdev driver=3Dnull-co,node-name=3Dnull -device $= dev,drive=3Dnull + check_info_block -blockdev driver=3Dnull-co,node-name=3Dnull -device $= dev,drive=3Dnull,id=3Dqdev_id +done + +echo +echo "=3D=3D=3D -drive if=3Dnone/-device=3D =3D=3D=3D" +echo + +# This creates two BlockBackends that will show up in 'info block'! +# A monitor-owned one from -drive, and anonymous one from -device +for dev in $fixed $removable; do + check_info_block -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -d= evice $dev,drive=3Dnull,id=3Dqdev_id +done + +echo +echo "=3D=3D=3D -drive if=3Dnone/-device=3D (with medium) =3D=3D= =3D" +echo + +for dev in $fixed $removable; do + check_info_block -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -d= evice $dev,drive=3Dnone0 + check_info_block -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -d= evice $dev,drive=3Dnone0,id=3Dqdev_id +done + +echo +echo "=3D=3D=3D -drive if=3Dnone/-device=3D (without medium) =3D= =3D=3D" +echo + +check_info_block -drive if=3Dnone + +for dev in $removable; do + check_info_block -drive if=3Dnone -device $dev,drive=3Dnone0 + check_info_block -drive if=3Dnone -device $dev,drive=3Dnone0,id=3Dqdev= _id +done + +echo +echo "=3D=3D=3D -drive if=3D... =3D=3D=3D" +echo + +check_info_block -drive if=3Dfloppy +check_info_block -drive if=3Dfloppy,driver=3Dnull-co + +check_info_block -drive if=3Dide,driver=3Dnull-co +check_info_block -drive if=3Dide,media=3Dcdrom +check_info_block -drive if=3Dide,driver=3Dnull-co,media=3Dcdrom + +check_info_block -drive if=3Dscsi,driver=3Dnull-co +check_info_block -drive if=3Dscsi,media=3Dcdrom +check_info_block -drive if=3Dscsi,driver=3Dnull-co,media=3Dcdrom + +check_info_block -drive if=3Dvirtio,driver=3Dnull-co + +check_info_block -drive if=3Dpflash,driver=3Dnull-co,size=3D1M + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/186.out b/tests/qemu-iotests/186.out new file mode 100644 index 0000000..b963b12 --- /dev/null +++ b/tests/qemu-iotests/186.out @@ -0,0 +1,489 @@ +QA output created by 186 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 + +=3D=3D=3D Empty drives =3D=3D=3D + +Testing: -device floppy +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +/machine/peripheral-anon/device[1]: [not inserted] + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -device floppy,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +qdev_id: [not inserted] + Attached to: qdev_id + Removable device: not locked, tray closed +(qemu) quit + +Testing: -device ide-cd +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +/machine/peripheral-anon/device[1]: [not inserted] + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -device ide-cd,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +qdev_id: [not inserted] + Attached to: qdev_id + Removable device: not locked, tray closed +(qemu) quit + +Testing: -device scsi-cd +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +/machine/peripheral-anon/device[1]: [not inserted] + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -device scsi-cd,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +qdev_id: [not inserted] + Attached to: qdev_id + Removable device: not locked, tray closed +(qemu) quit + + +=3D=3D=3D -blockdev/-device=3D =3D=3D=3D + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device ide-hd,drive= =3Dnull +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device ide-hd,drive= =3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: qdev_id + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device scsi-hd,drive= =3Dnull +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device scsi-hd,drive= =3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: qdev_id + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device virtio-blk-pc= i,drive=3Dnull +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1]/virtio-backend + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device virtio-blk-pc= i,drive=3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: /machine/peripheral/qdev_id/virtio-backend + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device floppy,drive= =3Dnull +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device floppy,drive= =3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device ide-cd,drive= =3Dnull +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device ide-cd,drive= =3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device scsi-cd,drive= =3Dnull +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -blockdev driver=3Dnull-co,node-name=3Dnull -device scsi-cd,drive= =3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +null: null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + + +=3D=3D=3D -drive if=3Dnone/-device=3D =3D=3D=3D + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device ide-hd= ,drive=3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Removable device: not locked, tray closed + Cache mode: writeback + +null: null-co:// (null-co) + Attached to: qdev_id + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device scsi-h= d,drive=3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Removable device: not locked, tray closed + Cache mode: writeback + +null: null-co:// (null-co) + Attached to: qdev_id + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device virtio= -blk-pci,drive=3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Removable device: not locked, tray closed + Cache mode: writeback + +null: null-co:// (null-co) + Attached to: /machine/peripheral/qdev_id/virtio-backend + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device floppy= ,drive=3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Removable device: not locked, tray closed + Cache mode: writeback + +null: null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device ide-cd= ,drive=3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Removable device: not locked, tray closed + Cache mode: writeback + +null: null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device scsi-c= d,drive=3Dnull,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Removable device: not locked, tray closed + Cache mode: writeback + +null: null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + + +=3D=3D=3D -drive if=3Dnone/-device=3D (with medium) =3D=3D=3D + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device ide-hd= ,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device ide-hd= ,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: qdev_id + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device scsi-h= d,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device scsi-h= d,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: qdev_id + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device virtio= -blk-pci,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1]/virtio-backend + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device virtio= -blk-pci,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: /machine/peripheral/qdev_id/virtio-backend + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device floppy= ,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device floppy= ,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device ide-cd= ,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device ide-cd= ,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device scsi-c= d,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dnone,driver=3Dnull-co,node-name=3Dnull -device scsi-c= d,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0 (null): null-co:// (null-co) + Attached to: qdev_id + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + + +=3D=3D=3D -drive if=3Dnone/-device=3D (without medium) =3D=3D=3D + +Testing: -drive if=3Dnone +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0: [not inserted] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -drive if=3Dnone -device floppy,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0: [not inserted] + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -drive if=3Dnone -device floppy,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0: [not inserted] + Attached to: qdev_id + Removable device: not locked, tray closed +(qemu) quit + +Testing: -drive if=3Dnone -device ide-cd,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0: [not inserted] + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -drive if=3Dnone -device ide-cd,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0: [not inserted] + Attached to: qdev_id + Removable device: not locked, tray closed +(qemu) quit + +Testing: -drive if=3Dnone -device scsi-cd,drive=3Dnone0 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0: [not inserted] + Attached to: /machine/peripheral-anon/device[1] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -drive if=3Dnone -device scsi-cd,drive=3Dnone0,id=3Dqdev_id +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +none0: [not inserted] + Attached to: qdev_id + Removable device: not locked, tray closed +(qemu) quit + + +=3D=3D=3D -drive if=3D... =3D=3D=3D + +Testing: -drive if=3Dfloppy +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +floppy0: [not inserted] + Attached to: /machine/unattached/device[17] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -drive if=3Dfloppy,driver=3Dnull-co +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +floppy0 (NODE_NAME): null-co:// (null-co) + Attached to: /machine/unattached/device[17] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dide,driver=3Dnull-co +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +ide0-hd0 (NODE_NAME): null-co:// (null-co) + Attached to: /machine/unattached/device[18] + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dide,media=3Dcdrom +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +ide0-cd0: [not inserted] + Attached to: /machine/unattached/device[18] + Removable device: not locked, tray closed +(qemu) quit + +Testing: -drive if=3Dide,driver=3Dnull-co,media=3Dcdrom +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +ide0-cd0 (NODE_NAME): null-co:// (null-co, read-only) + Attached to: /machine/unattached/device[18] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +warning: qemu-system-x86_64: -drive if=3Dscsi,driver=3Dnull-co: bus=3D0,un= it=3D0 is deprecated with this machine type +Testing: -drive if=3Dscsi,driver=3Dnull-co +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +scsi0-hd0 (NODE_NAME): null-co:// (null-co) + Attached to: /machine/unattached/device[27]/scsi.0/legacy[0] + Cache mode: writeback +(qemu) quit + +warning: qemu-system-x86_64: -drive if=3Dscsi,media=3Dcdrom: bus=3D0,unit= =3D0 is deprecated with this machine type +Testing: -drive if=3Dscsi,media=3Dcdrom +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +scsi0-cd0: [not inserted] + Attached to: /machine/unattached/device[27]/scsi.0/legacy[0] + Removable device: not locked, tray closed +(qemu) quit + +warning: qemu-system-x86_64: -drive if=3Dscsi,driver=3Dnull-co,media=3Dcdr= om: bus=3D0,unit=3D0 is deprecated with this machine type +Testing: -drive if=3Dscsi,driver=3Dnull-co,media=3Dcdrom +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +scsi0-cd0 (NODE_NAME): null-co:// (null-co, read-only) + Attached to: /machine/unattached/device[27]/scsi.0/legacy[0] + Removable device: not locked, tray closed + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dvirtio,driver=3Dnull-co +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +virtio0 (NODE_NAME): null-co:// (null-co) + Attached to: /machine/peripheral-anon/device[1]/virtio-backend + Cache mode: writeback +(qemu) quit + +Testing: -drive if=3Dpflash,driver=3Dnull-co,size=3D1M +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) info block +pflash0 (NODE_NAME): json:{"driver": "null-co", "size": "1M"} (null-co) + Attached to: /machine/unattached/device[2] + Cache mode: writeback +(qemu) quit + +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 2aba585..0961f8c 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -181,5 +181,6 @@ 182 rw auto quick 183 rw auto migration 185 rw auto +186 rw auto 188 rw auto quick 189 rw auto quick --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387795404339.55511832878426; Tue, 18 Jul 2017 07:23:15 -0700 (PDT) Received: from localhost ([::1]:56805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTP2-0004V1-Nw for importer@patchew.org; Tue, 18 Jul 2017 10:23:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKg-0000ma-S3 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKf-0007mn-Tm for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48376) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKb-0007j3-Jb; Tue, 18 Jul 2017 10:18:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A2054A6E6; Tue, 18 Jul 2017 14:18:32 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id A05057EF5F; Tue, 18 Jul 2017 14:18:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9A2054A6E6 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9A2054A6E6 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:17:59 +0200 Message-Id: <1500387486-5469-15-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Jul 2017 14:18:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 14/21] qemu-iotests: Test unplug of -device without drive 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This caused an assertion failure until recently because the BlockBackend would be detached on unplug, but was in fact never attached in the first place. Add a regression test. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: John Snow --- tests/qemu-iotests/067 | 13 +++++++++++++ tests/qemu-iotests/067.out | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tests/qemu-iotests/067 b/tests/qemu-iotests/067 index 38d23fc..5d4ca4b 100755 --- a/tests/qemu-iotests/067 +++ b/tests/qemu-iotests/067 @@ -137,6 +137,19 @@ run_qemu < Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388277580585.7158648104029; Tue, 18 Jul 2017 07:31:17 -0700 (PDT) Received: from localhost ([::1]:56860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTWu-00046k-8U for importer@patchew.org; Tue, 18 Jul 2017 10:31:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKg-0000mi-Uo for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKf-0007mv-V7 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKc-0007jw-Qm; Tue, 18 Jul 2017 10:18:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1F4FC058EBD; Tue, 18 Jul 2017 14:18:33 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD4EA7EF5F; Tue, 18 Jul 2017 14:18:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D1F4FC058EBD Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D1F4FC058EBD From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:18:00 +0200 Message-Id: <1500387486-5469-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Jul 2017 14:18:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 15/21] vvfat: add constants for special values of name[0] 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 4dae790..eb266b5 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -71,6 +71,11 @@ void nonono(const char* file, int line, const char* msg)= { =20 #endif =20 +#define DIR_DELETED 0xe5 +#define DIR_KANJI DIR_DELETED +#define DIR_KANJI_FAKE 0x05 +#define DIR_FREE 0x00 + /* dynamic array functions */ typedef struct array_t { char* pointer; @@ -466,7 +471,7 @@ static direntry_t *create_long_filename(BDRVVVFATState = *s, const char *filename) =20 static char is_free(const direntry_t* direntry) { - return direntry->name[0]=3D=3D0xe5 || direntry->name[0]=3D=3D0x00; + return direntry->name[0] =3D=3D DIR_DELETED || direntry->name[0] =3D= =3D DIR_FREE; } =20 static char is_volume_label(const direntry_t* direntry) @@ -487,7 +492,7 @@ static char is_short_name(const direntry_t* direntry) =20 static char is_directory(const direntry_t* direntry) { - return direntry->attributes & 0x10 && direntry->name[0] !=3D 0xe5; + return direntry->attributes & 0x10 && direntry->name[0] !=3D DIR_DELET= ED; } =20 static inline char is_dot(const direntry_t* direntry) @@ -589,8 +594,8 @@ static direntry_t *create_short_filename(BDRVVVFATState= *s, } } =20 - if (entry->name[0] =3D=3D 0xe5) { - entry->name[0] =3D 0x05; + if (entry->name[0] =3D=3D DIR_KANJI) { + entry->name[0] =3D DIR_KANJI_FAKE; } =20 /* numeric-tail generation */ @@ -1748,8 +1753,8 @@ static int parse_short_name(BDRVVVFATState* s, } else lfn->name[i + j + 1] =3D '\0'; =20 - if (lfn->name[0] =3D=3D 0x05) { - lfn->name[0] =3D 0xe5; + if (lfn->name[0] =3D=3D DIR_KANJI_FAKE) { + lfn->name[0] =3D DIR_KANJI; } lfn->len =3D strlen((char*)lfn->name); =20 --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500387943902343.8862110600327; Tue, 18 Jul 2017 07:25:43 -0700 (PDT) Received: from localhost ([::1]:56821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTRU-0006zS-L4 for importer@patchew.org; Tue, 18 Jul 2017 10:25:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKh-0000os-U7 for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKg-0007ni-OC for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60810) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKe-0007kb-19; Tue, 18 Jul 2017 10:18:36 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C990267C6; Tue, 18 Jul 2017 14:18:35 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A9397EF5F; Tue, 18 Jul 2017 14:18:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0C990267C6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0C990267C6 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:18:01 +0200 Message-Id: <1500387486-5469-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 18 Jul 2017 14:18:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/21] vvfat: add a constant for bootsector name 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau Also add links to related compatibility problems. Signed-off-by: Herv=C3=A9 Poussineau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Kevin Wolf --- block/vvfat.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/vvfat.c b/block/vvfat.c index eb266b5..36b4be9 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -71,6 +71,12 @@ void nonono(const char* file, int line, const char* msg)= { =20 #endif =20 +/* bootsector OEM name. see related compatibility problems at: + * https://jdebp.eu/FGA/volume-boot-block-oem-name-field.html + * http://seasip.info/Misc/oemid.html + */ +#define BOOTSECTOR_OEM_NAME "MSWIN4.1" + #define DIR_DELETED 0xe5 #define DIR_KANJI DIR_DELETED #define DIR_KANJI_FAKE 0x05 @@ -1028,7 +1034,7 @@ static int init_directories(BDRVVVFATState* s, bootsector->jump[0]=3D0xeb; bootsector->jump[1]=3D0x3e; bootsector->jump[2]=3D0x90; - memcpy(bootsector->name, "MSWIN4.1", 8); + memcpy(bootsector->name, BOOTSECTOR_OEM_NAME, 8); bootsector->sector_size=3Dcpu_to_le16(0x200); bootsector->sectors_per_cluster=3Ds->sectors_per_cluster; bootsector->reserved_sectors=3Dcpu_to_le16(1); --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388252692636.0954298802278; Tue, 18 Jul 2017 07:30:52 -0700 (PDT) Received: from localhost ([::1]:56858 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTWT-0003kG-At for importer@patchew.org; Tue, 18 Jul 2017 10:30:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKk-0000t6-0A for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKi-0007pS-QW for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38136) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKf-0007lU-21; Tue, 18 Jul 2017 10:18:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1BCAD61BA1; Tue, 18 Jul 2017 14:18:36 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B3B47EF5F; Tue, 18 Jul 2017 14:18:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1BCAD61BA1 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1BCAD61BA1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:18:02 +0200 Message-Id: <1500387486-5469-18-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 18 Jul 2017 14:18:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 17/21] vvfat: correctly parse non-ASCII short and long file names 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau Write support works again when image contains non-ASCII names. It is either= the case when user created a non-ASCII filename, or when initial directory cont= ained a non-ASCII filename (since 0c36111f57ec2188f679e7fa810291b7386bdca1) Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 59 +++++++++++++++++++++++++++++++++++++------------------= ---- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 36b4be9..ea7775f 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1669,6 +1669,7 @@ typedef struct { * filename length is 0x3f * 13 bytes. */ unsigned char name[0x3f * 13 + 1]; + gunichar2 name2[0x3f * 13 + 1]; int checksum, len; int sequence_number; } long_file_name; @@ -1690,16 +1691,21 @@ static int parse_long_name(long_file_name* lfn, return 1; =20 if (pointer[0] & 0x40) { + /* first entry; do some initialization */ lfn->sequence_number =3D pointer[0] & 0x3f; lfn->checksum =3D pointer[13]; lfn->name[0] =3D 0; lfn->name[lfn->sequence_number * 13] =3D 0; - } else if ((pointer[0] & 0x3f) !=3D --lfn->sequence_number) + } else if ((pointer[0] & 0x3f) !=3D --lfn->sequence_number) { + /* not the expected sequence number */ return -1; - else if (pointer[13] !=3D lfn->checksum) + } else if (pointer[13] !=3D lfn->checksum) { + /* not the expected checksum */ return -2; - else if (pointer[12] || pointer[26] || pointer[27]) + } else if (pointer[12] || pointer[26] || pointer[27]) { + /* invalid zero fields */ return -3; + } =20 offset =3D 13 * (lfn->sequence_number - 1); for (i =3D 0, j =3D 1; i < 13; i++, j+=3D2) { @@ -1708,16 +1714,29 @@ static int parse_long_name(long_file_name* lfn, else if (j =3D=3D 26) j =3D 28; =20 - if (pointer[j+1] =3D=3D 0) - lfn->name[offset + i] =3D pointer[j]; - else if (pointer[j+1] !=3D 0xff || (pointer[0] & 0x40) =3D=3D 0) - return -4; - else - lfn->name[offset + i] =3D 0; + if (pointer[j] =3D=3D 0 && pointer[j + 1] =3D=3D 0) { + /* end of long file name */ + break; + } + gunichar2 c =3D (pointer[j + 1] << 8) + pointer[j]; + lfn->name2[offset + i] =3D c; } =20 - if (pointer[0] & 0x40) - lfn->len =3D offset + strlen((char*)lfn->name + offset); + if (pointer[0] & 0x40) { + /* first entry; set len */ + lfn->len =3D offset + i; + } + if ((pointer[0] & 0x3f) =3D=3D 0x01) { + /* last entry; finalize entry */ + glong olen; + gchar *utf8 =3D g_utf16_to_utf8(lfn->name2, lfn->len, NULL, &olen,= NULL); + if (!utf8) { + return -4; + } + lfn->len =3D olen; + memcpy(lfn->name, utf8, olen + 1); + g_free(utf8); + } =20 return 0; } @@ -1733,12 +1752,14 @@ static int parse_short_name(BDRVVVFATState* s, =20 for (j =3D 7; j >=3D 0 && direntry->name[j] =3D=3D ' '; j--); for (i =3D 0; i <=3D j; i++) { - if (direntry->name[i] <=3D ' ' || direntry->name[i] > 0x7f) + uint8_t c =3D direntry->name[i]; + if (c !=3D to_valid_short_char(c)) { return -1; - else if (s->downcase_short_names) + } else if (s->downcase_short_names) { lfn->name[i] =3D qemu_tolower(direntry->name[i]); - else + } else { lfn->name[i] =3D direntry->name[i]; + } } =20 for (j =3D 2; j >=3D 0 && direntry->name[8 + j] =3D=3D ' '; j--) { @@ -1748,7 +1769,7 @@ static int parse_short_name(BDRVVVFATState* s, lfn->name[i + j + 1] =3D '\0'; for (;j >=3D 0; j--) { uint8_t c =3D direntry->name[8 + j]; - if (c <=3D ' ' || c > 0x7f) { + if (c !=3D to_valid_short_char(c)) { return -2; } else if (s->downcase_short_names) { lfn->name[i + j] =3D qemu_tolower(c); @@ -2966,7 +2987,6 @@ DLOG(checkpoint()); /* * Some sanity checks: * - do not allow writing to the boot sector - * - do not allow to write non-ASCII filenames */ =20 if (sector_num < s->offset_to_fat) @@ -3000,13 +3020,8 @@ DLOG(checkpoint()); direntries =3D (direntry_t*)(buf + 0x200 * (begin - sector= _num)); =20 for (k =3D 0; k < (end - begin) * 0x10; k++) { - /* do not allow non-ASCII filenames */ - if (parse_long_name(&lfn, direntries + k) < 0) { - fprintf(stderr, "Warning: non-ASCII filename\n"); - return -1; - } /* no access to the direntry of a read-only file */ - else if (is_short_name(direntries+k) && + if (is_short_name(direntries + k) && (direntries[k].attributes & 1)) { if (memcmp(direntries + k, array_get(&(s->directory), dir_index += k), --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388625138999.8865285296575; Tue, 18 Jul 2017 07:37:05 -0700 (PDT) Received: from localhost ([::1]:56889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTcS-0000V2-1Y for importer@patchew.org; Tue, 18 Jul 2017 10:37:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKq-00010l-El for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKp-0007ur-Hi for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35126) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKg-0007ma-9q; Tue, 18 Jul 2017 10:18:38 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C51D7CB8C; Tue, 18 Jul 2017 14:18:37 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C24C6F940; Tue, 18 Jul 2017 14:18:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4C51D7CB8C Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4C51D7CB8C From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:18:03 +0200 Message-Id: <1500387486-5469-19-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Jul 2017 14:18:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 18/21] vvfat: initialize memory after allocating it 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau This prevents some host to guest memory content leaks. Fixes: https://bugs.launchpad.net/qemu/+bug/1599539 Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/vvfat.c b/block/vvfat.c index ea7775f..6b11596 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -115,6 +115,7 @@ static inline int array_ensure_allocated(array_t* array= , int index) array->pointer =3D g_realloc(array->pointer, new_size); if (!array->pointer) return -1; + memset(array->pointer + array->size, 0, new_size - array->size); array->size =3D new_size; array->next =3D index + 1; } --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388337040680.7841734417339; Tue, 18 Jul 2017 07:32:17 -0700 (PDT) Received: from localhost ([::1]:56864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTXp-0004tf-Pi for importer@patchew.org; Tue, 18 Jul 2017 10:32:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKn-0000x5-8G for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKk-0007qJ-0t for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60696) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKh-0007o3-OI; Tue, 18 Jul 2017 10:18:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7463C04B939; Tue, 18 Jul 2017 14:18:38 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B93A6F940; Tue, 18 Jul 2017 14:18:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C7463C04B939 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C7463C04B939 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:18:04 +0200 Message-Id: <1500387486-5469-20-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 18 Jul 2017 14:18:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 19/21] block/vvfat: Fix compiler warning with gcc 7 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Max Reitz gcc 7 complains that the sprintf() might write a null byte beyond the end of the tail buffer. That is wrong, but we can silence it by making i unsigned (it can never be negative anyway, see the if condition right before). For some reason, this allows gcc to suddenly accurately calculate the range of i so we can give the tail[] array the exact size it needs to have (which is 8 bytes) without gcc complaining. In addition, let us convert the sprintf() to snprintf(), because that is always nicer, and add an assertion about the range of the return value afterwards so we can see that "8 - len" will never be negative and thus "entry->name + MIN(j, 8 - len)" will never be out of bounds. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/vvfat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 6b11596..a9e207f 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -549,7 +549,7 @@ static direntry_t *create_short_filename(BDRVVVFATState= *s, const gchar *p, *last_dot =3D NULL; gunichar c; bool lossy_conversion =3D false; - char tail[11]; + char tail[8]; =20 if (!entry) { return NULL; @@ -614,7 +614,8 @@ static direntry_t *create_short_filename(BDRVVVFATState= *s, for (i =3D lossy_conversion ? 1 : 0; i < 999999; i++) { direntry_t *entry1; if (i > 0) { - int len =3D sprintf(tail, "~%d", i); + int len =3D snprintf(tail, sizeof(tail), "~%u", (unsigned)i); + assert(len <=3D 7); memcpy(entry->name + MIN(j, 8 - len), tail, len); } for (entry1 =3D array_get(&(s->directory), directory_start); --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500388420677309.409117626989; Tue, 18 Jul 2017 07:33:40 -0700 (PDT) Received: from localhost ([::1]:56869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTZ9-000651-QR for importer@patchew.org; Tue, 18 Jul 2017 10:33:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKo-0000yF-AW for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKn-0007tB-Dm for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48736) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKi-0007p2-SY; Tue, 18 Jul 2017 10:18:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE8254A701; Tue, 18 Jul 2017 14:18:39 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 103DE7F46F; Tue, 18 Jul 2017 14:18:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DE8254A701 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DE8254A701 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:18:05 +0200 Message-Id: <1500387486-5469-21-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 18 Jul 2017 14:18:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 20/21] blockdev: move BDRV_O_NO_BACKING option forward 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: John Snow For both external_snapshot_prepare and qmp_drive_mirror, we eventually append the option BDRV_O_NO_BACKING. However, we generally do so after we create the image. To accommodate image creation wanting to verify that a backing file exists or not, add this option prior to create to override checking the existence of the backing file. This prevents QEMU from trying to re-open a backing file that's already in use (thanks to qcow2 locking). Signed-off-by: John Snow Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- blockdev.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/blockdev.c b/blockdev.c index 7f53cc8..6469f16 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1710,7 +1710,8 @@ static void external_snapshot_prepare(BlkActionState = *common, } =20 flags =3D state->old_bs->open_flags; - flags &=3D ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_= READ); + flags &=3D ~(BDRV_O_SNAPSHOT | BDRV_O_COPY_ON_READ); + flags |=3D BDRV_O_NO_BACKING; =20 /* create new image w/backing file */ mode =3D s->has_mode ? s->mode : NEW_IMAGE_MODE_ABSOLUTE_PATHS; @@ -1735,8 +1736,6 @@ static void external_snapshot_prepare(BlkActionState = *common, qdict_put_str(options, "node-name", snapshot_node_name); } qdict_put_str(options, "driver", format); - - flags |=3D BDRV_O_NO_BACKING; } =20 state->new_bs =3D bdrv_open(new_image_file, snapshot_ref, options, fla= gs, @@ -3548,6 +3547,9 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) backing_mode =3D MIRROR_OPEN_BACKING_CHAIN; } =20 + /* Don't open backing image in create() */ + flags |=3D BDRV_O_NO_BACKING; + if ((arg->sync =3D=3D MIRROR_SYNC_MODE_FULL || !source) && arg->mode !=3D NEW_IMAGE_MODE_EXISTING) { @@ -3587,8 +3589,7 @@ void qmp_drive_mirror(DriveMirror *arg, Error **errp) /* Mirroring takes care of copy-on-write using the source's backing * file. */ - target_bs =3D bdrv_open(arg->target, NULL, options, - flags | BDRV_O_NO_BACKING, errp); + target_bs =3D bdrv_open(arg->target, NULL, options, flags, errp); if (!target_bs) { goto out; } --=20 1.8.3.1 From nobody Thu May 2 13:03:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150038861290933.53381890175467; Tue, 18 Jul 2017 07:36:52 -0700 (PDT) Received: from localhost ([::1]:56888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTcD-0000JL-DU for importer@patchew.org; Tue, 18 Jul 2017 10:36:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dXTKs-00012z-4Y for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dXTKp-0007uy-Ls for qemu-devel@nongnu.org; Tue, 18 Jul 2017 10:18:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dXTKk-0007qE-HX; Tue, 18 Jul 2017 10:18:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C4DFC0587C4; Tue, 18 Jul 2017 14:18:41 +0000 (UTC) Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D4B56F940; Tue, 18 Jul 2017 14:18:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8C4DFC0587C4 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8C4DFC0587C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jul 2017 16:18:06 +0200 Message-Id: <1500387486-5469-22-git-send-email-kwolf@redhat.com> In-Reply-To: <1500387486-5469-1-git-send-email-kwolf@redhat.com> References: <1500387486-5469-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 18 Jul 2017 14:18:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 21/21] qemu-img: Check for backing image if specified during create 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, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: John Snow Or, rather, force the open of a backing image if one was specified for creation. Using a similar -unsafe option as rebase, allow qemu-img to ignore the backing file validation if possible. It may not always be possible, as in the existing case when a filesize for the new image was not specified. This is accomplished by shifting around the conditionals in bdrv_img_create, such that a backing file is always opened unless we provide BDRV_O_NO_BACKING. qemu-img is adjusted to pass this new flag when -u is provided to create. Sorry for the heinous looking diffstat, but it's mostly whitespace. Inspired by: https://bugzilla.redhat.com/show_bug.cgi?id=3D1213786 Signed-off-by: John Snow Signed-off-by: Kevin Wolf --- block.c | 94 +++++++++++++++++++++++++-----------------= ---- qemu-img-cmds.hx | 4 +- qemu-img.c | 16 +++++--- qemu-img.texi | 9 ++++- tests/qemu-iotests/082 | 4 +- tests/qemu-iotests/082.out | 4 +- tests/qemu-iotests/085 | 2 +- tests/qemu-iotests/111.out | 1 + tests/qemu-iotests/139 | 2 +- tests/qemu-iotests/156 | 2 +- tests/qemu-iotests/158 | 2 +- tests/qemu-iotests/189 | 2 +- 12 files changed, 83 insertions(+), 59 deletions(-) diff --git a/block.c b/block.c index 98a9209..2dd9262 100644 --- a/block.c +++ b/block.c @@ -4396,55 +4396,65 @@ void bdrv_img_create(const char *filename, const ch= ar *fmt, =20 backing_fmt =3D qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT); =20 - // The size for the image must always be specified, with one exception: - // If we are using a backing file, we can obtain the size from there + /* The size for the image must always be specified, unless we have a b= acking + * file and we have not been forbidden from opening it. */ size =3D qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0); - if (size =3D=3D -1) { - if (backing_file) { - BlockDriverState *bs; - char *full_backing =3D g_new0(char, PATH_MAX); - int64_t size; - int back_flags; - QDict *backing_options =3D NULL; - - bdrv_get_full_backing_filename_from_filename(filename, backing= _file, - full_backing, PAT= H_MAX, - &local_err); - if (local_err) { - g_free(full_backing); - goto out; - } + if (backing_file && !(flags & BDRV_O_NO_BACKING)) { + BlockDriverState *bs; + char *full_backing =3D g_new0(char, PATH_MAX); + int back_flags; + QDict *backing_options =3D NULL; + + bdrv_get_full_backing_filename_from_filename(filename, backing_fil= e, + full_backing, PATH_MA= X, + &local_err); + if (local_err) { + g_free(full_backing); + goto out; + } =20 - /* backing files always opened read-only */ - back_flags =3D flags; - back_flags &=3D ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BA= CKING); + /* backing files always opened read-only */ + back_flags =3D flags; + back_flags &=3D ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKIN= G); =20 - if (backing_fmt) { - backing_options =3D qdict_new(); - qdict_put_str(backing_options, "driver", backing_fmt); - } + if (backing_fmt) { + backing_options =3D qdict_new(); + qdict_put_str(backing_options, "driver", backing_fmt); + } =20 - bs =3D bdrv_open(full_backing, NULL, backing_options, back_fla= gs, - &local_err); - g_free(full_backing); - if (!bs) { - goto out; - } - size =3D bdrv_getlength(bs); - if (size < 0) { - error_setg_errno(errp, -size, "Could not get size of '%s'", - backing_file); - bdrv_unref(bs); - goto out; + bs =3D bdrv_open(full_backing, NULL, backing_options, back_flags, + &local_err); + g_free(full_backing); + if (!bs && size !=3D -1) { + /* Couldn't open BS, but we have a size, so it's nonfatal */ + warn_reportf_err(local_err, + "Could not verify backing image. " + "This may become an error in future versions.\= n"); + local_err =3D NULL; + } else if (!bs) { + /* Couldn't open bs, do not have size */ + error_append_hint(&local_err, + "Could not open backing image to determine s= ize.\n"); + goto out; + } else { + if (size =3D=3D -1) { + /* Opened BS, have no size */ + size =3D bdrv_getlength(bs); + if (size < 0) { + error_setg_errno(errp, -size, "Could not get size of '= %s'", + backing_file); + bdrv_unref(bs); + goto out; + } + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size, &error_abo= rt); } - - qemu_opt_set_number(opts, BLOCK_OPT_SIZE, size, &error_abort); - bdrv_unref(bs); - } else { - error_setg(errp, "Image creation needs a size parameter"); - goto out; } + } /* (backing_file && !(flags & BDRV_O_NO_BACKING)) */ + + if (size =3D=3D -1) { + error_setg(errp, "Image creation needs a size parameter"); + goto out; } =20 if (!quiet) { diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index ac5946b..3763f13 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -22,9 +22,9 @@ STEXI ETEXI =20 DEF("create", img_create, - "create [-q] [--object objectdef] [-f fmt] [-b backing_file] [-F backi= ng_fmt] [-o options] filename [size]") + "create [-q] [--object objectdef] [-f fmt] [-b backing_file] [-F backi= ng_fmt] [-u] [-o options] filename [size]") STEXI -@item create [--object @var{objectdef}] [-q] [-f @var{fmt}] [-b @var{backi= ng_file}] [-F @var{backing_fmt}] [-o @var{options}] @var{filename} [@var{si= ze}] +@item create [--object @var{objectdef}] [-q] [-f @var{fmt}] [-b @var{backi= ng_file}] [-F @var{backing_fmt}] [-u] [-o @var{options}] @var{filename} [@v= ar{size}] ETEXI =20 DEF("commit", img_commit, diff --git a/qemu-img.c b/qemu-img.c index 182e697..eb32b93 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -150,9 +150,11 @@ static void QEMU_NORETURN help(void) " 'snapshot_id_or_name' is deprecated, use 'snapshot_param'\n" " instead\n" " '-c' indicates that target image must be compressed (qcow fo= rmat only)\n" - " '-u' enables unsafe rebasing. It is assumed that old and new= backing file\n" - " match exactly. The image doesn't need a working backing= file before\n" - " rebasing in this case (useful for renaming the backing = file)\n" + " '-u' allows unsafe backing chains. For rebasing, it is assum= ed that old and\n" + " new backing file match exactly. The image doesn't need = a working\n" + " backing file before rebasing in this case (useful for r= enaming the\n" + " backing file). For image creation, allow creating witho= ut attempting\n" + " to open the backing file.\n" " '-h' with or without a command shows this help and lists the= supported formats\n" " '-p' show progress of command (only certain commands)\n" " '-q' use Quiet mode - do not print any output (except errors= )\n" @@ -429,6 +431,7 @@ static int img_create(int argc, char **argv) char *options =3D NULL; Error *local_err =3D NULL; bool quiet =3D false; + int flags =3D 0; =20 for(;;) { static const struct option long_options[] =3D { @@ -436,7 +439,7 @@ static int img_create(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":F:b:f:ho:q", + c =3D getopt_long(argc, argv, ":F:b:f:ho:qu", long_options, NULL); if (c =3D=3D -1) { break; @@ -476,6 +479,9 @@ static int img_create(int argc, char **argv) case 'q': quiet =3D true; break; + case 'u': + flags |=3D BDRV_O_NO_BACKING; + break; case OPTION_OBJECT: { QemuOpts *opts; opts =3D qemu_opts_parse_noisily(&qemu_object_opts, @@ -528,7 +534,7 @@ static int img_create(int argc, char **argv) } =20 bdrv_img_create(filename, fmt, base_filename, base_fmt, - options, img_size, 0, quiet, &local_err); + options, img_size, flags, quiet, &local_err); if (local_err) { error_reportf_err(local_err, "%s: ", filename); goto fail; diff --git a/qemu-img.texi b/qemu-img.texi index f11f603..72dabd6 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -233,7 +233,7 @@ If @code{-r} is specified, exit codes representing the = image state refer to the state after (the attempt at) repairing it. That is, a successful @code{-r = all} will yield the exit code 0, independently of the image state before. =20 -@item create [-f @var{fmt}] [-b @var{backing_file}] [-F @var{backing_fmt}]= [-o @var{options}] @var{filename} [@var{size}] +@item create [-f @var{fmt}] [-b @var{backing_file}] [-F @var{backing_fmt}]= [-u] [-o @var{options}] @var{filename} [@var{size}] =20 Create the new disk image @var{filename} of size @var{size} and format @var{fmt}. Depending on the file format, you can add one or more @var{opti= ons} @@ -244,6 +244,13 @@ only the differences from @var{backing_file}. No size = needs to be specified in this case. @var{backing_file} will never be modified unless you use the @code{commit} monitor command (or qemu-img commit). =20 +Note that a given backing file will be opened to check that it is valid. U= se +the @code{-u} option to enable unsafe backing file mode, which means that = the +image will be created even if the associated backing file cannot be opened= . A +matching backing file must be created or additional options be used to mak= e the +backing file specification valid when you want to use an image created this +way. + The size can also be specified using the @var{size} option with @code{-o}, it doesn't need to be specified separately in this case. =20 diff --git a/tests/qemu-iotests/082 b/tests/qemu-iotests/082 index ad1d9fa..d5c83d4 100755 --- a/tests/qemu-iotests/082 +++ b/tests/qemu-iotests/082 @@ -85,8 +85,8 @@ run_qemu_img create -f $IMGFMT -o cluster_size=3D4k -o he= lp "$TEST_IMG" $size run_qemu_img create -f $IMGFMT -o cluster_size=3D4k -o \? "$TEST_IMG" $size =20 # Looks like a help option, but is part of the backing file name -run_qemu_img create -f $IMGFMT -o backing_file=3D"$TEST_IMG",,help "$TEST_= IMG" $size -run_qemu_img create -f $IMGFMT -o backing_file=3D"$TEST_IMG",,\? "$TEST_IM= G" $size +run_qemu_img create -f $IMGFMT -u -o backing_file=3D"$TEST_IMG",,help "$TE= ST_IMG" $size +run_qemu_img create -f $IMGFMT -u -o backing_file=3D"$TEST_IMG",,\? "$TEST= _IMG" $size =20 # Try to trick qemu-img into creating escaped commas run_qemu_img create -f $IMGFMT -o backing_file=3D"$TEST_IMG", -o help "$TE= ST_IMG" $size diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index dbed67f..1527fbe 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -210,10 +210,10 @@ lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits nocow Turn off copy-on-write (valid only on btrfs) =20 -Testing: create -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2,,help TEST_DIR= /t.qcow2 128M +Testing: create -f qcow2 -u -o backing_file=3DTEST_DIR/t.qcow2,,help TEST_= DIR/t.qcow2 128M Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,help cluster_size=3D65536 lazy_refcounts=3Doff refcoun= t_bits=3D16 =20 -Testing: create -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2,,? TEST_DIR/t.= qcow2 128M +Testing: create -f qcow2 -u -o backing_file=3DTEST_DIR/t.qcow2,,? TEST_DIR= /t.qcow2 128M Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,? cluster_size=3D65536 lazy_refcounts=3Doff refcount_b= its=3D16 =20 Testing: create -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2, -o help TEST_= DIR/t.qcow2 128M diff --git a/tests/qemu-iotests/085 b/tests/qemu-iotests/085 index b97adcd..71efe50 100755 --- a/tests/qemu-iotests/085 +++ b/tests/qemu-iotests/085 @@ -104,7 +104,7 @@ function add_snapshot_image() { base_image=3D"${TEST_DIR}/$((${1}-1))-${snapshot_virt0}" snapshot_file=3D"${TEST_DIR}/${1}-${snapshot_virt0}" - _make_test_img -b "${base_image}" "$size" + _make_test_img -u -b "${base_image}" "$size" mv "${TEST_IMG}" "${snapshot_file}" do_blockdev_add "$1" "'backing': '', " "${snapshot_file}" } diff --git a/tests/qemu-iotests/111.out b/tests/qemu-iotests/111.out index 683c01a..5279c46 100644 --- a/tests/qemu-iotests/111.out +++ b/tests/qemu-iotests/111.out @@ -1,3 +1,4 @@ QA output created by 111 qemu-img: TEST_DIR/t.IMGFMT: Could not open 'TEST_DIR/t.IMGFMT.inexistent'= : No such file or directory +Could not open backing image to determine size. *** done diff --git a/tests/qemu-iotests/139 b/tests/qemu-iotests/139 index 175d8f0..9ff51d9 100644 --- a/tests/qemu-iotests/139 +++ b/tests/qemu-iotests/139 @@ -65,7 +65,7 @@ class TestBlockdevDel(iotests.QMPTestCase): # Add a BlockDriverState that will be used as overlay for the base_img= BDS def addBlockDriverStateOverlay(self, node): self.checkBlockDriverState(node, False) - iotests.qemu_img('create', '-f', iotests.imgfmt, + iotests.qemu_img('create', '-u', '-f', iotests.imgfmt, '-b', base_img, new_img, '1M') opts =3D {'driver': iotests.imgfmt, 'node-name': node, diff --git a/tests/qemu-iotests/156 b/tests/qemu-iotests/156 index d799b73..2c4a06e 100755 --- a/tests/qemu-iotests/156 +++ b/tests/qemu-iotests/156 @@ -66,7 +66,7 @@ _send_qemu_cmd $QEMU_HANDLE \ 'return' =20 # Create snapshot -TEST_IMG=3D"$TEST_IMG.overlay" _make_test_img -b "$TEST_IMG" 1M +TEST_IMG=3D"$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" 1M _send_qemu_cmd $QEMU_HANDLE \ "{ 'execute': 'blockdev-snapshot-sync', 'arguments': { 'device': 'source', diff --git a/tests/qemu-iotests/158 b/tests/qemu-iotests/158 index 823c120..24ac600 100755 --- a/tests/qemu-iotests/158 +++ b/tests/qemu-iotests/158 @@ -66,7 +66,7 @@ echo "=3D=3D verify pattern =3D=3D" $QEMU_IO --object $SECRET -c "read -P 0xa 0 $size" --image-opts $IMGSPECBA= SE | _filter_qemu_io | _filter_testdir =20 echo "=3D=3D create overlay =3D=3D" -_make_test_img --object $SECRET -o "encryption=3Don,encrypt.key-secret=3Ds= ec0" -b "$TEST_IMG_BASE" $size +_make_test_img -u --object $SECRET -o "encryption=3Don,encrypt.key-secret= =3Dsec0" -b "$TEST_IMG_BASE" $size =20 echo echo "=3D=3D writing part of a cluster =3D=3D" diff --git a/tests/qemu-iotests/189 b/tests/qemu-iotests/189 index 54ad980..e695475 100755 --- a/tests/qemu-iotests/189 +++ b/tests/qemu-iotests/189 @@ -66,7 +66,7 @@ echo "=3D=3D verify pattern =3D=3D" $QEMU_IO --object $SECRET0 -c "read -P 0xa 0 $size" --image-opts $IMGSPECB= ASE | _filter_qemu_io | _filter_testdir =20 echo "=3D=3D create overlay =3D=3D" -_make_test_img --object $SECRET1 -o "encrypt.format=3Dluks,encrypt.key-sec= ret=3Dsec1,encrypt.iter-time=3D10" -b "$TEST_IMG_BASE" $size +_make_test_img --object $SECRET1 -o "encrypt.format=3Dluks,encrypt.key-sec= ret=3Dsec1,encrypt.iter-time=3D10" -u -b "$TEST_IMG_BASE" $size =20 echo echo "=3D=3D writing part of a cluster =3D=3D" --=20 1.8.3.1