From: Amir Shehata Date: Thu, 10 Oct 2013 22:27:11 +0000 (-0700) Subject: LU-2456 lnet: Dynamic LNet Configuration (DLC) show command X-Git-Tag: 2.6.52~4 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=f3b3e3f1b92f507816120a53bbfd0ab4887a7a98 LU-2456 lnet: Dynamic LNet Configuration (DLC) show command This is the fifth patch of a set of patches that enables DLC. This patch adds the new structures which will be used in the IOCTL communication. It also added a set of show operations to show buffers, networks, statistics and peer information. Signed-off-by: Amir Shehata Change-Id: I96e5cb3dcf07289c6cd1deb46f4acb3c263ae21e Reviewed-on: http://review.whamcloud.com/8022 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Doug Oucharek Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/libcfs_ioctl.h b/libcfs/include/libcfs/libcfs_ioctl.h index 732a181..3fb0539 100644 --- a/libcfs/include/libcfs/libcfs_ioctl.h +++ b/libcfs/include/libcfs/libcfs_ioctl.h @@ -42,6 +42,7 @@ #define __LIBCFS_IOCTL_H__ #define LIBCFS_IOCTL_VERSION 0x0001000a +#define LIBCFS_IOCTL_VERSION2 0x0001000b struct libcfs_ioctl_hdr { __u32 ioc_len; @@ -89,6 +90,14 @@ do { \ data.ioc_hdr.ioc_len = sizeof(data); \ } while (0) +#define LIBCFS_IOC_INIT_V2(data, hdr) \ +do { \ + memset(&(data), 0, sizeof(data)); \ + (data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2; \ + (data).hdr.ioc_len = sizeof(data); \ +} while (0) + + #ifdef __KERNEL__ struct libcfs_ioctl_handler { @@ -109,8 +118,8 @@ struct libcfs_ioctl_handler { #define IOCTL_LIBCFS_TYPE long /* ioctls for manipulating snapshots 30- */ -#define IOC_LIBCFS_TYPE 'e' -#define IOC_LIBCFS_MIN_NR 30 +#define IOC_LIBCFS_TYPE ('e') +#define IOC_LIBCFS_MIN_NR 30 /* libcfs ioctls */ #define IOC_LIBCFS_PANIC _IOWR('e', 30, IOCTL_LIBCFS_TYPE) #define IOC_LIBCFS_CLEAR_DEBUG _IOWR('e', 31, IOCTL_LIBCFS_TYPE) @@ -118,34 +127,61 @@ struct libcfs_ioctl_handler { #define IOC_LIBCFS_MEMHOG _IOWR('e', 36, IOCTL_LIBCFS_TYPE) #define IOC_LIBCFS_PING_TEST _IOWR('e', 37, IOCTL_LIBCFS_TYPE) /* lnet ioctls */ -#define IOC_LIBCFS_GET_NI _IOWR('e', 50, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_FAIL_NID _IOWR('e', 51, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_ADD_ROUTE _IOWR('e', 52, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_DEL_ROUTE _IOWR('e', 53, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_GET_ROUTE _IOWR('e', 54, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_NOTIFY_ROUTER _IOWR('e', 55, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_UNCONFIGURE _IOWR('e', 56, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_GET_NI _IOWR('e', 50, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_FAIL_NID _IOWR('e', 51, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_NOTIFY_ROUTER _IOWR('e', 55, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_UNCONFIGURE _IOWR('e', 56, IOCTL_LIBCFS_TYPE) #define IOC_LIBCFS_PORTALS_COMPATIBILITY _IOWR('e', 57, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_LNET_DIST _IOWR('e', 58, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_CONFIGURE _IOWR('e', 59, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_TESTPROTOCOMPAT _IOWR('e', 60, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_PING _IOWR('e', 61, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_DEBUG_PEER _IOWR('e', 62, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_LNETST _IOWR('e', 63, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_LNET_DIST _IOWR('e', 58, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_CONFIGURE _IOWR('e', 59, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_TESTPROTOCOMPAT _IOWR('e', 60, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_PING _IOWR('e', 61, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_DEBUG_PEER _IOWR('e', 62, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_LNETST _IOWR('e', 63, IOCTL_LIBCFS_TYPE) /* lnd ioctls */ -#define IOC_LIBCFS_REGISTER_MYNID _IOWR('e', 70, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_CLOSE_CONNECTION _IOWR('e', 71, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_PUSH_CONNECTION _IOWR('e', 72, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_GET_CONN _IOWR('e', 73, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_DEL_PEER _IOWR('e', 74, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_ADD_PEER _IOWR('e', 75, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_GET_PEER _IOWR('e', 76, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_GET_TXDESC _IOWR('e', 77, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_ADD_INTERFACE _IOWR('e', 78, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_DEL_INTERFACE _IOWR('e', 79, IOCTL_LIBCFS_TYPE) -#define IOC_LIBCFS_GET_INTERFACE _IOWR('e', 80, IOCTL_LIBCFS_TYPE) - -#define IOC_LIBCFS_MAX_NR 80 +#define IOC_LIBCFS_REGISTER_MYNID _IOWR('e', 70, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_CLOSE_CONNECTION _IOWR('e', 71, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_PUSH_CONNECTION _IOWR('e', 72, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_GET_CONN _IOWR('e', 73, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_DEL_PEER _IOWR('e', 74, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_ADD_PEER _IOWR('e', 75, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_GET_PEER _IOWR('e', 76, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_GET_TXDESC _IOWR('e', 77, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_ADD_INTERFACE _IOWR('e', 78, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_DEL_INTERFACE _IOWR('e', 79, IOCTL_LIBCFS_TYPE) +#define IOC_LIBCFS_GET_INTERFACE _IOWR('e', 80, IOCTL_LIBCFS_TYPE) + + +/* + * DLC Speicif IOCTL numbers. + * In order to maintain backward compatibility with any possible external + * tools which might be accessing the IOCTL numbers, a new group of IOCTL + * number have been allocated. + */ +#define IOCTL_CONFIG_SIZE struct lnet_ioctl_config_data +#define IOC_LIBCFS_ADD_ROUTE _IOWR(IOC_LIBCFS_TYPE, 81, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_DEL_ROUTE _IOWR(IOC_LIBCFS_TYPE, 82, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_GET_ROUTE _IOWR(IOC_LIBCFS_TYPE, 83, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_ADD_NET _IOWR(IOC_LIBCFS_TYPE, 84, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_DEL_NET _IOWR(IOC_LIBCFS_TYPE, 85, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_GET_NET _IOWR(IOC_LIBCFS_TYPE, 86, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_CONFIG_RTR _IOWR(IOC_LIBCFS_TYPE, 87, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_ADD_BUF _IOWR(IOC_LIBCFS_TYPE, 88, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_GET_BUF _IOWR(IOC_LIBCFS_TYPE, 89, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_GET_PEER_INFO _IOWR(IOC_LIBCFS_TYPE, 90, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_GET_LNET_STATS _IOWR(IOC_LIBCFS_TYPE, 91, \ + IOCTL_CONFIG_SIZE) +#define IOC_LIBCFS_MAX_NR 91 static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data) { diff --git a/libcfs/libcfs/linux/linux-module.c b/libcfs/libcfs/linux/linux-module.c index 0008125..6d841b4 100644 --- a/libcfs/libcfs/linux/linux-module.c +++ b/libcfs/libcfs/linux/linux-module.c @@ -66,7 +66,8 @@ int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg, if (copy_from_user(&hdr, arg, sizeof(hdr))) RETURN(-EFAULT); - if (hdr.ioc_version != LIBCFS_IOCTL_VERSION) { + if (hdr.ioc_version != LIBCFS_IOCTL_VERSION && + hdr.ioc_version != LIBCFS_IOCTL_VERSION2) { CERROR("LNET: version mismatch expected %#x, got %#x\n", LIBCFS_IOCTL_VERSION, hdr.ioc_version); RETURN(-EINVAL); @@ -139,9 +140,9 @@ static long libcfs_ioctl(struct file *file, if (!capable(CAP_SYS_ADMIN)) return -EACCES; - if ( _IOC_TYPE(cmd) != IOC_LIBCFS_TYPE || - _IOC_NR(cmd) < IOC_LIBCFS_MIN_NR || - _IOC_NR(cmd) > IOC_LIBCFS_MAX_NR ) { + if (_IOC_TYPE(cmd) != IOC_LIBCFS_TYPE || + _IOC_NR(cmd) < IOC_LIBCFS_MIN_NR || + _IOC_NR(cmd) > IOC_LIBCFS_MAX_NR) { CDEBUG(D_IOCTL, "invalid ioctl ( type %d, nr %d, size %d )\n", _IOC_TYPE(cmd), _IOC_NR(cmd), _IOC_SIZE(cmd)); return (-EINVAL); diff --git a/libcfs/libcfs/module.c b/libcfs/libcfs/module.c index 8eeca56..16d0a16 100644 --- a/libcfs/libcfs/module.c +++ b/libcfs/libcfs/module.c @@ -35,15 +35,13 @@ */ #define DEBUG_SUBSYSTEM S_LNET -/* TODO - This will be completed in the subsequent patches. - * For this patch the MAX is hardcoded, in the next patch - * the value will be set to the largest data structure that - * can be sent from user space */ -#define LIBCFS_MAX_IOCTL_BUF_LEN 2048 +#define LNET_MAX_IOCTL_BUF_LEN (sizeof(struct lnet_ioctl_net_config) + \ + sizeof(struct lnet_ioctl_config_data)) #include #include #include +#include #include #include "tracefile.h" @@ -230,10 +228,11 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file *pfile, unsigned long cmd, int err; ENTRY; - /* TODO: this is going to change in subsequent patches - * to exclude messages which use the new data structures */ - if ((cmd <= IOC_LIBCFS_LNETST) || - (cmd >= IOC_LIBCFS_REGISTER_MYNID)) { + /* The libcfs_ioctl_data_adjust() function performs adjustment + * operations on the libcfs_ioctl_data structure to make + * it usable by the code. This doesn't need to be called + * for new data structures added. */ + if (hdr->ioc_version == LIBCFS_IOCTL_VERSION) { data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr); err = libcfs_ioctl_data_adjust(data); if (err != 0) { @@ -325,7 +324,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, * do a check here to restrict the size of the memory * to allocate to guard against DoS attacks. */ - if (buf_len > LIBCFS_MAX_IOCTL_BUF_LEN) { + if (buf_len > LNET_MAX_IOCTL_BUF_LEN) { CERROR("LNET: user buffer exceeds kernel buffer\n"); RETURN(-EINVAL); } diff --git a/lnet/include/lnet/Makefile.am b/lnet/include/lnet/Makefile.am index b7e824f..e40e743 100644 --- a/lnet/include/lnet/Makefile.am +++ b/lnet/include/lnet/Makefile.am @@ -4,5 +4,5 @@ SUBDIRS = linux DIST_SUBDIRS = linux EXTRA_DIST = api.h api-support.h \ - lib-lnet.h lib-types.h lnet.h lnetctl.h types.h \ + lib-dlc.h lib-lnet.h lib-types.h lnet.h lnetctl.h types.h \ socklnd.h lnetst.h diff --git a/lnet/include/lnet/lib-dlc.h b/lnet/include/lnet/lib-dlc.h new file mode 100644 index 0000000..6ea30c3 --- /dev/null +++ b/lnet/include/lnet/lib-dlc.h @@ -0,0 +1,110 @@ +/* + * LGPL HEADER START + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright (c) 2013, Intel Corporation, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + * + * LGPL HEADER END + * + * Contributers: + * Amir Shehata + */ + +#ifndef LNET_DLC_H +#define LNET_DLC_H + +#include +#include + +#define MAX_NUM_SHOW_ENTRIES 32 +#define LNET_MAX_STR_LEN 128 +#define LNET_MAX_SHOW_NUM_CPT 128 + +struct lnet_ioctl_net_config { + char ni_interfaces[LNET_MAX_INTERFACES][LNET_MAX_STR_LEN]; + __u32 ni_status; + __u32 ni_cpts[LNET_MAX_SHOW_NUM_CPT]; +}; + +struct lnet_ioctl_pool_cfg { + struct { + __u32 pl_npages; + __u32 pl_nbuffers; + __u32 pl_credits; + __u32 pl_mincredits; + } pl_pools[LNET_NRBPOOLS]; + __u32 pl_routing; +}; + +struct lnet_ioctl_config_data { + struct libcfs_ioctl_hdr cfg_hdr; + + __u32 cfg_net; + __u32 cfg_count; + __u64 cfg_nid; + __u32 cfg_ncpts; + + union { + struct { + __u32 rtr_hop; + __u32 rtr_priority; + __u32 rtr_flags; + } cfg_route; + struct { + char net_intf[LNET_MAX_STR_LEN]; + __s32 net_peer_timeout; + __s32 net_peer_tx_credits; + __s32 net_peer_rtr_credits; + __s32 net_max_tx_credits; + } cfg_net; + struct { + __u32 buf_enable; + __s32 buf_tiny; + __s32 buf_small; + __s32 buf_large; + } cfg_buffers; + } cfg_config_u; + + char cfg_bulk[0]; +}; + +struct lnet_ioctl_peer { + struct libcfs_ioctl_hdr pr_hdr; + __u32 pr_count; + __u32 pr_pad; + __u64 pr_nid; + + union { + struct { + char cr_aliveness[LNET_MAX_STR_LEN]; + __u32 cr_refcount; + __u32 cr_ni_peer_tx_credits; + __u32 cr_peer_tx_credits; + __u32 cr_peer_rtr_credits; + __u32 cr_peer_min_rtr_credits; + __u32 cr_peer_tx_qnob; + __u32 cr_ncpt; + } pr_peer_credits; + } pr_lnd_u; +}; + +struct lnet_ioctl_lnet_stats { + struct libcfs_ioctl_hdr st_hdr; + struct lnet_counters st_cntrs; +}; + +#endif /* LNET_DLC_H */ diff --git a/lnet/include/lnet/lib-lnet.h b/lnet/include/lnet/lib-lnet.h index 5c5a30d..03162b4 100644 --- a/lnet/include/lnet/lib-lnet.h +++ b/lnet/include/lnet/lib-lnet.h @@ -960,6 +960,11 @@ void lnet_peer_tables_cleanup(lnet_ni_t *ni); void lnet_peer_tables_destroy(void); int lnet_peer_tables_create(void); void lnet_debug_peer(lnet_nid_t nid); +int lnet_get_peers(int count, __u64 *nid, char *alivness, + int *ncpt, int *refcount, + int *ni_peer_tx_credits, int *peer_tx_credits, + int *peer_rtr_credits, int *peer_min_rtr_credtis, + int *peer_tx_qnob); #ifndef __KERNEL__ static inline int diff --git a/lnet/include/lnet/lib-types.h b/lnet/include/lnet/lib-types.h index 21d2636..9039e7a 100644 --- a/lnet/include/lnet/lib-types.h +++ b/lnet/include/lnet/lib-types.h @@ -403,7 +403,7 @@ struct lnet_tx_queue { struct list_head tq_delayed; /* delayed TXs */ }; -#define LNET_MAX_INTERFACES 16 +#define LNET_MAX_INTERFACES 16 typedef struct lnet_ni { #ifdef __KERNEL__ @@ -586,18 +586,18 @@ typedef struct { lnet_kiov_t rb_kiov[0]; /* the buffer space */ } lnet_rtrbuf_t; -typedef struct { - __u32 msgs_alloc; - __u32 msgs_max; - __u32 errors; - __u32 send_count; - __u32 recv_count; - __u32 route_count; - __u32 drop_count; - __u64 send_length; - __u64 recv_length; - __u64 route_length; - __u64 drop_length; +typedef struct lnet_counters { + __u32 msgs_alloc; + __u32 msgs_max; + __u32 errors; + __u32 send_count; + __u32 recv_count; + __u32 route_count; + __u32 drop_count; + __u64 send_length; + __u64 recv_length; + __u64 route_length; + __u64 drop_length; } WIRE_ATTR lnet_counters_t; #define LNET_PEER_HASHSIZE 503 /* prime! */ diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 58a4aa1..19e1a9c 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -36,6 +36,7 @@ #define DEBUG_SUBSYSTEM S_LNET #include +#include #ifdef __KERNEL__ #include #endif @@ -1979,6 +1980,7 @@ int LNetCtl(unsigned int cmd, void *arg) { struct libcfs_ioctl_data *data = arg; + struct lnet_ioctl_config_data *config; lnet_process_id_t id = {0}; lnet_ni_t *ni; int rc; @@ -2002,16 +2004,53 @@ LNetCtl(unsigned int cmd, void *arg) return (rc != 0) ? rc : lnet_check_routes(); case IOC_LIBCFS_DEL_ROUTE: + config = arg; LNET_MUTEX_LOCK(&the_lnet.ln_api_mutex); - rc = lnet_del_route(data->ioc_net, data->ioc_nid); + rc = lnet_del_route(config->cfg_net, config->cfg_nid); LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex); return rc; case IOC_LIBCFS_GET_ROUTE: - return lnet_get_route(data->ioc_count, - &data->ioc_net, &data->ioc_count, - &data->ioc_nid, &data->ioc_flags, - &data->ioc_priority); + config = arg; + return lnet_get_route(config->cfg_count, + &config->cfg_net, + &config->cfg_config_u.cfg_route.rtr_hop, + &config->cfg_nid, + &config->cfg_config_u.cfg_route.rtr_flags, + &config->cfg_config_u.cfg_route. + rtr_priority); + + case IOC_LIBCFS_ADD_NET: + return 0; + + case IOC_LIBCFS_DEL_NET: + return 0; + + case IOC_LIBCFS_GET_NET: + return 0; + + case IOC_LIBCFS_GET_LNET_STATS: + { + struct lnet_ioctl_lnet_stats *lnet_stats = arg; + + lnet_counters_get(&lnet_stats->st_cntrs); + return 0; + } + +#if defined(__KERNEL__) && defined(LNET_ROUTER) + case IOC_LIBCFS_CONFIG_RTR: + return 0; + + case IOC_LIBCFS_ADD_BUF: + return 0; +#endif + + case IOC_LIBCFS_GET_BUF: + return 0; + + case IOC_LIBCFS_GET_PEER_INFO: + return 0; + case IOC_LIBCFS_NOTIFY_ROUTER: return lnet_notify(NULL, data->ioc_nid, data->ioc_flags, cfs_time_current() - diff --git a/lnet/lnet/module.c b/lnet/lnet/module.c index aaad649..49366be 100644 --- a/lnet/lnet/module.c +++ b/lnet/lnet/module.c @@ -36,6 +36,7 @@ #define DEBUG_SUBSYSTEM S_LNET #include +#include static int config_on_load = 0; CFS_MODULE_PARM(config_on_load, "i", int, 0444, @@ -95,6 +96,9 @@ lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr) case IOC_LIBCFS_UNCONFIGURE: return lnet_unconfigure(); + case IOC_LIBCFS_ADD_NET: + return LNetCtl(cmd, hdr); + default: /* Passing LNET_PID_ANY only gives me a ref if the net is up * already; I'll need it to ensure the net can't go down while diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index 5b4b09e..744e151 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -39,6 +39,7 @@ #define DEBUG_SUBSYSTEM S_LNET #include +#include int lnet_peer_tables_create(void) @@ -387,3 +388,62 @@ lnet_debug_peer(lnet_nid_t nid) lnet_net_unlock(cpt); } + +int lnet_get_peers(int count, __u64 *nid, char *aliveness, + int *ncpt, int *refcount, + int *ni_peer_tx_credits, int *peer_tx_credits, + int *peer_rtr_credits, int *peer_min_rtr_credits, + int *peer_tx_qnob) +{ + struct lnet_peer_table *peer_table; + lnet_peer_t *lp; + int j; + int lncpt, found = 0; + + /* get the number of CPTs */ + lncpt = cfs_percpt_number(the_lnet.ln_peer_tables); + /* if the cpt number to be examined is >= the number of cpts in + * the system then indicate that there are no more cpts to examin + */ + if (*ncpt > lncpt) + return -1; + + /* get the current table */ + peer_table = the_lnet.ln_peer_tables[*ncpt]; + /* if the ptable is NULL then there are no more cpts to examine */ + if (peer_table == NULL) + return -1; + + lnet_net_lock(*ncpt); + + for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) { + struct list_head *peers = &peer_table->pt_hash[j]; + + list_for_each_entry(lp, peers, lp_hashlist) { + if (count-- > 0) + continue; + + snprintf(aliveness, LNET_MAX_STR_LEN, "NA"); + if (lnet_isrouter(lp) || + lnet_peer_aliveness_enabled(lp)) + snprintf(aliveness, LNET_MAX_STR_LEN, + lp->lp_alive ? "up" : "down"); + + *nid = lp->lp_nid; + *refcount = lp->lp_refcount; + *ni_peer_tx_credits = lp->lp_ni->ni_peertxcredits; + *peer_tx_credits = lp->lp_txcredits; + *peer_rtr_credits = lp->lp_rtrcredits; + *peer_min_rtr_credits = lp->lp_mintxcredits; + *peer_tx_qnob = lp->lp_txqnob; + + found = 1; + } + + } + lnet_net_unlock(*ncpt); + + *ncpt = lncpt; + + return found ? 0 : -ENOENT; +} diff --git a/lnet/utils/portals.c b/lnet/utils/portals.c index 7161f6b..42d2f67 100644 --- a/lnet/utils/portals.c +++ b/lnet/utils/portals.c @@ -22,6 +22,7 @@ #include #include #include +#include unsigned int libcfs_debug; unsigned int libcfs_printk = D_CANTMASK; @@ -1087,12 +1088,12 @@ jt_ptl_fail_nid (int argc, char **argv) int jt_ptl_add_route (int argc, char **argv) { - struct libcfs_ioctl_data data; - lnet_nid_t gateway_nid; - unsigned int hops = 1; + struct lnet_ioctl_config_data data; + lnet_nid_t gateway_nid; + unsigned int hops = 1; unsigned int priority = 0; - char *end; - int rc; + char *end; + int rc; if (argc < 2 || argc > 4) { fprintf(stderr, "usage: %s gateway [hopcount [priority]]\n", @@ -1100,14 +1101,14 @@ jt_ptl_add_route (int argc, char **argv) return -1; } - if (!g_net_is_set(argv[0])) - return (-1); + if (g_net_is_set(argv[0]) == 0) + return -1; - gateway_nid = libcfs_str2nid(argv[1]); - if (gateway_nid == LNET_NID_ANY) { - fprintf (stderr, "Can't parse gateway NID \"%s\"\n", argv[1]); - return (-1); - } + gateway_nid = libcfs_str2nid(argv[1]); + if (gateway_nid == LNET_NID_ANY) { + fprintf(stderr, "Can't parse gateway NID \"%s\"\n", argv[1]); + return -1; + } if (argc > 2) { hops = strtoul(argv[2], &end, 0); @@ -1127,51 +1128,52 @@ jt_ptl_add_route (int argc, char **argv) } } - LIBCFS_IOC_INIT(data); - data.ioc_net = g_net; - data.ioc_count = hops; - data.ioc_nid = gateway_nid; - data.ioc_priority = priority; + LIBCFS_IOC_INIT_V2(data, cfg_hdr); + data.cfg_net = g_net; + data.cfg_config_u.cfg_route.rtr_hop = hops; + data.cfg_nid = gateway_nid; + data.cfg_config_u.cfg_route.rtr_priority = priority; - rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data); - if (rc != 0) { - fprintf (stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n", strerror (errno)); - return (-1); - } + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data); + if (rc != 0) { + fprintf(stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n", + strerror(errno)); + return -1; + } - return (0); + return 0; } int jt_ptl_del_route (int argc, char **argv) { - struct libcfs_ioctl_data data; - lnet_nid_t nid; - int rc; + struct lnet_ioctl_config_data data; + lnet_nid_t nid; + int rc; - if (argc != 2) { - fprintf (stderr, "usage: %s gatewayNID\n", argv[0]); - return (0); - } + if (argc != 2) { + fprintf(stderr, "usage: %s gatewayNID\n", argv[0]); + return 0; + } - if (!libcfs_str2anynid(&nid, argv[1])) { - fprintf (stderr, "Can't parse gateway NID " - "\"%s\"\n", argv[1]); - return -1; - } + if (libcfs_str2anynid(&nid, argv[1]) == 0) { + fprintf(stderr, "Can't parse gateway NID " + "\"%s\"\n", argv[1]); + return -1; + } - LIBCFS_IOC_INIT(data); - data.ioc_net = g_net_set ? g_net : LNET_NIDNET(LNET_NID_ANY); - data.ioc_nid = nid; + LIBCFS_IOC_INIT_V2(data, cfg_hdr); + data.cfg_net = g_net_set ? g_net : LNET_NIDNET(LNET_NID_ANY); + data.cfg_nid = nid; - rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data); - if (rc != 0) { - fprintf (stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n", - libcfs_nid2str(nid), strerror (errno)); - return (-1); - } + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data); + if (rc != 0) { + fprintf(stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n", + libcfs_nid2str(nid), strerror(errno)); + return -1; + } - return (0); + return 0; } int @@ -1236,40 +1238,39 @@ jt_ptl_notify_router (int argc, char **argv) int jt_ptl_print_routes (int argc, char **argv) { - struct libcfs_ioctl_data data; - int rc; - int index; - __u32 net; - lnet_nid_t nid; - unsigned int hops; - int alive; + struct lnet_ioctl_config_data data; + int rc; + int index; + __u32 net; + lnet_nid_t nid; + unsigned int hops; + int alive; unsigned int pri; - for (index = 0;;index++) - { - LIBCFS_IOC_INIT(data); - data.ioc_count = index; + for (index = 0; ; index++) { + LIBCFS_IOC_INIT_V2(data, cfg_hdr); + data.cfg_count = index; - rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data); - if (rc != 0) - break; + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data); + if (rc != 0) + break; - net = data.ioc_net; - hops = data.ioc_count; - nid = data.ioc_nid; - alive = data.ioc_flags; - pri = data.ioc_priority; + net = data.cfg_net; + hops = data.cfg_config_u.cfg_route.rtr_hop; + nid = data.cfg_nid; + alive = data.cfg_config_u.cfg_route.rtr_flags; + pri = data.cfg_config_u.cfg_route.rtr_priority; printf("net %18s hops %u gw %32s %s pri %u\n", libcfs_net2str(net), hops, libcfs_nid2str(nid), alive ? "up" : "down", pri); - } + } - if (errno != ENOENT) - fprintf(stderr, "Error getting routes: %s: check dmesg.\n", - strerror(errno)); + if (errno != ENOENT) + fprintf(stderr, "Error getting routes: %s: check dmesg.\n", + strerror(errno)); - return (0); + return 0; } double