search for: nbdkit_handle_not_needed

Displaying 20 results from an estimated 53 matches for "nbdkit_handle_not_needed".

2019 Jan 01
0
[PATCH nbdkit] plugins, filters: Define and use NBDKIT_HANDLE_NOT_NEEDED.
A common idiom where we don't need a per-connection handle is: static void * myplugin_open (int readonly) { static int handle; return &handle; } We need to return some non-NULL value, but we don't care what. This commit defines a macro NBDKIT_HANDLE_NOT_NEEDED which contains a meaningless non-NULL pointer which can be used instead of the above. This is more descriptive than the previous code. --- docs/nbdkit-filter.pod | 3 ++- docs/nbdkit-plugin.pod | 3 ++- include/nbdkit-common.h | 5 +++++ filters/cache/cache.c...
2019 Jan 18
2
Re: [PATCH nbdkit 1/2] include: Fix NBDKIT_HANDLE_NOT_NEEDED for C90 compilers.
On 1/14/19 6:15 AM, Richard W.M. Jones wrote: > When an ANSI/C90 plugin compiled with ‘-pedantic’ uses > NBDKIT_HANDLE_NOT_NEEDED it gets the error: > > ISO C forbids conversion of function pointer to object pointer type While POSIX requires it to work. But such is life. > > This is because the existing macro worked by returning a function > pointer but in C90 function pointers cannot be cast to data poin...
2019 Jan 14
0
[PATCH nbdkit 1/2] include: Fix NBDKIT_HANDLE_NOT_NEEDED for C90 compilers.
When an ANSI/C90 plugin compiled with ‘-pedantic’ uses NBDKIT_HANDLE_NOT_NEEDED it gets the error: ISO C forbids conversion of function pointer to object pointer type This is because the existing macro worked by returning a function pointer but in C90 function pointers cannot be cast to data pointers since on some ancient architectures code and data pointers were incompati...
2019 Jan 18
0
Re: [PATCH nbdkit 1/2] include: Fix NBDKIT_HANDLE_NOT_NEEDED for C90 compilers.
On Fri, Jan 18, 2019 at 08:36:07AM -0600, Eric Blake wrote: > On 1/14/19 6:15 AM, Richard W.M. Jones wrote: > > When an ANSI/C90 plugin compiled with ‘-pedantic’ uses > > NBDKIT_HANDLE_NOT_NEEDED it gets the error: > > > > ISO C forbids conversion of function pointer to object pointer type > > While POSIX requires it to work. But such is life. > > > > > This is because the existing macro worked by returning a function > > pointer but in C90 funct...
2019 Jan 18
1
Re: [PATCH nbdkit 1/2] include: Fix NBDKIT_HANDLE_NOT_NEEDED for C90 compilers.
On 1/18/19 8:47 AM, Richard W.M. Jones wrote: > On Fri, Jan 18, 2019 at 08:36:07AM -0600, Eric Blake wrote: >> On 1/14/19 6:15 AM, Richard W.M. Jones wrote: >>> When an ANSI/C90 plugin compiled with ‘-pedantic’ uses >>> NBDKIT_HANDLE_NOT_NEEDED it gets the error: >>> >>> ISO C forbids conversion of function pointer to object pointer type >> >> While POSIX requires it to work. But such is life. >> >>> >>> This is because the existing macro worked by returning a function >>> p...
2019 Jan 14
4
[PATCH nbdkit 0/2] tests: Test that public headers are ANSI (ISO C90) compatible.
We previously discussed allowing the plugin API to be consumed by non-GCC/non-Clang/old compilers. This implements a test. Rich.
2019 Apr 27
0
[nbdkit PATCH 1/4] filters: Drop useless .open callbacks
...++ b/filters/cache/cache.c @@ -186,15 +186,6 @@ cache_config_complete (nbdkit_next_config_complete *next, void *nxdata) return next (nxdata); } -static void * -cache_open (nbdkit_next_open *next, void *nxdata, int readonly) -{ - if (next (nxdata, readonly) == -1) - return NULL; - - return NBDKIT_HANDLE_NOT_NEEDED; -} - /* Get the file size and ensure the cache is the correct size. */ static int64_t cache_get_size (struct nbdkit_next_ops *next_ops, void *nxdata, @@ -476,7 +467,6 @@ static struct nbdkit_filter filter = { .unload = cache_unload, .config = cache_config, .config...
2020 Mar 26
1
Re: [PATCH nbdkit 6/9] tests: Add a regression test that we can still compile with -undefined.
...ore like a true out-of-tree plugin that did not opt-in to our library? > +#include <stdio.h> > +#include <stdlib.h> > +#include <string.h> > + > +#include <nbdkit-plugin.h> > + > +static void * > +undefined_open (int readonly) > +{ > + return NBDKIT_HANDLE_NOT_NEEDED; Hmm. I don't see any _use_ of an nbdkit_* function here. It's not enough that this library links without libnbdkit.so, but we need to be testing that when it uses an undefined symbol, such a symbol actually gets provided via the nbdkit binary dlopen()ing this plugin. > +static st...
2019 Sep 18
1
[nbdkit PATCH] server: Saner filter .close calls
...readonly) if (handle == NULL) return -1; backend_set_handle (b, conn, handle); - return 0; } - else - return backend_open (b->next, conn, readonly); + else { + if (backend_open (b->next, conn, readonly) == -1) + return -1; + backend_set_handle (b, conn, NBDKIT_HANDLE_NOT_NEEDED); + } + return 0; } static void @@ -224,8 +227,9 @@ filter_close (struct backend *b, struct connection *conn) debug ("%s: close", b->name); - if (f->filter.close) + if (handle && f->filter.close) f->filter.close (handle); + backend_set_handle (b, conn...
2020 Apr 09
2
Re: [PATCH nbdkit v2 2/3] iso: Implement this plugin using fileops (read-only).
...plugins/iso/Makefile.am | 4 +- > plugins/iso/iso.c | 99 +++++++++++++++++++---------------------- > 2 files changed, 48 insertions(+), 55 deletions(-) > > @@ -193,25 +195,43 @@ iso_get_ready (void) > static void * > iso_open (int readonly) > { > - return NBDKIT_HANDLE_NOT_NEEDED; > + struct fileops *fops; > + int fd; > + > + fops = malloc (sizeof *fops); > + if (fops == NULL) { > + nbdkit_error ("malloc: %m"); > + return NULL; > + } > + > + /* Copy the fd because fileops needs to have its own file descriptor. */ > + f...
2020 Apr 09
0
[PATCH nbdkit v2 2/3] iso: Implement this plugin using fileops (read-only).
...;memstream failed: %m"); @@ -128,8 +130,8 @@ iso_unload (void) free (dirs[i]); free (dirs); - if (fd >= 0) - close (fd); + if (iso_fd >= 0) + close (iso_fd); } static int @@ -193,25 +195,43 @@ iso_get_ready (void) static void * iso_open (int readonly) { - return NBDKIT_HANDLE_NOT_NEEDED; + struct fileops *fops; + int fd; + + fops = malloc (sizeof *fops); + if (fops == NULL) { + nbdkit_error ("malloc: %m"); + return NULL; + } + + /* Copy the fd because fileops needs to have its own file descriptor. */ + fd = dup (iso_fd); + if (fd == -1) { + nbdkit_error...
2020 Feb 11
1
[nbdkit PATCH] filters: Make nxdata persistent
...*/ if (f->filter.open) - return f->filter.open (next_open, &nxdata, readonly); + nxdata->handle = f->filter.open (next_open, nxdata, readonly); else if (backend_open (b->next, conn, readonly) == -1) - return NULL; + nxdata->handle = NULL; else - return NBDKIT_HANDLE_NOT_NEEDED; + nxdata->handle = NBDKIT_HANDLE_NOT_NEEDED; + if (nxdata->handle == NULL) { + free (nxdata); + return NULL; + } + return nxdata; } static void filter_close (struct backend *b, struct connection *conn, void *handle) { struct backend_filter *f = container_of (b, struct bac...
2020 Feb 12
0
[PATCH nbdkit 3/3] server: filters: Remove struct b_h.
...(f->filter.open) - nxdata->handle = f->filter.open (next_open, nxdata, readonly); + handle = f->filter.open (next_open, b->next, readonly); else if (backend_open (b->next, readonly) == -1) - nxdata->handle = NULL; + handle = NULL; else - nxdata->handle = NBDKIT_HANDLE_NOT_NEEDED; - if (nxdata->handle == NULL) { - free (nxdata); - return NULL; - } - return nxdata; + handle = NBDKIT_HANDLE_NOT_NEEDED; + return handle; } static void filter_close (struct backend *b, void *handle) { struct backend_filter *f = container_of (b, struct backend_filter, back...
2019 Apr 27
8
[nbdkit PATCH 0/4] Fix truncate handling of real_size
While working on adding assertions to pthread_mutex_lock calls, I noticed that the truncate filter's use of mutex didn't really protect us, and isn't really necessary. Cleaning that up also spotted a couple of other potential cleanups. Eric Blake (4): filters: Drop useless .open callbacks truncate: Fix corruption when plugin changes per-connection size truncate: Test for safe
2020 Mar 06
1
Re: [PATCH nbdkit v2] New filter: limit: Limit number of clients that can connect.
...use clients can artificially slow down > + * the NBD negotiation in order to bypass the limit otherwise. > + */ > + if (limit > 0 && connections >= limit) { > + too_many_clients_error (); > + return NULL; > + } > + > + connections++; > + return NBDKIT_HANDLE_NOT_NEEDED; > +} > + > +static void > +limit_close (void *handle) > +{ > + ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&lock); > + connections--; > +} Overall looks good. As you say, we may want to enhance nbdkit with a way to enforce that a client complete handshake within a given time...
2020 Mar 04
7
[PATCH nbdkit 0/4] server: Add nbdkit_shutdown() call and two new filters.
This adds a new nbdkit_shutdown() API whereby plugins and filters can request that the server shuts down (asynchronously) during the serving phase. Two new filters are added, one of which depends on this feature and the other not needing it but being somewhat related. Rich.
2020 Mar 26
0
[PATCH nbdkit 6/9] tests: Add a regression test that we can still compile with -undefined.
...* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <nbdkit-plugin.h> + +static void * +undefined_open (int readonly) +{ + return NBDKIT_HANDLE_NOT_NEEDED; +} + +static int64_t +undefined_get_size (void *handle) +{ + return 0; +} + +#define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL + +static int +undefined_pread (void *handle, void *buf, uint32_t count, uint64_t offset) +{ + memset (buf, 0, count); + return 0; +} + +static struct nbdkit_plugin plu...
2020 Mar 04
2
[PATCH nbdkit v2] New filter: limit: Limit number of clients that can connect.
This is a second version of the limit filter. v1 was posted here: https://www.redhat.com/archives/libguestfs/2020-March/msg00015.html I didn't bother to repost the other three patches because they are the same. The difference is this version of the filter takes security more seriously. It shouldn't be possible for malicious clients to connect more than limit=N times to the plugin now,
2020 Feb 16
0
[nbdkit PATCH v4 2/4] tests: Add coverage of new nbdkit_set_dlopen_prefix
...has_a_library_by_this_name", RTLD_NOW); + msg = dlerror (); + assert (msg); + nbdkit_error ("dlopen failed as expected: %s\n", msg); + + return 0; +} + +/* These must be provided, but we don't really need to use them. */ +static void * +dlopen_open (int readonly) +{ + return NBDKIT_HANDLE_NOT_NEEDED; +} + +static int64_t +dlopen_get_size (void *handle) +{ + return 0; +} + +static int +dlopen_pread (void *handle, void *buf, uint32_t count, uint64_t offset) +{ + assert (false); +} + +static struct nbdkit_plugin plugin = { + .name = "dlopenplugin", + .version...
2019 May 16
0
[nbdkit PATCH 2/2] cache, cow: Round size down
...rs/cow/cow.c @@ -49,6 +49,7 @@ #include "blk.h" #include "isaligned.h" #include "minmax.h" +#include "rounding.h" #define THREAD_MODEL NBDKIT_THREAD_MODEL_PARALLEL @@ -80,7 +81,9 @@ cow_open (nbdkit_next_open *next, void *nxdata, int readonly) return NBDKIT_HANDLE_NOT_NEEDED; } -/* Get the file size and ensure the overlay is the correct size. */ +/* Get the file size; round it down to overlay granularity before + * setting overlay size. + */ static int64_t cow_get_size (struct nbdkit_next_ops *next_ops, void *nxdata, void *handle) @@ -93,6 +96,7 @@ c...