Whamcloud - gitweb
i=liang,b=13065:
[fs/lustre-release.git] / lnet / lnet / router_proc.c
index 5be36b1..6247c53 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002 Cluster File Systems, Inc.
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
  *
  *   This file is part of Portals
  *   http://sourceforge.net/projects/sandiaportals/
 
 #if defined(__KERNEL__) && defined(LNET_ROUTER)
 
+#if defined(__linux__)
 #include <linux/seq_file.h>
-#include <linux/lustre_compat25.h>
+#endif
 
 /* this is really lnet_proc.c */
 
-#define LNET_PROC_STATS   "sys/lnet/stats"
-#define LNET_PROC_ROUTES  "sys/lnet/routes"
-#define LNET_PROC_ROUTERS "sys/lnet/routers"
-#define LNET_PROC_PEERS   "sys/lnet/peers"
-#define LNET_PROC_BUFFERS "sys/lnet/buffers"
-#define LNET_PROC_NIS     "sys/lnet/nis"
+#define LNET_PROC_ROOT    "sys/lnet"
+#define LNET_PROC_STATS   LNET_PROC_ROOT"/stats"
+#define LNET_PROC_ROUTES  LNET_PROC_ROOT"/routes"
+#define LNET_PROC_ROUTERS LNET_PROC_ROOT"/routers"
+#define LNET_PROC_PEERS   LNET_PROC_ROOT"/peers"
+#define LNET_PROC_BUFFERS LNET_PROC_ROOT"/buffers"
+#define LNET_PROC_NIS     LNET_PROC_ROOT"/nis"
 
 static int
 lnet_router_proc_stats_read (char *page, char **start, off_t off,
@@ -249,10 +251,10 @@ lnet_route_seq_show (struct seq_file *s, void *iter)
 }
 
 static struct seq_operations lnet_routes_sops = {
-        .start = lnet_route_seq_start,
-        .stop  = lnet_route_seq_stop,
-        .next  = lnet_route_seq_next,
-        .show  = lnet_route_seq_show,
+        /* start */ lnet_route_seq_start,
+        /* stop */  lnet_route_seq_stop,
+        /* next */  lnet_route_seq_next,
+        /* show */  lnet_route_seq_show,
 };
 
 static int
@@ -271,17 +273,21 @@ lnet_route_seq_open(struct inode *inode, struct file *file)
         return rc;
 }
 
-static struct file_operations lnet_routes_fops = {
-        .owner   = THIS_MODULE,
-        .open    = lnet_route_seq_open,
-        .read    = seq_read,
-        .llseek  = seq_lseek,
-        .release = seq_release,
-};
+static struct file_operations lnet_routes_fops;
+
+static void
+lnet_init_routes_fops(void)
+{
+        lnet_routes_fops.owner   =  THIS_MODULE;
+        lnet_routes_fops.llseek  =  seq_lseek;
+        lnet_routes_fops.read    =  seq_read;
+        lnet_routes_fops.open    =  lnet_route_seq_open;
+        lnet_routes_fops.release =  seq_release;
+}
 
 typedef struct {
         __u64                lrtrsi_version;
-        lnet_peer_t          *lrtrsi_router;
+        lnet_peer_t         *lrtrsi_router;
         loff_t               lrtrsi_off;
 } lnet_router_seq_iterator_t;
 
@@ -321,7 +327,7 @@ lnet_router_seq_seek (lnet_router_seq_iterator_t *lrtrsi, loff_t off)
         }
 
         lrtrsi->lrtrsi_version = the_lnet.ln_routers_version;
-        lrtrsi->lrtrsi_off        = off;
+        lrtrsi->lrtrsi_off     = off;
 
         while (r != &the_lnet.ln_routers) {
                 lnet_peer_t *rtr = list_entry(r, 
@@ -339,7 +345,7 @@ lnet_router_seq_seek (lnet_router_seq_iterator_t *lrtrsi, loff_t off)
         }
 
         lrtrsi->lrtrsi_router = NULL;
-        rc             = -ENOENT;
+        rc = -ENOENT;
  out:
         LNET_UNLOCK();
         return rc;
@@ -395,10 +401,12 @@ lnet_router_seq_show (struct seq_file *s, void *iter)
 {
         lnet_router_seq_iterator_t *lrtrsi = iter;
         lnet_peer_t *lp;
-        lnet_nid_t  nid;
-        int         alive;
-        int         nrefs;
-        int         nrtrrefs;
+        lnet_nid_t   nid;
+        int          alive;
+        int          alive_cnt;
+        int          nrefs;
+        int          nrtrrefs;
+        time_t       last_ping;
 
         if (lrtrsi->lrtrsi_off == 0) {
                 seq_printf(s, "%-4s %7s %9s %6s %12s %s\n",
@@ -416,28 +424,27 @@ lnet_router_seq_show (struct seq_file *s, void *iter)
                 return -ESTALE;
         }
 
-        nrefs = lp->lp_refcount;
-        nrtrrefs = lp->lp_rtr_refcount;
-        nid   = lp->lp_nid;
-        alive = lp->lp_alive;
+        nid       = lp->lp_nid;
+        alive     = lp->lp_alive;
+        alive_cnt = lp->lp_alive_count;
+        nrefs     = lp->lp_refcount;
+        nrtrrefs  = lp->lp_rtr_refcount;
+        last_ping = lp->lp_ping_timestamp;
 
         LNET_UNLOCK();
 
-        seq_printf(s, 
-                   "%-4d %7d %9d %6s %12lu %s\n", 
-                   nrefs, nrtrrefs,
-                   lp->lp_alive_count,
-                   alive ? "up" : "down", 
-                   lp->lp_ping_timestamp,
-                   libcfs_nid2str(nid));
+        seq_printf(s,
+                   "%-4d %7d %9d %6s %12lu %s\n", nrefs, nrtrrefs,
+                   alive_cnt, alive ? "up" : "down",
+                   last_ping, libcfs_nid2str(nid));
         return 0;
 }
 
 static struct seq_operations lnet_routers_sops = {
-        .start = lnet_router_seq_start,
-        .stop  = lnet_router_seq_stop,
-        .next  = lnet_router_seq_next,
-        .show  = lnet_router_seq_show,
+        /* start */ lnet_router_seq_start,
+        /* stop */  lnet_router_seq_stop,
+        /* next */  lnet_router_seq_next,
+        /* show */  lnet_router_seq_show,
 };
 
 static int
@@ -456,13 +463,17 @@ lnet_router_seq_open(struct inode *inode, struct file *file)
         return rc;
 }
 
-static struct file_operations lnet_routers_fops = {
-        .owner   = THIS_MODULE,
-        .open    = lnet_router_seq_open,
-        .read    = seq_read,
-        .llseek  = seq_lseek,
-        .release = seq_release,
-};
+static struct file_operations lnet_routers_fops;
+
+static void
+lnet_init_routers_fops(void)
+{
+        lnet_routers_fops.owner   =  THIS_MODULE;
+        lnet_routers_fops.llseek  =  seq_lseek;
+        lnet_routers_fops.read    =  seq_read;
+        lnet_routers_fops.open    =  lnet_router_seq_open;
+        lnet_routers_fops.release =  seq_release;
+}
 
 typedef struct {
         unsigned long long   lpsi_version;
@@ -592,6 +603,7 @@ static int
 lnet_peer_seq_show (struct seq_file *s, void *iter)
 {
         lnet_peer_seq_iterator_t *lpsi = iter;
+        char                     *aliveness = "NA";
         lnet_peer_t              *lp;
         lnet_nid_t                nid;
         int                       maxcr;
@@ -599,7 +611,6 @@ lnet_peer_seq_show (struct seq_file *s, void *iter)
         int                       txcr;
         int                       minrtrcr;
         int                       rtrcr;
-        int                       alive;
         int                       txqnob;
         int                       nrefs;
 
@@ -627,23 +638,25 @@ lnet_peer_seq_show (struct seq_file *s, void *iter)
         mintxcr  = lp->lp_mintxcredits;
         rtrcr    = lp->lp_rtrcredits;
         minrtrcr = lp->lp_minrtrcredits;
-        alive    = lp->lp_alive;
         txqnob   = lp->lp_txqnob;
         nrefs    = lp->lp_refcount;
 
+        if (lnet_isrouter(lp) || lp->lp_ni->ni_peertimeout > 0)
+                aliveness = lp->lp_alive ? "up" : "down";
+
         LNET_UNLOCK();
 
         seq_printf(s, "%-24s %4d %5s %5d %5d %5d %5d %5d %d\n",
-                   libcfs_nid2str(nid), nrefs, alive ? "up" : "down",
+                   libcfs_nid2str(nid), nrefs, aliveness,
                    maxcr, rtrcr, minrtrcr, txcr, mintxcr, txqnob);
         return 0;
 }
 
 static struct seq_operations lnet_peer_sops = {
-        .start = lnet_peer_seq_start,
-        .stop  = lnet_peer_seq_stop,
-        .next  = lnet_peer_seq_next,
-        .show  = lnet_peer_seq_show,
+        /* start */ lnet_peer_seq_start,
+        /* stop */  lnet_peer_seq_stop,
+        /* next */  lnet_peer_seq_next,
+        /* show */  lnet_peer_seq_show,
 };
 
 static int
@@ -662,13 +675,17 @@ lnet_peer_seq_open(struct inode *inode, struct file *file)
         return rc;
 }
 
-static struct file_operations lnet_peer_fops = {
-        .owner   = THIS_MODULE,
-        .open    = lnet_peer_seq_open,
-        .read    = seq_read,
-        .llseek  = seq_lseek,
-        .release = seq_release,
-};
+static struct file_operations lnet_peer_fops;
+
+static void
+lnet_init_peer_fops(void)
+{
+        lnet_peer_fops.owner   =  THIS_MODULE;
+        lnet_peer_fops.llseek  =  seq_lseek;
+        lnet_peer_fops.read    =  seq_read;
+        lnet_peer_fops.open    =  lnet_peer_seq_open;
+        lnet_peer_fops.release =  seq_release;
+}
 
 typedef struct {
         int                  lbsi_idx;
@@ -800,10 +817,10 @@ lnet_buffer_seq_show (struct seq_file *s, void *iter)
 }
 
 static struct seq_operations lnet_buffer_sops = {
-        .start = lnet_buffer_seq_start,
-        .stop  = lnet_buffer_seq_stop,
-        .next  = lnet_buffer_seq_next,
-        .show  = lnet_buffer_seq_show,
+        /* start */ lnet_buffer_seq_start,
+        /* stop */  lnet_buffer_seq_stop,
+        /* next */  lnet_buffer_seq_next,
+        /* show */  lnet_buffer_seq_show,
 };
 
 static int
@@ -822,13 +839,17 @@ lnet_buffer_seq_open(struct inode *inode, struct file *file)
         return rc;
 }
 
-static struct file_operations lnet_buffers_fops = {
-        .owner   = THIS_MODULE,
-        .open    = lnet_buffer_seq_open,
-        .read    = seq_read,
-        .llseek  = seq_lseek,
-        .release = seq_release,
-};
+static struct file_operations lnet_buffers_fops;
+
+static void
+lnet_init_buffers_fops(void)
+{
+        lnet_buffers_fops.owner   =  THIS_MODULE;
+        lnet_buffers_fops.llseek  =  seq_lseek;
+        lnet_buffers_fops.read    =  seq_read;
+        lnet_buffers_fops.open    =  lnet_buffer_seq_open;
+        lnet_buffers_fops.release =  seq_release;
+}
 
 typedef struct {
         lnet_ni_t           *lnsi_ni;
@@ -937,12 +958,13 @@ lnet_ni_seq_show (struct seq_file *s, void *iter)
         int                     txcr;
         int                     mintxcr;
         int                     npeertxcr;
+        int                     npeerrtrcr;
         lnet_nid_t              nid;
         int                     nref;
 
         if (lnsi->lnsi_off == 0) {
-                seq_printf(s, "%-24s %4s %4s %5s %5s %5s\n",
-                           "nid", "refs", "peer", "max", "tx", "min");
+                seq_printf(s, "%-24s %4s %4s %4s %5s %5s %5s\n",
+                           "nid", "refs", "peer", "rtr", "max", "tx", "min");
                 return 0;
         }
 
@@ -952,26 +974,27 @@ lnet_ni_seq_show (struct seq_file *s, void *iter)
 
         ni = lnsi->lnsi_ni;
 
-        maxtxcr   = ni->ni_maxtxcredits;
-        txcr      = ni->ni_txcredits;
-        mintxcr   = ni->ni_mintxcredits;
-        npeertxcr = ni->ni_peertxcredits;
-        nid       = ni->ni_nid;
-        nref      = ni->ni_refcount;
+        maxtxcr    = ni->ni_maxtxcredits;
+        txcr       = ni->ni_txcredits;
+        mintxcr    = ni->ni_mintxcredits;
+        npeertxcr  = ni->ni_peertxcredits;
+        npeerrtrcr = ni->ni_peerrtrcredits;
+        nid        = ni->ni_nid;
+        nref       = ni->ni_refcount;
 
         LNET_UNLOCK();
 
-        seq_printf(s, "%-24s %4d %4d %5d %5d %5d\n",
+        seq_printf(s, "%-24s %4d %4d %4d %5d %5d %5d\n",
                    libcfs_nid2str(nid), nref,
-                   npeertxcr, maxtxcr, txcr, mintxcr);
+                   npeertxcr, npeerrtrcr, maxtxcr, txcr, mintxcr);
         return 0;
 }
 
 static struct seq_operations lnet_ni_sops = {
-        .start = lnet_ni_seq_start,
-        .stop  = lnet_ni_seq_stop,
-        .next  = lnet_ni_seq_next,
-        .show  = lnet_ni_seq_show,
+        /* start */ lnet_ni_seq_start,
+        /* stop */  lnet_ni_seq_stop,
+        /* next */  lnet_ni_seq_next,
+        /* show */  lnet_ni_seq_show,
 };
 
 static int
