Print this page
NEX-5175 want SMB statistics separately for reads, writes, other
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Matt Barden <Matt.Barden@nexenta.com>
NEX-5197 smbstat copying out wrong stats for per-share or per-client
Reviewed by: Gordon Ross <gwr@nexenta.com>
NEX-4811 SMB needs to export a header for kstats
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Jeffry Molanus <jeffry.molanus@nexenta.com>
NEX-4313 want iops, bandwidth, and latency kstats for smb
Portions contributed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Matt Barden <Matt.Barden@nexenta.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
5606 support build with binutils 2.25
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Marcel Telka <marcel.telka@nexenta.com>
Reviewed by: Piotr Jasiukajtis <estibi@me.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
NEX-3273 smbstat delays its output when redirected to a file
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Bayard Bell <bayard.bell@nexenta.com>
NEX-2705 smbstat output may lie about sat and show only zero for writes/s
SMB-78 smbstat should show SMB2 activity
SMB-11 SMB2 message parse & dispatch
SMB-12 SMB2 Negotiate Protocol
SMB-13 SMB2 Session Setup
SMB-14 SMB2 Logoff
SMB-15 SMB2 Tree Connect
SMB-16 SMB2 Tree Disconnect
SMB-17 SMB2 Create
SMB-18 SMB2 Close
SMB-19 SMB2 Flush
SMB-20 SMB2 Read
SMB-21 SMB2 Write
SMB-22 SMB2 Lock/Unlock
SMB-23 SMB2 Ioctl
SMB-24 SMB2 Cancel
SMB-25 SMB2 Echo
SMB-26 SMB2 Query Dir
SMB-27 SMB2 Change Notify
SMB-28 SMB2 Query Info
SMB-29 SMB2 Set Info
SMB-30 SMB2 Oplocks
SMB-53 SMB2 Create Context options
(SMB2 code review cleanup 1, 2, 3)
SMB-65 SMB server in non-global zones (data structure changes)
Many things move to the smb_server_t object, and
many functions gain an sv arg (which server).

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/smbsrv/smbstat/smbstat.c
          +++ new/usr/src/cmd/smbsrv/smbstat/smbstat.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  24      - * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
       24 + * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  25   25   */
  26   26  
  27   27  /*
  28   28   * smbstat: Server Message Block File System statistics
  29   29   *
  30   30   * The statistics this CLI displays come from two sources:
  31   31   *
  32   32   * 1) The kernel module 'smbsrv'.
  33   33   * 2) The SMB workers task queue statistics the task queue manager of Solaris
  34   34   *    maintains.
↓ open down ↓ 61 lines elided ↑ open up ↑
  96   96  #include <strings.h>
  97   97  #include <utility.h>
  98   98  #include <libintl.h>
  99   99  #include <zone.h>
 100  100  #include <termios.h>
 101  101  #include <stropts.h>
 102  102  #include <math.h>
 103  103  #include <umem.h>
 104  104  #include <locale.h>
 105  105  #include <smbsrv/smb_kstat.h>
      106 +#include <smbsrv/smb.h>
      107 +#include <smbsrv/smb2.h>
 106  108  
 107  109  #if !defined(TEXT_DOMAIN)
 108  110  #define TEXT_DOMAIN "SYS_TEST"
 109  111  #endif /* TEXT_DOMAIN */
 110  112  
 111  113  #define SMBSTAT_ID_NO_CPU       -1
 112  114  #define SMBSTAT_SNAPSHOT_COUNT  2               /* Must be a power of 2 */
 113  115  #define SMBSTAT_SNAPSHOT_MASK   (SMBSTAT_SNAPSHOT_COUNT - 1)
 114  116  
 115  117  #define SMBSTAT_HELP    \
