# HG changeset patch # User Paul Boddie # Date 1623019814 -7200 # Node ID adaea9880cce8c0849dfdf0a9d3a8e2432dfc2b4 # Parent 50c9aa47c6ad6c9a262d589de3bb74a2b0d8f9b5 Introduced notification flags for blocking file/pipe access operations. diff -r 50c9aa47c6ad -r adaea9880cce libfsclient/include/fsclient/client.h --- a/libfsclient/include/fsclient/client.h Thu May 20 00:01:53 2021 +0200 +++ b/libfsclient/include/fsclient/client.h Mon Jun 07 00:50:14 2021 +0200 @@ -56,7 +56,7 @@ /* Notification operations. */ -long client_set_blocking(file_t *file, int can_block); +long client_set_blocking(file_t *file, notify_flags_t flags); long client_subscribe(file_t *file, notify_flags_t flags); long client_unsubscribe(file_t *file); long client_wait(file_t *file); diff -r 50c9aa47c6ad -r adaea9880cce libfsclient/include/fsclient/file.h --- a/libfsclient/include/fsclient/file.h Thu May 20 00:01:53 2021 +0200 +++ b/libfsclient/include/fsclient/file.h Mon Jun 07 00:50:14 2021 +0200 @@ -65,7 +65,7 @@ /* Blocking accesses. */ - int can_block; + notify_flags_t can_block; } file_t; diff -r 50c9aa47c6ad -r adaea9880cce libfsclient/lib/src/client.cc --- a/libfsclient/lib/src/client.cc Thu May 20 00:01:53 2021 +0200 +++ b/libfsclient/lib/src/client.cc Mon Jun 07 00:50:14 2021 +0200 @@ -399,24 +399,24 @@ /* Set or unset blocking access for a file. */ -long client_set_blocking(file_t *file, int can_block) +long client_set_blocking(file_t *file, notify_flags_t flags) { long err; - if (file->can_block == can_block) + if (file->can_block == flags) return L4_EOK; // NOTE: Set appropriate flags. - if (can_block) - err = client_subscribe(file, 0); + if (flags) + err = client_subscribe(file, flags); else err = client_unsubscribe(file); if (err) return err; - file->can_block = can_block; + file->can_block = flags; return L4_EOK; } diff -r 50c9aa47c6ad -r adaea9880cce libfsserver/include/fsserver/pipe_paging.h --- a/libfsserver/include/fsserver/pipe_paging.h Thu May 20 00:01:53 2021 +0200 +++ b/libfsserver/include/fsserver/pipe_paging.h Mon Jun 07 00:50:14 2021 +0200 @@ -57,6 +57,7 @@ /* Notification IRQs. */ l4_cap_idx_t _irqs[2]; + notify_flags_t _flags[2]; /* Common functionality. */ @@ -72,9 +73,9 @@ /* Notification support. */ - virtual void notify(bool writing); + virtual void notify(bool writing, notify_flags_t flags); - virtual l4_cap_idx_t subscribe(bool writing); + virtual l4_cap_idx_t subscribe(bool writing, notify_flags_t flags); virtual void unsubscribe(bool writing); diff -r 50c9aa47c6ad -r adaea9880cce libfsserver/lib/pipes/pipe_pager.cc --- a/libfsserver/lib/pipes/pipe_pager.cc Thu May 20 00:01:53 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_pager.cc Mon Jun 07 00:50:14 2021 +0200 @@ -58,7 +58,7 @@ /* Notify the other endpoint. */ - _paging->notify(_writing); + _paging->notify(_writing, NOTIFY_PEER_CLOSED); } /* Support paging. */ @@ -154,7 +154,9 @@ *size = _size; - _paging->notify(_writing); + // NOTE: Perhaps employ a distinct event type for metadata updates. + + _paging->notify(_writing, NOTIFY_CONTENT_AVAILABLE | NOTIFY_SPACE_AVAILABLE); return L4_EOK; } @@ -164,11 +166,10 @@ long PipePager::subscribe(notify_flags_t flags, l4_cap_idx_t *irq) { - // NOTE: Need to interpret flags. - // NOTE: Readers can subscribe to new data (at end), and pipe closed events. - // NOTE: Writers can subscribe to new space and pipe closed events. + /* Readers can subscribe to new data (at end), and pipe closed events. + Writers can subscribe to new space and pipe closed events. */ - *irq = _paging->subscribe(_writing); + *irq = _paging->subscribe(_writing, flags); return L4_EOK; } diff -r 50c9aa47c6ad -r adaea9880cce libfsserver/lib/pipes/pipe_paging.cc --- a/libfsserver/lib/pipes/pipe_paging.cc Thu May 20 00:01:53 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_paging.cc Mon Jun 07 00:50:14 2021 +0200 @@ -44,21 +44,26 @@ for (unsigned int i = 0; i < 2; i++) _regions[i] = NULL; - /* Initialise IRQ objects for notifications. */ + /* Initialise IRQ objects and flags for notifications. */ for (unsigned int i = 0; i < 2; i++) + { _irqs[i] = L4_INVALID_CAP; + _flags[i] = 0; + } } /* Create an IRQ to subscribe to an endpoint's notifications. */ -l4_cap_idx_t PipePaging::subscribe(bool writing) +l4_cap_idx_t PipePaging::subscribe(bool writing, notify_flags_t flags) { int i = writing ? 1 : 0; if (l4_is_invalid_cap(_irqs[i])) ipc_create_irq(&_irqs[i]); + _flags[i] = flags; + return _irqs[i]; } @@ -72,18 +77,19 @@ { ipc_cap_free_um(_irqs[i]); _irqs[i] = L4_INVALID_CAP; + _flags[i] = 0; } } /* Notify the other endpoint. */ -void PipePaging::notify(bool writing) +void PipePaging::notify(bool writing, notify_flags_t flags) { /* Let the writer notify the reader, and the other way round. */ int i = writing ? 0 : 1; - if (l4_is_valid_cap(_irqs[i])) + if (l4_is_valid_cap(_irqs[i]) && (flags & _flags[i])) l4_irq_trigger(_irqs[i]); } @@ -170,7 +176,7 @@ /* Let the writer notify the reader. */ - notify(true); + notify(true, NOTIFY_CONTENT_AVAILABLE); /* Return the next region's mapper. */ @@ -205,7 +211,7 @@ /* Let the reader notify the writer. */ - notify(false); + notify(false, NOTIFY_SPACE_AVAILABLE); /* Return the next region's mapper. */ diff -r 50c9aa47c6ad -r adaea9880cce tests/dstest_pipe_client.cc --- a/tests/dstest_pipe_client.cc Thu May 20 00:01:53 2021 +0200 +++ b/tests/dstest_pipe_client.cc Mon Jun 07 00:50:14 2021 +0200 @@ -106,7 +106,8 @@ /* Make the reader and writer blocking to permit synchronisation. */ - if ((err = client_set_blocking(&reader, true)) || (err = client_set_blocking(&writer, true))) + if ((err = client_set_blocking(&reader, NOTIFY_CONTENT_AVAILABLE)) || + (err = client_set_blocking(&writer, NOTIFY_SPACE_AVAILABLE))) { printf("Could not set as blocking: %s\n", l4sys_errtostr(err)); return 1;