Skip to content

Commit

Permalink
tipc: remove redundant code in topology server
Browse files Browse the repository at this point in the history
The socket handling in the topology server is unnecessarily generic.
It is prepared to handle both SOCK_RDM, SOCK_DGRAM and SOCK_STREAM
type sockets, as well as the only socket type which is really used,
SOCK_SEQPACKET.

We now remove this redundant code to make the code more readable.

Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jon Maloy authored and David S. Miller committed Feb 16, 2018
1 parent 35ed663 commit 27469b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
36 changes: 7 additions & 29 deletions net/tipc/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ struct tipc_conn {
struct outqueue_entry {
struct list_head list;
struct kvec iov;
struct sockaddr_tipc dest;
};

static void tipc_recv_work(struct work_struct *work);
Expand All @@ -93,7 +92,6 @@ static void tipc_conn_kref_release(struct kref *kref)
{
struct tipc_conn *con = container_of(kref, struct tipc_conn, kref);
struct tipc_server *s = con->server;
struct sockaddr_tipc *saddr = s->saddr;
struct socket *sock = con->sock;
struct sock *sk;

Expand All @@ -103,8 +101,6 @@ static void tipc_conn_kref_release(struct kref *kref)
__module_get(sock->ops->owner);
__module_get(sk->sk_prot_creator->owner);
}
saddr->scope = -TIPC_NODE_SCOPE;
kernel_bind(sock, (struct sockaddr *)saddr, sizeof(*saddr));
sock_release(sock);
con->sock = NULL;
}
Expand Down Expand Up @@ -325,36 +321,24 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con)
{
struct tipc_server *s = con->server;
struct socket *sock = NULL;
int imp = TIPC_CRITICAL_IMPORTANCE;
int ret;

ret = sock_create_kern(s->net, AF_TIPC, SOCK_SEQPACKET, 0, &sock);
if (ret < 0)
return NULL;
ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE,
(char *)&s->imp, sizeof(s->imp));
(char *)&imp, sizeof(imp));
if (ret < 0)
goto create_err;
ret = kernel_bind(sock, (struct sockaddr *)s->saddr, sizeof(*s->saddr));
if (ret < 0)
goto create_err;

switch (s->type) {
case SOCK_STREAM:
case SOCK_SEQPACKET:
con->rx_action = tipc_accept_from_sock;

ret = kernel_listen(sock, 0);
if (ret < 0)
goto create_err;
break;
case SOCK_DGRAM:
case SOCK_RDM:
con->rx_action = tipc_receive_from_sock;
break;
default:
pr_err("Unknown socket type %d\n", s->type);
con->rx_action = tipc_accept_from_sock;
ret = kernel_listen(sock, 0);
if (ret < 0)
goto create_err;
}

/* As server's listening socket owner and creator is the same module,
* we have to decrease TIPC module reference count to guarantee that
Expand Down Expand Up @@ -444,7 +428,7 @@ static void tipc_clean_outqueues(struct tipc_conn *con)
}

int tipc_conn_sendmsg(struct tipc_server *s, int conid,
struct sockaddr_tipc *addr, void *data, size_t len)
void *data, size_t len)
{
struct outqueue_entry *e;
struct tipc_conn *con;
Expand All @@ -464,9 +448,6 @@ int tipc_conn_sendmsg(struct tipc_server *s, int conid,
return -ENOMEM;
}

if (addr)
memcpy(&e->dest, addr, sizeof(struct sockaddr_tipc));

spin_lock_bh(&con->outqueue_lock);
list_add_tail(&e->list, &con->outqueue);
spin_unlock_bh(&con->outqueue_lock);
Expand Down Expand Up @@ -575,10 +556,6 @@ static void tipc_send_to_sock(struct tipc_conn *con)
if (con->sock) {
memset(&msg, 0, sizeof(msg));
msg.msg_flags = MSG_DONTWAIT;
if (s->type == SOCK_DGRAM || s->type == SOCK_RDM) {
msg.msg_name = &e->dest;
msg.msg_namelen = sizeof(struct sockaddr_tipc);
}
ret = kernel_sendmsg(con->sock, &msg, &e->iov, 1,
e->iov.iov_len);
if (ret == -EWOULDBLOCK || ret == 0) {
Expand All @@ -591,6 +568,7 @@ static void tipc_send_to_sock(struct tipc_conn *con)
evt = e->iov.iov_base;
tipc_send_kern_top_evt(s->net, evt);
}

/* Don't starve users filling buffers */
if (++count >= MAX_SEND_MSG_COUNT) {
cond_resched();
Expand Down
4 changes: 1 addition & 3 deletions net/tipc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ struct tipc_server {
void *buf, size_t len);
struct sockaddr_tipc *saddr;
char name[TIPC_SERVER_NAME_LEN];
int imp;
int type;
};

int tipc_conn_sendmsg(struct tipc_server *s, int conid,
struct sockaddr_tipc *addr, void *data, size_t len);
void *data, size_t len);

bool tipc_topsrv_kern_subscr(struct net *net, u32 port, u32 type, u32 lower,
u32 upper, u32 filter, int *conid);
Expand Down
4 changes: 1 addition & 3 deletions net/tipc/subscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static void tipc_subscrp_send_event(struct tipc_subscription *sub,
sub->evt.found_upper = htohl(found_upper, sub->swap);
sub->evt.port.ref = htohl(port_ref, sub->swap);
sub->evt.port.node = htohl(node, sub->swap);
tipc_conn_sendmsg(tn->topsrv, subscriber->conid, NULL,
tipc_conn_sendmsg(tn->topsrv, subscriber->conid,
msg_sect.iov_base, msg_sect.iov_len);
}

Expand Down Expand Up @@ -375,8 +375,6 @@ int tipc_topsrv_start(struct net *net)
}
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 = tipc_subscrb_rcv_cb;
topsrv->tipc_conn_new = tipc_subscrb_connect_cb;
Expand Down

0 comments on commit 27469b7

Please sign in to comment.