@@ -990,82 +1013,95 @@ lnet_ni_seq_open(struct inode *inode, struct file *file)
         return rc;
 }
 
-static struct file_operations lnet_ni_fops = {
-        .owner   = THIS_MODULE,
-        .open    = lnet_ni_seq_open,
-        .read    = seq_read,
-        .llseek  = seq_lseek,
-        .release = seq_release,
-};
+static struct file_operations lnet_ni_fops;
+
+static void
+lnet_init_ni_fops(void)
+{
+        lnet_ni_fops.owner   =  THIS_MODULE;
+        lnet_ni_fops.llseek  =  seq_lseek;
+        lnet_ni_fops.read    =  seq_read;
+        lnet_ni_fops.open    =  lnet_ni_seq_open;
+        lnet_ni_fops.release =  seq_release;
+}
 
 void
 lnet_proc_init(void)
 {
-        struct proc_dir_entry *stats;
-        struct proc_dir_entry *routes;
-        struct proc_dir_entry *routers;
-        struct proc_dir_entry *peers;
+        struct proc_dir_entry *pde;
 
+#if 0
+        pde = proc_mkdir(LNET_PROC_ROOT, NULL);
+        if (pde == NULL) {
+                CERROR("couldn't create "LNET_PROC_ROOT"\n");
+                return; 
+        }
+#endif
         /* Initialize LNET_PROC_STATS */
-        stats = create_proc_entry (LNET_PROC_STATS, 0644, NULL);
-        if (stats == NULL) {
+        pde = create_proc_entry (LNET_PROC_STATS, 0644, NULL);
+        if (pde == NULL) {
                 CERROR("couldn't create proc entry %s\n", LNET_PROC_STATS);
                 return;
         }
 
-        stats->data = NULL;
-        stats->read_proc = lnet_router_proc_stats_read;
-        stats->write_proc = lnet_router_proc_stats_write;
+        pde->data = NULL;
+        pde->read_proc = lnet_router_proc_stats_read;
+        pde->write_proc = lnet_router_proc_stats_write;
 
         /* Initialize LNET_PROC_ROUTES */
-        routes = create_proc_entry (LNET_PROC_ROUTES, 0444, NULL);
-        if (routes == NULL) {
+        pde = create_proc_entry (LNET_PROC_ROUTES, 0444, NULL);
+        if (pde == NULL) {
                 CERROR("couldn't create proc entry %s\n", LNET_PROC_ROUTES);
                 return;
         }
 
-        routes->proc_fops = &lnet_routes_fops;
-        routes->data = NULL;
+        lnet_init_routes_fops();
+        pde->proc_fops = &lnet_routes_fops;
+        pde->data = NULL;
 
         /* Initialize LNET_PROC_ROUTERS */
-        routers = create_proc_entry (LNET_PROC_ROUTERS, 0444, NULL);
-        if (routers == NULL) {
+        pde = create_proc_entry (LNET_PROC_ROUTERS, 0444, NULL);
+        if (pde == NULL) {
                 CERROR("couldn't create proc entry %s\n", LNET_PROC_ROUTERS);
                 return;
         }
 
-        routers->proc_fops = &lnet_routers_fops;
-        routers->data = NULL;
+        lnet_init_routers_fops();
+        pde->proc_fops = &lnet_routers_fops;
+        pde->data = NULL;
 
         /* Initialize LNET_PROC_PEERS */
-        peers = create_proc_entry (LNET_PROC_PEERS, 0444, NULL);
-        if (peers == NULL) {
+        pde = create_proc_entry (LNET_PROC_PEERS, 0444, NULL);
+        if (pde == NULL) {
                 CERROR("couldn't create proc entry %s\n", LNET_PROC_PEERS);
                 return;
         }
 
-        peers->proc_fops = &lnet_peer_fops;
-        peers->data = NULL;
+        lnet_init_peer_fops();
+        pde->proc_fops = &lnet_peer_fops;
+        pde->data = NULL;
 
         /* Initialize LNET_PROC_BUFFERS */
-        peers = create_proc_entry (LNET_PROC_BUFFERS, 0444, NULL);
-        if (peers == NULL) {
+        pde = create_proc_entry (LNET_PROC_BUFFERS, 0444, NULL);
+        if (pde == NULL) {
                 CERROR("couldn't create proc entry %s\n", LNET_PROC_BUFFERS);
                 return;
         }
 
-        peers->proc_fops = &lnet_buffers_fops;
-        peers->data = NULL;
+        lnet_init_buffers_fops();
+        pde->proc_fops = &lnet_buffers_fops;
+        pde->data = NULL;
 
         /* Initialize LNET_PROC_NIS */
-        peers = create_proc_entry (LNET_PROC_NIS, 0444, NULL);
-        if (peers == NULL) {
+        pde = create_proc_entry (LNET_PROC_NIS, 0444, NULL);
+        if (pde == NULL) {
                 CERROR("couldn't create proc entry %s\n", LNET_PROC_NIS);
                 return;
         }
 
-        peers->proc_fops = &lnet_ni_fops;
-        peers->data = NULL;
+        lnet_init_ni_fops();
+        pde->proc_fops = &lnet_ni_fops;
+        pde->data = NULL;
 }
 
 void
@@ -1077,6 +1113,9 @@ lnet_proc_fini(void)
         remove_proc_entry(LNET_PROC_PEERS, 0);
         remove_proc_entry(LNET_PROC_BUFFERS, 0);
         remove_proc_entry(LNET_PROC_NIS, 0);
+#if 0   
+        remove_proc_entry(LNET_PROC_ROOT, 0);
+#endif
 }
 
 #else