Richard W.M. Jones
2020-Mar-23 12:28 UTC
[Libguestfs] [PATCH nbdkit 0/3] msys2 support for review
I pushed a few of the msys2 patches upstream. I changed the way that $(SHARED_LDFLAGS) works so it's more to my liking, and the others were pushed unchanged. Three patches remain which I'm posting on the mailing list for proper review. Rich.
Richard W.M. Jones
2020-Mar-23 12:28 UTC
[Libguestfs] [PATCH nbdkit 1/3] include: Function indirection for PE DLL
From: Yifan Gu <gyf304@gmail.com> This patch adds in indirection for API functions, as PE DLL loader does not resolve undefined symbols. This patch only includes header changes. --- include/nbdkit-common.h | 133 +++++++++++++++++++++++++++++++++++++++- include/nbdkit-compat.h | 97 +++++++++++++++++++++++++++++ include/nbdkit-filter.h | 39 ++++++++++++ include/nbdkit-plugin.h | 27 ++++++++ include/Makefile.am | 1 + 5 files changed, 295 insertions(+), 2 deletions(-) diff --git a/include/nbdkit-common.h b/include/nbdkit-common.h index 9d1d89d0..57abc423 100644 --- a/include/nbdkit-common.h +++ b/include/nbdkit-common.h @@ -40,10 +40,14 @@ #include <stdarg.h> #include <stdint.h> #include <errno.h> -#include <sys/socket.h> +#include <nbdkit-compat.h> #include <nbdkit-version.h> +#if defined(NBDKIT_INTERNAL) || !defined(WINDOWS_COMPAT) +#include <sys/socket.h> +#endif + #ifdef __cplusplus extern "C" { #endif @@ -76,6 +80,7 @@ extern "C" { #define NBDKIT_EXTENT_HOLE (1<<0) /* Same as NBD_STATE_HOLE */ #define NBDKIT_EXTENT_ZERO (1<<1) /* Same as NBD_STATE_ZERO */ +#if defined(NBDKIT_INTERNAL) || !defined(WINDOWS_COMPAT) extern void nbdkit_error (const char *msg, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2); extern void nbdkit_verror (const char *msg, va_list args) ATTRIBUTE_FORMAT_PRINTF (1, 0); @@ -113,9 +118,133 @@ extern const char *nbdkit_export_name (void); extern int nbdkit_peer_name (struct sockaddr *addr, socklen_t *addrlen); extern void nbdkit_shutdown (void); -struct nbdkit_extents; extern int nbdkit_add_extent (struct nbdkit_extents *, uint64_t offset, uint64_t length, uint32_t type); +#else +static void nbdkit_error (const char *msg, ...) + ATTRIBUTE_FORMAT_PRINTF (1, 2); +static void nbdkit_error (const char *msg, ...) +{ + va_list args; + va_start(args, msg); + _nbdkit_functions.verror(msg, args); + va_end(args); +} +static void nbdkit_verror (const char *msg, va_list args) + ATTRIBUTE_FORMAT_PRINTF (1, 0); +static void nbdkit_verror (const char *msg, va_list args) +{ + _nbdkit_functions.verror (msg, args); +} +static void nbdkit_debug (const char *msg, ...) + ATTRIBUTE_FORMAT_PRINTF (1, 2); +static void nbdkit_debug (const char *msg, ...) +{ + va_list args; + va_start (args, msg); + _nbdkit_functions.vdebug (msg, args); + va_end (args); +} +static void nbdkit_vdebug (const char *msg, va_list args) + ATTRIBUTE_FORMAT_PRINTF (1, 0); +static void nbdkit_vdebug (const char *msg, va_list args) +{ + _nbdkit_functions.vdebug (msg, args); +} + +static char *nbdkit_absolute_path (const char *path) +{ + return _nbdkit_functions.absolute_path (path); +} +static int64_t nbdkit_parse_size (const char *str) +{ + return _nbdkit_functions.parse_size (str); +} +static int nbdkit_parse_bool (const char *str) +{ + return _nbdkit_functions.parse_bool (str); +} +static int nbdkit_parse_int (const char *what, const char *str, + int *r) +{ + return _nbdkit_functions.parse_int (what, str, r); +} +static int nbdkit_parse_unsigned (const char *what, const char *str, + unsigned *r) +{ + return _nbdkit_functions.parse_unsigned (what, str, r); +} +static int nbdkit_parse_int8_t (const char *what, const char *str, + int8_t *r) +{ + return _nbdkit_functions.parse_int8_t (what, str, r); +} +static int nbdkit_parse_uint8_t (const char *what, const char *str, + uint8_t *r) +{ + return _nbdkit_functions.parse_uint8_t (what, str, r); +} +static int nbdkit_parse_int16_t (const char *what, const char *str, + int16_t *r) +{ + return _nbdkit_functions.parse_int16_t (what, str, r); +} +static int nbdkit_parse_uint16_t (const char *what, const char *str, + uint16_t *r) +{ + return _nbdkit_functions.parse_uint16_t (what, str, r); +} +static int nbdkit_parse_int32_t (const char *what, const char *str, + int32_t *r) +{ + return _nbdkit_functions.parse_int32_t (what, str, r); +} +static int nbdkit_parse_uint32_t (const char *what, const char *str, + uint32_t *r) +{ + return _nbdkit_functions.parse_uint32_t (what, str, r); +} +static int nbdkit_parse_int64_t (const char *what, const char *str, + int64_t *r) +{ + return _nbdkit_functions.parse_int64_t (what, str, r); +} +static int nbdkit_parse_uint64_t (const char *what, const char *str, + uint64_t *r) +{ + return _nbdkit_functions.parse_uint64_t(what, str, r); +} +static int nbdkit_read_password (const char *value, char **password) +{ + return _nbdkit_functions.read_password(value, password); +} +static char *nbdkit_realpath (const char *path) +{ + return _nbdkit_functions.realpath(path); +} +static int nbdkit_nanosleep (unsigned sec, unsigned nsec) +{ + return _nbdkit_functions.nanosleep(sec, nsec); +} +static const char *nbdkit_export_name (void) +{ + return _nbdkit_functions.export_name(); +} +static int nbdkit_peer_name (void *addr, void *addrlen) +{ + return _nbdkit_functions.peer_name(addr, addrlen); +} +static void nbdkit_shutdown (void) +{ + _nbdkit_functions.shutdown(); +} + +static int nbdkit_add_extent (struct nbdkit_extents *extents, + uint64_t offset, uint64_t length, uint32_t type) +{ + return _nbdkit_functions.add_extent(extents, offset, length, type); +} +#endif /* A static non-NULL pointer which can be used when you don't need a * per-connection handle. diff --git a/include/nbdkit-compat.h b/include/nbdkit-compat.h new file mode 100644 index 00000000..a0a4cb69 --- /dev/null +++ b/include/nbdkit-compat.h @@ -0,0 +1,97 @@ +/* nbdkit + * Copyright (C) 2013-2020 Red Hat Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Red Hat nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef NBDKIT_COMPAT_H +#define NBDKIT_COMPAT_H + +#if !defined (NBDKIT_PLUGIN_H) && !defined (NBDKIT_FILTER_H) +#error this header file should not be directly included +#endif + +#if defined(_WIN32) || defined(__MINGW32__) || defined(__CYGWIN__) || \ + defined(_MSC_VER) +#define WINDOWS_COMPAT +#endif + +struct nbdkit_extents; + +#if defined(WINDOWS_COMPAT) +#include <string.h> +#include <stdarg.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef WINDOWS_COMPAT +struct nbdkit_functions { + void (*verror) (const char *msg, va_list args); + void (*vdebug) (const char *msg, va_list args); + char * (*absolute_path) (const char *path); + int64_t (*parse_size) (const char *str); + int (*parse_bool) (const char *str); + int (*parse_int) (const char *what, const char *str, int *r); + int (*parse_unsigned) (const char *what, const char *str, unsigned *r); + int (*parse_int8_t) (const char *what, const char *str, int8_t *r); + int (*parse_uint8_t) (const char *what, const char *str, uint8_t *r); + int (*parse_int16_t) (const char *what, const char *str, int16_t *r); + int (*parse_uint16_t) (const char *what, const char *str, uint16_t *r); + int (*parse_int32_t) (const char *what, const char *str, int32_t *r); + int (*parse_uint32_t) (const char *what, const char *str, uint32_t *r); + int (*parse_int64_t) (const char *what, const char *str, int64_t *r); + int (*parse_uint64_t) (const char *what, const char *str, uint64_t *r); + int (*read_password) (const char *value, char **password); + char * (*realpath) (const char *path); + int (*nanosleep) (unsigned sec, unsigned nsec); + const char * (*export_name) (void); + int (*peer_name) (void *addr, void *addrlen); + void (*shutdown) (void); + + struct nbdkit_extents *(*extents_new) (uint64_t start, uint64_t end); + void (*extents_free) (struct nbdkit_extents *); + size_t (*extents_count) (const struct nbdkit_extents *); + struct nbdkit_extent (*get_extent) (const struct nbdkit_extents *, size_t); + int (*add_extent) (struct nbdkit_extents *, uint64_t offset, uint64_t length, + uint32_t type); + + void (*set_error) (int err); +}; + +struct nbdkit_functions _nbdkit_functions; +#endif + +#ifdef __cplusplus +} +#endif +#endif +#endif diff --git a/include/nbdkit-filter.h b/include/nbdkit-filter.h index ca58e496..40ab4345 100644 --- a/include/nbdkit-filter.h +++ b/include/nbdkit-filter.h @@ -110,11 +110,31 @@ struct nbdkit_extent { uint32_t type; }; +#if defined(NBDKIT_INTERNAL) || !defined(WINDOWS_COMPAT) extern struct nbdkit_extents *nbdkit_extents_new (uint64_t start, uint64_t end); extern void nbdkit_extents_free (struct nbdkit_extents *); extern size_t nbdkit_extents_count (const struct nbdkit_extents *); extern struct nbdkit_extent nbdkit_get_extent (const struct nbdkit_extents *, size_t); +#else +static struct nbdkit_extents *nbdkit_extents_new (uint64_t start, uint64_t end) +{ + return _nbdkit_functions.extents_new(start, end); +} +static void nbdkit_extents_free (struct nbdkit_extents *extents) +{ + _nbdkit_functions.extents_free(extents); +} +static size_t nbdkit_extents_count (const struct nbdkit_extents *extents) +{ + return _nbdkit_functions.extents_count(extents); +} +static struct nbdkit_extent nbdkit_get_extent (const struct nbdkit_extents *extents, + size_t size) +{ + return _nbdkit_functions.get_extent(extents, size); +} +#endif /* Filter struct. */ struct nbdkit_filter { @@ -204,6 +224,24 @@ struct nbdkit_filter { int *err); }; +#if defined(WINDOWS_COMPAT) +#define NBDKIT_REGISTER_FILTER(filter) \ + NBDKIT_CXX_LANG_C __declspec(dllexport) \ + struct nbdkit_filter * \ + filter_init (void) \ + { \ + (filter)._api_version = NBDKIT_FILTER_API_VERSION; \ + (filter)._version = NBDKIT_VERSION_STRING; \ + return &(filter); \ + } \ + NBDKIT_CXX_LANG_C __declspec(dllexport) \ + void \ + functions_init (struct nbdkit_functions *functions) \ + { \ + memcpy(&_nbdkit_functions, functions, \ + sizeof(struct nbdkit_functions)); \ + } +#else #define NBDKIT_REGISTER_FILTER(filter) \ NBDKIT_CXX_LANG_C \ struct nbdkit_filter * \ @@ -213,6 +251,7 @@ struct nbdkit_filter { (filter)._version = NBDKIT_VERSION_STRING; \ return &(filter); \ } +#endif #ifdef __cplusplus } diff --git a/include/nbdkit-plugin.h b/include/nbdkit-plugin.h index 7ff7bcee..6b6d99d3 100644 --- a/include/nbdkit-plugin.h +++ b/include/nbdkit-plugin.h @@ -140,8 +140,34 @@ struct nbdkit_plugin { int (*get_ready) (void); }; +#if defined(NBDKIT_INTERNAL) || !defined(WINDOWS_COMPAT) extern void nbdkit_set_error (int err); +#else +static void nbdkit_set_error (int err) +{ + _nbdkit_functions.set_error (err); +} +#endif +#if defined(WINDOWS_COMPAT) +#define NBDKIT_REGISTER_PLUGIN(plugin) \ + NBDKIT_CXX_LANG_C __declspec(dllexport) \ + struct nbdkit_plugin * \ + plugin_init (void) \ + { \ + (plugin)._struct_size = sizeof (plugin); \ + (plugin)._api_version = NBDKIT_API_VERSION; \ + (plugin)._thread_model = THREAD_MODEL; \ + return &(plugin); \ + } \ + NBDKIT_CXX_LANG_C __declspec(dllexport) \ + void \ + functions_init (struct nbdkit_functions *functions) \ + { \ + memcpy(&_nbdkit_functions, functions, \ + sizeof(struct nbdkit_functions)); \ + } +#else #define NBDKIT_REGISTER_PLUGIN(plugin) \ NBDKIT_CXX_LANG_C \ struct nbdkit_plugin * \ @@ -152,6 +178,7 @@ extern void nbdkit_set_error (int err); (plugin)._thread_model = THREAD_MODEL; \ return &(plugin); \ } +#endif #ifdef __cplusplus } diff --git a/include/Makefile.am b/include/Makefile.am index cf46abc6..8b413570 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -32,6 +32,7 @@ include $(top_srcdir)/common-rules.mk include_HEADERS = \ + nbdkit-compat.h \ nbdkit-common.h \ nbdkit-plugin.h \ nbdkit-filter.h \ -- 2.25.0
Richard W.M. Jones
2020-Mar-23 12:28 UTC
[Libguestfs] [PATCH nbdkit 2/3] server: Inject API functions for Windows
From: Yifan Gu <gyf304@gmail.com> Windows PE DLL needs function indirection, this patch injects API functions for plugins / filters if on Windows. Note that nbdkit_peer_name is explicitly disabled due to potential ABI incompatibilities. --- server/main.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/server/main.c b/server/main.c index b303146c..373918cf 100644 --- a/server/main.c +++ b/server/main.c @@ -104,6 +104,7 @@ unsigned int socket_activation /* $LISTEN_FDS and $LISTEN_PID set */; /* The linked list of zero or more filters, and one plugin. */ struct backend *top; +struct nbdkit_functions *functions = NULL; static char *random_fifo_dir = NULL; static char *random_fifo = NULL; @@ -152,6 +153,49 @@ dump_config (void) printf ("%s=%d\n", "version_minor", NBDKIT_VERSION_MINOR); } +#ifdef WINDOWS_COMPAT +static int dummy_peer_name (void *addr, void *addrlen) +{ + nbdkit_error ("nbdkit_peer_name not implemented on this platform"); + return -1; +} + +static void init_functions () +{ + functions = malloc (sizeof *functions); + if (functions == NULL) { + perror ("malloc"); + exit (EXIT_FAILURE); + } + functions->verror = nbdkit_verror; + functions->vdebug = nbdkit_vdebug; + functions->absolute_path = nbdkit_absolute_path; + functions->parse_size = nbdkit_parse_size; + functions->parse_bool = nbdkit_parse_bool; + functions->parse_int = nbdkit_parse_int; + functions->parse_unsigned = nbdkit_parse_unsigned; + functions->parse_int8_t = nbdkit_parse_int8_t; + functions->parse_uint8_t = nbdkit_parse_uint8_t; + functions->parse_int16_t = nbdkit_parse_int16_t; + functions->parse_uint16_t = nbdkit_parse_uint16_t; + functions->parse_int32_t = nbdkit_parse_int32_t; + functions->parse_uint32_t = nbdkit_parse_uint32_t; + functions->parse_int64_t = nbdkit_parse_int64_t; + functions->parse_uint64_t = nbdkit_parse_uint64_t; + functions->read_password = nbdkit_read_password; + functions->realpath = nbdkit_realpath; + functions->nanosleep = nbdkit_nanosleep; + functions->export_name = nbdkit_export_name; + functions->peer_name = dummy_peer_name; + functions->shutdown = nbdkit_shutdown; + functions->add_extent = nbdkit_add_extent; + functions->extents_new = nbdkit_extents_new; + functions->extents_free = nbdkit_extents_free; + functions->extents_count = nbdkit_extents_count; + functions->get_extent = nbdkit_get_extent; +} +#endif + int main (int argc, char *argv[]) { @@ -178,6 +222,9 @@ main (int argc, char *argv[]) perror ("expecting stdin/stdout to be opened"); exit (EXIT_FAILURE); } +#ifdef WINDOWS_COMPAT + init_functions (); +#endif #if !ENABLE_LIBFUZZER threadlocal_init (); @@ -772,6 +819,7 @@ open_plugin_so (size_t i, const char *name, int short_name) bool free_filename = false; void *dl; struct nbdkit_plugin *(*plugin_init) (void); + void *(*functions_init) (struct nbdkit_functions *); char *error; if (short_name) { @@ -797,6 +845,18 @@ open_plugin_so (size_t i, const char *name, int short_name) /* Initialize the plugin. See dlopen(3) to understand C weirdness. */ dlerror (); +#ifdef WINDOWS_COMPAT + *(void **) (&functions_init) = dlsym (dl, "functions_init"); + if ((error = dlerror ()) != NULL) { + fprintf (stderr, "%s: %s: %s\n", program_name, name, error); + exit (EXIT_FAILURE); + } + if (!functions_init) { + fprintf (stderr, "%s: %s: invalid functions_init\n", program_name, name); + exit (EXIT_FAILURE); + } + functions_init (functions); +#endif *(void **) (&plugin_init) = dlsym (dl, "plugin_init"); if ((error = dlerror ()) != NULL) { fprintf (stderr, "%s: %s: %s\n", program_name, name, error); @@ -825,6 +885,7 @@ open_filter_so (struct backend *next, size_t i, bool free_filename = false; void *dl; struct nbdkit_filter *(*filter_init) (void); + void *(*functions_init) (struct nbdkit_functions *); char *error; if (short_name) { @@ -846,6 +907,18 @@ open_filter_so (struct backend *next, size_t i, /* Initialize the filter. See dlopen(3) to understand C weirdness. */ dlerror (); +#ifdef WINDOWS_COMPAT + *(void **) (&functions_init) = dlsym (dl, "functions_init"); + if ((error = dlerror ()) != NULL) { + fprintf (stderr, "%s: %s: %s\n", program_name, name, error); + exit (EXIT_FAILURE); + } + if (!functions_init) { + fprintf (stderr, "%s: %s: invalid functions_init\n", program_name, name); + exit (EXIT_FAILURE); + } + functions_init (functions); +#endif *(void **) (&filter_init) = dlsym (dl, "filter_init"); if ((error = dlerror ()) != NULL) { fprintf (stderr, "%s: %s: %s\n", program_name, name, error); -- 2.25.0
Richard W.M. Jones
2020-Mar-23 12:28 UTC
[Libguestfs] [PATCH nbdkit 3/3] python: Remove extraneous static keyword
From: Yifan Gu <gyf304@gmail.com> The create_nbdkit_module function is intended to be exported, therefore the static keyword is not needed and prevents building on MSYS2. --- plugins/python/python.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/python/python.c b/plugins/python/python.c index a1a0438b..adc1aaa5 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c @@ -224,7 +224,7 @@ static struct PyModuleDef moduledef = { NULL }; -static PyMODINIT_FUNC +PyMODINIT_FUNC create_nbdkit_module (void) { PyObject *m; -- 2.25.0
Richard W.M. Jones
2020-Mar-23 12:48 UTC
Re: [Libguestfs] [PATCH nbdkit 1/3] include: Function indirection for PE DLL
On Mon, Mar 23, 2020 at 12:28:10PM +0000, Richard W.M. Jones wrote:> From: Yifan Gu <gyf304@gmail.com> > > This patch adds in indirection for API functions, as PE DLL loader > does not resolve undefined symbols. > > This patch only includes header changes. > --- > include/nbdkit-common.h | 133 +++++++++++++++++++++++++++++++++++++++- > include/nbdkit-compat.h | 97 +++++++++++++++++++++++++++++ > include/nbdkit-filter.h | 39 ++++++++++++ > include/nbdkit-plugin.h | 27 ++++++++ > include/Makefile.am | 1 + > 5 files changed, 295 insertions(+), 2 deletions(-) > > diff --git a/include/nbdkit-common.h b/include/nbdkit-common.h > index 9d1d89d0..57abc423 100644 > --- a/include/nbdkit-common.h > +++ b/include/nbdkit-common.h > @@ -40,10 +40,14 @@ > #include <stdarg.h> > #include <stdint.h> > #include <errno.h> > -#include <sys/socket.h> > > +#include <nbdkit-compat.h> > #include <nbdkit-version.h> > > +#if defined(NBDKIT_INTERNAL) || !defined(WINDOWS_COMPAT) > +#include <sys/socket.h> > +#endifThis should be #ifdef HAVE_SYS_SOCKET_H You'll need to add it to the list of headers in configure.ac AC_CHECK_HEADERS.> +#else > +static void nbdkit_error (const char *msg, ...) > + ATTRIBUTE_FORMAT_PRINTF (1, 2); > +static void nbdkit_error (const char *msg, ...) > +{ > + va_list args; > + va_start(args, msg); > + _nbdkit_functions.verror(msg, args);Note that it's not legal in C to prefix file-scope functions with ‘_’. So this should be just nbdkit_functions I think. But there's another problem with this struct which I'll come to.> diff --git a/include/nbdkit-compat.h b/include/nbdkit-compat.h > new file mode 100644 > index 00000000..a0a4cb69 > --- /dev/null > +++ b/include/nbdkit-compat.h > @@ -0,0 +1,97 @@ > +/* nbdkitAlthough it may not be visible in this email, in git this file contains CR-LF line endings. Needs to be LF only.> +#ifdef WINDOWS_COMPAT > +struct nbdkit_functions { > + void (*verror) (const char *msg, va_list args); > + void (*vdebug) (const char *msg, va_list args); > + char * (*absolute_path) (const char *path); > + int64_t (*parse_size) (const char *str); > + int (*parse_bool) (const char *str); > + int (*parse_int) (const char *what, const char *str, int *r); > + int (*parse_unsigned) (const char *what, const char *str, unsigned *r); > + int (*parse_int8_t) (const char *what, const char *str, int8_t *r); > + int (*parse_uint8_t) (const char *what, const char *str, uint8_t *r); > + int (*parse_int16_t) (const char *what, const char *str, int16_t *r); > + int (*parse_uint16_t) (const char *what, const char *str, uint16_t *r); > + int (*parse_int32_t) (const char *what, const char *str, int32_t *r); > + int (*parse_uint32_t) (const char *what, const char *str, uint32_t *r); > + int (*parse_int64_t) (const char *what, const char *str, int64_t *r); > + int (*parse_uint64_t) (const char *what, const char *str, uint64_t *r); > + int (*read_password) (const char *value, char **password); > + char * (*realpath) (const char *path); > + int (*nanosleep) (unsigned sec, unsigned nsec); > + const char * (*export_name) (void); > + int (*peer_name) (void *addr, void *addrlen); > + void (*shutdown) (void); > + > + struct nbdkit_extents *(*extents_new) (uint64_t start, uint64_t end); > + void (*extents_free) (struct nbdkit_extents *); > + size_t (*extents_count) (const struct nbdkit_extents *); > + struct nbdkit_extent (*get_extent) (const struct nbdkit_extents *, size_t); > + int (*add_extent) (struct nbdkit_extents *, uint64_t offset, uint64_t length, > + uint32_t type); > + > + void (*set_error) (int err); > +}; > + > +struct nbdkit_functions _nbdkit_functions;If I understand what's happening, the plugin has this struct, but it's essentially private to the plugin (why isn't it static?) The plugin also declares a functions_init public function which the server calls. Why did you define a new entry point for this instead of having a new function in the regular plugin/filter struct? Something that is called before load()? The bigger problem I foresee is what happens if you mix old/new plugin and old/new server versions and the contents of this struct changes? It's likely that the server should tell the plugin how large it thinks the struct is, so the plugin knows how much to copy and what fields to set to defaults. Rich. -- 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
Richard W.M. Jones
2020-Mar-23 12:48 UTC
Re: [Libguestfs] [PATCH nbdkit 2/3] server: Inject API functions for Windows
It seems as if patches 1 & 2 should be a single patch. 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
Richard W.M. Jones
2020-Mar-23 12:49 UTC
Re: [Libguestfs] [PATCH nbdkit 3/3] python: Remove extraneous static keyword
On Mon, Mar 23, 2020 at 12:28:12PM +0000, Richard W.M. Jones wrote:> From: Yifan Gu <gyf304@gmail.com> > > The create_nbdkit_module function is intended to be exported, therefore > the static keyword is not needed and prevents building on MSYS2. > --- > plugins/python/python.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/plugins/python/python.c b/plugins/python/python.c > index a1a0438b..adc1aaa5 100644 > --- a/plugins/python/python.c > +++ b/plugins/python/python.c > @@ -224,7 +224,7 @@ static struct PyModuleDef moduledef = { > NULL > }; > > -static PyMODINIT_FUNC > +PyMODINIT_FUNC > create_nbdkit_module (void) > { > PyObject *m; > --I don't believe this is correct. We call PyImport_AppendInittab ("nbdkit", create_nbdkit_module); later on so the function shouldn't need to public. What's the actual error when compiling this? 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
Apparently Analagous Threads
- Re: [PATCH nbdkit 3/3] python: Remove extraneous static keyword
- [PATCH nbdkit 3/3] python: Remove extraneous static keyword
- [PATCH nbdkit 0/3] msys2 support for review
- issue when building/making package from git
- [PATCH nbdkit] python: Drop support for Python 2.