Commit 242e82cc authored by Jon Maloy's avatar Jon Maloy Committed by David S. Miller

tipc: collapse subscription creation functions

After the previous changes it becomes logical to collapse the two-level
creation of subscription instances into one. We do that here.

We also rename the creation and deletion functions for more consistency.
Acked-by: default avatarYing Xue <ying.xue@windriver.com>
Signed-off-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8985ecc7
...@@ -203,7 +203,7 @@ static void tipc_con_delete_sub(struct tipc_conn *con, struct tipc_subscr *s) ...@@ -203,7 +203,7 @@ static void tipc_con_delete_sub(struct tipc_conn *con, struct tipc_subscr *s)
spin_lock_bh(&con->sub_lock); spin_lock_bh(&con->sub_lock);
list_for_each_entry_safe(sub, tmp, sub_list, subscrp_list) { list_for_each_entry_safe(sub, tmp, sub_list, subscrp_list) {
if (!s || !memcmp(s, &sub->evt.s, sizeof(*s))) if (!s || !memcmp(s, &sub->evt.s, sizeof(*s)))
tipc_sub_delete(sub); tipc_sub_unsubscribe(sub);
else if (s) else if (s)
break; break;
} }
...@@ -278,7 +278,7 @@ static int tipc_con_rcv_sub(struct tipc_server *srv, ...@@ -278,7 +278,7 @@ static int tipc_con_rcv_sub(struct tipc_server *srv,
tipc_con_delete_sub(con, s); tipc_con_delete_sub(con, s);
return 0; return 0;
} }
sub = tipc_subscrp_subscribe(srv, s, con->conid); sub = tipc_sub_subscribe(srv, s, con->conid);
if (!sub) if (!sub)
return -1; return -1;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* net/tipc/server.h: Include file for TIPC server code * net/tipc/server.h: Include file for TIPC server code
* *
* Copyright (c) 2012-2013, Wind River Systems * Copyright (c) 2012-2013, Wind River Systems
* Copyright (c) 2017, Ericsson AB
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
......
...@@ -134,33 +134,29 @@ void tipc_subscrp_get(struct tipc_subscription *subscription) ...@@ -134,33 +134,29 @@ void tipc_subscrp_get(struct tipc_subscription *subscription)
kref_get(&subscription->kref); kref_get(&subscription->kref);
} }
static struct tipc_subscription *tipc_subscrp_create(struct tipc_server *srv, struct tipc_subscription *tipc_sub_subscribe(struct tipc_server *srv,
struct tipc_subscr *s, struct tipc_subscr *s,
int conid) int conid)
{ {
struct tipc_net *tn = tipc_net(srv->net); struct tipc_net *tn = tipc_net(srv->net);
struct tipc_subscription *sub; struct tipc_subscription *sub;
u32 filter = tipc_sub_read(s, filter); u32 filter = tipc_sub_read(s, filter);
u32 timeout;
/* Refuse subscription if global limit exceeded */ if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCR) {
if (atomic_read(&tn->subscription_count) >= TIPC_MAX_SUBSCRIPTIONS) { pr_warn("Subscription rejected, max (%u)\n", TIPC_MAX_SUBSCR);
pr_warn("Subscription rejected, limit reached (%u)\n", return NULL;
TIPC_MAX_SUBSCRIPTIONS); }
if ((filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE) ||
(tipc_sub_read(s, seq.lower) > tipc_sub_read(s, seq.upper))) {
pr_warn("Subscription rejected, illegal request\n");
return NULL; return NULL;
} }
/* Allocate subscription object */
sub = kmalloc(sizeof(*sub), GFP_ATOMIC); sub = kmalloc(sizeof(*sub), GFP_ATOMIC);
if (!sub) { if (!sub) {
pr_warn("Subscription rejected, no memory\n"); pr_warn("Subscription rejected, no memory\n");
return NULL; return NULL;
} }
/* Initialize subscription object */
if (filter & TIPC_SUB_PORTS && filter & TIPC_SUB_SERVICE)
goto err;
if (tipc_sub_read(s, seq.lower) > tipc_sub_read(s, seq.upper))
goto err;
sub->server = srv; sub->server = srv;
sub->conid = conid; sub->conid = conid;
sub->inactive = false; sub->inactive = false;
...@@ -168,24 +164,6 @@ static struct tipc_subscription *tipc_subscrp_create(struct tipc_server *srv, ...@@ -168,24 +164,6 @@ static struct tipc_subscription *tipc_subscrp_create(struct tipc_server *srv,
spin_lock_init(&sub->lock); spin_lock_init(&sub->lock);
atomic_inc(&tn->subscription_count); atomic_inc(&tn->subscription_count);
kref_init(&sub->kref); kref_init(&sub->kref);
return sub;
err:
pr_warn("Subscription rejected, illegal request\n");
kfree(sub);
return NULL;
}
struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv,
struct tipc_subscr *s,
int conid)
{
struct tipc_subscription *sub = NULL;
u32 timeout;
sub = tipc_subscrp_create(srv, s, conid);
if (!sub)
return NULL;
tipc_nametbl_subscribe(sub); tipc_nametbl_subscribe(sub);
timer_setup(&sub->timer, tipc_subscrp_timeout, 0); timer_setup(&sub->timer, tipc_subscrp_timeout, 0);
timeout = tipc_sub_read(&sub->evt.s, timeout); timeout = tipc_sub_read(&sub->evt.s, timeout);
...@@ -194,7 +172,7 @@ struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv, ...@@ -194,7 +172,7 @@ struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv,
return sub; return sub;
} }
void tipc_sub_delete(struct tipc_subscription *sub) void tipc_sub_unsubscribe(struct tipc_subscription *sub)
{ {
tipc_nametbl_unsubscribe(sub); tipc_nametbl_unsubscribe(sub);
if (sub->evt.s.timeout != TIPC_WAIT_FOREVER) if (sub->evt.s.timeout != TIPC_WAIT_FOREVER)
......
/* /*
* net/tipc/subscr.h: Include file for TIPC network topology service * net/tipc/subscr.h: Include file for TIPC network topology service
* *
* Copyright (c) 2003-2006, Ericsson AB * Copyright (c) 2003-2017, Ericsson AB
* Copyright (c) 2005-2007, 2012-2013, Wind River Systems * Copyright (c) 2005-2007, 2012-2013, Wind River Systems
* All rights reserved. * All rights reserved.
* *
...@@ -39,8 +39,8 @@ ...@@ -39,8 +39,8 @@
#include "server.h" #include "server.h"
#define TIPC_MAX_SUBSCRIPTIONS 65535 #define TIPC_MAX_SUBSCR 65535
#define TIPC_MAX_PUBLICATIONS 65535 #define TIPC_MAX_PUBLICATIONS 65535
struct tipc_subscription; struct tipc_subscription;
struct tipc_conn; struct tipc_conn;
...@@ -66,10 +66,10 @@ struct tipc_subscription { ...@@ -66,10 +66,10 @@ struct tipc_subscription {
spinlock_t lock; /* serialize up/down and timer events */ spinlock_t lock; /* serialize up/down and timer events */
}; };
struct tipc_subscription *tipc_subscrp_subscribe(struct tipc_server *srv, struct tipc_subscription *tipc_sub_subscribe(struct tipc_server *srv,
struct tipc_subscr *s, struct tipc_subscr *s,
int conid); int conid);
void tipc_sub_delete(struct tipc_subscription *sub); void tipc_sub_unsubscribe(struct tipc_subscription *sub);
int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower, int tipc_subscrp_check_overlap(struct tipc_name_seq *seq, u32 found_lower,
u32 found_upper); u32 found_upper);
......
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