Commit 2c98da07 authored by Jon Maloy's avatar Jon Maloy Committed by David S. Miller

tipc: simplify signature of tipc_nametbl_withdraw() functions

Following the principles of the preceding commits, we reduce
the number of parameters passed along in tipc_sk_withdraw(),
tipc_nametbl_withdraw() and associated functions.
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 a45ffa68
...@@ -244,17 +244,19 @@ static void tipc_publ_purge(struct net *net, struct publication *p, u32 addr) ...@@ -244,17 +244,19 @@ static void tipc_publ_purge(struct net *net, struct publication *p, u32 addr)
{ {
struct tipc_net *tn = tipc_net(net); struct tipc_net *tn = tipc_net(net);
struct publication *_p; struct publication *_p;
struct tipc_uaddr ua;
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, p->scope, p->sr.type,
p->sr.lower, p->sr.upper);
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
_p = tipc_nametbl_remove_publ(net, p->sr.type, p->sr.lower, _p = tipc_nametbl_remove_publ(net, &ua, &p->sk, p->key);
p->sr.upper, p->sk.node, p->key);
if (_p) if (_p)
tipc_node_unsubscribe(net, &_p->binding_node, addr); tipc_node_unsubscribe(net, &_p->binding_node, addr);
spin_unlock_bh(&tn->nametbl_lock); spin_unlock_bh(&tn->nametbl_lock);
if (_p != p) { if (_p != p) {
pr_err("Unable to remove publication from failed node\n" pr_err("Unable to remove publication from failed node\n"
" (type=%u, lower=%u, node=0x%x, port=%u, key=%u)\n", " (type=%u, lower=%u, node=%u, port=%u, key=%u)\n",
p->sr.type, p->sr.lower, p->sk.node, p->sk.ref, p->key); p->sr.type, p->sr.lower, p->sk.node, p->sk.ref, p->key);
} }
...@@ -309,8 +311,7 @@ static bool tipc_update_nametbl(struct net *net, struct distr_item *i, ...@@ -309,8 +311,7 @@ static bool tipc_update_nametbl(struct net *net, struct distr_item *i,
return true; return true;
} }
} else if (dtype == WITHDRAWAL) { } else if (dtype == WITHDRAWAL) {
p = tipc_nametbl_remove_publ(net, ua.sr.type, ua.sr.lower, p = tipc_nametbl_remove_publ(net, &ua, &sk, key);
ua.sr.upper, node, key);
if (p) { if (p) {
tipc_node_unsubscribe(net, &p->binding_node, node); tipc_node_unsubscribe(net, &p->binding_node, node);
kfree_rcu(p, rcu); kfree_rcu(p, rcu);
......
...@@ -366,16 +366,18 @@ static bool tipc_service_insert_publ(struct net *net, ...@@ -366,16 +366,18 @@ static bool tipc_service_insert_publ(struct net *net,
/** /**
* tipc_service_remove_publ - remove a publication from a service * tipc_service_remove_publ - remove a publication from a service
* @sr: service_range to remove publication from * @r: service_range to remove publication from
* @node: target node * @sk: address publishing socket
* @key: target publication key * @key: target publication key
*/ */
static struct publication *tipc_service_remove_publ(struct service_range *sr, static struct publication *tipc_service_remove_publ(struct service_range *r,
u32 node, u32 key) struct tipc_socket_addr *sk,
u32 key)
{ {
struct publication *p; struct publication *p;
u32 node = sk->node;
list_for_each_entry(p, &sr->all_publ, all_publ) { list_for_each_entry(p, &r->all_publ, all_publ) {
if (p->key != key || (node && node != p->sk.node)) if (p->key != key || (node && node != p->sk.node))
continue; continue;
list_del(&p->all_publ); list_del(&p->all_publ);
...@@ -493,16 +495,20 @@ struct publication *tipc_nametbl_insert_publ(struct net *net, ...@@ -493,16 +495,20 @@ struct publication *tipc_nametbl_insert_publ(struct net *net,
return NULL; return NULL;
} }
struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, struct publication *tipc_nametbl_remove_publ(struct net *net,
u32 lower, u32 upper, struct tipc_uaddr *ua,
u32 node, u32 key) struct tipc_socket_addr *sk,
u32 key)
{ {
struct tipc_service *sc = tipc_service_find(net, type);
struct tipc_subscription *sub, *tmp; struct tipc_subscription *sub, *tmp;
struct service_range *sr = NULL;
struct publication *p = NULL; struct publication *p = NULL;
struct service_range *sr;
struct tipc_service *sc;
u32 upper = ua->sr.upper;
u32 lower = ua->sr.lower;
bool last; bool last;
sc = tipc_service_find(net, ua->sr.type);
if (!sc) if (!sc)
return NULL; return NULL;
...@@ -510,7 +516,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, ...@@ -510,7 +516,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
sr = tipc_service_find_range(sc, lower, upper); sr = tipc_service_find_range(sc, lower, upper);
if (!sr) if (!sr)
goto exit; goto exit;
p = tipc_service_remove_publ(sr, node, key); p = tipc_service_remove_publ(sr, sk, key);
if (!p) if (!p)
goto exit; goto exit;
...@@ -518,7 +524,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, ...@@ -518,7 +524,7 @@ struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
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, lower, upper, TIPC_WITHDRAWN,
p->sk.ref, node, p->scope, 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 */
...@@ -768,24 +774,22 @@ struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua, ...@@ -768,24 +774,22 @@ struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua,
/** /**
* tipc_nametbl_withdraw - withdraw a service binding * tipc_nametbl_withdraw - withdraw a service binding
* @net: network namespace * @net: network namespace
* @type: service type * @ua: service address/range being unbound
* @lower: service range lower bound * @sk: address of the socket being unbound from
* @upper: service range upper bound
* @key: target publication key * @key: target publication key
*/ */
int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, void tipc_nametbl_withdraw(struct net *net, struct tipc_uaddr *ua,
u32 upper, u32 key) struct tipc_socket_addr *sk, u32 key)
{ {
struct name_table *nt = tipc_name_table(net); struct name_table *nt = tipc_name_table(net);
struct tipc_net *tn = tipc_net(net); struct tipc_net *tn = tipc_net(net);
u32 self = tipc_own_addr(net);
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
struct publication *p; struct publication *p;
u32 rc_dests; u32 rc_dests;
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
p = tipc_nametbl_remove_publ(net, type, lower, upper, self, key); p = tipc_nametbl_remove_publ(net, ua, sk, key);
if (p) { if (p) {
nt->local_publ_count--; nt->local_publ_count--;
skb = tipc_named_withdraw(net, p); skb = tipc_named_withdraw(net, p);
...@@ -793,16 +797,13 @@ int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, ...@@ -793,16 +797,13 @@ int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower,
kfree_rcu(p, rcu); kfree_rcu(p, rcu);
} else { } else {
pr_err("Failed to remove local publication {%u,%u,%u}/%u\n", pr_err("Failed to remove local publication {%u,%u,%u}/%u\n",
type, lower, upper, key); ua->sr.type, ua->sr.lower, ua->sr.upper, key);
} }
rc_dests = nt->rc_dests; rc_dests = nt->rc_dests;
spin_unlock_bh(&tn->nametbl_lock); spin_unlock_bh(&tn->nametbl_lock);
if (skb) { if (skb)
tipc_node_broadcast(net, skb, rc_dests); tipc_node_broadcast(net, skb, rc_dests);
return 1;
}
return 0;
} }
/** /**
...@@ -900,7 +901,7 @@ static void tipc_service_delete(struct net *net, struct tipc_service *sc) ...@@ -900,7 +901,7 @@ static void tipc_service_delete(struct net *net, struct tipc_service *sc)
spin_lock_bh(&sc->lock); spin_lock_bh(&sc->lock);
rbtree_postorder_for_each_entry_safe(sr, tmpr, &sc->ranges, tree_node) { rbtree_postorder_for_each_entry_safe(sr, tmpr, &sc->ranges, tree_node) {
list_for_each_entry_safe(p, tmp, &sr->all_publ, all_publ) { list_for_each_entry_safe(p, tmp, &sr->all_publ, all_publ) {
tipc_service_remove_publ(sr, p->sk.node, p->key); tipc_service_remove_publ(sr, &p->sk, p->key);
kfree_rcu(p, rcu); kfree_rcu(p, rcu);
} }
rb_erase_augmented(&sr->tree_node, &sc->ranges, &sr_callbacks); rb_erase_augmented(&sr->tree_node, &sc->ranges, &sr_callbacks);
......
...@@ -123,15 +123,16 @@ bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 domain, ...@@ -123,15 +123,16 @@ bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 domain,
bool all); bool all);
struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua, struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua,
struct tipc_socket_addr *sk, u32 key); struct tipc_socket_addr *sk, u32 key);
int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 upper, void tipc_nametbl_withdraw(struct net *net, struct tipc_uaddr *ua,
u32 key); struct tipc_socket_addr *sk, u32 key);
struct publication *tipc_nametbl_insert_publ(struct net *net, struct publication *tipc_nametbl_insert_publ(struct net *net,
struct tipc_uaddr *ua, struct tipc_uaddr *ua,
struct tipc_socket_addr *sk, struct tipc_socket_addr *sk,
u32 key); u32 key);
struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, struct publication *tipc_nametbl_remove_publ(struct net *net,
u32 lower, u32 upper, struct tipc_uaddr *ua,
u32 node, u32 key); struct tipc_socket_addr *sk,
u32 key);
bool tipc_nametbl_subscribe(struct tipc_subscription *s); bool tipc_nametbl_subscribe(struct tipc_subscription *s);
void tipc_nametbl_unsubscribe(struct tipc_subscription *s); void tipc_nametbl_unsubscribe(struct tipc_subscription *s);
int tipc_nametbl_init(struct net *net); int tipc_nametbl_init(struct net *net);
......
...@@ -434,8 +434,7 @@ static void tipc_node_write_unlock(struct tipc_node *n) ...@@ -434,8 +434,7 @@ static void tipc_node_write_unlock(struct tipc_node *n)
} }
if (flags & TIPC_NOTIFY_LINK_DOWN) { if (flags & TIPC_NOTIFY_LINK_DOWN) {
tipc_mon_peer_down(net, n->addr, bearer_id); tipc_mon_peer_down(net, n->addr, bearer_id);
tipc_nametbl_withdraw(net, TIPC_LINK_STATE, n->addr, tipc_nametbl_withdraw(net, &ua, &sk, n->link_id);
n->addr, n->link_id);
} }
} }
......
...@@ -152,8 +152,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, ...@@ -152,8 +152,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
bool kern); bool kern);
static void tipc_sk_timeout(struct timer_list *t); static void tipc_sk_timeout(struct timer_list *t);
static int tipc_sk_publish(struct tipc_sock *tsk, struct tipc_uaddr *ua); static int tipc_sk_publish(struct tipc_sock *tsk, struct tipc_uaddr *ua);
static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, static int tipc_sk_withdraw(struct tipc_sock *tsk, struct tipc_uaddr *ua);
struct tipc_service_range const *seq);
static int tipc_sk_leave(struct tipc_sock *tsk); static int tipc_sk_leave(struct tipc_sock *tsk);
static struct tipc_sock *tipc_sk_lookup(struct net *net, u32 portid); static struct tipc_sock *tipc_sk_lookup(struct net *net, u32 portid);
static int tipc_sk_insert(struct tipc_sock *tsk); static int tipc_sk_insert(struct tipc_sock *tsk);
...@@ -643,7 +642,7 @@ static int tipc_release(struct socket *sock) ...@@ -643,7 +642,7 @@ static int tipc_release(struct socket *sock)
__tipc_shutdown(sock, TIPC_ERR_NO_PORT); __tipc_shutdown(sock, TIPC_ERR_NO_PORT);
sk->sk_shutdown = SHUTDOWN_MASK; sk->sk_shutdown = SHUTDOWN_MASK;
tipc_sk_leave(tsk); tipc_sk_leave(tsk);
tipc_sk_withdraw(tsk, 0, NULL); tipc_sk_withdraw(tsk, NULL);
__skb_queue_purge(&tsk->mc_method.deferredq); __skb_queue_purge(&tsk->mc_method.deferredq);
sk_stop_timer(sk, &sk->sk_timer); sk_stop_timer(sk, &sk->sk_timer);
tipc_sk_remove(tsk); tipc_sk_remove(tsk);
...@@ -681,7 +680,7 @@ static int __tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen) ...@@ -681,7 +680,7 @@ static int __tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen)
bool unbind = false; bool unbind = false;
if (unlikely(!alen)) if (unlikely(!alen))
return tipc_sk_withdraw(tsk, 0, NULL); return tipc_sk_withdraw(tsk, NULL);
if (ua->addrtype == TIPC_SERVICE_ADDR) { if (ua->addrtype == TIPC_SERVICE_ADDR) {
ua->addrtype = TIPC_SERVICE_RANGE; ua->addrtype = TIPC_SERVICE_RANGE;
...@@ -699,7 +698,7 @@ static int __tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen) ...@@ -699,7 +698,7 @@ static int __tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen)
return -EACCES; return -EACCES;
if (unbind) if (unbind)
return tipc_sk_withdraw(tsk, ua->scope, &ua->sr); return tipc_sk_withdraw(tsk, ua);
return tipc_sk_publish(tsk, ua); return tipc_sk_publish(tsk, ua);
} }
...@@ -2923,38 +2922,37 @@ static int tipc_sk_publish(struct tipc_sock *tsk, struct tipc_uaddr *ua) ...@@ -2923,38 +2922,37 @@ static int tipc_sk_publish(struct tipc_sock *tsk, struct tipc_uaddr *ua)
return 0; return 0;
} }
static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, static int tipc_sk_withdraw(struct tipc_sock *tsk, struct tipc_uaddr *ua)
struct tipc_service_range const *seq)
{ {
struct net *net = sock_net(&tsk->sk); struct net *net = sock_net(&tsk->sk);
struct publication *p; struct publication *safe, *p;
struct publication *safe; struct tipc_uaddr _ua;
int rc = -EINVAL; int rc = -EINVAL;
if (scope != TIPC_NODE_SCOPE)
scope = TIPC_CLUSTER_SCOPE;
list_for_each_entry_safe(p, safe, &tsk->publications, binding_sock) { list_for_each_entry_safe(p, safe, &tsk->publications, binding_sock) {
if (seq) { if (!ua) {
if (p->scope != scope) tipc_uaddr(&_ua, TIPC_SERVICE_RANGE, p->scope,
continue; p->sr.type, p->sr.lower, p->sr.upper);
if (p->sr.type != seq->type) tipc_nametbl_withdraw(net, &_ua, &p->sk, p->key);
continue; continue;
if (p->sr.lower != seq->lower)
continue;
if (p->sr.upper != seq->upper)
break;
tipc_nametbl_withdraw(net, p->sr.type, p->sr.lower,
p->sr.upper, p->key);
rc = 0;
break;
} }
tipc_nametbl_withdraw(net, p->sr.type, p->sr.lower, /* Unbind specific publication */
p->sr.upper, p->key); if (p->scope != ua->scope)
continue;
if (p->sr.type != ua->sr.type)
continue;
if (p->sr.lower != ua->sr.lower)
continue;
if (p->sr.upper != ua->sr.upper)
break;
tipc_nametbl_withdraw(net, ua, &p->sk, p->key);
rc = 0; rc = 0;
break;
} }
if (list_empty(&tsk->publications)) if (list_empty(&tsk->publications)) {
tsk->published = 0; tsk->published = 0;
rc = 0;
}
return rc; return rc;
} }
...@@ -3109,15 +3107,17 @@ static int tipc_sk_leave(struct tipc_sock *tsk) ...@@ -3109,15 +3107,17 @@ static int tipc_sk_leave(struct tipc_sock *tsk)
{ {
struct net *net = sock_net(&tsk->sk); struct net *net = sock_net(&tsk->sk);
struct tipc_group *grp = tsk->group; struct tipc_group *grp = tsk->group;
struct tipc_service_range seq; struct tipc_uaddr ua;
int scope; int scope;
if (!grp) if (!grp)
return -EINVAL; return -EINVAL;
tipc_group_self(grp, &seq, &scope); ua.addrtype = TIPC_SERVICE_RANGE;
tipc_group_self(grp, &ua.sr, &scope);
ua.scope = scope;
tipc_group_delete(net, grp); tipc_group_delete(net, grp);
tsk->group = NULL; tsk->group = NULL;
tipc_sk_withdraw(tsk, scope, &seq); tipc_sk_withdraw(tsk, &ua);
return 0; return 0;
} }
......
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