1.1 --- a/libfsclient/include/fsclient/notifier.h Mon Mar 14 01:33:25 2022 +0100
1.2 +++ b/libfsclient/include/fsclient/notifier.h Mon Mar 14 17:44:41 2022 +0100
1.3 @@ -49,10 +49,6 @@
1.4
1.5 l4_cap_idx_t endpoint = L4_INVALID_CAP;
1.6
1.7 - /* Server endpoint for unsubscribing. */
1.8 -
1.9 - l4_cap_idx_t peer = L4_INVALID_CAP;
1.10 -
1.11 bool is_null() { return l4_is_invalid_cap(endpoint); }
1.12 };
1.13
2.1 --- a/libfsclient/lib/src/Makefile Mon Mar 14 01:33:25 2022 +0100
2.2 +++ b/libfsclient/lib/src/Makefile Mon Mar 14 17:44:41 2022 +0100
2.3 @@ -16,7 +16,7 @@
2.4 # Individual interfaces.
2.5
2.6 CLIENT_INTERFACES_CC = dataspace directory file filesystem flush \
2.7 - mapped_file notification notifier_peer opener \
2.8 + mapped_file notification opener \
2.9 opener_context pipe pipe_opener
2.10
2.11 # Generated and plain source files.
3.1 --- a/libfsclient/lib/src/notifier.cc Mon Mar 14 01:33:25 2022 +0100
3.2 +++ b/libfsclient/lib/src/notifier.cc Mon Mar 14 17:44:41 2022 +0100
3.3 @@ -30,7 +30,6 @@
3.4
3.5 #include "notification_client.h"
3.6 #include "notifier.h"
3.7 -#include "notifier_peer_client.h"
3.8
3.9
3.10
3.11 @@ -205,12 +204,11 @@
3.12 return err;
3.13 }
3.14
3.15 - /* Subscribe, sending the notification endpoint and obtaining a peer endpoint
3.16 - for unsubscribing. */
3.17 + /* Subscribe, sending the notification endpoint. */
3.18
3.19 client_Notification notify(file->ref);
3.20
3.21 - err = notify.subscribe(state.endpoint, flags, &state.peer);
3.22 + err = notify.subscribe(state.endpoint, flags);
3.23
3.24 if (err)
3.25 {
3.26 @@ -235,14 +233,13 @@
3.27 if (state.is_null())
3.28 return -L4_EINVAL;
3.29
3.30 - /* Unsubscribe via the peer endpoint. */
3.31 + /* Unsubscribe via the notification interface. */
3.32
3.33 - client_NotifierPeer peer(state.peer);
3.34 + client_Notification notify(file->ref);
3.35
3.36 - peer.unsubscribe();
3.37 + notify.unsubscribe();
3.38
3.39 ipc_cap_free_um(state.endpoint);
3.40 - ipc_cap_free_um(state.peer);
3.41
3.42 _state.erase(file);
3.43
4.1 --- a/libfsserver/include/fsserver/directory_resource.h Mon Mar 14 01:33:25 2022 +0100
4.2 +++ b/libfsserver/include/fsserver/directory_resource.h Mon Mar 14 17:44:41 2022 +0100
4.3 @@ -63,8 +63,9 @@
4.4
4.5 /* Notification methods. */
4.6
4.7 - virtual long subscribe(l4_cap_idx_t endpoint, notify_flags_t flags,
4.8 - l4_cap_idx_t *peer);
4.9 + virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags);
4.10 +
4.11 + virtual long unsubscribe();
4.12 };
4.13
4.14 // vim: tabstop=4 expandtab shiftwidth=4
5.1 --- a/libfsserver/include/fsserver/file_pager.h Mon Mar 14 01:33:25 2022 +0100
5.2 +++ b/libfsserver/include/fsserver/file_pager.h Mon Mar 14 17:44:41 2022 +0100
5.3 @@ -74,8 +74,9 @@
5.4
5.5 /* Notification methods. */
5.6
5.7 - virtual long subscribe(l4_cap_idx_t endpoint, notify_flags_t flags,
5.8 - l4_cap_idx_t *peer);
5.9 + virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags);
5.10 +
5.11 + virtual long unsubscribe();
5.12 };
5.13
5.14 // vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/libfsserver/include/fsserver/notification.h Mon Mar 14 01:33:25 2022 +0100
6.2 +++ b/libfsserver/include/fsserver/notification.h Mon Mar 14 17:44:41 2022 +0100
6.3 @@ -37,7 +37,7 @@
6.4 /* Collection data types. */
6.5
6.6 typedef std::set<l4_cap_idx_t> NotifierSet;
6.7 -typedef std::map<l4_cap_idx_t, NotifierPeerEndpoint *> NotifierPeerMap;
6.8 +typedef std::map<void *, l4_cap_idx_t> SubscriberNotifierMap;
6.9
6.10 /* Notification endpoint details. */
6.11
6.12 @@ -68,9 +68,9 @@
6.13
6.14 NotificationEndpointList _endpoints;
6.15
6.16 - /* Notifier peer details. */
6.17 + /* Notifier subscriber details. */
6.18
6.19 - NotifierPeerMap _peers;
6.20 + SubscriberNotifierMap _subscribers;
6.21
6.22 /* Deferred notifications for new endpoints. */
6.23
6.24 @@ -81,9 +81,9 @@
6.25 virtual void _notify(unsigned int endpoint, notify_flags_t flags);
6.26
6.27 virtual long _subscribe(unsigned int endpoint, l4_cap_idx_t notifier,
6.28 - notify_flags_t flags, l4_cap_idx_t *peer);
6.29 + notify_flags_t flags, void *subscriber);
6.30
6.31 - virtual void _unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier);
6.32 + virtual void _unsubscribe(unsigned int endpoint, void *subscriber);
6.33
6.34 public:
6.35 explicit NotificationSupport(unsigned int endpoints=0);
6.36 @@ -97,12 +97,12 @@
6.37 virtual void notify_others(unsigned int endpoint, notify_flags_t flags);
6.38
6.39 virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags,
6.40 - l4_cap_idx_t *peer, unsigned int *endpoint_number);
6.41 + void *subscriber, unsigned int *endpoint_number);
6.42
6.43 virtual long subscribe(unsigned int endpoint, l4_cap_idx_t notifier,
6.44 - notify_flags_t flags, l4_cap_idx_t *peer);
6.45 + notify_flags_t flags, void *subscriber);
6.46
6.47 - virtual void unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier);
6.48 + virtual void unsubscribe(unsigned int endpoint, void *subscriber);
6.49 };
6.50
6.51 // vim: tabstop=4 expandtab shiftwidth=4
7.1 --- a/libfsserver/include/fsserver/notifier_peer_endpoint.h Mon Mar 14 01:33:25 2022 +0100
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,59 +0,0 @@
7.4 -/*
7.5 - * Notification unsubscribing support.
7.6 - *
7.7 - * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
7.8 - *
7.9 - * This program is free software; you can redistribute it and/or
7.10 - * modify it under the terms of the GNU General Public License as
7.11 - * published by the Free Software Foundation; either version 2 of
7.12 - * the License, or (at your option) any later version.
7.13 - *
7.14 - * This program is distributed in the hope that it will be useful,
7.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 - * GNU General Public License for more details.
7.18 - *
7.19 - * You should have received a copy of the GNU General Public License
7.20 - * along with this program; if not, write to the Free Software
7.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
7.22 - * Boston, MA 02110-1301, USA
7.23 - */
7.24 -
7.25 -#pragma once
7.26 -
7.27 -#include <fsserver/notification.h>
7.28 -#include <fsserver/notifier_peer_interface.h>
7.29 -#include <fsserver/resource.h>
7.30 -
7.31 -
7.32 -
7.33 -/* A notifier endpoint peer for unsubscribing from notifications. */
7.34 -
7.35 -class NotifierPeerEndpoint : public Resource, public NotifierPeer
7.36 -{
7.37 -protected:
7.38 - NotificationSupport *_notification;
7.39 - unsigned int _endpoint;
7.40 - l4_cap_idx_t _notifier;
7.41 -
7.42 -public:
7.43 - explicit NotifierPeerEndpoint(NotificationSupport *notification,
7.44 - unsigned int endpoint, l4_cap_idx_t notifier);
7.45 -
7.46 - virtual ~NotifierPeerEndpoint();
7.47 -
7.48 - /* Server details. */
7.49 -
7.50 - int expected_items();
7.51 -
7.52 - ipc_server_handler_type handler();
7.53 -
7.54 - void *interface()
7.55 - { return static_cast<NotifierPeer *>(this); }
7.56 -
7.57 - /* Operations. */
7.58 -
7.59 - virtual long unsubscribe();
7.60 -};
7.61 -
7.62 -// vim: tabstop=4 expandtab shiftwidth=4
8.1 --- a/libfsserver/include/fsserver/pipe_pager.h Mon Mar 14 01:33:25 2022 +0100
8.2 +++ b/libfsserver/include/fsserver/pipe_pager.h Mon Mar 14 17:44:41 2022 +0100
8.3 @@ -76,8 +76,9 @@
8.4
8.5 /* Notification methods. */
8.6
8.7 - virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags,
8.8 - l4_cap_idx_t *peer);
8.9 + virtual long subscribe(l4_cap_idx_t notifier, notify_flags_t flags);
8.10 +
8.11 + virtual long unsubscribe();
8.12 };
8.13
8.14 // vim: tabstop=4 expandtab shiftwidth=4
9.1 --- a/libfsserver/lib/Makefile Mon Mar 14 01:33:25 2022 +0100
9.2 +++ b/libfsserver/lib/Makefile Mon Mar 14 17:44:41 2022 +0100
9.3 @@ -36,7 +36,7 @@
9.4
9.5 CLIENT_INTERFACES_CC = notifier
9.6
9.7 -SERVER_INTERFACES_CC = notifier_peer opener pipe_opener $(call common_interfaces,$(COMP_INTERFACES_CC))
9.8 +SERVER_INTERFACES_CC = opener pipe_opener $(call common_interfaces,$(COMP_INTERFACES_CC))
9.9
9.10 # Generated and plain source files.
9.11
9.12 @@ -71,7 +71,6 @@
9.13 generic/provider_registry.cc \
9.14 generic/resource_registry.cc \
9.15 generic/notification.cc \
9.16 - generic/notifier_peer_endpoint.cc \
9.17 generic/pager.cc \
9.18 generic/provider.cc \
9.19 generic/resource_server.cc \
10.1 --- a/libfsserver/lib/directories/directory_resource.cc Mon Mar 14 01:33:25 2022 +0100
10.2 +++ b/libfsserver/lib/directories/directory_resource.cc Mon Mar 14 17:44:41 2022 +0100
10.3 @@ -128,10 +128,17 @@
10.4
10.5 /* Subscribe to notifications. */
10.6
10.7 -long DirectoryResource::subscribe(l4_cap_idx_t endpoint, notify_flags_t flags,
10.8 - l4_cap_idx_t *peer)
10.9 +long DirectoryResource::subscribe(l4_cap_idx_t notifier, notify_flags_t flags)
10.10 {
10.11 - return _provider->subscribe(endpoint, flags, peer, &_endpoint);
10.12 + return _provider->subscribe(notifier, flags, this, &_endpoint);
10.13 +}
10.14 +
10.15 +/* Unsubscribe from notifications. */
10.16 +
10.17 +long DirectoryResource::unsubscribe()
10.18 +{
10.19 + _provider->unsubscribe(_endpoint, this);
10.20 + return L4_EOK;
10.21 }
10.22
10.23 // vim: tabstop=4 expandtab shiftwidth=4
11.1 --- a/libfsserver/lib/files/file_pager.cc Mon Mar 14 01:33:25 2022 +0100
11.2 +++ b/libfsserver/lib/files/file_pager.cc Mon Mar 14 17:44:41 2022 +0100
11.3 @@ -111,13 +111,20 @@
11.4
11.5 /* Subscribe to notifications. */
11.6
11.7 -long FilePager::subscribe(l4_cap_idx_t endpoint, notify_flags_t flags,
11.8 - l4_cap_idx_t *peer)
11.9 +long FilePager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags)
11.10 {
11.11 /* Readers can subscribe to new data (flush) and file closed events.
11.12 Writers can subscribe to file closed events. */
11.13
11.14 - return _provider->subscribe(endpoint, flags, peer, &_endpoint);
11.15 + return _provider->subscribe(notifier, flags, this, &_endpoint);
11.16 +}
11.17 +
11.18 +/* Unsubscribe from notifications. */
11.19 +
11.20 +long FilePager::unsubscribe()
11.21 +{
11.22 + _provider->unsubscribe(_endpoint, this);
11.23 + return L4_EOK;
11.24 }
11.25
11.26 // vim: tabstop=4 expandtab shiftwidth=4
12.1 --- a/libfsserver/lib/generic/notification.cc Mon Mar 14 01:33:25 2022 +0100
12.2 +++ b/libfsserver/lib/generic/notification.cc Mon Mar 14 17:44:41 2022 +0100
12.3 @@ -23,7 +23,6 @@
12.4
12.5 #include "notification.h"
12.6 #include "notifier_client.h"
12.7 -#include "notifier_peer_endpoint.h"
12.8
12.9 #include "resource_server.h"
12.10
12.11 @@ -45,7 +44,7 @@
12.12 endpoint number. */
12.13
12.14 long NotificationSupport::subscribe(l4_cap_idx_t notifier, notify_flags_t flags,
12.15 - l4_cap_idx_t *peer, unsigned int *endpoint_number)
12.16 + void *subscriber, unsigned int *endpoint_number)
12.17 {
12.18 std::lock_guard<std::mutex> guard(_lock);
12.19
12.20 @@ -58,14 +57,14 @@
12.21 _endpoints[endpoint].deferred = _deferred;
12.22
12.23 *endpoint_number = endpoint;
12.24 - return _subscribe(endpoint, notifier, flags, peer);
12.25 + return _subscribe(endpoint, notifier, flags, subscriber);
12.26 }
12.27
12.28 /* Subscribe to a specific endpoint's notifications using a notification
12.29 object. */
12.30
12.31 long NotificationSupport::subscribe(unsigned int endpoint, l4_cap_idx_t notifier,
12.32 - notify_flags_t flags, l4_cap_idx_t *peer)
12.33 + notify_flags_t flags, void *subscriber)
12.34 {
12.35 std::lock_guard<std::mutex> guard(_lock);
12.36
12.37 @@ -79,22 +78,22 @@
12.38 _endpoints[endpoint].deferred = _deferred;
12.39 }
12.40
12.41 - return _subscribe(endpoint, notifier, flags, peer);
12.42 + return _subscribe(endpoint, notifier, flags, subscriber);
12.43 }
12.44
12.45 /* Unsubscribe from an endpoint's notifications. */
12.46
12.47 -void NotificationSupport::unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier)
12.48 +void NotificationSupport::unsubscribe(unsigned int endpoint, void *subscriber)
12.49 {
12.50 std::lock_guard<std::mutex> guard(_lock);
12.51
12.52 - _unsubscribe(endpoint, notifier);
12.53 + _unsubscribe(endpoint, subscriber);
12.54 }
12.55
12.56 /* Common subscription functionality. */
12.57
12.58 long NotificationSupport::_subscribe(unsigned int endpoint, l4_cap_idx_t notifier,
12.59 - notify_flags_t flags, l4_cap_idx_t *peer)
12.60 + notify_flags_t flags, void *subscriber)
12.61 {
12.62 /* Record details of the notifier itself. */
12.63
12.64 @@ -111,25 +110,30 @@
12.65 ep.deferred = 0;
12.66 }
12.67
12.68 - /* Create a notifier peer for unsubscribing. */
12.69 -
12.70 - NotifierPeerEndpoint *peer_ep = new NotifierPeerEndpoint(this, endpoint, notifier);
12.71 -
12.72 - _peers[notifier] = peer_ep;
12.73 + /* Record the subscriber's notifier. */
12.74
12.75 - long err = ResourceServer(peer_ep).start_thread(peer);
12.76 -
12.77 - if (err)
12.78 - _unsubscribe(endpoint, notifier);
12.79 -
12.80 - return err;
12.81 + _subscribers[subscriber] = notifier;
12.82 + return L4_EOK;
12.83 }
12.84
12.85 -void NotificationSupport::_unsubscribe(unsigned int endpoint, l4_cap_idx_t notifier)
12.86 +void NotificationSupport::_unsubscribe(unsigned int endpoint, void *subscriber)
12.87 {
12.88 if (endpoint >= _endpoints.size())
12.89 return;
12.90
12.91 + /* Find and remove the subscriber's notifier. */
12.92 +
12.93 + SubscriberNotifierMap::iterator itp = _subscribers.find(subscriber);
12.94 + l4_cap_idx_t notifier;
12.95 +
12.96 + if (itp == _subscribers.end())
12.97 + return;
12.98 +
12.99 + notifier = itp->second;
12.100 + _subscribers.erase(itp);
12.101 +
12.102 + /* Release the notifier. */
12.103 +
12.104 NotificationEndpoint &ep = _endpoints[endpoint];
12.105 NotifierSet::iterator it = ep.notifiers.find(notifier);
12.106
12.107 @@ -144,13 +148,6 @@
12.108 ep.deferred = 0;
12.109 }
12.110 }
12.111 -
12.112 - /* Remove the notifier peer. */
12.113 -
12.114 - NotifierPeerMap::iterator itp = _peers.find(notifier);
12.115 -
12.116 - if (itp != _peers.end())
12.117 - _peers.erase(itp);
12.118 }
12.119
12.120 /* Notify a particular endpoint. */
13.1 --- a/libfsserver/lib/generic/notifier_peer_endpoint.cc Mon Mar 14 01:33:25 2022 +0100
13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
13.3 @@ -1,60 +0,0 @@
13.4 -/*
13.5 - * Notification support.
13.6 - *
13.7 - * Copyright (C) 2021, 2022 Paul Boddie <paul@boddie.org.uk>
13.8 - *
13.9 - * This program is free software; you can redistribute it and/or
13.10 - * modify it under the terms of the GNU General Public License as
13.11 - * published by the Free Software Foundation; either version 2 of
13.12 - * the License, or (at your option) any later version.
13.13 - *
13.14 - * This program is distributed in the hope that it will be useful,
13.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
13.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13.17 - * GNU General Public License for more details.
13.18 - *
13.19 - * You should have received a copy of the GNU General Public License
13.20 - * along with this program; if not, write to the Free Software
13.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
13.22 - * Boston, MA 02110-1301, USA
13.23 - */
13.24 -
13.25 -#include "notifier_peer_endpoint.h"
13.26 -#include "notifier_peer_server.h"
13.27 -
13.28 -
13.29 -
13.30 -/* Notifier peer endpoint. */
13.31 -
13.32 -NotifierPeerEndpoint::NotifierPeerEndpoint(NotificationSupport *notification,
13.33 - unsigned int endpoint,
13.34 - l4_cap_idx_t notifier)
13.35 -: _notification(notification), _endpoint(endpoint), _notifier(notifier)
13.36 -{
13.37 -}
13.38 -
13.39 -NotifierPeerEndpoint::~NotifierPeerEndpoint()
13.40 -{
13.41 -}
13.42 -
13.43 -/* Server methods. */
13.44 -
13.45 -int NotifierPeerEndpoint::expected_items()
13.46 -{
13.47 - return NotifierPeer_expected_items;
13.48 -}
13.49 -
13.50 -ipc_server_handler_type NotifierPeerEndpoint::handler()
13.51 -{
13.52 - return (ipc_server_handler_type) handle_NotifierPeer;
13.53 -}
13.54 -
13.55 -/* Unsubscribe a notifier via this peer. */
13.56 -
13.57 -long NotifierPeerEndpoint::unsubscribe()
13.58 -{
13.59 - _notification->unsubscribe(_endpoint, _notifier);
13.60 - return L4_EOK;
13.61 -}
13.62 -
13.63 -// vim: tabstop=4 expandtab shiftwidth=4
14.1 --- a/libfsserver/lib/pipes/pipe_pager.cc Mon Mar 14 01:33:25 2022 +0100
14.2 +++ b/libfsserver/lib/pipes/pipe_pager.cc Mon Mar 14 17:44:41 2022 +0100
14.3 @@ -182,14 +182,22 @@
14.4
14.5 /* Subscribe to notifications. */
14.6
14.7 -long PipePager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags,
14.8 - l4_cap_idx_t *peer)
14.9 +long PipePager::subscribe(l4_cap_idx_t notifier, notify_flags_t flags)
14.10 {
14.11 /* Readers can subscribe to new data (at end), and pipe closed events.
14.12 Writers can subscribe to new space and pipe closed events. */
14.13
14.14 return _paging->subscribe(_writing ? PipePaging::WRITER : PipePaging::READER,
14.15 - notifier, flags, peer);
14.16 + notifier, flags, this);
14.17 +}
14.18 +
14.19 +/* Unsubscribe from notifications. */
14.20 +
14.21 +long PipePager::unsubscribe()
14.22 +{
14.23 + _paging->unsubscribe(_writing ? PipePaging::WRITER : PipePaging::READER,
14.24 + this);
14.25 + return L4_EOK;
14.26 }
14.27
14.28 // vim: tabstop=4 expandtab shiftwidth=4
15.1 --- a/libsystypes/idl/notification.idl Mon Mar 14 01:33:25 2022 +0100
15.2 +++ b/libsystypes/idl/notification.idl Mon Mar 14 17:44:41 2022 +0100
15.3 @@ -2,9 +2,12 @@
15.4
15.5 interface Notification
15.6 {
15.7 - /* Subscribe to events. Unsubscribing is done via the peer returned by the
15.8 - operation. */
15.9 + /* Subscribe to events, providing the given notifier to receive notifications
15.10 + according to the given flags. */
15.11 +
15.12 + [opcode(23)] void subscribe(in cap notifier, in notify_flags_t flags);
15.13
15.14 - [opcode(23)] void subscribe(in cap notifier, in notify_flags_t flags,
15.15 - out cap peer);
15.16 + /* Unsubscribe from events. */
15.17 +
15.18 + [opcode(24)] void unsubscribe();
15.19 };
16.1 --- a/libsystypes/idl/notifier_peer.idl Mon Mar 14 01:33:25 2022 +0100
16.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
16.3 @@ -1,6 +0,0 @@
16.4 -interface NotifierPeer
16.5 -{
16.6 - /* Unsubscribe from events. */
16.7 -
16.8 - [opcode(24)] void unsubscribe();
16.9 -};