Commit 09f78b85 authored by Jon Maloy's avatar Jon Maloy Committed by David S. Miller

tipc: simplify api between binding table and topology server

The function tipc_report_overlap() is called from the binding table
with numerous parameters taken from an instance of struct publication.
A closer look reveals that it always is safe to send along a pointer
to the instance itself, and hence reduce the call signature. We do
that in this commit.
Signed-off-by: default avatarJon Maloy <jmaloy@redhat.com>
Acked-by: default avatarYing Xue <ying.xue@windriver.com>
Acked-by: default avatarHoang Le <hoang.h.le@dektech.com.au>
Acked-by: default avatarTung Nguyen <tung.q.nguyen@dektech.com.au>
Acked-by: default avatarXin Long <lucien.xin@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6e44867b
...@@ -358,9 +358,7 @@ static bool tipc_service_insert_publ(struct net *net, ...@@ -358,9 +358,7 @@ static bool tipc_service_insert_publ(struct net *net,
/* Any subscriptions waiting for notification? */ /* Any subscriptions waiting for notification? */
list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) { list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) {
tipc_sub_report_overlap(sub, p->sr.lower, p->sr.upper, tipc_sub_report_overlap(sub, p, TIPC_PUBLISHED, first);
TIPC_PUBLISHED, p->sk.ref, p->sk.node,
p->scope, first);
} }
res = true; res = true;
exit: exit:
...@@ -453,9 +451,7 @@ static void tipc_service_subscribe(struct tipc_service *service, ...@@ -453,9 +451,7 @@ static void tipc_service_subscribe(struct tipc_service *service,
/* Sort the publications before reporting */ /* Sort the publications before reporting */
list_sort(NULL, &publ_list, tipc_publ_sort); list_sort(NULL, &publ_list, tipc_publ_sort);
list_for_each_entry_safe(p, tmp, &publ_list, list) { list_for_each_entry_safe(p, tmp, &publ_list, list) {
tipc_sub_report_overlap(sub, p->sr.lower, p->sr.upper, tipc_sub_report_overlap(sub, p, TIPC_PUBLISHED, true);
TIPC_PUBLISHED, p->sk.ref, p->sk.node,
p->scope, true);
list_del_init(&p->list); list_del_init(&p->list);
} }
} }
...@@ -511,8 +507,6 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, ...@@ -511,8 +507,6 @@ struct publication *tipc_nametbl_remove_publ(struct net *net,
struct publication *p = NULL; struct publication *p = NULL;
struct service_range *sr; struct service_range *sr;
struct tipc_service *sc; struct tipc_service *sc;
u32 upper = ua->sr.upper;
u32 lower = ua->sr.lower;
bool last; bool last;
sc = tipc_service_find(net, ua); sc = tipc_service_find(net, ua);
...@@ -530,8 +524,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, ...@@ -530,8 +524,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net,
/* Notify any waiting subscriptions */ /* Notify any waiting subscriptions */
last = list_empty(&sr->all_publ); last = list_empty(&sr->all_publ);
list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) { list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) {
tipc_sub_report_overlap(sub, lower, upper, TIPC_WITHDRAWN, tipc_sub_report_overlap(sub, p, TIPC_WITHDRAWN, last);
sk->ref, sk->node, ua->scope, last);
} }
/* Remove service range item if this was its last publication */ /* Remove service range item if this was its last publication */
...@@ -540,7 +533,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, ...@@ -540,7 +533,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net,
kfree(sr); kfree(sr);
} }
/* Delete service item if this no more publications and subscriptions */ /* Delete service item if no more publications and subscriptions */
if (RB_EMPTY_ROOT(&sc->ranges) && list_empty(&sc->subscriptions)) { if (RB_EMPTY_ROOT(&sc->ranges) && list_empty(&sc->subscriptions)) {
hlist_del_init_rcu(&sc->service_list); hlist_del_init_rcu(&sc->service_list);
kfree_rcu(sc, rcu); kfree_rcu(sc, rcu);
...@@ -839,7 +832,8 @@ bool tipc_nametbl_subscribe(struct tipc_subscription *sub) ...@@ -839,7 +832,8 @@ bool tipc_nametbl_subscribe(struct tipc_subscription *sub)
struct tipc_uaddr ua; struct tipc_uaddr ua;
bool res = true; bool res = true;
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type, 0, 0); tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type,
tipc_sub_read(s, seq.lower), tipc_sub_read(s, seq.upper));
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
sc = tipc_service_find(sub->net, &ua); sc = tipc_service_find(sub->net, &ua);
if (!sc) if (!sc)
...@@ -870,7 +864,8 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *sub) ...@@ -870,7 +864,8 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *sub)
struct tipc_service *sc; struct tipc_service *sc;
struct tipc_uaddr ua; struct tipc_uaddr ua;
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type, 0, 0); tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type,
tipc_sub_read(s, seq.lower), tipc_sub_read(s, seq.upper));
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
sc = tipc_service_find(sub->net, &ua); sc = tipc_service_find(sub->net, &ua);
if (!sc) if (!sc)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2017, Ericsson AB * Copyright (c) 2000-2017, Ericsson AB
* Copyright (c) 2005-2007, 2010-2013, Wind River Systems * Copyright (c) 2005-2007, 2010-2013, Wind River Systems
* Copyright (c) 2020, Red Hat Inc * Copyright (c) 2020-2021, Red Hat Inc
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -40,18 +40,26 @@ ...@@ -40,18 +40,26 @@
#include "subscr.h" #include "subscr.h"
static void tipc_sub_send_event(struct tipc_subscription *sub, static void tipc_sub_send_event(struct tipc_subscription *sub,
u32 found_lower, u32 found_upper, struct publication *p,
u32 event, u32 port, u32 node) u32 event)
{ {
struct tipc_subscr *s = &sub->evt.s;
struct tipc_event *evt = &sub->evt; struct tipc_event *evt = &sub->evt;
if (sub->inactive) if (sub->inactive)
return; return;
tipc_evt_write(evt, event, event); tipc_evt_write(evt, event, event);
tipc_evt_write(evt, found_lower, found_lower); if (p) {
tipc_evt_write(evt, found_upper, found_upper); tipc_evt_write(evt, found_lower, p->sr.lower);
tipc_evt_write(evt, port.ref, port); tipc_evt_write(evt, found_upper, p->sr.upper);
tipc_evt_write(evt, port.node, node); tipc_evt_write(evt, port.ref, p->sk.ref);
tipc_evt_write(evt, port.node, p->sk.node);
} else {
tipc_evt_write(evt, found_lower, s->seq.lower);
tipc_evt_write(evt, found_upper, s->seq.upper);
tipc_evt_write(evt, port.ref, 0);
tipc_evt_write(evt, port.node, 0);
}
tipc_topsrv_queue_evt(sub->net, sub->conid, event, evt); tipc_topsrv_queue_evt(sub->net, sub->conid, event, evt);
} }
...@@ -61,24 +69,23 @@ static void tipc_sub_send_event(struct tipc_subscription *sub, ...@@ -61,24 +69,23 @@ static void tipc_sub_send_event(struct tipc_subscription *sub,
* @found_lower: lower value to test * @found_lower: lower value to test
* @found_upper: upper value to test * @found_upper: upper value to test
* *
* Return: 1 if there is overlap, otherwise 0. * Returns true if there is overlap, otherwise false.
*/ */
int tipc_sub_check_overlap(struct tipc_service_range *seq, u32 found_lower, bool tipc_sub_check_overlap(struct tipc_service_range *sr,
u32 found_upper) u32 found_lower, u32 found_upper)
{ {
if (found_lower < seq->lower) if (found_lower < sr->lower)
found_lower = seq->lower; found_lower = sr->lower;
if (found_upper > seq->upper) if (found_upper > sr->upper)
found_upper = seq->upper; found_upper = sr->upper;
if (found_lower > found_upper) if (found_lower > found_upper)
return 0; return false;
return 1; return true;
} }
void tipc_sub_report_overlap(struct tipc_subscription *sub, void tipc_sub_report_overlap(struct tipc_subscription *sub,
u32 found_lower, u32 found_upper, struct publication *p,
u32 event, u32 port, u32 node, u32 event, bool must)
u32 scope, int must)
{ {
struct tipc_subscr *s = &sub->evt.s; struct tipc_subscr *s = &sub->evt.s;
u32 filter = tipc_sub_read(s, filter); u32 filter = tipc_sub_read(s, filter);
...@@ -88,29 +95,25 @@ void tipc_sub_report_overlap(struct tipc_subscription *sub, ...@@ -88,29 +95,25 @@ void tipc_sub_report_overlap(struct tipc_subscription *sub,
seq.lower = tipc_sub_read(s, seq.lower); seq.lower = tipc_sub_read(s, seq.lower);
seq.upper = tipc_sub_read(s, seq.upper); seq.upper = tipc_sub_read(s, seq.upper);
if (!tipc_sub_check_overlap(&seq, found_lower, found_upper)) if (!tipc_sub_check_overlap(&seq, p->sr.lower, p->sr.upper))
return; return;
if (!must && !(filter & TIPC_SUB_PORTS)) if (!must && !(filter & TIPC_SUB_PORTS))
return; return;
if (filter & TIPC_SUB_CLUSTER_SCOPE && scope == TIPC_NODE_SCOPE) if (filter & TIPC_SUB_CLUSTER_SCOPE && p->scope == TIPC_NODE_SCOPE)
return; return;
if (filter & TIPC_SUB_NODE_SCOPE && scope != TIPC_NODE_SCOPE) if (filter & TIPC_SUB_NODE_SCOPE && p->scope != TIPC_NODE_SCOPE)
return; return;
spin_lock(&sub->lock); spin_lock(&sub->lock);
tipc_sub_send_event(sub, found_lower, found_upper, tipc_sub_send_event(sub, p, event);
event, port, node);
spin_unlock(&sub->lock); spin_unlock(&sub->lock);
} }
static void tipc_sub_timeout(struct timer_list *t) static void tipc_sub_timeout(struct timer_list *t)
{ {
struct tipc_subscription *sub = from_timer(sub, t, timer); struct tipc_subscription *sub = from_timer(sub, t, timer);
struct tipc_subscr *s = &sub->evt.s;
spin_lock(&sub->lock); spin_lock(&sub->lock);
tipc_sub_send_event(sub, s->seq.lower, s->seq.upper, tipc_sub_send_event(sub, NULL, TIPC_SUBSCR_TIMEOUT);
TIPC_SUBSCR_TIMEOUT, 0, 0);
sub->inactive = true; sub->inactive = true;
spin_unlock(&sub->lock); spin_unlock(&sub->lock);
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2003-2017, Ericsson AB * Copyright (c) 2003-2017, Ericsson AB
* Copyright (c) 2005-2007, 2012-2013, Wind River Systems * Copyright (c) 2005-2007, 2012-2013, Wind River Systems
* Copyright (c) 2020, Red Hat Inc * Copyright (c) 2020-2021, Red Hat Inc
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#define TIPC_MAX_SUBSCR 65535 #define TIPC_MAX_SUBSCR 65535
#define TIPC_MAX_PUBL 65535 #define TIPC_MAX_PUBL 65535
struct publication;
struct tipc_subscription; struct tipc_subscription;
struct tipc_conn; struct tipc_conn;
...@@ -74,13 +75,9 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net, ...@@ -74,13 +75,9 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net,
struct tipc_subscr *s, struct tipc_subscr *s,
int conid); int conid);
void tipc_sub_unsubscribe(struct tipc_subscription *sub); void tipc_sub_unsubscribe(struct tipc_subscription *sub);
int tipc_sub_check_overlap(struct tipc_service_range *seq,
u32 found_lower, u32 found_upper);
void tipc_sub_report_overlap(struct tipc_subscription *sub, void tipc_sub_report_overlap(struct tipc_subscription *sub,
u32 found_lower, u32 found_upper, struct publication *p,
u32 event, u32 port, u32 node, u32 event, bool must);
u32 scope, int must);
int __net_init tipc_topsrv_init_net(struct net *net); int __net_init tipc_topsrv_init_net(struct net *net);
void __net_exit tipc_topsrv_exit_net(struct net *net); void __net_exit tipc_topsrv_exit_net(struct net *net);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment