From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xkbol-0000cI-VU for qemu-devel@nongnu.org; Sat, 01 Nov 2014 12:46:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xkboe-0003Qn-Fh for qemu-devel@nongnu.org; Sat, 01 Nov 2014 12:46:23 -0400 Received: from cantor2.suse.de ([195.135.220.15]:50821 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xkboe-0003Qg-3u for qemu-devel@nongnu.org; Sat, 01 Nov 2014 12:46:16 -0400 Message-ID: <54550E56.2050404@suse.de> Date: Sat, 01 Nov 2014 17:46:14 +0100 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1414857371-12294-1-git-send-email-ehabkost@redhat.com> <1414857371-12294-2-git-send-email-ehabkost@redhat.com> In-Reply-To: <1414857371-12294-2-git-send-email-ehabkost@redhat.com> Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/3] qdev: Create qdev_get_device_class() function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost , qemu-devel@nongnu.org Cc: Igor Mammedov , Gonglei , Stefan Hajnoczi , Paolo Bonzini Hi, Am 01.11.2014 um 16:56 schrieb Eduardo Habkost: > Extract the DeviceClass lookup from qdev_device_add() to a separate > function. >=20 > Signed-off-by: Eduardo Habkost > --- > qdev-monitor.c | 70 +++++++++++++++++++++++++++++++++++---------------= -------- > 1 file changed, 42 insertions(+), 28 deletions(-) >=20 > 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 ch= ar *alias) > return NULL; > } > =20 > +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 =3D object_class_by_name(*driver); > + if (!oc) { > + const char *typename =3D find_typename_by_alias(*driver); > + > + if (typename) { > + *driver =3D typename; > + oc =3D object_class_by_name(*driver); > + } > + } > + > + if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) { > + error_setg(errp, "'%s' is not a valid device model name", *dri= ver); > + 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 =3D 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 =3D NULL; > @@ -455,7 +493,6 @@ static BusState *qbus_find(const char *path) > =20 > 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) > } > =20 > /* find driver */ > - oc =3D object_class_by_name(driver); > - if (!oc) { > - const char *typename =3D find_typename_by_alias(driver); > - > - if (typename) { > - driver =3D typename; > - oc =3D 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 =3D 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 =3D qdev_get_device_class(&driver, &err); > + if (err) { > + qerror_report_err(err); > + error_free(err); > return NULL; > } > =20 Otherwise looks good. Regards, Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg