From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlgFx-00017l-7C for qemu-devel@nongnu.org; Wed, 27 Nov 2013 09:38:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlgFr-0004W4-7r for qemu-devel@nongnu.org; Wed, 27 Nov 2013 09:38:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49827) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlgFr-0004Vz-06 for qemu-devel@nongnu.org; Wed, 27 Nov 2013 09:38:15 -0500 Date: Wed, 27 Nov 2013 15:37:52 +0100 From: Igor Mammedov Message-ID: <20131127153752.2d5d7220@nial.usersys.redhat.com> In-Reply-To: <52937641.30003@redhat.com> References: <1385001528-12003-1-git-send-email-imammedo@redhat.com> <1385001528-12003-8-git-send-email-imammedo@redhat.com> <52934872.60904@redhat.com> <20131125170158.1258f535@nial.usersys.redhat.com> <52937641.30003@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 07/27] add memdev backend infrastructure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: peter.maydell@linaro.org, mdroth@linux.vnet.ibm.com, mst@redhat.com, mjt@tls.msk.ru, stefanb@linux.vnet.ibm.com, stefanha@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, vasilis.liaskovitis@profitbricks.com, quintela@redhat.com, chegu_vinod@hp.com, kraxel@redhat.com, aliguori@amazon.com, hutao@cn.fujitsu.com, marcel.a@redhat.com, lcapitulino@redhat.com, afaerber@suse.de On Mon, 25 Nov 2013 17:09:37 +0100 Paolo Bonzini wrote: > Il 25/11/2013 17:01, Igor Mammedov ha scritto: > >> > So this is why you need a new command-line option. > >> > > >> > I think we need a generic mechanism for post-initialization of whatever > >> > is given on the command line. Perhaps you can do that with an > >> > interface, and get rid of -memdev and memdev_add altogether? > >> > > >> > MemoryBackend's implementation of the interface's sole method would call > >> > get_memory, of course. > > > > What I would use instead of memdev_add in CLI/HMP/QMP? > > We could add a new object_add command. > > > Could you explain it a bit more, please? > > The interface would look like > > struct QOMCommandLineIface { > void complete(Object *object, Error **errp); > Object *get_base_path(void); > } > > MemoryBackend could implement it like this: > > void memory_backend_complete(Object *object, Error **errp) > { > MemoryBackend *backend = MEMORY_BACKEND(object); > MemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(obj); > if (bc->get_memory) { > bc->get_memory(backend, errp); > } > } > > Object *memory_backend_get_base_path(void); > { > return container_get(qdev_get_backend(), "/memdev"), > } > > A default implementation can be added to RNGBackend and TPMBackend. > vl.c can use the interface like this in object_create: > > obj = object_new(type); > QOMCommandLineIface *cmdline_iface; > > if (IS_QOM_COMMAND_LINE(obj)) { > object_unref(obj); > error... > return -1; > } > > if (qemu_opt_foreach(opts, object_set_property, obj, 1) < 0) { > object_unref(obj); > return -1; > } > > cmdline_iface = QOM_COMMAND_LINE_GET_IFACE(obj); > cmdline_iface->complete(obj, &local_err); > if (local_err)) { > error_propagate(...) > object_unref(obj); > return -1; > } > > object_property_add_child(cmdline_iface->get_base_path(), > id, obj, NULL); > > Then you can just use -object instead of -memdev. It looks like "realize" for -object / object-add implemented via an interface. Maybe it should be renamed from QOMCommandLineIface to QOMRealizeIface and s/complete/realize/ so anyone who knows about Device.realize would get meaning without digging in complete() implementations. Alternative would be to behave just like Rng/Tpm do, i.e. use -object to do late initialization in a backend user (DimmDevice.realize). Draw back of it would be user won't get error during the first command "object-add" and only will get error when creating DimmDevice calling "device_add".