From nobody Sat Nov 23 23:44:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1730892000; cv=none; d=zohomail.com; s=zohoarc; b=LVDFY4etdH2lDlRPmPibZJTsni3uDdat+TOzX/MCKsVUgjDdgoDToHTFznwRPpBzPYfC0x7QOl23B7swHJnk2NgbVa6dbhRF7Xv7pb9FfMJobZ46/yiXE4QegGQF/tj1VMXwMR88Q7jZ23Y9MhUtM4uh8M/sgX3jGY5ctWreb7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730892000; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ebWlvUPvola7RjQFgMDCOYyzuGWnR2oAgbNYXv0Di1g=; b=Qm+w6fc3DI2SnXsnB3ZhJfHIdSEyR0WhJATuD3i/qFnQ0/zmuPYGpDLq3Q25nQXwipWUlAGaja6dAbLZOrA90MwLal188zqCRd28YP6hOrbBE5n0pqxz0+bmCWPWuru9BY1huYA4wSMhWAUURbZSYsSkFT54oUW7lIZ/lmc5jlo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1730892000047582.8294114055313; Wed, 6 Nov 2024 03:20:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t8e4A-0002gi-0N; Wed, 06 Nov 2024 06:19:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8e46-0002em-LX; Wed, 06 Nov 2024 06:19:10 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t8e43-0008FD-97; Wed, 06 Nov 2024 06:19:10 -0500 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:94a7:0:640:198e:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 275DB60CA0; Wed, 6 Nov 2024 14:19:00 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b49f::1:6]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id dIfYi50AYGk0-akOMQYq6; Wed, 06 Nov 2024 14:18:59 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1730891939; bh=ebWlvUPvola7RjQFgMDCOYyzuGWnR2oAgbNYXv0Di1g=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=E85lG0Rsah1BsCuT5JU/sMmciC/5LiTY9S0R90uaOBK6ziw4wt5KIJj1evH+v5vOv MgNhT9NgQTX3DqjRlaqWC93wGIYzzc12bV9MLR9zLtGShf5uAZR7uJYc+22PvmUrx8 o5W3NqXpDpuJU7wXndm0IbysJgtbVkr4t1nMN5BI= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, raphael@enfabrica.net, mst@redhat.com Cc: sgarzare@redhat.com, kwolf@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, Vladimir Sementsov-Ogievskiy Subject: [PATCH v7 1/3] qdev-monitor: add option to report GenericError from find_device_state Date: Wed, 6 Nov 2024 14:18:35 +0300 Message-Id: <20241106111837.115820-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106111837.115820-1-vsementsov@yandex-team.ru> References: <20241106111837.115820-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1730892001292116600 Content-Type: text/plain; charset="utf-8" Here we just prepare for the following patch, making possible to report GenericError as recommended. This patch doesn't aim to prevent further use of DeviceNotFound by future interfaces: - find_device_state() is used in blk_by_qdev_id() and qmp_get_blk() functions, which may lead to spread of DeviceNotFound anyway - also, nothing prevent simply copy-pasting find_device_state() calls with false argument Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Markus Armbruster Acked-by: Raphael Norwitz --- system/qdev-monitor.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c index 320c47b72d..2c76cef4d8 100644 --- a/system/qdev-monitor.c +++ b/system/qdev-monitor.c @@ -885,13 +885,20 @@ void qmp_device_add(QDict *qdict, QObject **ret_data,= Error **errp) object_unref(OBJECT(dev)); } =20 -static DeviceState *find_device_state(const char *id, Error **errp) +/* + * Note that creating new APIs using error classes other than GenericError= is + * not recommended. Set use_generic_error=3Dtrue for new interfaces. + */ +static DeviceState *find_device_state(const char *id, bool use_generic_err= or, + Error **errp) { Object *obj =3D object_resolve_path_at(qdev_get_peripheral(), id); DeviceState *dev; =20 if (!obj) { - error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, + error_set(errp, + (use_generic_error ? + ERROR_CLASS_GENERIC_ERROR : ERROR_CLASS_DEVICE_NOT_FOUN= D), "Device '%s' not found", id); return NULL; } @@ -956,7 +963,7 @@ void qdev_unplug(DeviceState *dev, Error **errp) =20 void qmp_device_del(const char *id, Error **errp) { - DeviceState *dev =3D find_device_state(id, errp); + DeviceState *dev =3D find_device_state(id, false, errp); if (dev !=3D NULL) { if (dev->pending_deleted_event && (dev->pending_deleted_expires_ms =3D=3D 0 || @@ -1076,7 +1083,7 @@ BlockBackend *blk_by_qdev_id(const char *id, Error **= errp) =20 GLOBAL_STATE_CODE(); =20 - dev =3D find_device_state(id, errp); + dev =3D find_device_state(id, false, errp); if (dev =3D=3D NULL) { return NULL; } --=20 2.34.1