linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / tipc / bearer.c
index 75a5968..64dcb0f 100644 (file)
 
 #define MAX_ADDR_STR 32
 
-static struct media *media_list = NULL;
+static struct media *media_list = 0;
 static u32 media_count = 0;
 
-struct bearer *tipc_bearers = NULL;
+struct bearer *tipc_bearers = 0;
 
 /**
  * media_name_valid - validate media name
@@ -79,7 +79,7 @@ static struct media *media_find(const char *name)
                if (!strcmp(m_ptr->name, name))
                        return m_ptr;
        }
-       return NULL;
+       return 0;
 }
 
 /**
@@ -112,42 +112,39 @@ int  tipc_register_media(u32 media_type,
                goto exit;
 
        if (!media_name_valid(name)) {
-               warn("Media <%s> rejected, illegal name\n", name);
+               warn("Media registration error: illegal name <%s>\n", name);
                goto exit;
        }
        if (!bcast_addr) {
-               warn("Media <%s> rejected, no broadcast address\n", name);
+               warn("Media registration error: no broadcast address supplied\n");
                goto exit;
        }
        if ((bearer_priority < TIPC_MIN_LINK_PRI) &&
            (bearer_priority > TIPC_MAX_LINK_PRI)) {
-               warn("Media <%s> rejected, illegal priority (%u)\n", name, 
-                    bearer_priority);
+               warn("Media registration error: priority %u\n", bearer_priority);
                goto exit;
        }
        if ((link_tolerance < TIPC_MIN_LINK_TOL) || 
            (link_tolerance > TIPC_MAX_LINK_TOL)) {
-               warn("Media <%s> rejected, illegal tolerance (%u)\n", name,
-                    link_tolerance);
+               warn("Media registration error: tolerance %u\n", link_tolerance);
                goto exit;
        }
 
        media_id = media_count++;
        if (media_id >= MAX_MEDIA) {
-               warn("Media <%s> rejected, media limit reached (%u)\n", name,
-                    MAX_MEDIA);
+               warn("Attempt to register more than %u media\n", MAX_MEDIA);
                media_count--;
                goto exit;
        }
        for (i = 0; i < media_id; i++) {
                if (media_list[i].type_id == media_type) {
-                       warn("Media <%s> rejected, duplicate type (%u)\n", name,
+                       warn("Attempt to register second media with type %u\n", 
                             media_type);
                        media_count--;
                        goto exit;
                }
                if (!strcmp(name, media_list[i].name)) {
-                       warn("Media <%s> rejected, duplicate name\n", name);
+                       warn("Attempt to re-register media name <%s>\n", name);
                        media_count--;
                        goto exit;
                }
@@ -286,14 +283,11 @@ static struct bearer *bearer_find(const char *name)
        struct bearer *b_ptr;
        u32 i;
 
-       if (tipc_mode != TIPC_NET_MODE)
-               return NULL;
-
        for (i = 0, b_ptr = tipc_bearers; i < MAX_BEARERS; i++, b_ptr++) {
                if (b_ptr->active && (!strcmp(b_ptr->publ.name, name)))
                        return b_ptr;
        }
-       return NULL;
+       return 0;
 }
 
 /**
@@ -313,7 +307,7 @@ struct bearer *tipc_bearer_find_interface(const char *if_name)
                if (!strcmp(b_if_name, if_name))
                        return b_ptr;
        }
-       return NULL;
+       return 0;
 }
 
 /**
@@ -481,33 +475,26 @@ int tipc_enable_bearer(const char *name, u32 bcast_scope, u32 priority)
        u32 i;
        int res = -EINVAL;
 
-       if (tipc_mode != TIPC_NET_MODE) {
-               warn("Bearer <%s> rejected, not supported in standalone mode\n",
-                    name);
+       if (tipc_mode != TIPC_NET_MODE)
                return -ENOPROTOOPT;
-       }
-       if (!bearer_name_validate(name, &b_name)) {
-               warn("Bearer <%s> rejected, illegal name\n", name);
-               return -EINVAL;
-       }
-       if (!tipc_addr_domain_valid(bcast_scope) || 
-           !in_scope(bcast_scope, tipc_own_addr)) {
-               warn("Bearer <%s> rejected, illegal broadcast scope\n", name);
+
+       if (!bearer_name_validate(name, &b_name) ||
+           !tipc_addr_domain_valid(bcast_scope) ||
+           !in_scope(bcast_scope, tipc_own_addr))
                return -EINVAL;
-       }
+
        if ((priority < TIPC_MIN_LINK_PRI ||
             priority > TIPC_MAX_LINK_PRI) &&
-           (priority != TIPC_MEDIA_LINK_PRI)) {
-               warn("Bearer <%s> rejected, illegal priority\n", name);
+           (priority != TIPC_MEDIA_LINK_PRI))
                return -EINVAL;
-       }
 
        write_lock_bh(&tipc_net_lock);
+       if (!tipc_bearers)
+               goto failed;
 
        m_ptr = media_find(b_name.media_name);
        if (!m_ptr) {
-               warn("Bearer <%s> rejected, media <%s> not registered\n", name,
-                    b_name.media_name);
+               warn("No media <%s>\n", b_name.media_name);
                goto failed;
        }
 
@@ -523,24 +510,23 @@ restart:
                        continue;
                }
                if (!strcmp(name, tipc_bearers[i].publ.name)) {
-                       warn("Bearer <%s> rejected, already enabled\n", name);
+                       warn("Bearer <%s> already enabled\n", name);
                        goto failed;
                }
                if ((tipc_bearers[i].priority == priority) &&
                    (++with_this_prio > 2)) {
                        if (priority-- == 0) {
-                               warn("Bearer <%s> rejected, duplicate priority\n",
-                                    name);
+                               warn("Third bearer <%s> with priority %u, unable to lower to %u\n",
+                                    name, priority + 1, priority);
                                goto failed;
                        }
-                       warn("Bearer <%s> priority adjustment required %u->%u\n",
+                       warn("Third bearer <%s> with priority %u, lowering to %u\n",
                             name, priority + 1, priority);
                        goto restart;
                }
        }
        if (bearer_id >= MAX_BEARERS) {
-               warn("Bearer <%s> rejected, bearer limit reached (%u)\n", 
-                    name, MAX_BEARERS);
+               warn("Attempt to enable more than %d bearers\n", MAX_BEARERS);
                goto failed;
        }
 
@@ -550,7 +536,7 @@ restart:
        strcpy(b_ptr->publ.name, name);
        res = m_ptr->enable_bearer(&b_ptr->publ);
        if (res) {
-               warn("Bearer <%s> rejected, enable failure (%d)\n", name, -res);
+               warn("Failed to enable bearer <%s>\n", name);
                goto failed;
        }
 
@@ -566,7 +552,7 @@ restart:
                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);
+       b_ptr->publ.lock = SPIN_LOCK_UNLOCKED;
        write_unlock_bh(&tipc_net_lock);
        info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
             name, addr_string_fill(addr_string, bcast_scope), priority);
@@ -583,10 +569,13 @@ failed:
 
 int tipc_block_bearer(const char *name)
 {
-       struct bearer *b_ptr = NULL;
+       struct bearer *b_ptr = 0;
        struct link *l_ptr;
        struct link *temp_l_ptr;
 
+       if (tipc_mode != TIPC_NET_MODE)
+               return -ENOPROTOOPT;
+
        read_lock_bh(&tipc_net_lock);
        b_ptr = bearer_find(name);
        if (!b_ptr) {
@@ -595,7 +584,6 @@ int tipc_block_bearer(const char *name)
                return -EINVAL;
        }
 
-       info("Blocking bearer <%s>\n", name);
        spin_lock_bh(&b_ptr->publ.lock);
        b_ptr->publ.blocked = 1;
        list_for_each_entry_safe(l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
@@ -607,6 +595,7 @@ int tipc_block_bearer(const char *name)
        }
        spin_unlock_bh(&b_ptr->publ.lock);
        read_unlock_bh(&tipc_net_lock);
+       info("Blocked bearer <%s>\n", name);
        return TIPC_OK;
 }
 
@@ -622,13 +611,15 @@ static int bearer_disable(const char *name)
        struct link *l_ptr;
        struct link *temp_l_ptr;
 
+       if (tipc_mode != TIPC_NET_MODE)
+               return -ENOPROTOOPT;
+
        b_ptr = bearer_find(name);
        if (!b_ptr) {
                warn("Attempt to disable unknown bearer <%s>\n", name);
                return -EINVAL;
        }
 
-       info("Disabling bearer <%s>\n", name);
        tipc_disc_stop_link_req(b_ptr->link_req);
        spin_lock_bh(&b_ptr->publ.lock);
        b_ptr->link_req = NULL;
@@ -644,6 +635,7 @@ static int bearer_disable(const char *name)
                tipc_link_delete(l_ptr);
        }
        spin_unlock_bh(&b_ptr->publ.lock);
+       info("Disabled bearer <%s>\n", name);
        memset(b_ptr, 0, sizeof(struct bearer));
        return TIPC_OK;
 }
@@ -665,15 +657,17 @@ int tipc_bearer_init(void)
        int res;
 
        write_lock_bh(&tipc_net_lock);
-       tipc_bearers = kcalloc(MAX_BEARERS, sizeof(struct bearer), GFP_ATOMIC);
-       media_list = kcalloc(MAX_MEDIA, sizeof(struct media), GFP_ATOMIC);
+       tipc_bearers = kmalloc(MAX_BEARERS * sizeof(struct bearer), GFP_ATOMIC);
+       media_list = kmalloc(MAX_MEDIA * sizeof(struct media), GFP_ATOMIC);
        if (tipc_bearers && media_list) {
+               memset(tipc_bearers, 0, MAX_BEARERS * sizeof(struct bearer));
+               memset(media_list, 0, MAX_MEDIA * sizeof(struct media));
                res = TIPC_OK;
        } else {
                kfree(tipc_bearers);
                kfree(media_list);
-               tipc_bearers = NULL;
-               media_list = NULL;
+               tipc_bearers = 0;
+               media_list = 0;
                res = -ENOMEM;
        }
        write_unlock_bh(&tipc_net_lock);
@@ -697,8 +691,8 @@ void tipc_bearer_stop(void)
        }
        kfree(tipc_bearers);
        kfree(media_list);
-       tipc_bearers = NULL;
-       media_list = NULL;
+       tipc_bearers = 0;
+       media_list = 0;
        media_count = 0;
 }