Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/dbg.c: TIPC print buffer routines for debuggign |
| 3 | * |
Per Liden | 593a5f2 | 2006-01-11 19:14:19 +0100 | [diff] [blame] | 4 | * Copyright (c) 1996-2006, Ericsson AB |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 5 | * Copyright (c) 2005, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 | * Redistribution and use in source and binary forms, with or without |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the names of the copyright holders nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 20 | * Alternatively, this software may be distributed under the terms of the |
| 21 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 22 | * Software Foundation. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
| 38 | #include "config.h" |
| 39 | #include "dbg.h" |
| 40 | |
| 41 | #define MAX_STRING 512 |
| 42 | |
| 43 | static char print_string[MAX_STRING]; |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 44 | static DEFINE_SPINLOCK(print_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 45 | |
| 46 | static struct print_buf cons_buf = { NULL, 0, NULL, NULL }; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 47 | struct print_buf *TIPC_CONS = &cons_buf; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 48 | |
| 49 | static struct print_buf log_buf = { NULL, 0, NULL, NULL }; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 50 | struct print_buf *TIPC_LOG = &log_buf; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 51 | |
| 52 | |
| 53 | #define FORMAT(PTR,LEN,FMT) \ |
| 54 | {\ |
| 55 | va_list args;\ |
| 56 | va_start(args, FMT);\ |
| 57 | LEN = vsprintf(PTR, FMT, args);\ |
| 58 | va_end(args);\ |
| 59 | *(PTR + LEN) = '\0';\ |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * Locking policy when using print buffers. |
| 64 | * |
| 65 | * 1) Routines of the form printbuf_XXX() rely on the caller to prevent |
| 66 | * simultaneous use of the print buffer(s) being manipulated. |
| 67 | * 2) tipc_printf() uses 'print_lock' to prevent simultaneous use of |
| 68 | * 'print_string' and to protect its print buffer(s). |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 69 | * 3) TIPC_TEE() uses 'print_lock' to protect its print buffer(s). |
| 70 | * 4) Routines of the form log_XXX() uses 'print_lock' to protect TIPC_LOG. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 71 | */ |
| 72 | |
| 73 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 74 | * tipc_printbuf_init - initialize print buffer to empty |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 75 | */ |
| 76 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 77 | void tipc_printbuf_init(struct print_buf *pb, char *raw, u32 sz) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 78 | { |
| 79 | if (!pb || !raw || (sz < (MAX_STRING + 1))) |
| 80 | return; |
| 81 | |
| 82 | pb->crs = pb->buf = raw; |
| 83 | pb->size = sz; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 84 | pb->next = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 85 | pb->buf[0] = 0; |
| 86 | pb->buf[sz-1] = ~0; |
| 87 | } |
| 88 | |
| 89 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 90 | * tipc_printbuf_reset - reinitialize print buffer to empty state |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 91 | */ |
| 92 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 93 | void tipc_printbuf_reset(struct print_buf *pb) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 94 | { |
| 95 | if (pb && pb->buf) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 96 | tipc_printbuf_init(pb, pb->buf, pb->size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 100 | * tipc_printbuf_empty - test if print buffer is in empty state |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 101 | */ |
| 102 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 103 | int tipc_printbuf_empty(struct print_buf *pb) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 104 | { |
| 105 | return (!pb || !pb->buf || (pb->crs == pb->buf)); |
| 106 | } |
| 107 | |
| 108 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 109 | * tipc_printbuf_validate - check for print buffer overflow |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 110 | * |
| 111 | * Verifies that a print buffer has captured all data written to it. |
| 112 | * If data has been lost, linearize buffer and prepend an error message |
| 113 | * |
| 114 | * Returns length of print buffer data string (including trailing NULL) |
| 115 | */ |
| 116 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 117 | int tipc_printbuf_validate(struct print_buf *pb) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 118 | { |
| 119 | char *err = " *** PRINT BUFFER WRAPPED AROUND ***\n"; |
| 120 | char *cp_buf; |
| 121 | struct print_buf cb; |
| 122 | |
| 123 | if (!pb || !pb->buf) |
| 124 | return 0; |
| 125 | |
| 126 | if (pb->buf[pb->size - 1] == '\0') { |
| 127 | cp_buf = kmalloc(pb->size, GFP_ATOMIC); |
| 128 | if (cp_buf != NULL){ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 129 | tipc_printbuf_init(&cb, cp_buf, pb->size); |
| 130 | tipc_printbuf_move(&cb, pb); |
| 131 | tipc_printbuf_move(pb, &cb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 132 | kfree(cp_buf); |
| 133 | memcpy(pb->buf, err, strlen(err)); |
| 134 | } else { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 135 | tipc_printbuf_reset(pb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 136 | tipc_printf(pb, err); |
| 137 | } |
| 138 | } |
| 139 | return (pb->crs - pb->buf + 1); |
| 140 | } |
| 141 | |
| 142 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 143 | * tipc_printbuf_move - move print buffer contents to another print buffer |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 144 | * |
| 145 | * Current contents of destination print buffer (if any) are discarded. |
| 146 | * Source print buffer becomes empty if a successful move occurs. |
| 147 | */ |
| 148 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 149 | void tipc_printbuf_move(struct print_buf *pb_to, struct print_buf *pb_from) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 150 | { |
| 151 | int len; |
| 152 | |
| 153 | /* Handle the cases where contents can't be moved */ |
| 154 | |
| 155 | if (!pb_to || !pb_to->buf) |
| 156 | return; |
| 157 | |
| 158 | if (!pb_from || !pb_from->buf) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 159 | tipc_printbuf_reset(pb_to); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | |
| 163 | if (pb_to->size < pb_from->size) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 164 | tipc_printbuf_reset(pb_to); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 165 | tipc_printf(pb_to, "*** PRINT BUFFER OVERFLOW ***"); |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | /* Copy data from char after cursor to end (if used) */ |
| 170 | len = pb_from->buf + pb_from->size - pb_from->crs - 2; |
| 171 | if ((pb_from->buf[pb_from->size-1] == 0) && (len > 0)) { |
| 172 | strcpy(pb_to->buf, pb_from->crs + 1); |
| 173 | pb_to->crs = pb_to->buf + len; |
| 174 | } else |
| 175 | pb_to->crs = pb_to->buf; |
| 176 | |
| 177 | /* Copy data from start to cursor (always) */ |
| 178 | len = pb_from->crs - pb_from->buf; |
| 179 | strcpy(pb_to->crs, pb_from->buf); |
| 180 | pb_to->crs += len; |
| 181 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 182 | tipc_printbuf_reset(pb_from); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /** |
| 186 | * tipc_printf - append formatted output to print buffer chain |
| 187 | */ |
| 188 | |
| 189 | void tipc_printf(struct print_buf *pb, const char *fmt, ...) |
| 190 | { |
| 191 | int chars_to_add; |
| 192 | int chars_left; |
| 193 | char save_char; |
| 194 | struct print_buf *pb_next; |
| 195 | |
| 196 | spin_lock_bh(&print_lock); |
| 197 | FORMAT(print_string, chars_to_add, fmt); |
| 198 | if (chars_to_add >= MAX_STRING) |
| 199 | strcpy(print_string, "*** STRING TOO LONG ***"); |
| 200 | |
| 201 | while (pb) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 202 | if (pb == TIPC_CONS) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 203 | printk(print_string); |
| 204 | else if (pb->buf) { |
| 205 | chars_left = pb->buf + pb->size - pb->crs - 1; |
| 206 | if (chars_to_add <= chars_left) { |
| 207 | strcpy(pb->crs, print_string); |
| 208 | pb->crs += chars_to_add; |
| 209 | } else { |
| 210 | strcpy(pb->buf, print_string + chars_left); |
| 211 | save_char = print_string[chars_left]; |
| 212 | print_string[chars_left] = 0; |
| 213 | strcpy(pb->crs, print_string); |
| 214 | print_string[chars_left] = save_char; |
| 215 | pb->crs = pb->buf + chars_to_add - chars_left; |
| 216 | } |
| 217 | } |
| 218 | pb_next = pb->next; |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 219 | pb->next = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 220 | pb = pb_next; |
| 221 | } |
| 222 | spin_unlock_bh(&print_lock); |
| 223 | } |
| 224 | |
| 225 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 226 | * TIPC_TEE - perform next output operation on both print buffers |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 227 | */ |
| 228 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 229 | struct print_buf *TIPC_TEE(struct print_buf *b0, struct print_buf *b1) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 230 | { |
| 231 | struct print_buf *pb = b0; |
| 232 | |
| 233 | if (!b0 || (b0 == b1)) |
| 234 | return b1; |
| 235 | if (!b1) |
| 236 | return b0; |
| 237 | |
| 238 | spin_lock_bh(&print_lock); |
| 239 | while (pb->next) { |
| 240 | if ((pb->next == b1) || (pb->next == b0)) |
| 241 | pb->next = pb->next->next; |
| 242 | else |
| 243 | pb = pb->next; |
| 244 | } |
| 245 | pb->next = b1; |
| 246 | spin_unlock_bh(&print_lock); |
| 247 | return b0; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * print_to_console - write string of bytes to console in multiple chunks |
| 252 | */ |
| 253 | |
| 254 | static void print_to_console(char *crs, int len) |
| 255 | { |
| 256 | int rest = len; |
| 257 | |
| 258 | while (rest > 0) { |
| 259 | int sz = rest < MAX_STRING ? rest : MAX_STRING; |
| 260 | char c = crs[sz]; |
| 261 | |
| 262 | crs[sz] = 0; |
| 263 | printk((const char *)crs); |
| 264 | crs[sz] = c; |
| 265 | rest -= sz; |
| 266 | crs += sz; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * printbuf_dump - write print buffer contents to console |
| 272 | */ |
| 273 | |
| 274 | static void printbuf_dump(struct print_buf *pb) |
| 275 | { |
| 276 | int len; |
| 277 | |
| 278 | /* Dump print buffer from char after cursor to end (if used) */ |
| 279 | len = pb->buf + pb->size - pb->crs - 2; |
| 280 | if ((pb->buf[pb->size - 1] == 0) && (len > 0)) |
| 281 | print_to_console(pb->crs + 1, len); |
| 282 | |
| 283 | /* Dump print buffer from start to cursor (always) */ |
| 284 | len = pb->crs - pb->buf; |
| 285 | print_to_console(pb->buf, len); |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * tipc_dump - dump non-console print buffer(s) to console |
| 290 | */ |
| 291 | |
| 292 | void tipc_dump(struct print_buf *pb, const char *fmt, ...) |
| 293 | { |
| 294 | int len; |
| 295 | |
| 296 | spin_lock_bh(&print_lock); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 297 | FORMAT(TIPC_CONS->buf, len, fmt); |
| 298 | printk(TIPC_CONS->buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 299 | |
| 300 | for (; pb; pb = pb->next) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 301 | if (pb == TIPC_CONS) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 302 | continue; |
| 303 | printk("\n---- Start of dump,%s log ----\n\n", |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 304 | (pb == TIPC_LOG) ? "global" : "local"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 305 | printbuf_dump(pb); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 306 | tipc_printbuf_reset(pb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 307 | printk("\n-------- End of dump --------\n"); |
| 308 | } |
| 309 | spin_unlock_bh(&print_lock); |
| 310 | } |
| 311 | |
| 312 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 313 | * tipc_log_stop - free up TIPC log print buffer |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 314 | */ |
| 315 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 316 | void tipc_log_stop(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 317 | { |
| 318 | spin_lock_bh(&print_lock); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 319 | if (TIPC_LOG->buf) { |
| 320 | kfree(TIPC_LOG->buf); |
| 321 | TIPC_LOG->buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 322 | } |
| 323 | spin_unlock_bh(&print_lock); |
| 324 | } |
| 325 | |
| 326 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 327 | * tipc_log_reinit - set TIPC log print buffer to specified size |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 328 | */ |
| 329 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 330 | void tipc_log_reinit(int log_size) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 331 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 332 | tipc_log_stop(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 333 | |
| 334 | if (log_size) { |
| 335 | if (log_size <= MAX_STRING) |
| 336 | log_size = MAX_STRING + 1; |
| 337 | spin_lock_bh(&print_lock); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 338 | tipc_printbuf_init(TIPC_LOG, kmalloc(log_size, GFP_ATOMIC), log_size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 339 | spin_unlock_bh(&print_lock); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 344 | * tipc_log_resize - reconfigure size of TIPC log buffer |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 345 | */ |
| 346 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 347 | struct sk_buff *tipc_log_resize(const void *req_tlv_area, int req_tlv_space) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 348 | { |
| 349 | u32 value; |
| 350 | |
| 351 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 352 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 353 | |
| 354 | value = *(u32 *)TLV_DATA(req_tlv_area); |
| 355 | value = ntohl(value); |
| 356 | if (value != delimit(value, 0, 32768)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 357 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 358 | " (log size must be 0-32768)"); |
| 359 | tipc_log_reinit(value); |
| 360 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 364 | * tipc_log_dump - capture TIPC log buffer contents in configuration message |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 365 | */ |
| 366 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 367 | struct sk_buff *tipc_log_dump(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 368 | { |
| 369 | struct sk_buff *reply; |
| 370 | |
| 371 | spin_lock_bh(&print_lock); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 372 | if (!TIPC_LOG->buf) |
| 373 | reply = tipc_cfg_reply_ultra_string("log not activated\n"); |
| 374 | else if (tipc_printbuf_empty(TIPC_LOG)) |
| 375 | reply = tipc_cfg_reply_ultra_string("log is empty\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 376 | else { |
| 377 | struct tlv_desc *rep_tlv; |
| 378 | struct print_buf pb; |
| 379 | int str_len; |
| 380 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 381 | str_len = min(TIPC_LOG->size, 32768u); |
| 382 | reply = tipc_cfg_reply_alloc(TLV_SPACE(str_len)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 383 | if (reply) { |
| 384 | rep_tlv = (struct tlv_desc *)reply->data; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 385 | tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), str_len); |
| 386 | tipc_printbuf_move(&pb, TIPC_LOG); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 387 | str_len = strlen(TLV_DATA(rep_tlv)) + 1; |
| 388 | skb_put(reply, TLV_SPACE(str_len)); |
| 389 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 390 | } |
| 391 | } |
| 392 | spin_unlock_bh(&print_lock); |
| 393 | return reply; |
| 394 | } |
| 395 | |