X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lnet%2Flnet%2Frouter_proc.c;h=e1c5055fdd0561150c7325dce2407614acbcfd60;hb=facf5086667874c405c9ef6ce7f8f737868ffefd;hp=76d82b3393c5c91fc3dc7b200a6eafce30cb58cc;hpb=9e78291e0f1f0b12472d6a0b15eaf1aec8076ca1;p=fs%2Flustre-release.git diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c index 76d82b3..e1c5055 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/router_proc.c @@ -1,7 +1,7 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: +/* + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2011, Whamcloud, Inc. * * This file is part of Portals * http://sourceforge.net/projects/sandiaportals/ @@ -27,7 +27,8 @@ #if defined(__KERNEL__) && defined(LNET_ROUTER) -/* this is really lnet_proc.c */ +/* This is really lnet_proc.c. You might need to update sanity test 215 + * if any file format is changed. */ static cfs_sysctl_table_header_t *lnet_table_header = NULL; @@ -51,6 +52,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 +132,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 +149,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 +178,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,13 +199,14 @@ 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; @@ -197,10 +239,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 +262,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 +289,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,8 +308,8 @@ 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; @@ -311,10 +360,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); @@ -325,23 +376,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; @@ -349,7 +383,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; @@ -357,8 +391,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); @@ -373,24 +408,25 @@ int LL_PROC_PROTO(proc_lnet_peers) if (*ppos == 0) { s += snprintf(s, tmpstr + tmpsiz - s, - "%-24s %4s %5s %5s %5s %5s %5s %5s %s\n", - "nid", "refs", "state", "max", + "%-24s %4s %5s %5s %5s %5s %5s %5s %5s %s\n", + "nid", "refs", "state", "last", "max", "rtr", "min", "tx", "min", "queue"); 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; @@ -401,12 +437,12 @@ 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; - /* minor optimiztion: start from idx+1 + /* minor optimization: start from idx+1 * on next iteration if we've just * drained lp_hashlist */ if (lp->lp_hashlist.next == @@ -435,6 +471,7 @@ int LL_PROC_PROTO(proc_lnet_peers) if (peer != NULL) { lnet_nid_t nid = peer->lp_nid; int nrefs = peer->lp_refcount; + int lastalive = -1; char *aliveness = "NA"; int maxcr = peer->lp_ni->ni_peertxcredits; int txcr = peer->lp_txcredits; @@ -444,13 +481,28 @@ 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"; + if (lnet_peer_aliveness_enabled(peer)) { + cfs_time_t now = cfs_time_current(); + cfs_duration_t delta; + + delta = cfs_time_sub(now, peer->lp_last_alive); + lastalive = cfs_duration_sec(delta); + + /* No need to mess up peers contents with + * arbitrarily long integers - it suffices to + * know that lastalive is more than 10000s old + */ + if (lastalive >= 10000) + lastalive = 9999; + } + s += snprintf(s, tmpstr + tmpsiz - s, - "%-24s %4d %5s %5d %5d %5d %5d %5d %d\n", + "%-24s %4d %5s %5d %5d %5d %5d %5d %5d %d\n", libcfs_nid2str(nid), nrefs, aliveness, - maxcr, rtrcr, minrtrcr, txcr, + lastalive, maxcr, rtrcr, minrtrcr, txcr, mintxcr, txqnob); LASSERT (tmpstr + tmpsiz - s > 0); } @@ -463,10 +515,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); @@ -524,8 +576,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; @@ -561,7 +613,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; @@ -570,7 +622,7 @@ 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; @@ -619,7 +671,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; @@ -639,47 +691,49 @@ static cfs_sysctl_table_t lnet_table[] = { * to go via /proc for portability. */ { - .ctl_name = PSDEV_LNET_STATS, + INIT_CTL_NAME(PSDEV_LNET_STATS) .procname = "stats", .mode = 0644, .proc_handler = &proc_lnet_stats, }, { - .ctl_name = PSDEV_LNET_ROUTES, + INIT_CTL_NAME(PSDEV_LNET_ROUTES) .procname = "routes", .mode = 0444, .proc_handler = &proc_lnet_routes, }, { - .ctl_name = PSDEV_LNET_ROUTERS, + INIT_CTL_NAME(PSDEV_LNET_ROUTERS) .procname = "routers", .mode = 0444, .proc_handler = &proc_lnet_routers, }, { - .ctl_name = PSDEV_LNET_PEERS, + INIT_CTL_NAME(PSDEV_LNET_PEERS) .procname = "peers", .mode = 0444, .proc_handler = &proc_lnet_peers, }, { - .ctl_name = PSDEV_LNET_PEERS, + INIT_CTL_NAME(PSDEV_LNET_PEERS) .procname = "buffers", .mode = 0444, .proc_handler = &proc_lnet_buffers, }, { - .ctl_name = PSDEV_LNET_NIS, + INIT_CTL_NAME(PSDEV_LNET_NIS) .procname = "nis", .mode = 0444, .proc_handler = &proc_lnet_nis, }, - {0} + { + INIT_CTL_NAME(0) + } }; static cfs_sysctl_table_t top_table[] = { { - .ctl_name = CTL_LNET, + INIT_CTL_NAME(CTL_LNET) .procname = "lnet", .mode = 0555, .data = NULL, @@ -687,7 +741,7 @@ static cfs_sysctl_table_t top_table[] = { .child = lnet_table, }, { - .ctl_name = 0 + INIT_CTL_NAME(0) } };