From: "Andreas Färber" <afaerber@suse.de>
To: Eduardo Habkost <ehabkost@redhat.com>, qemu-devel@nongnu.org
Cc: Igor Mammedov <imammedo@redhat.com>,
Gonglei <arei.gonglei@huawei.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/3] qdev: Create qdev_get_device_class() function
Date: Sat, 01 Nov 2014 17:46:14 +0100 [thread overview]
Message-ID: <54550E56.2050404@suse.de> (raw)
In-Reply-To: <1414857371-12294-2-git-send-email-ehabkost@redhat.com>
Hi,
Am 01.11.2014 um 16:56 schrieb Eduardo Habkost:
> Extract the DeviceClass lookup from qdev_device_add() to a separate
> function.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> qdev-monitor.c | 70 +++++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 42 insertions(+), 28 deletions(-)
>
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index fac7d17..982f3f4 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -180,6 +180,44 @@ static const char *find_typename_by_alias(const char *alias)
> return NULL;
> }
>
> +static DeviceClass *qdev_get_device_class(const char **driver, Error **errp)
Since this does nothing qdev-specific, what about
device_get_class_by_name()? The only that's not generically suitable for
hw/core/ is the "driver" naming in the error handling; otherwise it
looks very similar to the CPUClass hooks I added a while back.
> +{
> + ObjectClass *oc;
> + DeviceClass *dc;
> +
> + oc = object_class_by_name(*driver);
> + if (!oc) {
> + const char *typename = find_typename_by_alias(*driver);
> +
> + if (typename) {
> + *driver = typename;
> + oc = object_class_by_name(*driver);
> + }
> + }
> +
> + if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
> + error_setg(errp, "'%s' is not a valid device model name", *driver);
> + return NULL;
> + }
> +
> + if (object_class_is_abstract(oc)) {
> + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
> + "non-abstract device type");
> + return NULL;
> + }
> +
See 3/3 for whether we may want to return here.
> + dc = DEVICE_CLASS(oc);
> + if (dc->cannot_instantiate_with_device_add_yet ||
> + (qdev_hotplug && !dc->hotpluggable)) {
> + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver",
> + "pluggable device type");
> + return NULL;
> + }
> +
> + return dc;
> +}
> +
> +
> int qdev_device_help(QemuOpts *opts)
> {
> Error *local_err = NULL;
> @@ -455,7 +493,6 @@ static BusState *qbus_find(const char *path)
>
> DeviceState *qdev_device_add(QemuOpts *opts)
> {
> - ObjectClass *oc;
> DeviceClass *dc;
> const char *driver, *path, *id;
> DeviceState *dev;
> @@ -469,33 +506,10 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> }
>
> /* find driver */
> - oc = object_class_by_name(driver);
> - if (!oc) {
> - const char *typename = find_typename_by_alias(driver);
> -
> - if (typename) {
> - driver = typename;
> - oc = object_class_by_name(driver);
> - }
> - }
> -
> - if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
> - qerror_report(ERROR_CLASS_GENERIC_ERROR,
> - "'%s' is not a valid device model name", driver);
> - return NULL;
> - }
> -
> - if (object_class_is_abstract(oc)) {
> - qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
> - "non-abstract device type");
> - return NULL;
> - }
> -
> - dc = DEVICE_CLASS(oc);
> - if (dc->cannot_instantiate_with_device_add_yet ||
> - (qdev_hotplug && !dc->hotpluggable)) {
> - qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver",
> - "pluggable device type");
> + dc = qdev_get_device_class(&driver, &err);
> + if (err) {
> + qerror_report_err(err);
> + error_free(err);
> return NULL;
> }
>
Otherwise looks good.
Regards,
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
next prev parent reply other threads:[~2014-11-01 16:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-01 15:56 [Qemu-devel] [PATCH 0/3] qdev: Validate class name for -device <class>, help Eduardo Habkost
2014-11-01 15:56 ` [Qemu-devel] [PATCH 1/3] qdev: Create qdev_get_device_class() function Eduardo Habkost
2014-11-01 16:46 ` Andreas Färber [this message]
2014-11-01 17:03 ` Eduardo Habkost
2014-11-01 15:56 ` [Qemu-devel] [PATCH 2/3] qdev: Move error printing to the end of qdev_device_help() Eduardo Habkost
2014-11-01 15:56 ` [Qemu-devel] [PATCH 3/3] qdev: Use qdev_device_add_get_class() for -device <type>, help Eduardo Habkost
2014-11-01 16:40 ` Andreas Färber
2014-11-01 16:45 ` Eduardo Habkost
2014-11-01 16:48 ` Andreas Färber
2014-11-01 17:22 ` Eduardo Habkost
2014-11-03 15:14 ` [Qemu-devel] [PATCH 0/3] qdev: Validate class name for -device <class>, help Stefan Hajnoczi
2014-11-04 16:51 ` Andreas Färber
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=54550E56.2050404@suse.de \
--to=afaerber@suse.de \
--cc=arei.gonglei@huawei.com \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).