Changeset 241
- Timestamp:
- 10/01/13 03:38:02 (11 years ago)
- Location:
- ksyslog/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ksyslog/trunk/ksyslog.c
r240 r241 26 26 static struct proc_dir_entry *ksyslog_proc_queue = NULL; 27 27 static struct proc_dir_entry *ksyslog_proc_nr_queued = NULL; 28 static struct proc_dir_entry *ksyslog_proc_nr_written = NULL; 29 static struct proc_dir_entry *ksyslog_proc_nr_dropped = NULL; 28 30 #endif 29 31 … … 31 33 static ushort ksyslog_port = 514; 32 34 static char *ksyslog_path = "/var/log/ksyslog.log"; 33 static u int ksyslog_queue_max= 2048;35 static ulong ksyslog_queue_length = 2048; 34 36 static ulong ksyslog_flush_interval = 45; /* milliseconds */ 35 37 … … 37 39 module_param(ksyslog_port, ushort, 0444); 38 40 module_param(ksyslog_path, charp, 0644); 39 module_param(ksyslog_queue_ max, uint, 0644);41 module_param(ksyslog_queue_length, ulong, 0644); 40 42 module_param(ksyslog_flush_interval, ulong, 0644); 43 44 static void 45 ksyslog_queue_init(struct ksyslog_queue *queue) 46 { 47 memset(queue, 0, sizeof(*queue)); 48 INIT_LIST_HEAD(&queue->head); 49 atomic64_set(&queue->nr_queued, 0); 50 atomic64_set(&queue->nr_written, 0); 51 atomic64_set(&queue->nr_dropped, 0); 52 } 41 53 42 54 static int … … 214 226 ksyslog_entry_add(struct ksyslog_queue *queue, struct ksyslog_entry *entry) 215 227 { 216 if (unlikely( queue->length >= ksyslog_queue_max))228 if (unlikely(atomic64_read(&queue->nr_queued) >= ksyslog_queue_length)) 217 229 return -ENOBUFS; 218 230 list_add_tail_rcu(&entry->list, &queue->head); 219 WARN_ON( ++queue->length > ksyslog_queue_max);231 WARN_ON(atomic64_inc_return(&queue->nr_queued) > ksyslog_queue_length); 220 232 return 0; 221 233 } … … 224 236 ksyslog_entry_del(struct ksyslog_queue *queue, struct ksyslog_entry *entry, bool free) 225 237 { 226 WARN_ON( --queue->length< 0);238 WARN_ON(atomic64_dec_return(&queue->nr_queued) < 0); 227 239 list_del_rcu(&entry->list); 228 240 if (free) … … 247 259 ksyslog_entry_del(from, entry, false); 248 260 if (unlikely(ksyslog_entry_add(to, entry))) { 261 atomic64_inc(&from->nr_dropped); 262 atomic64_inc(&to->nr_dropped); 249 263 ksyslog_drop_warning(entry); 250 264 call_rcu(&entry->rcu, ksyslog_entry_free); … … 272 286 struct ksyslog_queue write_queue; 273 287 274 memset(&write_queue, 0, sizeof(write_queue)); 275 INIT_LIST_HEAD(&write_queue.head); 288 ksyslog_queue_init(&write_queue); 276 289 277 290 spin_lock_bh(&ksyslog_queue_lock); … … 279 292 spin_unlock_bh(&ksyslog_queue_lock); 280 293 281 if ( write_queue.length<= 0)294 if (atomic64_read(&write_queue.nr_queued) <= 0) 282 295 goto out; 283 296 … … 310 323 } 311 324 325 atomic64_inc(&ksyslog_queue.nr_written); 312 326 kfree(buf); 313 327 call_rcu(&entry->rcu, ksyslog_entry_free); … … 317 331 spin_lock_bh(&ksyslog_queue_lock); 318 332 if (unlikely(ksyslog_entry_add(&ksyslog_queue, entry))) { 333 atomic64_inc(&ksyslog_queue.nr_dropped); 319 334 ksyslog_drop_warning(entry); 320 335 call_rcu(&entry->rcu, ksyslog_entry_free); … … 338 353 struct ksyslog_entry *entry; 339 354 340 err = skb_linearize(skb); 341 if (unlikely(err)) 342 goto out; 355 if (unlikely(skb_linearize(skb))) 356 goto err; 343 357 344 358 iph = ip_hdr(skb); 345 359 udph = udp_hdr(skb); 346 360 347 if (unlikely(!skb_pull(skb, sizeof(*udph)))) { 348 err = -EINVAL; 349 goto out; 350 } 361 if (unlikely(!skb_pull(skb, sizeof(*udph)))) 362 goto err; 351 363 352 364 entry = ksyslog_entry_create(skb, iph, udph); 353 if (unlikely(IS_ERR(entry))) { 354 err = PTR_ERR(entry); 355 goto out; 356 } 365 if (unlikely(IS_ERR(entry))) 366 goto err; 357 367 358 368 spin_lock_bh(&ksyslog_queue_lock); … … 360 370 spin_unlock_bh(&ksyslog_queue_lock); 361 371 362 if (unlikely(err)) 372 if (unlikely(err)) { 373 ksyslog_drop_warning(entry); 363 374 ksyslog_entry_free(&entry->rcu); 375 goto err; 376 } 364 377 365 378 out: 366 if (unlikely(err))367 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, IS_UDPLITE(sk));368 369 379 consume_skb(skb); 370 380 return 0; 381 382 err: 383 atomic64_inc(&ksyslog_queue.nr_dropped); 384 goto out; 371 385 } 372 386 … … 446 460 ksyslog_nr_queued_seq_show(struct seq_file *seq, void *v) 447 461 { 448 seq_printf(seq, "% u\n", ksyslog_queue.length);462 seq_printf(seq, "%lu\n", atomic64_read(&ksyslog_queue.nr_queued)); 449 463 return 0; 450 464 } … … 454 468 { 455 469 return single_open(file, ksyslog_nr_queued_seq_show, PDE(inode)->data); 470 } 471 472 static int 473 ksyslog_nr_written_seq_show(struct seq_file *seq, void *v) 474 { 475 seq_printf(seq, "%lu\n", atomic64_read(&ksyslog_queue.nr_written)); 476 return 0; 477 } 478 479 static int 480 ksyslog_nr_written_seq_open(struct inode *inode, struct file *file) 481 { 482 return single_open(file, ksyslog_nr_written_seq_show, PDE(inode)->data); 483 } 484 485 static int 486 ksyslog_nr_dropped_seq_show(struct seq_file *seq, void *v) 487 { 488 seq_printf(seq, "%lu\n", atomic64_read(&ksyslog_queue.nr_dropped)); 489 return 0; 490 } 491 492 static int 493 ksyslog_nr_dropped_seq_open(struct inode *inode, struct file *file) 494 { 495 return single_open(file, ksyslog_nr_dropped_seq_show, PDE(inode)->data); 456 496 } 457 497 … … 464 504 }; 465 505 506 static struct file_operations ksyslog_nr_written_fops = { 507 .owner = THIS_MODULE, 508 .open = ksyslog_nr_written_seq_open, 509 .read = seq_read, 510 .llseek = seq_lseek, 511 .release = single_release, 512 }; 513 514 static struct file_operations ksyslog_nr_dropped_fops = { 515 .owner = THIS_MODULE, 516 .open = ksyslog_nr_dropped_seq_open, 517 .read = seq_read, 518 .llseek = seq_lseek, 519 .release = single_release, 520 }; 521 522 static void 523 ksyslog_proc_destroy(void) 524 { 525 if (ksyslog_proc_queue) 526 remove_proc_entry(ksyslog_proc_queue->name, ksyslog_proc_queue->parent); 527 ksyslog_proc_queue = NULL; 528 529 if (ksyslog_proc_nr_queued) 530 remove_proc_entry(ksyslog_proc_nr_queued->name, ksyslog_proc_nr_queued->parent); 531 ksyslog_proc_nr_queued = NULL; 532 533 if (ksyslog_proc_nr_written) 534 remove_proc_entry(ksyslog_proc_nr_written->name, ksyslog_proc_nr_written->parent); 535 ksyslog_proc_nr_written = NULL; 536 537 if (ksyslog_proc_nr_dropped) 538 remove_proc_entry(ksyslog_proc_nr_dropped->name, ksyslog_proc_nr_dropped->parent); 539 ksyslog_proc_nr_dropped = NULL; 540 541 if (ksyslog_procdir) 542 remove_proc_entry(ksyslog_procdir->name, ksyslog_procdir->parent); 543 ksyslog_procdir = NULL; 544 } 545 466 546 static int 467 547 ksyslog_proc_init(void) … … 470 550 if (ksyslog_procdir == NULL) { 471 551 pr_err("proc_mkdir failed\n"); 472 return -ENOMEM;552 goto err; 473 553 } 474 554 … … 476 556 &ksyslog_queue_fops, &ksyslog_queue.head); 477 557 if (ksyslog_proc_queue == NULL) { 478 remove_proc_entry(ksyslog_procdir->name, ksyslog_procdir->parent); 479 pr_err("proc_create_data failed\n"); 480 return -ENOMEM; 558 pr_err("proc_create(queue) failed\n"); 559 goto err; 481 560 } 482 561 483 562 ksyslog_proc_nr_queued = proc_create("nr_queued", S_IRUGO, ksyslog_procdir, 484 &ksyslog_nr_queued_fops);563 &ksyslog_nr_queued_fops); 485 564 if (ksyslog_proc_nr_queued == NULL) { 486 remove_proc_entry(ksyslog_proc_queue->name, ksyslog_proc_queue->parent);487 remove_proc_entry(ksyslog_procdir->name, ksyslog_procdir->parent);488 pr_err("proc_create failed\n");489 return -ENOMEM; 490 }491 492 return 0;493 } 494 495 static void 496 ksyslog_proc_destroy(void) 497 { 498 if (ksyslog_proc_nr_queued)499 remove_proc_entry(ksyslog_proc_nr_queued->name, ksyslog_proc_nr_queued->parent);500 ksyslog_proc_nr_queued = NULL;501 502 if (ksyslog_proc_queue)503 remove_proc_entry(ksyslog_proc_queue->name, ksyslog_proc_queue->parent); 504 ksyslog_proc_queue = NULL;505 506 if (ksyslog_procdir) 507 remove_proc_entry(ksyslog_procdir->name, ksyslog_procdir->parent);508 ksyslog_procdir = NULL;565 pr_err("proc_create(nr_queued) failed\n"); 566 goto err; 567 } 568 569 ksyslog_proc_nr_written = proc_create("nr_written", S_IRUGO, ksyslog_procdir, 570 &ksyslog_nr_written_fops); 571 if (ksyslog_proc_nr_written == NULL) { 572 pr_err("proc_create(nr_written) failed\n"); 573 goto err; 574 } 575 576 ksyslog_proc_nr_dropped = proc_create("nr_dropped", S_IRUGO, ksyslog_procdir, 577 &ksyslog_nr_dropped_fops); 578 if (ksyslog_proc_nr_dropped == NULL) { 579 pr_err("proc_create(nr_dropped) failed\n"); 580 goto err; 581 } 582 583 return 0; 584 585 err: 586 ksyslog_proc_destroy(); 587 return -ENOMEM; 509 588 } 510 589 #endif … … 537 616 struct sockaddr_in sin; 538 617 539 INIT_LIST_HEAD(&ksyslog_queue.head);618 ksyslog_queue_init(&ksyslog_queue); 540 619 541 620 #ifdef CONFIG_PROC_FS -
ksyslog/trunk/ksyslog.h
r236 r241 74 74 struct ksyslog_queue { 75 75 struct list_head head; 76 unsigned int length; 76 atomic64_t nr_queued; 77 atomic64_t nr_written; 78 atomic64_t nr_dropped; 77 79 }; 78 80
Note: See TracChangeset
for help on using the changeset viewer.