From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFIV9-0004IU-F5 for qemu-devel@nongnu.org; Tue, 21 Jun 2016 06:01:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFIV7-0008Qf-G6 for qemu-devel@nongnu.org; Tue, 21 Jun 2016 06:01:46 -0400 Sender: Paolo Bonzini References: <1466016055-31351-1-git-send-email-clord@redhat.com> <20160617095451.GC6994@stefanha-x1.localdomain> <20160621093252.GF32560@stefanha-x1.localdomain> From: Paolo Bonzini Message-ID: Date: Tue, 21 Jun 2016 12:01:35 +0200 MIME-Version: 1.0 In-Reply-To: <20160621093252.GF32560@stefanha-x1.localdomain> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH 0/2] Dynamic module loading for block drivers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , Colin Lord Cc: kwolf@redhat.com, den@openvz.org, qemu-devel@nongnu.org, qemu-block@nongnu.org, mreitz@redhat.com On 21/06/2016 11:32, Stefan Hajnoczi wrote: > I think the issue comes from the fact that you are considering something > like load_block_module(const char *filename) as the API instead of > request_block_driver(const char *driver_name). In the latter case it's > possible to return a BlockDriver pointer. In the former it's not. > > The request_block_driver() approach requires a mapping from block driver > names to modules. This can be achieved using a directory layout with > symlinks (hmm...Windows portability?): > > /usr/lib/qemu/block/ > +--- sheepdog.so > +--- by-protocol/ > +--- sheepdog+unix -> ../sheepdog.so > > request_block_driver() would look at > /usr/lib/qemu/block/by-protocol/ to find the module file. Another possibility is to add a ".loaded" element to the block_driver_modules[] array and break the recursion (or infinite loop): retry: QLIST_FOREACH(drv1, &bdrv_drivers, list) { if (!strcmp(drv1->format_name, format_name)) { return drv1; } } for (i = 0; i < ARRAY_SIZE(block_driver_modules); ++i) { if (!block_driver_modules[i].loaded && !strcmp(block_driver_modules[i].format_name, format_name)) { block_driver_modules[i].loaded = true; block_module_load_one(block_driver_modules[i].library_name); goto retry; } } BTW, please give a name to block_driver_modules[x]'s type, so that you can assign &block_driver_modules[i] to a pointer and use that as a shortcut. Thanks, Paolo