From: "Daniel P. Berrange" <berrange@redhat.com>
To: "Marc Marí" <markmb@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 1/2] Add dynamic module loading for block drivers
Date: Thu, 27 Aug 2015 10:40:34 +0100 [thread overview]
Message-ID: <20150827094033.GE24486@redhat.com> (raw)
In-Reply-To: <20150827113541.28697140@markmb_rh>
On Thu, Aug 27, 2015 at 11:35:41AM +0200, Marc Marí wrote:
> On Thu, 27 Aug 2015 10:19:35 +0100
> "Daniel P. Berrange" <berrange@redhat.com> wrote:
>
> > On Mon, Aug 17, 2015 at 10:09:34AM +0200, Marc Marí wrote:
> > > Extend the current module interface to allow for block drivers to
> > > be loaded dynamically on request.
> > >
> > > The only block drivers that can be converted into modules are the
> > > drivers that don't perform any init operation except for
> > > registering themselves. This is why libiscsi has been disabled as a
> > > module.
> >
> > Seems like we would just need to split the iscsi opts registration out
> > into a separate file that is permanently linked.
> >
> > > All the necessary module information is located in a new structure
> > > found in include/qemu/module_block.h
> > >
> > > Signed-off-by: Marc Marí <markmb@redhat.com>
> > > ---
> > > block.c | 73
> > > +++++++++++++++++++++++++++++++++++-- configure
> > > | 2 +- include/qemu/module.h | 3 ++
> > > include/qemu/module_block.h | 89
> > > +++++++++++++++++++++++++++++++++++++++++++++
> > > util/module.c | 38 ++++++------------- 5 files
> > > changed, 174 insertions(+), 31 deletions(-) create mode 100644
> > > include/qemu/module_block.h
> > >
> > > diff --git a/block.c b/block.c
> > > index d088ee0..f24a624 100644
> > > --- a/block.c
> > > +++ b/block.c
> > > @@ -27,6 +27,7 @@
> > > #include "block/block_int.h"
> > > #include "block/blockjob.h"
> > > #include "qemu/error-report.h"
> > > +#include "qemu/module_block.h"
> > > #include "qemu/module.h"
> > > #include "qapi/qmp/qerror.h"
> > > #include "qapi/qmp/qjson.h"
> > > @@ -277,11 +278,30 @@ void bdrv_add_close_notifier(BlockDriverState
> > > *bs, Notifier *notify) BlockDriver *bdrv_find_format(const char
> > > *format_name) {
> > > BlockDriver *drv1;
> > > + int i;
> >
> > Nit-pick 'size_t' is a better type for loop iterators, especially
> > when combined with a sizeof() comparison. Some comment in later
> > functions too.
> >
> > > +
> > > QLIST_FOREACH(drv1, &bdrv_drivers, list) {
> > > if (!strcmp(drv1->format_name, format_name)) {
> > > return drv1;
> > > }
> > > }
> > > +
> > > + for (i = 0; i < ARRAY_SIZE(block_driver_module); ++i) {
> > > + if (!strcmp(block_driver_module[i].format_name,
> > > format_name)) {
> > > +
> > > block_module_load_one(block_driver_module[i].library_name);
> > > + /* Copying code is not nice, but this way the current
> > > discovery is
> > > + * not modified. Calling recursively could fail if the
> > > library
> > > + * has been deleted.
> > > + */
> >
> > Can you explaiin what you mean here about "if the library has been
> > deleted" ?
> >
> > Are you referring to possibilty of dlclose()ing the previously loaded
> > library, or about possibility of the module on disk having been
> > deleted or something else ?
>
> I was thinking of relaunching the search by calling recursively the
> function. But this would loop infinitely if somebody, manually, deleted
> the library file.
Ok, yea, that makes sense.
> If we have multiuple disks of the same type given to QEMU, it
> > seems like we might end up calling block_module_load_one()
> > multiple times for the same module & end up loading the same
> > .so multiple times as a result. Should module_load() keep a
> > record of everything it has loaded and short-circuit itself
> > to a no-op, so that callers of module_load() don't have to
> > worry about avoiding multiple calls.
>
> I avoided that because glib already has it. It just increments the
> reference count. Which is not important unless we want to dlclose it.
>
> https://developer.gnome.org/glib/stable/glib-Dynamic-Loading-of-Modules.html#g-module-open
Ah good.
NB, it is almost never safe to use dlclose() in a multi-threaded
application. A module may have created a thread-local variable
with a destructor function registered. There's no way to clean
these up prior to dlclose(), so the app would crash if you
dlclose() and a thread then exits. Since it is impractical to
audit all linked library code for use of thread locals, it is
safest to just avoid any use of dlclose().
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
next prev parent reply other threads:[~2015-08-27 9:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-17 8:09 [Qemu-devel] [PATCH 0/2] Dynamic module support for block drivers Marc Marí
2015-08-17 8:09 ` [Qemu-devel] [PATCH 1/2] Add dynamic module loading " Marc Marí
2015-08-27 9:19 ` Daniel P. Berrange
2015-08-27 9:35 ` Marc Marí
2015-08-27 9:40 ` Daniel P. Berrange [this message]
2015-09-03 16:33 ` Stefan Hajnoczi
2015-09-03 18:01 ` Marc Marí
2015-08-17 8:09 ` [Qemu-devel] [PATCH 2/2] Add dynamic generation of module_block.h Marc Marí
2015-08-27 9:23 ` Daniel P. Berrange
2015-08-27 9:37 ` Marc Marí
2015-08-27 8:51 ` [Qemu-devel] [PATCH 0/2] Dynamic module support for block drivers Marc Marí
2015-09-03 16:12 ` Stefan Hajnoczi
2015-09-03 18:07 ` Marc Marí
2015-09-07 13:09 ` Stefan Hajnoczi
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=20150827094033.GE24486@redhat.com \
--to=berrange@redhat.com \
--cc=markmb@redhat.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.