Skip to content

Commit

Permalink
tipc: Combine bearer structure with tipc_bearer structure
Browse files Browse the repository at this point in the history
Combines two distinct structures containing information about a TIPC bearer
into a single structure. The structures were previously kept separate so
that public information about a bearer could be made available to plug-in
media types using TIPC's native API, while the remaining information was
kept private for use by TIPC itself. However, now that the native API has
been removed there is no longer any need for this arrangement.

Since one of the structures was already embedded within the other, the
change largely involves replacing instances of "publ.foo" with "foo".
The changes do not otherwise alter the operation of TIPC bearers.

Signed-off-by: Allan Stephens <Allan.Stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
  • Loading branch information
ajstephens authored and Paul Gortmaker committed Feb 23, 2011
1 parent 23dd4cc commit 2d627b9
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 127 deletions.
28 changes: 14 additions & 14 deletions net/tipc/bcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (c) 2004-2006, Ericsson AB
* Copyright (c) 2004, Intel Corporation.
* Copyright (c) 2005, Wind River Systems
* Copyright (c) 2005, 2010-2011, Wind River Systems
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -61,8 +61,8 @@
*/

struct bcbearer_pair {
struct bearer *primary;
struct bearer *secondary;
struct tipc_bearer *primary;
struct tipc_bearer *secondary;
};

/**
Expand All @@ -81,7 +81,7 @@ struct bcbearer_pair {
*/

