On Wed, Dec 9, 2020 at 2:51 AM <jma...@redhat.com> wrote: > > From: Jon Maloy <jma...@redhat.com> > > We reduce the signature of tipc_find_service() and > tipc_create_service(). The reason for doing this might not > be obvious, but we plan to let struct tipc_uaddr contain > information that is relevant for these functions in a later > commit. > > Signed-off-by: Jon Maloy <jma...@redhat.com> > --- > net/tipc/name_table.c | 58 ++++++++++++++++++++++++++----------------- > net/tipc/name_table.h | 2 +- > net/tipc/socket.c | 2 +- > 3 files changed, 37 insertions(+), 25 deletions(-) > > diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c > index 57abed74d0d9..554a006d7c0d 100644 > --- a/net/tipc/name_table.c > +++ b/net/tipc/name_table.c > @@ -255,20 +255,25 @@ static struct publication *tipc_publ_create(struct > tipc_uaddr *ua, > * > * Allocates a single range structure and sets it to all 0's. > */ > -static struct tipc_service *tipc_service_create(u32 type, struct hlist_head > *hd) > +static struct tipc_service *tipc_service_create(struct net *net, > + struct tipc_uaddr *ua) is that too much to pass 'ua' pointer if only 'type' is being used here?
> { > - struct tipc_service *service = kzalloc(sizeof(*service), GFP_ATOMIC); > + struct name_table *nt = tipc_name_table(net); > + struct tipc_service *service; > + struct hlist_head *hd; > > + service = kzalloc(sizeof(*service), GFP_ATOMIC); > if (!service) { > pr_warn("Service creation failed, no memory\n"); > return NULL; > } > > spin_lock_init(&service->lock); > - service->type = type; > + service->type = ua->sr.type; > service->ranges = RB_ROOT; > INIT_HLIST_NODE(&service->service_list); > INIT_LIST_HEAD(&service->subscriptions); > + hd = &nt->services[hash(ua->sr.type)]; > hlist_add_head_rcu(&service->service_list, hd); > return service; > } > @@ -453,15 +458,16 @@ static void tipc_service_subscribe(struct tipc_service > *service, > } > } > > -static struct tipc_service *tipc_service_find(struct net *net, u32 type) > +static struct tipc_service *tipc_service_find(struct net *net, > + struct tipc_uaddr *ua) > { > struct name_table *nt = tipc_name_table(net); > struct hlist_head *service_head; > struct tipc_service *service; > > - service_head = &nt->services[hash(type)]; > + service_head = &nt->services[hash(ua->sr.type)]; > hlist_for_each_entry_rcu(service, service_head, service_list) { > - if (service->type == type) > + if (service->type == ua->sr.type) > return service; > } > return NULL; > @@ -472,7 +478,6 @@ struct publication *tipc_nametbl_insert_publ(struct net > *net, > struct tipc_socket_addr *sk, > u32 key) > { > - struct name_table *nt = tipc_name_table(net); > struct tipc_service *sc; > struct publication *p; > u32 type = ua->sr.type; > @@ -487,9 +492,9 @@ struct publication *tipc_nametbl_insert_publ(struct net > *net, > type, ua->sr.lower, ua->sr.upper, sk->node); > return NULL; > } > - sc = tipc_service_find(net, type); > + sc = tipc_service_find(net, ua); > if (!sc) > - sc = tipc_service_create(type, &nt->services[hash(type)]); > + sc = tipc_service_create(net, ua); > if (sc) { > spin_lock_bh(&sc->lock); > res = tipc_service_insert_publ(net, sc, p); > @@ -512,7 +517,7 @@ struct publication *tipc_nametbl_remove_publ(struct net > *net, > struct tipc_service *sc; > bool last; > > - sc = tipc_service_find(net, ua->sr.type); > + sc = tipc_service_find(net, ua); > if (!sc) > return NULL; > > @@ -585,7 +590,7 @@ bool tipc_nametbl_lookup_anycast(struct net *net, > return true; > > rcu_read_lock(); > - sc = tipc_service_find(net, ua->sr.type); > + sc = tipc_service_find(net, ua); > if (unlikely(!sc)) > goto exit; > > @@ -638,7 +643,7 @@ bool tipc_nametbl_lookup_group(struct net *net, struct > tipc_uaddr *ua, > > *dstcnt = 0; > rcu_read_lock(); > - sc = tipc_service_find(net, ua->sa.type); > + sc = tipc_service_find(net, ua); > if (unlikely(!sc)) > goto exit; > > @@ -682,7 +687,7 @@ void tipc_nametbl_lookup_mcast_sockets(struct net *net, > struct tipc_uaddr *ua, > u32 scope = ua->scope; > > rcu_read_lock(); > - sc = tipc_service_find(net, ua->sr.type); > + sc = tipc_service_find(net, ua); > if (!sc) > goto exit; > > @@ -711,7 +716,7 @@ void tipc_nametbl_lookup_mcast_nodes(struct net *net, > struct tipc_uaddr *ua, > struct publication *p; > > rcu_read_lock(); > - sc = tipc_service_find(net, ua->sr.type); > + sc = tipc_service_find(net, ua); > if (!sc) > goto exit; > > @@ -729,7 +734,7 @@ void tipc_nametbl_lookup_mcast_nodes(struct net *net, > struct tipc_uaddr *ua, > /* tipc_nametbl_build_group - build list of communication group members > */ > void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp, > - u32 type, u32 scope) > + struct tipc_uaddr *ua) > { > struct service_range *sr; > struct tipc_service *sc; > @@ -737,7 +742,7 @@ void tipc_nametbl_build_group(struct net *net, struct > tipc_group *grp, > struct rb_node *n; > > rcu_read_lock(); > - sc = tipc_service_find(net, type); > + sc = tipc_service_find(net, ua); > if (!sc) > goto exit; > > @@ -745,9 +750,10 @@ void tipc_nametbl_build_group(struct net *net, struct > tipc_group *grp, > for (n = rb_first(&sc->ranges); n; n = rb_next(n)) { > sr = container_of(n, struct service_range, tree_node); > list_for_each_entry(p, &sr->all_publ, all_publ) { > - if (p->scope != scope) > + if (p->scope != ua->scope) > continue; > - tipc_group_add_member(grp, p->sk.node, p->sk.ref, > p->sr.lower); > + tipc_group_add_member(grp, p->sk.node, p->sk.ref, > + p->sr.lower); > } > } > spin_unlock_bh(&sc->lock); > @@ -829,17 +835,18 @@ void tipc_nametbl_withdraw(struct net *net, struct > tipc_uaddr *ua, > */ > bool tipc_nametbl_subscribe(struct tipc_subscription *sub) > { > - struct name_table *nt = tipc_name_table(sub->net); > struct tipc_net *tn = tipc_net(sub->net); > struct tipc_subscr *s = &sub->evt.s; > u32 type = tipc_sub_read(s, seq.type); > struct tipc_service *sc; > + struct tipc_uaddr ua; > bool res = true; > > + tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type, 0, 0); > spin_lock_bh(&tn->nametbl_lock); > - sc = tipc_service_find(sub->net, type); > + sc = tipc_service_find(sub->net, &ua); > if (!sc) > - sc = tipc_service_create(type, &nt->services[hash(type)]); > + sc = tipc_service_create(sub->net, &ua); > if (sc) { > spin_lock_bh(&sc->lock); > tipc_service_subscribe(sc, sub); > @@ -864,9 +871,11 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription > *sub) > struct tipc_subscr *s = &sub->evt.s; > u32 type = tipc_sub_read(s, seq.type); > struct tipc_service *sc; > + struct tipc_uaddr ua; > > + tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, type, 0, 0); > spin_lock_bh(&tn->nametbl_lock); > - sc = tipc_service_find(sub->net, type); > + sc = tipc_service_find(sub->net, &ua); > if (!sc) > goto exit; > > @@ -1058,6 +1067,7 @@ static int tipc_nl_service_list(struct net *net, struct > tipc_nl_msg *msg, > struct tipc_net *tn = tipc_net(net); > struct tipc_service *service = NULL; > struct hlist_head *head; > + struct tipc_uaddr ua; > int err; > int i; > > @@ -1071,7 +1081,9 @@ static int tipc_nl_service_list(struct net *net, struct > tipc_nl_msg *msg, > > if (*last_type || > (!i && *last_key && (*last_lower == *last_key))) { > - service = tipc_service_find(net, *last_type); > + tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE, > + *last_type, *last_lower, *last_lower); > + service = tipc_service_find(net, &ua); > if (!service) > return -EPIPE; > } else { > diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h > index 909eaf706553..5b8102e70f3b 100644 > --- a/net/tipc/name_table.h > +++ b/net/tipc/name_table.h > @@ -121,7 +121,7 @@ bool tipc_nametbl_lookup_group(struct net *net, struct > tipc_uaddr *ua, > struct list_head *dsts, int *dstcnt, > u32 exclude, bool mcast); > void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp, > - u32 type, u32 domain); > + struct tipc_uaddr *ua); > struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr > *ua, > struct tipc_socket_addr *sk, u32 > key); > void tipc_nametbl_withdraw(struct net *net, struct tipc_uaddr *ua, > diff --git a/net/tipc/socket.c b/net/tipc/socket.c > index a349160a5ae4..8f1083d3859d 100644 > --- a/net/tipc/socket.c > +++ b/net/tipc/socket.c > @@ -3073,9 +3073,9 @@ static int tipc_sk_join(struct tipc_sock *tsk, struct > tipc_group_req *mreq) > msg_set_lookup_scope(hdr, mreq->scope); > msg_set_nametype(hdr, mreq->type); > msg_set_dest_droppable(hdr, true); > - tipc_nametbl_build_group(net, grp, mreq->type, mreq->scope); > tipc_uaddr(&ua, TIPC_SERVICE_RANGE, mreq->scope, > mreq->type, mreq->instance, mreq->instance); > + tipc_nametbl_build_group(net, grp, &ua); > rc = tipc_sk_publish(tsk, &ua); > if (rc) { > tipc_group_delete(net, grp); > -- > 2.28.0 > > > > _______________________________________________ > tipc-discussion mailing list > tipc-discussion@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/tipc-discussion _______________________________________________ tipc-discussion mailing list tipc-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tipc-discussion