nbdkit / mingw support
Eric: Yifan Gu has posted a few patches for mingw support. My comments below. https://github.com/gyf304/nbdkit/commit/a37c4ca6546dfc4e96e305af97b62e5a9d61... * I think the SHARED_LDFLAGS idea is good. I pushed a slightly different take on the idea here: https://github.com/libguestfs/nbdkit/commit/1d634009ab8e43592065ec469df63124... It's slightly different from what Yifan posted above, because I replaced -module -avoid-version -shared with $(SHARED_LDFLAGS), adding -no-undefined additionally on mingw. * Change to .gitignore is obviously fine, but I kept the file sorted: https://github.com/libguestfs/nbdkit/commit/002da4f4ca279a798fea1bf8749558d6... * Defining -D_spawnv=spawnv seems OK, but should be a separate patch. I didn't push anything. * Unclear why AM_CONDITIONAL(MINGW) is needed. It doesn't seem to be used anywhere unless I'm missing something. However if conditional compilation for mingw is needed for something, then this would be fine. * Unclear why it's necessary to rename nbdkit-common.h -> nbdkit-compat.h ? While this isn't API, it seems we should not rename it unless there's a good reason. * Functions are indirected through struct nbdkit_functions _nbdkit_functions which I guess is necessary because of PE linking (we've had similar problems with PE linking restrictions in other programs). However I wasn't very clear how this actually works, and we cannot break existing Linux binaries, so this needs more thought and must be conditional on Windows only. https://github.com/gyf304/nbdkit/commit/4f238c3e52a70b855dbb5f3eb3084d357b7c... * This one should be folded into the eventual nbdkit_functions patch. https://github.com/gyf304/nbdkit/commit/20d888fbb8ccf33f0975a070df0d8e3d929b... * Is there no way to get the socket peer on Windows? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
On Sat, Mar 21, 2020 at 12:06:15PM +0000, Richard W.M. Jones wrote:
https://github.com/gyf304/nbdkit/commit/20d888fbb8ccf33f0975a070df0d8e3d929b...
* Is there no way to get the socket peer on Windows?
And assuming there's no way to get the socket peer, then the function shouldn't be NULL (which will cause a segfault), but instead you should make the function return an error. eg: int nbdkit_peer_name (struct sockaddr *addr, socklen_t *addrlen) { +#ifndef WINDOWS [... existing code unchanged ...] +#else + nbdkit_error ("returning peer name is not supported on Windows"); + return -1; +#endif } If the problem is that msys doesn't have struct sockaddr or socklen_t, then I guess conditionally #defining them? Eric knows about this better than I do. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Answering a few questions: * Unclear why it's necessary to rename nbdkit-common.h -> nbdkit-compat.h - It's not a rename, but a new file. nbdkit-compat.h is included for PE DLL compatibility, and is included in nbdkit-common.h * Functions are indirected through struct nbdkit_functions _nbdkit_functions which I guess is necessary because of PE linking (we've had similar problems with PE linking restrictions in other programs). However I wasn't very clear how this actually works, and we cannot break existing Linux binaries, so this needs more thought and must be conditional on Windows only. - There are macro checks for an windows environment. If it's windows, then indirection is used. Otherwise, the original extern definitions are used. This shouldn't cause an ABI change on Linux. * Is there no way to get the socket peer on Windows? - It's not a lack of ways that prevents me from implementing this. The nbdkit port is to MSYS2 (which is a superset of mingw-64), and this is needed because nbdkit uses an extensive set of POSIX features that are not present in mingw-64, e.g. fork). This port requires MSYS2 to run. However, the user might choose to implement the plugins / filters using mingw-64, or just MSVC runtime, and I don't want to bind users to MSYS2. Now this causes a potential ABI incompatibility: MSYS2 socket definitions are provided by sys/socket.h, but mingw-64 / MSVC socket definitions are usually provided by winsock.h or winsock2.h. To prevent possible issues, I removed nbdkit_peer_name. This function is not defined in the include headers if Windows is detected, so it will cause a compile time error if someone attempts to use it. On Sat, Mar 21, 2020 at 1:20 PM Richard W.M. Jones <rjones@redhat.com> wrote:
On Sat, Mar 21, 2020 at 12:06:15PM +0000, Richard W.M. Jones wrote:
https://github.com/gyf304/nbdkit/commit/20d888fbb8ccf33f0975a070df0d8e3d929b...
* Is there no way to get the socket peer on Windows?
And assuming there's no way to get the socket peer, then the function shouldn't be NULL (which will cause a segfault), but instead you should make the function return an error. eg:
int nbdkit_peer_name (struct sockaddr *addr, socklen_t *addrlen) { +#ifndef WINDOWS [... existing code unchanged ...] +#else + nbdkit_error ("returning peer name is not supported on Windows"); + return -1; +#endif }
If the problem is that msys doesn't have struct sockaddr or socklen_t, then I guess conditionally #defining them? Eric knows about this better than I do.
Rich.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
On Sat, Mar 21, 2020 at 09:36:15PM -0400, Frank Gu wrote:
Answering a few questions:
* Unclear why it's necessary to rename nbdkit-common.h -> nbdkit-compat.h - It's not a rename, but a new file. nbdkit-compat.h is included for PE DLL compatibility, and is included in nbdkit-common.h
Oh I see. The github UI is super-confusing and made it look as if the file had been renamed. Is it possible at some point that you could rebase your work on top of the current head, and split it into individually reviewable patches? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
The rebased version is at https://github.com/gyf304/nbdkit/commits/msys2-port It is currently buildable with: autoreconf -i && ./configure host=x86_64-pc-msys && make -j A few changes are added: * nbdkit_peer_name is added back but will always error. * __declspec(dllexport) is added to the headers for PE compatibility. * -D_spawnv=spawnv is now removed. I think I didn't run ./configure properly last time. Here is the list of features that are tested to compile. Optional server features: bash-completion ........................ yes manual pages ........................... yes SELinux ................................ no TLS .................................... no Optional plugins: curl ................................... no example4 ............................... yes ext2 ................................... no floppy ................................. no guestfs ................................ no gzip ................................... no iso .................................... no libvirt ................................ no nbd .................................... no ssh .................................... no tar .................................... yes vddk ................................... yes Languages: lua .................................... no ocaml .................................. no perl ................................... yes python ................................. yes ruby ................................... no rust ................................... no tcl .................................... no Optional filters: ext2 ................................... no xz ..................................... no On Sun, Mar 22, 2020 at 10:28 AM Richard W.M. Jones <rjones@redhat.com> wrote:
On Sat, Mar 21, 2020 at 09:36:15PM -0400, Frank Gu wrote:
Answering a few questions:
* Unclear why it's necessary to rename nbdkit-common.h -> nbdkit-compat.h - It's not a rename, but a new file. nbdkit-compat.h is included for PE DLL compatibility, and is included in nbdkit-common.h
Oh I see. The github UI is super-confusing and made it look as if the file had been renamed.
Is it possible at some point that you could rebase your work on top of the current head, and split it into individually reviewable patches?
Rich.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
On 3/21/20 7:06 AM, Richard W.M. Jones wrote:
Eric:
Yifan Gu has posted a few patches for mingw support. My comments below.
https://github.com/gyf304/nbdkit/commit/a37c4ca6546dfc4e96e305af97b62e5a9d61...
* I think the SHARED_LDFLAGS idea is good. I pushed a slightly different take on the idea here: https://github.com/libguestfs/nbdkit/commit/1d634009ab8e43592065ec469df63124... It's slightly different from what Yifan posted above, because I replaced -module -avoid-version -shared with $(SHARED_LDFLAGS), adding -no-undefined additionally on mingw.
Why are we trying to avoid -no-undefined on other platforms? I do think it's annoying the way libtool picked their defaults: the lowest-common denominator in shared libraries is avoiding undefined symbols, while many platforms such as Linux permit it as extension. But instead of making libtool default to the lowest common denominator, instead, you HAVE to specify -no-undefined on platforms where undefined does not work, and on other platforms, the absence of -no-undefined lets you get away with extensions, while the explicit use of -no-undefined tells your toolchain to verify that indeed you are following the stricter compatibility setup of no undefined symbols. But if a strict setup is necessary for building on mingw, being able to validate on Linux that we are obeying a strict setup seems like it would be a good thing (then Linux builds can tell us if we accidentally introduce an undefined symbol dependency), rather than waiting until someone reports the problem on less-tested mingw. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
On Tue, Mar 24, 2020 at 01:43:52PM -0500, Eric Blake wrote:
On 3/21/20 7:06 AM, Richard W.M. Jones wrote:
Eric:
Yifan Gu has posted a few patches for mingw support. My comments below.
https://github.com/gyf304/nbdkit/commit/a37c4ca6546dfc4e96e305af97b62e5a9d61...
* I think the SHARED_LDFLAGS idea is good. I pushed a slightly different take on the idea here: https://github.com/libguestfs/nbdkit/commit/1d634009ab8e43592065ec469df63124... It's slightly different from what Yifan posted above, because I replaced -module -avoid-version -shared with $(SHARED_LDFLAGS), adding -no-undefined additionally on mingw.
Why are we trying to avoid -no-undefined on other platforms?
Isn't it because we rely on it, since our plugins need symbols that are undefined at link time such as nbdkit_*? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
On 3/24/20 1:54 PM, Richard W.M. Jones wrote:
On Tue, Mar 24, 2020 at 01:43:52PM -0500, Eric Blake wrote:
On 3/21/20 7:06 AM, Richard W.M. Jones wrote:
Eric:
Yifan Gu has posted a few patches for mingw support. My comments below.
https://github.com/gyf304/nbdkit/commit/a37c4ca6546dfc4e96e305af97b62e5a9d61...
* I think the SHARED_LDFLAGS idea is good. I pushed a slightly different take on the idea here: https://github.com/libguestfs/nbdkit/commit/1d634009ab8e43592065ec469df63124... It's slightly different from what Yifan posted above, because I replaced -module -avoid-version -shared with $(SHARED_LDFLAGS), adding -no-undefined additionally on mingw.
Why are we trying to avoid -no-undefined on other platforms?
Isn't it because we rely on it, since our plugins need symbols that are undefined at link time such as nbdkit_*?
Yes, at the moment they do, but do they need to? We could ship libnbdkit which provides just the symbols that plugins can link against, and then link our binary nbdkit against that same library, rather than expecting our plugins to compile undefined until loaded by our binary. In other words, if the fix is by separating our public functions into a shared library for mingw to compile plugins without undefined symbols, why not do the same for all platforms? -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
I think that will break the ABI backward compatibility. On Tue, Mar 24, 2020 at 15:16 Eric Blake <eblake@redhat.com> wrote:
On 3/24/20 1:54 PM, Richard W.M. Jones wrote:
On Tue, Mar 24, 2020 at 01:43:52PM -0500, Eric Blake wrote:
On 3/21/20 7:06 AM, Richard W.M. Jones wrote:
Eric:
Yifan Gu has posted a few patches for mingw support. My comments below.
https://github.com/gyf304/nbdkit/commit/a37c4ca6546dfc4e96e305af97b62e5a9d61...
* I think the SHARED_LDFLAGS idea is good. I pushed a slightly different take on the idea here:
https://github.com/libguestfs/nbdkit/commit/1d634009ab8e43592065ec469df63124...
It's slightly different from what Yifan posted above, because I replaced -module -avoid-version -shared with $(SHARED_LDFLAGS), adding -no-undefined additionally on mingw.
Why are we trying to avoid -no-undefined on other platforms?
Isn't it because we rely on it, since our plugins need symbols that are undefined at link time such as nbdkit_*?
Yes, at the moment they do, but do they need to? We could ship libnbdkit which provides just the symbols that plugins can link against, and then link our binary nbdkit against that same library, rather than expecting our plugins to compile undefined until loaded by our binary. In other words, if the fix is by separating our public functions into a shared library for mingw to compile plugins without undefined symbols, why not do the same for all platforms?
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
On 3/24/20 2:18 PM, Frank Gu wrote: [top-posting on technical lists makes it harder to follow the conversation; I'm reordering your mail]
On Tue, Mar 24, 2020 at 15:16 Eric Blake <eblake@redhat.com> wrote:
Isn't it because we rely on it, since our plugins need symbols that are undefined at link time such as nbdkit_*?
Yes, at the moment they do, but do they need to? We could ship libnbdkit which provides just the symbols that plugins can link against, and then link our binary nbdkit against that same library, rather than expecting our plugins to compile undefined until loaded by our binary. In other words, if the fix is by separating our public functions into a shared library for mingw to compile plugins without undefined symbols, why not do the same for all platforms?
I think that will break the ABI backward compatibility.
How does it break ABI compatibility? An old plugin that was compiled on Linux with undefined symbols will still have those symbols satisfied at load-time by nbdkit, since nbdkit itself depends on libnbdkit to pull in those symbols. And while we would change in-tree plugins to use -no-undefined (which means in-tree plugins link against libnbdkit), it doesn't force out-of-tree plugins to compile against the library (out-of-tree plugins are not required to use libtool), so out-of-tree plugins can still have the same ABI compatibility as what we guarantee for plugins compiled against older nbdkit versions. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
On Tue, Mar 24, 2020 at 02:16:32PM -0500, Eric Blake wrote:
On 3/24/20 1:54 PM, Richard W.M. Jones wrote:
On Tue, Mar 24, 2020 at 01:43:52PM -0500, Eric Blake wrote:
On 3/21/20 7:06 AM, Richard W.M. Jones wrote:
Eric:
Yifan Gu has posted a few patches for mingw support. My comments below.
https://github.com/gyf304/nbdkit/commit/a37c4ca6546dfc4e96e305af97b62e5a9d61...
* I think the SHARED_LDFLAGS idea is good. I pushed a slightly different take on the idea here: https://github.com/libguestfs/nbdkit/commit/1d634009ab8e43592065ec469df63124... It's slightly different from what Yifan posted above, because I replaced -module -avoid-version -shared with $(SHARED_LDFLAGS), adding -no-undefined additionally on mingw.
Why are we trying to avoid -no-undefined on other platforms?
Isn't it because we rely on it, since our plugins need symbols that are undefined at link time such as nbdkit_*?
Yes, at the moment they do, but do they need to? We could ship libnbdkit which provides just the symbols that plugins can link against, and then link our binary nbdkit against that same library, rather than expecting our plugins to compile undefined until loaded by our binary. In other words, if the fix is by separating our public functions into a shared library for mingw to compile plugins without undefined symbols, why not do the same for all platforms?
(For non-mingw platforms) this breaks the source API promises rather seriously, so if I understand your proposal correctly I don't think this is a good idea. It's possibly something we can consider for internal plugins, or for the V3 API. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
On 3/24/20 2:44 PM, Richard W.M. Jones wrote:
Why are we trying to avoid -no-undefined on other platforms?
Isn't it because we rely on it, since our plugins need symbols that are undefined at link time such as nbdkit_*?
Yes, at the moment they do, but do they need to? We could ship libnbdkit which provides just the symbols that plugins can link against, and then link our binary nbdkit against that same library, rather than expecting our plugins to compile undefined until loaded by our binary. In other words, if the fix is by separating our public functions into a shared library for mingw to compile plugins without undefined symbols, why not do the same for all platforms?
(For non-mingw platforms) this breaks the source API promises rather seriously, so if I understand your proposal correctly I don't think this is a good idea. It's possibly something we can consider for internal plugins, or for the V3 API.
How does it break API to request that someone link against a particular library if they want to avoid undefined symbols (and to continue to allow the to link with undefined symbols if they choose not to compile against that library)? That is, I'm trying to see what you are considering to be a break between: - what we have now: nbdkit-file-plugin.so: depends on nbdkit_realpath() as undefined symbol nbdkit binary: provides nbdkit_realpath() before dlloading the plugin - building with -no-undefined libnbdkit.so: provides nbdkit_realpath() nbdkit binary: depends on libnbdkit.so, making nbdkit_realpath() available nbdkit-file-plugin.so: depends on libnbdkit.so, so it sees nbdkit_realpath() - out-of-tree with undefined symbol libnbdkit.so: provides nbdkit_realpath() nbdkit binary: depends on libnbdkit.so, making nbdkit_realpath() available nbdkit-file-plugin.so: undefined dependency on nbdkit_realpath() -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
On 3/24/20 3:12 PM, Eric Blake wrote:
(For non-mingw platforms) this breaks the source API promises rather seriously, so if I understand your proposal correctly I don't think this is a good idea. It's possibly something we can consider for internal plugins, or for the V3 API.
How does it break API to request that someone link against a particular library if they want to avoid undefined symbols (and to continue to allow the to link with undefined symbols if they choose not to compile against that library)?
I guess what I haven't said yet is that the existing proposed patches from Frank for making mingw compile are NOT the right way to resolve the need for -no-undefined on that platform. Instead of creating lots of wrapper functions buried inside #ifdef WINDOWS_COMPAT, we really should be focusing on creating a clean libnbdkit.so/dll library that exposes all of the needed symbols without the need for preprocessor magic, and therefore without API breaks. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
I think I understand now that libnbdkit.so won't break the ABI for existing plugins. Does it require that plugins for newer nbdkit use -lnbdkit (which would be a source API break) or would it still be possible to compile without this? I guess as long as plugins do not start using -no-undefined then it would still work, so it wouldn't be a source API break. I had a look into how we might implement libnbdkit.so. Some functions are obviously self-contained (eg. nbdkit_parse_*, nbdkit_realpath, nbdkit_debug, nbdkit_error, nbdkit_*extents). Unfortunately some functions depend themselves on internals of the server: * nbdkit_nanosleep, nbdkit_export_name, nbdkit_peer_name call threadlocal_get_conn * nbdkit_set_error calls threadlocal_set_error * nbdkit_shutdown must set the quit global (or call a server function) I guess we can deal with the first ones by moving threadlocal.c into the same library, although it's a bit awkward. The quit flag is still more awkward because you have to move a lot of quit pipe handling code into the library which has knock-on effects all over. Rich. ---------------------------------------------------------------------- server/debug.c:nbdkit_vdebug (const char *fs, va_list args) server/debug.c:nbdkit_debug (const char *fs, ...) server/extents.c:nbdkit_extents_new (uint64_t start, uint64_t end) server/extents.c:nbdkit_extents_free (struct nbdkit_extents *exts) server/extents.c:nbdkit_extents_count (const struct nbdkit_extents *exts) server/extents.c:nbdkit_get_extent (const struct nbdkit_extents *exts, size_t i) server/extents.c:nbdkit_add_extent (struct nbdkit_extents *exts, server/log.c:nbdkit_verror (const char *fs, va_list args) server/log.c:nbdkit_error (const char *fs, ...) server/log.c:nbdkit_vfprintf(FILE *f, const char *fmt, va_list args) server/plugins.c:nbdkit_set_error (int err) server/public.c:nbdkit_absolute_path (const char *path) server/public.c:nbdkit_realpath (const char *path) server/public.c:nbdkit_parse_int (const char *what, const char *str, int *rp) server/public.c:nbdkit_parse_int8_t (const char *what, const char *str, int8_t *rp) server/public.c:nbdkit_parse_int16_t (const char *what, const char *str, int16_t *rp) server/public.c:nbdkit_parse_int32_t (const char *what, const char *str, int32_t *rp) server/public.c:nbdkit_parse_int64_t (const char *what, const char *str, int64_t *rp) server/public.c:nbdkit_parse_unsigned (const char *what, const char *str, unsigned *rp) server/public.c:nbdkit_parse_uint8_t (const char *what, const char *str, uint8_t *rp) server/public.c:nbdkit_parse_uint16_t (const char *what, const char *str, uint16_t *rp) server/public.c:nbdkit_parse_uint32_t (const char *what, const char *str, uint32_t *rp) server/public.c:nbdkit_parse_uint64_t (const char *what, const char *str, uint64_t *rp) server/public.c:nbdkit_parse_size (const char *str) server/public.c:nbdkit_parse_bool (const char *str) server/public.c:nbdkit_read_password (const char *value, char **password) server/public.c:nbdkit_nanosleep (unsigned sec, unsigned nsec) server/public.c:nbdkit_export_name (void) server/public.c:nbdkit_peer_name (struct sockaddr *addr, socklen_t *addrlen) server/quit.c:nbdkit_shutdown (void) -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
On 3/25/20 7:16 AM, Richard W.M. Jones wrote:
I think I understand now that libnbdkit.so won't break the ABI for existing plugins. Does it require that plugins for newer nbdkit use -lnbdkit (which would be a source API break) or would it still be possible to compile without this? I guess as long as plugins do not start using -no-undefined then it would still work, so it wouldn't be a source API break.
Yes, that's what I'm thinking - it's an API break if you have to add in -lnbdkit; but you only have to add that if you want to use -no-undefined. Plugins compiled without -lnbdkit (either because they predate the library, or because they specifically did not care about -no-undefined) should still be viable.
I had a look into how we might implement libnbdkit.so. Some functions are obviously self-contained (eg. nbdkit_parse_*, nbdkit_realpath, nbdkit_debug, nbdkit_error, nbdkit_*extents).
Unfortunately some functions depend themselves on internals of the server:
* nbdkit_nanosleep, nbdkit_export_name, nbdkit_peer_name call threadlocal_get_conn * nbdkit_set_error calls threadlocal_set_error * nbdkit_shutdown must set the quit global (or call a server function)
Yeah, there's some awkward dependencies to figure out. It's obvious the library has to export public nbdkit_* interfaces for the sake of plugins, but can it also export one additional symbol _nbdkit_init() for internal use? Then we can have the nbdkit binary pass whatever additional hooks are needed for proper isolation of the public interface (a callback pointer to get at threadlocal_get_conn, threadlocal_set_error, the address of the quit global, ...), and leave the symbol undocumented (plus the fact that the leading _ will discourage plugins from trying to abuse it).
I guess we can deal with the first ones by moving threadlocal.c into the same library, although it's a bit awkward. The quit flag is still more awkward because you have to move a lot of quit pipe handling code into the library which has knock-on effects all over.
The other extreme is to have the entire nbdkit engine in libnbdkit.so, plus the addition of a single internal-only callback _nbdkit_main(), then the nbdkit binary becomes a bare-bones: int main (int argc, char *argv[]) { return _nbdkit_main (argc, argv); } at which point you don't have to decide which functionality lives where. After all, you already have a linker script that limits what the main binary exports; which really becomes what libnbdkit.so has to export. If we are worried about plugins trying to abuse that additional entry point, you can have _nbdkit_main set a flag on first execution so that subsequent attempts to call it fail immediately; but I'm not too worried about it. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
On Wed, Mar 25, 2020 at 07:46:37AM -0500, Eric Blake wrote:
On 3/25/20 7:16 AM, Richard W.M. Jones wrote:
I think I understand now that libnbdkit.so won't break the ABI for existing plugins. Does it require that plugins for newer nbdkit use -lnbdkit (which would be a source API break) or would it still be possible to compile without this? I guess as long as plugins do not start using -no-undefined then it would still work, so it wouldn't be a source API break.
Yes, that's what I'm thinking - it's an API break if you have to add in -lnbdkit; but you only have to add that if you want to use -no-undefined. Plugins compiled without -lnbdkit (either because they predate the library, or because they specifically did not care about -no-undefined) should still be viable.
I had a look into how we might implement libnbdkit.so. Some functions are obviously self-contained (eg. nbdkit_parse_*, nbdkit_realpath, nbdkit_debug, nbdkit_error, nbdkit_*extents).
Unfortunately some functions depend themselves on internals of the server:
* nbdkit_nanosleep, nbdkit_export_name, nbdkit_peer_name call threadlocal_get_conn * nbdkit_set_error calls threadlocal_set_error * nbdkit_shutdown must set the quit global (or call a server function)
Yeah, there's some awkward dependencies to figure out. It's obvious the library has to export public nbdkit_* interfaces for the sake of plugins, but can it also export one additional symbol _nbdkit_init() for internal use? Then we can have the nbdkit binary pass whatever additional hooks are needed for proper isolation of the public interface (a callback pointer to get at threadlocal_get_conn, threadlocal_set_error, the address of the quit global, ...), and leave the symbol undocumented (plus the fact that the leading _ will discourage plugins from trying to abuse it).
Yes this is a good point. Also I suppose this interface between nbdkit <-> libnbdkit.so is *not* ABI so we can change this at will? It would mean that nbdkit & libnbdkit.so must always be shipped together, but that doesn't seem to be a problem. Rich.
I guess we can deal with the first ones by moving threadlocal.c into the same library, although it's a bit awkward. The quit flag is still more awkward because you have to move a lot of quit pipe handling code into the library which has knock-on effects all over.
The other extreme is to have the entire nbdkit engine in libnbdkit.so, plus the addition of a single internal-only callback _nbdkit_main(), then the nbdkit binary becomes a bare-bones: int main (int argc, char *argv[]) { return _nbdkit_main (argc, argv); }
at which point you don't have to decide which functionality lives where. After all, you already have a linker script that limits what the main binary exports; which really becomes what libnbdkit.so has to export. If we are worried about plugins trying to abuse that additional entry point, you can have _nbdkit_main set a flag on first execution so that subsequent attempts to call it fail immediately; but I'm not too worried about it.
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
On 3/25/20 8:01 AM, Richard W.M. Jones wrote:
Unfortunately some functions depend themselves on internals of the server:
* nbdkit_nanosleep, nbdkit_export_name, nbdkit_peer_name call threadlocal_get_conn * nbdkit_set_error calls threadlocal_set_error * nbdkit_shutdown must set the quit global (or call a server function)
Yeah, there's some awkward dependencies to figure out. It's obvious the library has to export public nbdkit_* interfaces for the sake of plugins, but can it also export one additional symbol _nbdkit_init() for internal use? Then we can have the nbdkit binary pass whatever additional hooks are needed for proper isolation of the public interface (a callback pointer to get at threadlocal_get_conn, threadlocal_set_error, the address of the quit global, ...), and leave the symbol undocumented (plus the fact that the leading _ will discourage plugins from trying to abuse it).
Yes this is a good point.
Also I suppose this interface between nbdkit <-> libnbdkit.so is *not* ABI so we can change this at will? It would mean that nbdkit & libnbdkit.so must always be shipped together, but that doesn't seem to be a problem.
Yes, I can live with that. Similar to how we declare that while plugins are API/ABI-compatible across versions, filters are not, and to run a filter, it must come from the same sources as the nbdkit binary. So I don't see it as a problem to change our undocumented _nbdkit_internal() entry point at will. Of course, it is still wise to make our internal interface robust enough to make it easy to detect if a user has ever accidentally mismatched versions, such as declaring that the first parameter is a version number regardless of how other parameters change over time. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
participants (3)
-
Eric Blake -
Frank Gu -
Richard W.M. Jones