Commit a62fbcce authored by Ying Xue's avatar Ying Xue Committed by David S. Miller

tipc: make subscriber server support net namespace

TIPC establishes one subscriber server which allows users to subscribe
their interesting name service status. After tipc supports namespace,
one dedicated tipc stack instance is created for each namespace, and
each instance can be deemed as one independent TIPC node. As a result,
subscriber server must be built for each namespace.
Signed-off-by: default avatarYing Xue <ying.xue@windriver.com>
Tested-by: default avatarTero Aho <Tero.Aho@coriant.com>
Reviewed-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 34747539
...@@ -68,8 +68,14 @@ static int __net_init tipc_init_net(struct net *net) ...@@ -68,8 +68,14 @@ static int __net_init tipc_init_net(struct net *net)
err = tipc_nametbl_init(net); err = tipc_nametbl_init(net);
if (err) if (err)
goto out_nametbl; goto out_nametbl;
err = tipc_subscr_start(net);
if (err)
goto out_subscr;
return 0; return 0;
out_subscr:
tipc_nametbl_stop(net);
out_nametbl: out_nametbl:
tipc_sk_rht_destroy(net); tipc_sk_rht_destroy(net);
out_sk_rht: out_sk_rht:
...@@ -78,6 +84,7 @@ static int __net_init tipc_init_net(struct net *net) ...@@ -78,6 +84,7 @@ static int __net_init tipc_init_net(struct net *net)
static void __net_exit tipc_exit_net(struct net *net) static void __net_exit tipc_exit_net(struct net *net)
{ {
tipc_subscr_stop(net);
tipc_net_stop(net); tipc_net_stop(net);
tipc_nametbl_stop(net); tipc_nametbl_stop(net);
tipc_sk_rht_destroy(net); tipc_sk_rht_destroy(net);
...@@ -104,10 +111,6 @@ static int __init tipc_init(void) ...@@ -104,10 +111,6 @@ static int __init tipc_init(void)
get_random_bytes(&tipc_random, sizeof(tipc_random)); get_random_bytes(&tipc_random, sizeof(tipc_random));
err = register_pernet_subsys(&tipc_net_ops);
if (err)
goto out_pernet;
err = tipc_netlink_start(); err = tipc_netlink_start();
if (err) if (err)
goto out_netlink; goto out_netlink;
...@@ -120,9 +123,9 @@ static int __init tipc_init(void) ...@@ -120,9 +123,9 @@ static int __init tipc_init(void)
if (err) if (err)
goto out_sysctl; goto out_sysctl;
err = tipc_subscr_start(); err = register_pernet_subsys(&tipc_net_ops);
if (err) if (err)
goto out_subscr; goto out_pernet;
err = tipc_bearer_setup(); err = tipc_bearer_setup();
if (err) if (err)
...@@ -131,28 +134,25 @@ static int __init tipc_init(void) ...@@ -131,28 +134,25 @@ static int __init tipc_init(void)
pr_info("Started in single node mode\n"); pr_info("Started in single node mode\n");
return 0; return 0;
out_bearer: out_bearer:
tipc_subscr_stop(); unregister_pernet_subsys(&tipc_net_ops);
out_subscr: out_pernet:
tipc_unregister_sysctl(); tipc_unregister_sysctl();
out_sysctl: out_sysctl:
tipc_socket_stop(); tipc_socket_stop();
out_socket: out_socket:
tipc_netlink_stop(); tipc_netlink_stop();
out_netlink: out_netlink:
unregister_pernet_subsys(&tipc_net_ops);
out_pernet:
pr_err("Unable to start in single node mode\n"); pr_err("Unable to start in single node mode\n");
return err; return err;
} }
static void __exit tipc_exit(void) static void __exit tipc_exit(void)
{ {
unregister_pernet_subsys(&tipc_net_ops);
tipc_bearer_cleanup(); tipc_bearer_cleanup();
tipc_netlink_stop(); tipc_netlink_stop();
tipc_subscr_stop();
tipc_socket_stop(); tipc_socket_stop();
tipc_unregister_sysctl(); tipc_unregister_sysctl();
unregister_pernet_subsys(&tipc_net_ops);
pr_info("Deactivated\n"); pr_info("Deactivated\n");
} }
......
...@@ -106,6 +106,10 @@ struct tipc_net { ...@@ -106,6 +106,10 @@ struct tipc_net {
/* Name table */ /* Name table */
spinlock_t nametbl_lock; spinlock_t nametbl_lock;
struct name_table *nametbl; struct name_table *nametbl;
/* Topology subscription server */
struct tipc_server *topsrv;
atomic_t subscription_count;
}; };
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
......
...@@ -309,7 +309,7 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con) ...@@ -309,7 +309,7 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con)
struct socket *sock = NULL; struct socket *sock = NULL;
int ret; int ret;
ret = tipc_sock_create_local(s->type, &sock); ret = tipc_sock_create_local(s->net, s->type, &sock);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE, ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE,
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
* @conn_idr: identifier set of connection * @conn_idr: identifier set of connection
* @idr_lock: protect the connection identifier set * @idr_lock: protect the connection identifier set
* @idr_in_use: amount of allocated identifier entry * @idr_in_use: amount of allocated identifier entry
* @net: network namspace instance
* @rcvbuf_cache: memory cache of server receive buffer * @rcvbuf_cache: memory cache of server receive buffer
* @rcv_wq: receive workqueue * @rcv_wq: receive workqueue
* @send_wq: send workqueue * @send_wq: send workqueue
...@@ -63,6 +64,7 @@ struct tipc_server { ...@@ -63,6 +64,7 @@ struct tipc_server {
struct idr conn_idr; struct idr conn_idr;
spinlock_t idr_lock; spinlock_t idr_lock;
int idr_in_use; int idr_in_use;
struct net *net;
struct kmem_cache *rcvbuf_cache; struct kmem_cache *rcvbuf_cache;
struct workqueue_struct *rcv_wq; struct workqueue_struct *rcv_wq;
struct workqueue_struct *send_wq; struct workqueue_struct *send_wq;
...@@ -73,7 +75,7 @@ struct tipc_server { ...@@ -73,7 +75,7 @@ struct tipc_server {
struct sockaddr_tipc *addr, void *usr_data, struct sockaddr_tipc *addr, void *usr_data,
void *buf, size_t len); void *buf, size_t len);
struct sockaddr_tipc *saddr; struct sockaddr_tipc *saddr;
const char name[TIPC_SERVER_NAME_LEN]; char name[TIPC_SERVER_NAME_LEN];
int imp; int imp;
int type; int type;
}; };
......
...@@ -388,7 +388,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock, ...@@ -388,7 +388,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
* *
* Returns 0 on success, errno otherwise * Returns 0 on success, errno otherwise
*/ */
int tipc_sock_create_local(int type, struct socket **res) int tipc_sock_create_local(struct net *net, int type, struct socket **res)
{ {
int rc; int rc;
...@@ -397,7 +397,7 @@ int tipc_sock_create_local(int type, struct socket **res) ...@@ -397,7 +397,7 @@ int tipc_sock_create_local(int type, struct socket **res)
pr_err("Failed to create kernel socket\n"); pr_err("Failed to create kernel socket\n");
return rc; return rc;
} }
tipc_sk_create(&init_net, *res, 0, 1); tipc_sk_create(net, *res, 0, 1);
return 0; return 0;
} }
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
int tipc_socket_init(void); int tipc_socket_init(void);
void tipc_socket_stop(void); void tipc_socket_stop(void);
int tipc_sock_create_local(int type, struct socket **res); int tipc_sock_create_local(struct net *net, int type, struct socket **res);
void tipc_sock_release_local(struct socket *sock); void tipc_sock_release_local(struct socket *sock);
int tipc_sock_accept_local(struct socket *sock, struct socket **newsock, int tipc_sock_accept_local(struct socket *sock, struct socket **newsock,
int flags); int flags);
......
...@@ -50,34 +50,6 @@ struct tipc_subscriber { ...@@ -50,34 +50,6 @@ struct tipc_subscriber {
struct list_head subscription_list; struct list_head subscription_list;
}; };
static void subscr_conn_msg_event(struct net *net, int conid,
struct sockaddr_tipc *addr, void *usr_data,
void *buf, size_t len);
static void *subscr_named_msg_event(int conid);
static void subscr_conn_shutdown_event(int conid, void *usr_data);
static atomic_t subscription_count = ATOMIC_INIT(0);
static struct sockaddr_tipc topsrv_addr __read_mostly = {
.family = AF_TIPC,
.addrtype = TIPC_ADDR_NAMESEQ,
.addr.nameseq.type = TIPC_TOP_SRV,
.addr.nameseq.lower = TIPC_TOP_SRV,
.addr.nameseq.upper = TIPC_TOP_SRV,
.scope = TIPC_NODE_SCOPE
};
static struct tipc_server topsrv __read_mostly = {
.saddr = &topsrv_addr,
.imp = TIPC_CRITICAL_IMPORTANCE,
.type = SOCK_SEQPACKET,
.max_rcvbuf_size = sizeof(struct tipc_subscr),
.name = "topology_server",
.tipc_conn_recvmsg = subscr_conn_msg_event,
.tipc_conn_new = subscr_named_msg_event,
.tipc_conn_shutdown = subscr_conn_shutdown_event,
};
/** /**
* htohl - convert value to endianness used by destination * htohl - convert value to endianness used by destination
* @in: value to convert * @in: value to convert
...@@ -94,6 +66,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower, ...@@ -94,6 +66,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper, u32 event, u32 port_ref, u32 found_upper, u32 event, u32 port_ref,
u32 node) u32 node)
{ {
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
struct tipc_subscriber *subscriber = sub->subscriber; struct tipc_subscriber *subscriber = sub->subscriber;
struct kvec msg_sect; struct kvec msg_sect;
...@@ -104,8 +77,8 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower, ...@@ -104,8 +77,8 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
sub->evt.found_upper = htohl(found_upper, sub->swap); sub->evt.found_upper = htohl(found_upper, sub->swap);
sub->evt.port.ref = htohl(port_ref, sub->swap); sub->evt.port.ref = htohl(port_ref, sub->swap);
sub->evt.port.node = htohl(node, sub->swap); sub->evt.port.node = htohl(node, sub->swap);
tipc_conn_sendmsg(&topsrv, subscriber->conid, NULL, msg_sect.iov_base, tipc_conn_sendmsg(tn->topsrv, subscriber->conid, NULL,
msg_sect.iov_len); msg_sect.iov_base, msg_sect.iov_len);
} }
/** /**
...@@ -146,6 +119,7 @@ static void subscr_timeout(unsigned long data) ...@@ -146,6 +119,7 @@ static void subscr_timeout(unsigned long data)
{ {
struct tipc_subscription *sub = (struct tipc_subscription *)data; struct tipc_subscription *sub = (struct tipc_subscription *)data;
struct tipc_subscriber *subscriber = sub->subscriber; struct tipc_subscriber *subscriber = sub->subscriber;
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
/* The spin lock per subscriber is used to protect its members */ /* The spin lock per subscriber is used to protect its members */
spin_lock_bh(&subscriber->lock); spin_lock_bh(&subscriber->lock);
...@@ -170,7 +144,7 @@ static void subscr_timeout(unsigned long data) ...@@ -170,7 +144,7 @@ static void subscr_timeout(unsigned long data)
/* Now destroy subscription */ /* Now destroy subscription */
kfree(sub); kfree(sub);
atomic_dec(&subscription_count); atomic_dec(&tn->subscription_count);
} }
/** /**
...@@ -180,10 +154,12 @@ static void subscr_timeout(unsigned long data) ...@@ -180,10 +154,12 @@ static void subscr_timeout(unsigned long data)
*/ */
static void subscr_del(struct tipc_subscription *sub) static void subscr_del(struct tipc_subscription *sub)
{ {
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
tipc_nametbl_unsubscribe(sub); tipc_nametbl_unsubscribe(sub);
list_del(&sub->subscription_list); list_del(&sub->subscription_list);
kfree(sub); kfree(sub);
atomic_dec(&subscription_count); atomic_dec(&tn->subscription_count);
} }
/** /**
...@@ -191,9 +167,12 @@ static void subscr_del(struct tipc_subscription *sub) ...@@ -191,9 +167,12 @@ static void subscr_del(struct tipc_subscription *sub)
* *
* Note: Must call it in process context since it might sleep. * Note: Must call it in process context since it might sleep.
*/ */
static void subscr_terminate(struct tipc_subscriber *subscriber) static void subscr_terminate(struct tipc_subscription *sub)
{ {
tipc_conn_terminate(&topsrv, subscriber->conid); struct tipc_subscriber *subscriber = sub->subscriber;
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
tipc_conn_terminate(tn->topsrv, subscriber->conid);
} }
static void subscr_release(struct tipc_subscriber *subscriber) static void subscr_release(struct tipc_subscriber *subscriber)
...@@ -263,7 +242,9 @@ static void subscr_cancel(struct tipc_subscr *s, ...@@ -263,7 +242,9 @@ static void subscr_cancel(struct tipc_subscr *s,
*/ */
static int subscr_subscribe(struct net *net, struct tipc_subscr *s, static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
struct tipc_subscriber *subscriber, struct tipc_subscriber *subscriber,
struct tipc_subscription **sub_p) { struct tipc_subscription **sub_p)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct tipc_subscription *sub; struct tipc_subscription *sub;
int swap; int swap;
...@@ -278,7 +259,7 @@ static int subscr_subscribe(struct net *net, struct tipc_subscr *s, ...@@ -278,7 +259,7 @@ static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
} }
/* Refuse subscription if global limit exceeded */ /* Refuse subscription if global limit exceeded */
if (atomic_read(&subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) { if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) {
pr_warn("Subscription rejected, limit reached (%u)\n", pr_warn("Subscription rejected, limit reached (%u)\n",
TIPC_MAX_SUBSCRIPTIONS); TIPC_MAX_SUBSCRIPTIONS);
return -EINVAL; return -EINVAL;
...@@ -309,7 +290,7 @@ static int subscr_subscribe(struct net *net, struct tipc_subscr *s, ...@@ -309,7 +290,7 @@ static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
sub->subscriber = subscriber; sub->subscriber = subscriber;
sub->swap = swap; sub->swap = swap;
memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr)); memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr));
atomic_inc(&subscription_count); atomic_inc(&tn->subscription_count);
if (sub->timeout != TIPC_WAIT_FOREVER) { if (sub->timeout != TIPC_WAIT_FOREVER) {
setup_timer(&sub->timer, subscr_timeout, (unsigned long)sub); setup_timer(&sub->timer, subscr_timeout, (unsigned long)sub);
mod_timer(&sub->timer, jiffies + sub->timeout); mod_timer(&sub->timer, jiffies + sub->timeout);
...@@ -336,7 +317,7 @@ static void subscr_conn_msg_event(struct net *net, int conid, ...@@ -336,7 +317,7 @@ static void subscr_conn_msg_event(struct net *net, int conid,
if (subscr_subscribe(net, (struct tipc_subscr *)buf, subscriber, if (subscr_subscribe(net, (struct tipc_subscr *)buf, subscriber,
&sub) < 0) { &sub) < 0) {
spin_unlock_bh(&subscriber->lock); spin_unlock_bh(&subscriber->lock);
subscr_terminate(subscriber); subscr_terminate(sub);
return; return;
} }
if (sub) if (sub)
...@@ -344,7 +325,6 @@ static void subscr_conn_msg_event(struct net *net, int conid, ...@@ -344,7 +325,6 @@ static void subscr_conn_msg_event(struct net *net, int conid,
spin_unlock_bh(&subscriber->lock); spin_unlock_bh(&subscriber->lock);
} }
/* Handle one request to establish a new subscriber */ /* Handle one request to establish a new subscriber */
static void *subscr_named_msg_event(int conid) static void *subscr_named_msg_event(int conid)
{ {
...@@ -363,12 +343,50 @@ static void *subscr_named_msg_event(int conid) ...@@ -363,12 +343,50 @@ static void *subscr_named_msg_event(int conid)
return (void *)subscriber; return (void *)subscriber;
} }
int tipc_subscr_start(void) int tipc_subscr_start(struct net *net)
{ {
return tipc_server_start(&topsrv); 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->imp = TIPC_CRITICAL_IMPORTANCE;
topsrv->type = SOCK_SEQPACKET;
topsrv->max_rcvbuf_size = sizeof(struct tipc_subscr);
topsrv->tipc_conn_recvmsg = subscr_conn_msg_event;
topsrv->tipc_conn_new = subscr_named_msg_event;
topsrv->tipc_conn_shutdown = subscr_conn_shutdown_event;
strncpy(topsrv->name, name, strlen(name) + 1);
tn->topsrv = topsrv;
atomic_set(&tn->subscription_count, 0);
return tipc_server_start(topsrv);
} }
void tipc_subscr_stop(void) void tipc_subscr_stop(struct net *net)
{ {
tipc_server_stop(&topsrv); 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);
} }
...@@ -74,13 +74,10 @@ struct tipc_subscription { ...@@ -74,13 +74,10 @@ struct tipc_subscription {
int tipc_subscr_overlap(struct tipc_subscription *sub, u32 found_lower, int tipc_subscr_overlap(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper); u32 found_upper);
void tipc_subscr_report_overlap(struct tipc_subscription *sub, u32 found_lower, void tipc_subscr_report_overlap(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper, u32 event, u32 port_ref, u32 found_upper, u32 event, u32 port_ref,
u32 node, int must); u32 node, int must);
int tipc_subscr_start(struct net *net);
int tipc_subscr_start(void); void tipc_subscr_stop(struct net *net);
void tipc_subscr_stop(void);
#endif #endif
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