Whamcloud - gitweb
Update copyrights on source files changed since 2010-02-15.
[fs/lustre-release.git] / lnet / lnet / router_proc.c
index fce91c2..cd9bdca 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  *
  *   This file is part of Portals
  *   http://sourceforge.net/projects/sandiaportals/
@@ -51,6 +51,41 @@ enum {
 #define PSDEV_LNET_NIS     CTL_UNNUMBERED
 #endif
 
+/*
+ * NB: we don't use the highest bit of *ppos because it's signed;
+ *     next 9 bits is used to stash idx (assuming that
+ *     LNET_PEER_HASHSIZE < 512)
+ */
+#define LNET_LOFFT_BITS        (sizeof(loff_t) * 8)
+#define LNET_VERSION_BITS      MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
+#define LNET_PHASH_IDX_BITS    9
+#define LNET_PHASH_NUM_BITS    (LNET_LOFFT_BITS - 1 -\
+                                LNET_VERSION_BITS - LNET_PHASH_IDX_BITS)
+#define LNET_PHASH_BITS        (LNET_PHASH_IDX_BITS + LNET_PHASH_NUM_BITS)
+
+#define LNET_VERSION_BITMASK   ((1ULL << LNET_VERSION_BITS) - 1)
+#define LNET_PHASH_IDX_BITMASK ((1ULL << LNET_PHASH_IDX_BITS) - 1)
+#define LNET_PHASH_NUM_BITMASK ((1ULL << LNET_PHASH_NUM_BITS) - 1)
+
+#define LNET_VERSION_MASK      (LNET_VERSION_BITMASK << LNET_PHASH_BITS)
+#define LNET_PHASH_IDX_MASK    (LNET_PHASH_IDX_BITMASK << LNET_PHASH_NUM_BITS)
+#define LNET_PHASH_NUM_MASK    (LNET_PHASH_NUM_BITMASK)
+
+#define LNET_VERSION_GET(pos)   (int)(((pos) & LNET_VERSION_MASK) >> \
+                                     LNET_PHASH_BITS)
+#define LNET_PHASH_IDX_GET(pos) (int)(((pos) & LNET_PHASH_IDX_MASK) >> \
+                                      LNET_PHASH_NUM_BITS)
+#define LNET_PHASH_NUM_GET(pos) (int)((pos) & LNET_PHASH_NUM_MASK)
+#define LNET_VERSION_VALID_MASK(ver) \
+                                (unsigned int)((ver) & \
+                                 LNET_VERSION_BITMASK)
+#define LNET_PHASH_POS_MAKE(ver, idx, num)                                     \
+                                (((((loff_t)(ver)) & LNET_VERSION_BITMASK) <<  \
+                                   LNET_PHASH_BITS) |                          \
+                                 ((((loff_t)(idx)) & LNET_PHASH_IDX_BITMASK) <<\
+                                   LNET_PHASH_NUM_BITS) |                      \
+                                 ((num) & LNET_PHASH_NUM_BITMASK))
+
 static int __proc_lnet_stats(void *data, int write,
                              loff_t pos, void *buffer, int nob)
 {
@@ -96,8 +131,8 @@ static int __proc_lnet_stats(void *data, int write,
         if (pos >= min_t(int, len, strlen(tmpstr)))
                 rc = 0;
         else
-                rc = trace_copyout_string(buffer, nob,
-                                          tmpstr + pos, "\n");
+                rc = cfs_trace_copyout_string(buffer, nob,
+                                              tmpstr + pos, "\n");
 
         LIBCFS_FREE(tmpstr, tmpsiz);
         LIBCFS_FREE(ctrs, sizeof(*ctrs));
@@ -113,10 +148,14 @@ int LL_PROC_PROTO(proc_lnet_routes)
         char      *s;
         const int  tmpsiz = 256;
         int        len;
-        int       *ver_p  = (unsigned int *)(&filp->private_data);
+        int        ver;
+        int        num;
 
         DECLARE_LL_PROC_PPOS_DECL;
 
+        num = LNET_PHASH_NUM_GET(*ppos);
+        ver = LNET_VERSION_GET(*ppos);
+
         LASSERT (!write);
 
         if (*lenp == 0)
@@ -138,18 +177,19 @@ int LL_PROC_PROTO(proc_lnet_routes)
                 LASSERT (tmpstr + tmpsiz - s > 0);
 
                 LNET_LOCK();
-                *ver_p = (unsigned int)the_lnet.ln_remote_nets_version;
+                ver = (unsigned int)the_lnet.ln_remote_nets_version;
                 LNET_UNLOCK();
+                *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
         } else {
-                struct list_head  *n;
-                struct list_head  *r;
+                cfs_list_t        *n;
+                cfs_list_t        *r;
                 lnet_route_t      *route = NULL;
                 lnet_remotenet_t  *rnet  = NULL;
-                int                skip  = *ppos - 1;
+                int                skip  = num - 1;
 
                 LNET_LOCK();
 
-                if (*ver_p != (unsigned int)the_lnet.ln_remote_nets_version) {
+                if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_remote_nets_version)) {
                         LNET_UNLOCK();
                         LIBCFS_FREE(tmpstr, tmpsiz);
                         return -ESTALE;
@@ -158,19 +198,20 @@ int LL_PROC_PROTO(proc_lnet_routes)
                 n = the_lnet.ln_remote_nets.next;
 
                 while (n != &the_lnet.ln_remote_nets && route == NULL) {
-                        rnet = list_entry(n, lnet_remotenet_t, lrn_list);
+                        rnet = cfs_list_entry(n, lnet_remotenet_t, lrn_list);
 
                         r = rnet->lrn_routes.next;
 
                         while (r != &rnet->lrn_routes) {
-                                lnet_route_t *re = list_entry(r, lnet_route_t,
-                                                              lr_list);
+                                lnet_route_t *re =
+                                        cfs_list_entry(r, lnet_route_t,
+                                                       lr_list);
                                 if (skip == 0) {
                                         route = re;
                                         break;
-                                } else
-                                        skip--;
+                                }
 
+                                skip--;
                                 r = r->next;
                         }
 
@@ -197,10 +238,12 @@ int LL_PROC_PROTO(proc_lnet_routes)
         if (len > *lenp) {    /* linux-supplied buffer is too small */
                 rc = -EINVAL;
         } else if (len > 0) { /* wrote something */
-                if (copy_to_user(buffer, tmpstr, len))
+                if (cfs_copy_to_user(buffer, tmpstr, len))
                         rc = -EFAULT;
-                else
-                        *ppos += 1;
+                else {
+                        num += 1;
+                        *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
+                }
         }
 
         LIBCFS_FREE(tmpstr, tmpsiz);
@@ -218,10 +261,14 @@ int LL_PROC_PROTO(proc_lnet_routers)
         char      *s;
         const int  tmpsiz = 256;
         int        len;
-        int       *ver_p = (unsigned int *)(&filp->private_data);
+        int        ver;
+        int        num;
 
         DECLARE_LL_PROC_PPOS_DECL;
 
+        num = LNET_PHASH_NUM_GET(*ppos);
+        ver = LNET_VERSION_GET(*ppos);
+
         LASSERT (!write);
 
         if (*lenp == 0)
@@ -241,16 +288,17 @@ int LL_PROC_PROTO(proc_lnet_routers)
                 LASSERT (tmpstr + tmpsiz - s > 0);
 
                 LNET_LOCK();
-                *ver_p = (unsigned int)the_lnet.ln_routers_version;
+                ver = (unsigned int)the_lnet.ln_routers_version;
                 LNET_UNLOCK();
+                *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
         } else {
-                struct list_head  *r;
+                cfs_list_t        *r;
                 lnet_peer_t       *peer = NULL;
-                int                skip = *ppos - 1;
+                int                skip = num - 1;
 
                 LNET_LOCK();
 
-                if (*ver_p != (unsigned int)the_lnet.ln_routers_version) {
+                if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_routers_version)) {
                         LNET_UNLOCK();
                         LIBCFS_FREE(tmpstr, tmpsiz);
                         return -ESTALE;
@@ -259,15 +307,15 @@ int LL_PROC_PROTO(proc_lnet_routers)
                 r = the_lnet.ln_routers.next;
 
                 while (r != &the_lnet.ln_routers) {
-                        lnet_peer_t *lp = list_entry(r, lnet_peer_t,
-                                                     lp_rtr_list);
+                        lnet_peer_t *lp = cfs_list_entry(r, lnet_peer_t,
+                                                         lp_rtr_list);
 
                         if (skip == 0) {
                                 peer = lp;
-                                        break;
-                                } else
-                                        skip--;
+                                break;
+                        }
 
+                        skip--;
                         r = r->next;
                 }
 
@@ -280,8 +328,10 @@ int LL_PROC_PROTO(proc_lnet_routers)
                         int alive_cnt = peer->lp_alive_count;
                         int alive     = peer->lp_alive;
                         int pingsent  = !peer->lp_ping_notsent;
-                        int last_ping = cfs_duration_sec(now - peer->lp_ping_timestamp);
-                        int down_ni   = lnet_router_down_ni(peer, LNET_NIDNET(LNET_NID_ANY));
+                        int last_ping = cfs_duration_sec(cfs_time_sub(now,
+                                                     peer->lp_ping_timestamp));
+                        int down_ni   = lnet_router_down_ni(peer,
+                                                    LNET_NIDNET(LNET_NID_ANY));
 
                         if (deadline == 0)
                                 s += snprintf(s, tmpstr + tmpsiz - s,
@@ -296,7 +346,7 @@ int LL_PROC_PROTO(proc_lnet_routers)
                                               nrefs, nrtrrefs, alive_cnt,
                                               alive ? "up" : "down", last_ping,
                                               pingsent,
-                                              cfs_duration_sec(deadline - now),
+                                              cfs_duration_sec(cfs_time_sub(deadline, now)),
                                               down_ni, libcfs_nid2str(nid));
                         LASSERT (tmpstr + tmpsiz - s > 0);
                 }
@@ -309,10 +359,12 @@ int LL_PROC_PROTO(proc_lnet_routers)
         if (len > *lenp) {    /* linux-supplied buffer is too small */
                 rc = -EINVAL;
         } else if (len > 0) { /* wrote something */
-                if (copy_to_user(buffer, tmpstr, len))
+                if (cfs_copy_to_user(buffer, tmpstr, len))
                         rc = -EFAULT;
-                else
-                        *ppos += 1;
+                else {
+                        num += 1;
+                        *ppos = LNET_PHASH_POS_MAKE(ver, 0, num);
+                }
         }
 
         LIBCFS_FREE(tmpstr, tmpsiz);
@@ -323,23 +375,6 @@ int LL_PROC_PROTO(proc_lnet_routers)
         return rc;
 }
 
-/*
- * NB: we don't use the highest bit of *ppos because it's signed;
- *     next 9 bits is used to stash idx (assuming that
- *     LNET_PEER_HASHSIZE < 512)
- */
-#define LNET_LOFFT_BITS (sizeof(loff_t) * 8)
-#define LNET_PHASH_BITS 9
-#define LNET_PHASH_IDX_MASK (((1ULL << LNET_PHASH_BITS) - 1) <<               \
-                             (LNET_LOFFT_BITS - LNET_PHASH_BITS - 1))
-#define LNET_PHASH_NUM_MASK ((1ULL <<                                         \
-                              (LNET_LOFFT_BITS - LNET_PHASH_BITS -1)) - 1)
-#define LNET_PHASH_IDX_GET(pos) (int)(((pos) & LNET_PHASH_IDX_MASK) >>  \
-                                      (LNET_LOFFT_BITS - LNET_PHASH_BITS -1))
-#define LNET_PHASH_NUM_GET(pos) (int)((pos) & LNET_PHASH_NUM_MASK)
-#define LNET_PHASH_POS_MAKE(idx, num) ((((loff_t)idx) << (LNET_LOFFT_BITS -   \
-                                                  LNET_PHASH_BITS -1)) | (num))
-
 int LL_PROC_PROTO(proc_lnet_peers)
 {
         int        rc = 0;
@@ -347,7 +382,7 @@ int LL_PROC_PROTO(proc_lnet_peers)
         char      *s;
         const int  tmpsiz      = 256;
         int        len;
-        int       *ver_p       = (unsigned int *)(&filp->private_data);
+        int        ver;
         int        idx;
         int        num;
 
@@ -355,8 +390,9 @@ int LL_PROC_PROTO(proc_lnet_peers)
 
         idx = LNET_PHASH_IDX_GET(*ppos);
         num = LNET_PHASH_NUM_GET(*ppos);
+        ver = LNET_VERSION_GET(*ppos);
 
-        CLASSERT ((1 << LNET_PHASH_BITS) > LNET_PEER_HASHSIZE);
+        CLASSERT ((1ULL << LNET_PHASH_BITS) > LNET_PEER_HASHSIZE);
 
         LASSERT (!write);
 
@@ -377,18 +413,19 @@ int LL_PROC_PROTO(proc_lnet_peers)
                 LASSERT (tmpstr + tmpsiz - s > 0);
 
                 LNET_LOCK();
-                *ver_p  = (unsigned int)the_lnet.ln_peertable_version;
+                ver = (unsigned int)the_lnet.ln_peertable_version;
                 LNET_UNLOCK();
+                *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
 
                 num++;
         } else {
-                struct list_head  *p    = NULL;
+                cfs_list_t        *p    = NULL;
                 lnet_peer_t       *peer = NULL;
                 int                skip = num - 1;
 
                 LNET_LOCK();
 
-                if (*ver_p != (unsigned int)the_lnet.ln_peertable_version) {
+                if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_peertable_version)) {
                         LNET_UNLOCK();
                         LIBCFS_FREE(tmpstr, tmpsiz);
                         return -ESTALE;
@@ -399,8 +436,8 @@ int LL_PROC_PROTO(proc_lnet_peers)
                                 p = the_lnet.ln_peer_hash[idx].next;
 
                         while (p != &the_lnet.ln_peer_hash[idx]) {
-                                lnet_peer_t *lp = list_entry(p, lnet_peer_t,
-                                                             lp_hashlist);
+                                lnet_peer_t *lp = cfs_list_entry(p, lnet_peer_t,
+                                                                 lp_hashlist);
                                 if (skip == 0) {
                                         peer = lp;
 
@@ -411,13 +448,14 @@ int LL_PROC_PROTO(proc_lnet_peers)
                                             &the_lnet.ln_peer_hash[idx]) {
                                                 num = 1;
                                                 idx++;
-                                        } else
+                                        } else {
                                                 num++;
+                                        }
 
                                         break;
-                                } else
-                                        skip--;
+                                }
 
+                                skip--;
                                 p = lp->lp_hashlist.next;
                         }
 
@@ -441,7 +479,7 @@ int LL_PROC_PROTO(proc_lnet_peers)
                         int        txqnob    = peer->lp_txqnob;
 
                         if (lnet_isrouter(peer) ||
-                            peer->lp_ni->ni_peertimeout > 0)
+                            lnet_peer_aliveness_enabled(peer))
                                 aliveness = peer->lp_alive ? "up" : "down";
 
                         s += snprintf(s, tmpstr + tmpsiz - s,
@@ -460,10 +498,10 @@ int LL_PROC_PROTO(proc_lnet_peers)
         if (len > *lenp) {    /* linux-supplied buffer is too small */
                 rc = -EINVAL;
         } else if (len > 0) { /* wrote something */
-                if (copy_to_user(buffer, tmpstr, len))
+                if (cfs_copy_to_user(buffer, tmpstr, len))
                         rc = -EFAULT;
                 else
-                        *ppos = LNET_PHASH_POS_MAKE(idx, num);
+                        *ppos = LNET_PHASH_POS_MAKE(ver, idx, num);
         }
 
         LIBCFS_FREE(tmpstr, tmpsiz);
@@ -521,8 +559,8 @@ static int __proc_lnet_buffers(void *data, int write,
         if (pos >= min_t(int, len, strlen(tmpstr)))
                 rc = 0;
         else
-                rc = trace_copyout_string(buffer, nob,
-                                          tmpstr + pos, NULL);
+                rc = cfs_trace_copyout_string(buffer, nob,
+                                              tmpstr + pos, NULL);
 
         LIBCFS_FREE(tmpstr, tmpsiz);
         return rc;
@@ -558,7 +596,7 @@ int LL_PROC_PROTO(proc_lnet_nis)
                               "rtr", "max", "tx", "min");
                 LASSERT (tmpstr + tmpsiz - s > 0);
         } else {
-                struct list_head  *n;
+                cfs_list_t        *n;
                 lnet_ni_t         *ni   = NULL;
                 int                skip = *ppos - 1;
 
@@ -567,19 +605,20 @@ int LL_PROC_PROTO(proc_lnet_nis)
                 n = the_lnet.ln_nis.next;
 
                 while (n != &the_lnet.ln_nis) {
-                        lnet_ni_t *a_ni = list_entry(n, lnet_ni_t, ni_list);
+                        lnet_ni_t *a_ni = cfs_list_entry(n, lnet_ni_t, ni_list);
 
                         if (skip == 0) {
                                 ni = a_ni;
                                 break;
-                        } else
-                                skip--;
+                        }
 
+                        skip--;
                         n = n->next;
                 }
 
                 if (ni != NULL) {
                         cfs_time_t now = cfs_time_current();
+                        int        last_alive = -1;
                         int        maxtxcr = ni->ni_maxtxcredits;
                         int        txcr = ni->ni_txcredits;
                         int        mintxcr = ni->ni_mintxcredits;
@@ -587,11 +626,11 @@ int LL_PROC_PROTO(proc_lnet_nis)
                         int        npeerrtrcr = ni->ni_peerrtrcredits;
                         lnet_nid_t nid = ni->ni_nid;
                         int        nref = ni->ni_refcount;
-                        int        last_alive;
                         char      *stat;
 
-                        last_alive = (the_lnet.ln_routing) ?
-                                 cfs_duration_sec(now - ni->ni_last_alive) : -1;
+                        if (the_lnet.ln_routing)
+                                last_alive = cfs_duration_sec(cfs_time_sub(now,
+                                                            ni->ni_last_alive));
                         if (ni->ni_lnd->lnd_type == LOLND)  /* @lo forever alive */
                                 last_alive = 0;
 
@@ -615,7 +654,7 @@ int LL_PROC_PROTO(proc_lnet_nis)
         if (len > *lenp) {    /* linux-supplied buffer is too small */
                 rc = -EINVAL;
         } else if (len > 0) { /* wrote something */
-                if (copy_to_user(buffer, tmpstr, len))
+                if (cfs_copy_to_user(buffer, tmpstr, len))
                         rc = -EFAULT;
                 else
                         *ppos += 1;