Skip to content

Commit 09f78b8

Browse files
lmcjomadavem330
authored andcommitted
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: Jon Maloy <jmaloy@redhat.com> Acked-by: Ying Xue <ying.xue@windriver.com> Acked-by: Hoang Le <hoang.h.le@dektech.com.au> Acked-by: Tung Nguyen <tung.q.nguyen@dektech.com.au> Acked-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6e44867 commit 09f78b8

File tree

3 files changed

+43
-48
lines changed

3 files changed

+43
-48
lines changed

net/tipc/name_table.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ static bool tipc_service_insert_publ(struct net *net,
358358

359359
/* Any subscriptions waiting for notification? */
360360
list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) {
361-
tipc_sub_report_overlap(sub, p->sr.lower, p->sr.upper,
362-
TIPC_PUBLISHED, p->sk.ref, p->sk.node,
363-
p->scope, first);
361+
tipc_sub_report_overlap(sub, p, TIPC_PUBLISHED, first);
364362
}
365363
res = true;
366364
exit:
@@ -453,9 +451,7 @@ static void tipc_service_subscribe(struct tipc_service *service,
453451
/* Sort the publications before reporting */
454452
list_sort(NULL, &publ_list, tipc_publ_sort);
455453
list_for_each_entry_safe(p, tmp, &publ_list, list) {
456-
tipc_sub_report_overlap(sub, p->sr.lower, p->sr.upper,
457-
TIPC_PUBLISHED, p->sk.ref, p->sk.node,
458-
p->scope, true);
454+
tipc_sub_report_overlap(sub, p, TIPC_PUBLISHED, true);
459455
list_del_init(&p->list);
460456
}
461457
}
@@ -511,8 +507,6 @@ struct publication *tipc_nametbl_remove_publ(struct net *net,
511507
struct publication *p = NULL;
512508
struct service_range *sr;
513509
struct tipc_service *sc;
514-
u32 upper = ua->sr.upper;
515-
u32 lower = ua->sr.lower;
516510
bool last;
517511

518512
sc = tipc_service_find(net, ua);
@@ -530,8 +524,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net,
530524
/* Notify any waiting subscriptions */
531525
last = list_empty(&sr->all_publ);
532526
list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) {
533-
tipc_sub_report_overlap(sub, lower, upper, TIPC_WITHDRAWN,
534-
sk->ref, sk->node, ua->scope, last);
527+
tipc_sub_report_overlap(sub, p, TIPC_WITHDRAWN, last);
535528
}
536529

537530
/* Remove service range item if this was its last publication */
@@ -540,7 +533,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net,
540533
kfree(sr);
541534
}
542535

543-
/* Delete service item if this no more publications and subscriptions */
536+
/* Delete service item if no more publications and subscriptions */
544537
if (RB_EMPTY_ROOT(&sc->ranges) && list_empty(&sc->subscriptions)) {
545538
hlist_del_init_rcu(&sc->service_list);
546539
kfree_rcu(sc, rcu);
@@ -839,7 +832,8 @@ bool tipc_nametbl_subscribe(struct tipc_subscription *sub)
839832
struct tipc_uaddr ua;
840833
bool res = true;
841834

842-
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type, 0, 0);
835+
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type,
836+
tipc_sub_read(s, seq.lower), tipc_sub_read(s, seq.upper));
843837
spin_lock_bh(&tn->nametbl_lock);
844838
sc = tipc_service_find(sub->net, &ua);
845839
if (!sc)
@@ -870,7 +864,8 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *sub)
870864
struct tipc_service *sc;
871865
struct tipc_uaddr ua;
872866

873-
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type, 0, 0);
867+
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type,
868+
tipc_sub_read(s, seq.lower), tipc_sub_read(s, seq.upper));
874869
spin_lock_bh(&tn->nametbl_lock);
875870
sc = tipc_service_find(sub->net, &ua);
876871
if (!sc)

net/tipc/subscr.c

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2017, Ericsson AB
55
* Copyright (c) 2005-2007, 2010-2013, Wind River Systems
6-
* Copyright (c) 2020, Red Hat Inc
6+
* Copyright (c) 2020-2021, Red Hat Inc
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -40,18 +40,26 @@
4040
#include "subscr.h"
4141

4242
static void tipc_sub_send_event(struct tipc_subscription *sub,
43-
u32 found_lower, u32 found_upper,
44-
u32 event, u32 port, u32 node)
43+
struct publication *p,
44+
u32 event)
4545
{
46+
struct tipc_subscr *s = &sub->evt.s;
4647
struct tipc_event *evt = &sub->evt;
4748

4849
if (sub->inactive)
4950
return;
5051
tipc_evt_write(evt, event, event);
51-
tipc_evt_write(evt, found_lower, found_lower);
52-
tipc_evt_write(evt, found_upper, found_upper);
53-
tipc_evt_write(evt, port.ref, port);
54-
tipc_evt_write(evt, port.node, node);
52+
if (p) {
53+
tipc_evt_write(evt, found_lower, p->sr.lower);
54+
tipc_evt_write(evt, found_upper, p->sr.upper);
55+
tipc_evt_write(evt, port.ref, p->sk.ref);
56+
tipc_evt_write(evt, port.node, p->sk.node);
57+
} else {
58+
tipc_evt_write(evt, found_lower, s->seq.lower);
59+
tipc_evt_write(evt, found_upper, s->seq.upper);
60+
tipc_evt_write(evt, port.ref, 0);
61+
tipc_evt_write(evt, port.node, 0);
62+
}
5563
tipc_topsrv_queue_evt(sub->net, sub->conid, event, evt);
5664
}
5765

