netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: dada1@cosmosbay.com
Cc: jimi@sngx.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH updated] net: add ability to clear per-interface network statistics via procfs
Date: Fri, 16 May 2008 13:03:09 -0700 (PDT)	[thread overview]
Message-ID: <20080516.130309.258561311.davem@davemloft.net> (raw)
In-Reply-To: <482DB46A.8020103@cosmosbay.com>

From: Eric Dumazet <dada1@cosmosbay.com>
Date: Fri, 16 May 2008 18:20:58 +0200

netdev CC:'d, people please...  Eric, you in particular know
better :-)))

> James Cammarata a écrit :
> > From: James Cammarata <jimi@sngx.net>
> >
> > Added the ability to write to /proc/net/dev in order to clear the 
> > interface counters for a given interface.  The ability to zero out 
> > counters (especially the error counters) is extremely useful when 
> > troubleshooting interface issues.  Now diffed against 2.6.25.4, and 
> > added some sanity checking.
> >
> Hello James
> 
> 1) Every call to get_proc_net() should be paired with a call to 
> put_net(), or else you  leak  struct net.
> 
> 2) I am not sure this is the right way to do this... Did you consider to 
> extend ethtool instead ?
> 
> > Syntax:
> >  echo 'net clear-stats ifdev' > /proc/net/dev
> > Where "ifdev" is the device name you wish to clear.
> >
> > This code is based mainly on the code found in drivers/scsi/scsi_proc.c
> >
> > Signed-off-by: James Cammarata <jimi@sngx.net>
> > ---
> >
> > --- linux-2.6.25.4/net/core/dev.c       2008-05-15 10:00:12.000000000 
> > -0500
> > +++ linux-2.6.25.4-jcammara/net/core/dev.c      2008-05-16 
> > 07:02:48.000000000 -0500
> > @@ -2455,2 +2455,78 @@
> >
> > +/**
> > + * proc_net_dev_write - handle writes to /proc/net/dev
> > + * @file: not used
> > + * @buf: buffer to write
> > + * @length: length of buf, at most PAGE_SIZE
> > + * @ppos: not used
> > + *
> > + * Description: this provides a mechanism to clear statistics on a
> > + * per-interface basis
> > + * "echo 'net clear-stats ifdev' >/proc/net/dev"
> > + * with  "ifdev" replaced by the device name you wish to clear.
> > + *
> > + */
> > +static ssize_t proc_net_dev_write(struct file *file, const char 
> > __user *buf,
> > +                                  size_t length, loff_t *ppos)
> > +{
> > +        char *buffer, *p;
> > +        char devname[IFNAMSIZ];
> > +        struct net *net;
> > +        struct net_device *dev;
> > +        int err;
> > +
> > +        if (!buf || length > PAGE_SIZE)
> > +                return -EINVAL;
> > +
> > +        buffer = (char *)__get_free_page(GFP_KERNEL);
> > +        if (!buffer)
> > +                return -ENOMEM;
> > +
> > +        err = -EFAULT;
> > +        if (copy_from_user(buffer, buf, length))
> > +                goto out;
> > +
> > +        err = -EINVAL;
> > +        if (length < PAGE_SIZE)
> > +                buffer[length] = '\0';
> > +        else if (buffer[PAGE_SIZE-1])
> > +                goto out;
> > +
> > +        err = -ENXIO;
> > +        net = get_proc_net(file->f_dentry->d_inode);
> > +        if (!net)
> > +                goto out;
> > +
> > +        /*
> > +         * Usage: echo "net clear-stats ifdev" >/proc/net/dev
> > +         * with  "ifdev" replaced by the device name you wish to clear.
> > +         */
> > +        if (!strncmp("net clear-stats",buffer,15)) {
> > +                p = buffer + 16;
> > +                if(sscanf(p,"%16s",devname)>0) {
> > +                        dev = dev_get_by_name(net,devname);
> > +                        if (dev) {
> > +                                if (dev->get_stats) {
> > +                                        struct net_device_stats *stats =
> > +                                               dev->get_stats(dev);
> > +                                        memset(stats,0,
> > +                                               sizeof(struct 
> > net_device_stats));
> > +                                }
> > +                                dev_put(dev);
> > +                        }
> > +                }
> > +        }
> > +
> > +        /*
> > +         * convert success returns so that we return the
> > +         * number of bytes consumed.
> > +         */
> > +        if (!err)
> > +                err = length;
> > +
> Here probably, you should add
> 
>     put_net(net);
> 
> > + out:
> > +        free_page((unsigned long)buffer);
> > +        return err;
> > +}
> > +
> > static void *softnet_seq_start(struct seq_file *seq, loff_t *pos)
> > @@ -2498,2 +2574,3 @@
> >        .read    = seq_read,
> > +        .write   = proc_net_dev_write,
> >        .llseek  = seq_lseek,
> >
> >
> 
> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  parent reply	other threads:[~2008-05-16 20:03 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <482DA5B6.1020606@sngx.net>
2008-05-16 20:00 ` [PATCH updated] net: add ability to clear per-interface network statistics via procfs David Miller
2008-05-16 20:09   ` Rick Jones
2008-05-17 15:06     ` James Cammarata
     [not found] ` <482DB46A.8020103@cosmosbay.com>
2008-05-16 20:03   ` David Miller [this message]
     [not found]   ` <482EF192.4070707@sngx.net>
2008-05-17 21:41     ` Eric Dumazet
2008-05-17 22:49       ` James Cammarata
2008-05-18  0:31         ` Ben Hutchings
2008-05-18  1:43           ` Patrick McHardy
2008-05-18  5:09           ` James Cammarata
2008-05-18 11:27             ` Ben Hutchings
2008-05-29  1:45             ` [PATCH] net: add ability to clear stats via ethtool - e1000/pcnet32 James Cammarata
2008-05-29  2:08               ` James Cammarata
2008-05-29  5:11               ` Andrew Morton
2008-05-29 12:34                 ` James Cammarata
2008-05-29 14:45                   ` Alan Cox
2008-05-29 17:15                     ` James Cammarata
2008-05-29 20:50                       ` David Miller
2008-05-29 21:18                         ` James Cammarata
2008-05-30 19:12                     ` Bill Fink
2008-05-30 22:14                       ` Rick Jones
2008-05-31  1:09                         ` Bill Fink
2008-05-31  2:41                           ` Stephen Hemminger
2008-05-31  4:47                             ` Bill Fink
2008-05-31 12:11                       ` Alan Cox
2008-05-31 23:57                         ` Bill Fink
2008-06-01  1:46                           ` Ben Hutchings
2008-06-01 20:46                             ` Bill Fink
2008-06-01 22:29                               ` Ben Hutchings
2008-06-02  3:55                                 ` Bill Fink
2008-06-02  5:39                               ` David Miller
2008-06-02 15:41                                 ` Bill Fink
2008-06-02  4:50                           ` Glen Turner
2008-06-02 16:10                             ` Bill Fink
2008-06-03 12:28                               ` James Cammarata
2008-06-03 12:35                                 ` Ben Hutchings
2008-06-03 14:46                                 ` Alan Cox
2008-06-04  3:05                                   ` James Cammarata
2008-05-29 14:48                   ` Chris Friesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080516.130309.258561311.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=dada1@cosmosbay.com \
    --cc=jimi@sngx.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).