Whamcloud - gitweb
LU-10452 lnet: cleanup YAML output
[fs/lustre-release.git] / lnet / utils / lnetconfig / liblnetconfig.c
index 99ce6a8..dce0795 100644 (file)
@@ -18,7 +18,7 @@
  *
  * LGPL HEADER END
  *
- * Copyright (c) 2014, 2016, Intel Corporation.
+ * Copyright (c) 2014, 2017, Intel Corporation.
  *
  * Author:
  *   Amir Shehata <amir.shehata@intel.com>
@@ -51,7 +51,6 @@
 #include <fcntl.h>
 #include <ifaddrs.h>
 #include "liblnetconfig.h"
-#include "cyaml.h"
 
 #define CONFIG_CMD             "configure"
 #define UNCONFIG_CMD           "unconfigure"
 #define MANAGE_CMD              "manage"
 
 #define modparam_path "/sys/module/lnet/parameters/"
+#define gni_nid_path "/proc/cray_xt/"
+
+const char *gmsg_stat_names[] = {"sent_stats", "received_stats",
+                                "dropped_stats"};
 
 /*
  * lustre_lnet_ip_range_descr
@@ -237,6 +240,7 @@ int lustre_lnet_add_intf_descr(struct list_head *list, char *intf, int len)
 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr)
 {
        if (nw_descr != NULL) {
+               nw_descr->nw_id = 0;
                INIT_LIST_HEAD(&nw_descr->network_on_rule);
                INIT_LIST_HEAD(&nw_descr->nw_intflist);
        }
@@ -393,8 +397,7 @@ failed:
 
 int lustre_lnet_config_lib_init(void)
 {
-       return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
-                               LNET_DEV_MAJOR, LNET_DEV_MINOR);
+       return register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH);
 }
 
 void lustre_lnet_config_lib_uninit(void)
@@ -495,7 +498,7 @@ static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
        struct lnet_ioctl_ping_data ping;
        struct cYAML *root = NULL, *ping_node = NULL, *item = NULL,
                     *first_seq = NULL, *tmp = NULL, *peer_ni = NULL;
-       lnet_process_id_t id;
+       struct lnet_process_id id;
        char err_str[LNET_MAX_STR_LEN] = {0};
        char *sep, *token, *end;
        char buf[6];
@@ -504,7 +507,7 @@ static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call,
        int i;
        bool flag = false;
 
-       len = (sizeof(lnet_process_id_t) * LNET_INTERFACES_MAX_DEFAULT);
+       len = (sizeof(struct lnet_process_id) * LNET_INTERFACES_MAX_DEFAULT);
 
        data = calloc(1, len);
        if (data == NULL)
@@ -820,7 +823,7 @@ int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
        if (nw == NULL || gw == NULL) {
                snprintf(err_str,
                         sizeof(err_str),
-                        "\"missing mandatory parameter(s): '%s'\"",
+                        "\"missing mandatory parameter in route config:'%s'\"",
                         (nw == NULL && gw == NULL) ? "network, gateway" :
                         (nw == NULL) ? "network" : "gateway");
                rc = LUSTRE_CFG_RC_MISSING_PARAM;
@@ -903,7 +906,7 @@ int lustre_lnet_del_route(char *nw, char *gw,
        if (nw == NULL || gw == NULL) {
                snprintf(err_str,
                         sizeof(err_str),
-                        "\"missing mandatory parameter(s): '%s'\"",
+                        "\"missing mandatory parameter in route delete: '%s'\"",
                         (nw == NULL && gw == NULL) ? "network, gateway" :
                         (nw == NULL) ? "network" : "gateway");
                rc = LUSTRE_CFG_RC_MISSING_PARAM;
@@ -949,7 +952,7 @@ out:
 
 int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
                           int seq_no, struct cYAML **show_rc,
-                          struct cYAML **err_rc)
+                          struct cYAML **err_rc, bool backup)
 {
        struct lnet_ioctl_config_data data;
        lnet_nid_t gateway_nid;
@@ -1069,7 +1072,8 @@ int lustre_lnet_show_route(char *nw, char *gw, int hops, int prio, int detail,
                                                cfg_route.rtr_priority) == NULL)
                                goto out;
 
-                       if (cYAML_create_string(item, "state",
+                       if (!backup &&
+                           cYAML_create_string(item, "state",
                                                data.cfg_config_u.cfg_route.
                                                        rtr_flags ?
                                                "up" : "down") == NULL)
@@ -1144,51 +1148,102 @@ static int socket_intf_query(int request, char *intf,
        return rc;
 }
 
+static int lustre_lnet_queryip(struct lnet_dlc_intf_descr *intf, __u32 *ip)
+{
+       struct ifreq ifr;
+       int rc;
+
+       memset(&ifr, 0, sizeof(ifr));
+       rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
+       if (rc != 0)
+               return LUSTRE_CFG_RC_BAD_PARAM;
+
+       if ((ifr.ifr_flags & IFF_UP) == 0)
+               return LUSTRE_CFG_RC_BAD_PARAM;
+
+       memset(&ifr, 0, sizeof(ifr));
+       rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
+       if (rc != 0)
+               return LUSTRE_CFG_RC_BAD_PARAM;
+
+       *ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
+       *ip = bswap_32(*ip);
+
+       return LUSTRE_CFG_RC_NO_ERR;
+}
+
 /*
  * for each interface in the array of interfaces find the IP address of
  * that interface, create its nid and add it to an array of NIDs.
  * Stop if any of the interfaces is down
  */
 static int lustre_lnet_intf2nids(struct lnet_dlc_network_descr *nw,
-                                lnet_nid_t **nids, __u32 *nnids)
+                                lnet_nid_t **nids, __u32 *nnids,
+                                char *err_str, size_t str_len)
 {
        int i = 0, count = 0, rc;
-       struct ifreq ifr;
-       __u32 ip;
        struct lnet_dlc_intf_descr *intf;
+       char val[LNET_MAX_STR_LEN];
+       __u32 ip;
+       int gni_num;
 
-       if (nw == NULL || nids == NULL)
+
+       if (nw == NULL || nids == NULL) {
+               snprintf(err_str, str_len,
+                        "\"unexpected parameters to lustre_lnet_intf2nids()\"");
+               err_str[str_len - 1] = '\0';
                return LUSTRE_CFG_RC_BAD_PARAM;
+       }
 
-       list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
-               count++;
+       if (LNET_NETTYP(nw->nw_id) == GNILND) {
+               count = 1;
+       } else {
+               list_for_each_entry(intf, &nw->nw_intflist, intf_on_network)
+                       count++;
+       }
 
        *nids = calloc(count, sizeof(lnet_nid_t));
-       if (*nids == NULL)
+       if (*nids == NULL) {
+               snprintf(err_str, str_len,
+                        "\"out of memory\"");
+               err_str[str_len - 1] = '\0';
                return LUSTRE_CFG_RC_OUT_OF_MEM;
-
-       list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
-               memset(&ifr, 0, sizeof(ifr));
-               rc = socket_intf_query(SIOCGIFFLAGS, intf->intf_name, &ifr);
-               if (rc != 0)
-                       goto failed;
-
-               if ((ifr.ifr_flags & IFF_UP) == 0) {
-                       rc = LUSTRE_CFG_RC_BAD_PARAM;
+       }
+       /*
+        * special case the GNI interface since it doesn't have an IP
+        * address. The assumption is that there can only be one GNI
+        * interface in the system. No interface name is provided.
+        */
+       if (LNET_NETTYP(nw->nw_id) == GNILND) {
+               rc = read_sysfs_file(gni_nid_path, "nid", val,
+                               1, sizeof(val));
+               if (rc) {
+                       snprintf(err_str, str_len,
+                                "\"cannot read gni nid\"");
+                       err_str[str_len - 1] = '\0';
                        goto failed;
                }
+               gni_num = atoi(val);
 
-               memset(&ifr, 0, sizeof(ifr));
-               rc = socket_intf_query(SIOCGIFADDR, intf->intf_name, &ifr);
-               if (rc != 0)
-                       goto failed;
+               (*nids)[i] = LNET_MKNID(nw->nw_id, gni_num);
 
-               ip = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr;
-               ip = bswap_32(ip);
+               goto out;
+       }
+
+       /* look at the other interfaces */
+       list_for_each_entry(intf, &nw->nw_intflist, intf_on_network) {
+               rc = lustre_lnet_queryip(intf, &ip);
+               if (rc != LUSTRE_CFG_RC_NO_ERR) {
+                       snprintf(err_str, str_len,
+                                "\"couldn't query intf %s\"", intf->intf_name);
+                       err_str[str_len - 1] = '\0';
+                       goto failed;
+               }
                (*nids)[i] = LNET_MKNID(nw->nw_id, ip);
                i++;
        }
 
+out:
        *nnids = count;
 
        return 0;
@@ -1357,25 +1412,34 @@ int lustre_lnet_match_ip_to_intf(struct ifaddrs *ifa,
        return LUSTRE_CFG_RC_MATCH;
 }
 
-int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
-                                    lnet_nid_t **nids, __u32 *nnids)
+static int lustre_lnet_resolve_ip2nets_rule(struct lustre_lnet_ip2nets *ip2nets,
+                                           lnet_nid_t **nids, __u32 *nnids,
+                                           char *err_str, size_t str_len)
 {
        struct ifaddrs *ifa;
        int rc = LUSTRE_CFG_RC_NO_ERR;
 
        rc = getifaddrs(&ifa);
-       if (rc < 0)
+       if (rc < 0) {
+               snprintf(err_str, str_len,
+                        "\"failed to get interface addresses: %d\"", -errno);
+               err_str[str_len - 1] = '\0';
                return -errno;
+       }
 
        rc = lustre_lnet_match_ip_to_intf(ifa,
                                          &ip2nets->ip2nets_net.nw_intflist,
                                          &ip2nets->ip2nets_ip_ranges);
        if (rc != LUSTRE_CFG_RC_MATCH) {
+               snprintf(err_str, str_len,
+                        "\"couldn't match ip to existing interfaces\"");
+               err_str[str_len - 1] = '\0';
                freeifaddrs(ifa);
                return rc;
        }
 
-       rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids);
+       rc = lustre_lnet_intf2nids(&ip2nets->ip2nets_net, nids, nnids,
+                                  err_str, sizeof(err_str));
        if (rc != LUSTRE_CFG_RC_NO_ERR) {
                *nids = NULL;
                *nnids = 0;
@@ -1493,13 +1557,10 @@ lustre_lnet_config_ip2nets(struct lustre_lnet_ip2nets *ip2nets,
         * The memory is allocated in that function then freed here when
         * it's no longer needed.
         */
-       rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids);
-       if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH) {
-               snprintf(err_str,
-                        sizeof(err_str),
-                        "\"cannot resolve ip2nets rule\"");
+       rc = lustre_lnet_resolve_ip2nets_rule(ip2nets, &nids, &nnids, err_str,
+                                             sizeof(err_str));
+       if (rc != LUSTRE_CFG_RC_NO_ERR && rc != LUSTRE_CFG_RC_MATCH)
                goto out;
-       }
 
        if (list_empty(&ip2nets->ip2nets_net.nw_intflist)) {
                snprintf(err_str, sizeof(err_str),
@@ -1540,10 +1601,14 @@ int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
 
        snprintf(err_str, sizeof(err_str), "\"success\"");
 
-       if (ip2net == NULL && nw_descr == NULL) {
+       if (ip2net == NULL && (nw_descr == NULL || nw_descr->nw_id == 0 ||
+           (list_empty(&nw_descr->nw_intflist) &&
+            LNET_NETTYP(nw_descr->nw_id) != GNILND))) {
                snprintf(err_str,
                         sizeof(err_str),
-                        "\"mandatory parameters not specified.\"");
+                        "\"missing mandatory parameters in NI config: '%s'\"",
+                        (nw_descr == NULL) ? "network , interface" :
+                        (nw_descr->nw_id == 0) ? "network" : "interface");
                rc = LUSTRE_CFG_RC_MISSING_PARAM;
                goto out;
        }
@@ -1624,7 +1689,11 @@ int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
                goto out;
        }
 
-       if (list_empty(&nw_descr->nw_intflist)) {
+       /*
+        * special case the GNI since no interface name is expected
+        */
+       if (list_empty(&nw_descr->nw_intflist) &&
+           (LNET_NETTYP(nw_descr->nw_id) != GNILND)) {
                snprintf(err_str,
                        sizeof(err_str),
                        "\"no interface name provided\"");
@@ -1632,10 +1701,9 @@ int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
                goto out;
        }
 
-       rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids);
+       rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
+                                  err_str, sizeof(err_str));
        if (rc != 0) {
-               snprintf(err_str, sizeof(err_str),
-                        "\"bad parameter\"");
                rc = LUSTRE_CFG_RC_BAD_PARAM;
                goto out;
        }
@@ -1677,10 +1745,12 @@ int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
 
        snprintf(err_str, sizeof(err_str), "\"success\"");
 
-       if (nw_descr == NULL) {
+       if (nw_descr == NULL || nw_descr->nw_id == 0) {
                snprintf(err_str,
                         sizeof(err_str),
-                        "\"missing mandatory parameter\"");
+                        "\"missing mandatory parameter in deleting NI: '%s'\"",
+                        (nw_descr == NULL) ? "network , interface" :
+                        (nw_descr->nw_id == 0) ? "network" : "interface");
                rc = LUSTRE_CFG_RC_MISSING_PARAM;
                goto out;
        }
@@ -1697,10 +1767,9 @@ int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw_descr,
                goto out;
        }
 
-       rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids);
+       rc = lustre_lnet_intf2nids(nw_descr, &nids, &nnids,
+                                  err_str, sizeof(err_str));
        if (rc != 0) {
-               snprintf(err_str, sizeof(err_str),
-                        "\"bad parameter\"");
                rc = LUSTRE_CFG_RC_BAD_PARAM;
                goto out;
        }
@@ -1748,13 +1817,56 @@ out:
        return rc;
 }
 
+static bool
+add_msg_stats_to_yaml_blk(struct cYAML *yaml,
+                         struct lnet_ioctl_comm_count *counts)
+{
+       if (cYAML_create_number(yaml, "put",
+                               counts->ico_put_count)
+                                       == NULL)
+               return false;
+       if (cYAML_create_number(yaml, "get",
+                               counts->ico_get_count)
+                                       == NULL)
+               return false;
+       if (cYAML_create_number(yaml, "reply",
+                               counts->ico_reply_count)
+                                       == NULL)
+               return false;
+       if (cYAML_create_number(yaml, "ack",
+                               counts->ico_ack_count)
+                                       == NULL)
+               return false;
+       if (cYAML_create_number(yaml, "hello",
+                               counts->ico_hello_count)
+                                       == NULL)
+               return false;
+
+       return true;
+}
+
+static struct lnet_ioctl_comm_count *
+get_counts(struct lnet_ioctl_element_msg_stats *msg_stats, int idx)
+{
+       if (idx == 0)
+               return &msg_stats->im_send_stats;
+       if (idx == 1)
+               return &msg_stats->im_recv_stats;
+       if (idx == 2)
+               return &msg_stats->im_drop_stats;
+
+       return NULL;
+}
+
 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
-                        struct cYAML **show_rc, struct cYAML **err_rc)
+                        struct cYAML **show_rc, struct cYAML **err_rc,
+                        bool backup)
 {
        char *buf;
        struct lnet_ioctl_config_ni *ni_data;
        struct lnet_ioctl_config_lnd_tunables *lnd;
        struct lnet_ioctl_element_stats *stats;
+       struct lnet_ioctl_element_msg_stats msg_stats;
        __u32 net = LNET_NIDNET(LNET_NID_ANY);
        __u32 prev_net = LNET_NIDNET(LNET_NID_ANY);
        int rc = LUSTRE_CFG_RC_OUT_OF_MEM, i, j;
@@ -1825,6 +1937,10 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                    net != rc_net)
                        continue;
 
+               /* if we're backing up don't store lo */
+               if (backup && LNET_NETTYP(rc_net) == LOLND)
+                       continue;
+
                /* default rc to -1 in case we hit the goto */
                rc = -1;
                exist = true;
@@ -1858,11 +1974,13 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                if (first_seq == NULL)
                        first_seq = item;
 
-               if (cYAML_create_string(item, "nid",
+               if (!backup &&
+                   cYAML_create_string(item, "nid",
                                        libcfs_nid2str(ni_data->lic_nid)) == NULL)
                        goto out;
 
-               if (cYAML_create_string(item,
+               if (!backup &&
+                   cYAML_create_string(item,
                                        "status",
                                        (ni_data->lic_status ==
                                          LNET_NI_STATUS_UP) ?
@@ -1891,6 +2009,10 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
 
                if (detail) {
                        char *limit;
+                       int k;
+
+                       if (backup)
+                               goto continue_without_msg_stats;
 
                        statistics = cYAML_create_object(item, "statistics");
                        if (statistics == NULL)
@@ -1911,6 +2033,40 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                                                        == NULL)
                                goto out;
 
+                       if (detail < 2)
+                               goto continue_without_msg_stats;
+
+                       LIBCFS_IOC_INIT_V2(msg_stats, im_hdr);
+                       msg_stats.im_hdr.ioc_len = sizeof(msg_stats);
+                       msg_stats.im_idx = i;
+
+                       rc = l_ioctl(LNET_DEV_ID,
+                                    IOC_LIBCFS_GET_LOCAL_NI_MSG_STATS,
+                                    &msg_stats);
+                       if (rc != 0) {
+                               l_errno = errno;
+                               goto continue_without_msg_stats;
+                       }
+
+                       for (k = 0; k < 3; k++) {
+                               struct lnet_ioctl_comm_count *counts;
+                               struct cYAML *msg_statistics = NULL;
+
+                               msg_statistics = cYAML_create_object(item,
+                                                (char *)gmsg_stat_names[k]);
+                               if (msg_statistics == NULL)
+                                       goto out;
+
+                               counts = get_counts(&msg_stats, k);
+                               if (counts == NULL)
+                                       goto out;
+
+                               if (!add_msg_stats_to_yaml_blk(msg_statistics,
+                                                              counts))
+                                       goto out;
+                       }
+
+continue_without_msg_stats:
                        tunables = cYAML_create_object(item, "tunables");
                        if (!tunables)
                                goto out;
@@ -1919,24 +2075,30 @@ int lustre_lnet_show_net(char *nw, int detail, int seq_no,
                        if (rc != LUSTRE_CFG_RC_NO_ERR)
                                goto out;
 
-                       tunables = cYAML_create_object(item, "lnd tunables");
-                       if (tunables == NULL)
-                               goto out;
-
                        rc = lustre_ni_show_tunables(tunables, LNET_NETTYP(rc_net),
                                                     &lnd->lt_tun);
-                       if (rc != LUSTRE_CFG_RC_NO_ERR)
+                       if (rc != LUSTRE_CFG_RC_NO_ERR &&
+                           rc != LUSTRE_CFG_RC_NO_MATCH)
                                goto out;
 
-                       if (cYAML_create_number(item, "tcp bonding",
-                                               ni_data->lic_tcp_bonding)
-                                                       == NULL)
-                               goto out;
+                       if (rc != LUSTRE_CFG_RC_NO_MATCH) {
+                               tunables = cYAML_create_object(item,
+                                                              "lnd tunables");
+                               if (tunables == NULL)
+                                       goto out;
+                       }
 
-                       if (cYAML_create_number(item, "dev cpt",
+                       if (!backup &&
+                           cYAML_create_number(item, "dev cpt",
                                                ni_data->lic_dev_cpt) == NULL)
                                goto out;
 
+                       if (!backup &&
+                           cYAML_create_number(item, "tcp bonding",
+                                               ni_data->lic_tcp_bonding)
+                                                       == NULL)
+                               goto out;
+
                        /* out put the CPTs in the format: "[x,x,x,...]" */
                        limit = str_buf + str_buf_len - 3;
                        pos += snprintf(pos, limit - pos, "\"[");
@@ -2146,7 +2308,7 @@ out:
 }
 
 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
-                            struct cYAML **err_rc)
+                            struct cYAML **err_rc, bool backup)
 {
        struct lnet_ioctl_config_data *data;
        struct lnet_ioctl_pool_cfg *pool_cfg = NULL;
@@ -2175,7 +2337,10 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
        if (root == NULL)
                goto out;
 
-       pools_node = cYAML_create_seq(root, "routing");
+       if (backup)
+               pools_node = cYAML_create_object(root, "routing");
+       else
+               pools_node = cYAML_create_seq(root, "routing");
        if (pools_node == NULL)
                goto out;
 
@@ -2195,6 +2360,9 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
 
                pool_cfg = (struct lnet_ioctl_pool_cfg *)data->cfg_bulk;
 
+               if (backup)
+                       goto calculate_buffers;
+
                snprintf(node_name, sizeof(node_name), "cpt[%d]", i);
                item = cYAML_create_seq_item(pools_node);
                if (item == NULL)
@@ -2207,24 +2375,31 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
                if (cpt == NULL)
                        goto out;
 
+calculate_buffers:
                /* create the tree  and print */
                for (j = 0; j < LNET_NRBPOOLS; j++) {
-                       type_node = cYAML_create_object(cpt, pools[j]);
-                       if (type_node == NULL)
-                               goto out;
-                       if (cYAML_create_number(type_node, "npages",
+                       if (!backup) {
+                               type_node = cYAML_create_object(cpt, pools[j]);
+                               if (type_node == NULL)
+                                       goto out;
+                       }
+                       if (!backup &&
+                           cYAML_create_number(type_node, "npages",
                                                pool_cfg->pl_pools[j].pl_npages)
                            == NULL)
                                goto out;
-                       if (cYAML_create_number(type_node, "nbuffers",
+                       if (!backup &&
+                           cYAML_create_number(type_node, "nbuffers",
                                                pool_cfg->pl_pools[j].
                                                  pl_nbuffers) == NULL)
                                goto out;
-                       if (cYAML_create_number(type_node, "credits",
+                       if (!backup &&
+                           cYAML_create_number(type_node, "credits",
                                                pool_cfg->pl_pools[j].
                                                   pl_credits) == NULL)
                                goto out;
-                       if (cYAML_create_number(type_node, "mincredits",
+                       if (!backup &&
+                           cYAML_create_number(type_node, "mincredits",
                                                pool_cfg->pl_pools[j].
                                                   pl_mincredits) == NULL)
                                goto out;
@@ -2235,6 +2410,15 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
        }
 
        if (pool_cfg != NULL) {
+               if (backup) {
+                       if (cYAML_create_number(pools_node, "enable",
+                                               pool_cfg->pl_routing) ==
+                       NULL)
+                               goto out;
+
+                       goto add_buffer_section;
+               }
+
                item = cYAML_create_seq_item(pools_node);
                if (item == NULL)
                        goto out;
@@ -2244,6 +2428,7 @@ int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
                        goto out;
        }
 
+add_buffer_section:
        /* create a buffers entry in the show. This is necessary so that
         * if the YAML output is used to configure a node, the buffer
         * configuration takes hold */
@@ -2299,7 +2484,8 @@ out:
 }
 
 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
-                         struct cYAML **show_rc, struct cYAML **err_rc)
+                         struct cYAML **show_rc, struct cYAML **err_rc,
+                         bool backup)
 {
        /*
         * TODO: This function is changing in a future patch to accommodate
@@ -2308,17 +2494,18 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
        struct lnet_ioctl_peer_cfg peer_info;
        struct lnet_peer_ni_credit_info *lpni_cri;
        struct lnet_ioctl_element_stats *lpni_stats;
+       struct lnet_ioctl_element_msg_stats *msg_stats;
        lnet_nid_t *nidp;
        int rc = LUSTRE_CFG_RC_OUT_OF_MEM;
-       int i;
-       int j;
+       int i, j, k;
        int l_errno = 0;
        __u32 count;
        __u32 size;
        struct cYAML *root = NULL, *peer = NULL, *peer_ni = NULL,
-                    *first_seq = NULL, *peer_root = NULL, *tmp = NULL;
+                    *first_seq = NULL, *peer_root = NULL, *tmp = NULL,
+                    *msg_statistics = NULL, *statistics = NULL;
        char err_str[LNET_MAX_STR_LEN];
-       lnet_process_id_t *list = NULL;
+       struct lnet_process_id *list = NULL;
        void *data = NULL;
        void *lpni_data;
 
@@ -2335,7 +2522,7 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
                goto out;
 
        count = 1000;
-       size = count * sizeof(lnet_process_id_t);
+       size = count * sizeof(struct lnet_process_id);
        list = malloc(size);
        if (list == NULL) {
                l_errno = ENOMEM;
@@ -2431,6 +2618,17 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
                                        peer_info.prcfg_mr ? "True" : "False")
                    == NULL)
                        goto out;
+               /*
+                * print out the state of the peer only if details are
+                * requested
+                */
+               if (detail >= 3) {
+                       if (!backup &&
+                           cYAML_create_number(peer, "peer state",
+                                               peer_info.prcfg_state)
+                               == NULL)
+                               goto out;
+               }
 
                tmp = cYAML_create_seq(peer, "peer ni");
                if (tmp == NULL)
@@ -2441,7 +2639,8 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
                        nidp = lpni_data;
                        lpni_cri = (void*)nidp + sizeof(nidp);
                        lpni_stats = (void *)lpni_cri + sizeof(*lpni_cri);
-                       lpni_data = (void *)lpni_stats + sizeof(*lpni_stats);
+                       msg_stats = (void *)lpni_stats + sizeof(*lpni_stats);
+                       lpni_data = (void *)msg_stats + sizeof(*msg_stats);
 
                        peer_ni = cYAML_create_seq_item(tmp);
                        if (peer_ni == NULL)
@@ -2452,6 +2651,9 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
                            == NULL)
                                goto out;
 
+                       if (backup)
+                               continue;
+
                        if (cYAML_create_string(peer_ni, "state",
                                                lpni_cri->cr_aliveness)
                            == NULL)
@@ -2490,24 +2692,49 @@ int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
                            == NULL)
                                goto out;
 
-                       if (cYAML_create_number(peer_ni, "send_count",
+                       if (cYAML_create_number(peer_ni, "refcount",
+                                               lpni_cri->cr_refcount) == NULL)
+                               goto out;
+
+                       statistics = cYAML_create_object(peer_ni, "statistics");
+                       if (statistics == NULL)
+                               goto out;
+
+                       if (cYAML_create_number(statistics, "send_count",
                                                lpni_stats->iel_send_count)
                            == NULL)
                                goto out;
 
-                       if (cYAML_create_number(peer_ni, "recv_count",
+                       if (cYAML_create_number(statistics, "recv_count",
                                                lpni_stats->iel_recv_count)
                            == NULL)
                                goto out;
 
-                       if (cYAML_create_number(peer_ni, "drop_count",
+                       if (cYAML_create_number(statistics, "drop_count",
                                                lpni_stats->iel_drop_count)
                            == NULL)
                                goto out;
 
-                       if (cYAML_create_number(peer_ni, "refcount",
-                                               lpni_cri->cr_refcount) == NULL)
-                               goto out;
+                       if (detail < 2)
+                               continue;
+
+                       for (k = 0; k < 3; k++) {
+                               struct lnet_ioctl_comm_count *counts;
+
+                               msg_statistics = cYAML_create_object(peer_ni,
+                                                (char *) gmsg_stat_names[k]);
+                               if (msg_statistics == NULL)
+                                       goto out;
+
+                               counts = get_counts(msg_stats, k);
+                               if (counts == NULL)
+                                       goto out;
+
+                               if (!add_msg_stats_to_yaml_blk(msg_statistics,
+                                                              counts))
+                                       goto out;
+                       }
+
                }
        }
 
@@ -2562,7 +2789,7 @@ int lustre_lnet_list_peer(int seq_no,
        int l_errno = 0;
        struct cYAML *root = NULL, *list_root = NULL, *first_seq = NULL;
        char err_str[LNET_MAX_STR_LEN];
-       lnet_process_id_t *list = NULL;
+       struct lnet_process_id *list = NULL;
 
        snprintf(err_str, sizeof(err_str),
                 "\"out of memory\"");
@@ -2579,7 +2806,7 @@ int lustre_lnet_list_peer(int seq_no,
                goto out;
 
        count = 1000;
-       size = count * sizeof(lnet_process_id_t);
+       size = count * sizeof(struct lnet_process_id);
        list = malloc(size);
        if (list == NULL) {
                l_errno = ENOMEM;
@@ -3513,8 +3740,7 @@ static int handle_yaml_show_route(struct cYAML *tree, struct cYAML **show_rc,
                                      (prio) ? prio->cy_valueint : -1,
                                      (detail) ? detail->cy_valueint : 0,
                                      (seq_no) ? seq_no->cy_valueint : -1,
-                                     show_rc,
-                                     err_rc);
+                                     show_rc, err_rc, false);
 }
 
 static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
@@ -3529,8 +3755,7 @@ static int handle_yaml_show_net(struct cYAML *tree, struct cYAML **show_rc,
        return lustre_lnet_show_net((net) ? net->cy_valuestring : NULL,
                                    (detail) ? detail->cy_valueint : 0,
                                    (seq_no) ? seq_no->cy_valueint : -1,
-                                   show_rc,
-                                   err_rc);
+                                   show_rc, err_rc, false);
 }
 
 static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
@@ -3541,7 +3766,7 @@ static int handle_yaml_show_routing(struct cYAML *tree, struct cYAML **show_rc,
        seq_no = cYAML_get_object_item(tree, "seq_no");
 
        return lustre_lnet_show_routing((seq_no) ? seq_no->cy_valueint : -1,
-                                       show_rc, err_rc);
+                                       show_rc, err_rc, false);
 }
 
 static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
@@ -3556,7 +3781,7 @@ static int handle_yaml_show_peers(struct cYAML *tree, struct cYAML **show_rc,
        return lustre_lnet_show_peer((nid) ? nid->cy_valuestring : NULL,
                                     (detail) ? detail->cy_valueint : 0,
                                     (seq_no) ? seq_no->cy_valueint : -1,
-                                    show_rc, err_rc);
+                                    show_rc, err_rc, false);
 }
 
 static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
@@ -3570,6 +3795,41 @@ static int handle_yaml_show_stats(struct cYAML *tree, struct cYAML **show_rc,
                                      show_rc, err_rc);
 }
 
+static int handle_yaml_config_numa(struct cYAML *tree, struct cYAML **show_rc,
+                                 struct cYAML **err_rc)
+{
+       struct cYAML *seq_no, *range;
+
+       seq_no = cYAML_get_object_item(tree, "seq_no");
+       range = cYAML_get_object_item(tree, "range");
+
+       return lustre_lnet_config_numa_range(range ? range->cy_valueint : -1,
+                                            seq_no ? seq_no->cy_valueint : -1,
+                                            err_rc);
+}
+
+static int handle_yaml_del_numa(struct cYAML *tree, struct cYAML **show_rc,
+                              struct cYAML **err_rc)
+{
+       struct cYAML *seq_no;
+
+       seq_no = cYAML_get_object_item(tree, "seq_no");
+
+       return lustre_lnet_config_numa_range(0, seq_no ? seq_no->cy_valueint : -1,
+                                            err_rc);
+}
+
+static int handle_yaml_show_numa(struct cYAML *tree, struct cYAML **show_rc,
+                               struct cYAML **err_rc)
+{
+       struct cYAML *seq_no;
+
+       seq_no = cYAML_get_object_item(tree, "seq_no");
+
+       return lustre_lnet_show_numa_range(seq_no ? seq_no->cy_valueint : -1,
+                                          show_rc, err_rc);
+}
+
 static int handle_yaml_config_global_settings(struct cYAML *tree,
                                              struct cYAML **show_rc,
                                              struct cYAML **err_rc)
@@ -3713,6 +3973,7 @@ static struct lookup_cmd_hdlr_tbl lookup_config_tbl[] = {
        { .name = "buffers",    .cb = handle_yaml_config_buffers },
        { .name = "statistics", .cb = handle_yaml_no_op },
        { .name = "global",     .cb = handle_yaml_config_global_settings},
+       { .name = "numa",       .cb = handle_yaml_config_numa },
        { .name = "ping",       .cb = handle_yaml_no_op },
        { .name = "discover",   .cb = handle_yaml_no_op },
        { .name = NULL } };
@@ -3726,6 +3987,7 @@ static struct lookup_cmd_hdlr_tbl lookup_del_tbl[] = {
        { .name = "buffers",    .cb = handle_yaml_no_op },
        { .name = "statistics", .cb = handle_yaml_no_op },
        { .name = "global",     .cb = handle_yaml_del_global_settings},
+       { .name = "numa",       .cb = handle_yaml_del_numa },
        { .name = "ping",       .cb = handle_yaml_no_op },
        { .name = "discover",   .cb = handle_yaml_no_op },
        { .name = NULL } };
@@ -3739,6 +4001,7 @@ static struct lookup_cmd_hdlr_tbl lookup_show_tbl[] = {
        { .name = "buffers",    .cb = handle_yaml_show_routing },
        { .name = "statistics", .cb = handle_yaml_show_stats },
        { .name = "global",     .cb = handle_yaml_show_global_settings},
+       { .name = "numa",       .cb = handle_yaml_show_numa },
        { .name = "ping",       .cb = handle_yaml_no_op },
        { .name = "discover",   .cb = handle_yaml_no_op },
        { .name = NULL } };
@@ -3752,6 +4015,7 @@ static struct lookup_cmd_hdlr_tbl lookup_exec_tbl[] = {
        { .name = "buffers",    .cb = handle_yaml_no_op },
        { .name = "statistics", .cb = handle_yaml_no_op },
        { .name = "global",     .cb = handle_yaml_no_op },
+       { .name = "numa",       .cb = handle_yaml_no_op },
        { .name = "ping",       .cb = handle_yaml_ping },
        { .name = "discover",   .cb = handle_yaml_discover },
        { .name = NULL } };