Received: from eggs.gnu.org ([2001:4830:134:3::10]:40835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xkc5e-0006bX-HA for qemu-devel@nongnu.org; Sat, 01 Nov 2014 13:03:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xkc5Y-0000ts-8G for qemu-devel@nongnu.org; Sat, 01 Nov 2014 13:03:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xkc5Y-0000tW-0t for qemu-devel@nongnu.org; Sat, 01 Nov 2014 13:03:44 -0400 Date: Sat, 1 Nov 2014 15:03:33 -0200 From: Eduardo Habkost Message-ID: <20141101170333.GE3298@thinpad.lan.raisama.net> References: <1414857371-12294-1-git-send-email-ehabkost@redhat.com> <1414857371-12294-2-git-send-email-ehabkost@redhat.com> <54550E56.2050404@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <54550E56.2050404@suse.de> 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: Andreas =?iso-8859-1?Q?F=E4rber?= Cc: Igor Mammedov , Gonglei , qemu-devel@nongnu.org, Stefan Hajnoczi , Paolo Bonzini On Sat, Nov 01, 2014 at 05:46:14PM +0100, Andreas F=E4rber wrote: > Hi, >=20 > 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 = char *alias) > > return NULL; > > } > > =20 > > +static DeviceClass *qdev_get_device_class(const char **driver, Error= **errp) >=20 > Since this does nothing qdev-specific, what about > device_get_class_by_name()? The only that's not generically suitable fo= r > hw/core/ is the "driver" naming in the error handling; otherwise it > looks very similar to the CPUClass hooks I added a while back. Well, I don't know where's the line that divides "qdev-specific" from "DeviceState-specific". The distinction seems arbitrary to me, and I won't see any problem if somebody moves all qdev-*.c files inside hw/core. :) I assume that at least qdev_alias_table (which is used by both qdev_device_add() and qdev_device_help()) can be considered qdev-specific (but just because the table is currently inside qdev-monitor.c). Anyway, the only point of this function is to reduce code duplication between qdev_device_add() and qdev_device_help() while fixing the "-device ,help" crashes. If somebody wants to move any of the existing qdev-*.c logic to hw/core later, I won't complain (but I wouldn't want to do that after hard freeze). >=20 > > +{ > > + 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", *d= river); > > + return NULL; > > + } > > + > > + if (object_class_is_abstract(oc)) { > > + error_set(errp, QERR_INVALID_PARAMETER_VALUE, "driver", > > + "non-abstract device type"); > > + return NULL; > > + } > > + >=20 > See 3/3 for whether we may want to return here. The point of this function is to allow reuse of checks that are necessary on both qdev_device_add() and qdev_device_help(), and both functions need to reject abstract and cannot_instantiate_with_device_add_yet classes. --=20 Eduardo