On Mon, Sep 26, 2022 at 05:05:48PM -0500, Eric Blake wrote: > Rather than always relying on the implicit global list managed by > nbd_add_meta_context() and nbd_clear_meta_contexts(), we can take the > user's list of contexts as a direct parameter. This finally makes use > of the non-NULL queries parameter of the nbd_internal_set_querylist() > added in a previous patch. > > The C test is added along with this commit (applying the new test > independently wouldn't compile), but the language bindings are done > separately for ease of review. > ---
> +++ b/tests/opt-list-meta-queries.c > + /* Get into negotiating state. */ > + nbd = nbd_create (); > + if (nbd == NULL || > + nbd_set_opt_mode (nbd, true) == -1 || > + nbd_connect_command (nbd, args) == -1) { > + fprintf (stderr, "%s\n", nbd_get_error ()); > + exit (EXIT_FAILURE); > + } > + > + /* A NULL query is an error (C-only test) */ > + p = (struct progress) { .count = 0 }; > + r = nbd_opt_list_meta_context_queries (nbd, NULL, ctx); > + if (r != -1 || nbd_get_errno () != EFAULT) { > + fprintf (stderr, "expected EFAULT for NULL query list\n"); > + exit (EXIT_FAILURE); > + } > + if (p.count != 0 || p.seen) { > + fprintf (stderr, "unexpected use of callback on failure\n"); > + exit (EXIT_FAILURE); > + } Actually, once I weaken patch 1/18 to not trigger EFAULT on NULL StringList, this currently behaves the same as calling nbd_opt_list_meta_context() (that is, reusing the global nbd_add_meta_context() list); that is equally confusing, and we may decide that it is better to treat NULL the same as an explicit empty list rather than going back to the global implicit list. Since there will probably be followup patches, for now I'm just changing this from testing a specific behavior to instead being a FIXME comment reminding us to revisit it once we decide how to consistently handle NULL arguments. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs