From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602071973; cv=none; d=zohomail.com; s=zohoarc; b=IAPwSz8m2Y3rByfVjrUrZCSiupjka3N5KVZBM5QB8ZNCqZGo48k2114CfUTGD0uNK9ovBbBHjO1La1oANZSARjltaEBBv5nKI7CVVqZuMa7/av5GcmmhJUy2nPVJ6KEgJrEA51cfhpMGCg3dXOO7xTMLsEsdkRCZnD12LUt+8KE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602071973; 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=mkBNPei9uMoqu12UG5Q0b8HB14/E7ipCviA8H8P7BJA=; b=OktHbqcqLMVOgvv3YGJ8BlTED8beBU4BDw1X8AieoJBby5oLd1O1JVfMIhwkX3AFTkEUCroFzWrzC32tZ1EIWiJoMPhFtCx/vRY1ZYeszJZ9Vl89RbasOa4FZgSXvAQKgj8iNOiJNWZTjtxhmO9QlQmvFRvVZcVvBS9UMt2ua7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602071973711453.55585642269375; Wed, 7 Oct 2020 04:59:33 -0700 (PDT) Received: from localhost ([::1]:49040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ86W-0004b5-6l for importer@patchew.org; Wed, 07 Oct 2020 07:59:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84H-0001T4-65 for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84C-0001ge-RS for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:12 -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-168-LVEceakyO_GqGnslRwxHqw-1; Wed, 07 Oct 2020 07:57: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 D773C81F005; Wed, 7 Oct 2020 11:57:04 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id A83235577B; Wed, 7 Oct 2020 11:57:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071828; 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=mkBNPei9uMoqu12UG5Q0b8HB14/E7ipCviA8H8P7BJA=; b=YjyAg3Czlfyaqf+xYa38zFYqU5/N/hhZYReec3iLObBsr4CAwvTj5cYth+9gbTkVJjd9Wz 31xJufm+Hs7nom9iLpK2DQJkUhU/PR5YqpDgDttB5/yIBPDTB2kjlmBpnEySKo2iAHhF2D uT+XMTBCvU14Prc2DMfA8FGycIOuB4E= X-MC-Unique: LVEceakyO_GqGnslRwxHqw-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 01/17] qtest: rename qtest_qmp_receive to qtest_qmp_receive_dict Date: Wed, 7 Oct 2020 07:56:44 -0400 Message-Id: <20201007115700.707938-2-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, Maxim Levitsky , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky In the next patch a new version of qtest_qmp_receive will be reintroduced that will buffer received qmp events for later consumption in qtest_qmp_eventwait_ref No functional change intended. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky Signed-off-by: Paolo Bonzini --- tests/qtest/ahci-test.c | 4 ++-- tests/qtest/device-plug-test.c | 2 +- tests/qtest/drive_del-test.c | 2 +- tests/qtest/libqos/libqtest.h | 4 ++-- tests/qtest/libqtest.c | 16 ++++++++-------- tests/qtest/pvpanic-test.c | 2 +- tests/qtest/qmp-test.c | 18 +++++++++--------- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index 5e1954852e..d42ebaeb4c 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1590,7 +1590,7 @@ static void test_atapi_tray(void) qtest_qmp_send(ahci->parent->qts, "{'execute': 'blockdev-open-tray', " "'arguments': {'id': 'cd0'}}"); atapi_wait_tray(ahci, true); - rsp =3D qtest_qmp_receive(ahci->parent->qts); + rsp =3D qtest_qmp_receive_dict(ahci->parent->qts); qobject_unref(rsp); =20 qmp_discard_response(ahci->parent->qts, @@ -1620,7 +1620,7 @@ static void test_atapi_tray(void) qtest_qmp_send(ahci->parent->qts, "{'execute': 'blockdev-close-tray', " "'arguments': {'id': 'cd0'}}"); atapi_wait_tray(ahci, false); - rsp =3D qtest_qmp_receive(ahci->parent->qts); + rsp =3D qtest_qmp_receive_dict(ahci->parent->qts); qobject_unref(rsp); =20 /* Now, to convince ATAPI we understand the media has changed... */ diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c index 9214892741..a2247856be 100644 --- a/tests/qtest/device-plug-test.c +++ b/tests/qtest/device-plug-test.c @@ -23,7 +23,7 @@ static void device_del_start(QTestState *qtest, const cha= r *id) =20 static void device_del_finish(QTestState *qtest) { - QDict *resp =3D qtest_qmp_receive(qtest); + QDict *resp =3D qtest_qmp_receive_dict(qtest); =20 g_assert(qdict_haskey(resp, "return")); qobject_unref(resp); diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c index 2d765865ce..ba0cd77445 100644 --- a/tests/qtest/drive_del-test.c +++ b/tests/qtest/drive_del-test.c @@ -41,7 +41,7 @@ static void device_del(QTestState *qts) /* Complication: ignore DEVICE_DELETED event */ qmp_discard_response(qts, "{'execute': 'device_del'," " 'arguments': { 'id': 'dev0' } }"); - response =3D qtest_qmp_receive(qts); + response =3D qtest_qmp_receive_dict(qts); g_assert(response); g_assert(qdict_haskey(response, "return")); qobject_unref(response); diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h index 209fcf6973..9b3f99b322 100644 --- a/tests/qtest/libqos/libqtest.h +++ b/tests/qtest/libqos/libqtest.h @@ -191,12 +191,12 @@ void qtest_qmp_vsend(QTestState *s, const char *fmt, = va_list ap) GCC_FMT_ATTR(2, 0); =20 /** - * qtest_receive: + * qtest_qmp_receive_dict: * @s: #QTestState instance to operate on. * * Reads a QMP message from QEMU and returns the response. */ -QDict *qtest_qmp_receive(QTestState *s); +QDict *qtest_qmp_receive_dict(QTestState *s); =20 /** * qtest_qmp_eventwait: diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 58f58e1ece..dadc465825 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -322,7 +322,7 @@ QTestState *qtest_init(const char *extra_args) QDict *greeting; =20 /* Read the QMP greeting and then do the handshake */ - greeting =3D qtest_qmp_receive(s); + greeting =3D qtest_qmp_receive_dict(s); qobject_unref(greeting); qobject_unref(qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }")); =20 @@ -603,7 +603,7 @@ QDict *qmp_fd_receive(int fd) return qmp.response; } =20 -QDict *qtest_qmp_receive(QTestState *s) +QDict *qtest_qmp_receive_dict(QTestState *s) { return qmp_fd_receive(s->qmp_fd); } @@ -678,7 +678,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t f= ds_num, qtest_qmp_vsend_fds(s, fds, fds_num, fmt, ap); =20 /* Receive reply */ - return qtest_qmp_receive(s); + return qtest_qmp_receive_dict(s); } =20 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap) @@ -686,7 +686,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_li= st ap) qtest_qmp_vsend(s, fmt, ap); =20 /* Receive reply */ - return qtest_qmp_receive(s); + return qtest_qmp_receive_dict(s); } =20 QDict *qmp_fd(int fd, const char *fmt, ...) @@ -776,7 +776,7 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const cha= r *event) QDict *response; =20 for (;;) { - response =3D qtest_qmp_receive(s); + response =3D qtest_qmp_receive_dict(s); if ((qdict_haskey(response, "event")) && (strcmp(qdict_get_str(response, "event"), event) =3D=3D 0)) { return response; @@ -807,7 +807,7 @@ char *qtest_vhmp(QTestState *s, const char *fmt, va_lis= t ap) while (ret =3D=3D NULL && qdict_get_try_str(resp, "event")) { /* Ignore asynchronous QMP events */ qobject_unref(resp); - resp =3D qtest_qmp_receive(s); + resp =3D qtest_qmp_receive_dict(s); ret =3D g_strdup(qdict_get_try_str(resp, "return")); } g_assert(ret); @@ -1255,7 +1255,7 @@ QDict *qtest_qmp_receive_success(QTestState *s, const char *event; =20 for (;;) { - response =3D qtest_qmp_receive(s); + response =3D qtest_qmp_receive_dict(s); g_assert(!qdict_haskey(response, "error")); ret =3D qdict_get_qdict(response, "return"); if (ret) { @@ -1345,7 +1345,7 @@ void qtest_qmp_device_del(QTestState *qts, const char= *id) rsp =3D qtest_qmp_receive_success(qts, device_deleted_cb, &got_event); qobject_unref(rsp); if (!got_event) { - rsp =3D qtest_qmp_receive(qts); + rsp =3D qtest_qmp_receive_dict(qts); g_assert_cmpstr(qdict_get_try_str(rsp, "event"), =3D=3D, "DEVICE_DELETED"); qobject_unref(rsp); diff --git a/tests/qtest/pvpanic-test.c b/tests/qtest/pvpanic-test.c index e57639481e..b0b20ad340 100644 --- a/tests/qtest/pvpanic-test.c +++ b/tests/qtest/pvpanic-test.c @@ -24,7 +24,7 @@ static void test_panic(void) =20 qtest_outb(qts, 0x505, 0x1); =20 - response =3D qtest_qmp_receive(qts); + response =3D qtest_qmp_receive_dict(qts); g_assert(qdict_haskey(response, "event")); g_assert_cmpstr(qdict_get_str(response, "event"), =3D=3D, "GUEST_PANIC= KED"); g_assert(qdict_haskey(response, "data")); diff --git a/tests/qtest/qmp-test.c b/tests/qtest/qmp-test.c index e1032c5a21..eb1cd8abb8 100644 --- a/tests/qtest/qmp-test.c +++ b/tests/qtest/qmp-test.c @@ -47,37 +47,37 @@ static void test_malformed(QTestState *qts) =20 /* syntax error */ qtest_qmp_send_raw(qts, "{]\n"); - resp =3D qtest_qmp_receive(qts); + resp =3D qtest_qmp_receive_dict(qts); qmp_expect_error_and_unref(resp, "GenericError"); assert_recovered(qts); =20 /* lexical error: impossible byte outside string */ qtest_qmp_send_raw(qts, "{\xFF"); - resp =3D qtest_qmp_receive(qts); + resp =3D qtest_qmp_receive_dict(qts); qmp_expect_error_and_unref(resp, "GenericError"); assert_recovered(qts); =20 /* lexical error: funny control character outside string */ qtest_qmp_send_raw(qts, "{\x01"); - resp =3D qtest_qmp_receive(qts); + resp =3D qtest_qmp_receive_dict(qts); qmp_expect_error_and_unref(resp, "GenericError"); assert_recovered(qts); =20 /* lexical error: impossible byte in string */ qtest_qmp_send_raw(qts, "{'bad \xFF"); - resp =3D qtest_qmp_receive(qts); + resp =3D qtest_qmp_receive_dict(qts); qmp_expect_error_and_unref(resp, "GenericError"); assert_recovered(qts); =20 /* lexical error: control character in string */ qtest_qmp_send_raw(qts, "{'execute': 'nonexistent', 'id':'\n"); - resp =3D qtest_qmp_receive(qts); + resp =3D qtest_qmp_receive_dict(qts); qmp_expect_error_and_unref(resp, "GenericError"); assert_recovered(qts); =20 /* lexical error: interpolation */ qtest_qmp_send_raw(qts, "%%p"); - resp =3D qtest_qmp_receive(qts); + resp =3D qtest_qmp_receive_dict(qts); qmp_expect_error_and_unref(resp, "GenericError"); assert_recovered(qts); =20 @@ -111,7 +111,7 @@ static void test_qmp_protocol(void) qts =3D qtest_init_without_qmp_handshake(common_args); =20 /* Test greeting */ - resp =3D qtest_qmp_receive(qts); + resp =3D qtest_qmp_receive_dict(qts); q =3D qdict_get_qdict(resp, "QMP"); g_assert(q); test_version(qdict_get(q, "version")); @@ -205,7 +205,7 @@ static void send_oob_cmd_that_fails(QTestState *s, cons= t char *id) =20 static void recv_cmd_id(QTestState *s, const char *id) { - QDict *resp =3D qtest_qmp_receive(s); + QDict *resp =3D qtest_qmp_receive_dict(s); =20 g_assert_cmpstr(qdict_get_try_str(resp, "id"), =3D=3D, id); qobject_unref(resp); @@ -222,7 +222,7 @@ static void test_qmp_oob(void) qts =3D qtest_init_without_qmp_handshake(common_args); =20 /* Check the greeting message. */ - resp =3D qtest_qmp_receive(qts); + resp =3D qtest_qmp_receive_dict(qts); q =3D qdict_get_qdict(resp, "QMP"); g_assert(q); capabilities =3D qdict_get_qlist(q, "capabilities"); --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072300; cv=none; d=zohomail.com; s=zohoarc; b=A47/0wHJ1l7TO3GkzZOMjc02feccoJPyxmPydaqHWeaO7QBkrn3ACvU0k/5ewuxg0j86XciuDI8F6T0PImahf2hhI9zeIhqqJINYny1cjPdBKci/GifWzY5P1c9MPF+y5AHsioYXEbvk6gclxnv/78MgSGpH2UzuzFjTnhpZ3Aw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072300; 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=WSybe/F61UcKWf9cKwsuGQfmd1CuQH+qTGEvPZqxSsI=; b=WogRrynYOVSeBe2A6lqJEf9qPymJH/w4WZdvQM1F/kBjuj7jGmdtRR+KP6xFQv6XGqlHbW1tf2IlndWfZEmj3RRYMePyWlBt34BAMY1tTd/LlMa4Qnw0lcynWHUlTrO5YB3vDjcxCv0nJxzgupDBkB67EvcdY1EgXbDQkMUOwr0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072300988554.9776682035485; Wed, 7 Oct 2020 05:05:00 -0700 (PDT) Received: from localhost ([::1]:33980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8Bl-0001qn-Uq for importer@patchew.org; Wed, 07 Oct 2020 08:04:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84I-0001Ud-Nx for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:37449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84D-0001gl-1P for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57: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-230-MuZp7bqoMBSD-3z2-GyhHg-1; Wed, 07 Oct 2020 07:57: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 6BC4710BBEC5; Wed, 7 Oct 2020 11:57:05 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id F15C95577B; Wed, 7 Oct 2020 11:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071828; 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=WSybe/F61UcKWf9cKwsuGQfmd1CuQH+qTGEvPZqxSsI=; b=IehpTEdu+RsePpfl90TgPn9QQTq6bi6DmFDZ1nqoLjdbeRYl/M34hc/MHhrbZ9sdNpF4nE NxWVy2eXCwFIbwLlSy219ZV9+GRZwc4Q++Bp6uPxDZgCqeEdTtvOkuuOBP3KvZWy+rf22C IsCg0edUXYe3ECWnkCFjGB7vm7iVnOk= X-MC-Unique: MuZp7bqoMBSD-3z2-GyhHg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 02/17] qtest: Reintroduce qtest_qmp_receive Date: Wed, 7 Oct 2020 07:56:45 -0400 Message-Id: <20201007115700.707938-3-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, Maxim Levitsky , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky The new qtest_qmp_receive buffers all the received qmp events, allowing qtest_qmp_eventwait_ref to return them. This is intended to solve the race in regard to ordering of qmp events vs qmp responses, as soon as the callers start using the new interface. In addition to that, define qtest_qmp_event_ref a function which only scans the buffer that qtest_qmp_receive stores the events to. This is intended for callers that are only interested in events that were received during the last call to the qtest_qmp_receive. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky Message-Id: <20201006123904.610658-3-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- tests/qtest/libqos/libqtest.h | 23 ++++++++++++++++ tests/qtest/libqtest.c | 49 ++++++++++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h index 9b3f99b322..a2e3961792 100644 --- a/tests/qtest/libqos/libqtest.h +++ b/tests/qtest/libqos/libqtest.h @@ -198,6 +198,16 @@ void qtest_qmp_vsend(QTestState *s, const char *fmt, v= a_list ap) */ QDict *qtest_qmp_receive_dict(QTestState *s); =20 +/** + * qtest_qmp_receive: + * @s: #QTestState instance to operate on. + * + * Reads a QMP message from QEMU and returns the response. + * Buffers all the events received meanwhile, until a + * call to qtest_qmp_eventwait + */ +QDict *qtest_qmp_receive(QTestState *s); + /** * qtest_qmp_eventwait: * @s: #QTestState instance to operate on. @@ -217,6 +227,19 @@ void qtest_qmp_eventwait(QTestState *s, const char *ev= ent); */ QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event); =20 +/** + * qtest_qmp_event_ref: + * @s: #QTestState instance to operate on. + * @s: #event event to return. + * + * Removes non-matching events from the buffer that was set by + * qtest_qmp_receive, until an event bearing the given name is found, + * and returns it. + * If no event matches, clears the buffer and returns NULL. + * + */ +QDict *qtest_qmp_event_ref(QTestState *s, const char *event); + /** * qtest_qmp_receive_success: * @s: #QTestState instance to operate on diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index dadc465825..d4c49a52ff 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -63,6 +63,7 @@ struct QTestState bool irq_level[MAX_IRQ]; GString *rx; QTestTransportOps ops; + GList *pending_events; }; =20 static GHookList abrt_hooks; @@ -279,6 +280,7 @@ QTestState *qtest_init_without_qmp_handshake(const char= *extra_args) =20 g_test_message("starting QEMU: %s", command); =20 + s->pending_events =3D NULL; s->wstatus =3D 0; s->expected_status =3D 0; s->qemu_pid =3D fork(); @@ -386,6 +388,13 @@ void qtest_quit(QTestState *s) close(s->fd); close(s->qmp_fd); g_string_free(s->rx, true); + + for (GList *it =3D s->pending_events; it !=3D NULL; it =3D it->next) { + qobject_unref((QDict *)it->data); + } + + g_list_free(s->pending_events); + g_free(s); } =20 @@ -603,6 +612,19 @@ QDict *qmp_fd_receive(int fd) return qmp.response; } =20 +QDict *qtest_qmp_receive(QTestState *s) +{ + while (true) { + QDict *response =3D qtest_qmp_receive_dict(s); + + if (!qdict_get_try_str(response, "event")) { + return response; + } + /* Stash the event for a later consumption */ + s->pending_events =3D g_list_prepend(s->pending_events, response); + } +} + QDict *qtest_qmp_receive_dict(QTestState *s) { return qmp_fd_receive(s->qmp_fd); @@ -771,10 +793,34 @@ void qtest_qmp_send_raw(QTestState *s, const char *fm= t, ...) va_end(ap); } =20 -QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event) +QDict *qtest_qmp_event_ref(QTestState *s, const char *event) { + GList *next =3D NULL; QDict *response; =20 + for (GList *it =3D s->pending_events; it !=3D NULL; it =3D next) { + + next =3D it->next; + response =3D (QDict *)it->data; + + s->pending_events =3D g_list_remove_link(s->pending_events, it); + + if (!strcmp(qdict_get_str(response, "event"), event)) { + return response; + } + qobject_unref(response); + } + return NULL; +} + +QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event) +{ + QDict *response =3D qtest_qmp_event_ref(s, event); + + if (response) { + return response; + } + for (;;) { response =3D qtest_qmp_receive_dict(s); if ((qdict_haskey(response, "event")) && @@ -1403,6 +1449,7 @@ QTestState *qtest_inproc_init(QTestState **s, bool lo= g, const char* arch, { QTestState *qts; qts =3D g_new0(QTestState, 1); + qts->pending_events =3D NULL; *s =3D qts; /* Expose qts early on, since the query endianness relies = on it */ qts->wstatus =3D 0; for (int i =3D 0; i < MAX_IRQ; i++) { --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072174; cv=none; d=zohomail.com; s=zohoarc; b=hVdPSs6TRm5hpXPsOUdgTFiucZOwE5cyh/gPh+dB2Eiyh5/NJ5V0QaZ1LFJsWviySNlyN/hXB89wZSWK4xmzyOpurynvox7EnBbvsqBw94ZU0tsqxAJGVc2I3c1mk+KR3S2yAXGcnB+TL9pIn+bEK8QgaKp4HMLJWbZTRd+DY3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072174; 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=uAJ2cD9EbDnle3AkY/6ltfJ3Qb/+qcsUaD8BFkIZXuc=; b=SsiIGlvzdInNEjVif4KN51Q4tx/2btlg/YO1OSrdJ3/PjNNd4MOQNNSfr2cnQX+xGd5tlptq2D2lgJdbRIrVUmBjbNqSevk3cTH5tcdMTU9yvrbhahUTw5Mle4WK5xK1BjfZ6X4mxjMamiw/NzsfzdWGdTu1n1K5mYIwa7u/RsM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072174110160.65279387793896; Wed, 7 Oct 2020 05:02:54 -0700 (PDT) Received: from localhost ([::1]:57652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ89k-0008OA-PH for importer@patchew.org; Wed, 07 Oct 2020 08:02:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84H-0001Tg-Ip for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84D-0001gw-Nh for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:13 -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-509-Sz4BSwIoNIGAm6eVqY0NnA-1; Wed, 07 Oct 2020 07:57: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 F1B4510BBEC7; Wed, 7 Oct 2020 11:57:05 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84E995577B; Wed, 7 Oct 2020 11:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071829; 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=uAJ2cD9EbDnle3AkY/6ltfJ3Qb/+qcsUaD8BFkIZXuc=; b=QlfrsBHGoXSuNdTrwhSqXTGJ1zBC13PEUrzxmvg0jCOkFwqVKAGKz4Giw+OQ1/oiHggsl0 VZelUhf5nIbTz0RlFNi38DFg3Dw0mMyKEPBqVxEpcBLpgLASarJ0G3z9jOvslhtt79WsWL V3PVtwt2r6ln6dDVQkHp606OIPssAmk= X-MC-Unique: Sz4BSwIoNIGAm6eVqY0NnA-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 03/17] qtest: remove qtest_qmp_receive_success Date: Wed, 7 Oct 2020 07:56:46 -0400 Message-Id: <20201007115700.707938-4-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:54:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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, Maxim Levitsky , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky The purpose of qtest_qmp_receive_success was mostly to process events that arrived between the issueing of a command and the "return" line from QMP. This is now handled by the buffering of events that libqtest performs automatically. Signed-off-by: Maxim Levitsky [Extracted from Maxim's patch to a separate commit. - Paolo] Signed-off-by: Paolo Bonzini --- tests/qtest/libqos/libqtest.h | 17 ----------- tests/qtest/libqtest.c | 53 ++++----------------------------- tests/qtest/migration-helpers.c | 25 ++++++++++++---- 3 files changed, 25 insertions(+), 70 deletions(-) diff --git a/tests/qtest/libqos/libqtest.h b/tests/qtest/libqos/libqtest.h index a2e3961792..64bb1cd9eb 100644 --- a/tests/qtest/libqos/libqtest.h +++ b/tests/qtest/libqos/libqtest.h @@ -240,23 +240,6 @@ QDict *qtest_qmp_eventwait_ref(QTestState *s, const ch= ar *event); */ QDict *qtest_qmp_event_ref(QTestState *s, const char *event); =20 -/** - * qtest_qmp_receive_success: - * @s: #QTestState instance to operate on - * @event_cb: Event callback - * @opaque: Argument for @event_cb - * - * Poll QMP messages until a command success response is received. - * If @event_cb, call it for each event received, passing @opaque, - * the event's name and data. - * Return the success response's "return" member. - */ -QDict *qtest_qmp_receive_success(QTestState *s, - void (*event_cb)(void *opaque, - const char *name, - QDict *data), - void *opaque); - /** * qtest_hmp: * @s: #QTestState instance to operate on. diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index d4c49a52ff..baac667b8d 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -1291,35 +1291,6 @@ void qtest_cb_for_every_machine(void (*cb)(const cha= r *machine), qobject_unref(response); } =20 -QDict *qtest_qmp_receive_success(QTestState *s, - void (*event_cb)(void *opaque, - const char *event, - QDict *data), - void *opaque) -{ - QDict *response, *ret, *data; - const char *event; - - for (;;) { - response =3D qtest_qmp_receive_dict(s); - g_assert(!qdict_haskey(response, "error")); - ret =3D qdict_get_qdict(response, "return"); - if (ret) { - break; - } - event =3D qdict_get_str(response, "event"); - data =3D qdict_get_qdict(response, "data"); - if (event_cb) { - event_cb(opaque, event, data); - } - qobject_unref(response); - } - - qobject_ref(ret); - qobject_unref(response); - return ret; -} - /* * Generic hot-plugging test via the device_add QMP commands. */ @@ -1355,13 +1326,6 @@ void qtest_qmp_device_add(QTestState *qts, const cha= r *driver, const char *id, qobject_unref(args); } =20 -static void device_deleted_cb(void *opaque, const char *name, QDict *data) -{ - bool *got_event =3D opaque; - - g_assert_cmpstr(name, =3D=3D, "DEVICE_DELETED"); - *got_event =3D true; -} =20 /* * Generic hot-unplugging test via the device_del QMP command. @@ -1378,24 +1342,17 @@ static void device_deleted_cb(void *opaque, const c= har *name, QDict *data) * and this one: * * {"return": {}} - * - * But the order of arrival may vary - so we've got to detect both. */ void qtest_qmp_device_del(QTestState *qts, const char *id) { - bool got_event =3D false; QDict *rsp; =20 - qtest_qmp_send(qts, "{'execute': 'device_del', 'arguments': {'id': %s}= }", - id); - rsp =3D qtest_qmp_receive_success(qts, device_deleted_cb, &got_event); + rsp =3D qtest_qmp(qts, "{'execute': 'device_del', 'arguments': {'id': = %s}}", + id); + + g_assert(qdict_haskey(rsp, "return")); qobject_unref(rsp); - if (!got_event) { - rsp =3D qtest_qmp_receive_dict(qts); - g_assert_cmpstr(qdict_get_try_str(rsp, "event"), - =3D=3D, "DEVICE_DELETED"); - qobject_unref(rsp); - } + qtest_qmp_eventwait(qts, "DEVICE_DELETED"); } =20 bool qmp_rsp_is_err(QDict *rsp) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index 516093b39a..b799dbafb7 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -17,10 +17,12 @@ =20 bool got_stop; =20 -static void stop_cb(void *opaque, const char *name, QDict *data) +static void check_stop_event(QTestState *who) { - if (!strcmp(name, "STOP")) { + QDict *event =3D qtest_qmp_event_ref(who, "STOP"); + if (event) { got_stop =3D true; + qobject_unref(event); } } =20 @@ -30,12 +32,19 @@ static void stop_cb(void *opaque, const char *name, QDi= ct *data) QDict *wait_command_fd(QTestState *who, int fd, const char *command, ...) { va_list ap; + QDict *resp; =20 va_start(ap, command); qtest_qmp_vsend_fds(who, &fd, 1, command, ap); va_end(ap); =20 - return qtest_qmp_receive_success(who, stop_cb, NULL); + resp =3D qtest_qmp_receive(who); + check_stop_event(who); + + g_assert(!qdict_haskey(resp, "error")); + g_assert(qdict_haskey(resp, "return")); + + return qdict_get_qdict(resp, "return"); } =20 /* @@ -44,12 +53,18 @@ QDict *wait_command_fd(QTestState *who, int fd, const c= har *command, ...) QDict *wait_command(QTestState *who, const char *command, ...) { va_list ap; + QDict *resp; =20 va_start(ap, command); - qtest_qmp_vsend(who, command, ap); + resp =3D qtest_vqmp(who, command, ap); va_end(ap); =20 - return qtest_qmp_receive_success(who, stop_cb, NULL); + check_stop_event(who); + + g_assert(!qdict_haskey(resp, "error")); + g_assert(qdict_haskey(resp, "return")); + + return qdict_get_qdict(resp, "return"); } =20 /* --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072102; cv=none; d=zohomail.com; s=zohoarc; b=TfcOmsEOrfNzXiWbxfOf4jcCtYDOuN4UOGduUtbQrR/eMrJJ2+0O2rAbHeMoW4iRy46dUOJuzjTl6lhRanFyyEPVIMJciXrH84+AGqZD2a0dTPMwKBq+UPzo0upzLMiB3iSg3LrOZrThRPDxbTaoq0K0cVisXNRQ4lIy598cidE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072102; 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=wE4xYngsHjpqAQke6cOySjcfqIG9xco+FEa43LMMRDo=; b=nKWcpp6z61KQGnH4LmJm0krPSSXXyz/L9uzE8HQABV4qh3MHTBiHdJCGTGrNFAQUVUH+NjWaqyN960W38oNZLZd/4Mjj56jRtfQjkND0tWJYFiBgMsPcKzhwHSvuMfTpL6TvVB75oYqMoW2v/y/gut+hBbuRchOralzJDDKTvI8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072102498524.2330407564026; Wed, 7 Oct 2020 05:01:42 -0700 (PDT) Received: from localhost ([::1]:53796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ88b-0006ij-0s for importer@patchew.org; Wed, 07 Oct 2020 08:01:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84H-0001T2-2n for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52715) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84D-0001gy-V3 for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:12 -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-196-8QZhCiaZPkmckPLRtzj5mA-1; Wed, 07 Oct 2020 07:57: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 76C0A425E0; Wed, 7 Oct 2020 11:57:06 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 186F755760; Wed, 7 Oct 2020 11:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071829; 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=wE4xYngsHjpqAQke6cOySjcfqIG9xco+FEa43LMMRDo=; b=Fvm0LZqpzKOLySbMrYkW24fa42PNhvigYx75XY1yFNI0k55fGLNp67Bzj8N3WWVKhvBx/N QO9McLVYa6O4ZeLRJ3PCEdXnoFD4s1HlyiQn2afCfCrE0YD1AWOE5vVIMtI+ktweqh31p7 eCcRNw40hRomlhUmlSV3RpgB64/kFac= X-MC-Unique: 8QZhCiaZPkmckPLRtzj5mA-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 04/17] device-plug-test: use qtest_qmp to send the device_del command Date: Wed, 7 Oct 2020 07:56:47 -0400 Message-Id: <20201007115700.707938-5-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Simplify the code now that events are buffered. There is no need anymore to separate sending the command and retrieving the response. Signed-off-by: Paolo Bonzini --- tests/qtest/device-plug-test.c | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c index a2247856be..559d47727a 100644 --- a/tests/qtest/device-plug-test.c +++ b/tests/qtest/device-plug-test.c @@ -15,26 +15,17 @@ #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" =20 -static void device_del_start(QTestState *qtest, const char *id) +static void device_del(QTestState *qtest, const char *id) { - qtest_qmp_send(qtest, - "{'execute': 'device_del', 'arguments': { 'id': %s } }"= , id); -} + QDict *resp; =20 -static void device_del_finish(QTestState *qtest) -{ - QDict *resp =3D qtest_qmp_receive_dict(qtest); + resp =3D qtest_qmp(qtest, + "{'execute': 'device_del', 'arguments': { 'id': %s } = }", id); =20 g_assert(qdict_haskey(resp, "return")); qobject_unref(resp); } =20 -static void device_del_request(QTestState *qtest, const char *id) -{ - device_del_start(qtest, id); - device_del_finish(qtest); -} - static void system_reset(QTestState *qtest) { QDict *resp; @@ -79,7 +70,7 @@ static void test_pci_unplug_request(void) * be processed. However during system reset, the removal will be * handled, removing the device. */ - device_del_request(qtest, "dev0"); + device_del(qtest, "dev0"); system_reset(qtest); wait_device_deleted_event(qtest, "dev0"); =20 @@ -90,13 +81,8 @@ static void test_ccw_unplug(void) { QTestState *qtest =3D qtest_initf("-device virtio-balloon-ccw,id=3Ddev= 0"); =20 - /* - * The DEVICE_DELETED events will be sent before the command - * completes. - */ - device_del_start(qtest, "dev0"); + device_del(qtest, "dev0"); wait_device_deleted_event(qtest, "dev0"); - device_del_finish(qtest); =20 qtest_quit(qtest); } @@ -109,7 +95,7 @@ static void test_spapr_cpu_unplug_request(void) "-device power9_v2.0-spapr-cpu-core,core-id=3D1,id= =3Ddev0"); =20 /* similar to test_pci_unplug_request */ - device_del_request(qtest, "dev0"); + device_del(qtest, "dev0"); system_reset(qtest); wait_device_deleted_event(qtest, "dev0"); =20 @@ -125,7 +111,7 @@ static void test_spapr_memory_unplug_request(void) "-device pc-dimm,id=3Ddev0,memdev=3Dmem0"); =20 /* similar to test_pci_unplug_request */ - device_del_request(qtest, "dev0"); + device_del(qtest, "dev0"); system_reset(qtest); wait_device_deleted_event(qtest, "dev0"); =20 @@ -139,7 +125,7 @@ static void test_spapr_phb_unplug_request(void) qtest =3D qtest_initf("-device spapr-pci-host-bridge,index=3D1,id=3Dde= v0"); =20 /* similar to test_pci_unplug_request */ - device_del_request(qtest, "dev0"); + device_del(qtest, "dev0"); system_reset(qtest); wait_device_deleted_event(qtest, "dev0"); =20 --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602071940; cv=none; d=zohomail.com; s=zohoarc; b=InqP6NGVwz73N9oAKe1saZdmqL9hAgh25sD4VZMwb2h6StLmNT29ZAsVfhyGZlpSxcsD//hB83SoPavMy7CLKm7zdTuR2YHZFk0eJZXgVSuOhgnPskYk7PSSZXUyC4ArkeuMC+cv0rcIkcVZTf8SIcMdNiYo2M/eh1Cre4ZwQyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602071940; 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=55WpEi90PG0R1Tz2B85E8h1Orp/fQfXznmS5ayIoWgQ=; b=QJlIcYuDYnFycPMwEckqJAtokoqSFxchSXqO8X/skMLluvsDE1G2x8hbvMP0Ekr9BEBb2i6MAfM4Jx7UHJteOaikhUmjJg0luExHLnbPUDmDDmXwUPMz7j6TLXOG/5ppg3SVXkuHLk/QaXdLBJtjUC9bTIYpiSXS8OQOyvmELes= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602071940007455.2076097719048; Wed, 7 Oct 2020 04:59:00 -0700 (PDT) Received: from localhost ([::1]:47130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ85y-0003pY-My for importer@patchew.org; Wed, 07 Oct 2020 07:58:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84J-0001VT-8X for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84F-0001hC-6r for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57: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-179-MCSYwST9NnOgEnClt9k9-Q-1; Wed, 07 Oct 2020 07:57:08 -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 0B2898031F9; Wed, 7 Oct 2020 11:57:07 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91A0055760; Wed, 7 Oct 2020 11:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071830; 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=55WpEi90PG0R1Tz2B85E8h1Orp/fQfXznmS5ayIoWgQ=; b=ODh4kMwySwVvIpH9XFFfSOAoOjmSHahVgmzpQmkIsir4UuvXaGAAKYFXdsXNBeWkGrjyGT AeJKrgeOgscQX9NHCniNZklULXGrAGnusTBwMcGOFL6KnJLD3m5zUw9gRJN5TMZB77bdHR GmjeARQo2irAXOnWjXZOfgpVVF4uHAc= X-MC-Unique: MCSYwST9NnOgEnClt9k9-Q-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 05/17] qtest: switch users back to qtest_qmp_receive Date: Wed, 7 Oct 2020 07:56:48 -0400 Message-Id: <20201007115700.707938-6-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:54:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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, Maxim Levitsky , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Let test use the new functionality for buffering events. The only remaining users of qtest_qmp_receive_dict are tests that fuzz the QMP protocol. Tested with 'make check-qtest'. Signed-off-by: Maxim Levitsky Message-Id: <20201006123904.610658-4-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- tests/qtest/ahci-test.c | 4 ++-- tests/qtest/drive_del-test.c | 9 +++------ tests/qtest/libqtest.c | 12 +++--------- tests/qtest/pvpanic-test.c | 4 +--- tests/qtest/tpm-util.c | 8 ++++++-- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/tests/qtest/ahci-test.c b/tests/qtest/ahci-test.c index d42ebaeb4c..5e1954852e 100644 --- a/tests/qtest/ahci-test.c +++ b/tests/qtest/ahci-test.c @@ -1590,7 +1590,7 @@ static void test_atapi_tray(void) qtest_qmp_send(ahci->parent->qts, "{'execute': 'blockdev-open-tray', " "'arguments': {'id': 'cd0'}}"); atapi_wait_tray(ahci, true); - rsp =3D qtest_qmp_receive_dict(ahci->parent->qts); + rsp =3D qtest_qmp_receive(ahci->parent->qts); qobject_unref(rsp); =20 qmp_discard_response(ahci->parent->qts, @@ -1620,7 +1620,7 @@ static void test_atapi_tray(void) qtest_qmp_send(ahci->parent->qts, "{'execute': 'blockdev-close-tray', " "'arguments': {'id': 'cd0'}}"); atapi_wait_tray(ahci, false); - rsp =3D qtest_qmp_receive_dict(ahci->parent->qts); + rsp =3D qtest_qmp_receive(ahci->parent->qts); qobject_unref(rsp); =20 /* Now, to convince ATAPI we understand the media has changed... */ diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c index ba0cd77445..9d20a1ed8b 100644 --- a/tests/qtest/drive_del-test.c +++ b/tests/qtest/drive_del-test.c @@ -15,9 +15,6 @@ #include "libqos/virtio.h" #include "qapi/qmp/qdict.h" =20 -/* TODO actually test the results and get rid of this */ -#define qmp_discard_response(q, ...) qobject_unref(qtest_qmp(q, __VA_ARGS_= _)) - static void drive_add(QTestState *qts) { char *resp =3D qtest_hmp(qts, "drive_add 0 if=3Dnone,id=3Ddrive0"); @@ -38,13 +35,13 @@ static void device_del(QTestState *qts) { QDict *response; =20 - /* Complication: ignore DEVICE_DELETED event */ - qmp_discard_response(qts, "{'execute': 'device_del'," + response =3D qtest_qmp(qts, "{'execute': 'device_del'," " 'arguments': { 'id': 'dev0' } }"); - response =3D qtest_qmp_receive_dict(qts); g_assert(response); g_assert(qdict_haskey(response, "return")); qobject_unref(response); + + qtest_qmp_eventwait(qts, "DEVICE_DELETED"); } =20 static void test_drive_without_dev(void) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index baac667b8d..08929f5ff6 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -324,7 +324,7 @@ QTestState *qtest_init(const char *extra_args) QDict *greeting; =20 /* Read the QMP greeting and then do the handshake */ - greeting =3D qtest_qmp_receive_dict(s); + greeting =3D qtest_qmp_receive(s); qobject_unref(greeting); qobject_unref(qtest_qmp(s, "{ 'execute': 'qmp_capabilities' }")); =20 @@ -700,7 +700,7 @@ QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t f= ds_num, qtest_qmp_vsend_fds(s, fds, fds_num, fmt, ap); =20 /* Receive reply */ - return qtest_qmp_receive_dict(s); + return qtest_qmp_receive(s); } =20 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap) @@ -708,7 +708,7 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_li= st ap) qtest_qmp_vsend(s, fmt, ap); =20 /* Receive reply */ - return qtest_qmp_receive_dict(s); + return qtest_qmp_receive(s); } =20 QDict *qmp_fd(int fd, const char *fmt, ...) @@ -850,12 +850,6 @@ char *qtest_vhmp(QTestState *s, const char *fmt, va_li= st ap) " 'arguments': {'command-line': %s}}", cmd); ret =3D g_strdup(qdict_get_try_str(resp, "return")); - while (ret =3D=3D NULL && qdict_get_try_str(resp, "event")) { - /* Ignore asynchronous QMP events */ - qobject_unref(resp); - resp =3D qtest_qmp_receive_dict(s); - ret =3D g_strdup(qdict_get_try_str(resp, "return")); - } g_assert(ret); qobject_unref(resp); g_free(cmd); diff --git a/tests/qtest/pvpanic-test.c b/tests/qtest/pvpanic-test.c index b0b20ad340..0657de797f 100644 --- a/tests/qtest/pvpanic-test.c +++ b/tests/qtest/pvpanic-test.c @@ -24,9 +24,7 @@ static void test_panic(void) =20 qtest_outb(qts, 0x505, 0x1); =20 - response =3D qtest_qmp_receive_dict(qts); - g_assert(qdict_haskey(response, "event")); - g_assert_cmpstr(qdict_get_str(response, "event"), =3D=3D, "GUEST_PANIC= KED"); + response =3D qtest_qmp_eventwait_ref(qts, "GUEST_PANICKED"); g_assert(qdict_haskey(response, "data")); data =3D qdict_get_qdict(response, "data"); g_assert(qdict_haskey(data, "action")); diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c index 3ed6c8548a..5a33a6ef0f 100644 --- a/tests/qtest/tpm-util.c +++ b/tests/qtest/tpm-util.c @@ -237,12 +237,16 @@ void tpm_util_migrate(QTestState *who, const char *ur= i) void tpm_util_wait_for_migration_complete(QTestState *who) { while (true) { + QDict *rsp; QDict *rsp_return; bool completed; const char *status; =20 - qtest_qmp_send(who, "{ 'execute': 'query-migrate' }"); - rsp_return =3D qtest_qmp_receive_success(who, NULL, NULL); + rsp =3D qtest_qmp(who, "{ 'execute': 'query-migrate' }"); + g_assert(qdict_haskey(rsp, "return")); + rsp_return =3D qdict_get_qdict(rsp, "return"); + + g_assert(!qdict_haskey(rsp_return, "error")); status =3D qdict_get_str(rsp_return, "status"); completed =3D strcmp(status, "completed") =3D=3D 0; g_assert_cmpstr(status, !=3D, "failed"); --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072439; cv=none; d=zohomail.com; s=zohoarc; b=VWbvztTisckZnLlDdXz116u6vhh1TywJClvVQil4zf8l655VxUj2dhiC+rhoKCN9UoWbuuUA3rPtpPLDfni4azyQEL6o1PV5fWL0d0zXfSS+Ac7SMWld7ui/TX0DioMbRGHA1irrXmeX68eXvCAQqKZifChFL4U2LdLKhbCDBvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072439; 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=22Qsmi4XFKCBVOTxJQOM0XpcwaYo5VRpQRb9bg3qLkc=; b=dZI4hBizPvqo/TwGeam/S460OhOdFkBQ7/d5OK8ChMOU9+KvvRRKLb/HWoBOBxVnnrt+MnxJFH9WxRnxfZjp4ssNuy1sBHtLoZ8Krfy9I32T6fMUfIlk1jSQQyiKOofXZFiW8HchOpiD7DKH7FbEp96alR6sx/ckufRD0riUanQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072439822949.3035389371516; Wed, 7 Oct 2020 05:07:19 -0700 (PDT) Received: from localhost ([::1]:42270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8E2-0005QZ-B7 for importer@patchew.org; Wed, 07 Oct 2020 08:07:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84J-0001VU-9b for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51495) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84F-0001hH-6u for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57: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-18-TUaxWs6NNtOMpnagtnSLtw-1; Wed, 07 Oct 2020 07:57:08 -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 82D441007469; Wed, 7 Oct 2020 11:57:07 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2503555760; Wed, 7 Oct 2020 11:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071830; 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=22Qsmi4XFKCBVOTxJQOM0XpcwaYo5VRpQRb9bg3qLkc=; b=I3S2anLGI+GKUSzh/3wqtfIiQ2GTqZXXtR7UQpsJbF5qj5gl6jL85z0c0vO6UgAeKc0+Z0 2Tt0YZdrDUVzvVNoKfMJohSSH3oXKycZvbSUznKIShB+mVEhGuOjBxTIfd7/6eF3mc6tqO /jSEEr8uq8DfrNwgDitEI/xGYaYsO4Q= X-MC-Unique: TUaxWs6NNtOMpnagtnSLtw-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 06/17] qtest: check that drives are really appearing and disappearing Date: Wed, 7 Oct 2020 07:56:49 -0400 Message-Id: <20201007115700.707938-7-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Do not just trust the HMP commands to create and delete the drive, use query-block to check that this is actually the case. Signed-off-by: Paolo Bonzini Reviewed-by: Kevin Wolf --- tests/qtest/drive_del-test.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c index 9d20a1ed8b..ff772b3671 100644 --- a/tests/qtest/drive_del-test.c +++ b/tests/qtest/drive_del-test.c @@ -14,20 +14,49 @@ #include "libqos/libqtest.h" #include "libqos/virtio.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" + +static bool has_drive(QTestState *qts) +{ + QDict *response; + QList *ret; + QListEntry *entry; + bool found; + + response =3D qtest_qmp(qts, "{'execute': 'query-block'}"); + g_assert(response && qdict_haskey(response, "return")); + ret =3D qdict_get_qlist(response, "return"); + + found =3D false; + QLIST_FOREACH_ENTRY(ret, entry) { + QDict *entry_dict =3D qobject_to(QDict, entry->value); + if (!strcmp(qdict_get_str(entry_dict, "device"), "drive0")) { + found =3D true; + break; + } + } + + qobject_unref(response); + return found; +} =20 static void drive_add(QTestState *qts) { char *resp =3D qtest_hmp(qts, "drive_add 0 if=3Dnone,id=3Ddrive0"); =20 g_assert_cmpstr(resp, =3D=3D, "OK\r\n"); + g_assert(has_drive(qts)); g_free(resp); } =20 static void drive_del(QTestState *qts) { - char *resp =3D qtest_hmp(qts, "drive_del drive0"); + char *resp; =20 + g_assert(has_drive(qts)); + resp =3D qtest_hmp(qts, "drive_del drive0"); g_assert_cmpstr(resp, =3D=3D, ""); + g_assert(!has_drive(qts)); g_free(resp); } =20 @@ -130,6 +159,7 @@ static void test_drive_del_device_del(void) */ drive_del(qts); device_del(qts); + g_assert(!has_drive(qts)); =20 qtest_quit(qts); } --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072381; cv=none; d=zohomail.com; s=zohoarc; b=hfaL0HSsfZwcxXU1Wk63se7Izkf+mszuSSsnPh6ENtStujw1oYHDjaft4xYv81tj6Wvfr8UBZUW3KRcC/ueq14gWUv9kBq0aQS53S7A2yY2wbj70fjh1I505KRoKScCZ5p7Q8xSmgrQ0AVvKFe5XF2f9HxNfv3dB66nv/1MGOb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072381; 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=9E3o8fGuO9gRD0UXxWbsF/STu5GlclTl2ZlUOU+Iopg=; b=GAy+MAi7SHGP+E4hy75diXKVyH/5aE086nvZ9qNRCliLYFqE6DBNiy3LqqFD/RuIWGCpbj5VWJmeVf8EYzAOuHSAPRn18Sjl7HfbK1d0nR4sm67bn6BDHUHgW3qEvtnkut54VjWuuudbyunVj2jy1Wq7Jajej6mELHsmGsbZXOg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 16020723811521018.9539416393357; Wed, 7 Oct 2020 05:06:21 -0700 (PDT) Received: from localhost ([::1]:38806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8D5-0003zH-Kx for importer@patchew.org; Wed, 07 Oct 2020 08:06:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84N-0001YF-Ry for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84F-0001hZ-KN for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:19 -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-340-DtIQpYRVPGm04YJ0L6YnCg-1; Wed, 07 Oct 2020 07:57: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 0842F18A0766; Wed, 7 Oct 2020 11:57:08 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D90E55760; Wed, 7 Oct 2020 11:57:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071830; 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=9E3o8fGuO9gRD0UXxWbsF/STu5GlclTl2ZlUOU+Iopg=; b=eShU4VnJ7Mj+QIh/BJ4nNPfH0ViSMP0toMy9cXxAbgSavOFCUstHF/ql4xAp/6DoSf18H2 PNCWjCtavyCynBtdmmkfOY9KSr6tOc3KVtTjGIfmQ/CuYKwMUvjZ2IcyAmJ8sxH8GFPDCf 0pjIc6BjWM7YwJ/744s8TQs6NNkqsjI= X-MC-Unique: DtIQpYRVPGm04YJ0L6YnCg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 07/17] qemu-iotests, qtest: rewrite test 067 as a qtest Date: Wed, 7 Oct 2020 07:56:50 -0400 Message-Id: <20201007115700.707938-8-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Test 067 from qemu-iotests is executing QMP commands to hotplug and hot-unplug disks, devices and blockdevs. Because the power of the text-based test harness is limited, it is actually limiting the checks that it does, for example by skipping DEVICE_DELETED events. tests/qtest already has a similar test, drive_del-test.c. We can merge them, and even reuse some of the existing code in drive_del-test.c, and improve the quality of the test by covering DEVICE_DELETED events. The only difference is that the new test will always use null-co:// for the medium rather than qcow2 or raw, but this should be irrelevant for what the test is covering. For example there are no "qemu-img check" runs in 067 that would check that the file is properly closed. The new tests requires PCI hot-plug support, so drive_del-test is moved from qemu-system-ppc to qemu-system-ppc64. Signed-off-by: Paolo Bonzini Reviewed-by: Kevin Wolf --- .gitlab-ci.yml | 2 +- tests/qemu-iotests/067 | 157 ------------- tests/qemu-iotests/067.out | 414 ----------------------------------- tests/qemu-iotests/group | 1 - tests/qtest/drive_del-test.c | 211 ++++++++++++++++-- tests/qtest/meson.build | 4 +- 6 files changed, 190 insertions(+), 599 deletions(-) delete mode 100755 tests/qemu-iotests/067 delete mode 100644 tests/qemu-iotests/067.out diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a51c89554f..a4cf87481e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -232,7 +232,7 @@ build-tcg-disabled: - ./check -raw 001 002 003 004 005 008 009 010 011 012 021 025 032 033= 048 052 063 077 086 101 104 106 113 148 150 151 152 157 159 160 163 170 171 183 184 192 194 197 208 215 221 222 226 227 236 253 277 - - ./check -qcow2 028 051 056 057 058 065 067 068 082 085 091 095 096 1= 02 122 + - ./check -qcow2 028 051 056 057 058 065 068 082 085 091 095 096 102 1= 22 124 132 139 142 144 145 151 152 155 157 165 194 196 197 200 202 208 209 215 216 218 222 227 234 246 247 248 250 254 255 257 258 260 261 262 263 264 270 272 273 277 279 diff --git a/tests/qemu-iotests/067 b/tests/qemu-iotests/067 deleted file mode 100755 index a63be9cabf..0000000000 --- a/tests/qemu-iotests/067 +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env bash -# -# Test automatic deletion of BDSes created by -drive/drive_add -# -# Copyright (C) 2013 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" - -status=3D1 # failure is the default! - -# get standard environment, filters and checks -. ./common.rc -. ./common.filter - -_supported_fmt qcow2 -_supported_proto file -# Because anything other than 16 would change the output of query-block, -# and external data files would change the output of -# query-named-block-nodes -_unsupported_imgopts 'refcount_bits=3D\([^1]\|.\([^6]\|$\)\)' data_file - -do_run_qemu() -{ - echo Testing: "$@" - $QEMU -nographic -qmp-pretty stdio -serial none "$@" - echo -} - -# Remove QMP events from (pretty-printed) output. Doesn't handle -# nested dicts correctly, but we don't get any of those in this test. -_filter_qmp_events() -{ - tr '\n' '\t' | sed -e \ - 's/{\s*"timestamp":\s*{[^}]*},\s*"event":[^,}]*\(,\s*"data":\s*{[^}]*}\)\= ?\s*}\s*//g' \ - | tr '\t' '\n' -} - -run_qemu() -{ - do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu \ - | _filter_actual_image_size \ - | _filter_generated_node_ids | _filter_qmp_event= s \ - | _filter_img_info -} - -size=3D128M - -_make_test_img $size - -echo -echo =3D=3D=3D -drive/-device and device_del =3D=3D=3D -echo - -run_qemu -drive file=3D$TEST_IMG,format=3D$IMGFMT,if=3Dnone,id=3Ddisk -dev= ice virtio-blk,drive=3Ddisk,id=3Dvirtio0 <value); - if (!strcmp(qdict_get_str(entry_dict, "device"), "drive0")) { + if (!strcmp(qdict_get_str(entry_dict, key), "drive0")) { found =3D true; break; } @@ -40,6 +40,38 @@ static bool has_drive(QTestState *qts) return found; } =20 +static bool has_drive(QTestState *qts) +{ + return look_for_drive0(qts, "query-block", "device"); +} + +static bool has_blockdev(QTestState *qts) +{ + return look_for_drive0(qts, "query-named-block-nodes", "node-name"); +} + +static void blockdev_add_with_media(QTestState *qts) +{ + QDict *response; + + response =3D qtest_qmp(qts, + "{ 'execute': 'blockdev-add'," + " 'arguments': {" + " 'driver': 'raw'," + " 'node-name': 'drive0'," + " 'file': {" + " 'driver': 'null-co'," + " 'read-zeroes': true" + " }" + " }" + "}"); + + g_assert(response); + g_assert(qdict_haskey(response, "return")); + qobject_unref(response); + g_assert(has_blockdev(qts)); +} + static void drive_add(QTestState *qts) { char *resp =3D qtest_hmp(qts, "drive_add 0 if=3Dnone,id=3Ddrive0"); @@ -49,6 +81,17 @@ static void drive_add(QTestState *qts) g_free(resp); } =20 +static void drive_add_with_media(QTestState *qts) +{ + char *resp =3D qtest_hmp(qts, + "drive_add 0 if=3Dnone,id=3Ddrive0,file=3Dnull-= co://," + "file.read-zeroes=3Don,format=3Draw"); + + g_assert_cmpstr(resp, =3D=3D, "OK\r\n"); + g_assert(has_drive(qts)); + g_free(resp); +} + static void drive_del(QTestState *qts) { char *resp; @@ -60,7 +103,43 @@ static void drive_del(QTestState *qts) g_free(resp); } =20 -static void device_del(QTestState *qts) +/* + * qvirtio_get_dev_type: + * Returns: the preferred virtio bus/device type for the current architect= ure. + * TODO: delete this + */ +static const char *qvirtio_get_dev_type(void) +{ + const char *arch =3D qtest_get_arch(); + + if (g_str_equal(arch, "arm") || g_str_equal(arch, "aarch64")) { + return "device"; /* for virtio-mmio */ + } else if (g_str_equal(arch, "s390x")) { + return "ccw"; + } else { + return "pci"; + } +} + +static void device_add(QTestState *qts) +{ + QDict *response; + char driver[32]; + snprintf(driver, sizeof(driver), "virtio-blk-%s", + qvirtio_get_dev_type()); + + response =3D qtest_qmp(qts, "{'execute': 'device_add'," + " 'arguments': {" + " 'driver': %s," + " 'drive': 'drive0'," + " 'id': 'dev0'" + "}}", driver); + g_assert(response); + g_assert(qdict_haskey(response, "return")); + qobject_unref(response); +} + +static void device_del(QTestState *qts, bool and_reset) { QDict *response; =20 @@ -70,6 +149,13 @@ static void device_del(QTestState *qts) g_assert(qdict_haskey(response, "return")); qobject_unref(response); =20 + if (and_reset) { + response =3D qtest_qmp(qts, "{'execute': 'system_reset' }"); + g_assert(response); + g_assert(qdict_haskey(response, "return")); + qobject_unref(response); + } + qtest_qmp_eventwait(qts, "DEVICE_DELETED"); } =20 @@ -91,24 +177,6 @@ static void test_drive_without_dev(void) qtest_quit(qts); } =20 -/* - * qvirtio_get_dev_type: - * Returns: the preferred virtio bus/device type for the current architect= ure. - * TODO: delete this - */ -static const char *qvirtio_get_dev_type(void) -{ - const char *arch =3D qtest_get_arch(); - - if (g_str_equal(arch, "arm") || g_str_equal(arch, "aarch64")) { - return "device"; /* for virtio-mmio */ - } else if (g_str_equal(arch, "s390x")) { - return "ccw"; - } else { - return "pci"; - } -} - static void test_after_failed_device_add(void) { char driver[32]; @@ -158,12 +226,97 @@ static void test_drive_del_device_del(void) * Doing it in this order takes notoriously tricky special paths */ drive_del(qts); - device_del(qts); + device_del(qts, false); g_assert(!has_drive(qts)); =20 qtest_quit(qts); } =20 +static void test_cli_device_del(void) +{ + QTestState *qts; + + /* + * -drive/-device and device_del. Start with a drive used by a + * device that unplugs after reset. + */ + qts =3D qtest_initf("-drive if=3Dnone,id=3Ddrive0,file=3Dnull-co://," + "file.read-zeroes=3Don,format=3Draw" + " -device virtio-blk-%s,drive=3Ddrive0,id=3Ddev0", + qvirtio_get_dev_type()); + + device_del(qts, true); + g_assert(!has_drive(qts)); + + qtest_quit(qts); +} + +static void test_empty_device_del(void) +{ + QTestState *qts; + + /* device_del with no drive plugged. */ + qts =3D qtest_initf("-device virtio-scsi-%s -device scsi-cd,id=3Ddev0", + qvirtio_get_dev_type()); + + device_del(qts, false); + qtest_quit(qts); +} + +static void test_device_add_and_del(void) +{ + QTestState *qts; + + /* + * -drive/device_add and device_del. Start with a drive used by a + * device that unplugs after reset. + */ + qts =3D qtest_init("-drive if=3Dnone,id=3Ddrive0,file=3Dnull-co://," + "file.read-zeroes=3Don,format=3Draw"); + + device_add(qts); + device_del(qts, true); + g_assert(!has_drive(qts)); + + qtest_quit(qts); +} + +static void test_drive_add_device_add_and_del(void) +{ + QTestState *qts; + + qts =3D qtest_init(""); + + /* + * drive_add/device_add and device_del. The drive is used by a + * device that unplugs after reset. + */ + drive_add_with_media(qts); + device_add(qts); + device_del(qts, true); + g_assert(!has_drive(qts)); + + qtest_quit(qts); +} + +static void test_blockdev_add_device_add_and_del(void) +{ + QTestState *qts; + + qts =3D qtest_init(""); + + /* + * blockdev_add/device_add and device_del. The it drive is used by a + * device that unplugs after reset, but it doesn't go away. + */ + blockdev_add_with_media(qts); + device_add(qts); + device_del(qts, true); + g_assert(has_blockdev(qts)); + + qtest_quit(qts); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -173,8 +326,18 @@ int main(int argc, char **argv) if (qvirtio_get_dev_type() !=3D NULL) { qtest_add_func("/drive_del/after_failed_device_add", test_after_failed_device_add); - qtest_add_func("/blockdev/drive_del_device_del", + qtest_add_func("/drive_del/drive_del_device_del", test_drive_del_device_del); + qtest_add_func("/device_del/drive/cli_device", + test_cli_device_del); + qtest_add_func("/device_del/drive/device_add", + test_device_add_and_del); + qtest_add_func("/device_del/drive/drive_add_device_add", + test_drive_add_device_add_and_del); + qtest_add_func("/device_del/empty", + test_empty_device_del); + qtest_add_func("/device_del/blockdev", + test_blockdev_add_device_add_and_del); } =20 return g_test_run(); diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 550a0b51a6..2254ce3257 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -111,7 +111,7 @@ qtests_moxie =3D [ 'boot-serial-test' ] qtests_ppc =3D \ (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] = : []) + \ (config_all_devices.has_key('CONFIG_M48T59') ? ['m48t59-test'] : []) + = \ - ['boot-order-test', 'prom-env-test', 'drive_del-test', 'boot-serial-test= '] \ + ['boot-order-test', 'prom-env-test', 'boot-serial-test'] = \ =20 qtests_ppc64 =3D \ (config_all_devices.has_key('CONFIG_PSERIES') ? ['device-plug-test'] : [= ]) + \ @@ -121,7 +121,7 @@ qtests_ppc64 =3D \ (config_all_devices.has_key('CONFIG_USB_UHCI') ? ['usb-hcd-uhci-test'] := []) + \ (config_all_devices.has_key('CONFIG_USB_XHCI_NEC') ? ['usb-hcd-xhci-test= '] : []) + \ (config_host.has_key('CONFIG_POSIX') ? ['test-filter-mirror'] : []) + = \ - qtests_pci + ['migration-test', 'numa-test', 'cpu-plug-test'] + qtests_pci + ['migration-test', 'numa-test', 'cpu-plug-test', 'drive_del= -test'] =20 qtests_sh4 =3D (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endia= nness-test'] : []) qtests_sh4eb =3D (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['end= ianness-test'] : []) --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072151; cv=none; d=zohomail.com; s=zohoarc; b=GHiDsgmwJzLtapQWfQ/zSF+afc/8MkRtc8pSDS7kVQr1jzZfUA5dbgfZJIOYYproeSssiPneh/QkbxABeeG78heq9LpU/8ZJba6Rv1BL4GWHdIChHTzmHz3gbnIkoMp+ImREGbe7iChe+DyD5bgB8/wjjOTvDHCU6/n50GhILyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072151; 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=Ai/kbtMb/L/VAFzZtCExa/yUmMY/NsTeSEW84RTLTn0=; b=jiCqGfKfqr+H2uNXUsyv2dQ/cY8hJrnH+B10rf06Qk8F3F/8rpqe2rgGLAB9MafMZhzwqdsMVvJms4srEqynYylVKDI4nOoXcNwUy9dzJDCU8XPaKtc7DSNtbtBSI2PIK1dSTZ28FWxUZzQk7koS2ypQhOjIi4iLOJGH0vS7+mg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072150993219.5551116291191; Wed, 7 Oct 2020 05:02:30 -0700 (PDT) Received: from localhost ([::1]:55566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ89N-0007U6-EG for importer@patchew.org; Wed, 07 Oct 2020 08:02:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84N-0001Xx-2S for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84H-0001i3-5F for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:18 -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-283-yKtfqVZvObWN7HIvLXdjTg-1; Wed, 07 Oct 2020 07:57: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 81ACB1007464; Wed, 7 Oct 2020 11:57:08 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22A7D55783; Wed, 7 Oct 2020 11:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071832; 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=Ai/kbtMb/L/VAFzZtCExa/yUmMY/NsTeSEW84RTLTn0=; b=faFaBFZFSvFiDKoR5resnrCSqbVaEuz8U5hHda657EXFEBWRgV3JKAnNhndkPejeswBrnT rOf07seFjjCQQKkNVDaBmrIsrhWm/WfTci1+jX4GU5tjTpz9O7y3zFU6uD4eQOj+s1zvAH rNdkGJzwK8zkjXOB3ar+UhxWvtfXI2g= X-MC-Unique: yKtfqVZvObWN7HIvLXdjTg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 08/17] qdev: add "check if address free" callback for buses Date: Wed, 7 Oct 2020 07:56:51 -0400 Message-Id: <20201007115700.707938-9-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:54:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Check if an address is free on the bus before plugging in the device. This makes it possible to do the check without any side effects, and to detect the problem early without having to do it in the realize callback. Signed-off-by: Paolo Bonzini Message-Id: <20201006123904.610658-5-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 17 +++++++++++++++-- hw/net/virtio-net.c | 2 +- hw/sd/core.c | 3 ++- include/hw/qdev-core.h | 13 ++++++++++++- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 96772a15bd..74db78df36 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -94,13 +94,23 @@ static void bus_add_child(BusState *bus, DeviceState *c= hild) 0); } =20 -void qdev_set_parent_bus(DeviceState *dev, BusState *bus) +static bool bus_check_address(BusState *bus, DeviceState *child, Error **e= rrp) +{ + BusClass *bc =3D BUS_GET_CLASS(bus); + return !bc->check_address || bc->check_address(bus, child, errp); +} + +bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp) { BusState *old_parent_bus =3D dev->parent_bus; DeviceClass *dc =3D DEVICE_GET_CLASS(dev); =20 assert(dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type)); =20 + if (!bus_check_address(bus, dev, errp)) { + return false; + } + if (old_parent_bus) { trace_qdev_update_parent_bus(dev, object_get_typename(OBJECT(dev)), old_parent_bus, object_get_typename(OBJECT(old_parent_bus)), @@ -126,6 +136,7 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bu= s) object_unref(OBJECT(old_parent_bus)); object_unref(OBJECT(dev)); } + return true; } =20 DeviceState *qdev_new(const char *name) @@ -371,7 +382,9 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Erro= r **errp) assert(!dev->realized && !dev->parent_bus); =20 if (bus) { - qdev_set_parent_bus(dev, bus); + if (!qdev_set_parent_bus(dev, bus, errp)) { + return false; + } } else { assert(!DEVICE_GET_CLASS(dev)->bus_type); } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 7bf27b9db7..268cecc498 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3142,7 +3142,7 @@ static bool failover_replug_primary(VirtIONet *n, Err= or **errp) error_setg(errp, "virtio_net: couldn't find primary bus"); return false; } - qdev_set_parent_bus(n->primary_dev, n->primary_bus); + qdev_set_parent_bus(n->primary_dev, n->primary_bus, &error_abort); n->primary_should_be_hidden =3D false; if (!qemu_opt_set_bool(n->primary_device_opts, "partially_hotplugged", true, errp)) { diff --git a/hw/sd/core.c b/hw/sd/core.c index 957d116f1a..08c93b5903 100644 --- a/hw/sd/core.c +++ b/hw/sd/core.c @@ -23,6 +23,7 @@ #include "hw/qdev-core.h" #include "hw/sd/sd.h" #include "qemu/module.h" +#include "qapi/error.h" #include "trace.h" =20 static inline const char *sdbus_name(SDBus *sdbus) @@ -240,7 +241,7 @@ void sdbus_reparent_card(SDBus *from, SDBus *to) readonly =3D sc->get_readonly(card); =20 sdbus_set_inserted(from, false); - qdev_set_parent_bus(DEVICE(card), &to->qbus); + qdev_set_parent_bus(DEVICE(card), &to->qbus, &error_abort); sdbus_set_inserted(to, true); sdbus_set_readonly(to, readonly); } diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 72064f4dd4..14d476c587 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -210,13 +210,24 @@ struct BusClass { /* FIXME first arg should be BusState */ void (*print_dev)(Monitor *mon, DeviceState *dev, int indent); char *(*get_dev_path)(DeviceState *dev); + /* * This callback is used to create Open Firmware device path in accord= ance * with OF spec http://forthworks.com/standards/of1275.pdf. Individual= bus * bindings can be found at http://playground.sun.com/1275/bindings/. */ char *(*get_fw_dev_path)(DeviceState *dev); + void (*reset)(BusState *bus); + + /* + * Return whether the device can be added to @bus, + * based on the address that was set (via device properties) + * before realize. If not, on return @errp contains the + * human-readable error message. + */ + bool (*check_address)(BusState *bus, DeviceState *dev, Error **errp); + BusRealize realize; BusUnrealize unrealize; =20 @@ -788,7 +799,7 @@ const char *qdev_fw_name(DeviceState *dev); Object *qdev_get_machine(void); =20 /* FIXME: make this a link<> */ -void qdev_set_parent_bus(DeviceState *dev, BusState *bus); +bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp); =20 extern bool qdev_hotplug; extern bool qdev_hot_removed; --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072161; cv=none; d=zohomail.com; s=zohoarc; b=dc+ncuGHzenb3DRNmb5jhHzjLhfm/GaLpX9NzCW/JMAqzkKWFNdV9Xlh542P8kNX2BR2V4McNBB3ic+bRVl/M83eADn20CC/1ig9lyoOn27y7cYWeNBniijcXO+a47OhPQxiXOBIgJNG0CPtjmNOlnM0seQf8kgZb4gEPa2r4ms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072161; 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=CrmoymnzAgikECEklmSg1XDyOEymdcxw7MwzoWGtGiE=; b=Asy2BZQzFqF5Xg7tb4IIA5q8KlQ4K0fGLFng4PIjvYpcz05xx3NxnTwiGr723QKNq9tK80PlE0XZZuW73vgkl+F4KM90xHPdAoMam9kdk39Ycp9dhpC0kCY5f4LQbcbvTPzzZzvjb75DYQ2UX+53b5bnb/queaqst0c7Yli4B3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 160207216100764.61149881266317; Wed, 7 Oct 2020 05:02:41 -0700 (PDT) Received: from localhost ([::1]:56482 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ89X-0007tP-KO for importer@patchew.org; Wed, 07 Oct 2020 08:02:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84O-0001YJ-Fh for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30080) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84L-0001k0-2C for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:20 -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-550-zT8-JcTDM4eeWXsS17Ovow-1; Wed, 07 Oct 2020 07:57:14 -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 098651007468; Wed, 7 Oct 2020 11:57:12 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BEF555785; Wed, 7 Oct 2020 11:57:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071836; 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=CrmoymnzAgikECEklmSg1XDyOEymdcxw7MwzoWGtGiE=; b=DLkgxbhPcWFVQRy6uEze9XKSmoTsiOzeMgMzJCdb916QekZoZSyCmGF+h0Rv4EGS7FZE6h AJSra2xPg0K43QvrJNZWpdVdYgaOXRcDV6fQcuXxNSHKRuz6vcVA7kdXgUlk/q2nINUuF8 8MKsEFyRNo+lslVvjwQQx8pJ3Q4RvOk= X-MC-Unique: zT8-JcTDM4eeWXsS17Ovow-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 09/17] scsi/scsi_bus: switch search direction in scsi_device_find Date: Wed, 7 Oct 2020 07:56:52 -0400 Message-Id: <20201007115700.707938-10-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@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=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, Maxim Levitsky , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky This change will allow us to convert the bus children list to RCU, while not changing the logic of this function Signed-off-by: Maxim Levitsky Reviewed-by: Stefan Hajnoczi Message-Id: <20200913160259.32145-2-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-bus.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 3284a5d1fb..6b1ed7ae9a 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -1572,7 +1572,7 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channe= l, int id, int lun) BusChild *kid; SCSIDevice *target_dev =3D NULL; =20 - QTAILQ_FOREACH_REVERSE(kid, &bus->qbus.children, sibling) { + QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) { DeviceState *qdev =3D kid->child; SCSIDevice *dev =3D SCSI_DEVICE(qdev); =20 @@ -1580,7 +1580,15 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int chann= el, int id, int lun) if (dev->lun =3D=3D lun) { return dev; } - target_dev =3D dev; + + /* + * If we don't find exact match (channel/bus/lun), + * we will return the first device which matches channel/bus + */ + + if (!target_dev) { + target_dev =3D dev; + } } } return target_dev; --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072562; cv=none; d=zohomail.com; s=zohoarc; b=KJrZFxtUYQjkle4yz4dXxjCGfd9HD665LGZHfeYKGfLvINFmlIDCFq7GDC6cvYvOMExSJsvHdunFyLagr2PwInqAC6O29a9DBZeRQfvyaryGDKgTiycSxnOl71zCunWLn4DFmN8x2KvD29e9qnXaPDvnvzpRWGORhbHb6eKWb34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072562; 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=ceM7PphOnMySWLEUgFCdxPQq6ixQ0Q1whnbjS30O+vg=; b=P2P44nt34qAMBldx2gS1EJxKQSVJS0IgP62s0jp9r1p+aKLqSzfCHu0moT2c4DTxjsDEOwX2pTVwL77Zw3sivyKUkRBCeWUmFcFOvQCWviVXevAh24Q/6yvBqJqVQCVPJ4QpWeL4hbWSS1LZd1KNpCmQL1jp/XCn1sCKa0sqXtM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072562902446.1736042381873; Wed, 7 Oct 2020 05:09:22 -0700 (PDT) Received: from localhost ([::1]:47708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8G1-0007l2-MW for importer@patchew.org; Wed, 07 Oct 2020 08:09:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84S-0001fP-Vd for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84P-0001la-Iv for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:24 -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-116-gyCxVid0PFSEaPqf0VC6gQ-1; Wed, 07 Oct 2020 07:57:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E26951007464; Wed, 7 Oct 2020 11:57:15 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D81560BEC; Wed, 7 Oct 2020 11:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071840; 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=ceM7PphOnMySWLEUgFCdxPQq6ixQ0Q1whnbjS30O+vg=; b=DUwUK3CD0+3kFO8BqLrmToloGSg5MmEKiUeYewWM5d2RUJMgGXCAsN8ddrDMEITIzr0e7h q3rpRMFmNrrcg/LBm32VD4b25JEKKa89TLx1XG98REp1q6//ZI9mbN86CAswE2slXD5ksV JoH7YtAGuqYDs0sgCD9vibruMIhG6tM= X-MC-Unique: gyCxVid0PFSEaPqf0VC6gQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 10/17] device_core: use drain_call_rcu in in qmp_device_add Date: Wed, 7 Oct 2020 07:56:53 -0400 Message-Id: <20201007115700.707938-11-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, qemu-block@nongnu.org, Stefan Hajnoczi , Maxim Levitsky , Stefan Hajnoczi , mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Soon, a device removal might only happen on RCU callback execution. This is okay for device-del which provides a DEVICE_DELETED event, but not for the failure case of device-add. To avoid changing monitor semantics, just drain all pending RCU callbacks on error. Signed-off-by: Maxim Levitsky Suggested-by: Stefan Hajnoczi Reviewed-by: Stefan Hajnoczi Message-Id: <20200913160259.32145-4-mlevitsk@redhat.com> [Don't use it in qmp_device_del. - Paolo] Signed-off-by: Paolo Bonzini --- softmmu/qdev-monitor.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index e9b7228480..bcfb90a08f 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -803,6 +803,18 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, = Error **errp) return; } dev =3D qdev_device_add(opts, errp); + + /* + * Drain all pending RCU callbacks. This is done because + * some bus related operations can delay a device removal + * (in this case this can happen if device is added and then + * removed due to a configuration error) + * to a RCU callback, but user might expect that this interface + * will finish its job completely once qmp command returns result + * to the user + */ + drain_call_rcu(); + if (!dev) { qemu_opts_del(opts); return; --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072961; cv=none; d=zohomail.com; s=zohoarc; b=HV2gBksix4ENGGTAEEPoKEoiQ6zKgtAIhRbSZ8Jzcsu8wNZ6ZAYwt2dqABNzzebBOZVTR1Irp6tNXPTKiESR7dXzKWVZXVxb6Ya0zm9EdTChGwScfDSTaAwZXT6X3uwys2sV+0XUU9SkyDgDzzgN+eaT4OrBU3hPLUalF72tiv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072961; 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=xudVhDJCcMtA8YjfA06jzSmAzA2xquxEpsgiDd4Fkyo=; b=fK5I8COc2po/DTQKath/lPxZ85/06qhP/izlVWEm2r2u692ObBB2Jx8BYvuerKp8O6KrvX3BcUyOSka2B4WzA9grdey6rduahF9dfgusNKoc/rvo3cn7MzT4mnFalKJO5dM/CJwhbU9QAXaXVKeHk7hP/MvMHLN9H2C//7qhWbk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072961578817.2462825115289; Wed, 7 Oct 2020 05:16:01 -0700 (PDT) Received: from localhost ([::1]:59206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8MS-0004Ws-4N for importer@patchew.org; Wed, 07 Oct 2020 08:16:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84V-0001n3-Fo for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48518) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84R-0001mF-CL for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:27 -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-493-r5vfvhMfNVylM3M6boxyBA-1; Wed, 07 Oct 2020 07:57:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B45910BBEC3; Wed, 7 Oct 2020 11:57:16 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A0EC60BEC; Wed, 7 Oct 2020 11:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071841; 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=xudVhDJCcMtA8YjfA06jzSmAzA2xquxEpsgiDd4Fkyo=; b=WYZi5gTHnw3Liuisp05fLWNc5VzI1vFegIIoOd4Pk/TP8xq/MCxU01m9Ku4kD631rkTCMW jsuv+fQl/Ezne2QscB3VRh30Pp87X4CogXk21EOKoHNYsoR51jX33K3I72abyb0SOTYd5n 2KhT/VBx/FVUwshslRPqV6ZvQilrDFE= X-MC-Unique: r5vfvhMfNVylM3M6boxyBA-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 11/17] device-core: use RCU for list of children of a bus Date: Wed, 7 Oct 2020 07:56:54 -0400 Message-Id: <20201007115700.707938-12-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:54:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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, Maxim Levitsky , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky This fixes the race between device emulation code that tries to find a child device to dispatch the request to (e.g a scsi disk), and hotplug of a new device to that bus. Note that this doesn't convert all the readers of the list but only these that might go over that list without BQL held. This is a very small first step to make this code thread safe. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky Reviewed-by: Stefan Hajnoczi Message-Id: <20200913160259.32145-5-mlevitsk@redhat.com> [Use RCU_READ_LOCK_GUARD in more places, adjust testcase now that the delay in DEVICE_DELETED due to RCU is more consistent. - Paolo] Signed-off-by: Paolo Bonzini Message-Id: <20201006123904.610658-9-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/core/bus.c | 28 +++++++++++++++++----------- hw/core/qdev.c | 37 +++++++++++++++++++++++-------------- hw/scsi/scsi-bus.c | 12 +++++++++--- hw/scsi/virtio-scsi.c | 6 +++++- include/hw/qdev-core.h | 9 +++++++++ 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/hw/core/bus.c b/hw/core/bus.c index 6b987b6946..a0483859ae 100644 --- a/hw/core/bus.c +++ b/hw/core/bus.c @@ -49,12 +49,14 @@ int qbus_walk_children(BusState *bus, } } =20 - QTAILQ_FOREACH(kid, &bus->children, sibling) { - err =3D qdev_walk_children(kid->child, - pre_devfn, pre_busfn, - post_devfn, post_busfn, opaque); - if (err < 0) { - return err; + WITH_RCU_READ_LOCK_GUARD() { + QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) { + err =3D qdev_walk_children(kid->child, + pre_devfn, pre_busfn, + post_devfn, post_busfn, opaque); + if (err < 0) { + return err; + } } } =20 @@ -90,8 +92,10 @@ static void bus_reset_child_foreach(Object *obj, Resetta= bleChildCallback cb, BusState *bus =3D BUS(obj); BusChild *kid; =20 - QTAILQ_FOREACH(kid, &bus->children, sibling) { - cb(OBJECT(kid->child), opaque, type); + WITH_RCU_READ_LOCK_GUARD() { + QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) { + cb(OBJECT(kid->child), opaque, type); + } } } =20 @@ -194,9 +198,11 @@ static void bus_set_realized(Object *obj, bool value, = Error **errp) =20 /* TODO: recursive realization */ } else if (!value && bus->realized) { - QTAILQ_FOREACH(kid, &bus->children, sibling) { - DeviceState *dev =3D kid->child; - qdev_unrealize(dev); + WITH_RCU_READ_LOCK_GUARD() { + QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) { + DeviceState *dev =3D kid->child; + qdev_unrealize(dev); + } } if (bc->unrealize) { bc->unrealize(bus); diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 74db78df36..59e5e710b7 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -51,6 +51,12 @@ const VMStateDescription *qdev_get_vmsd(DeviceState *dev) return dc->vmsd; } =20 +static void bus_free_bus_child(BusChild *kid) +{ + object_unref(OBJECT(kid->child)); + g_free(kid); +} + static void bus_remove_child(BusState *bus, DeviceState *child) { BusChild *kid; @@ -60,15 +66,16 @@ static void bus_remove_child(BusState *bus, DeviceState= *child) char name[32]; =20 snprintf(name, sizeof(name), "child[%d]", kid->index); - QTAILQ_REMOVE(&bus->children, kid, sibling); + QTAILQ_REMOVE_RCU(&bus->children, kid, sibling); =20 bus->num_children--; =20 /* This gives back ownership of kid->child back to us. */ object_property_del(OBJECT(bus), name); - object_unref(OBJECT(kid->child)); - g_free(kid); - return; + + /* free the bus kid, when it is safe to do so*/ + call_rcu(kid, bus_free_bus_child, rcu); + break; } } } @@ -83,7 +90,7 @@ static void bus_add_child(BusState *bus, DeviceState *chi= ld) kid->child =3D child; object_ref(OBJECT(kid->child)); =20 - QTAILQ_INSERT_HEAD(&bus->children, kid, sibling); + QTAILQ_INSERT_HEAD_RCU(&bus->children, kid, sibling); =20 /* This transfers ownership of kid->child to the property. */ snprintf(name, sizeof(name), "child[%d]", kid->index); @@ -672,17 +679,19 @@ DeviceState *qdev_find_recursive(BusState *bus, const= char *id) DeviceState *ret; BusState *child; =20 - QTAILQ_FOREACH(kid, &bus->children, sibling) { - DeviceState *dev =3D kid->child; + WITH_RCU_READ_LOCK_GUARD() { + QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) { + DeviceState *dev =3D kid->child; =20 - if (dev->id && strcmp(dev->id, id) =3D=3D 0) { - return dev; - } + if (dev->id && strcmp(dev->id, id) =3D=3D 0) { + return dev; + } =20 - QLIST_FOREACH(child, &dev->child_bus, sibling) { - ret =3D qdev_find_recursive(child, id); - if (ret) { - return ret; + QLIST_FOREACH(child, &dev->child_bus, sibling) { + ret =3D qdev_find_recursive(child, id); + if (ret) { + return ret; + } } } } diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 6b1ed7ae9a..4cf1f404b4 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -400,7 +400,10 @@ static bool scsi_target_emulate_report_luns(SCSITarget= Req *r) id =3D r->req.dev->id; found_lun0 =3D false; n =3D 0; - QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) { + + RCU_READ_LOCK_GUARD(); + + QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) { DeviceState *qdev =3D kid->child; SCSIDevice *dev =3D SCSI_DEVICE(qdev); =20 @@ -421,7 +424,7 @@ static bool scsi_target_emulate_report_luns(SCSITargetR= eq *r) memset(r->buf, 0, len); stl_be_p(&r->buf[0], n); i =3D found_lun0 ? 8 : 16; - QTAILQ_FOREACH(kid, &r->req.bus->qbus.children, sibling) { + QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) { DeviceState *qdev =3D kid->child; SCSIDevice *dev =3D SCSI_DEVICE(qdev); =20 @@ -430,6 +433,7 @@ static bool scsi_target_emulate_report_luns(SCSITargetR= eq *r) i +=3D 8; } } + assert(i =3D=3D n + 8); r->len =3D len; return true; @@ -1572,7 +1576,8 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channe= l, int id, int lun) BusChild *kid; SCSIDevice *target_dev =3D NULL; =20 - QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) { + RCU_READ_LOCK_GUARD(); + QTAILQ_FOREACH_RCU(kid, &bus->qbus.children, sibling) { DeviceState *qdev =3D kid->child; SCSIDevice *dev =3D SCSI_DEVICE(qdev); =20 @@ -1591,6 +1596,7 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channe= l, int id, int lun) } } } + return target_dev; } =20 diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 3a71ea7097..971afbb217 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -367,12 +367,16 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSC= SIReq *req) case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: target =3D req->req.tmf.lun[1]; s->resetting++; - QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) { + + rcu_read_lock(); + QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { d =3D SCSI_DEVICE(kid->child); if (d->channel =3D=3D 0 && d->id =3D=3D target) { qdev_reset_all(&d->qdev); } } + rcu_read_unlock(); + s->resetting--; break; =20 diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 14d476c587..2c6307e3ed 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -3,6 +3,8 @@ =20 #include "qemu/queue.h" #include "qemu/bitmap.h" +#include "qemu/rcu.h" +#include "qemu/rcu_queue.h" #include "qom/object.h" #include "hw/hotplug.h" #include "hw/resettable.h" @@ -238,6 +240,7 @@ struct BusClass { }; =20 typedef struct BusChild { + struct rcu_head rcu; DeviceState *child; int index; QTAILQ_ENTRY(BusChild) sibling; @@ -258,6 +261,12 @@ struct BusState { int max_index; bool realized; int num_children; + + /* + * children is a RCU QTAILQ, thus readers must use RCU to access it, + * and writers must hold the big qemu lock + */ + QTAILQ_HEAD(, BusChild) children; QLIST_ENTRY(BusState) sibling; ResettableState reset; --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072519; cv=none; d=zohomail.com; s=zohoarc; b=CAIDsdSU7Gi5EvvCOGICt3Zeh/zQ/rWGEW645peOEmyRtjqLUoQt/5fywM9vsZv0MUNSt9uptC8joyPwxdQn8YSZkut54yzjUMIyWBbrMCtOS9h9PDCExeBQEk9vqWSd+1hM3iXCvZfJif3u7cmzIPT63z/89Mg/8CG8DqKnY04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072519; 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=d3v5cQxcIySqlSBjEcok3n/xI8fAKEf5zkOQbUOR8KU=; b=P5Ht9YXRD9cRzibIiQRl99A+e0jD3Ee5TrSQHlc6eMce0jK+XOEJCsB4MTSfPalpi6QZA+6DhnmSBvNWlf1Qn3M1Q3OVFUeYZAEU5h5TEnKe7PdROrWcMjMidKVVPp+EomHntvxkwkU2qJvNeAU1+URQcZjdEY5B2R13arLx2UA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 16020725193491007.4963678269921; Wed, 7 Oct 2020 05:08:39 -0700 (PDT) Received: from localhost ([::1]:46360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8FK-0007Au-0M for importer@patchew.org; Wed, 07 Oct 2020 08:08:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84S-0001eI-MV for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28797) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84P-0001lO-FU for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:24 -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-136-t8KxaerFMW-HFFoM52je7w-1; Wed, 07 Oct 2020 07:57:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2422E1007470; Wed, 7 Oct 2020 11:57:17 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6E6E60BEC; Wed, 7 Oct 2020 11:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071840; 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=d3v5cQxcIySqlSBjEcok3n/xI8fAKEf5zkOQbUOR8KU=; b=dHT4fNrWvltr07apPJP7aMcVzIRxQFDV8uOKitN09DjJ7xjws7jQ049gkkbbpjI4lEPP0m 0dsCMQBAYCqvIS0wJtsi1zPPdppd0lxruw1Ffdq5gmnOe+mbIYaCnj/80aNAgrCg+2X+Y7 NsOAb321d1CGotQWDNObCpE/57YYcy0= X-MC-Unique: t8KxaerFMW-HFFoM52je7w-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 12/17] scsi: switch to bus->check_address Date: Wed, 7 Oct 2020 07:56:55 -0400 Message-Id: <20201007115700.707938-13-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini Message-Id: <20201006123904.610658-6-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-bus.c | 122 ++++++++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 47 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 4cf1f404b4..4ab9811cd8 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -22,33 +22,6 @@ static void scsi_req_dequeue(SCSIRequest *req); static uint8_t *scsi_target_alloc_buf(SCSIRequest *req, size_t len); static void scsi_target_free_buf(SCSIRequest *req); =20 -static Property scsi_props[] =3D { - DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0), - DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1), - DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1), - DEFINE_PROP_END_OF_LIST(), -}; - -static void scsi_bus_class_init(ObjectClass *klass, void *data) -{ - BusClass *k =3D BUS_CLASS(klass); - HotplugHandlerClass *hc =3D HOTPLUG_HANDLER_CLASS(klass); - - k->get_dev_path =3D scsibus_get_dev_path; - k->get_fw_dev_path =3D scsibus_get_fw_dev_path; - hc->unplug =3D qdev_simple_device_unplug_cb; -} - -static const TypeInfo scsi_bus_info =3D { - .name =3D TYPE_SCSI_BUS, - .parent =3D TYPE_BUS, - .instance_size =3D sizeof(SCSIBus), - .class_init =3D scsi_bus_class_init, - .interfaces =3D (InterfaceInfo[]) { - { TYPE_HOTPLUG_HANDLER }, - { } - } -}; static int next_scsi_bus; =20 static void scsi_device_realize(SCSIDevice *s, Error **errp) @@ -160,35 +133,68 @@ static void scsi_dma_restart_cb(void *opaque, int run= ning, RunState state) } } =20 -static void scsi_qdev_realize(DeviceState *qdev, Error **errp) +static bool scsi_bus_is_address_free(SCSIBus *bus, + int channel, int target, int lun, + SCSIDevice **p_dev) +{ + SCSIDevice *d =3D scsi_device_find(bus, channel, target, lun); + if (d && d->lun =3D=3D lun) { + if (p_dev) { + *p_dev =3D d; + } + return false; + } + if (p_dev) { + *p_dev =3D NULL; + } + return true; +} + +static bool scsi_bus_check_address(BusState *qbus, DeviceState *qdev, Erro= r **errp) { SCSIDevice *dev =3D SCSI_DEVICE(qdev); - SCSIBus *bus =3D DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus); - SCSIDevice *d; - Error *local_err =3D NULL; + SCSIBus *bus =3D SCSI_BUS(qbus); =20 if (dev->channel > bus->info->max_channel) { error_setg(errp, "bad scsi channel id: %d", dev->channel); - return; + return false; } if (dev->id !=3D -1 && dev->id > bus->info->max_target) { error_setg(errp, "bad scsi device id: %d", dev->id); - return; + return false; } if (dev->lun !=3D -1 && dev->lun > bus->info->max_lun) { error_setg(errp, "bad scsi device lun: %d", dev->lun); - return; + return false; + } + + if (dev->id !=3D -1 && dev->lun !=3D -1) { + SCSIDevice *d; + if (!scsi_bus_is_address_free(bus, dev->channel, dev->id, dev->lun= , &d)) { + error_setg(errp, "lun already used by '%s'", d->qdev.id); + return false; + } } =20 + return true; +} + +static void scsi_qdev_realize(DeviceState *qdev, Error **errp) +{ + SCSIDevice *dev =3D SCSI_DEVICE(qdev); + SCSIBus *bus =3D DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus); + bool is_free; + Error *local_err =3D NULL; + if (dev->id =3D=3D -1) { int id =3D -1; if (dev->lun =3D=3D -1) { dev->lun =3D 0; } do { - d =3D scsi_device_find(bus, dev->channel, ++id, dev->lun); - } while (d && d->lun =3D=3D dev->lun && id < bus->info->max_target= ); - if (d && d->lun =3D=3D dev->lun) { + is_free =3D scsi_bus_is_address_free(bus, dev->channel, ++id, = dev->lun, NULL); + } while (!is_free && id < bus->info->max_target); + if (!is_free) { error_setg(errp, "no free target"); return; } @@ -196,20 +202,13 @@ static void scsi_qdev_realize(DeviceState *qdev, Erro= r **errp) } else if (dev->lun =3D=3D -1) { int lun =3D -1; do { - d =3D scsi_device_find(bus, dev->channel, dev->id, ++lun); - } while (d && d->lun =3D=3D lun && lun < bus->info->max_lun); - if (d && d->lun =3D=3D lun) { + is_free =3D scsi_bus_is_address_free(bus, dev->channel, dev->i= d, ++lun, NULL); + } while (!is_free && lun < bus->info->max_lun); + if (!is_free) { error_setg(errp, "no free lun"); return; } dev->lun =3D lun; - } else { - d =3D scsi_device_find(bus, dev->channel, dev->id, dev->lun); - assert(d); - if (d->lun =3D=3D dev->lun && dev !=3D d) { - error_setg(errp, "lun already used by '%s'", d->qdev.id); - return; - } } =20 QTAILQ_INIT(&dev->requests); @@ -1723,6 +1722,13 @@ const VMStateDescription vmstate_scsi_device =3D { } }; =20 +static Property scsi_props[] =3D { + DEFINE_PROP_UINT32("channel", SCSIDevice, channel, 0), + DEFINE_PROP_UINT32("scsi-id", SCSIDevice, id, -1), + DEFINE_PROP_UINT32("lun", SCSIDevice, lun, -1), + DEFINE_PROP_END_OF_LIST(), +}; + static void scsi_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k =3D DEVICE_CLASS(klass); @@ -1753,6 +1759,28 @@ static const TypeInfo scsi_device_type_info =3D { .instance_init =3D scsi_dev_instance_init, }; =20 +static void scsi_bus_class_init(ObjectClass *klass, void *data) +{ + BusClass *k =3D BUS_CLASS(klass); + HotplugHandlerClass *hc =3D HOTPLUG_HANDLER_CLASS(klass); + + k->get_dev_path =3D scsibus_get_dev_path; + k->get_fw_dev_path =3D scsibus_get_fw_dev_path; + k->check_address =3D scsi_bus_check_address; + hc->unplug =3D qdev_simple_device_unplug_cb; +} + +static const TypeInfo scsi_bus_info =3D { + .name =3D TYPE_SCSI_BUS, + .parent =3D TYPE_BUS, + .instance_size =3D sizeof(SCSIBus), + .class_init =3D scsi_bus_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + } +}; + static void scsi_register_types(void) { type_register_static(&scsi_bus_info); --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072748; cv=none; d=zohomail.com; s=zohoarc; b=RTN0Be1zPuPpIJOWP9hPOtzaheO1u3yhWImuP09jnmg7n4+PsmFtko31vsu04oAUcWqMgpvAFBTuC9DvId7tTuS1DZBIYi/U2Dt4m7UWUZGTGY1/U1kCrRwyvJ2TTBhtgrNDcd/ASRKDyU80zKjenv1hAFWqcjaXnITnQ3Dpr0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072748; 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=0X1TnjZlRdHw8tcCNGOF380Ublm92SUhVeJg2HrPl0Y=; b=dYwQrPnkh7Jg/hONT/nHZEai7+UmalvQ45D6SIx0E/1NgQXlo241n6wK6bm7R0ecGtvLX0hPqgDw+MW+zxniuWZJmJ+ecANo1RIAFGaH9OeR+9EOjh/yM1Q2IGWmf5H0dZjDFnO5QSV+jbUi5Zf8afHtHYheDSaY0gXAgKrjbqw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072748666418.73492963064587; Wed, 7 Oct 2020 05:12:28 -0700 (PDT) Received: from localhost ([::1]:54568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8J0-0002R1-D0 for importer@patchew.org; Wed, 07 Oct 2020 08:12:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84V-0001mm-EB for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42479) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84P-0001lc-L8 for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:27 -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-190-G3Pj886nNbOeOw2PJuffYg-1; Wed, 07 Oct 2020 07:57:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2A9B81F000; Wed, 7 Oct 2020 11:57:17 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FFAD60BEC; Wed, 7 Oct 2020 11:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071840; 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=0X1TnjZlRdHw8tcCNGOF380Ublm92SUhVeJg2HrPl0Y=; b=Zy4qSW5wPlM5NDLzNmb8IPJt/VvqbB9CmoMALWE+HD/xRwkoQETiPnWGoq1ROntz8L7CAw CXQFj37buzJNrFDFYVaULGZH/BZvPja5QtXAsxt7nPuuHniGEoTHM6jjfaPcr0TT32uu4x k4qw+tjA/kHlIHoNxhKUAfLQ+FgpU7A= X-MC-Unique: G3Pj886nNbOeOw2PJuffYg-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 13/17] device-core: use atomic_set on .realized property Date: Wed, 7 Oct 2020 07:56:56 -0400 Message-Id: <20201007115700.707938-14-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, Maxim Levitsky , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Some code might race with placement of new devices on a bus. We currently first place a (unrealized) device on the bus and then realize it. As a workaround, users that scan the child device list, can check the realized property to see if it is safe to access such a device. Use an atomic write here too to aid with this. A separate discussion is what to do with devices that are unrealized: It looks like for this case we only call the hotplug handler's unplug callback and its up to it to unrealize the device. An atomic operation doesn't cause harm for this code path though. Signed-off-by: Maxim Levitsky Reviewed-by: Stefan Hajnoczi Message-Id: <20200913160259.32145-6-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini Message-Id: <20201006123904.610658-10-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 19 ++++++++++++++++++- include/hw/qdev-core.h | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 59e5e710b7..fc4daa36fa 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -946,7 +946,25 @@ static void device_set_realized(Object *obj, bool valu= e, Error **errp) } } =20 + qatomic_store_release(&dev->realized, value); + } else if (!value && dev->realized) { + + /* + * Change the value so that any concurrent users are aware + * that the device is going to be unrealized + * + * TODO: change .realized property to enum that states + * each phase of the device realization/unrealization + */ + + qatomic_set(&dev->realized, value); + /* + * Ensure that concurrent users see this update prior to + * any other changes done by unrealize. + */ + smp_wmb(); + QLIST_FOREACH(bus, &dev->child_bus, sibling) { qbus_unrealize(bus); } @@ -961,7 +979,6 @@ static void device_set_realized(Object *obj, bool value= , Error **errp) } =20 assert(local_err =3D=3D NULL); - dev->realized =3D value; return; =20 child_realize_fail: diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 2c6307e3ed..868973319e 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -163,6 +163,8 @@ struct NamedClockList { /** * DeviceState: * @realized: Indicates whether the device has been fully constructed. + * When accessed outsize big qemu lock, must be accessed with + * atomic_load_acquire() * @reset: ResettableState for the device; handled by Resettable interface. * * This structure should not be accessed directly. We declare it here --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072655; cv=none; d=zohomail.com; s=zohoarc; b=lZT+9W4xVt49sVi+eO3qKAMgMG1969vw+2yYbCpqIZw2QZEGP8+5qpW/jkxfXrf/xIARBoTuR5q7OcUoJ3iJSoCgKfbRPVsttWVwYETdvqRjyraF8NUlLp0DfMKI746veb88UYA2TaZX6yXMre+5FTuUvLvvUUbM8u6Vyf4ek5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072655; 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=dOm/tm/s7vlLGUaUhM3KYMR3GBBc1c4+MT8F0OlIOdc=; b=C+C/D1ydxUpx0tO+G96ZrH5we2EQIqSYk0I9VHI8EqIEFLquGLuJqqsgoZMNEdU7dCXm1Ta9sOsOv9m2Lm7Pcp/bw80jRdtsmFUQbDZ4A47GTzJ8PNrNI0CPkdLyBEuSCGAI7FNoKuVbAvPS9vumiy8bU5/+iZclv5NL/ErA6a4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072655832644.6567191974656; Wed, 7 Oct 2020 05:10:55 -0700 (PDT) Received: from localhost ([::1]:50472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8HW-0000W8-2C for importer@patchew.org; Wed, 07 Oct 2020 08:10:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84U-0001kK-Nr for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84R-0001mD-CN for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:26 -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-359-YYq1JicLNfi2__YEsmSQZQ-1; Wed, 07 Oct 2020 07:57:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6ED9D10BBEC2; Wed, 7 Oct 2020 11:57:18 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id DED4960BEC; Wed, 7 Oct 2020 11:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071841; 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=dOm/tm/s7vlLGUaUhM3KYMR3GBBc1c4+MT8F0OlIOdc=; b=J2V2l6mdYrOzFJe3kcyzMVAQt2G7KoJJ9xF3QnpGm+K+/7WnxDsmLpMLmzkc+UWkCD/Fre 4CBT3pubWz4gAgmywsCk4XnLUnQODq/jKzvKwQDwsIdAqwJGZRr2kDq+tKSWYnUFqzOpGw IONTnuVrcTYdvt2QbheQO3vFUkqR3CA= X-MC-Unique: YYq1JicLNfi2__YEsmSQZQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 14/17] scsi/scsi-bus: scsi_device_find: don't return unrealized devices Date: Wed, 7 Oct 2020 07:56:57 -0400 Message-Id: <20201007115700.707938-15-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:54:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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, Maxim Levitsky , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The device core first places a device on the bus and then realizes it. Make scsi_device_find avoid returing such devices to avoid races in drivers that use an iothread (currently virtio-scsi) Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D1812399 Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky Reviewed-by: Stefan Hajnoczi Message-Id: <20200913160259.32145-7-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini Message-Id: <20201006123904.610658-11-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-bus.c | 83 +++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 30 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 4ab9811cd8..7599113efe 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -24,6 +24,55 @@ static void scsi_target_free_buf(SCSIRequest *req); =20 static int next_scsi_bus; =20 +static SCSIDevice *do_scsi_device_find(SCSIBus *bus, + int channel, int id, int lun, + bool include_unrealized) +{ + BusChild *kid; + SCSIDevice *retval =3D NULL; + + QTAILQ_FOREACH_RCU(kid, &bus->qbus.children, sibling) { + DeviceState *qdev =3D kid->child; + SCSIDevice *dev =3D SCSI_DEVICE(qdev); + + if (dev->channel =3D=3D channel && dev->id =3D=3D id) { + if (dev->lun =3D=3D lun) { + retval =3D dev; + break; + } + + /* + * If we don't find exact match (channel/bus/lun), + * we will return the first device which matches channel/bus + */ + + if (!retval) { + retval =3D dev; + } + } + } + + /* + * This function might run on the IO thread and we might race against + * main thread hot-plugging the device. + * We assume that as soon as .realized is set to true we can let + * the user access the device. + */ + + if (retval && !include_unrealized && + !qatomic_load_acquire(&retval->qdev.realized)) { + retval =3D NULL; + } + + return retval; +} + +SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun) +{ + RCU_READ_LOCK_GUARD(); + return do_scsi_device_find(bus, channel, id, lun, false); +} + static void scsi_device_realize(SCSIDevice *s, Error **errp) { SCSIDeviceClass *sc =3D SCSI_DEVICE_GET_CLASS(s); @@ -137,7 +186,10 @@ static bool scsi_bus_is_address_free(SCSIBus *bus, int channel, int target, int lun, SCSIDevice **p_dev) { - SCSIDevice *d =3D scsi_device_find(bus, channel, target, lun); + SCSIDevice *d; + + RCU_READ_LOCK_GUARD(); + d =3D do_scsi_device_find(bus, channel, target, lun, true); if (d && d->lun =3D=3D lun) { if (p_dev) { *p_dev =3D d; @@ -1570,35 +1622,6 @@ static char *scsibus_get_fw_dev_path(DeviceState *de= v) qdev_fw_name(dev), d->id, d->lun); } =20 -SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int id, int lun) -{ - BusChild *kid; - SCSIDevice *target_dev =3D NULL; - - RCU_READ_LOCK_GUARD(); - QTAILQ_FOREACH_RCU(kid, &bus->qbus.children, sibling) { - DeviceState *qdev =3D kid->child; - SCSIDevice *dev =3D SCSI_DEVICE(qdev); - - if (dev->channel =3D=3D channel && dev->id =3D=3D id) { - if (dev->lun =3D=3D lun) { - return dev; - } - - /* - * If we don't find exact match (channel/bus/lun), - * we will return the first device which matches channel/bus - */ - - if (!target_dev) { - target_dev =3D dev; - } - } - } - - return target_dev; -} - /* SCSI request list. For simplicity, pv points to the whole device */ =20 static int put_scsi_requests(QEMUFile *f, void *pv, size_t size, --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072677; cv=none; d=zohomail.com; s=zohoarc; b=DjkVlnp79Rfc6I5kD35FR/E6++/ugZN6kbJQcKpatG2ZwNeRrn98OKHJ02l3VDEKydD7ZxMO+qNN4k1awZHH8frA/UsMkbdfKcchmYqdQXIvCNAUi3etPf7IUqFLg5wDD8iIkFNe7H/miV8P5ZMwppDoDKcD+5z/jGgPvv8/IdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072677; 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=h86QYWe84/+aRJP+nlAXGp7OtWwOWXKNZ6fAFrPDu4c=; b=VvAv0zYmUg4rmbcNymdHGuLZFQTD/lSXG4n5joNdM9bn6ByIaJsZlnAzEvzgDudB0iH+x0n+JN0o7/y1OhBNw3UKZOx0CpXhXAiX+46vMYGRY9KiZTxGjlv743y3lB69bJGyahxqLkJpp9z8y1OPXVhRUGdRD1MyZHEY7CI78zo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 160207267778550.392330396896455; Wed, 7 Oct 2020 05:11:17 -0700 (PDT) Received: from localhost ([::1]:51808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8Hs-0001EE-Jl for importer@patchew.org; Wed, 07 Oct 2020 08:11:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84T-0001hv-SM for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:41111) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84R-0001mH-7f for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:25 -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-270-sdA9sgceOYiaiUkRd-kPuw-1; Wed, 07 Oct 2020 07:57:20 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1767881F002; Wed, 7 Oct 2020 11:57:19 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A48D60BEC; Wed, 7 Oct 2020 11:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071842; 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=h86QYWe84/+aRJP+nlAXGp7OtWwOWXKNZ6fAFrPDu4c=; b=Mq0Atwhn/kxVl9V09HCQ3vs18rn42qnI+UCRWMSDdaAsSjGnZBRRnyjiEeCdc6MEC2POT1 +QnTKoWtzJRvA5rrR/can8XBbfb10ernixvsumxzNxjlDp8yft7Ll3sFIwvOZN967yxte0 8EKZ6QItoXASqEjKImUnbbXQwOBPnVQ= X-MC-Unique: sdA9sgceOYiaiUkRd-kPuw-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 15/17] scsi/scsi_bus: Add scsi_device_get Date: Wed, 7 Oct 2020 07:56:58 -0400 Message-Id: <20201007115700.707938-16-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:44:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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, Stefan Hajnoczi , Maxim Levitsky , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Add scsi_device_get which finds the scsi device and takes a reference to it. Suggested-by: Stefan Hajnoczi Signed-off-by: Maxim Levitsky Message-Id: <20200913160259.32145-8-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini Message-Id: <20201006123904.610658-12-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-bus.c | 11 +++++++++++ include/hw/scsi/scsi.h | 1 + 2 files changed, 12 insertions(+) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 7599113efe..eda8cb7e70 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -73,6 +73,17 @@ SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, = int id, int lun) return do_scsi_device_find(bus, channel, id, lun, false); } =20 +SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, int id, int lun) +{ + SCSIDevice *d; + RCU_READ_LOCK_GUARD(); + d =3D do_scsi_device_find(bus, channel, id, lun, false); + if (d) { + object_ref(d); + } + return d; +} + static void scsi_device_realize(SCSIDevice *s, Error **errp) { SCSIDeviceClass *sc =3D SCSI_DEVICE_GET_CLASS(s); diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 7a55cdbd74..09fa5c9d2a 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -190,6 +190,7 @@ int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf= , int len, bool fixed); int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size, uint8_t *buf, uint8_t buf_size); SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lu= n); +SCSIDevice *scsi_device_get(SCSIBus *bus, int channel, int target, int lun= ); =20 /* scsi-generic.c. */ extern const SCSIReqOps scsi_generic_req_ops; --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072377; cv=none; d=zohomail.com; s=zohoarc; b=blL7ZN9wLai8IQedhoj9Lc0KNwVB5IXKwwQboQc+60D8HGlvwnTJaGfPQzVk6+dmgLFuuluVPWinBFn+0TVWKCgGsibl3yyR7LX+n4np6Arx0e4kTKq7nDyd277vSD4ZJ/nViMqflIksQ6cEuLu1I2iL36ooyKJHdkA2rnu9fHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072377; 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=pW3I7+8Fr03yk/X+Wk7CJwUrSBzdKsHrG85hgVxf070=; b=eB9YC3DueBlmkTHvI5aqL6m5KSruhKDHhmt1duoID9vsjMopy6+3lT41F6x49GJ682e8J/LlCj18k44yC7HiTDFsClf81wLEXt45SyZWQBEAJ5BSFjIrsqkp3GlosfN80kxYF+KOAtgQZNskTe2K5lp2hIr+aGdCSHQhCtdoiFs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 16020723779521021.6177510067108; Wed, 7 Oct 2020 05:06:17 -0700 (PDT) Received: from localhost ([::1]:38594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8D2-0003u2-LG for importer@patchew.org; Wed, 07 Oct 2020 08:06:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84W-0001om-1u for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50207) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84R-0001mc-N6 for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:27 -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-521-RcOW_gnRP8S8ptKRhoEpgQ-1; Wed, 07 Oct 2020 07:57:20 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4AD081F004; Wed, 7 Oct 2020 11:57:19 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 327A860BEC; Wed, 7 Oct 2020 11:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071843; 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=pW3I7+8Fr03yk/X+Wk7CJwUrSBzdKsHrG85hgVxf070=; b=gyTLuoOQo/70uAeFO/JCUwstQZkYCHBkVX4usLBkpctNaIXsmmdzYRtVtNzEOf4qmwvPe2 eHd5PF1iIOf05ND1ApYLpCk7IVoNbrqtfYnULCNjPn5zUjOfuzKu8HwGckf9HsPmgMcv8e ZPtMsip0ACRspdBqZ4xYTqg2a7PIhpw= X-MC-Unique: RcOW_gnRP8S8ptKRhoEpgQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 16/17] virtio-scsi: use scsi_device_get Date: Wed, 7 Oct 2020 07:56:59 -0400 Message-Id: <20201007115700.707938-17-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:54:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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, qemu-block@nongnu.org, Stefan Hajnoczi , Maxim Levitsky , Stefan Hajnoczi , mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky This will help us to avoid the scsi device disappearing after we took a reference to it. It doesn't by itself forbid case when we try to access an unrealized device Suggested-by: Stefan Hajnoczi Signed-off-by: Maxim Levitsky Reviewed-by: Stefan Hajnoczi Message-Id: <20200913160259.32145-9-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini Message-Id: <20201006123904.610658-13-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/virtio-scsi.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 971afbb217..3db9a8aae9 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -33,7 +33,7 @@ static inline int virtio_scsi_get_lun(uint8_t *lun) return ((lun[2] << 8) | lun[3]) & 0x3FFF; } =20 -static inline SCSIDevice *virtio_scsi_device_find(VirtIOSCSI *s, uint8_t *= lun) +static inline SCSIDevice *virtio_scsi_device_get(VirtIOSCSI *s, uint8_t *l= un) { if (lun[0] !=3D 1) { return NULL; @@ -41,7 +41,7 @@ static inline SCSIDevice *virtio_scsi_device_find(VirtIOS= CSI *s, uint8_t *lun) if (lun[2] !=3D 0 && !(lun[2] >=3D 0x40 && lun[2] < 0x80)) { return NULL; } - return scsi_device_find(&s->bus, 0, lun[1], virtio_scsi_get_lun(lun)); + return scsi_device_get(&s->bus, 0, lun[1], virtio_scsi_get_lun(lun)); } =20 void virtio_scsi_init_req(VirtIOSCSI *s, VirtQueue *vq, VirtIOSCSIReq *req) @@ -256,7 +256,7 @@ static inline void virtio_scsi_ctx_check(VirtIOSCSI *s,= SCSIDevice *d) * case of async cancellation. */ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req) { - SCSIDevice *d =3D virtio_scsi_device_find(s, req->req.tmf.lun); + SCSIDevice *d =3D virtio_scsi_device_get(s, req->req.tmf.lun); SCSIRequest *r, *next; BusChild *kid; int target; @@ -370,10 +370,10 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSC= SIReq *req) =20 rcu_read_lock(); QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { - d =3D SCSI_DEVICE(kid->child); - if (d->channel =3D=3D 0 && d->id =3D=3D target) { - qdev_reset_all(&d->qdev); - } + SCSIDevice *d1 =3D SCSI_DEVICE(kid->child); + if (d1->channel =3D=3D 0 && d1->id =3D=3D target) { + qdev_reset_all(&d1->qdev); + } } rcu_read_unlock(); =20 @@ -386,14 +386,17 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSC= SIReq *req) break; } =20 + object_unref(OBJECT(d)); return ret; =20 incorrect_lun: req->resp.tmf.response =3D VIRTIO_SCSI_S_INCORRECT_LUN; + object_unref(OBJECT(d)); return ret; =20 fail: req->resp.tmf.response =3D VIRTIO_SCSI_S_BAD_TARGET; + object_unref(OBJECT(d)); return ret; } =20 @@ -564,7 +567,7 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOSCS= I *s, VirtIOSCSIReq *req) } } =20 - d =3D virtio_scsi_device_find(s, req->req.cmd.lun); + d =3D virtio_scsi_device_get(s, req->req.cmd.lun); if (!d) { req->resp.cmd.response =3D VIRTIO_SCSI_S_BAD_TARGET; virtio_scsi_complete_cmd_req(req); @@ -580,10 +583,12 @@ static int virtio_scsi_handle_cmd_req_prepare(VirtIOS= CSI *s, VirtIOSCSIReq *req) req->sreq->cmd.xfer > req->qsgl.size)) { req->resp.cmd.response =3D VIRTIO_SCSI_S_OVERRUN; virtio_scsi_complete_cmd_req(req); + object_unref(OBJECT(d)); return -ENOBUFS; } scsi_req_ref(req->sreq); blk_io_plug(d->conf.blk); + object_unref(OBJECT(d)); return 0; } =20 --=20 2.26.2 From nobody Fri May 17 01:43:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602072350; cv=none; d=zohomail.com; s=zohoarc; b=ZNNkuCjl90XhRHHtXnGK6JfOSHFevkX/xDgjKSCeNEtrL/XxS6+g2GOwUiNlivaP5dUuVx+pKot/yPD+G+sv0p3ooNvXg7qO5X2S3DkJvh3Da4FRuqd5G1PxL25Tx79xrSNzHDlyxyn+kFZqVYvT6nvXVPUZuOSdxsNvKlylNJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602072350; 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=U0UUOtrq1fQ0NSBTSHvIDAywl8g3kvLSProVYS7MmD4=; b=dqqBpOoZqbIad0KwH0gyReq+5ivs4O2SetDP/jptad4ETbaaG6i7RFQmMYJzbwoef9WepSqgEFONR2TfEauHA95QVKEgc2bPHDrG5yrVa7ALzkZFhmls7eqZpdIC1RUhGU2Pwu6a5tzFWASNzNBh1vv+oYrcD1zEksOMPgirb6o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602072350398775.1763183106369; Wed, 7 Oct 2020 05:05:50 -0700 (PDT) Received: from localhost ([::1]:37236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQ8Ca-0003IR-Ly for importer@patchew.org; Wed, 07 Oct 2020 08:05:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQ84X-0001r6-DT for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35199) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQ84U-0001o1-95 for qemu-devel@nongnu.org; Wed, 07 Oct 2020 07:57:29 -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-375-hyNJwnDAP0urlTjrtDPXDQ-1; Wed, 07 Oct 2020 07:57:21 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7023F10BBEC3; Wed, 7 Oct 2020 11:57:20 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id E013160BEC; Wed, 7 Oct 2020 11:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602071845; 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=U0UUOtrq1fQ0NSBTSHvIDAywl8g3kvLSProVYS7MmD4=; b=fnNnwnoSp4FCIfN2rJgQMPhUvfSmOuL1IPDn7hX6k4cgxb32BnpA06VzlXwxWDEfqdTaSx sO5MTYY2StsfvpaiCiDsY/BIO0pj3rNtrL3Qd/wScZNpupSvH+eqYDTZhp0jpRSqyxE5Kt yf6znsa+bEclYzNuxAKZGyuiQTp/4to= X-MC-Unique: hyNJwnDAP0urlTjrtDPXDQ-1 From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH v8 17/17] scsi/scsi_bus: fix races in REPORT LUNS Date: Wed, 7 Oct 2020 07:57:00 -0400 Message-Id: <20201007115700.707938-18-pbonzini@redhat.com> In-Reply-To: <20201007115700.707938-1-pbonzini@redhat.com> References: <20201007115700.707938-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/07 00:54:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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.742, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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, Maxim Levitsky , Stefan Hajnoczi , qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Maxim Levitsky Currently scsi_target_emulate_report_luns iterates over the child device li= st twice, and there is no guarantee that this list is the same in both iterati= ons. The reason for iterating twice is that the first iteration calculates how much memory to allocate. However if we use a dynamic array we can avoid iterating twice, and therefore we avoid this race. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1866707 Signed-off-by: Maxim Levitsky Reviewed-by: Stefan Hajnoczi Message-Id: <20200913160259.32145-10-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini Message-Id: <20201006123904.610658-14-mlevitsk@redhat.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-bus.c | 68 ++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index eda8cb7e70..b901e701f0 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -438,19 +438,23 @@ struct SCSITargetReq { static void store_lun(uint8_t *outbuf, int lun) { if (lun < 256) { + /* Simple logical unit addressing method*/ + outbuf[0] =3D 0; outbuf[1] =3D lun; - return; + } else { + /* Flat space addressing method */ + outbuf[0] =3D 0x40 | (lun >> 8); + outbuf[1] =3D (lun & 255); } - outbuf[1] =3D (lun & 255); - outbuf[0] =3D (lun >> 8) | 0x40; } =20 static bool scsi_target_emulate_report_luns(SCSITargetReq *r) { BusChild *kid; - int i, len, n; int channel, id; - bool found_lun0; + uint8_t tmp[8] =3D {0}; + int len =3D 0; + GByteArray *buf; =20 if (r->req.cmd.xfer < 16) { return false; @@ -458,46 +462,40 @@ static bool scsi_target_emulate_report_luns(SCSITarge= tReq *r) if (r->req.cmd.buf[2] > 2) { return false; } + + /* reserve space for 63 LUNs*/ + buf =3D g_byte_array_sized_new(512); + channel =3D r->req.dev->channel; id =3D r->req.dev->id; - found_lun0 =3D false; - n =3D 0; =20 - RCU_READ_LOCK_GUARD(); + /* add size (will be updated later to correct value */ + g_byte_array_append(buf, tmp, 8); + len +=3D 8; =20 - QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) { - DeviceState *qdev =3D kid->child; - SCSIDevice *dev =3D SCSI_DEVICE(qdev); + /* add LUN0 */ + g_byte_array_append(buf, tmp, 8); + len +=3D 8; =20 - if (dev->channel =3D=3D channel && dev->id =3D=3D id) { - if (dev->lun =3D=3D 0) { - found_lun0 =3D true; + WITH_RCU_READ_LOCK_GUARD() { + QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) { + DeviceState *qdev =3D kid->child; + SCSIDevice *dev =3D SCSI_DEVICE(qdev); + + if (dev->channel =3D=3D channel && dev->id =3D=3D id && dev->l= un !=3D 0) { + store_lun(tmp, dev->lun); + g_byte_array_append(buf, tmp, 8); + len +=3D 8; } - n +=3D 8; } } - if (!found_lun0) { - n +=3D 8; - } - - scsi_target_alloc_buf(&r->req, n + 8); - - len =3D MIN(n + 8, r->req.cmd.xfer & ~7); - memset(r->buf, 0, len); - stl_be_p(&r->buf[0], n); - i =3D found_lun0 ? 8 : 16; - QTAILQ_FOREACH_RCU(kid, &r->req.bus->qbus.children, sibling) { - DeviceState *qdev =3D kid->child; - SCSIDevice *dev =3D SCSI_DEVICE(qdev); =20 - if (dev->channel =3D=3D channel && dev->id =3D=3D id) { - store_lun(&r->buf[i], dev->lun); - i +=3D 8; - } - } + r->buf_len =3D len; + r->buf =3D g_byte_array_free(buf, FALSE); + r->len =3D MIN(len, r->req.cmd.xfer & ~7); =20 - assert(i =3D=3D n + 8); - r->len =3D len; + /* store the LUN list length */ + stl_be_p(&r->buf[0], len - 8); return true; } =20 --=20 2.26.2