Print this page
10052 "dladm show-ether" should pick one kstat snapshot and stick with it
Reviewed by: Rob Johnston <rob.johnston@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gergo Doma <domag02@gmail.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>

*** 21,30 **** --- 21,34 ---- /* * Copyright 2010 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + /* + * Copyright 2019 OmniOS Community Edition (OmniOSce) Association. + */ + #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <strings.h> #include <err.h>
*** 167,177 **** dladm_status_t dladm_get_single_mac_stat(dladm_handle_t handle, datalink_id_t linkid, const char *name, uint8_t type, void *val) { - kstat_ctl_t *kcp; char module[DLPI_LINKNAME_MAX]; uint_t instance; char link[DLPI_LINKNAME_MAX]; dladm_status_t status; uint32_t flags, media; --- 171,180 ----
*** 193,226 **** status = dladm_parselink(dpap.dp_dev, module, &instance); if (status != DLADM_STATUS_OK) return (status); - if ((kcp = kstat_open()) == NULL) { - warn("kstat_open operation failed"); - return (-1); - } - /* * The kstat query could fail if the underlying MAC * driver was already detached. */ ! if ((ksp = kstat_lookup(kcp, module, instance, "mac")) == NULL && ! (ksp = kstat_lookup(kcp, module, instance, NULL)) == NULL) goto bail; ! if (kstat_read(kcp, ksp, NULL) == -1) goto bail; if (dladm_kstat_value(ksp, name, type, val) < 0) goto bail; - (void) kstat_close(kcp); return (DLADM_STATUS_OK); bail: - (void) kstat_close(kcp); return (dladm_errno2status(errno)); } /* Compute sum of 2 pktsums (s1 = s2 + s3) */ void --- 196,229 ---- status = dladm_parselink(dpap.dp_dev, module, &instance); if (status != DLADM_STATUS_OK) return (status); /* * The kstat query could fail if the underlying MAC * driver was already detached. */ ! if (dladm_dld_kcp(handle) == NULL) { ! warn("kstat_open operation failed"); ! return (-1); ! } ! ! if ((ksp = kstat_lookup(dladm_dld_kcp(handle), module, instance, ! "mac")) == NULL && ! (ksp = kstat_lookup(dladm_dld_kcp(handle), module, instance, ! NULL)) == NULL) goto bail; ! if (kstat_read(dladm_dld_kcp(handle), ksp, NULL) == -1) goto bail; if (dladm_kstat_value(ksp, name, type, val) < 0) goto bail; return (DLADM_STATUS_OK); bail: return (dladm_errno2status(errno)); } /* Compute sum of 2 pktsums (s1 = s2 + s3) */ void
*** 716,754 **** } } /* Support for legacy drivers */ void ! i_query_legacy_stats(const char *linkname, pktsum_t *stats) { - kstat_ctl_t *kcp; kstat_t *ksp; bzero(stats, sizeof (*stats)); ! if ((kcp = kstat_open()) == NULL) return; ! ksp = dladm_kstat_lookup(kcp, "link", 0, linkname, NULL); if (ksp != NULL) ! dladm_get_stats(kcp, ksp, stats); ! ! (void) kstat_close(kcp); } void * ! i_dlstat_legacy_rx_lane_stats(const char *linkname) { dladm_stat_chain_t *head = NULL; pktsum_t stats; rx_lane_stat_entry_t *rx_lane_stat_entry; bzero(&stats, sizeof (pktsum_t)); /* Query for dls stats */ ! i_query_legacy_stats(linkname, &stats); /* Convert to desired data type */ rx_lane_stat_entry = calloc(1, sizeof (rx_lane_stat_entry_t)); if (rx_lane_stat_entry == NULL) goto done; --- 719,754 ---- } } /* Support for legacy drivers */ void ! i_query_legacy_stats(dladm_handle_t dh, const char *linkname, pktsum_t *stats) { kstat_t *ksp; bzero(stats, sizeof (*stats)); ! if (dladm_dld_kcp(dh) == NULL) return; ! ksp = dladm_kstat_lookup(dladm_dld_kcp(dh), "link", 0, linkname, NULL); if (ksp != NULL) ! dladm_get_stats(dladm_dld_kcp(dh), ksp, stats); } void * ! i_dlstat_legacy_rx_lane_stats(dladm_handle_t dh, const char *linkname) { dladm_stat_chain_t *head = NULL; pktsum_t stats; rx_lane_stat_entry_t *rx_lane_stat_entry; bzero(&stats, sizeof (pktsum_t)); /* Query for dls stats */ ! i_query_legacy_stats(dh, linkname, &stats); /* Convert to desired data type */ rx_lane_stat_entry = calloc(1, sizeof (rx_lane_stat_entry_t)); if (rx_lane_stat_entry == NULL) goto done;
*** 772,791 **** done: return (head); } void * ! i_dlstat_legacy_tx_lane_stats(const char *linkname) { dladm_stat_chain_t *head = NULL; pktsum_t stats; tx_lane_stat_entry_t *tx_lane_stat_entry; bzero(&stats, sizeof (pktsum_t)); /* Query for dls stats */ ! i_query_legacy_stats(linkname, &stats); /* Convert to desired data type */ tx_lane_stat_entry = calloc(1, sizeof (tx_lane_stat_entry_t)); if (tx_lane_stat_entry == NULL) goto done; --- 772,791 ---- done: return (head); } void * ! i_dlstat_legacy_tx_lane_stats(dladm_handle_t dh, const char *linkname) { dladm_stat_chain_t *head = NULL; pktsum_t stats; tx_lane_stat_entry_t *tx_lane_stat_entry; bzero(&stats, sizeof (pktsum_t)); /* Query for dls stats */ ! i_query_legacy_stats(dh, linkname, &stats); /* Convert to desired data type */ tx_lane_stat_entry = calloc(1, sizeof (tx_lane_stat_entry_t)); if (tx_lane_stat_entry == NULL) goto done;
*** 890,913 **** { DLSTAT_FANOUT_IDLIST, DLSTAT_MAC_FANOUT, i_dlstat_fanout_search} }; static void ! i_dlstat_get_idlist(const char *modname, dlstat_idlist_type_t idlist_type, uint_t idlist[], uint_t *size) { ! kstat_ctl_t *kcp; kstat_t *ksp; char *prefix; int prefixlen; boolean_t (*fptr_searchkstat)(kstat_t *); *size = 0; ! if ((kcp = kstat_open()) == NULL) { warn("kstat_open operation failed"); ! goto done; } prefix = dladm_extract_idlist[idlist_type].di_prefix; fptr_searchkstat = dladm_extract_idlist[idlist_type].di_searchkstat; prefixlen = strlen(prefix); --- 890,914 ---- { DLSTAT_FANOUT_IDLIST, DLSTAT_MAC_FANOUT, i_dlstat_fanout_search} }; static void ! i_dlstat_get_idlist(dladm_handle_t handle, const char *modname, ! dlstat_idlist_type_t idlist_type, uint_t idlist[], uint_t *size) { ! kstat_ctl_t *kcp = dladm_dld_kcp(handle); kstat_t *ksp; char *prefix; int prefixlen; boolean_t (*fptr_searchkstat)(kstat_t *); *size = 0; ! if (kcp == NULL) { warn("kstat_open operation failed"); ! return; } prefix = dladm_extract_idlist[idlist_type].di_prefix; fptr_searchkstat = dladm_extract_idlist[idlist_type].di_searchkstat; prefixlen = strlen(prefix);
*** 916,943 **** fptr_searchkstat(ksp)) { idlist[(*size)++] = atoi(&ksp->ks_name[prefixlen]); } } dladm_sort_index_list(idlist, *size); - - done: - (void) kstat_close(kcp); } static dladm_stat_chain_t * ! i_dlstat_query_stats(const char *modname, const char *prefix, ! uint_t idlist[], uint_t idlist_size, void * (*fn)(kstat_ctl_t *, kstat_t *, int)) { - kstat_ctl_t *kcp; kstat_t *ksp; char statname[MAXLINKNAMELEN]; int i = 0; dladm_stat_chain_t *head = NULL, *prev = NULL; dladm_stat_chain_t *curr; ! if ((kcp = kstat_open()) == NULL) { warn("kstat_open operation failed"); return (NULL); } for (i = 0; i < idlist_size; i++) { --- 917,940 ---- fptr_searchkstat(ksp)) { idlist[(*size)++] = atoi(&ksp->ks_name[prefixlen]); } } dladm_sort_index_list(idlist, *size); } static dladm_stat_chain_t * ! i_dlstat_query_stats(dladm_handle_t handle, const char *modname, ! const char *prefix, uint_t idlist[], uint_t idlist_size, void * (*fn)(kstat_ctl_t *, kstat_t *, int)) { kstat_t *ksp; char statname[MAXLINKNAMELEN]; int i = 0; dladm_stat_chain_t *head = NULL, *prev = NULL; dladm_stat_chain_t *curr; ! if (dladm_dld_kcp(handle) == NULL) { warn("kstat_open operation failed"); return (NULL); } for (i = 0; i < idlist_size; i++) {
*** 944,962 **** uint_t index = idlist[i]; (void) snprintf(statname, sizeof (statname), "%s%d", prefix, index); ! ksp = dladm_kstat_lookup(kcp, modname, 0, statname, NULL); if (ksp == NULL) continue; curr = malloc(sizeof (dladm_stat_chain_t)); if (curr == NULL) break; ! curr->dc_statentry = fn(kcp, ksp, index); if (curr->dc_statentry == NULL) { free(curr); break; } --- 941,960 ---- uint_t index = idlist[i]; (void) snprintf(statname, sizeof (statname), "%s%d", prefix, index); ! ksp = dladm_kstat_lookup(dladm_dld_kcp(handle), modname, 0, ! statname, NULL); if (ksp == NULL) continue; curr = malloc(sizeof (dladm_stat_chain_t)); if (curr == NULL) break; ! curr->dc_statentry = fn(dladm_dld_kcp(handle), ksp, index); if (curr->dc_statentry == NULL) { free(curr); break; }
*** 970,1005 **** prev->dc_next = curr; prev = curr; } done: - (void) kstat_close(kcp); return (head); } static misc_stat_entry_t * ! i_dlstat_misc_stats(const char *linkname) { - kstat_ctl_t *kcp; kstat_t *ksp; misc_stat_entry_t *misc_stat_entry = NULL; ! if ((kcp = kstat_open()) == NULL) return (NULL); ! ksp = dladm_kstat_lookup(kcp, linkname, 0, DLSTAT_MAC_MISC_STAT, NULL); if (ksp == NULL) goto done; misc_stat_entry = calloc(1, sizeof (misc_stat_entry_t)); if (misc_stat_entry == NULL) goto done; ! i_dlstat_get_stats(kcp, ksp, &misc_stat_entry->mse_stats, misc_stats_list, MISC_STAT_SIZE); done: - (void) kstat_close(kcp); return (misc_stat_entry); } /* Rx lane statistic specific functions */ static boolean_t --- 968,1002 ---- prev->dc_next = curr; prev = curr; } done: return (head); } static misc_stat_entry_t * ! i_dlstat_misc_stats(dladm_handle_t handle, const char *linkname) { kstat_t *ksp; misc_stat_entry_t *misc_stat_entry = NULL; ! if (dladm_dld_kcp(handle) == NULL) return (NULL); ! ksp = dladm_kstat_lookup(dladm_dld_kcp(handle), linkname, 0, ! DLSTAT_MAC_MISC_STAT, NULL); if (ksp == NULL) goto done; misc_stat_entry = calloc(1, sizeof (misc_stat_entry_t)); if (misc_stat_entry == NULL) goto done; ! i_dlstat_get_stats(dladm_dld_kcp(handle), ksp, ! &misc_stat_entry->mse_stats, misc_stats_list, MISC_STAT_SIZE); done: return (misc_stat_entry); } /* Rx lane statistic specific functions */ static boolean_t
*** 1106,1120 **** free(rx_lane_stat_entry); return (local_stat_entry); } static dladm_stat_chain_t * ! i_dlstat_rx_local_stats(const char *linkname) { dladm_stat_chain_t *local_stats = NULL; ! local_stats = i_dlstat_query_stats(linkname, DLSTAT_MAC_RX_SWLANE, default_idlist, default_idlist_size, i_dlstat_rx_local_retrieve_stat); if (local_stats != NULL) { (void) strlcpy(local_stats->dc_statheader, "mac_rx_local", --- 1103,1118 ---- free(rx_lane_stat_entry); return (local_stat_entry); } static dladm_stat_chain_t * ! i_dlstat_rx_local_stats(dladm_handle_t handle, const char *linkname) { dladm_stat_chain_t *local_stats = NULL; ! local_stats = i_dlstat_query_stats(handle, linkname, ! DLSTAT_MAC_RX_SWLANE, default_idlist, default_idlist_size, i_dlstat_rx_local_retrieve_stat); if (local_stats != NULL) { (void) strlcpy(local_stats->dc_statheader, "mac_rx_local",
*** 1122,1138 **** } return (local_stats); } static dladm_stat_chain_t * ! i_dlstat_rx_bcast_stats(const char *linkname) { misc_stat_entry_t *misc_stat_entry; dladm_stat_chain_t *head = NULL; rx_lane_stat_entry_t *rx_lane_stat_entry; ! misc_stat_entry = i_dlstat_misc_stats(linkname); if (misc_stat_entry == NULL) goto done; rx_lane_stat_entry = calloc(1, sizeof (rx_lane_stat_entry_t)); if (rx_lane_stat_entry == NULL) --- 1120,1136 ---- } return (local_stats); } static dladm_stat_chain_t * ! i_dlstat_rx_bcast_stats(dladm_handle_t handle, const char *linkname) { misc_stat_entry_t *misc_stat_entry; dladm_stat_chain_t *head = NULL; rx_lane_stat_entry_t *rx_lane_stat_entry; ! misc_stat_entry = i_dlstat_misc_stats(handle, linkname); if (misc_stat_entry == NULL) goto done; rx_lane_stat_entry = calloc(1, sizeof (rx_lane_stat_entry_t)); if (rx_lane_stat_entry == NULL)
*** 1164,1180 **** done: return (head); } static dladm_stat_chain_t * ! i_dlstat_rx_defunctlane_stats(const char *linkname) { misc_stat_entry_t *misc_stat_entry; dladm_stat_chain_t *head = NULL; rx_lane_stat_entry_t *rx_lane_stat_entry; ! misc_stat_entry = i_dlstat_misc_stats(linkname); if (misc_stat_entry == NULL) goto done; rx_lane_stat_entry = calloc(1, sizeof (rx_lane_stat_entry_t)); if (rx_lane_stat_entry == NULL) --- 1162,1178 ---- done: return (head); } static dladm_stat_chain_t * ! i_dlstat_rx_defunctlane_stats(dladm_handle_t handle, const char *linkname) { misc_stat_entry_t *misc_stat_entry; dladm_stat_chain_t *head = NULL; rx_lane_stat_entry_t *rx_lane_stat_entry; ! misc_stat_entry = i_dlstat_misc_stats(handle, linkname); if (misc_stat_entry == NULL) goto done; rx_lane_stat_entry = calloc(1, sizeof (rx_lane_stat_entry_t)); if (rx_lane_stat_entry == NULL)
*** 1212,1240 **** done: return (head); } static dladm_stat_chain_t * ! i_dlstat_rx_hwlane_stats(const char *linkname) { uint_t rx_hwlane_idlist[MAX_RINGS_PER_GROUP]; uint_t rx_hwlane_idlist_size; ! i_dlstat_get_idlist(linkname, DLSTAT_RX_HWLANE_IDLIST, rx_hwlane_idlist, &rx_hwlane_idlist_size); ! return (i_dlstat_query_stats(linkname, DLSTAT_MAC_RX_HWLANE, rx_hwlane_idlist, rx_hwlane_idlist_size, i_dlstat_rx_hwlane_retrieve_stat)); } /*ARGSUSED*/ static dladm_stat_chain_t * i_dlstat_rx_swlane_stats(dladm_handle_t dh, datalink_id_t linkid, const char *linkname) { ! return (i_dlstat_query_stats(linkname, DLSTAT_MAC_RX_SWLANE, default_idlist, default_idlist_size, i_dlstat_rx_swlane_retrieve_stat)); } void * --- 1210,1238 ---- done: return (head); } static dladm_stat_chain_t * ! i_dlstat_rx_hwlane_stats(dladm_handle_t handle, const char *linkname) { uint_t rx_hwlane_idlist[MAX_RINGS_PER_GROUP]; uint_t rx_hwlane_idlist_size; ! i_dlstat_get_idlist(handle, linkname, DLSTAT_RX_HWLANE_IDLIST, rx_hwlane_idlist, &rx_hwlane_idlist_size); ! return (i_dlstat_query_stats(handle, linkname, DLSTAT_MAC_RX_HWLANE, rx_hwlane_idlist, rx_hwlane_idlist_size, i_dlstat_rx_hwlane_retrieve_stat)); } /*ARGSUSED*/ static dladm_stat_chain_t * i_dlstat_rx_swlane_stats(dladm_handle_t dh, datalink_id_t linkid, const char *linkname) { ! return (i_dlstat_query_stats(dh, linkname, DLSTAT_MAC_RX_SWLANE, default_idlist, default_idlist_size, i_dlstat_rx_swlane_retrieve_stat)); } void *
*** 1258,1275 **** "_softmac", &is_legacy_driver) != DLADM_STATUS_OK) { goto done; } if (is_legacy_driver) { ! head = i_dlstat_legacy_rx_lane_stats(linkname); goto done; } ! local_stats = i_dlstat_rx_local_stats(linkname); ! bcast_stats = i_dlstat_rx_bcast_stats(linkname); ! defunctlane_stats = i_dlstat_rx_defunctlane_stats(linkname); ! lane_stats = i_dlstat_rx_hwlane_stats(linkname); if (lane_stats == NULL) lane_stats = i_dlstat_rx_swlane_stats(dh, linkid, linkname); head = i_dlstat_join_lists(local_stats, bcast_stats); head = i_dlstat_join_lists(head, defunctlane_stats); --- 1256,1273 ---- "_softmac", &is_legacy_driver) != DLADM_STATUS_OK) { goto done; } if (is_legacy_driver) { ! head = i_dlstat_legacy_rx_lane_stats(dh, linkname); goto done; } ! local_stats = i_dlstat_rx_local_stats(dh, linkname); ! bcast_stats = i_dlstat_rx_bcast_stats(dh, linkname); ! defunctlane_stats = i_dlstat_rx_defunctlane_stats(dh, linkname); ! lane_stats = i_dlstat_rx_hwlane_stats(dh, linkname); if (lane_stats == NULL) lane_stats = i_dlstat_rx_swlane_stats(dh, linkid, linkname); head = i_dlstat_join_lists(local_stats, bcast_stats); head = i_dlstat_join_lists(head, defunctlane_stats);
*** 1348,1364 **** done: return (tx_lane_stat_entry); } static dladm_stat_chain_t * ! i_dlstat_tx_bcast_stats(const char *linkname) { misc_stat_entry_t *misc_stat_entry; dladm_stat_chain_t *head = NULL; tx_lane_stat_entry_t *tx_lane_stat_entry; ! misc_stat_entry = i_dlstat_misc_stats(linkname); if (misc_stat_entry == NULL) goto done; tx_lane_stat_entry = calloc(1, sizeof (tx_lane_stat_entry_t)); if (tx_lane_stat_entry == NULL) --- 1346,1362 ---- done: return (tx_lane_stat_entry); } static dladm_stat_chain_t * ! i_dlstat_tx_bcast_stats(dladm_handle_t handle, const char *linkname) { misc_stat_entry_t *misc_stat_entry; dladm_stat_chain_t *head = NULL; tx_lane_stat_entry_t *tx_lane_stat_entry; ! misc_stat_entry = i_dlstat_misc_stats(handle, linkname); if (misc_stat_entry == NULL) goto done; tx_lane_stat_entry = calloc(1, sizeof (tx_lane_stat_entry_t)); if (tx_lane_stat_entry == NULL)
*** 1388,1404 **** done: return (head); } static dladm_stat_chain_t * ! i_dlstat_tx_defunctlane_stats(const char *linkname) { misc_stat_entry_t *misc_stat_entry; dladm_stat_chain_t *head = NULL; tx_lane_stat_entry_t *tx_lane_stat_entry; ! misc_stat_entry = i_dlstat_misc_stats(linkname); if (misc_stat_entry == NULL) goto done; tx_lane_stat_entry = calloc(1, sizeof (tx_lane_stat_entry_t)); if (tx_lane_stat_entry == NULL) --- 1386,1402 ---- done: return (head); } static dladm_stat_chain_t * ! i_dlstat_tx_defunctlane_stats(dladm_handle_t handle, const char *linkname) { misc_stat_entry_t *misc_stat_entry; dladm_stat_chain_t *head = NULL; tx_lane_stat_entry_t *tx_lane_stat_entry; ! misc_stat_entry = i_dlstat_misc_stats(handle, linkname); if (misc_stat_entry == NULL) goto done; tx_lane_stat_entry = calloc(1, sizeof (tx_lane_stat_entry_t)); if (tx_lane_stat_entry == NULL)
*** 1426,1454 **** done: return (head); } static dladm_stat_chain_t * ! i_dlstat_tx_hwlane_stats(const char *linkname) { uint_t tx_hwlane_idlist[MAX_RINGS_PER_GROUP]; uint_t tx_hwlane_idlist_size; ! i_dlstat_get_idlist(linkname, DLSTAT_TX_HWLANE_IDLIST, tx_hwlane_idlist, &tx_hwlane_idlist_size); ! return (i_dlstat_query_stats(linkname, DLSTAT_MAC_TX_HWLANE, tx_hwlane_idlist, tx_hwlane_idlist_size, i_dlstat_tx_hwlane_retrieve_stat)); } /*ARGSUSED*/ static dladm_stat_chain_t * i_dlstat_tx_swlane_stats(dladm_handle_t dh, datalink_id_t linkid, const char *linkname) { ! return (i_dlstat_query_stats(linkname, DLSTAT_MAC_TX_SWLANE, default_idlist, default_idlist_size, i_dlstat_tx_swlane_retrieve_stat)); } void * --- 1424,1452 ---- done: return (head); } static dladm_stat_chain_t * ! i_dlstat_tx_hwlane_stats(dladm_handle_t handle, const char *linkname) { uint_t tx_hwlane_idlist[MAX_RINGS_PER_GROUP]; uint_t tx_hwlane_idlist_size; ! i_dlstat_get_idlist(handle, linkname, DLSTAT_TX_HWLANE_IDLIST, tx_hwlane_idlist, &tx_hwlane_idlist_size); ! return (i_dlstat_query_stats(handle, linkname, DLSTAT_MAC_TX_HWLANE, tx_hwlane_idlist, tx_hwlane_idlist_size, i_dlstat_tx_hwlane_retrieve_stat)); } /*ARGSUSED*/ static dladm_stat_chain_t * i_dlstat_tx_swlane_stats(dladm_handle_t dh, datalink_id_t linkid, const char *linkname) { ! return (i_dlstat_query_stats(dh, linkname, DLSTAT_MAC_TX_SWLANE, default_idlist, default_idlist_size, i_dlstat_tx_swlane_retrieve_stat)); } void *
*** 1471,1487 **** "_softmac", &is_legacy_driver) != DLADM_STATUS_OK) { goto done; } if (is_legacy_driver) { ! head = i_dlstat_legacy_tx_lane_stats(linkname); goto done; } ! bcast_stats = i_dlstat_tx_bcast_stats(linkname); ! defunctlane_stats = i_dlstat_tx_defunctlane_stats(linkname); ! lane_stats = i_dlstat_tx_hwlane_stats(linkname); if (lane_stats == NULL) lane_stats = i_dlstat_tx_swlane_stats(dh, linkid, linkname); head = i_dlstat_join_lists(bcast_stats, defunctlane_stats); head = i_dlstat_join_lists(head, lane_stats); --- 1469,1485 ---- "_softmac", &is_legacy_driver) != DLADM_STATUS_OK) { goto done; } if (is_legacy_driver) { ! head = i_dlstat_legacy_tx_lane_stats(dh, linkname); goto done; } ! bcast_stats = i_dlstat_tx_bcast_stats(dh, linkname); ! defunctlane_stats = i_dlstat_tx_defunctlane_stats(dh, linkname); ! lane_stats = i_dlstat_tx_hwlane_stats(dh, linkname); if (lane_stats == NULL) lane_stats = i_dlstat_tx_swlane_stats(dh, linkid, linkname); head = i_dlstat_join_lists(bcast_stats, defunctlane_stats); head = i_dlstat_join_lists(head, lane_stats);
*** 1650,1669 **** if (dladm_datalink_id2info(dh, linkid, NULL, NULL, NULL, linkname, DLPI_LINKNAME_MAX) != DLADM_STATUS_OK) { return (NULL); } ! i_dlstat_get_idlist(linkname, DLSTAT_FANOUT_IDLIST, fanout_idlist, &fanout_idlist_size); for (i = 0; i < idlist_size; i++) { uint_t index = idlist[i]; (void) snprintf(statprefix, sizeof (statprefix), "%s%d_fanout", prefix, index); ! curr_head = i_dlstat_query_stats(modname, statprefix, fanout_idlist, fanout_idlist_size, i_dlstat_fanout_retrieve_stat); if (curr_head == NULL) /* Last lane */ break; --- 1648,1667 ---- if (dladm_datalink_id2info(dh, linkid, NULL, NULL, NULL, linkname, DLPI_LINKNAME_MAX) != DLADM_STATUS_OK) { return (NULL); } ! i_dlstat_get_idlist(dh, linkname, DLSTAT_FANOUT_IDLIST, fanout_idlist, &fanout_idlist_size); for (i = 0; i < idlist_size; i++) { uint_t index = idlist[i]; (void) snprintf(statprefix, sizeof (statprefix), "%s%d_fanout", prefix, index); ! curr_head = i_dlstat_query_stats(dh, modname, statprefix, fanout_idlist, fanout_idlist_size, i_dlstat_fanout_retrieve_stat); if (curr_head == NULL) /* Last lane */ break;
*** 1705,1715 **** const char *linkname) { uint_t rx_hwlane_idlist[MAX_RINGS_PER_GROUP]; uint_t rx_hwlane_idlist_size; ! i_dlstat_get_idlist(linkname, DLSTAT_RX_HWLANE_IDLIST, rx_hwlane_idlist, &rx_hwlane_idlist_size); return (i_dlstat_query_fanout_stats(dh, linkid, rx_hwlane_idlist, rx_hwlane_idlist_size, linkname, DLSTAT_MAC_RX_HWLANE)); } --- 1703,1713 ---- const char *linkname) { uint_t rx_hwlane_idlist[MAX_RINGS_PER_GROUP]; uint_t rx_hwlane_idlist_size; ! i_dlstat_get_idlist(dh, linkname, DLSTAT_RX_HWLANE_IDLIST, rx_hwlane_idlist, &rx_hwlane_idlist_size); return (i_dlstat_query_fanout_stats(dh, linkid, rx_hwlane_idlist, rx_hwlane_idlist_size, linkname, DLSTAT_MAC_RX_HWLANE)); }
*** 1831,1844 **** } modname = dpa.dp_dev; } else modname = linkname; ! i_dlstat_get_idlist(modname, DLSTAT_RX_RING_IDLIST, rx_ring_idlist, &rx_ring_idlist_size); ! return (i_dlstat_query_stats(modname, DLSTAT_MAC_RX_RING, rx_ring_idlist, rx_ring_idlist_size, i_dlstat_rx_ring_retrieve_stat)); } /* Tx ring statistic specific functions */ --- 1829,1842 ---- } modname = dpa.dp_dev; } else modname = linkname; ! i_dlstat_get_idlist(dh, modname, DLSTAT_RX_RING_IDLIST, rx_ring_idlist, &rx_ring_idlist_size); ! return (i_dlstat_query_stats(dh, modname, DLSTAT_MAC_RX_RING, rx_ring_idlist, rx_ring_idlist_size, i_dlstat_rx_ring_retrieve_stat)); } /* Tx ring statistic specific functions */
*** 1918,1931 **** } modname = dpa.dp_dev; } else modname = linkname; ! i_dlstat_get_idlist(modname, DLSTAT_TX_RING_IDLIST, tx_ring_idlist, &tx_ring_idlist_size); ! return (i_dlstat_query_stats(modname, DLSTAT_MAC_TX_RING, tx_ring_idlist, tx_ring_idlist_size, i_dlstat_tx_ring_retrieve_stat)); } /* Rx ring total statistic specific functions */ --- 1916,1929 ---- } modname = dpa.dp_dev; } else modname = linkname; ! i_dlstat_get_idlist(dh, modname, DLSTAT_TX_RING_IDLIST, tx_ring_idlist, &tx_ring_idlist_size); ! return (i_dlstat_query_stats(dh, modname, DLSTAT_MAC_TX_RING, tx_ring_idlist, tx_ring_idlist_size, i_dlstat_tx_ring_retrieve_stat)); } /* Rx ring total statistic specific functions */
*** 2168,2194 **** /* * Query dls stats for the aggr port. This results in query for stats into * the corresponding device driver. */ static aggr_port_stat_entry_t * ! i_dlstat_single_port_stats(const char *portname, datalink_id_t linkid) { - kstat_ctl_t *kcp; kstat_t *ksp; char module[DLPI_LINKNAME_MAX]; uint_t instance; aggr_port_stat_entry_t *aggr_port_stat_entry = NULL; if (dladm_parselink(portname, module, &instance) != DLADM_STATUS_OK) goto done; ! if ((kcp = kstat_open()) == NULL) { warn("kstat open operation failed"); return (NULL); } ! ksp = dladm_kstat_lookup(kcp, module, instance, "mac", NULL); if (ksp == NULL) goto done; aggr_port_stat_entry = calloc(1, sizeof (aggr_port_stat_entry_t)); if (aggr_port_stat_entry == NULL) --- 2166,2193 ---- /* * Query dls stats for the aggr port. This results in query for stats into * the corresponding device driver. */ static aggr_port_stat_entry_t * ! i_dlstat_single_port_stats(dladm_handle_t handle, const char *portname, ! datalink_id_t linkid) { kstat_t *ksp; char module[DLPI_LINKNAME_MAX]; uint_t instance; aggr_port_stat_entry_t *aggr_port_stat_entry = NULL; if (dladm_parselink(portname, module, &instance) != DLADM_STATUS_OK) goto done; ! if (dladm_dld_kcp(handle) == NULL) { warn("kstat open operation failed"); return (NULL); } ! ksp = dladm_kstat_lookup(dladm_dld_kcp(handle), module, instance, ! "mac", NULL); if (ksp == NULL) goto done; aggr_port_stat_entry = calloc(1, sizeof (aggr_port_stat_entry_t)); if (aggr_port_stat_entry == NULL)
*** 2195,2208 **** goto done; /* Save port's linkid */ aggr_port_stat_entry->ape_portlinkid = linkid; ! i_dlstat_get_stats(kcp, ksp, &aggr_port_stat_entry->ape_stats, aggr_port_stats_list, AGGR_PORT_STAT_SIZE); done: - (void) kstat_close(kcp); return (aggr_port_stat_entry); } void * dlstat_aggr_port_stats(dladm_handle_t dh, datalink_id_t linkid) --- 2194,2207 ---- goto done; /* Save port's linkid */ aggr_port_stat_entry->ape_portlinkid = linkid; ! i_dlstat_get_stats(dladm_dld_kcp(handle), ksp, ! &aggr_port_stat_entry->ape_stats, aggr_port_stats_list, AGGR_PORT_STAT_SIZE); done: return (aggr_port_stat_entry); } void * dlstat_aggr_port_stats(dladm_handle_t dh, datalink_id_t linkid)
*** 2226,2237 **** if (dladm_phys_info(dh, portp->lp_linkid, &dpa, DLADM_OPT_ACTIVE) != DLADM_STATUS_OK) { goto done; } ! aggr_port_stat_entry = i_dlstat_single_port_stats(dpa.dp_dev, ! portp->lp_linkid); /* Create dladm_stat_chain_t object for this stat */ curr = malloc(sizeof (dladm_stat_chain_t)); if (curr == NULL) { free(aggr_port_stat_entry); --- 2225,2236 ---- if (dladm_phys_info(dh, portp->lp_linkid, &dpa, DLADM_OPT_ACTIVE) != DLADM_STATUS_OK) { goto done; } ! aggr_port_stat_entry = i_dlstat_single_port_stats(dh, ! dpa.dp_dev, portp->lp_linkid); /* Create dladm_stat_chain_t object for this stat */ curr = malloc(sizeof (dladm_stat_chain_t)); if (curr == NULL) { free(aggr_port_stat_entry);
*** 2277,2287 **** if (dladm_datalink_id2info(dh, linkid, NULL, NULL, NULL, linkname, DLPI_LINKNAME_MAX) != DLADM_STATUS_OK) { goto done; } ! misc_stat_entry = i_dlstat_misc_stats(linkname); if (misc_stat_entry == NULL) goto done; head = malloc(sizeof (dladm_stat_chain_t)); if (head == NULL) { --- 2276,2286 ---- if (dladm_datalink_id2info(dh, linkid, NULL, NULL, NULL, linkname, DLPI_LINKNAME_MAX) != DLADM_STATUS_OK) { goto done; } ! misc_stat_entry = i_dlstat_misc_stats(dh, linkname); if (misc_stat_entry == NULL) goto done; head = malloc(sizeof (dladm_stat_chain_t)); if (head == NULL) {
*** 2511,2542 **** } } /* flow stats specific routines */ flow_stat_t * ! dladm_flow_stat_query(const char *flowname) { - kstat_ctl_t *kcp; kstat_t *ksp; flow_stat_t *flow_stat = NULL; ! if ((kcp = kstat_open()) == NULL) return (NULL); flow_stat = calloc(1, sizeof (flow_stat_t)); if (flow_stat == NULL) goto done; ! ksp = dladm_kstat_lookup(kcp, NULL, -1, flowname, "flow"); if (ksp != NULL) { ! i_dlstat_get_stats(kcp, ksp, flow_stat, flow_stats_list, ! FLOW_STAT_SIZE); } done: - (void) kstat_close(kcp); return (flow_stat); } flow_stat_t * dladm_flow_stat_diff(flow_stat_t *op1, flow_stat_t *op2) --- 2510,2540 ---- } } /* flow stats specific routines */ flow_stat_t * ! dladm_flow_stat_query(dladm_handle_t handle, const char *flowname) { kstat_t *ksp; flow_stat_t *flow_stat = NULL; ! if (dladm_dld_kcp(handle) == NULL) return (NULL); flow_stat = calloc(1, sizeof (flow_stat_t)); if (flow_stat == NULL) goto done; ! ksp = dladm_kstat_lookup(dladm_dld_kcp(handle), NULL, -1, flowname, ! "flow"); if (ksp != NULL) { ! i_dlstat_get_stats(dladm_dld_kcp(handle), ksp, flow_stat, ! flow_stats_list, FLOW_STAT_SIZE); } done: return (flow_stat); } flow_stat_t * dladm_flow_stat_diff(flow_stat_t *op1, flow_stat_t *op2)
*** 2563,2579 **** free(curr); } /* Query all flow stats */ name_value_stat_entry_t * ! dladm_flow_stat_query_all(const char *flowname) { flow_stat_t *flow_stat; name_value_stat_entry_t *name_value_stat_entry = NULL; /* Query flow stats */ ! flow_stat = dladm_flow_stat_query(flowname); if (flow_stat == NULL) goto done; /* Allocate memory for query all stat entry */ name_value_stat_entry = calloc(1, sizeof (name_value_stat_entry_t)); --- 2561,2577 ---- free(curr); } /* Query all flow stats */ name_value_stat_entry_t * ! dladm_flow_stat_query_all(dladm_handle_t handle, const char *flowname) { flow_stat_t *flow_stat; name_value_stat_entry_t *name_value_stat_entry = NULL; /* Query flow stats */ ! flow_stat = dladm_flow_stat_query(handle, flowname); if (flow_stat == NULL) goto done; /* Allocate memory for query all stat entry */ name_value_stat_entry = calloc(1, sizeof (name_value_stat_entry_t));