2006-01-02 13:04:38 -05:00
|
|
|
/*
|
2008-05-19 16:30:13 -04:00
|
|
|
* net/tipc/subscr.h: Include file for TIPC network topology service
|
2007-02-09 09:25:21 -05:00
|
|
|
*
|
2018-02-15 04:40:47 -05:00
|
|
|
* Copyright (c) 2003-2017, Ericsson AB
|
tipc: convert topology server to use new server facility
As the new TIPC server infrastructure has been introduced, we can
now convert the TIPC topology server to it. We get two benefits
from doing this:
1) It simplifies the topology server locking policy. In the
original locking policy, we placed one spin lock pointer in the
tipc_subscriber structure to reuse the lock of the subscriber's
server port, controlling access to members of tipc_subscriber
instance. That is, we only used one lock to ensure both
tipc_port and tipc_subscriber members were safely accessed.
Now we introduce another spin lock for tipc_subscriber structure
only protecting themselves, to get a finer granularity locking
policy. Moreover, the change will allow us to make the topology
server code more readable and maintainable.
2) It fixes a bug where sent subscription events may be lost when
the topology port is congested. Using the new service, the
topology server now queues sent events into an outgoing buffer,
and then wakes up a sender process which has been blocked in
workqueue context. The process will keep picking events from the
buffer and send them to their respective subscribers, using the
kernel socket interface, until the buffer is empty. Even if the
socket is congested during transmission there is no risk that
events may be dropped, since the sender process may block when
needed.
Some minor reordering of initialization is done, since we now
have a scenario where the topology server must be started after
socket initialization has taken place, as the former depends
on the latter. And overall, we see a simplification of the
TIPC subscriber code in making this changeover.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-17 10:54:40 -04:00
|
|
|
* Copyright (c) 2005-2007, 2012-2013, Wind River Systems
|
2006-01-02 13:04:38 -05:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-01-11 07:30:43 -05:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-02 13:04:38 -05:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2006-01-11 07:30:43 -05:00
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
* 3. Neither the names of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
2006-01-02 13:04:38 -05:00
|
|
|
*
|
2006-01-11 07:30:43 -05:00
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT OWNER 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
|
2006-01-02 13:04:38 -05:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _TIPC_SUBSCR_H
|
|
|
|
#define _TIPC_SUBSCR_H
|
|
|
|
|
2018-02-15 04:40:51 -05:00
|
|
|
#include "topsrv.h"
|
tipc: convert topology server to use new server facility
As the new TIPC server infrastructure has been introduced, we can
now convert the TIPC topology server to it. We get two benefits
from doing this:
1) It simplifies the topology server locking policy. In the
original locking policy, we placed one spin lock pointer in the
tipc_subscriber structure to reuse the lock of the subscriber's
server port, controlling access to members of tipc_subscriber
instance. That is, we only used one lock to ensure both
tipc_port and tipc_subscriber members were safely accessed.
Now we introduce another spin lock for tipc_subscriber structure
only protecting themselves, to get a finer granularity locking
policy. Moreover, the change will allow us to make the topology
server code more readable and maintainable.
2) It fixes a bug where sent subscription events may be lost when
the topology port is congested. Using the new service, the
topology server now queues sent events into an outgoing buffer,
and then wakes up a sender process which has been blocked in
workqueue context. The process will keep picking events from the
buffer and send them to their respective subscribers, using the
kernel socket interface, until the buffer is empty. Even if the
socket is congested during transmission there is no risk that
events may be dropped, since the sender process may block when
needed.
Some minor reordering of initialization is done, since we now
have a scenario where the topology server must be started after
socket initialization has taken place, as the former depends
on the latter. And overall, we see a simplification of the
TIPC subscriber code in making this changeover.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-17 10:54:40 -04:00
|
|
|
|
2018-02-15 04:40:47 -05:00
|
|
|
#define TIPC_MAX_SUBSCR 65535
|
2018-03-29 17:20:41 -04:00
|
|
|
#define TIPC_MAX_PUBL 65535
|
2015-01-09 02:27:01 -05:00
|
|
|
|
2011-12-29 20:43:44 -05:00
|
|
|
struct tipc_subscription;
|
tipc: eliminate struct tipc_subscriber
It is unnecessary to keep two structures, struct tipc_conn and struct
tipc_subscriber, with a one-to-one relationship and still with different
life cycles. The fact that the two often run in different contexts, and
still may access each other via direct pointers constitutes an additional
hazard, something we have experienced at several occasions, and still
see happening.
We have identified at least two remaining problems that are easier to
fix if we simplify the topology server data structure somewhat.
- When there is a race between a subscription up/down event and a
timeout event, it is fully possible that the former might be delivered
after the latter, leading to confusion for the receiver.
- The function tipc_subcrp_timeout() is executing in interrupt context,
while the following call chain is at least theoretically possible:
tipc_subscrp_timeout()
tipc_subscrp_send_event()
tipc_conn_sendmsg()
conn_put()
tipc_conn_kref_release()
sock_release(sock)
I.e., we end up calling a function that might try to sleep in
interrupt context. To eliminate this, we need to ensure that the
tipc_conn structure and the socket, as well as the subscription
instances, only are deleted in work queue context, i.e., after the
timeout event really has been sent out.
We now remove this unnecessary complexity, by merging data and
functionality of the subscriber structure into struct tipc_conn
and the associated file server.c. We thereafter add a spinlock and
a new 'inactive' state to the subscription structure. Using those,
both problems described above can be easily solved.
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-15 04:40:44 -05:00
|
|
|
struct tipc_conn;
|
2008-05-19 16:27:31 -04:00
|
|
|
|
2006-01-02 13:04:38 -05:00
|
|
|
/**
|
2011-12-29 20:43:44 -05:00
|
|
|
* struct tipc_subscription - TIPC network topology subscription object
|
tipc: convert topology server to use new server facility
As the new TIPC server infrastructure has been introduced, we can
now convert the TIPC topology server to it. We get two benefits
from doing this:
1) It simplifies the topology server locking policy. In the
original locking policy, we placed one spin lock pointer in the
tipc_subscriber structure to reuse the lock of the subscriber's
server port, controlling access to members of tipc_subscriber
instance. That is, we only used one lock to ensure both
tipc_port and tipc_subscriber members were safely accessed.
Now we introduce another spin lock for tipc_subscriber structure
only protecting themselves, to get a finer granularity locking
policy. Moreover, the change will allow us to make the topology
server code more readable and maintainable.
2) It fixes a bug where sent subscription events may be lost when
the topology port is congested. Using the new service, the
topology server now queues sent events into an outgoing buffer,
and then wakes up a sender process which has been blocked in
workqueue context. The process will keep picking events from the
buffer and send them to their respective subscribers, using the
kernel socket interface, until the buffer is empty. Even if the
socket is congested during transmission there is no risk that
events may be dropped, since the sender process may block when
needed.
Some minor reordering of initialization is done, since we now
have a scenario where the topology server must be started after
socket initialization has taken place, as the former depends
on the latter. And overall, we see a simplification of the
TIPC subscriber code in making this changeover.
Signed-off-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-06-17 10:54:40 -04:00
|
|
|
* @subscriber: pointer to its subscriber
|
2006-01-02 13:04:38 -05:00
|
|
|
* @seq: name sequence associated with subscription
|
2008-05-19 16:30:13 -04:00
|
|
|
* @timer: timer governing subscription duration (optional)
|
|
|
|
* @nameseq_list: adjacent subscriptions in name sequence's subscription list
|
2018-02-15 04:40:48 -05:00
|
|
|
* @sub_list: adjacent subscriptions in subscriber's subscription list
|
2006-01-02 13:04:38 -05:00
|
|
|
* @evt: template for events generated by subscription
|
|
|
|
*/
|
2011-12-29 20:43:44 -05:00
|
|
|
struct tipc_subscription {
|
2017-01-24 07:00:44 -05:00
|
|
|
struct kref kref;
|
2018-02-15 04:40:49 -05:00
|
|
|
struct net *net;
|
2008-05-19 16:30:13 -04:00
|
|
|
struct timer_list timer;
|
2018-03-29 17:20:41 -04:00
|
|
|
struct list_head service_list;
|
2018-02-15 04:40:48 -05:00
|
|
|
struct list_head sub_list;
|
2006-01-02 13:04:38 -05:00
|
|
|
struct tipc_event evt;
|
tipc: eliminate struct tipc_subscriber
It is unnecessary to keep two structures, struct tipc_conn and struct
tipc_subscriber, with a one-to-one relationship and still with different
life cycles. The fact that the two often run in different contexts, and
still may access each other via direct pointers constitutes an additional
hazard, something we have experienced at several occasions, and still
see happening.
We have identified at least two remaining problems that are easier to
fix if we simplify the topology server data structure somewhat.
- When there is a race between a subscription up/down event and a
timeout event, it is fully possible that the former might be delivered
after the latter, leading to confusion for the receiver.
- The function tipc_subcrp_timeout() is executing in interrupt context,
while the following call chain is at least theoretically possible:
tipc_subscrp_timeout()
tipc_subscrp_send_event()
tipc_conn_sendmsg()
conn_put()
tipc_conn_kref_release()
sock_release(sock)
I.e., we end up calling a function that might try to sleep in
interrupt context. To eliminate this, we need to ensure that the
tipc_conn structure and the socket, as well as the subscription
instances, only are deleted in work queue context, i.e., after the
timeout event really has been sent out.
We now remove this unnecessary complexity, by merging data and
functionality of the subscriber structure into struct tipc_conn
and the associated file server.c. We thereafter add a spinlock and
a new 'inactive' state to the subscription structure. Using those,
both problems described above can be easily solved.
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2018-02-15 04:40:44 -05:00
|
|
|
int conid;
|
|
|
|
bool inactive;
|
|
|
|
spinlock_t lock; /* serialize up/down and timer events */
|
2006-01-02 13:04:38 -05:00
|
|
|
};
|
|
|
|
|
2018-02-15 04:40:49 -05:00
|
|
|
struct tipc_subscription *tipc_sub_subscribe(struct net *net,
|
2018-02-15 04:40:47 -05:00
|
|
|
struct tipc_subscr *s,
|
|
|
|
int conid);
|
|
|
|
void tipc_sub_unsubscribe(struct tipc_subscription *sub);
|
2018-02-15 04:40:46 -05:00
|
|
|
|
2018-02-15 04:40:48 -05:00
|
|
|
int tipc_sub_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
|
|
|
|
u32 found_upper);
|
|
|
|
void tipc_sub_report_overlap(struct tipc_subscription *sub,
|
|
|
|
u32 found_lower, u32 found_upper,
|
|
|
|
u32 event, u32 port, u32 node,
|
|
|
|
u32 scope, int must);
|
2019-05-20 02:43:59 -04:00
|
|
|
|
|
|
|
int __net_init tipc_topsrv_init_net(struct net *net);
|
|
|
|
void __net_exit tipc_topsrv_exit_net(struct net *net);
|
2006-01-02 13:04:38 -05:00
|
|
|
|
2018-02-15 04:40:48 -05:00
|
|
|
void tipc_sub_put(struct tipc_subscription *subscription);
|
|
|
|
void tipc_sub_get(struct tipc_subscription *subscription);
|
2017-03-28 06:28:28 -04:00
|
|
|
|
2018-02-15 04:40:46 -05:00
|
|
|
#define TIPC_FILTER_MASK (TIPC_SUB_PORTS | TIPC_SUB_SERVICE | TIPC_SUB_CANCEL)
|
|
|
|
|
|
|
|
/* tipc_sub_read - return field_ of struct sub_ in host endian format
|
|
|
|
*/
|
|
|
|
#define tipc_sub_read(sub_, field_) \
|
|
|
|
({ \
|
|
|
|
struct tipc_subscr *sub__ = sub_; \
|
|
|
|
u32 val__ = (sub__)->field_; \
|
|
|
|
int swap_ = !((sub__)->filter & TIPC_FILTER_MASK); \
|
|
|
|
(swap_ ? swab32(val__) : val__); \
|
|
|
|
})
|
|
|
|
|
|
|
|
/* tipc_evt_write - write val_ to field_ of struct evt_ in user endian format
|
|
|
|
*/
|
|
|
|
#define tipc_evt_write(evt_, field_, val_) \
|
|
|
|
({ \
|
|
|
|
struct tipc_event *evt__ = evt_; \
|
|
|
|
u32 val__ = val_; \
|
|
|
|
int swap_ = !((evt__)->s.filter & (TIPC_FILTER_MASK)); \
|
|
|
|
(evt__)->field_ = swap_ ? swab32(val__) : val__; \
|
|
|
|
})
|
|
|
|
|
2006-01-02 13:04:38 -05:00
|
|
|
#endif
|