Print this page
OS-276 global zone duplicate kstat when two zones have same vnic name

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/flowstat/flowstat.c
          +++ new/usr/src/cmd/flowstat/flowstat.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   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   23   * Use is subject to license terms.
       24 + * Copyright 2011 Joyent, Inc.  All rights reserved.
  24   25   */
  25   26  
  26   27  #include <stdio.h>
  27   28  #include <locale.h>
  28   29  #include <stdarg.h>
  29   30  #include <stdlib.h>
  30   31  #include <fcntl.h>
  31   32  #include <string.h>
  32   33  #include <stropts.h>
  33   34  #include <errno.h>
↓ open down ↓ 149 lines elided ↑ open up ↑
 183  184  
 184  185  static char *progname;
 185  186  
 186  187  /*
 187  188   * Handle to libdladm.  Opened in main() before the sub-command
 188  189   * specific function is called.
 189  190   */
 190  191  static dladm_handle_t handle = NULL;
 191  192  
 192  193  const char *usage_ermsg = "flowstat [-r | -t] [-i interval] "
 193      -            "[-l link] [flow]\n"
      194 +            "[-l link] [-z zonename] [flow]\n"
 194  195              "       flowstat [-S] [-A] [-i interval] [-p] [ -o field[,...]]\n"
 195      -            "                [-u R|K|M|G|T|P] [-l link] [flow]\n"
      196 +            "                [-u R|K|M|G|T|P] [-l link] [-z zonename] [flow]\n"
 196  197              "       flowstat -h [-a] [-d] [-F format]"
 197  198              " [-s <DD/MM/YYYY,HH:MM:SS>]\n"
 198  199              "                [-e <DD/MM/YYYY,HH:MM:SS>] -f <logfile> "
 199  200              "[<flow>]";
 200  201  
 201  202  static void
 202  203  usage(void)
 203  204  {
 204  205          (void) fprintf(stderr, "%s\n", gettext(usage_ermsg));
 205  206  
↓ open down ↓ 343 lines elided ↑ open up ↑
 549  550          boolean_t               S_arg = B_FALSE;
 550  551          boolean_t               flow_arg = B_FALSE;
 551  552          datalink_id_t           linkid = DATALINK_ALL_LINKID;
 552  553          char                    linkname[MAXLINKNAMELEN];
 553  554          char                    flowname[MAXFLOWNAMELEN];
 554  555          uint32_t                interval = 0;
 555  556          char                    unit = '\0';
 556  557          show_flow_state_t       state;
 557  558          char                    *fields_str = NULL;
 558  559          char                    *o_fields_str = NULL;
      560 +        char                    *zonename = NULL;
 559  561  
 560  562          char                    *total_stat_fields =
 561  563              "flow,ipkts,rbytes,ierrs,opkts,obytes,oerrs";
 562  564          char                    *rx_stat_fields =
 563  565              "flow,ipkts,rbytes,ierrs";
 564  566          char                    *tx_stat_fields =
 565  567              "flow,opkts,obytes,oerrs";
 566  568  
 567  569          ofmt_handle_t           ofmt;
 568  570          ofmt_status_t           oferr;
↓ open down ↓ 6 lines elided ↑ open up ↑
 575  577  #define TEXT_DOMAIN "SYS_TEST"
 576  578  #endif
 577  579          (void) textdomain(TEXT_DOMAIN);
 578  580  
 579  581          progname = argv[0];
 580  582  
 581  583          /* Open the libdladm handle */
 582  584          if ((status = dladm_open(&handle)) != DLADM_STATUS_OK)
 583  585                  die_dlerr(status, "could not open /dev/dld");
 584  586  
      587 +        linkname[0] = '\0';
 585  588          bzero(&state, sizeof (state));
 586  589  
 587  590          opterr = 0;
 588      -        while ((option = getopt_long(argc, argv, ":rtApSi:o:u:l:h",
      591 +        while ((option = getopt_long(argc, argv, ":rtApSi:o:u:l:hz:",
 589  592              NULL, NULL)) != -1) {
 590  593                  switch (option) {
 591  594                  case 'r':
 592  595                          if (r_arg)
 593  596                                  die_optdup(option);
 594  597  
 595  598                          r_arg = B_TRUE;
 596  599                          break;
 597  600                  case 't':
 598  601                          if (t_arg)
↓ open down ↓ 36 lines elided ↑ open up ↑
 635  638  
 636  639                          u_arg = B_TRUE;
 637  640                          if (!flowstat_unit(optarg, &unit))
 638  641                                  die("invalid unit value '%s',"
 639  642                                      "unit must be R|K|M|G|T|P", optarg);
 640  643                          break;
 641  644                  case 'l':
 642  645                          if (strlcpy(linkname, optarg, MAXLINKNAMELEN)
 643  646                              >= MAXLINKNAMELEN)
 644  647                                  die("link name too long\n");
 645      -                        if (dladm_name2info(handle, linkname, &linkid, NULL,
 646      -                            NULL, NULL) != DLADM_STATUS_OK)
 647      -                                die("invalid link '%s'", linkname);
 648  648                          break;
 649  649                  case 'h':
 650  650                          if (r_arg || t_arg || p_arg || o_arg || u_arg ||
 651  651                              i_arg || S_arg || A_arg) {
 652  652                                  die("the option -h is not compatible with "
 653  653                                      "-r, -t, -p, -o, -u, -i, -S, -A");
 654  654                          }
 655  655                          do_show_history(argc, argv);
 656  656                          return (0);
 657  657                          break;
      658 +                case 'z':
      659 +                        zonename = optarg;
      660 +                        break;
 658  661                  default:
 659  662                          die_opterr(optopt, option, usage_ermsg);
 660  663                          break;
 661  664                  }
 662  665          }
 663  666  
 664  667          if (r_arg && t_arg)
 665  668                  die("the option -t and -r are not compatible");
 666  669  
 667  670          if (u_arg && p_arg)
↓ open down ↓ 8 lines elided ↑ open up ↑
 676  679          if (S_arg &&
 677  680              (r_arg || t_arg || p_arg || o_arg || u_arg))
 678  681                  die("the option -S is not compatible with "
 679  682                      "-r, -t, -p, -o, -u");
 680  683  
 681  684          if (A_arg &&
 682  685              (r_arg || t_arg || p_arg || o_arg || u_arg || i_arg))
 683  686                  die("the option -A is not compatible with "
 684  687                      "-r, -t, -p, -o, -u, -i");
 685  688  
      689 +        if (linkname[0] != '\0') {
      690 +                if (dladm_zname2info(handle, zonename, linkname, &linkid, NULL,
      691 +                    NULL, NULL) != DLADM_STATUS_OK)
      692 +                        die("invalid link '%s'", linkname);
      693 +        }
      694 +
 686  695          /* get flow name (optional last argument) */
 687  696          if (optind == (argc-1)) {
 688  697                  if (strlcpy(flowname, argv[optind], MAXFLOWNAMELEN)
 689  698                      >= MAXFLOWNAMELEN)
 690  699                          die("flow name too long");
 691  700                  flow_arg = B_TRUE;
 692  701          } else if (optind != argc) {
 693  702                  usage();
 694  703          }
 695  704  
↓ open down ↓ 454 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX