diff options
Diffstat (limited to 'net/tipc')
-rw-r--r-- | net/tipc/config.c | 2 | ||||
-rw-r--r-- | net/tipc/core.c | 6 | ||||
-rw-r--r-- | net/tipc/core.h | 124 | ||||
-rw-r--r-- | net/tipc/dbg.c | 231 | ||||
-rw-r--r-- | net/tipc/dbg.h | 12 | ||||
-rw-r--r-- | net/tipc/link.c | 20 | ||||
-rw-r--r-- | net/tipc/msg.c | 10 | ||||
-rw-r--r-- | net/tipc/name_distr.c | 3 | ||||
-rw-r--r-- | net/tipc/name_table.c | 7 | ||||
-rw-r--r-- | net/tipc/port.c | 20 | ||||
-rw-r--r-- | net/tipc/ref.c | 12 | ||||
-rw-r--r-- | net/tipc/socket.c | 5 | ||||
-rw-r--r-- | net/tipc/subscr.c | 1 |
13 files changed, 245 insertions, 208 deletions
diff --git a/net/tipc/config.c b/net/tipc/config.c index c71337a22d33..91d56f8fee9f 100644 --- a/net/tipc/config.c +++ b/net/tipc/config.c | |||
@@ -529,7 +529,7 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area | |||
529 | break; | 529 | break; |
530 | #endif | 530 | #endif |
531 | case TIPC_CMD_SET_LOG_SIZE: | 531 | case TIPC_CMD_SET_LOG_SIZE: |
532 | rep_tlv_buf = tipc_log_resize(req_tlv_area, req_tlv_space); | 532 | rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space); |
533 | break; | 533 | break; |
534 | case TIPC_CMD_DUMP_LOG: | 534 | case TIPC_CMD_DUMP_LOG: |
535 | rep_tlv_buf = tipc_log_dump(); | 535 | rep_tlv_buf = tipc_log_dump(); |
diff --git a/net/tipc/core.c b/net/tipc/core.c index 740aac5cdfb6..6d6aa5a3c240 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c | |||
@@ -49,7 +49,7 @@ | |||
49 | #include "config.h" | 49 | #include "config.h" |
50 | 50 | ||
51 | 51 | ||
52 | #define TIPC_MOD_VER "1.6.3" | 52 | #define TIPC_MOD_VER "1.6.4" |
53 | 53 | ||
54 | #ifndef CONFIG_TIPC_ZONES | 54 | #ifndef CONFIG_TIPC_ZONES |
55 | #define CONFIG_TIPC_ZONES 3 | 55 | #define CONFIG_TIPC_ZONES 3 |
@@ -182,7 +182,7 @@ static int __init tipc_init(void) | |||
182 | { | 182 | { |
183 | int res; | 183 | int res; |
184 | 184 | ||
185 | tipc_log_reinit(CONFIG_TIPC_LOG); | 185 | tipc_log_resize(CONFIG_TIPC_LOG); |
186 | info("Activated (version " TIPC_MOD_VER | 186 | info("Activated (version " TIPC_MOD_VER |
187 | " compiled " __DATE__ " " __TIME__ ")\n"); | 187 | " compiled " __DATE__ " " __TIME__ ")\n"); |
188 | 188 | ||
@@ -209,7 +209,7 @@ static void __exit tipc_exit(void) | |||
209 | tipc_core_stop_net(); | 209 | tipc_core_stop_net(); |
210 | tipc_core_stop(); | 210 | tipc_core_stop(); |
211 | info("Deactivated\n"); | 211 | info("Deactivated\n"); |
212 | tipc_log_stop(); | 212 | tipc_log_resize(0); |
213 | } | 213 | } |
214 | 214 | ||
215 | module_init(tipc_init); | 215 | module_init(tipc_init); |
diff --git a/net/tipc/core.h b/net/tipc/core.h index 5a0e4878d3b7..bd78d1705c0f 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h | |||
@@ -2,7 +2,7 @@ | |||
2 | * net/tipc/core.h: Include file for TIPC global declarations | 2 | * net/tipc/core.h: Include file for TIPC global declarations |
3 | * | 3 | * |
4 | * Copyright (c) 2005-2006, Ericsson AB | 4 | * Copyright (c) 2005-2006, Ericsson AB |
5 | * Copyright (c) 2005-2006, Wind River Systems | 5 | * Copyright (c) 2005-2007, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -59,84 +59,108 @@ | |||
59 | #include <linux/vmalloc.h> | 59 | #include <linux/vmalloc.h> |
60 | 60 | ||
61 | /* | 61 | /* |
62 | * TIPC debugging code | 62 | * TIPC sanity test macros |
63 | */ | 63 | */ |
64 | 64 | ||
65 | #define assert(i) BUG_ON(!(i)) | 65 | #define assert(i) BUG_ON(!(i)) |
66 | 66 | ||
67 | struct tipc_msg; | ||
68 | extern struct print_buf *TIPC_NULL, *TIPC_CONS, *TIPC_LOG; | ||
69 | extern struct print_buf *TIPC_TEE(struct print_buf *, struct print_buf *); | ||
70 | void tipc_msg_print(struct print_buf*,struct tipc_msg *,const char*); | ||
71 | void tipc_printf(struct print_buf *, const char *fmt, ...); | ||
72 | void tipc_dump(struct print_buf*,const char *fmt, ...); | ||
73 | |||
74 | #ifdef CONFIG_TIPC_DEBUG | ||
75 | |||
76 | /* | 67 | /* |
77 | * TIPC debug support included: | 68 | * TIPC system monitoring code |
78 | * - system messages are printed to TIPC_OUTPUT print buffer | ||
79 | * - debug messages are printed to DBG_OUTPUT print buffer | ||
80 | */ | 69 | */ |
81 | 70 | ||
82 | #define err(fmt, arg...) tipc_printf(TIPC_OUTPUT, KERN_ERR "TIPC: " fmt, ## arg) | 71 | /* |
83 | #define warn(fmt, arg...) tipc_printf(TIPC_OUTPUT, KERN_WARNING "TIPC: " fmt, ## arg) | 72 | * TIPC's print buffer subsystem supports the following print buffers: |
84 | #define info(fmt, arg...) tipc_printf(TIPC_OUTPUT, KERN_NOTICE "TIPC: " fmt, ## arg) | 73 | * |
74 | * TIPC_NULL : null buffer (i.e. print nowhere) | ||
75 | * TIPC_CONS : system console | ||
76 | * TIPC_LOG : TIPC log buffer | ||
77 | * &buf : user-defined buffer (struct print_buf *) | ||
78 | * | ||
79 | * Note: TIPC_LOG is configured to echo its output to the system console; | ||
80 | * user-defined buffers can be configured to do the same thing. | ||
81 | */ | ||
85 | 82 | ||
86 | #define dbg(fmt, arg...) do {if (DBG_OUTPUT != TIPC_NULL) tipc_printf(DBG_OUTPUT, fmt, ## arg);} while(0) | 83 | extern struct print_buf *const TIPC_NULL; |
87 | #define msg_dbg(msg, txt) do {if (DBG_OUTPUT != TIPC_NULL) tipc_msg_print(DBG_OUTPUT, msg, txt);} while(0) | 84 | extern struct print_buf *const TIPC_CONS; |
88 | #define dump(fmt, arg...) do {if (DBG_OUTPUT != TIPC_NULL) tipc_dump(DBG_OUTPUT, fmt, ##arg);} while(0) | 85 | extern struct print_buf *const TIPC_LOG; |
89 | 86 | ||
87 | void tipc_printf(struct print_buf *, const char *fmt, ...); | ||
90 | 88 | ||
91 | /* | 89 | /* |
92 | * By default, TIPC_OUTPUT is defined to be system console and TIPC log buffer, | 90 | * TIPC_OUTPUT is the destination print buffer for system messages. |
93 | * while DBG_OUTPUT is the null print buffer. These defaults can be changed | ||
94 | * here, or on a per .c file basis, by redefining these symbols. The following | ||
95 | * print buffer options are available: | ||
96 | * | ||
97 | * TIPC_NULL : null buffer (i.e. print nowhere) | ||
98 | * TIPC_CONS : system console | ||
99 | * TIPC_LOG : TIPC log buffer | ||
100 | * &buf : user-defined buffer (struct print_buf *) | ||
101 | * TIPC_TEE(&buf_a,&buf_b) : list of buffers (eg. TIPC_TEE(TIPC_CONS,TIPC_LOG)) | ||
102 | */ | 91 | */ |
103 | 92 | ||
104 | #ifndef TIPC_OUTPUT | 93 | #ifndef TIPC_OUTPUT |
105 | #define TIPC_OUTPUT TIPC_TEE(TIPC_CONS,TIPC_LOG) | 94 | #define TIPC_OUTPUT TIPC_LOG |
106 | #endif | ||
107 | |||
108 | #ifndef DBG_OUTPUT | ||
109 | #define DBG_OUTPUT TIPC_NULL | ||
110 | #endif | 95 | #endif |
111 | 96 | ||
112 | #else | ||
113 | |||
114 | /* | 97 | /* |
115 | * TIPC debug support not included: | 98 | * TIPC can be configured to send system messages to TIPC_OUTPUT |
116 | * - system messages are printed to system console | 99 | * or to the system console only. |
117 | * - debug messages are not printed | ||
118 | */ | 100 | */ |
119 | 101 | ||
102 | #ifdef CONFIG_TIPC_DEBUG | ||
103 | |||
104 | #define err(fmt, arg...) tipc_printf(TIPC_OUTPUT, \ | ||
105 | KERN_ERR "TIPC: " fmt, ## arg) | ||
106 | #define warn(fmt, arg...) tipc_printf(TIPC_OUTPUT, \ | ||
107 | KERN_WARNING "TIPC: " fmt, ## arg) | ||
108 | #define info(fmt, arg...) tipc_printf(TIPC_OUTPUT, \ | ||
109 | KERN_NOTICE "TIPC: " fmt, ## arg) | ||
110 | |||
111 | #else | ||
112 | |||
120 | #define err(fmt, arg...) printk(KERN_ERR "TIPC: " fmt , ## arg) | 113 | #define err(fmt, arg...) printk(KERN_ERR "TIPC: " fmt , ## arg) |
121 | #define info(fmt, arg...) printk(KERN_INFO "TIPC: " fmt , ## arg) | 114 | #define info(fmt, arg...) printk(KERN_INFO "TIPC: " fmt , ## arg) |
122 | #define warn(fmt, arg...) printk(KERN_WARNING "TIPC: " fmt , ## arg) | 115 | #define warn(fmt, arg...) printk(KERN_WARNING "TIPC: " fmt , ## arg) |
123 | 116 | ||
124 | #define dbg(fmt, arg...) do {} while (0) | 117 | #endif |
125 | #define msg_dbg(msg,txt) do {} while (0) | ||
126 | #define dump(fmt,arg...) do {} while (0) | ||
127 | 118 | ||
119 | /* | ||
120 | * DBG_OUTPUT is the destination print buffer for debug messages. | ||
121 | * It defaults to the the null print buffer, but can be redefined | ||
122 | * (typically in the individual .c files being debugged) to allow | ||
123 | * selected debug messages to be generated where needed. | ||
124 | */ | ||
125 | |||
126 | #ifndef DBG_OUTPUT | ||
127 | #define DBG_OUTPUT TIPC_NULL | ||
128 | #endif | ||
128 | 129 | ||
129 | /* | 130 | /* |
130 | * TIPC_OUTPUT is defined to be the system console, while DBG_OUTPUT is | 131 | * TIPC can be configured to send debug messages to the specified print buffer |
131 | * the null print buffer. Thes ensures that any system or debug messages | 132 | * (typically DBG_OUTPUT) or to suppress them entirely. |
132 | * that are generated without using the above macros are handled correctly. | ||
133 | */ | 133 | */ |
134 | 134 | ||
135 | #undef TIPC_OUTPUT | 135 | #ifdef CONFIG_TIPC_DEBUG |
136 | #define TIPC_OUTPUT TIPC_CONS | ||
137 | 136 | ||
138 | #undef DBG_OUTPUT | 137 | #define dbg(fmt, arg...) \ |
139 | #define DBG_OUTPUT TIPC_NULL | 138 | do { \ |
139 | if (DBG_OUTPUT != TIPC_NULL) \ | ||
140 | tipc_printf(DBG_OUTPUT, fmt, ## arg); \ | ||
141 | } while (0) | ||
142 | #define msg_dbg(msg, txt) \ | ||
143 | do { \ | ||
144 | if (DBG_OUTPUT != TIPC_NULL) \ | ||
145 | tipc_msg_dbg(DBG_OUTPUT, msg, txt); \ | ||
146 | } while (0) | ||
147 | #define dump(fmt, arg...) \ | ||
148 | do { \ | ||
149 | if (DBG_OUTPUT != TIPC_NULL) \ | ||
150 | tipc_dump_dbg(DBG_OUTPUT, fmt, ##arg); \ | ||
151 | } while (0) | ||
152 | |||
153 | void tipc_msg_dbg(struct print_buf *, struct tipc_msg *, const char *); | ||
154 | void tipc_dump_dbg(struct print_buf *, const char *fmt, ...); | ||
155 | |||
156 | #else | ||
157 | |||
158 | #define dbg(fmt, arg...) do {} while (0) | ||
159 | #define msg_dbg(msg, txt) do {} while (0) | ||
160 | #define dump(fmt, arg...) do {} while (0) | ||
161 | |||
162 | #define tipc_msg_dbg(...) do {} while (0) | ||
163 | #define tipc_dump_dbg(...) do {} while (0) | ||
140 | 164 | ||
141 | #endif | 165 | #endif |
142 | 166 | ||
diff --git a/net/tipc/dbg.c b/net/tipc/dbg.c index e809d2a2ce06..29ecae851668 100644 --- a/net/tipc/dbg.c +++ b/net/tipc/dbg.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * net/tipc/dbg.c: TIPC print buffer routines for debugging | 2 | * net/tipc/dbg.c: TIPC print buffer routines for debugging |
3 | * | 3 | * |
4 | * Copyright (c) 1996-2006, Ericsson AB | 4 | * Copyright (c) 1996-2006, Ericsson AB |
5 | * Copyright (c) 2005-2006, Wind River Systems | 5 | * Copyright (c) 2005-2007, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -38,17 +38,43 @@ | |||
38 | #include "config.h" | 38 | #include "config.h" |
39 | #include "dbg.h" | 39 | #include "dbg.h" |
40 | 40 | ||
41 | static char print_string[TIPC_PB_MAX_STR]; | 41 | /* |
42 | static DEFINE_SPINLOCK(print_lock); | 42 | * TIPC pre-defines the following print buffers: |
43 | * | ||
44 | * TIPC_NULL : null buffer (i.e. print nowhere) | ||
45 | * TIPC_CONS : system console | ||
46 | * TIPC_LOG : TIPC log buffer | ||
47 | * | ||
48 | * Additional user-defined print buffers are also permitted. | ||
49 | */ | ||
43 | 50 | ||
44 | static struct print_buf null_buf = { NULL, 0, NULL, NULL }; | 51 | static struct print_buf null_buf = { NULL, 0, NULL, 0 }; |
45 | struct print_buf *TIPC_NULL = &null_buf; | 52 | struct print_buf *const TIPC_NULL = &null_buf; |
46 | 53 | ||
47 | static struct print_buf cons_buf = { NULL, 0, NULL, NULL }; | 54 | static struct print_buf cons_buf = { NULL, 0, NULL, 1 }; |
48 | struct print_buf *TIPC_CONS = &cons_buf; | 55 | struct print_buf *const TIPC_CONS = &cons_buf; |
49 | 56 | ||
50 | static struct print_buf log_buf = { NULL, 0, NULL, NULL }; | 57 | static struct print_buf log_buf = { NULL, 0, NULL, 1 }; |
51 | struct print_buf *TIPC_LOG = &log_buf; | 58 | struct print_buf *const TIPC_LOG = &log_buf; |
59 | |||
60 | /* | ||
61 | * Locking policy when using print buffers. | ||
62 | * | ||
63 | * 1) tipc_printf() uses 'print_lock' to protect against concurrent access to | ||
64 | * 'print_string' when writing to a print buffer. This also protects against | ||
65 | * concurrent writes to the print buffer being written to. | ||
66 | * | ||
67 | * 2) tipc_dump() and tipc_log_XXX() leverage the aforementioned | ||
68 | * use of 'print_lock' to protect against all types of concurrent operations | ||
69 | * on their associated print buffer (not just write operations). | ||
70 | * | ||
71 | * Note: All routines of the form tipc_printbuf_XXX() are lock-free, and rely | ||
72 | * on the caller to prevent simultaneous use of the print buffer(s) being | ||
73 | * manipulated. | ||
74 | */ | ||
75 | |||
76 | static char print_string[TIPC_PB_MAX_STR]; | ||
77 | static DEFINE_SPINLOCK(print_lock); | ||
52 | 78 | ||
53 | 79 | ||
54 | #define FORMAT(PTR,LEN,FMT) \ | 80 | #define FORMAT(PTR,LEN,FMT) \ |
@@ -60,27 +86,14 @@ struct print_buf *TIPC_LOG = &log_buf; | |||
60 | *(PTR + LEN) = '\0';\ | 86 | *(PTR + LEN) = '\0';\ |
61 | } | 87 | } |
62 | 88 | ||
63 | /* | ||
64 | * Locking policy when using print buffers. | ||
65 | * | ||
66 | * The following routines use 'print_lock' for protection: | ||
67 | * 1) tipc_printf() - to protect its print buffer(s) and 'print_string' | ||
68 | * 2) TIPC_TEE() - to protect its print buffer(s) | ||
69 | * 3) tipc_dump() - to protect its print buffer(s) and 'print_string' | ||
70 | * 4) tipc_log_XXX() - to protect TIPC_LOG | ||
71 | * | ||
72 | * All routines of the form tipc_printbuf_XXX() rely on the caller to prevent | ||
73 | * simultaneous use of the print buffer(s) being manipulated. | ||
74 | */ | ||
75 | |||
76 | /** | 89 | /** |
77 | * tipc_printbuf_init - initialize print buffer to empty | 90 | * tipc_printbuf_init - initialize print buffer to empty |
78 | * @pb: pointer to print buffer structure | 91 | * @pb: pointer to print buffer structure |
79 | * @raw: pointer to character array used by print buffer | 92 | * @raw: pointer to character array used by print buffer |
80 | * @size: size of character array | 93 | * @size: size of character array |
81 | * | 94 | * |
82 | * Makes the print buffer a null device that discards anything written to it | 95 | * Note: If the character array is too small (or absent), the print buffer |
83 | * if the character array is too small (or absent). | 96 | * becomes a null device that discards anything written to it. |
84 | */ | 97 | */ |
85 | 98 | ||
86 | void tipc_printbuf_init(struct print_buf *pb, char *raw, u32 size) | 99 | void tipc_printbuf_init(struct print_buf *pb, char *raw, u32 size) |
@@ -88,13 +101,13 @@ void tipc_printbuf_init(struct print_buf *pb, char *raw, u32 size) | |||
88 | pb->buf = raw; | 101 | pb->buf = raw; |
89 | pb->crs = raw; | 102 | pb->crs = raw; |
90 | pb->size = size; | 103 | pb->size = size; |
91 | pb->next = NULL; | 104 | pb->echo = 0; |
92 | 105 | ||
93 | if (size < TIPC_PB_MIN_SIZE) { | 106 | if (size < TIPC_PB_MIN_SIZE) { |
94 | pb->buf = NULL; | 107 | pb->buf = NULL; |
95 | } else if (raw) { | 108 | } else if (raw) { |
96 | pb->buf[0] = 0; | 109 | pb->buf[0] = 0; |
97 | pb->buf[size-1] = ~0; | 110 | pb->buf[size - 1] = ~0; |
98 | } | 111 | } |
99 | } | 112 | } |
100 | 113 | ||
@@ -105,7 +118,11 @@ void tipc_printbuf_init(struct print_buf *pb, char *raw, u32 size) | |||
105 | 118 | ||
106 | void tipc_printbuf_reset(struct print_buf *pb) | 119 | void tipc_printbuf_reset(struct print_buf *pb) |
107 | { | 120 | { |
108 | tipc_printbuf_init(pb, pb->buf, pb->size); | 121 | if (pb->buf) { |
122 | pb->crs = pb->buf; | ||
123 | pb->buf[0] = 0; | ||
124 | pb->buf[pb->size - 1] = ~0; | ||
125 | } | ||
109 | } | 126 | } |
110 | 127 | ||
111 | /** | 128 | /** |
@@ -141,7 +158,7 @@ int tipc_printbuf_validate(struct print_buf *pb) | |||
141 | 158 | ||
142 | if (pb->buf[pb->size - 1] == 0) { | 159 | if (pb->buf[pb->size - 1] == 0) { |
143 | cp_buf = kmalloc(pb->size, GFP_ATOMIC); | 160 | cp_buf = kmalloc(pb->size, GFP_ATOMIC); |
144 | if (cp_buf != NULL){ | 161 | if (cp_buf) { |
145 | tipc_printbuf_init(&cb, cp_buf, pb->size); | 162 | tipc_printbuf_init(&cb, cp_buf, pb->size); |
146 | tipc_printbuf_move(&cb, pb); | 163 | tipc_printbuf_move(&cb, pb); |
147 | tipc_printbuf_move(pb, &cb); | 164 | tipc_printbuf_move(pb, &cb); |
@@ -179,15 +196,16 @@ void tipc_printbuf_move(struct print_buf *pb_to, struct print_buf *pb_from) | |||
179 | } | 196 | } |
180 | 197 | ||
181 | if (pb_to->size < pb_from->size) { | 198 | if (pb_to->size < pb_from->size) { |
182 | tipc_printbuf_reset(pb_to); | 199 | strcpy(pb_to->buf, "*** PRINT BUFFER MOVE ERROR ***"); |
183 | tipc_printf(pb_to, "*** PRINT BUFFER MOVE ERROR ***"); | 200 | pb_to->buf[pb_to->size - 1] = ~0; |
201 | pb_to->crs = strchr(pb_to->buf, 0); | ||
184 | return; | 202 | return; |
185 | } | 203 | } |
186 | 204 | ||
187 | /* Copy data from char after cursor to end (if used) */ | 205 | /* Copy data from char after cursor to end (if used) */ |
188 | 206 | ||
189 | len = pb_from->buf + pb_from->size - pb_from->crs - 2; | 207 | len = pb_from->buf + pb_from->size - pb_from->crs - 2; |
190 | if ((pb_from->buf[pb_from->size-1] == 0) && (len > 0)) { | 208 | if ((pb_from->buf[pb_from->size - 1] == 0) && (len > 0)) { |
191 | strcpy(pb_to->buf, pb_from->crs + 1); | 209 | strcpy(pb_to->buf, pb_from->crs + 1); |
192 | pb_to->crs = pb_to->buf + len; | 210 | pb_to->crs = pb_to->buf + len; |
193 | } else | 211 | } else |
@@ -203,8 +221,8 @@ void tipc_printbuf_move(struct print_buf *pb_to, struct print_buf *pb_from) | |||
203 | } | 221 | } |
204 | 222 | ||
205 | /** | 223 | /** |
206 | * tipc_printf - append formatted output to print buffer chain | 224 | * tipc_printf - append formatted output to print buffer |
207 | * @pb: pointer to chain of print buffers (may be NULL) | 225 | * @pb: pointer to print buffer |
208 | * @fmt: formatted info to be printed | 226 | * @fmt: formatted info to be printed |
209 | */ | 227 | */ |
210 | 228 | ||
@@ -213,68 +231,40 @@ void tipc_printf(struct print_buf *pb, const char *fmt, ...) | |||
213 | int chars_to_add; | 231 | int chars_to_add; |
214 | int chars_left; | 232 | int chars_left; |
215 | char save_char; | 233 | char save_char; |
216 | struct print_buf *pb_next; | ||
217 | 234 | ||
218 | spin_lock_bh(&print_lock); | 235 | spin_lock_bh(&print_lock); |
236 | |||
219 | FORMAT(print_string, chars_to_add, fmt); | 237 | FORMAT(print_string, chars_to_add, fmt); |
220 | if (chars_to_add >= TIPC_PB_MAX_STR) | 238 | if (chars_to_add >= TIPC_PB_MAX_STR) |
221 | strcpy(print_string, "*** PRINT BUFFER STRING TOO LONG ***"); | 239 | strcpy(print_string, "*** PRINT BUFFER STRING TOO LONG ***"); |
222 | 240 | ||
223 | while (pb) { | 241 | if (pb->buf) { |
224 | if (pb == TIPC_CONS) | 242 | chars_left = pb->buf + pb->size - pb->crs - 1; |
225 | printk(print_string); | 243 | if (chars_to_add <= chars_left) { |
226 | else if (pb->buf) { | 244 | strcpy(pb->crs, print_string); |
227 | chars_left = pb->buf + pb->size - pb->crs - 1; | 245 | pb->crs += chars_to_add; |
228 | if (chars_to_add <= chars_left) { | 246 | } else if (chars_to_add >= (pb->size - 1)) { |
229 | strcpy(pb->crs, print_string); | 247 | strcpy(pb->buf, print_string + chars_to_add + 1 |
230 | pb->crs += chars_to_add; | 248 | - pb->size); |
231 | } else if (chars_to_add >= (pb->size - 1)) { | 249 | pb->crs = pb->buf + pb->size - 1; |
232 | strcpy(pb->buf, print_string + chars_to_add + 1 | 250 | } else { |
233 | - pb->size); | 251 | strcpy(pb->buf, print_string + chars_left); |
234 | pb->crs = pb->buf + pb->size - 1; | 252 | save_char = print_string[chars_left]; |
235 | } else { | 253 | print_string[chars_left] = 0; |
236 | strcpy(pb->buf, print_string + chars_left); | 254 | strcpy(pb->crs, print_string); |
237 | save_char = print_string[chars_left]; | 255 | print_string[chars_left] = save_char; |
238 | print_string[chars_left] = 0; | 256 | pb->crs = pb->buf + chars_to_add - chars_left; |
239 | strcpy(pb->crs, print_string); | ||
240 | print_string[chars_left] = save_char; | ||
241 | pb->crs = pb->buf + chars_to_add - chars_left; | ||
242 | } | ||
243 | } | 257 | } |
244 | pb_next = pb->next; | ||
245 | pb->next = NULL; | ||
246 | pb = pb_next; | ||
247 | } | 258 | } |
248 | spin_unlock_bh(&print_lock); | ||
249 | } | ||
250 | 259 | ||
251 | /** | 260 | if (pb->echo) |
252 | * TIPC_TEE - perform next output operation on both print buffers | 261 | printk(print_string); |
253 | * @b0: pointer to chain of print buffers (may be NULL) | ||
254 | * @b1: pointer to print buffer to add to chain | ||
255 | * | ||
256 | * Returns pointer to print buffer chain. | ||
257 | */ | ||
258 | 262 | ||
259 | struct print_buf *TIPC_TEE(struct print_buf *b0, struct print_buf *b1) | ||
260 | { | ||
261 | struct print_buf *pb = b0; | ||
262 | |||
263 | if (!b0 || (b0 == b1)) | ||
264 | return b1; | ||
265 | |||
266 | spin_lock_bh(&print_lock); | ||
267 | while (pb->next) { | ||
268 | if ((pb->next == b1) || (pb->next == b0)) | ||
269 | pb->next = pb->next->next; | ||
270 | else | ||
271 | pb = pb->next; | ||
272 | } | ||
273 | pb->next = b1; | ||
274 | spin_unlock_bh(&print_lock); | 263 | spin_unlock_bh(&print_lock); |
275 | return b0; | ||
276 | } | 264 | } |
277 | 265 | ||
266 | #ifdef CONFIG_TIPC_DEBUG | ||
267 | |||
278 | /** | 268 | /** |
279 | * print_to_console - write string of bytes to console in multiple chunks | 269 | * print_to_console - write string of bytes to console in multiple chunks |
280 | */ | 270 | */ |
@@ -321,72 +311,66 @@ static void printbuf_dump(struct print_buf *pb) | |||
321 | } | 311 | } |
322 | 312 | ||
323 | /** | 313 | /** |
324 | * tipc_dump - dump non-console print buffer(s) to console | 314 | * tipc_dump_dbg - dump (non-console) print buffer to console |
325 | * @pb: pointer to chain of print buffers | 315 | * @pb: pointer to print buffer |
326 | */ | 316 | */ |
327 | 317 | ||
328 | void tipc_dump(struct print_buf *pb, const char *fmt, ...) | 318 | void tipc_dump_dbg(struct print_buf *pb, const char *fmt, ...) |
329 | { | 319 | { |
330 | struct print_buf *pb_next; | ||
331 | int len; | 320 | int len; |
332 | 321 | ||
322 | if (pb == TIPC_CONS) | ||
323 | return; | ||
324 | |||
333 | spin_lock_bh(&print_lock); | 325 | spin_lock_bh(&print_lock); |
326 | |||
334 | FORMAT(print_string, len, fmt); | 327 | FORMAT(print_string, len, fmt); |
335 | printk(print_string); | 328 | printk(print_string); |
336 | 329 | ||
337 | for (; pb; pb = pb->next) { | 330 | printk("\n---- Start of %s log dump ----\n\n", |
338 | if (pb != TIPC_CONS) { | 331 | (pb == TIPC_LOG) ? "global" : "local"); |
339 | printk("\n---- Start of %s log dump ----\n\n", | 332 | printbuf_dump(pb); |
340 | (pb == TIPC_LOG) ? "global" : "local"); | 333 | tipc_printbuf_reset(pb); |
341 | printbuf_dump(pb); | 334 | printk("\n---- End of dump ----\n"); |
342 | tipc_printbuf_reset(pb); | 335 | |
343 | printk("\n---- End of dump ----\n"); | ||
344 | } | ||
345 | pb_next = pb->next; | ||
346 | pb->next = NULL; | ||
347 | pb = pb_next; | ||
348 | } | ||
349 | spin_unlock_bh(&print_lock); | 336 | spin_unlock_bh(&print_lock); |
350 | } | 337 | } |
351 | 338 | ||
339 | #endif | ||
340 | |||
352 | /** | 341 | /** |
353 | * tipc_log_stop - free up TIPC log print buffer | 342 | * tipc_log_resize - change the size of the TIPC log buffer |
343 | * @log_size: print buffer size to use | ||
354 | */ | 344 | */ |
355 | 345 | ||
356 | void tipc_log_stop(void) | 346 | int tipc_log_resize(int log_size) |
357 | { | 347 | { |
348 | int res = 0; | ||
349 | |||
358 | spin_lock_bh(&print_lock); | 350 | spin_lock_bh(&print_lock); |
359 | if (TIPC_LOG->buf) { | 351 | if (TIPC_LOG->buf) { |
360 | kfree(TIPC_LOG->buf); | 352 | kfree(TIPC_LOG->buf); |
361 | TIPC_LOG->buf = NULL; | 353 | TIPC_LOG->buf = NULL; |
362 | } | 354 | } |
363 | spin_unlock_bh(&print_lock); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * tipc_log_reinit - (re)initialize TIPC log print buffer | ||
368 | * @log_size: print buffer size to use | ||
369 | */ | ||
370 | |||
371 | void tipc_log_reinit(int log_size) | ||
372 | { | ||
373 | tipc_log_stop(); | ||
374 | |||
375 | if (log_size) { | 355 | if (log_size) { |
376 | if (log_size < TIPC_PB_MIN_SIZE) | 356 | if (log_size < TIPC_PB_MIN_SIZE) |
377 | log_size = TIPC_PB_MIN_SIZE; | 357 | log_size = TIPC_PB_MIN_SIZE; |
378 | spin_lock_bh(&print_lock); | 358 | res = TIPC_LOG->echo; |
379 | tipc_printbuf_init(TIPC_LOG, kmalloc(log_size, GFP_ATOMIC), | 359 | tipc_printbuf_init(TIPC_LOG, kmalloc(log_size, GFP_ATOMIC), |
380 | log_size); | 360 | log_size); |
381 | spin_unlock_bh(&print_lock); | 361 | TIPC_LOG->echo = res; |
362 | res = !TIPC_LOG->buf; | ||
382 | } | 363 | } |
364 | spin_unlock_bh(&print_lock); | ||
365 | |||
366 | return res; | ||
383 | } | 367 | } |
384 | 368 | ||
385 | /** | 369 | /** |
386 | * tipc_log_resize - reconfigure size of TIPC log buffer | 370 | * tipc_log_resize_cmd - reconfigure size of TIPC log buffer |
387 | */ | 371 | */ |
388 | 372 | ||
389 | struct sk_buff *tipc_log_resize(const void *req_tlv_area, int req_tlv_space) | 373 | struct sk_buff *tipc_log_resize_cmd(const void *req_tlv_area, int req_tlv_space) |
390 | { | 374 | { |
391 | u32 value; | 375 | u32 value; |
392 | 376 | ||
@@ -397,7 +381,9 @@ struct sk_buff *tipc_log_resize(const void *req_tlv_area, int req_tlv_space) | |||
397 | if (value != delimit(value, 0, 32768)) | 381 | if (value != delimit(value, 0, 32768)) |
398 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 382 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
399 | " (log size must be 0-32768)"); | 383 | " (log size must be 0-32768)"); |
400 | tipc_log_reinit(value); | 384 | if (tipc_log_resize(value)) |
385 | return tipc_cfg_reply_error_string( | ||
386 | "unable to create specified log (log size is now 0)"); | ||
401 | return tipc_cfg_reply_none(); | 387 | return tipc_cfg_reply_none(); |
402 | } | 388 | } |
403 | 389 | ||
@@ -410,27 +396,32 @@ struct sk_buff *tipc_log_dump(void) | |||
410 | struct sk_buff *reply; | 396 | struct sk_buff *reply; |
411 | 397 | ||
412 | spin_lock_bh(&print_lock); | 398 | spin_lock_bh(&print_lock); |
413 | if (!TIPC_LOG->buf) | 399 | if (!TIPC_LOG->buf) { |
400 | spin_unlock_bh(&print_lock); | ||
414 | reply = tipc_cfg_reply_ultra_string("log not activated\n"); | 401 | reply = tipc_cfg_reply_ultra_string("log not activated\n"); |
415 | else if (tipc_printbuf_empty(TIPC_LOG)) | 402 | } else if (tipc_printbuf_empty(TIPC_LOG)) { |
403 | spin_unlock_bh(&print_lock); | ||
416 | reply = tipc_cfg_reply_ultra_string("log is empty\n"); | 404 | reply = tipc_cfg_reply_ultra_string("log is empty\n"); |
405 | } | ||
417 | else { | 406 | else { |
418 | struct tlv_desc *rep_tlv; | 407 | struct tlv_desc *rep_tlv; |
419 | struct print_buf pb; | 408 | struct print_buf pb; |
420 | int str_len; | 409 | int str_len; |
421 | 410 | ||
422 | str_len = min(TIPC_LOG->size, 32768u); | 411 | str_len = min(TIPC_LOG->size, 32768u); |
412 | spin_unlock_bh(&print_lock); | ||
423 | reply = tipc_cfg_reply_alloc(TLV_SPACE(str_len)); | 413 | reply = tipc_cfg_reply_alloc(TLV_SPACE(str_len)); |
424 | if (reply) { | 414 | if (reply) { |
425 | rep_tlv = (struct tlv_desc *)reply->data; | 415 | rep_tlv = (struct tlv_desc *)reply->data; |
426 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), str_len); | 416 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), str_len); |
417 | spin_lock_bh(&print_lock); | ||
427 | tipc_printbuf_move(&pb, TIPC_LOG); | 418 | tipc_printbuf_move(&pb, TIPC_LOG); |
419 | spin_unlock_bh(&print_lock); | ||
428 | str_len = strlen(TLV_DATA(rep_tlv)) + 1; | 420 | str_len = strlen(TLV_DATA(rep_tlv)) + 1; |
429 | skb_put(reply, TLV_SPACE(str_len)); | 421 | skb_put(reply, TLV_SPACE(str_len)); |
430 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | 422 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
431 | } | 423 | } |
432 | } | 424 | } |
433 | spin_unlock_bh(&print_lock); | ||
434 | return reply; | 425 | return reply; |
435 | } | 426 | } |
436 | 427 | ||
diff --git a/net/tipc/dbg.h b/net/tipc/dbg.h index c01b085000e0..5ef1bc8f64ef 100644 --- a/net/tipc/dbg.h +++ b/net/tipc/dbg.h | |||
@@ -2,7 +2,7 @@ | |||
2 | * net/tipc/dbg.h: Include file for TIPC print buffer routines | 2 | * net/tipc/dbg.h: Include file for TIPC print buffer routines |
3 | * | 3 | * |
4 | * Copyright (c) 1997-2006, Ericsson AB | 4 | * Copyright (c) 1997-2006, Ericsson AB |
5 | * Copyright (c) 2005-2006, Wind River Systems | 5 | * Copyright (c) 2005-2007, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
@@ -42,14 +42,14 @@ | |||
42 | * @buf: pointer to character array containing print buffer contents | 42 | * @buf: pointer to character array containing print buffer contents |
43 | * @size: size of character array | 43 | * @size: size of character array |
44 | * @crs: pointer to first unused space in character array (i.e. final NUL) | 44 | * @crs: pointer to first unused space in character array (i.e. final NUL) |
45 | * @next: used to link print buffers when printing to more than one at a time | 45 | * @echo: echo output to system console if non-zero |
46 | */ | 46 | */ |
47 | 47 | ||
48 | struct print_buf { | 48 | struct print_buf { |
49 | char *buf; | 49 | char *buf; |
50 | u32 size; | 50 | u32 size; |
51 | char *crs; | 51 | char *crs; |
52 | struct print_buf *next; | 52 | int echo; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | #define TIPC_PB_MIN_SIZE 64 /* minimum size for a print buffer's array */ | 55 | #define TIPC_PB_MIN_SIZE 64 /* minimum size for a print buffer's array */ |
@@ -61,10 +61,10 @@ int tipc_printbuf_empty(struct print_buf *pb); | |||
61 | int tipc_printbuf_validate(struct print_buf *pb); | 61 | int tipc_printbuf_validate(struct print_buf *pb); |
62 | void tipc_printbuf_move(struct print_buf *pb_to, struct print_buf *pb_from); | 62 | void tipc_printbuf_move(struct print_buf *pb_to, struct print_buf *pb_from); |
63 | 63 | ||
64 | void tipc_log_reinit(int log_size); | 64 | int tipc_log_resize(int log_size); |
65 | void tipc_log_stop(void); | ||
66 | 65 | ||
67 | struct sk_buff *tipc_log_resize(const void *req_tlv_area, int req_tlv_space); | 66 | struct sk_buff *tipc_log_resize_cmd(const void *req_tlv_area, |
67 | int req_tlv_space); | ||
68 | struct sk_buff *tipc_log_dump(void); | 68 | struct sk_buff *tipc_log_dump(void); |
69 | 69 | ||
70 | #endif | 70 | #endif |
diff --git a/net/tipc/link.c b/net/tipc/link.c index 2a26a16e269f..bd206ebe4eea 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c | |||
@@ -147,9 +147,21 @@ static void link_print(struct link *l_ptr, struct print_buf *buf, | |||
147 | 147 | ||
148 | #define LINK_LOG_BUF_SIZE 0 | 148 | #define LINK_LOG_BUF_SIZE 0 |
149 | 149 | ||
150 | #define dbg_link(fmt, arg...) do {if (LINK_LOG_BUF_SIZE) tipc_printf(&l_ptr->print_buf, fmt, ## arg); } while(0) | 150 | #define dbg_link(fmt, arg...) \ |
151 | #define dbg_link_msg(msg, txt) do {if (LINK_LOG_BUF_SIZE) tipc_msg_print(&l_ptr->print_buf, msg, txt); } while(0) | 151 | do { \ |
152 | #define dbg_link_state(txt) do {if (LINK_LOG_BUF_SIZE) link_print(l_ptr, &l_ptr->print_buf, txt); } while(0) | 152 | if (LINK_LOG_BUF_SIZE) \ |
153 | tipc_printf(&l_ptr->print_buf, fmt, ## arg); \ | ||
154 | } while (0) | ||
155 | #define dbg_link_msg(msg, txt) \ | ||
156 | do { \ | ||
157 | if (LINK_LOG_BUF_SIZE) \ | ||
158 | tipc_msg_dbg(&l_ptr->print_buf, msg, txt); \ | ||
159 | } while (0) | ||
160 | #define dbg_link_state(txt) \ | ||
161 | do { \ | ||
162 | if (LINK_LOG_BUF_SIZE) \ | ||
163 | link_print(l_ptr, &l_ptr->print_buf, txt); \ | ||
164 | } while (0) | ||
153 | #define dbg_link_dump() do { \ | 165 | #define dbg_link_dump() do { \ |
154 | if (LINK_LOG_BUF_SIZE) { \ | 166 | if (LINK_LOG_BUF_SIZE) { \ |
155 | tipc_printf(LOG, "\n\nDumping link <%s>:\n", l_ptr->name); \ | 167 | tipc_printf(LOG, "\n\nDumping link <%s>:\n", l_ptr->name); \ |
@@ -1651,7 +1663,7 @@ static void link_retransmit_failure(struct link *l_ptr, struct sk_buff *buf) | |||
1651 | struct tipc_msg *msg = buf_msg(buf); | 1663 | struct tipc_msg *msg = buf_msg(buf); |
1652 | 1664 | ||
1653 | warn("Retransmission failure on link <%s>\n", l_ptr->name); | 1665 | warn("Retransmission failure on link <%s>\n", l_ptr->name); |
1654 | tipc_msg_print(TIPC_OUTPUT, msg, ">RETR-FAIL>"); | 1666 | tipc_msg_dbg(TIPC_OUTPUT, msg, ">RETR-FAIL>"); |
1655 | 1667 | ||
1656 | if (l_ptr->addr) { | 1668 | if (l_ptr->addr) { |
1657 | 1669 | ||
diff --git a/net/tipc/msg.c b/net/tipc/msg.c index 696a8633df75..38abebaae889 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c | |||
@@ -41,7 +41,9 @@ | |||
41 | #include "bearer.h" | 41 | #include "bearer.h" |
42 | 42 | ||
43 | 43 | ||
44 | void tipc_msg_print(struct print_buf *buf, struct tipc_msg *msg, const char *str) | 44 | #ifdef CONFIG_TIPC_DEBUG |
45 | |||
46 | void tipc_msg_dbg(struct print_buf *buf, struct tipc_msg *msg, const char *str) | ||
45 | { | 47 | { |
46 | u32 usr = msg_user(msg); | 48 | u32 usr = msg_user(msg); |
47 | tipc_printf(buf, str); | 49 | tipc_printf(buf, str); |
@@ -315,9 +317,11 @@ void tipc_msg_print(struct print_buf *buf, struct tipc_msg *msg, const char *str | |||
315 | } | 317 | } |
316 | tipc_printf(buf, "\n"); | 318 | tipc_printf(buf, "\n"); |
317 | if ((usr == CHANGEOVER_PROTOCOL) && (msg_msgcnt(msg))) { | 319 | if ((usr == CHANGEOVER_PROTOCOL) && (msg_msgcnt(msg))) { |
318 | tipc_msg_print(buf,msg_get_wrapped(msg)," /"); | 320 | tipc_msg_dbg(buf, msg_get_wrapped(msg), " /"); |
319 | } | 321 | } |
320 | if ((usr == MSG_FRAGMENTER) && (msg_type(msg) == FIRST_FRAGMENT)) { | 322 | if ((usr == MSG_FRAGMENTER) && (msg_type(msg) == FIRST_FRAGMENT)) { |
321 | tipc_msg_print(buf,msg_get_wrapped(msg)," /"); | 323 | tipc_msg_dbg(buf, msg_get_wrapped(msg), " /"); |
322 | } | 324 | } |
323 | } | 325 | } |
326 | |||
327 | #endif | ||
diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c index 39fd1619febf..aecba5cd87d6 100644 --- a/net/tipc/name_distr.c +++ b/net/tipc/name_distr.c | |||
@@ -41,9 +41,6 @@ | |||
41 | #include "msg.h" | 41 | #include "msg.h" |
42 | #include "name_distr.h" | 42 | #include "name_distr.h" |
43 | 43 | ||
44 | #undef DBG_OUTPUT | ||
45 | #define DBG_OUTPUT NULL | ||
46 | |||
47 | #define ITEM_SIZE sizeof(struct distr_item) | 44 | #define ITEM_SIZE sizeof(struct distr_item) |
48 | 45 | ||
49 | /** | 46 | /** |
diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c index ac7dfdda7973..892373e498e4 100644 --- a/net/tipc/name_table.c +++ b/net/tipc/name_table.c | |||
@@ -1050,15 +1050,12 @@ void tipc_nametbl_dump(void) | |||
1050 | 1050 | ||
1051 | int tipc_nametbl_init(void) | 1051 | int tipc_nametbl_init(void) |
1052 | { | 1052 | { |
1053 | int array_size = sizeof(struct hlist_head) * tipc_nametbl_size; | 1053 | table.types = kcalloc(tipc_nametbl_size, sizeof(struct hlist_head), |
1054 | 1054 | GFP_ATOMIC); | |
1055 | table.types = kzalloc(array_size, GFP_ATOMIC); | ||
1056 | if (!table.types) | 1055 | if (!table.types) |
1057 | return -ENOMEM; | 1056 | return -ENOMEM; |
1058 | 1057 | ||
1059 | write_lock_bh(&tipc_nametbl_lock); | ||
1060 | table.local_publ_count = 0; | 1058 | table.local_publ_count = 0; |
1061 | write_unlock_bh(&tipc_nametbl_lock); | ||
1062 | return 0; | 1059 | return 0; |
1063 | } | 1060 | } |
1064 | 1061 | ||
diff --git a/net/tipc/port.c b/net/tipc/port.c index 2f5806410c64..757de38fe6af 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c | |||
@@ -211,15 +211,18 @@ exit: | |||
211 | } | 211 | } |
212 | 212 | ||
213 | /** | 213 | /** |
214 | * tipc_createport_raw - create a native TIPC port | 214 | * tipc_createport_raw - create a generic TIPC port |
215 | * | 215 | * |
216 | * Returns local port reference | 216 | * Returns port reference, or 0 if unable to create it |
217 | * | ||
218 | * Note: The newly created port is returned in the locked state. | ||
217 | */ | 219 | */ |
218 | 220 | ||
219 | u32 tipc_createport_raw(void *usr_handle, | 221 | u32 tipc_createport_raw(void *usr_handle, |
220 | u32 (*dispatcher)(struct tipc_port *, struct sk_buff *), | 222 | u32 (*dispatcher)(struct tipc_port *, struct sk_buff *), |
221 | void (*wakeup)(struct tipc_port *), | 223 | void (*wakeup)(struct tipc_port *), |
222 | const u32 importance) | 224 | const u32 importance, |
225 | struct tipc_port **tp_ptr) | ||
223 | { | 226 | { |
224 | struct port *p_ptr; | 227 | struct port *p_ptr; |
225 | struct tipc_msg *msg; | 228 | struct tipc_msg *msg; |
@@ -237,7 +240,6 @@ u32 tipc_createport_raw(void *usr_handle, | |||
237 | return 0; | 240 | return 0; |
238 | } | 241 | } |
239 | 242 | ||
240 | tipc_port_lock(ref); | ||
241 | p_ptr->publ.usr_handle = usr_handle; | 243 | p_ptr->publ.usr_handle = usr_handle; |
242 | p_ptr->publ.max_pkt = MAX_PKT_DEFAULT; | 244 | p_ptr->publ.max_pkt = MAX_PKT_DEFAULT; |
243 | p_ptr->publ.ref = ref; | 245 | p_ptr->publ.ref = ref; |
@@ -262,7 +264,7 @@ u32 tipc_createport_raw(void *usr_handle, | |||
262 | INIT_LIST_HEAD(&p_ptr->port_list); | 264 | INIT_LIST_HEAD(&p_ptr->port_list); |
263 | list_add_tail(&p_ptr->port_list, &ports); | 265 | list_add_tail(&p_ptr->port_list, &ports); |
264 | spin_unlock_bh(&tipc_port_list_lock); | 266 | spin_unlock_bh(&tipc_port_list_lock); |
265 | tipc_port_unlock(p_ptr); | 267 | *tp_ptr = &p_ptr->publ; |
266 | return ref; | 268 | return ref; |
267 | } | 269 | } |
268 | 270 | ||
@@ -1053,6 +1055,7 @@ int tipc_createport(u32 user_ref, | |||
1053 | { | 1055 | { |
1054 | struct user_port *up_ptr; | 1056 | struct user_port *up_ptr; |
1055 | struct port *p_ptr; | 1057 | struct port *p_ptr; |
1058 | struct tipc_port *tp_ptr; | ||
1056 | u32 ref; | 1059 | u32 ref; |
1057 | 1060 | ||
1058 | up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC); | 1061 | up_ptr = kmalloc(sizeof(*up_ptr), GFP_ATOMIC); |
@@ -1060,12 +1063,13 @@ int tipc_createport(u32 user_ref, | |||
1060 | warn("Port creation failed, no memory\n"); | 1063 | warn("Port creation failed, no memory\n"); |
1061 | return -ENOMEM; | 1064 | return -ENOMEM; |
1062 | } | 1065 | } |
1063 | ref = tipc_createport_raw(NULL, port_dispatcher, port_wakeup, importance); | 1066 | ref = tipc_createport_raw(NULL, port_dispatcher, port_wakeup, |
1064 | p_ptr = tipc_port_lock(ref); | 1067 | importance, &tp_ptr); |
1065 | if (!p_ptr) { | 1068 | if (ref == 0) { |
1066 | kfree(up_ptr); | 1069 | kfree(up_ptr); |
1067 | return -ENOMEM; | 1070 | return -ENOMEM; |
1068 | } | 1071 | } |
1072 | p_ptr = (struct port *)tp_ptr; | ||
1069 | 1073 | ||
1070 | p_ptr->user_port = up_ptr; | 1074 | p_ptr->user_port = up_ptr; |
1071 | up_ptr->user_ref = user_ref; | 1075 | up_ptr->user_ref = user_ref; |
diff --git a/net/tipc/ref.c b/net/tipc/ref.c index 89cbab24d08f..a101de86824d 100644 --- a/net/tipc/ref.c +++ b/net/tipc/ref.c | |||
@@ -142,9 +142,13 @@ void tipc_ref_table_stop(void) | |||
142 | /** | 142 | /** |
143 | * tipc_ref_acquire - create reference to an object | 143 | * tipc_ref_acquire - create reference to an object |
144 | * | 144 | * |
145 | * Return a unique reference value which can be translated back to the pointer | 145 | * Register an object pointer in reference table and lock the object. |
146 | * 'object' at a later time. Also, pass back a pointer to the lock protecting | 146 | * Returns a unique reference value that is used from then on to retrieve the |
147 | * the object, but without locking it. | 147 | * object pointer, or to determine that the object has been deregistered. |
148 | * | ||
149 | * Note: The object is returned in the locked state so that the caller can | ||
150 | * register a partially initialized object, without running the risk that | ||
151 | * the object will be accessed before initialization is complete. | ||
148 | */ | 152 | */ |
149 | 153 | ||
150 | u32 tipc_ref_acquire(void *object, spinlock_t **lock) | 154 | u32 tipc_ref_acquire(void *object, spinlock_t **lock) |
@@ -178,13 +182,13 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock) | |||
178 | ref = (next_plus_upper & ~index_mask) + index; | 182 | ref = (next_plus_upper & ~index_mask) + index; |
179 | entry->ref = ref; | 183 | entry->ref = ref; |
180 | entry->object = object; | 184 | entry->object = object; |
181 | spin_unlock_bh(&entry->lock); | ||
182 | *lock = &entry->lock; | 185 | *lock = &entry->lock; |
183 | } | 186 | } |
184 | else if (tipc_ref_table.init_point < tipc_ref_table.capacity) { | 187 | else if (tipc_ref_table.init_point < tipc_ref_table.capacity) { |
185 | index = tipc_ref_table.init_point++; | 188 | index = tipc_ref_table.init_point++; |
186 | entry = &(tipc_ref_table.entries[index]); | 189 | entry = &(tipc_ref_table.entries[index]); |
187 | spin_lock_init(&entry->lock); | 190 | spin_lock_init(&entry->lock); |
191 | spin_lock_bh(&entry->lock); | ||
188 | ref = tipc_ref_table.start_mask + index; | 192 | ref = tipc_ref_table.start_mask + index; |
189 | entry->ref = ref; | 193 | entry->ref = ref; |
190 | entry->object = object; | 194 | entry->object = object; |
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 230f9ca2ad6b..38f48795b40e 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -188,6 +188,7 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol) | |||
188 | const struct proto_ops *ops; | 188 | const struct proto_ops *ops; |
189 | socket_state state; | 189 | socket_state state; |
190 | struct sock *sk; | 190 | struct sock *sk; |
191 | struct tipc_port *tp_ptr; | ||
191 | u32 portref; | 192 | u32 portref; |
192 | 193 | ||
193 | /* Validate arguments */ | 194 | /* Validate arguments */ |
@@ -225,7 +226,7 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol) | |||
225 | /* Allocate TIPC port for socket to use */ | 226 | /* Allocate TIPC port for socket to use */ |
226 | 227 | ||
227 | portref = tipc_createport_raw(sk, &dispatch, &wakeupdispatch, | 228 | portref = tipc_createport_raw(sk, &dispatch, &wakeupdispatch, |
228 | TIPC_LOW_IMPORTANCE); | 229 | TIPC_LOW_IMPORTANCE, &tp_ptr); |
229 | if (unlikely(portref == 0)) { | 230 | if (unlikely(portref == 0)) { |
230 | sk_free(sk); | 231 | sk_free(sk); |
231 | return -ENOMEM; | 232 | return -ENOMEM; |
@@ -241,6 +242,8 @@ static int tipc_create(struct net *net, struct socket *sock, int protocol) | |||
241 | sk->sk_backlog_rcv = backlog_rcv; | 242 | sk->sk_backlog_rcv = backlog_rcv; |
242 | tipc_sk(sk)->p = tipc_get_port(portref); | 243 | tipc_sk(sk)->p = tipc_get_port(portref); |
243 | 244 | ||
245 | spin_unlock_bh(tp_ptr->lock); | ||
246 | |||
244 | if (sock->state == SS_READY) { | 247 | if (sock->state == SS_READY) { |
245 | tipc_set_portunreturnable(portref, 1); | 248 | tipc_set_portunreturnable(portref, 1); |
246 | if (sock->type == SOCK_DGRAM) | 249 | if (sock->type == SOCK_DGRAM) |
diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c index 8c01ccd3626c..8f8d0a6c1c16 100644 --- a/net/tipc/subscr.c +++ b/net/tipc/subscr.c | |||
@@ -474,6 +474,7 @@ static void subscr_named_msg_event(void *usr_handle, | |||
474 | kfree(subscriber); | 474 | kfree(subscriber); |
475 | return; | 475 | return; |
476 | } | 476 | } |
477 | spin_unlock_bh(subscriber->lock); | ||
477 | 478 | ||
478 | /* Establish a connection to subscriber */ | 479 | /* Establish a connection to subscriber */ |
479 | 480 | ||