fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / net / tipc / config.c
index 3c8e674..baf55c4 100644 (file)
@@ -2,7 +2,7 @@
  * net/tipc/config.c: TIPC configuration management code
  * 
  * Copyright (c) 2002-2006, Ericsson AB
- * Copyright (c) 2004-2005, Wind River Systems
+ * Copyright (c) 2004-2006, Wind River Systems
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -63,7 +63,7 @@ struct manager {
 
 static struct manager mng = { 0};
 
-static spinlock_t config_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(config_lock);
 
 static const void *req_tlv_area;       /* request message TLV area */
 static int req_tlv_space;              /* request message TLV area size */
@@ -107,7 +107,7 @@ int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
 struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
 {
        struct sk_buff *buf;
-       u32 value_net;
+       __be32 value_net;
 
        buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value)));
        if (buf) {
@@ -208,7 +208,7 @@ static void cfg_cmd_event(struct tipc_cmd_msg *msg,
 
                        if (mng.link_subscriptions > 64)
                                break;
-                       sub = (struct subscr_data *)kmalloc(sizeof(*sub),
+                       sub = kmalloc(sizeof(*sub),
                                                            GFP_ATOMIC);
                        if (sub == NULL) {
                                warn("Memory squeeze; dropped remote link subscription\n");
@@ -284,20 +284,28 @@ static struct sk_buff *cfg_set_own_addr(void)
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
 
-       addr = *(u32 *)TLV_DATA(req_tlv_area);
-       addr = ntohl(addr);
+       addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
        if (addr == tipc_own_addr)
                return tipc_cfg_reply_none();
        if (!tipc_addr_node_valid(addr))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (node address)");
-       if (tipc_own_addr)
+       if (tipc_mode == TIPC_NET_MODE)
                return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
                                                   " (cannot change node address once assigned)");
+       tipc_own_addr = addr;
+
+       /* 
+        * Must release all spinlocks before calling start_net() because
+        * Linux version of TIPC calls eth_media_start() which calls
+        * register_netdevice_notifier() which may block!
+        *
+        * Temporarily releasing the lock should be harmless for non-Linux TIPC,
+        * but Linux version of eth_media_start() should really be reworked
+        * so that it can be called with spinlocks held.
+        */
 
        spin_unlock_bh(&config_lock);
-       tipc_core_stop_net();
-       tipc_own_addr = addr;
        tipc_core_start_net();
        spin_lock_bh(&config_lock);
        return tipc_cfg_reply_none();
@@ -310,8 +318,7 @@ static struct sk_buff *cfg_set_remote_mng(void)
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
 
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
        tipc_remote_management = (value != 0);
        return tipc_cfg_reply_none();
 }
@@ -323,8 +330,7 @@ static struct sk_buff *cfg_set_max_publications(void)
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
 
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
        if (value != delimit(value, 1, 65535))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (max publications must be 1-65535)");
@@ -339,8 +345,7 @@ static struct sk_buff *cfg_set_max_subscriptions(void)
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
 
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
        if (value != delimit(value, 1, 65535))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (max subscriptions must be 1-65535");
@@ -350,50 +355,20 @@ static struct sk_buff *cfg_set_max_subscriptions(void)
 
 static struct sk_buff *cfg_set_max_ports(void)
 {
-       int orig_mode;
        u32 value;
 
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
+       if (value == tipc_max_ports)
+               return tipc_cfg_reply_none();
        if (value != delimit(value, 127, 65535))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (max ports must be 127-65535)");
-
-       if (value == tipc_max_ports)
-               return tipc_cfg_reply_none();
-
-       if (atomic_read(&tipc_user_count) > 2)
+       if (tipc_mode != TIPC_NOT_RUNNING)
                return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
-                                                  " (cannot change max ports while TIPC users exist)");
-
-       spin_unlock_bh(&config_lock);
-       orig_mode = tipc_get_mode();
-       if (orig_mode == TIPC_NET_MODE)
-               tipc_core_stop_net();
-       tipc_core_stop();
+                       " (cannot change max ports while TIPC is active)");
        tipc_max_ports = value;
-       tipc_core_start();
-       if (orig_mode == TIPC_NET_MODE)
-               tipc_core_start_net();
-       spin_lock_bh(&config_lock);
-       return tipc_cfg_reply_none();
-}
-
-static struct sk_buff *set_net_max(int value, int *parameter)
-{
-       int orig_mode;
-
-       if (value != *parameter) {
-               orig_mode = tipc_get_mode();
-               if (orig_mode == TIPC_NET_MODE)
-                       tipc_core_stop_net();
-               *parameter = value;
-               if (orig_mode == TIPC_NET_MODE)
-                       tipc_core_start_net();
-       }
-
        return tipc_cfg_reply_none();
 }
 
@@ -403,12 +378,17 @@ static struct sk_buff *cfg_set_max_zones(void)
 
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
+       if (value == tipc_max_zones)
+               return tipc_cfg_reply_none();
        if (value != delimit(value, 1, 255))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (max zones must be 1-255)");
-       return set_net_max(value, &tipc_max_zones);
+       if (tipc_mode == TIPC_NET_MODE)
+               return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
+                       " (cannot change max zones once TIPC has joined a network)");
+       tipc_max_zones = value;
+       return tipc_cfg_reply_none();
 }
 
 static struct sk_buff *cfg_set_max_clusters(void)
