search for: finished_read

Displaying 20 results from an estimated 27 matches for "finished_read".

2019 Jul 30
0
[PATCH libnbd] examples: Fix theoretical cookie race in example.
...= g_new (char, BUFFER_SIZE); @@ -385,11 +384,9 @@ read_data (gpointer user_data) nr_buffers++; posn += BUFFER_SIZE; - buffers[i].rcookie = - nbd_aio_pread_callback (gssrc->nbd, buffers[i].data, - BUFFER_SIZE, buffers[i].offset, - finished_read, NULL, 0); - if (buffers[i].rcookie == -1) { + if (nbd_aio_pread_callback (gssrc->nbd, buffers[i].data, + BUFFER_SIZE, buffers[i].offset, + finished_read, &buffers[i], 0) == -1) { fprintf (stderr, "%s\n", nbd_get_erro...
2019 Jul 30
4
[PATCH libnbd] examples: Fix theoretical cookie race in example.
Previously discussed here: https://www.redhat.com/archives/libguestfs/2019-July/msg00213.html It turns out that deferring callbacks is a PITA. (It would be a bit easier if C has closures.) However by rewriting the example we can avoid the need to use the cookie at all and make it run a bit more efficiently, so let's do that instead. Rich.
2019 Jul 17
1
Re: [PATCH libnbd] examples: Include an example of integrating with the glib main loop.
...t; +static struct buffer buffers[MAX_BUFFERS]; > +static size_t nr_buffers; > + > +static bool finished, reader_paused; > + > +static GMainLoop *loop; > + > +static void connected (struct NBDSource *source); > +static gboolean read_data (gpointer user_data); > +static int finished_read (void *vp, int64_t cookie, int *error); > +static gboolean write_data (gpointer user_data); > +static int finished_write (void *vp, int64_t cookie, int *error); > + > +int > +main (int argc, char *argv[]) > +{ > + struct nbd_handle *src, *dest; > + GMainContext *loopctx =...
2019 Jul 17
2
[PATCH libnbd v2] examples: Include an example of integrating with glib main loop.
This is working now, and incorporates all of the changes in Eric's review, *except* that it still doesn't retire commands (although this seems to make no obvious difference, except possibly a performance and memory impact). Rich.
2019 Jul 17
2
Re: [PATCH libnbd v2] examples: Include an example of integrating with the glib main loop.
...*/ > +static gboolean > +read_data (gpointer user_data) > +{ > + static uint64_t posn = 0; > + buffers[i].rcookie = > + nbd_aio_pread_callback (gssrc->nbd, buffers[i].data, > + BUFFER_SIZE, buffers[i].offset, > + finished_read, NULL, 0); It may be possible in rare situations that the libnbd state machine can send() the command AND see data ready to recv() (perhaps from a previous command still in flight), where it ends up read()ing until blocking and happens to get the server's reply to this command and fire off the...
2019 Jul 15
2
[PATCH libnbd] examples: Include an example of integrating with the glibc main loop.
** NOT WORKING ** This patch shows how to integrate libnbd and the glib main loop. Posted mainly as a point of discussion as it doesn't quite work yet. Rich.
2019 Aug 14
2
Re: [PATCH libnbd 1/4] api: Combine callback and user_data into a single struct.
...ven longer to type. I can live with this conversion. > +++ b/examples/glib-main-loop.c > @@ -384,7 +384,8 @@ read_data (gpointer user_data) > > if (nbd_aio_pread (gssrc->nbd, buffers[i].data, > BUFFER_SIZE, buffers[i].offset, > - finished_read, &buffers[i], 0) == -1) { > + (nbd_completion_callback) { .callback = finished_read, .user_data = &buffers[i] }, > + 0) == -1) { > fprintf (stderr, "%s\n", nbd_get_error ()); > exit (EXIT_FAILURE); > } > @@ -42...
2019 Aug 14
1
Re: [PATCH libnbd 1/4] api: Combine callback and user_data into a single struct.
...(nbd_completion_callback) { .callback = finished_write, .user_data = buffer }, >> >> Worth splitting the long lines? > > It's tricky to format these. Even after splitting the line they still > go over 7x chars. Would it ease typing if we added a macro: NBD_COMPLETION (finished_read, &buffers[i]) although that gets trickier when we add an optional free callback (C already allows initializers with 1, 2, or 3 members set, but writing a variable-argument macro to do the same gets rather hairy - it can be done with the help of intermediate macros, but that's a lot to cram...
2019 Jul 15
0
[PATCH libnbd] examples: Include an example of integrating with the glib main loop.
...enum buffer_state state; + char *data; +}; + +static struct buffer buffers[MAX_BUFFERS]; +static size_t nr_buffers; + +static bool finished, reader_paused; + +static GMainLoop *loop; + +static void connected (struct NBDSource *source); +static gboolean read_data (gpointer user_data); +static int finished_read (void *vp, int64_t cookie, int *error); +static gboolean write_data (gpointer user_data); +static int finished_write (void *vp, int64_t cookie, int *error); + +int +main (int argc, char *argv[]) +{ + struct nbd_handle *src, *dest; + GMainContext *loopctx = NULL; + + /* Create the main loop. */ +...
2019 Jul 17
0
[PATCH libnbd v2] examples: Include an example of integrating with the glib main loop.
...enum buffer_state state; + char *data; +}; + +static struct buffer buffers[MAX_BUFFERS]; +static size_t nr_buffers; + +static bool finished, reader_paused; + +static GMainLoop *loop; + +static void connected (struct NBDSource *source); +static gboolean read_data (gpointer user_data); +static int finished_read (void *vp, int64_t rcookie, int *error); +static gboolean write_data (gpointer user_data); +static int finished_write (void *vp, int64_t wcookie, int *error); + +int +main (int argc, char *argv[]) +{ + struct nbd_handle *src, *dest; + GMainContext *loopctx = NULL; + + /* Create the main loop. */...
2019 Aug 14
0
Re: [PATCH libnbd 1/4] api: Combine callback and user_data into a single struct.
...ieve it's possible. > > +++ b/examples/glib-main-loop.c > > @@ -384,7 +384,8 @@ read_data (gpointer user_data) > > > > if (nbd_aio_pread (gssrc->nbd, buffers[i].data, > > BUFFER_SIZE, buffers[i].offset, > > - finished_read, &buffers[i], 0) == -1) { > > + (nbd_completion_callback) { .callback = finished_read, .user_data = &buffers[i] }, > > + 0) == -1) { > > fprintf (stderr, "%s\n", nbd_get_error ()); > > exit (EXIT_FAILURE); &...
2019 Jul 30
3
[PATCH libnbd] lib: Remove cookie parameter from completion callbacks.
...s/glib-main-loop.c b/examples/glib-main-loop.c index 826651e..05a59e3 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -268,11 +268,9 @@ static GMainLoop *loop; static void connected (struct NBDSource *source); static gboolean read_data (gpointer user_data); -static int finished_read (unsigned valid_flag, void *vp, - int64_t rcookie, int *error); +static int finished_read (unsigned valid_flag, void *vp, int *error); static gboolean write_data (gpointer user_data); -static int finished_write (unsigned valid_flag, void *vp, - in...
2019 Jul 17
0
Re: [PATCH libnbd v2] examples: Include an example of integrating with the glib main loop.
...> callback, all prior to the nbd_aio_pread_callback() returning. If that > ever happens, then buffers[i].rcookie will still be unset at the time > the callback fires... > >> +/* This callback is called from libnbd when any read command finishes. */ >> +static int >> +finished_read (void *vp, int64_t rcookie, int *error) >> +{ >> + size_t i; >> + >> + if (gssrc == NULL) >> + return 0; >> + >> + DEBUG (gssrc, "finished_read: read completed"); >> + >> + /* Find the corresponding buffer and mark it as complet...
2019 Aug 12
0
[PATCH libnbd 7/7] api: Remove the valid_flag from all callbacks.
...es/glib-main-loop.c b/examples/glib-main-loop.c index 05a59e3..216eb5e 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -268,9 +268,9 @@ static GMainLoop *loop; static void connected (struct NBDSource *source); static gboolean read_data (gpointer user_data); -static int finished_read (unsigned valid_flag, void *vp, int *error); +static int finished_read (void *vp, int *error); static gboolean write_data (gpointer user_data); -static int finished_write (unsigned valid_flag, void *vp, int *error); +static int finished_write (void *vp, int *error); int main (int argc, char *a...
2019 Jul 24
0
[PATCH libnbd 2/3] lib: Implement closure lifetimes.
...s/glib-main-loop.c b/examples/glib-main-loop.c index c633c1d..9d61923 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -272,9 +272,11 @@ static GMainLoop *loop; static void connected (struct NBDSource *source); static gboolean read_data (gpointer user_data); -static int finished_read (void *vp, int64_t rcookie, int *error); +static int finished_read (int valid_flag, void *vp, + int64_t rcookie, int *error); static gboolean write_data (gpointer user_data); -static int finished_write (void *vp, int64_t wcookie, int *error); +static int finished_write (in...
2019 Aug 13
0
[PATCH libnbd 2/4] api: Add free function and remove valid_flag parameter.
...es/glib-main-loop.c b/examples/glib-main-loop.c index a8e8ceb..9c279d3 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -268,9 +268,9 @@ static GMainLoop *loop; static void connected (struct NBDSource *source); static gboolean read_data (gpointer user_data); -static int finished_read (unsigned valid_flag, void *vp, int *error); +static int finished_read (void *vp, int *error); static gboolean write_data (gpointer user_data); -static int finished_write (unsigned valid_flag, void *vp, int *error); +static int finished_write (void *vp, int *error); int main (int argc, char *a...
2019 Jul 24
0
[PATCH libnbd v2 2/5] lib: Implement closure lifetimes.
...s/glib-main-loop.c b/examples/glib-main-loop.c index c633c1d..b7c496f 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -272,9 +272,11 @@ static GMainLoop *loop; static void connected (struct NBDSource *source); static gboolean read_data (gpointer user_data); -static int finished_read (void *vp, int64_t rcookie, int *error); +static int finished_read (unsigned valid_flag, void *vp, + int64_t rcookie, int *error); static gboolean write_data (gpointer user_data); -static int finished_write (void *vp, int64_t wcookie, int *error); +static int finished_writ...
2019 Jul 25
0
[PATCH libnbd v3 1/2] lib: Implement closure lifetimes.
...s/glib-main-loop.c b/examples/glib-main-loop.c index 2230077..2d192e6 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -274,9 +274,11 @@ static GMainLoop *loop; static void connected (struct NBDSource *source); static gboolean read_data (gpointer user_data); -static int finished_read (void *vp, int64_t rcookie, int *error); +static int finished_read (unsigned valid_flag, void *vp, + int64_t rcookie, int *error); static gboolean write_data (gpointer user_data); -static int finished_write (void *vp, int64_t wcookie, int *error); +static int finished_writ...
2019 Aug 13
8
[PATCH libnbd 0/4] Add free function to callbacks.
Patches 1 & 2 are rather complex, but the end result is that we pass closures + user_data + free function in single struct parameters as I described previously in this email: https://www.redhat.com/archives/libguestfs/2019-August/msg00210.html Patch 3 adds a convenient FREE_CALLBACK macro which seems a worthwhile simplification if you buy into 1 & 2. Patch 4 adds another macro which is
2019 Jul 25
4
[PATCH libnbd v3 0/2] lib: Implement closure lifetimes.
I think I've addressed everything that was raised in review. Some of the highlights: - Callbacks should be freed reliably along all exit paths. - There's a simple test of closure lifetimes. - I've tried to use VALID|FREE in all the places where I'm confident that it's safe and correct to do. There may be more places. Note this is an optimization and shouldn't