Skip to content

Commit

Permalink
Added more logs for failure cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshgajjala committed Mar 24, 2014
1 parent 0820ac6 commit 7169a41
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 68 deletions.
15 changes: 12 additions & 3 deletions net/tipc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
int new_tlv_space = TLV_SPACE(tlv_data_size);

if (skb_tailroom(buf) < new_tlv_space)
if (skb_tailroom(buf) < new_tlv_space) {
drop_log("Failed to append tlv, no tail room\n");
return 0;
}
skb_put(buf, new_tlv_space);
tlv->tlv_type = htons(tlv_type);
tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
Expand All @@ -86,6 +88,8 @@ static struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
value_net = htonl(value);
tipc_cfg_append_tlv(buf, tlv_type, &value_net,
sizeof(value_net));
} else {
drop_log("Failed to append unsigned tlv, no memory\n");
}
return buf;
}
Expand All @@ -101,8 +105,11 @@ struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
int string_len = strlen(string) + 1;

buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
if (buf)
if (buf) {
tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
} else {
drop_log("Failed to append string tlv, no memory\n");
}
return buf;
}

Expand All @@ -123,8 +130,10 @@ static struct sk_buff *tipc_show_stats(void)
return tipc_cfg_reply_error_string("unsupported argument");

buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
if (buf == NULL)
if (buf == NULL) {
drop_log("Failed to show stats, no memory\n");
return NULL;
}

