2006-01-02 21:04:38 +03:00
|
|
|
/*
|
2008-05-20 00:30:13 +04:00
|
|
|
* net/tipc/subscr.c: TIPC network topology service
|
2007-02-09 17:25:21 +03:00
|
|
|
*
|
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 12:40:44 +03:00
|
|
|
* Copyright (c) 2000-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 18:54:40 +04:00
|
|
|
* Copyright (c) 2005-2007, 2010-2013, Wind River Systems
|
2006-01-02 21:04:38 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2006-01-11 15:30:43 +03:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2006-01-02 21:04:38 +03:00
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
2006-01-11 15:30:43 +03: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 21:04:38 +03:00
|
|
|
*
|
2006-01-11 15:30:43 +03: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 21:04:38 +03:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "name_table.h"
|
2008-05-20 00:30:13 +04:00
|
|
|
#include "subscr.h"
|
2006-01-02 21:04:38 +03:00
|
|
|
|
2010-10-21 05:06:16 +04:00
|
|
|
/**
|
|
|
|
* htohl - convert value to endianness used by destination
|
|
|
|
* @in: value to convert
|
|
|
|
* @swap: non-zero if endianness must be reversed
|
|
|
|
*
|
|
|
|
* Returns converted value
|
|
|
|
*/
|
|
|
|
static u32 htohl(u32 in, int swap)
|
|
|
|
{
|
|
|
|
return swap ? swab32(in) : in;
|
|
|
|
}
|
|
|
|
|
2015-05-04 05:36:44 +03:00
|
|
|
static void tipc_subscrp_send_event(struct tipc_subscription *sub,
|
|
|
|
u32 found_lower, u32 found_upper,
|
|
|
|
u32 event, u32 port_ref, u32 node)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2015-01-09 10:27:11 +03:00
|
|
|
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
|
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 18:54:40 +04:00
|
|
|
struct kvec msg_sect;
|
2006-01-02 21:04:38 +03:00
|
|
|
|
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 12:40:44 +03:00
|
|
|
if (sub->inactive)
|
|
|
|
return;
|
2006-01-02 21:04:38 +03:00
|
|
|
msg_sect.iov_base = (void *)&sub->evt;
|
|
|
|
msg_sect.iov_len = sizeof(struct tipc_event);
|
2010-10-21 05:06:16 +04:00
|
|
|
sub->evt.event = htohl(event, sub->swap);
|
|
|
|
sub->evt.found_lower = htohl(found_lower, sub->swap);
|
|
|
|
sub->evt.found_upper = htohl(found_upper, sub->swap);
|
|
|
|
sub->evt.port.ref = htohl(port_ref, sub->swap);
|
|
|
|
sub->evt.port.node = htohl(node, sub->swap);
|
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 12:40:44 +03:00
|
|
|
tipc_conn_sendmsg(tn->topsrv, sub->conid, event,
|
2015-01-09 10:27:11 +03:00
|
|
|
msg_sect.iov_base, msg_sect.iov_len);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-04 05:36:44 +03:00
|
|
|
* tipc_subscrp_check_overlap - test for subscription overlap with the
|
|
|
|
* given values
|
2006-01-02 21:04:38 +03:00
|
|
|
*
|
|
|
|
* Returns 1 if there is overlap, otherwise 0.
|
|
|
|
*/
|
2016-02-02 12:52:10 +03:00
|
|
|
int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
|
2015-05-04 05:36:44 +03:00
|
|
|
u32 found_upper)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2016-02-02 12:52:10 +03:00
|
|
|
if (found_lower < seq->lower)
|
|
|
|
found_lower = seq->lower;
|
|
|
|
if (found_upper > seq->upper)
|
|
|
|
found_upper = seq->upper;
|
2006-01-02 21:04:38 +03:00
|
|
|
if (found_lower > found_upper)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-02 12:52:10 +03:00
|
|
|
u32 tipc_subscrp_convert_seq_type(u32 type, int swap)
|
|
|
|
{
|
|
|
|
return htohl(type, swap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tipc_subscrp_convert_seq(struct tipc_name_seq *in, int swap,
|
|
|
|
struct tipc_name_seq *out)
|
|
|
|
{
|
|
|
|
out->type = htohl(in->type, swap);
|
|
|
|
out->lower = htohl(in->lower, swap);
|
|
|
|
out->upper = htohl(in->upper, swap);
|
|
|
|
}
|
|
|
|
|
2015-05-04 05:36:44 +03:00
|
|
|
void tipc_subscrp_report_overlap(struct tipc_subscription *sub, u32 found_lower,
|
|
|
|
u32 found_upper, u32 event, u32 port_ref,
|
2018-01-08 23:03:30 +03:00
|
|
|
u32 node, u32 scope, int must)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2018-01-08 23:03:30 +03:00
|
|
|
u32 filter = htohl(sub->evt.s.filter, sub->swap);
|
2016-02-02 12:52:10 +03:00
|
|
|
struct tipc_name_seq seq;
|
|
|
|
|
|
|
|
tipc_subscrp_convert_seq(&sub->evt.s.seq, sub->swap, &seq);
|
|
|
|
if (!tipc_subscrp_check_overlap(&seq, found_lower, found_upper))
|
2006-01-02 21:04:38 +03:00
|
|
|
return;
|
2018-01-08 23:03:30 +03:00
|
|
|
if (!must && !(filter & TIPC_SUB_PORTS))
|
|
|
|
return;
|
|
|
|
if (filter & TIPC_SUB_CLUSTER_SCOPE && scope == TIPC_NODE_SCOPE)
|
|
|
|
return;
|
|
|
|
if (filter & TIPC_SUB_NODE_SCOPE && scope != TIPC_NODE_SCOPE)
|
2006-01-02 21:04:38 +03:00
|
|
|
return;
|
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 12:40:44 +03:00
|
|
|
spin_lock(&sub->lock);
|
|
|
|
tipc_subscrp_send_event(sub, found_lower, found_upper,
|
|
|
|
event, port_ref, node);
|
|
|
|
spin_unlock(&sub->lock);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
2017-10-31 00:06:45 +03:00
|
|
|
static void tipc_subscrp_timeout(struct timer_list *t)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2017-10-31 00:06:45 +03:00
|
|
|
struct tipc_subscription *sub = from_timer(sub, t, timer);
|
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 12:40:44 +03:00
|
|
|
struct tipc_subscr *s = &sub->evt.s;
|
2008-05-20 00:29:47 +04:00
|
|
|
|
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 12:40:44 +03:00
|
|
|
spin_lock(&sub->lock);
|
|
|
|
tipc_subscrp_send_event(sub, s->seq.lower, s->seq.upper,
|
2015-05-04 05:36:44 +03:00
|
|
|
TIPC_SUBSCR_TIMEOUT, 0, 0);
|
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 12:40:44 +03:00
|
|
|
sub->inactive = true;
|
|
|
|
spin_unlock(&sub->lock);
|
2006-10-17 08:59:42 +04:00
|
|
|
}
|
|
|
|
|
2017-01-24 15:00:44 +03:00
|
|
|
static void tipc_subscrp_kref_release(struct kref *kref)
|
|
|
|
{
|
|
|
|
struct tipc_subscription *sub = container_of(kref,
|
|
|
|
struct tipc_subscription,
|
|
|
|
kref);
|
|
|
|
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
|
|
|
|
|
|
|
|
atomic_dec(&tn->subscription_count);
|
|
|
|
kfree(sub);
|
|
|
|
}
|
|
|
|
|
2017-03-28 13:28:28 +03:00
|
|
|
void tipc_subscrp_put(struct tipc_subscription *subscription)
|
2017-01-24 15:00:44 +03:00
|
|
|
{
|
|
|
|
kref_put(&subscription->kref, tipc_subscrp_kref_release);
|
|
|
|
}
|
|
|
|
|
2017-03-28 13:28:28 +03:00
|
|
|
void tipc_subscrp_get(struct tipc_subscription *subscription)
|
2017-01-24 15:00:44 +03:00
|
|
|
{
|
|
|
|
kref_get(&subscription->kref);
|
|
|
|
}
|
|
|
|
|
2016-02-02 12:52:11 +03:00
|
|
|
static struct tipc_subscription *tipc_subscrp_create(struct net *net,
|
|
|
|
struct tipc_subscr *s,
|
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 12:40:44 +03:00
|
|
|
int conid, bool swap)
|
2015-01-09 10:27:11 +03:00
|
|
|
{
|
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
2011-12-30 05:43:44 +04:00
|
|
|
struct tipc_subscription *sub;
|
2016-02-02 12:52:12 +03:00
|
|
|
u32 filter = htohl(s->filter, swap);
|
2006-10-17 08:59:42 +04:00
|
|
|
|
2006-01-02 21:04:38 +03:00
|
|
|
/* Refuse subscription if global limit exceeded */
|
2015-01-09 10:27:11 +03:00
|
|
|
if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Subscription rejected, limit reached (%u)\n",
|
2012-08-16 16:09:13 +04:00
|
|
|
TIPC_MAX_SUBSCRIPTIONS);
|
2016-02-02 12:52:11 +03:00
|
|
|
return NULL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate subscription object */
|
2008-05-20 00:29:47 +04:00
|
|
|
sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
|
2006-06-26 10:52:17 +04:00
|
|
|
if (!sub) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Subscription rejected, no memory\n");
|
2016-02-02 12:52:11 +03:00
|
|
|
return NULL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize subscription object */
|
2015-01-09 10:27:09 +03:00
|
|
|
sub->net = net;
|
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 12:40:44 +03:00
|
|
|
sub->conid = conid;
|
|
|
|
sub->inactive = false;
|
2016-02-02 12:52:09 +03:00
|
|
|
if (((filter & TIPC_SUB_PORTS) && (filter & TIPC_SUB_SERVICE)) ||
|
2016-02-02 12:52:10 +03:00
|
|
|
(htohl(s->seq.lower, swap) > htohl(s->seq.upper, swap))) {
|
2012-06-29 08:16:37 +04:00
|
|
|
pr_warn("Subscription rejected, illegal request\n");
|
2006-01-02 21:04:38 +03:00
|
|
|
kfree(sub);
|
2016-02-02 12:52:11 +03:00
|
|
|
return NULL;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
2016-02-02 12:52:09 +03:00
|
|
|
|
2010-10-21 05:06:16 +04:00
|
|
|
sub->swap = swap;
|
2015-05-04 05:36:44 +03:00
|
|
|
memcpy(&sub->evt.s, s, sizeof(*s));
|
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 12:40:44 +03:00
|
|
|
spin_lock_init(&sub->lock);
|
2015-01-09 10:27:11 +03:00
|
|
|
atomic_inc(&tn->subscription_count);
|
2017-01-24 15:00:44 +03:00
|
|
|
kref_init(&sub->kref);
|
2016-02-02 12:52:11 +03:00
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
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 12:40:44 +03:00
|
|
|
struct tipc_subscription *tipc_subscrp_subscribe(struct net *net,
|
|
|
|
struct tipc_subscr *s,
|
|
|
|
int conid, bool swap,
|
|
|
|
bool status)
|
2016-02-02 12:52:11 +03:00
|
|
|
{
|
|
|
|
struct tipc_subscription *sub = NULL;
|
|
|
|
u32 timeout;
|
|
|
|
|
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 12:40:44 +03:00
|
|
|
sub = tipc_subscrp_create(net, s, conid, swap);
|
2016-02-02 12:52:11 +03:00
|
|
|
if (!sub)
|
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 12:40:44 +03:00
|
|
|
return NULL;
|
2016-02-02 12:52:11 +03:00
|
|
|
|
tipc: add option to suppress PUBLISH events for pre-existing publications
Currently, when a user is subscribing for binding table publications,
he will receive a PUBLISH event for all already existing matching items
in the binding table.
However, a group socket making a subscriptions doesn't need this initial
status update from the binding table, because it has already scanned it
during the join operation. Worse, the multiplicatory effect of issuing
mutual events for dozens or hundreds group members within a short time
frame put a heavy load on the topology server, with the end result that
scale out operations on a big group tend to take much longer than needed.
We now add a new filter option, TIPC_SUB_NO_STATUS, for topology server
subscriptions, so that this initial avalanche of events is suppressed.
This change, along with the previous commit, significantly improves the
range and speed of group scale out operations.
We keep the new option internal for the tipc driver, at least for now.
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-01-08 23:03:29 +03:00
|
|
|
tipc_nametbl_subscribe(sub, status);
|
2017-10-31 00:06:45 +03:00
|
|
|
timer_setup(&sub->timer, tipc_subscrp_timeout, 0);
|
2016-02-02 12:52:12 +03:00
|
|
|
timeout = htohl(sub->evt.s.timeout, swap);
|
2017-01-24 15:00:44 +03:00
|
|
|
if (timeout != TIPC_WAIT_FOREVER)
|
|
|
|
mod_timer(&sub->timer, jiffies + msecs_to_jiffies(timeout));
|
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 12:40:44 +03:00
|
|
|
return sub;
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
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 12:40:44 +03:00
|
|
|
void tipc_sub_delete(struct tipc_subscription *sub)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
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 12:40:44 +03:00
|
|
|
tipc_nametbl_unsubscribe(sub);
|
|
|
|
if (sub->evt.s.timeout != TIPC_WAIT_FOREVER)
|
|
|
|
del_timer_sync(&sub->timer);
|
|
|
|
list_del(&sub->subscrp_list);
|
|
|
|
tipc_subscrp_put(sub);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
2015-05-04 05:36:44 +03:00
|
|
|
int tipc_topsrv_start(struct net *net)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2015-01-09 10:27:11 +03:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
|
|
|
const char name[] = "topology_server";
|
|
|
|
struct tipc_server *topsrv;
|
|
|
|
struct sockaddr_tipc *saddr;
|
|
|
|
|
|
|
|
saddr = kzalloc(sizeof(*saddr), GFP_ATOMIC);
|
|
|
|
if (!saddr)
|
|
|
|
return -ENOMEM;
|
|
|
|
saddr->family = AF_TIPC;
|
|
|
|
saddr->addrtype = TIPC_ADDR_NAMESEQ;
|
|
|
|
saddr->addr.nameseq.type = TIPC_TOP_SRV;
|
|
|
|
saddr->addr.nameseq.lower = TIPC_TOP_SRV;
|
|
|
|
saddr->addr.nameseq.upper = TIPC_TOP_SRV;
|
|
|
|
saddr->scope = TIPC_NODE_SCOPE;
|
|
|
|
|
|
|
|
topsrv = kzalloc(sizeof(*topsrv), GFP_ATOMIC);
|
|
|
|
if (!topsrv) {
|
|
|
|
kfree(saddr);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
topsrv->net = net;
|
|
|
|
topsrv->saddr = saddr;
|
|
|
|
topsrv->max_rcvbuf_size = sizeof(struct tipc_subscr);
|
|
|
|
|
|
|
|
strncpy(topsrv->name, name, strlen(name) + 1);
|
|
|
|
tn->topsrv = topsrv;
|
|
|
|
atomic_set(&tn->subscription_count, 0);
|
|
|
|
|
|
|
|
return tipc_server_start(topsrv);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|
|
|
|
|
2015-05-04 05:36:44 +03:00
|
|
|
void tipc_topsrv_stop(struct net *net)
|
2006-01-02 21:04:38 +03:00
|
|
|
{
|
2015-01-09 10:27:11 +03:00
|
|
|
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
|
|
|
struct tipc_server *topsrv = tn->topsrv;
|
|
|
|
|
|
|
|
tipc_server_stop(topsrv);
|
|
|
|
kfree(topsrv->saddr);
|
|
|
|
kfree(topsrv);
|
2006-01-02 21:04:38 +03:00
|
|
|
}
|