struct bcbearer {
struct bearer bearer;
struct tipc_bearer bearer;
struct media media;
struct bcbearer_pair bpairs[MAX_BEARERS];
struct bcbearer_pair bpairs_temp[TIPC_MAX_LINK_PRI + 1];
Expand Down Expand Up @@ -574,8 +574,8 @@ static int tipc_bcbearer_send(struct sk_buff *buf,
bcbearer->remains = tipc_bcast_nmap;

for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) {
struct bearer *p = bcbearer->bpairs[bp_index].primary;
struct bearer *s = bcbearer->bpairs[bp_index].secondary;
struct tipc_bearer *p = bcbearer->bpairs[bp_index].primary;
struct tipc_bearer *s = bcbearer->bpairs[bp_index].secondary;

if (!p)
break; /* no more bearers to try */
Expand All @@ -584,11 +584,11 @@ static int tipc_bcbearer_send(struct sk_buff *buf,
if (bcbearer->remains_new.count == bcbearer->remains.count)
continue; /* bearer pair doesn't add anything */

if (p->publ.blocked ||
p->media->send_msg(buf, &p->publ, &p->media->bcast_addr)) {
if (p->blocked ||
p->media->send_msg(buf, p, &p->media->bcast_addr)) {
/* unable to send on primary bearer */
if (!s || s->publ.blocked ||
s->media->send_msg(buf, &s->publ,
if (!s || s->blocked ||
s->media->send_msg(buf, s,
&s->media->bcast_addr)) {
/* unable to send on either bearer */
continue;
Expand Down Expand Up @@ -633,7 +633,7 @@ void tipc_bcbearer_sort(void)
memset(bp_temp, 0, sizeof(bcbearer->bpairs_temp));

for (b_index = 0; b_index < MAX_BEARERS; b_index++) {
struct bearer *b = &tipc_bearers[b_index];
struct tipc_bearer *b = &tipc_bearers[b_index];

if (!b->active || !b->nodes.count)
continue;
Expand Down Expand Up @@ -682,12 +682,12 @@ void tipc_bcbearer_sort(void)

void tipc_bcbearer_push(void)
{
struct bearer *b_ptr;
struct tipc_bearer *b_ptr;

spin_lock_bh(&bc_lock);
b_ptr = &bcbearer->bearer;
if (b_ptr->publ.blocked) {
b_ptr->publ.blocked = 0;
if (b_ptr->blocked) {
b_ptr->blocked = 0;
tipc_bearer_lock_push(b_ptr);
}
spin_unlock_bh(&bc_lock);
Expand Down
98 changes: 48 additions & 50 deletions net/tipc/bearer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* net/tipc/bearer.c: TIPC bearer code
*
* Copyright (c) 1996-2006, Ericsson AB
* Copyright (c) 2004-2006, Wind River Systems
* Copyright (c) 2004-2006, 2010-2011, Wind River Systems
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -44,7 +44,7 @@
static struct media media_list[MAX_MEDIA];
static u32 media_count;

struct bearer tipc_bearers[MAX_BEARERS];
struct tipc_bearer tipc_bearers[MAX_BEARERS];

/**
* media_name_valid - validate media name
Expand Down Expand Up @@ -278,13 +278,13 @@ static int bearer_name_validate(const char *name,
* bearer_find - locates bearer object with matching bearer name
*/

static struct bearer *bearer_find(const char *name)
static struct tipc_bearer *bearer_find(const char *name)
{
struct bearer *b_ptr;
struct tipc_bearer *b_ptr;
u32 i;

for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
if (b_ptr->active && (!strcmp(b_ptr->publ.name, name)))
if (b_ptr->active && (!strcmp(b_ptr->name, name)))
return b_ptr;
}
return NULL;
Expand All @@ -294,16 +294,16 @@ static struct bearer *bearer_find(const char *name)
* tipc_bearer_find_interface - locates bearer object with matching interface name
*/

struct bearer *tipc_bearer_find_interface(const char *if_name)
struct tipc_bearer *tipc_bearer_find_interface(const char *if_name)
{
struct bearer *b_ptr;
struct tipc_bearer *b_ptr;
char *b_if_name;
u32 i;

for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
if (!b_ptr->active)
continue;
b_if_name = strchr(b_ptr->publ.name, ':') + 1;
b_if_name = strchr(b_ptr->name, ':') + 1;
if (!strcmp(b_if_name, if_name))
return b_ptr;
}
Expand All @@ -318,7 +318,7 @@ struct sk_buff *tipc_bearer_get_names(void)
{
struct sk_buff *buf;
struct media *m_ptr;
struct bearer *b_ptr;
struct tipc_bearer *b_ptr;
int i, j;

buf = tipc_cfg_reply_alloc(MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME));
Expand All @@ -331,23 +331,23 @@ struct sk_buff *tipc_bearer_get_names(void)
b_ptr = &tipc_bearers[j];
if (b_ptr->active && (b_ptr->media == m_ptr)) {
tipc_cfg_append_tlv(buf, TIPC_TLV_BEARER_NAME,
b_ptr->publ.name,
strlen(b_ptr->publ.name) + 1);
b_ptr->name,
strlen(b_ptr->name) + 1);
}
}
}
read_unlock_bh(&tipc_net_lock);
return buf;
}

void tipc_bearer_add_dest(struct bearer *b_ptr, u32 dest)
void tipc_bearer_add_dest(struct tipc_bearer *b_ptr, u32 dest)
{
tipc_nmap_add(&b_ptr->nodes, dest);
tipc_disc_update_link_req(b_ptr->link_req);
tipc_bcbearer_sort();
}

void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest)
void tipc_bearer_remove_dest(struct tipc_bearer *b_ptr, u32 dest)
{
tipc_nmap_remove(&b_ptr->nodes, dest);
tipc_disc_update_link_req(b_ptr->link_req);
Expand All @@ -362,12 +362,12 @@ void tipc_bearer_remove_dest(struct bearer *b_ptr, u32 dest)
* bearer.lock must be taken before calling
* Returns binary true(1) ore false(0)
*/
static int bearer_push(struct bearer *b_ptr)
static int bearer_push(struct tipc_bearer *b_ptr)
{
u32 res = 0;
struct link *ln, *tln;

if (b_ptr->publ.blocked)
if (b_ptr->blocked)
return 0;

while (!list_empty(&b_ptr->cong_links) && (res != PUSH_FAILED)) {
Expand All @@ -382,13 +382,13 @@ static int bearer_push(struct bearer *b_ptr)
return list_empty(&b_ptr->cong_links);
}

void tipc_bearer_lock_push(struct bearer *b_ptr)
void tipc_bearer_lock_push(struct tipc_bearer *b_ptr)
{
int res;

spin_lock_bh(&b_ptr->publ.lock);
spin_lock_bh(&b_ptr->lock);
res = bearer_push(b_ptr);
spin_unlock_bh(&b_ptr->publ.lock);
spin_unlock_bh(&b_ptr->lock);
if (res)
tipc_bcbearer_push();
}
Expand All @@ -398,16 +398,14 @@ void tipc_bearer_lock_push(struct bearer *b_ptr)
* Interrupt enabling new requests after bearer congestion or blocking:
* See bearer_send().
*/
void tipc_continue(struct tipc_bearer *tb_ptr)
void tipc_continue(struct tipc_bearer *b_ptr)
{
struct bearer *b_ptr = (struct bearer *)tb_ptr;

spin_lock_bh(&b_ptr->publ.lock);
spin_lock_bh(&b_ptr->lock);
b_ptr->continue_count++;
if (!list_empty(&b_ptr->cong_links))
tipc_k_signal((Handler)tipc_bearer_lock_push, (unsigned long)b_ptr);
b_ptr->publ.blocked = 0;
spin_unlock_bh(&b_ptr->publ.lock);
b_ptr->blocked = 0;
spin_unlock_bh(&b_ptr->lock);
}

/*
Expand All @@ -418,7 +416,7 @@ void tipc_continue(struct tipc_bearer *tb_ptr)
* bearer.lock is busy
*/

static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_ptr)
static void tipc_bearer_schedule_unlocked(struct tipc_bearer *b_ptr, struct link *l_ptr)
{
list_move_tail(&l_ptr->link_list, &b_ptr->cong_links);
}
Expand All @@ -431,11 +429,11 @@ static void tipc_bearer_schedule_unlocked(struct bearer *b_ptr, struct link *l_p
* bearer.lock is free
*/

void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr)
void tipc_bearer_schedule(struct tipc_bearer *b_ptr, struct link *l_ptr)
{
spin_lock_bh(&b_ptr->publ.lock);
spin_lock_bh(&b_ptr->lock);
tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
spin_unlock_bh(&b_ptr->publ.lock);
spin_unlock_bh(&b_ptr->lock);
}


Expand All @@ -444,28 +442,28 @@ void tipc_bearer_schedule(struct bearer *b_ptr, struct link *l_ptr)
* and if there is, try to resolve it before returning.
* 'tipc_net_lock' is read_locked when this function is called
*/
int tipc_bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr)
int tipc_bearer_resolve_congestion(struct tipc_bearer *b_ptr, struct link *l_ptr)
{
int res = 1;

if (list_empty(&b_ptr->cong_links))
return 1;
spin_lock_bh(&b_ptr->publ.lock);
spin_lock_bh(&b_ptr->lock);
if (!bearer_push(b_ptr)) {
tipc_bearer_schedule_unlocked(b_ptr, l_ptr);
res = 0;
}
spin_unlock_bh(&b_ptr->publ.lock);
spin_unlock_bh(&b_ptr->lock);
return res;
}

/**
* tipc_bearer_congested - determines if bearer is currently congested
*/

int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr)
int tipc_bearer_congested(struct tipc_bearer *b_ptr, struct link *l_ptr)
{
if (unlikely(b_ptr->publ.blocked))
if (unlikely(b_ptr->blocked))
return 1;
if (likely(list_empty(&b_ptr->cong_links)))
return 0;
Expand All @@ -478,7 +476,7 @@ int tipc_bearer_congested(struct bearer *b_ptr, struct link *l_ptr)

int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
{
struct bearer *b_ptr;
struct tipc_bearer *b_ptr;
struct media *m_ptr;
struct bearer_name b_name;
char addr_string[16];
Expand Down Expand Up @@ -528,7 +526,7 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
bearer_id = i;
continue;
}
if (!strcmp(name, tipc_bearers[i].publ.name)) {
if (!strcmp(name, tipc_bearers[i].name)) {
warn("Bearer <%s> rejected, already enabled\n", name);
goto failed;
}
Expand All @@ -551,8 +549,8 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
}

b_ptr = &tipc_bearers[bearer_id];
strcpy(b_ptr->publ.name, name);
res = m_ptr->enable_bearer(&b_ptr->publ);
strcpy(b_ptr->name, name);
res = m_ptr->enable_bearer(b_ptr);
if (res) {
warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
goto failed;
Expand All @@ -570,7 +568,7 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
b_ptr->link_req = tipc_disc_init_link_req(b_ptr, &m_ptr->bcast_addr,
bcast_scope, 2);
}
spin_lock_init(&b_ptr->publ.lock);
spin_lock_init(&b_ptr->lock);
write_unlock_bh(&tipc_net_lock);
info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
name, tipc_addr_string_fill(addr_string, bcast_scope), priority);
Expand All @@ -587,7 +585,7 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)

int tipc_block_bearer(const char *name)
{
struct bearer *b_ptr = NULL;
struct tipc_bearer *b_ptr = NULL;
struct link *l_ptr;
struct link *temp_l_ptr;

Expand All @@ -600,16 +598,16 @@ int tipc_block_bearer(const char *name)
}

info("Blocking bearer <%s>\n", name);
spin_lock_bh(&b_ptr->publ.lock);
b_ptr->publ.blocked = 1;
spin_lock_bh(&b_ptr->lock);
b_ptr->blocked = 1;
list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
struct tipc_node *n_ptr = l_ptr->owner;

spin_lock_bh(&n_ptr->lock);
tipc_link_reset(l_ptr);
spin_unlock_bh(&n_ptr->lock);
}
spin_unlock_bh(&b_ptr->publ.lock);
spin_unlock_bh(&b_ptr->lock);
read_unlock_bh(&tipc_net_lock);
return 0;
}
Expand All @@ -620,27 +618,27 @@ int tipc_block_bearer(const char *name)
* Note: This routine assumes caller holds tipc_net_lock.
*/

static void bearer_disable(struct bearer *b_ptr)
static void bearer_disable(struct tipc_bearer *b_ptr)
{
struct link *l_ptr;
struct link *temp_l_ptr;

info("Disabling bearer <%s>\n", b_ptr->publ.name);
info("Disabling bearer <%s>\n", b_ptr->name);
tipc_disc_stop_link_req(b_ptr->link_req);
spin_lock_bh(&b_ptr->publ.lock);
spin_lock_bh(&b_ptr->lock);
b_ptr->link_req = NULL;
b_ptr->publ.blocked = 1;
b_ptr->media->disable_bearer(&b_ptr->publ);
b_ptr->blocked = 1;
b_ptr->media->disable_bearer(b_ptr);
list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
tipc_link_delete(l_ptr);
}
spin_unlock_bh(&b_ptr->publ.lock);
memset(b_ptr, 0, sizeof(struct bearer));
spin_unlock_bh(&b_ptr->lock);
memset(b_ptr, 0, sizeof(struct tipc_bearer));
}

int tipc_disable_bearer(const char *name)
{
struct bearer *b_ptr;
struct tipc_bearer *b_ptr;
int res;

write_lock_bh(&tipc_net_lock);
Expand Down
Loading

0 comments on commit 2d627b9

Please sign in to comment.