From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985150; cv=none; d=zohomail.com; s=zohoarc; b=eObnz2y/jN58Y9G47gMBLBWb1NAKTV9gDSuWJ/4EMx/Y+fczc9qvRnn32dojwrhkJNgSbq+yrek8bVjub0uHacDN1a3OcEfqcUYjZBS1KvZVyNLlA15Tc4bfGKjsaibKSPb01S7A29KzlUBCPhT0+sGZMCmsIRBbrhy6bcN+F4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985150; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5xWuU0hBtpAwHuQvWGIwrd39FN93VworOtiulnbrtDI=; b=WHfgGCQFkGuCog+dtGFR3bla5tMd4E/UEHaeQoRZQPGietopxNewdAw6O9lv7Onk9aYvVYgBlyADvs+CfTpTpvAzDlAXMmv9UXhsQzCM/g+pZMIXLK7Drr/7sBHGuS7NyplO/NJeTV6GliDyU3EfwHUzKEyhbSlXdUs1C0LREQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617985150589525.3424052365715; Fri, 9 Apr 2021 09:19:10 -0700 (PDT) Received: from localhost ([::1]:59856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUtqf-0002gO-GO for importer@patchew.org; Fri, 09 Apr 2021 12:19:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50002) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnh-0007Qh-BV for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44006) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnf-0003Jl-LM for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-eieJM6hNPCKiqK3uOXuqNA-1; Fri, 09 Apr 2021 12:16:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73B1A10CE780; Fri, 9 Apr 2021 16:15:59 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 712665D6A1; Fri, 9 Apr 2021 16:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984962; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5xWuU0hBtpAwHuQvWGIwrd39FN93VworOtiulnbrtDI=; b=aulmUSAVYrYbe5s/tOvp95G/vjvK2yD1Mm6pS5DrYNKUoPRiX2Jx6HqsYGcgxD6VZD9sSo qnaNxVhQ6v2pE2DAb7RQOlBfLegsiZxgMhEai3d4kP7tdogQPXfBNBEMm1QI8nOoeLQrHM +ASwLyIu/pIo/s5ir+W7/Nt6w929OJk= X-MC-Unique: eieJM6hNPCKiqK3uOXuqNA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 01/10] block/rbd: fix memory leak in qemu_rbd_connect() Date: Fri, 9 Apr 2021 18:15:39 +0200 Message-Id: <20210409161548.341297-2-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella In qemu_rbd_connect(), 'mon_host' is allocated by qemu_rbd_mon_host() using g_strjoinv(), but it's only freed in the error path, leaking memory in the success path as reported by valgrind: 80 bytes in 4 blocks are definitely lost in loss record 5,028 of 6,516 at 0x4839809: malloc (vg_replace_malloc.c:307) by 0x5315BB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x532B6FF: g_strjoinv (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x87D07E: qemu_rbd_mon_host (rbd.c:538) by 0x87D07E: qemu_rbd_connect (rbd.c:562) by 0x87E1CE: qemu_rbd_open (rbd.c:740) by 0x840EB1: bdrv_open_driver (block.c:1528) by 0x8453A9: bdrv_open_common (block.c:1802) by 0x8453A9: bdrv_open_inherit (block.c:3444) by 0x8464C2: bdrv_open (block.c:3537) by 0x8108CD: qmp_blockdev_add (blockdev.c:3569) by 0x8EA61B: qmp_marshal_blockdev_add (qapi-commands-block-core.c:1086) by 0x90B528: do_qmp_dispatch_bh (qmp-dispatch.c:131) by 0x907EA4: aio_bh_poll (async.c:164) Fix freeing 'mon_host' also when qemu_rbd_connect() ends correctly. Fixes: 0a55679b4a5061f4d74bdb1a0e81611ba3390b00 Signed-off-by: Stefano Garzarella Message-Id: <20210329150129.121182-2-sgarzare@redhat.com> Reviewed-by: Markus Armbruster Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/rbd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 9071a00e3f..24cefcd0dc 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -563,13 +563,13 @@ static int qemu_rbd_connect(rados_t *cluster, rados_i= octx_t *io_ctx, if (local_err) { error_propagate(errp, local_err); r =3D -EINVAL; - goto failed_opts; + goto out; } =20 r =3D rados_create(cluster, opts->user); if (r < 0) { error_setg_errno(errp, -r, "error initializing"); - goto failed_opts; + goto out; } =20 /* try default location when conf=3DNULL, but ignore failure */ @@ -626,11 +626,12 @@ static int qemu_rbd_connect(rados_t *cluster, rados_i= octx_t *io_ctx, */ rados_ioctx_set_namespace(*io_ctx, opts->q_namespace); =20 - return 0; + r =3D 0; + goto out; =20 failed_shutdown: rados_shutdown(*cluster); -failed_opts: +out: g_free(mon_host); return r; } --=20 2.30.2 From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985655; cv=none; d=zohomail.com; s=zohoarc; b=n3+3w5pSPMJr86ci5H9LKplJ16g22LNQlp+QOzL4hzIGnLProl0FFrLT0gvNL99HuJb4Zfr3jAuuhrfBX4DDyDieTUJIkGpT426kzRhq0oNtQ6yD2QxIhH9PUJUPRKpxYOakW5ylxI/oYAA9XytnH6VKvlvwLZQSfWTGOHvxUNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985655; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=A4rs2GIunkVXTiERjt/BtjkxPnrk2e2igFzTgpneroE=; b=hmfj3QdoRW130wxqWfY9WhUEjBXoPlPNw/oOq1IBXR7Qr9IHqz9ed5dGrngNaB2eUIAL5qb9BS9XZorYpBpVEapyPtwJoLiTI5GjucB+EpBVhh4H5Zt6Vq2eIAZOWfYUqJ+Ws66QTD4gslBACj4k9SIGLhAknFsRHEYMLZWH+FI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161798565553611.25855688919387; Fri, 9 Apr 2021 09:27:35 -0700 (PDT) Received: from localhost ([::1]:33992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUtyn-00072F-OW for importer@patchew.org; Fri, 09 Apr 2021 12:27:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnk-0007aV-Ka for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39016) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtni-0003Le-NB for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-524-P-D5wflCOdewDmrD-SKG1g-1; Fri, 09 Apr 2021 12:16:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 999631883522; Fri, 9 Apr 2021 16:16:00 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id A871B5D6A1; Fri, 9 Apr 2021 16:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A4rs2GIunkVXTiERjt/BtjkxPnrk2e2igFzTgpneroE=; b=FFqSNVArzb6KQ62DSWddcddQNVef4zuK9u9LfREDp9JzL2ndE32zR0UJlgvavQ00g+5x6E XQX1bKgvarxp1vDbWVyIJK7dOjCVrdXgvrEIM6bBqO59c07NsOWvKPjQ7z+EN/eh7gW32p x+Gdp0Ze6ZRtbp8NkjEQuLGVvrwl4wQ= X-MC-Unique: P-D5wflCOdewDmrD-SKG1g-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 02/10] block/rbd: fix memory leak in qemu_rbd_co_create_opts() Date: Fri, 9 Apr 2021 18:15:40 +0200 Message-Id: <20210409161548.341297-3-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella When we allocate 'q_namespace', we forgot to set 'has_q_namespace' to true. This can cause several issues, including a memory leak, since qapi_free_BlockdevCreateOptions() does not deallocate that memory, as reported by valgrind: 13 bytes in 1 blocks are definitely lost in loss record 7 of 96 at 0x4839809: malloc (vg_replace_malloc.c:307) by 0x48CEBB8: g_malloc (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x48E3FE3: g_strdup (in /usr/lib64/libglib-2.0.so.0.6600.8) by 0x180010: qemu_rbd_co_create_opts (rbd.c:446) by 0x1AE72C: bdrv_create_co_entry (block.c:492) by 0x241902: coroutine_trampoline (coroutine-ucontext.c:173) by 0x57530AF: ??? (in /usr/lib64/libc-2.32.so) by 0x1FFEFFFA6F: ??? Fix setting 'has_q_namespace' to true when we allocate 'q_namespace'. Fixes: 19ae9ae014 ("block/rbd: Add support for ceph namespaces") Signed-off-by: Stefano Garzarella Message-Id: <20210329150129.121182-3-sgarzare@redhat.com> Reviewed-by: Markus Armbruster Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf --- block/rbd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/rbd.c b/block/rbd.c index 24cefcd0dc..f098a89c7b 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -444,6 +444,7 @@ static int coroutine_fn qemu_rbd_co_create_opts(BlockDr= iver *drv, loc->user =3D g_strdup(qdict_get_try_str(options, "user")); loc->has_user =3D !!loc->user; loc->q_namespace =3D g_strdup(qdict_get_try_str(options, "namespace")); + loc->has_q_namespace =3D !!loc->q_namespace; loc->image =3D g_strdup(qdict_get_try_str(options, "image")); keypairs =3D qdict_get_try_str(options, "=3Dkeyvalue-pairs"); =20 --=20 2.30.2 From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985263; cv=none; d=zohomail.com; s=zohoarc; b=i/NbfJUfR/9f/Yz/fMRr5BTimS48U2n5AjWikE5T83ESanqekRc8eJfUlUiJvhvU8VOiAINFRWF2bllpBuPRCMe7ZljNC3Io0giByMw/+t7uKC+zQESrrP4TnkWw1+BrWh5ZH7XjsUl/ggDIXuB2W3S7P4Cd3tWJlNhM0E6MOQM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985263; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5qSF660ST1GkAHZy3ocYEL3QL2JbhGpv8Nq9GpDOhcc=; b=IRQ6jmO90r5oqI1P3ZkSqBf4XTleOTmFsvNc78SysiKc7bP4u/HWU9M8UgSJ20uSfYeL/HbRIGUclhnFBQh4dR0tRCV8TgM48K+OJ0wbUMoMftLOcDgleB/nQJ5jh8SRcnYgN5GoT8KCbOuM54HyVWt0AhWy+IhKOxqyNWBW79Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16179852633821014.0850745552642; Fri, 9 Apr 2021 09:21:03 -0700 (PDT) Received: from localhost ([::1]:38302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUtsU-0005Lv-AK for importer@patchew.org; Fri, 09 Apr 2021 12:21:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnr-0007fn-7Y for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23552) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnk-0003MI-8W for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-RnrravnFOneeDQTe36l01w-1; Fri, 09 Apr 2021 12:16:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D81E9107ACE4; Fri, 9 Apr 2021 16:16:01 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0EF35D6A1; Fri, 9 Apr 2021 16:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5qSF660ST1GkAHZy3ocYEL3QL2JbhGpv8Nq9GpDOhcc=; b=SmBAxamnBHn43QjoCPsnrHb866bWRr+K9jTTHxy7gJFE+0Iq3Z4nhCjIjSbX+V6hgSHA5Q bRi0L5jY7igsXHR4JODmh0pVdHgN2FlBoc/Y4fLM7oRD+0VIEN0m3sUo270XY5U0GDIa+J ATfBYZeQqaZoKJvicVVm36sK+ZJb0QM= X-MC-Unique: RnrravnFOneeDQTe36l01w-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 03/10] iotests/qsd-jobs: Filter events in the first test Date: Fri, 9 Apr 2021 18:15:41 +0200 Message-Id: <20210409161548.341297-4-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz The job may or may not be ready before the 'quit' is issued. Whether it is is irrelevant; for the purpose of the test, it only needs to still be there. Filter the job status change and READY events from the output so it becomes reliable. Reported-by: Peter Maydell Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Max Reitz Message-Id: <20210401132839.139939-1-mreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- tests/qemu-iotests/tests/qsd-jobs | 5 ++++- tests/qemu-iotests/tests/qsd-jobs.out | 10 ---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/qemu-iotests/tests/qsd-jobs b/tests/qemu-iotests/tests/q= sd-jobs index 972b6b3898..510bf0a9dc 100755 --- a/tests/qemu-iotests/tests/qsd-jobs +++ b/tests/qemu-iotests/tests/qsd-jobs @@ -52,9 +52,12 @@ echo "=3D=3D=3D Job still present at shutdown =3D=3D=3D" echo =20 # Just make sure that this doesn't crash +# (Filter job status and READY events, because their order may differ +# between runs, particularly around when 'quit' is issued) $QSD --chardev stdio,id=3Dstdio --monitor chardev=3Dstdio \ --blockdev node-name=3Dfile0,driver=3Dfile,filename=3D"$TEST_IMG" \ - --blockdev node-name=3Dfmt0,driver=3Dqcow2,file=3Dfile0 < (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161798538797436.72266646333037; Fri, 9 Apr 2021 09:23:07 -0700 (PDT) Received: from localhost ([::1]:46862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUtuU-0000Ui-Uw for importer@patchew.org; Fri, 09 Apr 2021 12:23:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnr-0007gS-IH for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnj-0003Lo-7M for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-466-5TmMWFBgMzGuQNqnmOHCag-1; Fri, 09 Apr 2021 12:16:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C40E188352C; Fri, 9 Apr 2021 16:16:03 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A4385D6A1; Fri, 9 Apr 2021 16:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZSXeO8oZCR3bRAXAIlADUmJrrUFAZHUJqPzVBpHGJ3Y=; b=htp9XgFgu1YDBz2kfqw4A0XUawYXIPmKY1K7xr8WcV9z0ldgHAJ/vDY2pVr6fCFrEuoo/g 1Mwc6nEK9IhbiHH1+KkfqOO8gcH1S94asDZoqTE7YSFywRgF1rMNwTYdj0NMAmfPBOU4WP xANCc9fARnvM3Y+2dcUlB5EU8j4yP3I= X-MC-Unique: 5TmMWFBgMzGuQNqnmOHCag-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 04/10] iotests: add test for removing persistent bitmap from backing file Date: Fri, 9 Apr 2021 18:15:42 +0200 Message-Id: <20210409161548.341297-5-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Just demonstrate one of x-blockdev-reopen usecases. We can't simply remove persistent bitmap from RO node (for example from backing file), as we need to remove it from the image too. So, we should reopen the node first. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210401161522.8001-1-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- .../tests/remove-bitmap-from-backing | 69 +++++++++++++++++++ .../tests/remove-bitmap-from-backing.out | 6 ++ 2 files changed, 75 insertions(+) create mode 100755 tests/qemu-iotests/tests/remove-bitmap-from-backing create mode 100644 tests/qemu-iotests/tests/remove-bitmap-from-backing.out diff --git a/tests/qemu-iotests/tests/remove-bitmap-from-backing b/tests/qe= mu-iotests/tests/remove-bitmap-from-backing new file mode 100755 index 0000000000..0ea4c36507 --- /dev/null +++ b/tests/qemu-iotests/tests/remove-bitmap-from-backing @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# +# Test removing persistent bitmap from backing +# +# Copyright (c) 2021 Virtuozzo International GmbH. +# +# 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 . +# + +import iotests +from iotests import log, qemu_img_create, qemu_img, qemu_img_pipe + +iotests.script_initialize(supported_fmts=3D['qcow2']) + +top, base =3D iotests.file_path('top', 'base') +size =3D '1M' + +assert qemu_img_create('-f', iotests.imgfmt, base, size) =3D=3D 0 +assert qemu_img_create('-f', iotests.imgfmt, '-b', base, + '-F', iotests.imgfmt, top, size) =3D=3D 0 + +assert qemu_img('bitmap', '--add', base, 'bitmap0') =3D=3D 0 +# Just assert that our method of checking bitmaps in the image works. +assert 'bitmaps' in qemu_img_pipe('info', base) + +vm =3D iotests.VM().add_drive(top, 'backing.node-name=3Dbase') +vm.launch() + +log('Trying to remove persistent bitmap from r-o base node, should fail:') +vm.qmp_log('block-dirty-bitmap-remove', node=3D'base', name=3D'bitmap0') + +new_base_opts =3D { + 'node-name': 'base', + 'driver': 'qcow2', + 'file': { + 'driver': 'file', + 'filename': base + }, + 'read-only': False +} + +# Don't want to bother with filtering qmp_log for reopen command +result =3D vm.qmp('x-blockdev-reopen', **new_base_opts) +if result !=3D {'return': {}}: + log('Failed to reopen: ' + str(result)) + +log('Remove persistent bitmap from base node reopened to RW:') +vm.qmp_log('block-dirty-bitmap-remove', node=3D'base', name=3D'bitmap0') + +new_base_opts['read-only'] =3D True +result =3D vm.qmp('x-blockdev-reopen', **new_base_opts) +if result !=3D {'return': {}}: + log('Failed to reopen: ' + str(result)) + +vm.shutdown() + +if 'bitmaps' in qemu_img_pipe('info', base): + log('ERROR: Bitmap is still in the base image') diff --git a/tests/qemu-iotests/tests/remove-bitmap-from-backing.out b/test= s/qemu-iotests/tests/remove-bitmap-from-backing.out new file mode 100644 index 0000000000..c28af82c75 --- /dev/null +++ b/tests/qemu-iotests/tests/remove-bitmap-from-backing.out @@ -0,0 +1,6 @@ +Trying to remove persistent bitmap from r-o base node, should fail: +{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", = "node": "base"}} +{"error": {"class": "GenericError", "desc": "Bitmap 'bitmap0' is readonly = and cannot be modified"}} +Remove persistent bitmap from base node reopened to RW: +{"execute": "block-dirty-bitmap-remove", "arguments": {"name": "bitmap0", = "node": "base"}} +{"return": {}} --=20 2.30.2 From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985573; cv=none; d=zohomail.com; s=zohoarc; b=WA4AD/whs39E6Rj5pwiCs0rmjzPCNHgD1iKQprHa4qgmaaTaLyadHGIbddoxyt+bJSC1fSGN92l2ZHxnWumetLRuE594+eT4gnFt5lDwqkbIq3bVZnEVKqmOytunfElth4nlBId0U9Ca14Bn19uxAJ7RqIGsO05VC1Mc15Vu8EY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985573; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HwlkFMWL4rMNLHBkKMTTS+lHDYZorJX/JWzqXUBTAFk=; b=D9op5wHXKlVL4IfHFvQ2tkoo0OfXR1cb45CY8+3b65D8fP6nW32OuiJmmM7MWQ4Axw6H5wghhA034MicuOIw8LJLTHXED05B8VhQb/Q5+dBW2L66X4yN4iXRjN/rMKaVQGSAwHWaXe5H8wcWlV+AnJYGiVYY3fsLg6PQuezrzy8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617985573597626.2498985048139; Fri, 9 Apr 2021 09:26:13 -0700 (PDT) Received: from localhost ([::1]:57262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUtxU-0004jP-7A for importer@patchew.org; Fri, 09 Apr 2021 12:26:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnu-0007mS-0w for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43954) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnq-0003NZ-IH for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-xZcls_N5MIyyCJ87S8FirQ-1; Fri, 09 Apr 2021 12:16:05 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 556DD5B38C; Fri, 9 Apr 2021 16:16:04 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6460D5D6A1; Fri, 9 Apr 2021 16:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HwlkFMWL4rMNLHBkKMTTS+lHDYZorJX/JWzqXUBTAFk=; b=BLaQfxmR1sfM6zefeGD0N4v3MXX4CZhZ/1vDHqxVwddG4qUnjoRrQ3Qll8iLvSVhlWvh3r tTABmZMdjDQq82lDy73juHm2kYDx5f2/IWpoTVTA25bD/HrBLKbfeRIhjLrASWDR5uj1c9 C3KfWfZVI4aafoWs0hMfzzjldVrwa/o= X-MC-Unique: xZcls_N5MIyyCJ87S8FirQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 05/10] iotests: Test mirror-top filter permissions Date: Fri, 9 Apr 2021 18:15:43 +0200 Message-Id: <20210409161548.341297-6-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz Add a test accompanying commit 53431b9086b2832ca1aeff0c55e186e9ed79bd11 ("block/mirror: Fix mirror_top's permissions"). Signed-off-by: Max Reitz Message-Id: <20210331122815.51491-1-mreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/qemu-iotests/tests/mirror-top-perms | 121 ++++++++++++++++++ tests/qemu-iotests/tests/mirror-top-perms.out | 5 + 2 files changed, 126 insertions(+) create mode 100755 tests/qemu-iotests/tests/mirror-top-perms create mode 100644 tests/qemu-iotests/tests/mirror-top-perms.out diff --git a/tests/qemu-iotests/tests/mirror-top-perms b/tests/qemu-iotests= /tests/mirror-top-perms new file mode 100755 index 0000000000..451a0666f8 --- /dev/null +++ b/tests/qemu-iotests/tests/mirror-top-perms @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +# group: rw +# +# Test permissions taken by the mirror-top filter +# +# Copyright (C) 2021 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 . +# + +import os +import iotests +from iotests import qemu_img + +# Import qemu after iotests.py has amended sys.path +# pylint: disable=3Dwrong-import-order +import qemu + + +image_size =3D 1 * 1024 * 1024 +source =3D os.path.join(iotests.test_dir, 'source.img') + + +class TestMirrorTopPerms(iotests.QMPTestCase): + def setUp(self): + assert qemu_img('create', '-f', iotests.imgfmt, source, + str(image_size)) =3D=3D 0 + self.vm =3D iotests.VM() + self.vm.add_drive(source) + self.vm.add_blockdev(f'null-co,node-name=3Dnull,size=3D{image_size= }') + self.vm.launch() + + # Will be created by the test function itself + self.vm_b =3D None + + def tearDown(self): + try: + self.vm.shutdown() + except qemu.machine.AbnormalShutdown: + pass + + if self.vm_b is not None: + self.vm_b.shutdown() + + os.remove(source) + + def test_cancel(self): + """ + Before commit 53431b9086b28, mirror-top used to not take any + permissions but WRITE and share all permissions. Because it + is inserted between the source's original parents and the + source, there generally was no parent that would have taken or + unshared any permissions on the source, which means that an + external process could access the image unhindered by locks. + (Unless there was a parent above the protocol node that would + take its own locks, e.g. a format driver.) + This is bad enough, but if the mirror job is then cancelled, + the mirroring VM tries to take back the image, restores the + original permissions taken and unshared, and assumes this must + just work. But it will not, and so the VM aborts. + + Commit 53431b9086b28 made mirror keep the original permissions + and so no other process can "steal" the image. + + (Note that you cannot really do the same with the target image + and then completing the job, because the mirror job always + took/unshared the correct permissions on the target. For + example, it does not share READ_CONSISTENT, which makes it + difficult to let some other qemu process open the image.) + """ + + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'drive0', + target=3D'null', + sync=3D'full') + self.assert_qmp(result, 'return', {}) + + self.vm.event_wait('BLOCK_JOB_READY') + + # We want this to fail because the image cannot be locked. + # If it does not fail, continue still and see what happens. + self.vm_b =3D iotests.VM(path_suffix=3D'b') + # Must use -blockdev -device so we can use share-rw. + # (And we need share-rw=3Don because mirror-top was always + # forced to take the WRITE permission so it can write to the + # source image.) + self.vm_b.add_blockdev(f'file,node-name=3Ddrive0,filename=3D{sourc= e}') + self.vm_b.add_device('virtio-blk,drive=3Ddrive0,share-rw=3Don') + try: + self.vm_b.launch() + print('ERROR: VM B launched successfully, this should not have= ' + 'happened') + except qemu.qmp.QMPConnectError: + assert 'Is another process using the image' in self.vm_b.get_l= og() + + result =3D self.vm.qmp('block-job-cancel', + device=3D'mirror') + self.assert_qmp(result, 'return', {}) + + self.vm.event_wait('BLOCK_JOB_COMPLETED') + + +if __name__ =3D=3D '__main__': + # No metadata format driver supported, because they would for + # example always unshare the WRITE permission. The raw driver + # just passes through the permissions from the guest device, and + # those are the permissions that we want to test. + iotests.main(supported_fmts=3D['raw'], + supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/tests/mirror-top-perms.out b/tests/qemu-iot= ests/tests/mirror-top-perms.out new file mode 100644 index 0000000000..ae1213e6f8 --- /dev/null +++ b/tests/qemu-iotests/tests/mirror-top-perms.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK --=20 2.30.2 From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985796; cv=none; d=zohomail.com; s=zohoarc; b=RXw1rzWU7p175oDR8CYgzQgwSJQLZSmRcqGrmCY07lrzaSBQ4QjJl1AvJ54MQhtPBfd1O+++c5MyOUInft/E85Sb3RX3mcRtrrl6gGERzpCG8PN8aDepXhNl137pG5Tw6OsSu+H9EORr79HuwZ7AtConYfdBaGKayyWsbfioPUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985796; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9Sj4e2NEIvxuDraAfQXbZsFPZEpqZRgCntMne31n7VM=; b=VzrBxC9u2QW7Cue2bt1PUjWKL6pUAcxnAaA3vjHhOFVXBk3dzuQikx19GReZYiwmAklAJsp0U8RpWXeEnIpwfuAcbsOugbjp7QBn3QzDYYKmzELy9d8SAB1BHFLVMGxfFvEoHTps+fLOwLjSMjz3yo47vTkjUWEMgjT37jaaBmI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617985796875657.1034785205451; Fri, 9 Apr 2021 09:29:56 -0700 (PDT) Received: from localhost ([::1]:40956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUu14-0001Ub-PV for importer@patchew.org; Fri, 09 Apr 2021 12:29:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtns-0007jb-HY for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52462) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnl-0003NS-Jb for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-OogYZ0-JN7eBd0ZiHc0Kcw-1; Fri, 09 Apr 2021 12:16:06 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91982107ACC7; Fri, 9 Apr 2021 16:16:05 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CA385D6A1; Fri, 9 Apr 2021 16:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Sj4e2NEIvxuDraAfQXbZsFPZEpqZRgCntMne31n7VM=; b=G7mRrxg5WgXpFsqDRWuZrO8asTa0PKomWvZgQEI0CVCveP2l6SyFphk2MLc5NQFwlTEKZc m1uhBASOhQZf+zb1wR2BHQ2410VlNX2BJlnlEhz0S7XkJcgkdtYcKvnzUfq0xLXePifEEh xywB25Ti8zBOSW8RSbbwzkEQ48tqu80= X-MC-Unique: OogYZ0-JN7eBd0ZiHc0Kcw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 06/10] hw/block/fdc: Fix 'fallback' property on sysbus floppy disk controllers Date: Fri, 9 Apr 2021 18:15:44 +0200 Message-Id: <20210409161548.341297-7-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) From: Philippe Mathieu-Daud=C3=A9 Setting the 'fallback' property corrupts the QOM instance state (FDCtrlSysBus) because it accesses an incorrect offset (it uses the offset of the FDCtrlISABus state). Cc: qemu-stable@nongnu.org Fixes: a73275dd6fc ("fdc: Add fallback option") Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20210407133742.1680424-1-f4bug@amsat.org> Reviewed-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/block/fdc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/block/fdc.c b/hw/block/fdc.c index 82afda7f3a..a825c2acba 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -2893,7 +2893,7 @@ static Property sysbus_fdc_properties[] =3D { DEFINE_PROP_SIGNED("fdtypeB", FDCtrlSysBus, state.qdev_for_drives[1].t= ype, FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, FloppyDriveType), - DEFINE_PROP_SIGNED("fallback", FDCtrlISABus, state.fallback, + DEFINE_PROP_SIGNED("fallback", FDCtrlSysBus, state.fallback, FLOPPY_DRIVE_TYPE_144, qdev_prop_fdc_drive_type, FloppyDriveType), DEFINE_PROP_END_OF_LIST(), @@ -2918,7 +2918,7 @@ static Property sun4m_fdc_properties[] =3D { DEFINE_PROP_SIGNED("fdtype", FDCtrlSysBus, state.qdev_for_drives[0].ty= pe, FLOPPY_DRIVE_TYPE_AUTO, qdev_prop_fdc_drive_type, FloppyDriveType), - DEFINE_PROP_SIGNED("fallback", FDCtrlISABus, state.fallback, + DEFINE_PROP_SIGNED("fallback", FDCtrlSysBus, state.fallback, FLOPPY_DRIVE_TYPE_144, qdev_prop_fdc_drive_type, FloppyDriveType), DEFINE_PROP_END_OF_LIST(), --=20 2.30.2 From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985992; cv=none; d=zohomail.com; s=zohoarc; b=Ku5mcWQJHFVNWvbyOiDW1ayeEwE8ix/V950QAi3Mdz+XnoL4sfhUI1pO8kMp71fDyab/vX8nkaMWoSivQYQY9kq1aNwwyUkZX9LIHLyeScas1+GdbEKPYazlpO3GE51Z9n8My8EQibGFTcTbAyEKIAh6HIcMJrBuZyC3qk3C354= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985992; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CAw/IADhNh/BttxkT1Kn1aKYF2k8HdTDwkIzAeO6v2k=; b=QLI4ND2z6upspmsvg8/MET/CW66SyUjhnt1/+bYebvnCgTLECpDI+e7/iQmuCbxb5dJstw/IyfyjgH+b1Ata1LKFYjUiQ0HaZRe+xgM3+Vimm9dDoYpc5HGdWtWHSu3IxjLOn0x086nW1ym29k6jAHfxZkF6Gnh2C61K93QwhVA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617985992143647.5416673741804; Fri, 9 Apr 2021 09:33:12 -0700 (PDT) Received: from localhost ([::1]:48360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUu4E-0004co-Q0 for importer@patchew.org; Fri, 09 Apr 2021 12:33:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnt-0007mI-Th for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22548) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnq-0003Nf-NN for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-530-uFtxCuYyOzeXmhF4P2hggg-1; Fri, 09 Apr 2021 12:16:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA59987A826; Fri, 9 Apr 2021 16:16:06 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8CD65D6A1; Fri, 9 Apr 2021 16:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CAw/IADhNh/BttxkT1Kn1aKYF2k8HdTDwkIzAeO6v2k=; b=LiZ+5bfJpOJ27TGl+jqCob2JlNpccudNdoUWFHG+1jkP7zfADkty4tK/htzl9k4Adje/T2 eTcNMgb7XTifiRzcVPkEKhiWtRSHowhYdAeTrLRNDMX/cP+lvQjbqHdwSGmItZeLVxtMdj M4otkLKVJc/QfLYzlKrAsOijR5ifzos= X-MC-Unique: uFtxCuYyOzeXmhF4P2hggg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 07/10] mirror: Move open_backing_file to exit_common Date: Fri, 9 Apr 2021 18:15:45 +0200 Message-Id: <20210409161548.341297-8-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz This is a graph change and therefore should be done in job-finalize (which is what invokes mirror_exit_common()). Signed-off-by: Max Reitz Message-Id: <20210409120422.144040-2-mreitz@redhat.com> Signed-off-by: Kevin Wolf --- block/mirror.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index d7e54c0ff7..f1f936bf1a 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -689,6 +689,14 @@ static int mirror_exit_common(Job *job) ret =3D -EPERM; } } + } else if (!abort && s->backing_mode =3D=3D MIRROR_OPEN_BACKING_CHAIN)= { + assert(!bdrv_backing_chain_next(target_bs)); + ret =3D bdrv_open_backing_file(bdrv_skip_filters(target_bs), NULL, + "backing", &local_err); + if (ret < 0) { + error_report_err(local_err); + local_err =3D NULL; + } } =20 if (s->to_replace) { @@ -1107,9 +1115,6 @@ immediate_exit: static void mirror_complete(Job *job, Error **errp) { MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common.job); - BlockDriverState *target; - - target =3D blk_bs(s->target); =20 if (!s->synced) { error_setg(errp, "The active block job '%s' cannot be completed", @@ -1117,17 +1122,6 @@ static void mirror_complete(Job *job, Error **errp) return; } =20 - if (s->backing_mode =3D=3D MIRROR_OPEN_BACKING_CHAIN) { - int ret; - - assert(!bdrv_backing_chain_next(target)); - ret =3D bdrv_open_backing_file(bdrv_skip_filters(target), NULL, - "backing", errp); - if (ret < 0) { - return; - } - } - /* block all operations on to_replace bs */ if (s->replaces) { AioContext *replace_aio_context; --=20 2.30.2 From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985684; cv=none; d=zohomail.com; s=zohoarc; b=Yiqjq+yH8UzbHBg3bOhqAocAJZJnSjsfc8lX+ehmUOp1G0FkYj+orjPnyjbei97SqCPdVXC2D3qViqoRumhSYd+TXSu4zEKuqAZnKe0AL7U/2I/DDQC4pGt3YTcwbLEUqFSixPp2LFb8vYjYGRsaGGGrQcJ8WThTowSk5gLP8EM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985684; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=envdenWhikru72pinNtwLZrRiTerRxbNv4jonq+HG1k=; b=d3B7BlQ2C7VFRPUPpMEh37gt4RhT8OzWsbunv+QVMBelIyGC1SkfEhSRv1agxt+IXHsZbqzV8Jp2RqD1X6kbC1O8RdMOG4Zff5/DoLy/o1Q9gEjGKyGdBIjpROGBFjlnXcE1DAdiwbNoI9mgFr/wkhk7/F+vVDZRXOwtmOd0rhg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617985684755325.6604097918672; Fri, 9 Apr 2021 09:28:04 -0700 (PDT) Received: from localhost ([::1]:35134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUtzH-0007Uv-OM for importer@patchew.org; Fri, 09 Apr 2021 12:28:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnz-0007sX-Ni for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21110) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnq-0003Ot-Ns for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-47TvgiSHM2e5VfiFRcKsYA-1; Fri, 09 Apr 2021 12:16:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0EA2610CE780; Fri, 9 Apr 2021 16:16:08 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CF9C5D6A1; Fri, 9 Apr 2021 16:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=envdenWhikru72pinNtwLZrRiTerRxbNv4jonq+HG1k=; b=ZyxPQ1BcH5ImE65kHwDXJFoRk9nBk2r9hkVIxJf/9I4qIc6EPorMtpZ+FrMEqIbJiBI6rm mb4CXJhW4Zppa2o3SbLSDWwZV2IkH1QbQYBlfQQnq7TDxe4tnILqn6C5X+GXdjWgMPA2YD ygd0Ar7btbX4L5j2a1uAYLM7B019Mdo= X-MC-Unique: 47TvgiSHM2e5VfiFRcKsYA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 08/10] mirror: Do not enter a paused job on completion Date: Fri, 9 Apr 2021 18:15:46 +0200 Message-Id: <20210409161548.341297-9-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz Currently, it is impossible to complete jobs on standby (i.e. paused ready jobs), but actually the only thing in mirror_complete() that does not work quite well with a paused job is the job_enter() at the end. If we make it conditional, this function works just fine even if the mirror job is paused. So technically this is a no-op, but obviously the intention is to accept block-job-complete even for jobs on standby, which we need this patch for first. Signed-off-by: Max Reitz Message-Id: <20210409120422.144040-3-mreitz@redhat.com> Signed-off-by: Kevin Wolf --- block/mirror.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index f1f936bf1a..5a71bd8bbc 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1148,7 +1148,11 @@ static void mirror_complete(Job *job, Error **errp) } =20 s->should_complete =3D true; - job_enter(job); + + /* If the job is paused, it will be re-entered when it is resumed */ + if (!job->paused) { + job_enter(job); + } } =20 static void coroutine_fn mirror_pause(Job *job) --=20 2.30.2 From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985337; cv=none; d=zohomail.com; s=zohoarc; b=FOoR7W8j5+F2CbqIHt/K1fLAHYOrulITmHRgrcvigpZNvmrJBY6ovG6GFpbtUHKXkTCgD139YYRBkr54qlavjn6omcWbIBdjVjv6np88jCGRQizP8hOD5hv3xIr9c6ipz7dNShPTCIdyCLUocJmaB0yyQxaNYRsGFZautTdvpJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985337; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6cyGtTKb0Ub94dC5ay9OpqyYGaN9Q+YEJi5ImXJogl8=; b=G93P7HjijXAOS4Byg3zaZj5VC/XL9jWoUZv8PhsN0R5TvN82IIQAhusRLYFnUWjLdwyDVTi9yz7mcvrhTTxRKkch+JbWK4huFqdJX23v6ovqktxuiDMOtrIMd74T2wogJKF5zDQqRP0QqgN8QHz2vP3hJ7KF/Al8EqD0mMv2Vq0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1617985337023905.5499074910084; Fri, 9 Apr 2021 09:22:17 -0700 (PDT) Received: from localhost ([::1]:42394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUttf-00076X-Ty for importer@patchew.org; Fri, 09 Apr 2021 12:22:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnt-0007lh-I4 for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34381) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnq-0003PC-N6 for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-494-rWDEfyzMPnqFNFVx0djXfA-1; Fri, 09 Apr 2021 12:16:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 732F01883520; Fri, 9 Apr 2021 16:16:09 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 559E15D6A1; Fri, 9 Apr 2021 16:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6cyGtTKb0Ub94dC5ay9OpqyYGaN9Q+YEJi5ImXJogl8=; b=hQPRHc2LSSdVA3Tza23BEzwT6Y/sYDRURhVRyoUDnva5DIN6mGq8xECa7Z1ntvLMsSy6Tq 0/2XKHHPt7QECWxcETfcW4arSII8ZJFQDv5fVEpfV1hVcHPF3meHtAdoLoraJQq3LixqDA fy3ORHkcFWuWvJkD1YPxMLITKsPL57A= X-MC-Unique: rWDEfyzMPnqFNFVx0djXfA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 09/10] job: Allow complete for jobs on standby Date: Fri, 9 Apr 2021 18:15:47 +0200 Message-Id: <20210409161548.341297-10-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz The only job that implements .complete is the mirror job, and it can handle completion requests just fine while the job is paused. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1945635 Signed-off-by: Max Reitz Message-Id: <20210409120422.144040-4-mreitz@redhat.com> Signed-off-by: Kevin Wolf --- job.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/job.c b/job.c index 289edee143..4aff13d95a 100644 --- a/job.c +++ b/job.c @@ -56,7 +56,7 @@ bool JobVerbTable[JOB_VERB__MAX][JOB_STATUS__MAX] =3D { [JOB_VERB_PAUSE] =3D {0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, [JOB_VERB_RESUME] =3D {0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, [JOB_VERB_SET_SPEED] =3D {0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, - [JOB_VERB_COMPLETE] =3D {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, + [JOB_VERB_COMPLETE] =3D {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}, [JOB_VERB_FINALIZE] =3D {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, [JOB_VERB_DISMISS] =3D {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, }; @@ -991,7 +991,7 @@ void job_complete(Job *job, Error **errp) if (job_apply_verb(job, JOB_VERB_COMPLETE, errp)) { return; } - if (job->pause_count || job_is_cancelled(job) || !job->driver->complet= e) { + if (job_is_cancelled(job) || !job->driver->complete) { error_setg(errp, "The active block job '%s' cannot be completed", job->id); return; --=20 2.30.2 From nobody Fri May 3 05:12:29 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1617985531; cv=none; d=zohomail.com; s=zohoarc; b=IhHqsBzYYCsvuBKIika12yFHPSaMqbPz8JYU1aLPHrqJd4T8ieBANDlOmSFrtpZGLjcJqoDuO3tadxSWA6FJHnxHp911pGZDVR6uORKzdq+TaY8+9Y4n/PFuhWVnrljs1dgHft10Tb9QDxPFpD0/d56jnOD63vzd+HfxvbTm1VM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617985531; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=o7fEMgeVW9+T+3j6ePfNv+7W9IpovBjHExMzjPaNj4g=; b=VdL4VIuBReyn9YanbsIFjjd+mokCXNzSfujrHHzQFjLmK6a98CObuzydWV4Ph2SfBWZZqErdKGVqA1EtLgEXACYZ9DPbqgh4EF/Dz06SQ3iqUPyDT+5Z2L5huhXn+JF6c6dM/khmIL0QbJWmURQ3W+29uMhfZoxhhkzZO+5M9v4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161798553125875.93698141317873; Fri, 9 Apr 2021 09:25:31 -0700 (PDT) Received: from localhost ([::1]:55596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUtwo-00041i-7y for importer@patchew.org; Fri, 09 Apr 2021 12:25:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnx-0007rj-PW for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUtnq-0003Pc-Oh for qemu-devel@nongnu.org; Fri, 09 Apr 2021 12:16:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-24-N0dk7AR2MtiqsuOsz2Udgw-1; Fri, 09 Apr 2021 12:16:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8460087A826; Fri, 9 Apr 2021 16:16:10 +0000 (UTC) Received: from merkur.fritz.box (ovpn-115-63.ams2.redhat.com [10.36.115.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9036A5D6A1; Fri, 9 Apr 2021 16:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617984973; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=o7fEMgeVW9+T+3j6ePfNv+7W9IpovBjHExMzjPaNj4g=; b=isUioF4E65irCV7rq49t7QeSavJwAOHHbLctokWFp3XwrmudjMQfAbHPK9kTZA2DtNrMch IgjYzepTHkCkMvzdn2YsdNLzEF7/aXHks3rtC45BV6fif42OxdahDG2kt6U1Tl9LC72POd TlBqt0TFwQbqo5m3tQn0a8yRyfHWkLI= X-MC-Unique: N0dk7AR2MtiqsuOsz2Udgw-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 10/10] test-blockjob: Test job_wait_unpaused() Date: Fri, 9 Apr 2021 18:15:48 +0200 Message-Id: <20210409161548.341297-11-kwolf@redhat.com> In-Reply-To: <20210409161548.341297-1-kwolf@redhat.com> References: <20210409161548.341297-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Max Reitz Create a job that remains on STANDBY after a drained section, and see that invoking job_wait_unpaused() will get it unstuck. Signed-off-by: Max Reitz Message-Id: <20210409120422.144040-5-mreitz@redhat.com> Signed-off-by: Kevin Wolf --- tests/unit/test-blockjob.c | 121 +++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/tests/unit/test-blockjob.c b/tests/unit/test-blockjob.c index 7519847912..dcacfa6c7c 100644 --- a/tests/unit/test-blockjob.c +++ b/tests/unit/test-blockjob.c @@ -16,6 +16,7 @@ #include "block/blockjob_int.h" #include "sysemu/block-backend.h" #include "qapi/qmp/qdict.h" +#include "iothread.h" =20 static const BlockJobDriver test_block_job_driver =3D { .job_driver =3D { @@ -375,6 +376,125 @@ static void test_cancel_concluded(void) cancel_common(s); } =20 +/* (See test_yielding_driver for the job description) */ +typedef struct YieldingJob { + BlockJob common; + bool should_complete; +} YieldingJob; + +static void yielding_job_complete(Job *job, Error **errp) +{ + YieldingJob *s =3D container_of(job, YieldingJob, common.job); + s->should_complete =3D true; + job_enter(job); +} + +static int coroutine_fn yielding_job_run(Job *job, Error **errp) +{ + YieldingJob *s =3D container_of(job, YieldingJob, common.job); + + job_transition_to_ready(job); + + while (!s->should_complete) { + job_yield(job); + } + + return 0; +} + +/* + * This job transitions immediately to the READY state, and then + * yields until it is to complete. + */ +static const BlockJobDriver test_yielding_driver =3D { + .job_driver =3D { + .instance_size =3D sizeof(YieldingJob), + .free =3D block_job_free, + .user_resume =3D block_job_user_resume, + .run =3D yielding_job_run, + .complete =3D yielding_job_complete, + }, +}; + +/* + * Test that job_complete() works even on jobs that are in a paused + * state (i.e., STANDBY). + * + * To do this, run YieldingJob in an IO thread, get it into the READY + * state, then have a drained section. Before ending the section, + * acquire the context so the job will not be entered and will thus + * remain on STANDBY. + * + * job_complete() should still work without error. + * + * Note that on the QMP interface, it is impossible to lock an IO + * thread before a drained section ends. In practice, the + * bdrv_drain_all_end() and the aio_context_acquire() will be + * reversed. However, that makes for worse reproducibility here: + * Sometimes, the job would no longer be in STANDBY then but already + * be started. We cannot prevent that, because the IO thread runs + * concurrently. We can only prevent it by taking the lock before + * ending the drained section, so we do that. + * + * (You can reverse the order of operations and most of the time the + * test will pass, but sometimes the assert(status =3D=3D STANDBY) will + * fail.) + */ +static void test_complete_in_standby(void) +{ + BlockBackend *blk; + IOThread *iothread; + AioContext *ctx; + Job *job; + BlockJob *bjob; + + /* Create a test drive, move it to an IO thread */ + blk =3D create_blk(NULL); + iothread =3D iothread_new(); + + ctx =3D iothread_get_aio_context(iothread); + blk_set_aio_context(blk, ctx, &error_abort); + + /* Create our test job */ + bjob =3D mk_job(blk, "job", &test_yielding_driver, true, + JOB_MANUAL_FINALIZE | JOB_MANUAL_DISMISS); + job =3D &bjob->job; + assert(job->status =3D=3D JOB_STATUS_CREATED); + + /* Wait for the job to become READY */ + job_start(job); + aio_context_acquire(ctx); + AIO_WAIT_WHILE(ctx, job->status !=3D JOB_STATUS_READY); + aio_context_release(ctx); + + /* Begin the drained section, pausing the job */ + bdrv_drain_all_begin(); + assert(job->status =3D=3D JOB_STATUS_STANDBY); + /* Lock the IO thread to prevent the job from being run */ + aio_context_acquire(ctx); + /* This will schedule the job to resume it */ + bdrv_drain_all_end(); + + /* But the job cannot run, so it will remain on standby */ + assert(job->status =3D=3D JOB_STATUS_STANDBY); + + /* Even though the job is on standby, this should work */ + job_complete(job, &error_abort); + + /* The test is done now, clean up. */ + job_finish_sync(job, NULL, &error_abort); + assert(job->status =3D=3D JOB_STATUS_PENDING); + + job_finalize(job, &error_abort); + assert(job->status =3D=3D JOB_STATUS_CONCLUDED); + + job_dismiss(&job, &error_abort); + + destroy_blk(blk); + aio_context_release(ctx); + iothread_join(iothread); +} + int main(int argc, char **argv) { qemu_init_main_loop(&error_abort); @@ -389,5 +509,6 @@ int main(int argc, char **argv) g_test_add_func("/blockjob/cancel/standby", test_cancel_standby); g_test_add_func("/blockjob/cancel/pending", test_cancel_pending); g_test_add_func("/blockjob/cancel/concluded", test_cancel_concluded); + g_test_add_func("/blockjob/complete_in_standby", test_complete_in_stan= dby); return g_test_run(); } --=20 2.30.2