All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
To: qemu-block@nongnu.org, raphael@enfabrica.net, mst@redhat.com
Cc: kwolf@redhat.com, hreitz@redhat.com, pbonzini@redhat.com,
	berrange@redhat.com, eduardo@habkost.net, armbru@redhat.com,
	dave@treblig.org, eblake@redhat.com, qemu-devel@nongnu.org,
	vsementsov@yandex-team.ru, yc-core@yandex-team.ru
Subject: [PATCH v3 3/5] qdev-monitor: add option to report GenericError from find_device_state
Date: Fri, 29 Mar 2024 21:37:56 +0300	[thread overview]
Message-ID: <20240329183758.3360733-4-vsementsov@yandex-team.ru> (raw)
In-Reply-To: <20240329183758.3360733-1-vsementsov@yandex-team.ru>

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 <vsementsov@yandex-team.ru>
---
 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 840177d19f..7e075d91c1 100644
--- a/system/qdev-monitor.c
+++ b/system/qdev-monitor.c
@@ -878,13 +878,20 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp)
     object_unref(OBJECT(dev));
 }
 
-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=true for new interfaces.
+ */
+static DeviceState *find_device_state(const char *id, bool use_generic_error,
+                                      Error **errp)
 {
     Object *obj = object_resolve_path_at(qdev_get_peripheral(), id);
     DeviceState *dev;
 
     if (!obj) {
-        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+        error_set(errp,
+                  (use_generic_error ?
+                   ERROR_CLASS_GENERIC_ERROR : ERROR_CLASS_DEVICE_NOT_FOUND),
                   "Device '%s' not found", id);
         return NULL;
     }
@@ -948,7 +955,7 @@ void qdev_unplug(DeviceState *dev, Error **errp)
 
 void qmp_device_del(const char *id, Error **errp)
 {
-    DeviceState *dev = find_device_state(id, errp);
+    DeviceState *dev = find_device_state(id, false, errp);
     if (dev != NULL) {
         if (dev->pending_deleted_event &&
             (dev->pending_deleted_expires_ms == 0 ||
@@ -1068,7 +1075,7 @@ BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
 
     GLOBAL_STATE_CODE();
 
-    dev = find_device_state(id, errp);
+    dev = find_device_state(id, false, errp);
     if (dev == NULL) {
         return NULL;
     }
-- 
2.34.1



  parent reply	other threads:[~2024-03-29 18:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29 18:37 [PATCH v3 0/5] vhost-user-blk: live resize additional APIs Vladimir Sementsov-Ogievskiy
2024-03-29 18:37 ` [PATCH v3 1/5] vhost-user-blk: simplify and fix vhost_user_blk_handle_config_change Vladimir Sementsov-Ogievskiy
2024-03-29 18:37 ` [PATCH v3 2/5] qdev-monitor: fix error message in find_device_state() Vladimir Sementsov-Ogievskiy
2024-03-29 18:37 ` Vladimir Sementsov-Ogievskiy [this message]
2024-03-29 18:37 ` [PATCH v3 4/5] qapi: introduce device-sync-config Vladimir Sementsov-Ogievskiy
2024-04-24 11:48   ` Markus Armbruster
2024-04-29  8:18     ` Vladimir Sementsov-Ogievskiy
2024-04-29 10:51       ` Markus Armbruster
2024-04-29 12:22         ` Vladimir Sementsov-Ogievskiy
2024-04-29 13:04           ` Markus Armbruster
2024-04-29 14:49             ` Vladimir Sementsov-Ogievskiy
2024-04-24 12:05   ` Markus Armbruster
2024-03-29 18:37 ` [PATCH v3 5/5] qapi: introduce CONFIG_READ event Vladimir Sementsov-Ogievskiy
2024-04-24 12:11   ` Markus Armbruster
2024-04-29  9:02     ` Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240329183758.3360733-4-vsementsov@yandex-team.ru \
    --to=vsementsov@yandex-team.ru \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dave@treblig.org \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael@enfabrica.net \
    --cc=yc-core@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.