rep_tlv = (struct tlv_desc *)buf->data;
pb = TLV_DATA(rep_tlv);
Expand Down
6 changes: 5 additions & 1 deletion net/tipc/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ struct tipc_node *tipc_node_find(u32 addr)
{
struct tipc_node *node;

if (unlikely(!in_own_cluster_exact(addr)))
if (unlikely(!in_own_cluster_exact(addr))) {
drop_log("Node not in my cluster\n");
return NULL;
}

hlist_for_each_entry(node, &node_htable[tipc_hashfn(addr)], hash) {
if (node->addr == addr)
Expand Down Expand Up @@ -357,6 +359,7 @@ struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
buf = tipc_cfg_reply_alloc(payload_size);
if (!buf) {
read_unlock_bh(&tipc_net_lock);
drop_log("Failed to create space for all nodes info, no memory\n");
return NULL;
}

Expand Down Expand Up @@ -406,6 +409,7 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
buf = tipc_cfg_reply_alloc(payload_size);
if (!buf) {
read_unlock_bh(&tipc_net_lock);
drop_log("Failed get node links, no memory\n");
return NULL;
}

Expand Down
4 changes: 3 additions & 1 deletion net/tipc/node_subscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ void tipc_nodesub_subscribe(struct tipc_node_subscr *node_sub, u32 addr,
*/
void tipc_nodesub_unsubscribe(struct tipc_node_subscr *node_sub)
{
if (!node_sub->node)
if (!node_sub->node) {
drop_log("Node unsubscription rejected, no node\n");
return;
}

tipc_node_lock(node_sub->node);
list_del_init(&node_sub->nodesub_list);
Expand Down
4 changes: 3 additions & 1 deletion net/tipc/ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ int tipc_ref_table_init(u32 requested_size, u32 start)

/* allocate table & mark all entries as uninitialized */
table = vzalloc(actual_size * sizeof(struct reference));
if (table == NULL)
if (table == NULL) {
drop_log("Failed to create reference table, no memory\n");
return -ENOMEM;
}

tipc_ref_table.entries = table;
tipc_ref_table.capacity = requested_size;
Expand Down
45 changes: 36 additions & 9 deletions net/tipc/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ static struct tipc_conn *tipc_alloc_conn(struct tipc_server *s)
int ret;

con = kzalloc(sizeof(struct tipc_conn), GFP_ATOMIC);
if (!con)
if (!con) {
drop_log("Tipc alloc connection failed, no memory\n");
return ERR_PTR(-ENOMEM);
}

kref_init(&con->kref);
INIT_LIST_HEAD(&con->outqueue);
Expand All @@ -218,6 +220,7 @@ static struct tipc_conn *tipc_alloc_conn(struct tipc_server *s)
if (ret < 0) {
kfree(con);
spin_unlock_bh(&s->idr_lock);
drop_log("Tipc alloc connection failed, idr_alloc failed ret:%d\n", ret);
return ERR_PTR(-ENOMEM);
}
con->conid = ret;
Expand All @@ -242,6 +245,7 @@ static int tipc_receive_from_sock(struct tipc_conn *con)
buf = kmem_cache_alloc(s->rcvbuf_cache, GFP_ATOMIC);
if (!buf) {
ret = -ENOMEM;
drop_log("Failed to recv msg from sock, no memory\n");
goto out_close;
}

Expand Down Expand Up @@ -280,13 +284,16 @@ static int tipc_accept_from_sock(struct tipc_conn *con)
int ret;

ret = tipc_sock_accept_local(sock, &newsock, O_NONBLOCK);
if (ret < 0)
if (ret < 0) {
drop_log("failed accept connection, Err ret:%d\n", ret);
return ret;
}

newcon = tipc_alloc_conn(con->server);
if (IS_ERR(newcon)) {
ret = PTR_ERR(newcon);
sock_release(newsock);
drop_log("failed allocate new connection, ret:%d\n", ret);
return ret;
}

Expand All @@ -308,24 +315,32 @@ static struct socket *tipc_create_listen_sock(struct tipc_conn *con)
int ret;

ret = tipc_sock_create_local(s->type, &sock);
if (ret < 0)
if (ret < 0) {
drop_log("Failed to create local socket, Err ret:%d\n", ret);
return NULL;
}
ret = kernel_setsockopt(sock, SOL_TIPC, TIPC_IMPORTANCE,
(char *)&s->imp, sizeof(s->imp));
if (ret < 0)
if (ret < 0) {
drop_log("Failed to set socket options, Err ret:%d\n", ret);
goto create_err;
}
ret = kernel_bind(sock, (struct sockaddr *)s->saddr, sizeof(*s->saddr));
if (ret < 0)
if (ret < 0) {
drop_log("Failed to bind socket, Err ret:%d\n", ret);
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)
if (ret < 0) {
drop_log("Failed to listen on socket, Err ret:%d\n", ret);
goto create_err;
}
break;
case SOCK_DGRAM:
case SOCK_RDM:
Expand Down Expand Up @@ -357,6 +372,7 @@ static int tipc_open_listening_sock(struct tipc_server *s)
idr_remove(&s->conn_idr, con->conid);
s->idr_in_use--;
kfree(con);
drop_log("Failed to create listen socket\n");
return -EINVAL;
}

Expand All @@ -370,12 +386,15 @@ static struct outqueue_entry *tipc_alloc_entry(void *data, int len)
void *buf;

entry = kmalloc(sizeof(struct outqueue_entry), GFP_ATOMIC);
if (!entry)
if (!entry) {
drop_log("Failed allocate quueue entry , no memory\n");
return NULL;
}

buf = kmalloc(len, GFP_ATOMIC);
if (!buf) {
kfree(entry);
drop_log("Failed allocate entry of len %d, no memory\n", len);
return NULL;
}

Expand Down Expand Up @@ -411,12 +430,15 @@ int tipc_conn_sendmsg(struct tipc_server *s, int conid,
struct tipc_conn *con;

con = tipc_conn_lookup(s, conid);
if (!con)
if (!con) {
drop_log("Failed to send msg, Invalid connection\n");
return -EINVAL;
}

e = tipc_alloc_entry(data, len);
if (!e) {
conn_put(con);
drop_log("Failed allocate entry, no memory\n");
return -ENOMEM;
}

Expand Down Expand Up @@ -476,6 +498,7 @@ static void tipc_send_to_sock(struct tipc_conn *con)
cond_resched();
goto out;
} else if (ret < 0) {
drop_log("kernel send msg failed, Err ret=%d\n", ret);
goto send_err;
}

Expand Down Expand Up @@ -559,18 +582,22 @@ int tipc_server_start(struct tipc_server *s)

s->rcvbuf_cache = kmem_cache_create(s->name, s->max_rcvbuf_size,
0, SLAB_HWCACHE_ALIGN, NULL);
if (!s->rcvbuf_cache)
if (!s->rcvbuf_cache) {
drop_log("Failed to mem cache create, no memory\n");
return -ENOMEM;
}

ret = tipc_work_start(s);
if (ret < 0) {
kmem_cache_destroy(s->rcvbuf_cache);
drop_log("Failed to start work, Err ret:%d\n", ret);
return ret;
}
ret = tipc_open_listening_sock(s);
if (ret < 0) {
tipc_work_stop(s);
kmem_cache_destroy(s->rcvbuf_cache);
drop_log("Failed to open listening socket, Err ret:%d\n", ret);
return ret;
}
return ret;
Expand Down
Loading

0 comments on commit 7169a41

Please sign in to comment.