[Libguestfs] [nbdkit PATCH 1/5] api: Add .default_export

Eric Blake eblake at redhat.com
Wed Aug 26 13:26:21 UTC 2020


On 8/25/20 10:46 AM, Eric Blake wrote:
> I'm about to add an 'exportname' filter, and in the process, I noticed
> a few shortcomings in our API.  Time to fix those before the 1.22
> release locks our API in stone.  Overloading .list_exports in order to
> determine a canonical export name at .open time is awkward; the two
> uses (answering NBD_OPT_LIST for a full list, vs. remapping a client's
> "" into a canonical name during .open) are orthogonal enough to
> warrant separate plugin callbacks.  This will also make it easier to
> express the notion of no default export (connecting to "" is an error)
> at the same time as listing other exports.  Another consideration is
> that when tls=1, the choice of export to expose pre-TLS vs. post-TLS
> may differ, but without a call to .open yet, our just-added
> nbdkit_is_tls() does not fit our preferred lifecycle, so this has to
> be a parameter to the new .default_export.  We will alter the
> signature of .list_exports soon; in the meantime, the bool
> default_only parameter is now ignored.
> 

> +++ b/server/plugins.c

> @@ -282,15 +283,29 @@ static int
>   plugin_list_exports (struct backend *b, int readonly, int default_only,
>                        struct nbdkit_exports *exports)
>   {
> -  GET_CONN;
>     struct backend_plugin *p = container_of (b, struct backend_plugin, backend);
> 
> -  if (!p->plugin.list_exports)
> -    return nbdkit_add_export (exports, "", NULL);
> +  if (!p->plugin.list_exports) {
> +    const char *def = backend_default_export (b, readonly);
> +    if (def == NULL)
> +      return 0;
> +    return nbdkit_add_export (exports, def, NULL);
> +  }

This makes sense, but it is hard to replicate in language plugins.  As 
submitted in this round of patches, patch 5/5 causes test-eflags.sh to 
fail, because the sh plugin can't access the caching 
backend_default_export(), but instead called sh_default_export(), but 
the test was checking for proper caching.

My solution is to add nbdkit_add_default(exports), which tells nbdkit to 
append .default_export to the list at a later point in the process. 
I'll post v2 shortly.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




More information about the Libguestfs mailing list