X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Futils%2Frouterstat.c;h=2071ac9b8eeb4345d4652af2e6ddf8f908c5051d;hb=def25e9c7eff57cdaf8a6ee5e8e7db005bab6525;hp=2baa75992950a3f5e4dff8e1c177177d96b7403d;hpb=08aa217ce49aba1ded52e0f7adb8a607035123fd;p=fs%2Flustre-release.git diff --git a/lnet/utils/routerstat.c b/lnet/utils/routerstat.c index 2baa759..2071ac9 100644 --- a/lnet/utils/routerstat.c +++ b/lnet/utils/routerstat.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -34,14 +30,18 @@ * Lustre is a trademark of Sun Microsystems, Inc. */ -#include #include -#include #include -#include +#include +#include +#include #include +#include #include #include +#include + +#include double timenow () @@ -106,7 +106,7 @@ do_stat (int fd) lseek (fd, 0, SEEK_SET); now = timenow(); - n = read (fd, buffer, sizeof (buffer)); + n = read(fd, buffer, sizeof(buffer) - 1); if (n < 0) { fprintf (stderr, "Can't read statfile\n"); @@ -168,28 +168,36 @@ do_stat (int fd) last = timenow(); } -int main (int argc, char **argv) +int main(int argc, char **argv) { - int interval = 0; - int fd; - - if (argc > 1) - interval = atoi (argv[1]); - - fd = open ("/proc/sys/lnet/stats", O_RDONLY); - if (fd < 0) - { - fprintf (stderr, "Can't open stat: %s\n", strerror (errno)); - return (1); - } - - do_stat (fd); - if (interval == 0) - return (0); - - for (;;) - { - sleep (interval); - do_stat (fd); - } + int interval = 0; + glob_t path; + int fd; + + if (argc > 1) + interval = atoi(argv[1]); + + if (cfs_get_param_paths(&path, "stats") != 0) { + fprintf(stderr, "LNet stats not available\n"); + return 1; + } + + fd = open(path.gl_pathv[0], O_RDONLY); + if (fd < 0) { + fprintf(stderr, "failed to open '%s': %s\n", path.gl_pathv[0], + strerror(errno)); + cfs_free_param_data(&path); + return 1; + } + cfs_free_param_data(&path); + + do_stat(fd); + if (interval == 0) + return 0; + + while (1) { + sleep(interval); + do_stat(fd); + } + /* Never reached */ }