Skip to content

Commit

Permalink
tipc: rename functions defined in subscr.c
Browse files Browse the repository at this point in the history
When a topology server accepts a connection request from its client,
it allocates a connection instance and a tipc_subscriber structure
object. The former is used to communicate with client, and the latter
is often treated as a subscriber which manages all subscription events
requested from a same client. When a topology server receives a request
of subscribing name services from a client through the connection, it
creates a tipc_subscription structure instance which is seen as a
subscription recording what name services are subscribed. In order to
manage all subscriptions from a same client, topology server links
them into the subscrp_list of the subscriber. So subscriber and
subscription completely represents different meanings respectively,
but function names associated with them make us so confused that we
are unable to easily tell which function is against subscriber and
which is to subscription. So we want to eliminate the confusion by
renaming them.

Signed-off-by: Ying Xue <[email protected]>
Reviewed-by: Jon Maloy <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
ying-xue authored and davem330 committed May 4, 2015
1 parent 29a1ff6 commit 57f1d18
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 97 deletions.
4 changes: 2 additions & 2 deletions net/tipc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int __net_init tipc_init_net(struct net *net)
if (err)
goto out_nametbl;

err = tipc_subscr_start(net);
err = tipc_topsrv_start(net);
if (err)
goto out_subscr;
return 0;
Expand All @@ -83,7 +83,7 @@ static int __net_init tipc_init_net(struct net *net)

static void __net_exit tipc_exit_net(struct net *net)
{
tipc_subscr_stop(net);
tipc_topsrv_stop(net);
tipc_net_stop(net);
tipc_nametbl_stop(net);
tipc_sk_rht_destroy(net);
Expand Down
34 changes: 12 additions & 22 deletions net/tipc/name_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,9 @@ static struct publication *tipc_nameseq_insert_publ(struct net *net,

/* Any subscriptions waiting for notification? */
list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
tipc_subscr_report_overlap(s,
publ->lower,
publ->upper,
TIPC_PUBLISHED,
publ->ref,
publ->node,
created_subseq);
tipc_subscrp_report_overlap(s, publ->lower, publ->upper,
TIPC_PUBLISHED, publ->ref,
publ->node, created_subseq);
}
return publ;
}
Expand Down Expand Up @@ -404,13 +400,9 @@ static struct publication *tipc_nameseq_remove_publ(struct net *net,

/* Notify any waiting subscriptions */
list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
tipc_subscr_report_overlap(s,
publ->lower,
publ->upper,
TIPC_WITHDRAWN,
publ->ref,
publ->node,
removed_subseq);
tipc_subscrp_report_overlap(s, publ->lower, publ->upper,
TIPC_WITHDRAWN, publ->ref,
publ->node, removed_subseq);
}