@@ -61,24 +69,23 @@ static void tipc_sub_send_event(struct tipc_subscription *sub,
6169
* @found_lower: lower value to test
6270
* @found_upper: upper value to test
6371
*
64-
* Return: 1 if there is overlap, otherwise 0.
72+
* Returns true if there is overlap, otherwise false.
6573
*/
66-
int tipc_sub_check_overlap(struct tipc_service_range *seq, u32 found_lower,
67-
u32 found_upper)
74+
bool tipc_sub_check_overlap(struct tipc_service_range *sr,
75+
u32 found_lower, u32 found_upper)
6876
{
69-
if (found_lower < seq->lower)
70-
found_lower = seq->lower;
71-
if (found_upper > seq->upper)
72-
found_upper = seq->upper;
77+
if (found_lower < sr->lower)
78+
found_lower = sr->lower;
79+
if (found_upper > sr->upper)
80+
found_upper = sr->upper;
7381
if (found_lower > found_upper)
74-
return 0;
75-
return 1;
82+
return false;
83+
return true;
7684
}
7785

7886
void tipc_sub_report_overlap(struct tipc_subscription *sub,
79-
u32 found_lower, u32 found_upper,
80-
u32 event, u32 port, u32 node,
81-
u32 scope, int must)
87+
struct publication *p,
88+
u32 event, bool must)
8289
{
8390
struct tipc_subscr *s = &sub->evt.s;
8491
u32 filter = tipc_sub_read(s, filter);
@@ -88,29 +95,25 @@ void tipc_sub_report_overlap(struct tipc_subscription *sub,
8895
seq.lower = tipc_sub_read(s, seq.lower);
8996
seq.upper = tipc_sub_read(s, seq.upper);
9097

91-
if (!tipc_sub_check_overlap(&seq, found_lower, found_upper))
98+
if (!tipc_sub_check_overlap(&seq, p->sr.lower, p->sr.upper))
9299
return;
93-
94100
if (!must && !(filter & TIPC_SUB_PORTS))
95101
return;
96-
if (filter & TIPC_SUB_CLUSTER_SCOPE && scope == TIPC_NODE_SCOPE)
102+
if (filter & TIPC_SUB_CLUSTER_SCOPE && p->scope == TIPC_NODE_SCOPE)
97103
return;
98-
if (filter & TIPC_SUB_NODE_SCOPE && scope != TIPC_NODE_SCOPE)
104+
if (filter & TIPC_SUB_NODE_SCOPE && p->scope != TIPC_NODE_SCOPE)
99105
return;
100106
spin_lock(&sub->lock);
101-
tipc_sub_send_event(sub, found_lower, found_upper,
102-
event, port, node);
107+
tipc_sub_send_event(sub, p, event);
103108
spin_unlock(&sub->lock);
104109
}
105110

106111
static void tipc_sub_timeout(struct timer_list *t)
107112
{
108113
struct tipc_subscription *sub = from_timer(sub, t, timer);
109-
struct tipc_subscr *s = &sub->evt.s;
110114

111115
spin_lock(&sub->lock);
112-
tipc_sub_send_event(sub, s->seq.lower, s->seq.upper,
113-
TIPC_SUBSCR_TIMEOUT, 0, 0);
116+
tipc_sub_send_event(sub, NULL, TIPC_SUBSCR_TIMEOUT);
114117
sub->inactive = true;
115118
spin_unlock(&sub->lock);
116119
}

net/tipc/subscr.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2003-2017, Ericsson AB
55
* Copyright (c) 2005-2007, 2012-2013, Wind River Systems
6-
* Copyright (c) 2020, Red Hat Inc
6+
* Copyright (c) 2020-2021, Red Hat Inc
77
* All rights reserved.
88
*
99
* Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,7 @@
4343
#define TIPC_MAX_SUBSCR 65535
4444
#define TIPC_MAX_PUBL 65535
4545

46+
struct publication;
4647
struct tipc_subscription;
4748
struct tipc_conn;
4849

@@ -74,13 +75,9 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net,
7475
struct tipc_subscr *s,
7576
int conid);
7677
void tipc_sub_unsubscribe(struct tipc_subscription *sub);
77-
78-
int tipc_sub_check_overlap(struct tipc_service_range *seq,
79-
u32 found_lower, u32 found_upper);
8078
void tipc_sub_report_overlap(struct tipc_subscription *sub,
81-
u32 found_lower, u32 found_upper,
82-
u32 event, u32 port, u32 node,
83-
u32 scope, int must);
79+
struct publication *p,
80+
u32 event, bool must);
8481

8582
int __net_init tipc_topsrv_init_net(struct net *net);
8683
void __net_exit tipc_topsrv_exit_net(struct net *net);

0 commit comments

Comments
 (0)