From: Anthony Liguori <anthony@codemonkey.ws>
To: "Dominik Żeromski" <dzeromsk@gmail.com>, qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH] Support for loading devices as dynamic libraries
Date: Sat, 25 Aug 2012 15:50:00 -0500 [thread overview]
Message-ID: <874nnqhf2f.fsf@codemonkey.ws> (raw)
In-Reply-To: <1345893020-4894-1-git-send-email-dzeromsk@gmail.com>
Dominik Żeromski <dzeromsk@gmail.com> writes:
> Adding support for loading DSO with -device option.
Hi,
A few things:
1) Out of tree modules are boring and there's very little
support/sympathy for supporting out of tree modules. That said, if
you implemented support for in tree modules and the build system
happened to work with out of tree modules too (as Linux does), you
would find much more support for that.
2) The GNU module guidelines should be followed. Namely, we should
expect modules to declare their licenses and programmatically enforce
license compatibility.
3) You should use glib's module loading API, not libdl
4) An explicitly insmod command should be used to load modules. Module
dependency is very complicated. It's easier to just load modules in
a specific order based on a configuration file.
There are very useful reasons to have modules in QEMU. I really think
Spice support would make sense as a module, for instance. libspice has
a lot of dependencies and forcing distros to set those dependencies as
dependencies on QEMU really stinks.
So there's pretty good use-cases for in-tree modules. It's definitely
worth doing. It's also pretty useful when doing security certifications.
Regards,
Anthony Liguori
>
> Example Makefile for out of tree modules:
> #v+
> DEVICENAME=pcnet2
>
> hw-obj-y=pcnet-pci.o
> hw-obj-y+=pcnet.o
>
> include rules.mak
>
> .PHONY: all
>
> QEMU_CFLAGS=-I../qemu-kvm -I../qemu-kvm/hw
> QEMU_CFLAGS+=-I../qemu-kvm/fpu -I../qemu-kvm/include
> QEMU_CFLAGS+=-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
>
> QEMU_CFLAGS+=-DTARGET_PHYS_ADDR_BITS=64 -fPIC
> LDFLAGS+=-shared
>
> LIBNAME=libqemu_$(DEVICENAME).so
>
> all: $(LIBNAME)
>
> $(LIBNAME): $(hw-obj-y)
> $(call LINK,$^)
>
> clean:
> rm -f *.o
> rm -f *.d
> rm -f $(LIBNAME)
>
> # Include automatically generated dependency files
> -include $(patsubst %.o, %.d, $(hw-obj-y))
>
> #v-
>
> Signed-off-by: Dominik Żeromski <dzeromsk@gmail.com>
> ---
> Makefile.target | 4 +++-
> hw/qdev-monitor.c | 11 +++++++++++
> 2 files changed, 14 insertions(+), 1 deletions(-)
>
> diff --git a/Makefile.target b/Makefile.target
> index 74f7a4a..7fd9245 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -130,7 +130,9 @@ obj-$(CONFIG_HAVE_GET_MEMORY_MAPPING) += memory_mapping.o
> obj-$(CONFIG_HAVE_CORE_DUMP) += dump.o
> obj-$(CONFIG_NO_GET_MEMORY_MAPPING) += memory_mapping-stub.o
> obj-$(CONFIG_NO_CORE_DUMP) += dump-stub.o
> -LIBS+=-lz
> +LIBS+=-lz -ldl
> +
> +LDFLAGS+=-rdynamic
>
> QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
> QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> index 7915b45..3b5b0b0 100644
> --- a/hw/qdev-monitor.c
> +++ b/hw/qdev-monitor.c
> @@ -17,6 +17,8 @@
> * License along with this library; if not, see <http://www.gnu.org/licenses/>.
> */
>
> +#include <dlfcn.h>
> +
> #include "qdev.h"
> #include "monitor.h"
> #include "qmp-commands.h"
> @@ -402,6 +404,8 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> const char *driver, *path, *id;
> DeviceState *qdev;
> BusState *bus;
> + void *libhandle;
> + char libname[NAME_MAX];
>
> driver = qemu_opt_get(opts, "driver");
> if (!driver) {
> @@ -419,7 +423,14 @@ DeviceState *qdev_device_add(QemuOpts *opts)
> obj = object_class_by_name(driver);
> }
> }
> + if (!obj) {
> + snprintf(libname, sizeof(libname), "libqemu_%s.so", driver);
>
> + libhandle = dlopen(libname, RTLD_NOW);
> + if (libhandle != NULL) {
> + obj = object_class_by_name(driver);
> + }
> + }
> if (!obj) {
> qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
> return NULL;
> --
> 1.7.0.4
prev parent reply other threads:[~2012-08-25 20:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-25 11:10 [Qemu-devel] [PATCH] Support for loading devices as dynamic libraries Dominik Żeromski
2012-08-25 13:53 ` Stefan Hajnoczi
2012-08-25 17:06 ` Dominik Żeromski
2012-08-25 18:18 ` Stefan Hajnoczi
2012-08-25 20:50 ` Anthony Liguori [this message]
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=874nnqhf2f.fsf@codemonkey.ws \
--to=anthony@codemonkey.ws \
--cc=dzeromsk@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.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).