@@ -417,10 +397,9 @@ static struct sk_buff *cfg_set_max_clusters(void)
 
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
-       if (value != 1)
-               return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
+       if (value != delimit(value, 1, 1))
+               return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (max clusters fixed at 1)");
        return tipc_cfg_reply_none();
 }
@@ -431,12 +410,17 @@ static struct sk_buff *cfg_set_max_nodes(void)
 
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
+       if (value == tipc_max_nodes)
+               return tipc_cfg_reply_none();
        if (value != delimit(value, 8, 2047))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (max nodes must be 8-2047)");
-       return set_net_max(value, &tipc_max_nodes);
+       if (tipc_mode == TIPC_NET_MODE)
+               return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
+                       " (cannot change max nodes once TIPC has joined a network)");
+       tipc_max_nodes = value;
+       return tipc_cfg_reply_none();
 }
 
 static struct sk_buff *cfg_set_max_slaves(void)
@@ -445,8 +429,7 @@ static struct sk_buff *cfg_set_max_slaves(void)
 
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
        if (value != 0)
                return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
                                                   " (max secondary nodes fixed at 0)");
@@ -459,17 +442,17 @@ static struct sk_buff *cfg_set_netid(void)
 
        if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
                return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
-       value = *(u32 *)TLV_DATA(req_tlv_area);
-       value = ntohl(value);
+       value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
+       if (value == tipc_net_id)
+               return tipc_cfg_reply_none();
        if (value != delimit(value, 1, 9999))
                return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
                                                   " (network id must be 1-9999)");
-
-       if (tipc_own_addr)
+       if (tipc_mode == TIPC_NET_MODE)
                return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
-                                                  " (cannot change network id once part of network)");
-       
-       return set_net_max(value, &tipc_net_id);
+                       " (cannot change network id once TIPC has joined a network)");
+       tipc_net_id = value;
+       return tipc_cfg_reply_none();
 }
 
 struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
@@ -620,7 +603,8 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
                rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
                break;
        default:
-               rep_tlv_buf = NULL;
+               rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
+                                                         " (unknown command)");
                break;
        }
 
@@ -649,7 +633,7 @@ static void cfg_named_msg_event(void *userdata,
        if ((size < sizeof(*req_hdr)) ||
            (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
            (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
-               warn("discarded invalid configuration message\n");
+               warn("Invalid configuration message discarded\n");
                return;
        }
 
@@ -683,11 +667,11 @@ int tipc_cfg_init(void)
        memset(&mng, 0, sizeof(mng));
        INIT_LIST_HEAD(&mng.link_subscribers);
 
-       res = tipc_attach(&mng.user_ref, 0, 0);
+       res = tipc_attach(&mng.user_ref, NULL, NULL);
        if (res)
                goto failed;
 
-       res = tipc_createport(mng.user_ref, 0, TIPC_CRITICAL_IMPORTANCE,
+       res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
                              NULL, NULL, NULL,
                              NULL, cfg_named_msg_event, NULL,
                              NULL, &mng.port_ref);