return publ;
Expand All @@ -432,19 +424,17 @@ static void tipc_nameseq_subscribe(struct name_seq *nseq,
return;

while (sseq != &nseq->sseqs[nseq->first_free]) {
if (tipc_subscr_overlap(s, sseq->lower, sseq->upper)) {
if (tipc_subscrp_check_overlap(s, sseq->lower, sseq->upper)) {
struct publication *crs;
struct name_info *info = sseq->info;
int must_report = 1;

list_for_each_entry(crs, &info->zone_list, zone_list) {
tipc_subscr_report_overlap(s,
sseq->lower,
sseq->upper,
TIPC_PUBLISHED,
crs->ref,
crs->node,
must_report);
tipc_subscrp_report_overlap(s, sseq->lower,
sseq->upper,
TIPC_PUBLISHED,
crs->ref, crs->node,
must_report);
must_report = 0;
}
}
Expand Down
116 changes: 52 additions & 64 deletions net/tipc/subscr.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
* struct tipc_subscriber - TIPC network topology subscriber
* @conid: connection identifier to server connecting to subscriber
* @lock: control access to subscriber
* @subscription_list: list of subscription objects for this subscriber
* @subscrp_list: list of subscription objects for this subscriber
*/
struct tipc_subscriber {
int conid;
spinlock_t lock;
struct list_head subscription_list;
struct list_head subscrp_list;
};

/**
Expand All @@ -62,9 +62,9 @@ static u32 htohl(u32 in, int swap)
return swap ? swab32(in) : in;
}

static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper, u32 event, u32 port_ref,
u32 node)
static void tipc_subscrp_send_event(struct tipc_subscription *sub,
u32 found_lower, u32 found_upper,
u32 event, u32 port_ref, u32 node)
{
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);
struct tipc_subscriber *subscriber = sub->subscriber;
Expand All @@ -82,12 +82,13 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
}

/**
* tipc_subscr_overlap - test for subscription overlap with the given values
* tipc_subscrp_check_overlap - test for subscription overlap with the
* given values
*
* Returns 1 if there is overlap, otherwise 0.
*/
int tipc_subscr_overlap(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper)
int tipc_subscrp_check_overlap(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper)
{
if (found_lower < sub->seq.lower)
found_lower = sub->seq.lower;
Expand All @@ -98,24 +99,20 @@ int tipc_subscr_overlap(struct tipc_subscription *sub, u32 found_lower,
return 1;
}

/**
* tipc_subscr_report_overlap - issue event if there is subscription overlap
*
* Protected by nameseq.lock in name_table.c
*/
void tipc_subscr_report_overlap(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper, u32 event, u32 port_ref,
u32 node, int must)
void tipc_subscrp_report_overlap(struct tipc_subscription *sub, u32 found_lower,
u32 found_upper, u32 event, u32 port_ref,
u32 node, int must)
{
if (!tipc_subscr_overlap(sub, found_lower, found_upper))
if (!tipc_subscrp_check_overlap(sub, found_lower, found_upper))
return;
if (!must && !(sub->filter & TIPC_SUB_PORTS))
return;

subscr_send_event(sub, found_lower, found_upper, event, port_ref, node);
tipc_subscrp_send_event(sub, found_lower, found_upper, event, port_ref,
node);
}

static void subscr_timeout(unsigned long data)
static void tipc_subscrp_timeout(unsigned long data)
{
struct tipc_subscription *sub = (struct tipc_subscription *)data;
struct tipc_subscriber *subscriber = sub->subscriber;
Expand All @@ -134,50 +131,45 @@ static void subscr_timeout(unsigned long data)
tipc_nametbl_unsubscribe(sub);

/* Unlink subscription from subscriber */
list_del(&sub->subscription_list);
list_del(&sub->subscrp_list);

spin_unlock_bh(&subscriber->lock);

/* Notify subscriber of timeout */
subscr_send_event(sub, sub->evt.s.seq.lower, sub->evt.s.seq.upper,
TIPC_SUBSCR_TIMEOUT, 0, 0);
tipc_subscrp_send_event(sub, sub->evt.s.seq.lower, sub->evt.s.seq.upper,
TIPC_SUBSCR_TIMEOUT, 0, 0);

/* Now destroy subscription */
kfree(sub);
atomic_dec(&tn->subscription_count);
}

/**
* subscr_del - delete a subscription within a subscription list
*
* Called with subscriber lock held.
*/
static void subscr_del(struct tipc_subscription *sub)
static void tipc_subscrp_delete(struct tipc_subscription *sub)
{
struct tipc_net *tn = net_generic(sub->net, tipc_net_id);

tipc_nametbl_unsubscribe(sub);
list_del(&sub->subscription_list);
list_del(&sub->subscrp_list);
kfree(sub);
atomic_dec(&tn->subscription_count);
}

static void subscr_release(struct tipc_subscriber *subscriber)
static void tipc_subscrb_delete(struct tipc_subscriber *subscriber)
{
struct tipc_subscription *sub;
struct tipc_subscription *sub_temp;

spin_lock_bh(&subscriber->lock);

/* Destroy any existing subscriptions for subscriber */
list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
subscription_list) {
list_for_each_entry_safe(sub, sub_temp, &subscriber->subscrp_list,
subscrp_list) {
if (sub->timeout != TIPC_WAIT_FOREVER) {
spin_unlock_bh(&subscriber->lock);
del_timer_sync(&sub->timer);
spin_lock_bh(&subscriber->lock);
}
subscr_del(sub);
tipc_subscrp_delete(sub);
}
spin_unlock_bh(&subscriber->lock);

Expand All @@ -186,24 +178,24 @@ static void subscr_release(struct tipc_subscriber *subscriber)
}

/**
* subscr_cancel - handle subscription cancellation request
* tipc_subscrp_cancel - handle subscription cancellation request
*
* Called with subscriber lock held. Routine must temporarily release lock
* to enable the subscription timeout routine to finish without deadlocking;
* the lock is then reclaimed to allow caller to release it upon return.
*
* Note that fields of 's' use subscriber's endianness!
*/
static void subscr_cancel(struct tipc_subscr *s,
struct tipc_subscriber *subscriber)
static void tipc_subscrp_cancel(struct tipc_subscr *s,
struct tipc_subscriber *subscriber)
{
struct tipc_subscription *sub;
struct tipc_subscription *sub_temp;
int found = 0;

/* Find first matching subscription, exit if not found */
list_for_each_entry_safe(sub, sub_temp, &subscriber->subscription_list,
subscription_list) {
list_for_each_entry_safe(sub, sub_temp, &subscriber->subscrp_list,
subscrp_list) {
if (!memcmp(s, &sub->evt.s, sizeof(struct tipc_subscr))) {
found = 1;
break;
Expand All @@ -219,17 +211,12 @@ static void subscr_cancel(struct tipc_subscr *s,
del_timer_sync(&sub->timer);
spin_lock_bh(&subscriber->lock);
}
subscr_del(sub);
tipc_subscrp_delete(sub);
}

/**
* subscr_subscribe - create subscription for subscriber
*
* Called with subscriber lock held.
*/
static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
struct tipc_subscriber *subscriber,
struct tipc_subscription **sub_p)
static int tipc_subscrp_create(struct net *net, struct tipc_subscr *s,
struct tipc_subscriber *subscriber,
struct tipc_subscription **sub_p)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct tipc_subscription *sub;
Expand All @@ -241,7 +228,7 @@ static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
/* Detect & process a subscription cancellation request */
if (s->filter & htohl(TIPC_SUB_CANCEL, swap)) {
s->filter &= ~htohl(TIPC_SUB_CANCEL, swap);
subscr_cancel(s, subscriber);
tipc_subscrp_cancel(s, subscriber);
return 0;
}

Expand Down Expand Up @@ -273,36 +260,37 @@ static int subscr_subscribe(struct net *net, struct tipc_subscr *s,
kfree(sub);
return -EINVAL;
}
list_add(&sub->subscription_list, &subscriber->subscription_list);
list_add(&sub->subscrp_list, &subscriber->subscrp_list);
sub->subscriber = subscriber;
sub->swap = swap;
memcpy(&sub->evt.s, s, sizeof(struct tipc_subscr));
memcpy(&sub->evt.s, s, sizeof(*s));
atomic_inc(&tn->subscription_count);
if (sub->timeout != TIPC_WAIT_FOREVER) {
setup_timer(&sub->timer, subscr_timeout, (unsigned long)sub);
setup_timer(&sub->timer, tipc_subscrp_timeout,
(unsigned long)sub);
mod_timer(&sub->timer, jiffies + sub->timeout);
}
*sub_p = sub;
return 0;
}

/* Handle one termination request for the subscriber */
static void subscr_conn_shutdown_event(int conid, void *usr_data)
static void tipc_subscrb_shutdown_cb(int conid, void *usr_data)
{
subscr_release((struct tipc_subscriber *)usr_data);
tipc_subscrb_delete((struct tipc_subscriber *)usr_data);
}

/* Handle one request to create a new subscription for the subscriber */
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 tipc_subscrb_rcv_cb(struct net *net, int conid,
struct sockaddr_tipc *addr, void *usr_data,
void *buf, size_t len)
{
struct tipc_subscriber *subscriber = usr_data;
struct tipc_subscription *sub = NULL;
struct tipc_net *tn = net_generic(net, tipc_net_id);

spin_lock_bh(&subscriber->lock);
subscr_subscribe(net, (struct tipc_subscr *)buf, subscriber, &sub);
tipc_subscrp_create(net, (struct tipc_subscr *)buf, subscriber, &sub);
if (sub)
tipc_nametbl_subscribe(sub);
else
Expand All @@ -311,7 +299,7 @@ static void subscr_conn_msg_event(struct net *net, int conid,
}

/* Handle one request to establish a new subscriber */
static void *subscr_named_msg_event(int conid)
static void *tipc_subscrb_connect_cb(int conid)
{
struct tipc_subscriber *subscriber;

Expand All @@ -321,14 +309,14 @@ static void *subscr_named_msg_event(int conid)
pr_warn("Subscriber rejected, no memory\n");
return NULL;
}
INIT_LIST_HEAD(&subscriber->subscription_list);
INIT_LIST_HEAD(&subscriber->subscrp_list);
subscriber->conid = conid;
spin_lock_init(&subscriber->lock);

return (void *)subscriber;
}

int tipc_subscr_start(struct net *net)
int tipc_topsrv_start(struct net *net)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
const char name[] = "topology_server";
Expand All @@ -355,9 +343,9 @@ int tipc_subscr_start(struct net *net)
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;
topsrv->tipc_conn_recvmsg = tipc_subscrb_rcv_cb;
topsrv->tipc_conn_new = tipc_subscrb_connect_cb;
topsrv->tipc_conn_shutdown = tipc_subscrb_shutdown_cb;

strncpy(topsrv->name, name, strlen(name) + 1);
tn->topsrv = topsrv;
Expand All @@ -366,7 +354,7 @@ int tipc_subscr_start(struct net *net)
return tipc_server_start(topsrv);
}

void tipc_subscr_stop(struct net *net)
void tipc_topsrv_stop(struct net *net)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct tipc_server *topsrv = tn->topsrv;
Expand Down
Loading

0 comments on commit 57f1d18

Please sign in to comment.