↓ open down ↓ 21 lines elided ↑ open up ↑
 137  139  #define SMBSRV_UTILIZATION_FORMAT       \
 138  140          "%1.3e  %1.3e  %1.3e  %1.3e  %3.0f  %3.0f  %3.0f  %s " \
 139  141          "%3.0f  %3.0f    %3.0f\n"
 140  142  
 141  143  #define SMBSRV_REQUESTS_BANNER  \
 142  144          "\n%30s code   %%   rbytes/s   tbytes/s     req/s     rt-mean"  \
 143  145          "   rt-stddev\n"
 144  146  #define SMBSRV_REQUESTS_FORMAT  \
 145  147          "%30s  %02X   %3.0f  %1.3e  %1.3e  %1.3e  %1.3e  %1.3e\n"
 146  148  
      149 +#define SMBSRV_CLNT_SHARE_BANNER        \
      150 +        "%30s  rbytes/s   tbytes/s     req/s     rt-mean   rt-stddev\n"
      151 +#define SMBSRV_CLNT_SHARE_FORMAT        \
      152 +        "%30s  %1.3e  %1.3e  %1.3e  %1.3e  %1.3e\n"
      153 +
      154 +
 147  155  typedef enum {
 148  156          CPU_TICKS_IDLE = 0,
 149  157          CPU_TICKS_USER,
 150  158          CPU_TICKS_KERNEL,
 151  159          CPU_TICKS_SENTINEL
 152  160  } cpu_state_idx_t;
 153  161  
 154  162  typedef struct smbstat_cpu_snapshot {
 155  163          processorid_t   cs_id;
 156  164          int             cs_state;
↓ open down ↓ 3 lines elided ↑ open up ↑
 160  168  typedef struct smbstat_srv_snapshot {
 161  169          hrtime_t        ss_snaptime;
 162  170          smbsrv_kstats_t ss_data;
 163  171  } smbstat_srv_snapshot_t;
 164  172  
 165  173  typedef struct smbstat_wrk_snapshot {
 166  174          uint64_t        ws_maxthreads;
 167  175          uint64_t        ws_bnalloc;
 168  176  } smbstat_wrk_snapshot_t;
 169  177  
      178 +/* Per-Client or Per-Share statistics. */
      179 +typedef struct smbstat_clsh_snapshot {
      180 +        hrtime_t        cs_snaptime;
      181 +        smbsrv_clsh_kstats_t    cs_data;
      182 +} smbstat_clsh_snapshot_t;
      183 +
 170  184  typedef struct smbstat_req_info {
 171  185          char            ri_name[KSTAT_STRLEN];
 172  186          int             ri_opcode;
 173  187          double          ri_pct;
 174  188          double          ri_tbs;
 175  189          double          ri_rbs;
 176  190          double          ri_rqs;
 177  191          double          ri_stddev;
 178  192          double          ri_mean;
 179  193  } smbstat_req_info_t;
↓ open down ↓ 27 lines elided ↑ open up ↑
 207  221          double          si_upct;        /* Utilization in % */
 208  222          double          si_avw;         /* Average number of requests waiting */
 209  223          double          si_avr;         /* Average number of requests running */
 210  224          double          si_wserv;       /* Average waiting time */
 211  225          double          si_rserv;       /* Average running time */
 212  226          boolean_t       si_sat;
 213  227          double          si_ticks[CPU_TICKS_SENTINEL];
 214  228          /*
 215  229           * Latency & Throughput per request
 216  230           */
 217      -        smbstat_req_info_t      si_reqs1[SMB_COM_NUM];
 218      -        smbstat_req_info_t      si_reqs2[SMB2__NCMDS];
      231 +        smbstat_req_info_t      si_reqs1[SMBSRV_KS_NREQS1];
      232 +        smbstat_req_info_t      si_reqs2[SMBSRV_KS_NREQS2];
      233 +        /*
      234 +         * Latency & Throughput on specified client or share
      235 +         */
      236 +        smbstat_req_info_t      si_clsh[SMBSRV_CLSH__NREQ];
 219  237  } smbstat_srv_info_t;
 220  238  
 221  239  static void smbstat_init(void);
 222  240  static void smbstat_fini(void);
 223  241  static void smbstat_kstat_snapshot(void);
 224  242  static void smbstat_kstat_process(void);
 225  243  static void smbstat_kstat_print(void);
 226  244  
 227  245  static void smbstat_print_counters(void);
 228  246  static void smbstat_print_throughput(void);
 229  247  static void smbstat_print_utilization(void);
 230  248  static void smbstat_print_requests(void);
      249 +static void smbstat_print_client_or_share(void);
 231  250  
 232  251  static void smbstat_cpu_init(void);
 233  252  static void smbstat_cpu_fini(void);
 234  253  static smbstat_cpu_snapshot_t *smbstat_cpu_current_snapshot(void);
 235  254  static smbstat_cpu_snapshot_t *smbstat_cpu_previous_snapshot(void);
 236  255  static void smbstat_cpu_snapshot(void);
 237  256  static void smbstat_cpu_process(void);
 238  257  
 239  258  static void smbstat_wrk_init(void);
 240  259  static void smbstat_wrk_fini(void);
 241  260  static void smbstat_wrk_snapshot(void);
 242  261  static void smbstat_wrk_process(void);
 243  262  static smbstat_wrk_snapshot_t *smbstat_wrk_current_snapshot(void);
 244  263  
      264 +static void smbstat_clsh_init(void);
      265 +static void smbstat_clsh_fini(void);
      266 +static void smbstat_clsh_snapshot(void);
      267 +static void smbstat_clsh_process(void);
      268 +static smbstat_clsh_snapshot_t *smbstat_clsh_current_snapshot(void);
      269 +static smbstat_clsh_snapshot_t *smbstat_clsh_previous_snapshot(void);
      270 +
 245  271  static void smbstat_srv_init(void);
 246  272  static void smbstat_srv_fini(void);
 247  273  static void smbstat_srv_snapshot(void);
 248  274  static void smbstat_srv_process(void);
 249  275  static void smbstat_srv_process_counters(smbstat_srv_snapshot_t *);
 250  276  static void smbstat_srv_process_throughput(smbstat_srv_snapshot_t *,
 251  277      smbstat_srv_snapshot_t *);
 252  278  static void smbstat_srv_process_utilization(smbstat_srv_snapshot_t *,
 253  279      smbstat_srv_snapshot_t *);
 254  280  static void smbstat_srv_process_requests(smbstat_srv_snapshot_t *,
↓ open down ↓ 24 lines elided ↑ open up ↑
 279  305          "cpu_ticks_kernel"
 280  306  };
 281  307  
 282  308  static boolean_t        smbstat_opt_a = B_FALSE;        /* all */
 283  309  static boolean_t        smbstat_opt_c = B_FALSE;        /* counters */
 284  310  static boolean_t        smbstat_opt_n = B_FALSE;        /* by name */
 285  311  static boolean_t        smbstat_opt_u = B_FALSE;        /* utilization */
 286  312  static boolean_t        smbstat_opt_t = B_FALSE;        /* throughput */
 287  313  static boolean_t        smbstat_opt_r = B_FALSE;        /* requests */
 288  314  static boolean_t        smbstat_opt_z = B_FALSE;        /* non-zero requests */
      315 +static boolean_t        smbstat_opt_C = B_FALSE;        /* per-client stats */
      316 +static boolean_t        smbstat_opt_S = B_FALSE;        /* per-share stats */
      317 +static char             *smbstat_opt_clsh = NULL;       /* -C or -S arg. */
 289  318  
 290  319  static uint_t           smbstat_interval = 0;
 291  320  static long             smbstat_nrcpus = 0;
 292  321  static kstat_ctl_t      *smbstat_ksc = NULL;
 293  322  static kstat_t          *smbstat_srv_ksp = NULL;
 294  323  static kstat_t          *smbstat_wrk_ksp = NULL;
      324 +static kstat_t          *smbstat_clsh_ksp = NULL;
 295  325  static struct winsize   smbstat_ws;
 296  326  static uint16_t         smbstat_rows = 0;
 297  327  
 298  328  static int smbstat_snapshot_idx = 0;
 299  329  static smbstat_cpu_snapshot_t *smbstat_cpu_snapshots[SMBSTAT_SNAPSHOT_COUNT];
 300  330  static smbstat_srv_snapshot_t smbstat_srv_snapshots[SMBSTAT_SNAPSHOT_COUNT];
 301  331  static smbstat_wrk_snapshot_t smbstat_wrk_snapshots[SMBSTAT_SNAPSHOT_COUNT];
      332 +static smbstat_clsh_snapshot_t smbstat_clsh_snapshots[SMBSTAT_SNAPSHOT_COUNT];
 302  333  static smbstat_srv_info_t smbstat_srv_info;
 303  334  
 304  335  /*
 305  336   * main
 306  337   */
 307  338  int
 308  339  main(int argc, char *argv[])
 309  340  {
 310  341          int     c;
 311  342  
 312  343          (void) setlocale(LC_ALL, "");
 313  344          (void) textdomain(TEXT_DOMAIN);
 314  345  
 315  346          if (is_system_labeled()) {
 316  347                  (void) fprintf(stderr,
 317  348                      gettext("%s: Trusted Extensions not supported.\n"),
 318  349                      argv[0]);
 319  350                  return (1);
 320  351          }
 321  352  
 322      -        while ((c = getopt(argc, argv, "achnrtuz")) != EOF) {
      353 +        while ((c = getopt(argc, argv, "achnrtuzC:S:")) != EOF) {
 323  354                  switch (c) {
 324  355                  case 'a':
 325  356                          smbstat_opt_a = B_TRUE;
 326  357                          break;
 327  358                  case 'n':
 328  359                          smbstat_opt_n = B_TRUE;
 329  360                          break;
 330  361                  case 'u':
 331  362                          smbstat_opt_u = B_TRUE;
 332  363                          break;
↓ open down ↓ 2 lines elided ↑ open up ↑
 335  366                          break;
 336  367                  case 'r':
 337  368                          smbstat_opt_r = B_TRUE;
 338  369                          break;
 339  370                  case 't':
 340  371                          smbstat_opt_t = B_TRUE;
 341  372                          break;
 342  373                  case 'z':
 343  374                          smbstat_opt_z = B_TRUE;
 344  375                          break;
      376 +                case 'C': /* per-client stats. */
      377 +                        smbstat_opt_S = B_FALSE;
      378 +                        smbstat_opt_C = B_TRUE;
      379 +                        smbstat_opt_clsh = optarg;
      380 +                        break;
      381 +                case 'S': /* per-share stats. */
      382 +                        smbstat_opt_C = B_FALSE;
      383 +                        smbstat_opt_S = B_TRUE;
      384 +                        smbstat_opt_clsh = optarg;
      385 +                        break;
 345  386                  case 'h':
 346  387                          smbstat_usage(stdout, 0);
 347  388                  default:
 348  389                          smbstat_usage(stderr, 1);
 349  390                  }
 350  391          }
 351  392  
 352  393          if (!smbstat_opt_u &&
 353  394              !smbstat_opt_c &&
 354  395              !smbstat_opt_r &&
 355      -            !smbstat_opt_t) {
      396 +            !smbstat_opt_t &&
      397 +            !smbstat_opt_C &&
      398 +            !smbstat_opt_S) {
 356  399                  /* Default options when none is specified. */
 357  400                  smbstat_opt_u = B_TRUE;
 358  401                  smbstat_opt_t = B_TRUE;
 359  402          }
 360  403  
 361  404          if (optind < argc) {
 362  405                  smbstat_interval =
 363  406                      smbstat_strtoi(argv[optind], "invalid count");
 364  407                  optind++;
 365  408          }
 366  409  
 367  410          if ((argc - optind) > 1)
 368  411                  smbstat_usage(stderr, 1);
 369  412  
 370  413          (void) atexit(smbstat_fini);
 371  414          smbstat_init();
      415 +        smbstat_req_order();
 372  416          for (;;) {
 373  417                  smbstat_kstat_snapshot();
 374  418                  smbstat_kstat_process();
 375  419                  smbstat_kstat_print();
 376  420                  if (smbstat_interval == 0)
 377  421                          break;
 378  422                  (void) sleep(smbstat_interval);
 379  423                  smbstat_snapshot_inc_idx();
 380  424          }
 381  425          return (0);
↓ open down ↓ 6 lines elided ↑ open up ↑
 388  432   */
 389  433  static void
 390  434  smbstat_init(void)
 391  435  {
 392  436          if ((smbstat_ksc = kstat_open()) == NULL)
 393  437                  smbstat_fail(1, gettext("kstat_open(): can't open /dev/kstat"));
 394  438  
 395  439          smbstat_cpu_init();
 396  440          smbstat_srv_init();
 397  441          smbstat_wrk_init();
 398      -        smbstat_req_order();
      442 +        smbstat_clsh_init();
 399  443  }
 400  444  
 401  445  /*
 402  446   * smbstat_fini
 403  447   *
 404  448   * Releases the resources smbstat_init() allocated.
 405  449   */
 406  450  static void
 407  451  smbstat_fini(void)
 408  452  {
      453 +        smbstat_clsh_fini();
 409  454          smbstat_wrk_fini();
 410  455          smbstat_srv_fini();
 411  456          smbstat_cpu_fini();
 412  457          (void) kstat_close(smbstat_ksc);
 413  458  }
 414  459  
 415  460  /*
 416  461   * smbstat_kstat_snapshot
 417  462   *
 418  463   * Takes a snapshot of the data.
 419  464   */
 420  465  static void
 421  466  smbstat_kstat_snapshot(void)
 422  467  {
 423  468          smbstat_cpu_snapshot();
 424  469          smbstat_srv_snapshot();
 425  470          smbstat_wrk_snapshot();
      471 +        smbstat_clsh_snapshot();
 426  472  }
 427  473  
 428  474  /*
 429  475   * smbstat_kstat_process
 430  476   */
 431  477  static void
 432  478  smbstat_kstat_process(void)
 433  479  {
 434  480          smbstat_cpu_process();
 435  481          smbstat_srv_process();
 436  482          smbstat_wrk_process();
      483 +        smbstat_clsh_process();
 437  484  }
 438  485  
 439  486  /*
 440  487   * smbstat_kstat_print
 441  488   *
 442  489   * Print the data processed.
 443  490   */
 444  491  static void
 445  492  smbstat_kstat_print(void)
 446  493  {
 447  494          smbstat_termio_init();
 448  495          smbstat_print_counters();
 449  496          smbstat_print_throughput();
 450  497          smbstat_print_utilization();
 451  498          smbstat_print_requests();
      499 +        smbstat_print_client_or_share();
 452  500          (void) fflush(stdout);
 453  501  }
 454  502  
 455  503  /*
 456  504   * smbstat_print_counters
 457  505   *
 458  506   * Displays the SMB server counters (session, users...).
 459  507   */
 460  508  static void
 461  509  smbstat_print_counters(void)
↓ open down ↓ 22 lines elided ↑ open up ↑
 484  532   *
 485  533   * Formats the SMB server throughput output.
 486  534   */
 487  535  static void
 488  536  smbstat_print_throughput(void)
 489  537  {
 490  538          if (!smbstat_opt_t)
 491  539                  return;
 492  540  
 493  541          if (smbstat_opt_u || smbstat_opt_r || smbstat_opt_c ||
 494      -            (smbstat_rows == 0) || (smbstat_rows >= smbstat_ws.ws_row)) {
      542 +            smbstat_opt_C || smbstat_opt_S || (smbstat_rows == 0) ||
      543 +            (smbstat_rows >= smbstat_ws.ws_row)) {
 495  544                  (void) printf(SMBSRV_THROUGHPUT_BANNER);
 496  545                  smbstat_rows = 1;
 497  546          }
 498  547          (void) printf(SMBSRV_THROUGHPUT_FORMAT,
 499  548              smbstat_zero(smbstat_srv_info.si_rbs),
 500  549              smbstat_zero(smbstat_srv_info.si_tbs),
 501  550              smbstat_zero(smbstat_srv_info.si_rqs),
 502  551              smbstat_zero(smbstat_srv_info.si_rds),
 503  552              smbstat_zero(smbstat_srv_info.si_wrs));
 504  553  
↓ open down ↓ 45 lines elided ↑ open up ↑
 550  599  {
 551  600          smbstat_req_info_t      *prq;
 552  601          int                     i;
 553  602  
 554  603          if (!smbstat_opt_r)
 555  604                  return;
 556  605  
 557  606          (void) printf(SMBSRV_REQUESTS_BANNER, "       ");
 558  607  
 559  608          prq = smbstat_srv_info.si_reqs1;
 560      -        for (i = 0; i < SMB_COM_NUM; i++) {
      609 +        for (i = 0; i < SMBSRV_KS_NREQS1; i++) {
 561  610                  if (!smbstat_opt_a &&
 562  611                      strncmp(prq[i].ri_name, "Invalid", sizeof ("Invalid")) == 0)
 563  612                          continue;
 564  613  
 565  614                  if (!smbstat_opt_z || (prq[i].ri_pct != 0)) {
 566  615                          (void) printf(SMBSRV_REQUESTS_FORMAT,
 567  616                              prq[i].ri_name,
 568  617                              prq[i].ri_opcode,
 569  618                              smbstat_zero(prq[i].ri_pct),
 570  619                              smbstat_zero(prq[i].ri_rbs),
 571  620                              smbstat_zero(prq[i].ri_tbs),
 572  621                              smbstat_zero(prq[i].ri_rqs),
 573  622                              prq[i].ri_mean,
 574  623                              prq[i].ri_stddev);
 575  624                  }
 576  625          }
 577  626  
 578  627          prq = smbstat_srv_info.si_reqs2;
 579      -        for (i = 0; i < SMB2__NCMDS; i++) {
      628 +        for (i = 0; i < SMBSRV_KS_NREQS2; i++) {
 580  629                  if (!smbstat_opt_a && i == SMB2_INVALID_CMD)
 581  630                          continue;
 582  631  
 583  632                  if (!smbstat_opt_z || (prq[i].ri_pct != 0)) {
 584  633                          (void) printf(SMBSRV_REQUESTS_FORMAT,
 585  634                              prq[i].ri_name,
 586  635                              prq[i].ri_opcode,
 587  636                              smbstat_zero(prq[i].ri_pct),
 588  637                              smbstat_zero(prq[i].ri_rbs),
 589  638                              smbstat_zero(prq[i].ri_tbs),
 590  639                              smbstat_zero(prq[i].ri_rqs),
 591  640                              prq[i].ri_mean,
 592  641                              prq[i].ri_stddev);
 593  642                  }
 594  643          }
 595  644  }
 596  645  
      646 +static void
      647 +smbstat_print_client_or_share(void)
      648 +{
      649 +        smbstat_req_info_t      *prq;
      650 +        int     idx;
      651 +
      652 +        if (smbstat_opt_clsh == NULL)
      653 +                return;
      654 +
      655 +        (void) printf(SMBSRV_CLNT_SHARE_BANNER, "       ");
      656 +
      657 +        prq = &smbstat_srv_info.si_clsh[0];
      658 +
      659 +        for (idx = 0; idx < SMBSRV_CLSH__NREQ; idx++, prq++) {
      660 +        (void) printf(SMBSRV_CLNT_SHARE_FORMAT,
      661 +            prq->ri_name,
      662 +            smbstat_zero(prq->ri_rbs),
      663 +            smbstat_zero(prq->ri_tbs),
      664 +            smbstat_zero(prq->ri_rqs),
      665 +            prq->ri_mean,
      666 +            prq->ri_stddev);
      667 +        }
      668 +}
      669 +
      670 +
 597  671  /*
 598  672   * smbstat_cpu_init
 599  673   */
 600  674  static void
 601  675  smbstat_cpu_init(void)
 602  676  {
 603  677          size_t  size;
 604  678          int     i;
 605  679  
 606  680          smbstat_nrcpus = sysconf(_SC_CPUID_MAX) + 1;
↓ open down ↓ 178 lines elided ↑ open up ↑
 785  859  /*
 786  860   * smbstat_wrk_current_snapshot
 787  861   */
 788  862  static smbstat_wrk_snapshot_t *
 789  863  smbstat_wrk_current_snapshot(void)
 790  864  {
 791  865          return (&smbstat_wrk_snapshots[smbstat_snapshot_idx]);
 792  866  }
 793  867  
 794  868  /*
      869 + * smbstat_clsh_init
      870 + *
      871 + * Lookup the kstat for the client or share specified.
      872 + * The names for these look like:
      873 + *      session (a.k.a. client)
      874 + *              cl/$IPADDR  and instance ss->s_kid
      875 + *      share
      876 + *              sh/sharename    (always instance 0)
      877 + *
      878 + * These will look like: smbsrv:0:sh/myshare
      879 + * or smbsrv:N:cl/10.10.0.2
      880 + */
      881 +static void
      882 +smbstat_clsh_init(void)
      883 +{
      884 +        static const char       *kr_names[] = SMBSRV_CLSH__NAMES;
      885 +        char    ks_name[KSTAT_STRLEN];
      886 +        char    *prefix = "";
      887 +        smbstat_req_info_t *info;
      888 +        int     instance = -1;
      889 +        int     i;
      890 +
      891 +        if (smbstat_opt_clsh == NULL)
      892 +                return;
      893 +
      894 +        /*
      895 +         * Currently we don't take an instance so this will return data
      896 +         * from the first or the only client from the IP address specified.
      897 +         */
      898 +        if (smbstat_opt_C)
      899 +                prefix = "cl";
      900 +        if (smbstat_opt_S)
      901 +                prefix = "sh";
      902 +        (void) snprintf(ks_name, sizeof (ks_name),
      903 +            "%s/%s", prefix, smbstat_opt_clsh);
      904 +
      905 +        smbstat_clsh_ksp = kstat_lookup(smbstat_ksc, SMBSRV_KSTAT_MODULE,
      906 +            instance, ks_name);
      907 +        if (smbstat_clsh_ksp == NULL) {
      908 +                smbstat_fail(1, gettext("cannot retrieve smbsrv %s kstat\n"),
      909 +                    ks_name);
      910 +        }
      911 +
      912 +        info = smbstat_srv_info.si_clsh;
      913 +        for (i = 0; i < SMBSRV_CLSH__NREQ; i++) {
      914 +                (void) strlcpy(info[i].ri_name, kr_names[i],
      915 +                    sizeof (info[i].ri_name));
      916 +        }
      917 +}
      918 +
      919 +static void
      920 +smbstat_clsh_fini(void)
      921 +{
      922 +        smbstat_clsh_ksp = NULL;
      923 +}
      924 +
      925 +/*
      926 + * smbstat_clsh_snapshot
      927 + */
      928 +static void
      929 +smbstat_clsh_snapshot(void)
      930 +{
      931 +        smbstat_clsh_snapshot_t *curr;
      932 +
      933 +        if (smbstat_clsh_ksp == NULL)
      934 +                return;
      935 +
      936 +        curr = smbstat_clsh_current_snapshot();
      937 +
      938 +        if ((kstat_read(smbstat_ksc, smbstat_clsh_ksp, NULL) == -1) ||
      939 +            (smbstat_clsh_ksp->ks_data_size != sizeof (curr->cs_data)))
      940 +                smbstat_fail(1, gettext("kstat_read('%s') failed"),
      941 +                    smbstat_clsh_ksp->ks_name);
      942 +
      943 +        curr->cs_snaptime = smbstat_clsh_ksp->ks_snaptime;
      944 +
      945 +        bcopy(smbstat_clsh_ksp->ks_data, &curr->cs_data,
      946 +            sizeof (curr->cs_data));
      947 +}
      948 +
      949 +/*
      950 + * smbstat_clsh_process
      951 + */
      952 +static void
      953 +smbstat_clsh_process(void)
      954 +{
      955 +        smbstat_clsh_snapshot_t *curr, *prev;
      956 +        boolean_t               firstcall;
      957 +        int     idx;
      958 +
      959 +        curr = smbstat_clsh_current_snapshot();
      960 +        prev = smbstat_clsh_previous_snapshot();
      961 +        firstcall = (prev->cs_snaptime == 0);
      962 +
      963 +
      964 +        for (idx = 0; idx < SMBSRV_CLSH__NREQ; idx++) {
      965 +                smbstat_srv_process_one_req(
      966 +                    &smbstat_srv_info.si_clsh[idx],
      967 +                    &curr->cs_data.ks_clsh[idx],
      968 +                    &prev->cs_data.ks_clsh[idx],
      969 +                    firstcall);
      970 +        }
      971 +}
      972 +
      973 +/*
      974 + * smbstat_clsh_current_snapshot
      975 + */
      976 +static smbstat_clsh_snapshot_t *
      977 +smbstat_clsh_current_snapshot(void)
      978 +{
      979 +        return (&smbstat_clsh_snapshots[smbstat_snapshot_idx]);
      980 +}
      981 +
      982 +static smbstat_clsh_snapshot_t *
      983 +smbstat_clsh_previous_snapshot(void)
      984 +{
      985 +        int     idx;
      986 +
      987 +        idx = (smbstat_snapshot_idx - 1) & SMBSTAT_SNAPSHOT_MASK;
      988 +        return (&smbstat_clsh_snapshots[idx]);
      989 +}
      990 +
      991 +/*
 795  992   * smbstat_srv_init
 796  993   */
 797  994  static void
 798  995  smbstat_srv_init(void)
 799  996  {
 800  997          smbstat_srv_ksp = kstat_lookup(smbstat_ksc, SMBSRV_KSTAT_MODULE,
 801      -            getzoneid(), SMBSRV_KSTAT_STATISTICS);
      998 +            -1, SMBSRV_KSTAT_STATISTICS);
 802  999          if (smbstat_srv_ksp == NULL)
 803 1000                  smbstat_fail(1, gettext("cannot retrieve smbsrv kstat\n"));
 804 1001  }
 805 1002  
 806 1003  /*
 807 1004   * smbstat_srv_fini
 808 1005   */
 809 1006  static void
 810 1007  smbstat_srv_fini(void)
 811 1008  {
↓ open down ↓ 213 lines elided ↑ open up ↑
1025 1222  smbstat_srv_process_requests(
1026 1223      smbstat_srv_snapshot_t      *curr,
1027 1224      smbstat_srv_snapshot_t      *prev)
1028 1225  {
1029 1226          smbstat_req_info_t      *info;
1030 1227          smb_kstat_req_t         *curr_req;
1031 1228          smb_kstat_req_t         *prev_req;
1032 1229          int                     i, idx;
1033 1230          boolean_t       firstcall = (prev->ss_snaptime == 0);
1034 1231  
1035      -        for (i = 0; i < SMB_COM_NUM; i++) {
     1232 +        for (i = 0; i < SMBSRV_KS_NREQS1; i++) {
1036 1233                  info = &smbstat_srv_info.si_reqs1[i];
1037 1234                  idx = info[i].ri_opcode & 0xFF;
1038 1235                  curr_req = &curr->ss_data.ks_reqs1[idx];
1039 1236                  prev_req = &prev->ss_data.ks_reqs1[idx];
1040 1237                  smbstat_srv_process_one_req(
1041 1238                      info, curr_req, prev_req, firstcall);
1042 1239          }
1043 1240  
1044      -        for (i = 0; i < SMB2__NCMDS; i++) {
     1241 +        for (i = 0; i < SMBSRV_KS_NREQS2; i++) {
1045 1242                  info = &smbstat_srv_info.si_reqs2[i];
1046 1243                  curr_req = &curr->ss_data.ks_reqs2[i];
1047 1244                  prev_req = &prev->ss_data.ks_reqs2[i];
1048 1245                  smbstat_srv_process_one_req(
1049 1246                      info, curr_req, prev_req, firstcall);
1050 1247          }
1051 1248  }
1052 1249  
1053 1250  static void
1054 1251  smbstat_srv_process_one_req(
↓ open down ↓ 37 lines elided ↑ open up ↑
1092 1289          if (nrqs > 0) {
1093 1290                  info->ri_stddev /= nrqs;
1094 1291                  info->ri_stddev = sqrt(info->ri_stddev);
1095 1292          } else {
1096 1293                  info->ri_stddev = 0;
1097 1294          }
1098 1295          info->ri_stddev /= NANOSEC;
1099 1296          info->ri_mean /= NANOSEC;
1100 1297  }
1101 1298  
1102      -
1103 1299  /*
1104 1300   * smbstat_srv_current_snapshot
1105 1301   *
1106 1302   * Returns the current snapshot.
1107 1303   */
1108 1304  static smbstat_srv_snapshot_t *
1109 1305  smbstat_srv_current_snapshot(void)
1110 1306  {
1111 1307          return (&smbstat_srv_snapshots[smbstat_snapshot_idx]);
1112 1308  }
↓ open down ↓ 158 lines elided ↑ open up ↑
1271 1467          smbstat_srv_snapshot_t  *ss;
1272 1468          smbstat_req_info_t      *info;
1273 1469          smb_kstat_req_t         *reqs;
1274 1470          int                     i;
1275 1471  
1276 1472          smbstat_srv_snapshot();
1277 1473          ss = smbstat_srv_current_snapshot();
1278 1474  
1279 1475          reqs = ss->ss_data.ks_reqs1;
1280 1476          info = smbstat_srv_info.si_reqs1;
1281      -        for (i = 0; i < SMB_COM_NUM; i++) {
     1477 +        for (i = 0; i < SMBSRV_KS_NREQS1; i++) {
1282 1478                  (void) strlcpy(info[i].ri_name, reqs[i].kr_name,
1283 1479                      sizeof (reqs[i].kr_name));
1284 1480                  info[i].ri_opcode = i;
1285 1481          }
1286 1482          if (smbstat_opt_n)
1287      -                qsort(info, SMB_COM_NUM, sizeof (smbstat_req_info_t),
     1483 +                qsort(info, SMBSRV_KS_NREQS1, sizeof (smbstat_req_info_t),
1288 1484                      smbstat_req_cmp_name);
1289 1485  
1290 1486          reqs = ss->ss_data.ks_reqs2;
1291 1487          info = smbstat_srv_info.si_reqs2;
1292      -        for (i = 0; i < SMB2__NCMDS; i++) {
     1488 +        for (i = 0; i < SMBSRV_KS_NREQS2; i++) {
1293 1489                  (void) strlcpy(info[i].ri_name, reqs[i].kr_name,
1294 1490                      sizeof (reqs[i].kr_name));
1295 1491                  info[i].ri_opcode = i;
1296 1492          }
1297 1493          if (smbstat_opt_n)
1298      -                qsort(info, SMB2__NCMDS, sizeof (smbstat_req_info_t),
     1494 +                qsort(info, SMBSRV_KS_NREQS2, sizeof (smbstat_req_info_t),
1299 1495                      smbstat_req_cmp_name);
1300 1496  }
1301 1497  
1302 1498  /*
1303 1499   * Return the number of ticks delta between two hrtime_t
1304 1500   * values. Attempt to cater for various kinds of overflow
1305 1501   * in hrtime_t - no matter how improbable.
1306 1502   */
1307 1503  static double
1308 1504  smbstat_hrtime_delta(hrtime_t old, hrtime_t new)
↓ open down ↓ 58 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX