aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/mon/mon_text.c
diff options
context:
space:
mode:
authorPete Zaitcev <zaitcev@redhat.com>2006-12-31 01:43:10 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2007-02-07 18:44:34 -0500
commit6f23ee1fefdc1f80bd8a3ab04a1c41ab2dec14c9 (patch)
tree36a5241c29333580de3e3c75e2c62edc1cdf583c /drivers/usb/mon/mon_text.c
parenta8ef36bc0a5fe973bddaa54a5a07cda29e04a602 (diff)
USB: add binary API to usbmon
This patch adds a new, "binary" API in addition to the old, text API usbmon had before. The new API allows for less CPU use, and it allows to capture all data from a packet where old API only captured 32 bytes at most. There are some limitations and conditions to this, e.g. in case someone constructs a URB with 1GB of data, it's not likely to be captured, because even the huge buffers of the new reader are finite. Nonetheless, I expect this new capability to capture all data for all real life scenarios. The downside is, a special user mode application is required where cat(1) worked before. I have sample code at http://people.redhat.com/zaitcev/linux/ and Paolo Abeni is working on patching libpcap. This patch was initially written by Paolo and later I tweaked it, and we had a little back-and-forth. So this is a jointly authored patch, but I am submitting this I am responsible for the bugs. Signed-off-by: Paolo Abeni <paolo.abeni@email.it> Signed-off-by: Pete Zaitcev <zaitcev@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/mon/mon_text.c')
-rw-r--r--drivers/usb/mon/mon_text.c67
1 files changed, 66 insertions, 1 deletions
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 05cf2c9a8f84..d38a1279d9d9 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -9,6 +9,7 @@
9#include <linux/usb.h> 9#include <linux/usb.h>
10#include <linux/time.h> 10#include <linux/time.h>
11#include <linux/mutex.h> 11#include <linux/mutex.h>
12#include <linux/debugfs.h>
12#include <asm/uaccess.h> 13#include <asm/uaccess.h>
13 14
14#include "usb_mon.h" 15#include "usb_mon.h"
@@ -63,6 +64,8 @@ struct mon_reader_text {
63 char slab_name[SLAB_NAME_SZ]; 64 char slab_name[SLAB_NAME_SZ];
64}; 65};
65 66
67static struct dentry *mon_dir; /* Usually /sys/kernel/debug/usbmon */
68
66static void mon_text_ctor(void *, struct kmem_cache *, unsigned long); 69static void mon_text_ctor(void *, struct kmem_cache *, unsigned long);
67 70
68/* 71/*
@@ -436,7 +439,7 @@ static int mon_text_release(struct inode *inode, struct file *file)
436 return 0; 439 return 0;
437} 440}
438 441
439const struct file_operations mon_fops_text = { 442static const struct file_operations mon_fops_text = {
440 .owner = THIS_MODULE, 443 .owner = THIS_MODULE,
441 .open = mon_text_open, 444 .open = mon_text_open,
442 .llseek = no_llseek, 445 .llseek = no_llseek,
@@ -447,6 +450,47 @@ const struct file_operations mon_fops_text = {
447 .release = mon_text_release, 450 .release = mon_text_release,
448}; 451};
449 452
453int mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus)
454{
455 struct dentry *d;
456 enum { NAMESZ = 10 };
457 char name[NAMESZ];
458 int rc;
459
460 rc = snprintf(name, NAMESZ, "%dt", ubus->busnum);
461 if (rc <= 0 || rc >= NAMESZ)
462 goto err_print_t;
463 d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_text);
464 if (d == NULL)
465 goto err_create_t;
466 mbus->dent_t = d;
467
468 /* XXX The stats do not belong to here (text API), but oh well... */
469 rc = snprintf(name, NAMESZ, "%ds", ubus->busnum);
470 if (rc <= 0 || rc >= NAMESZ)
471 goto err_print_s;
472 d = debugfs_create_file(name, 0600, mon_dir, mbus, &mon_fops_stat);
473 if (d == NULL)
474 goto err_create_s;
475 mbus->dent_s = d;
476
477 return 1;
478
479err_create_s:
480err_print_s:
481 debugfs_remove(mbus->dent_t);
482 mbus->dent_t = NULL;
483err_create_t:
484err_print_t:
485 return 0;
486}
487
488void mon_text_del(struct mon_bus *mbus)
489{
490 debugfs_remove(mbus->dent_t);
491 debugfs_remove(mbus->dent_s);
492}
493
450/* 494/*
451 * Slab interface: constructor. 495 * Slab interface: constructor.
452 */ 496 */
@@ -459,3 +503,24 @@ static void mon_text_ctor(void *mem, struct kmem_cache *slab, unsigned long sfla
459 memset(mem, 0xe5, sizeof(struct mon_event_text)); 503 memset(mem, 0xe5, sizeof(struct mon_event_text));
460} 504}
461 505
506int __init mon_text_init(void)
507{
508 struct dentry *mondir;
509
510 mondir = debugfs_create_dir("usbmon", NULL);
511 if (IS_ERR(mondir)) {
512 printk(KERN_NOTICE TAG ": debugfs is not available\n");
513 return -ENODEV;
514 }
515 if (mondir == NULL) {
516 printk(KERN_NOTICE TAG ": unable to create usbmon directory\n");
517 return -ENODEV;
518 }
519 mon_dir = mondir;
520 return 0;
521}
522
523void __exit mon_text_exit(void)
524{
525 debugfs_remove(mon_dir);
526}