Print this page
OS-249

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libdladm/common/libdllink.c
          +++ new/usr/src/lib/libdladm/common/libdllink.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright (c) 2011, Joyent Inc. All rights reserved.
  23   24   */
  24   25  
  25   26  #include <sys/types.h>
  26   27  #include <unistd.h>
  27   28  #include <errno.h>
  28   29  #include <fcntl.h>
  29   30  #include <assert.h>
  30   31  #include <ctype.h>
  31   32  #include <strings.h>
  32   33  #include <sys/stat.h>
↓ open down ↓ 346 lines elided ↑ open up ↑
 379  380                  s = "unknown";
 380  381                  break;
 381  382          }
 382  383          (void) snprintf(buf, DLADM_STRSIZE, "%s", s);
 383  384          return (buf);
 384  385  }
 385  386  
 386  387  /*
 387  388   * Case 1: rename an existing link1 to a link2 that does not exist.
 388  389   * Result: <linkid1, link2>
      390 + * The zonename parameter is used to allow us to create a VNIC in the global
      391 + * zone which is assigned to a non-global zone.  Since there is a race condition
      392 + * in the create process if two VNICs have the same name, we need to rename it
      393 + * after it has been assigned to the zone.
 389  394   */
 390  395  static dladm_status_t
 391  396  i_dladm_rename_link_c1(dladm_handle_t handle, datalink_id_t linkid1,
 392      -    const char *link1, const char *link2, uint32_t flags)
      397 +    const char *link1, const char *link2, uint32_t flags, const char *zonename)
 393  398  {
 394  399          dld_ioc_rename_t        dir;
 395  400          dladm_status_t          status = DLADM_STATUS_OK;
 396  401  
 397  402          /*
 398  403           * Link is currently available. Check to see whether anything is
 399  404           * holding this link to prevent a rename operation.
 400  405           */
 401  406          if (flags & DLADM_OPT_ACTIVE) {
 402  407                  dir.dir_linkid1 = linkid1;
 403  408                  dir.dir_linkid2 = DATALINK_INVALID_LINKID;
 404  409                  (void) strlcpy(dir.dir_link, link2, MAXLINKNAMELEN);
      410 +                if (zonename != NULL)
      411 +                        dir.dir_zoneinit = B_TRUE;
      412 +                else
      413 +                        dir.dir_zoneinit = B_FALSE;
 405  414  
 406  415                  if (ioctl(dladm_dld_fd(handle), DLDIOC_RENAME, &dir) < 0) {
 407  416                          status = dladm_errno2status(errno);
 408  417                          return (status);
 409  418                  }
 410  419          }
 411  420  
 412  421          status = dladm_remap_datalink_id(handle, linkid1, link2);
 413  422          if (status != DLADM_STATUS_OK && (flags & DLADM_OPT_ACTIVE)) {
 414  423                  (void) strlcpy(dir.dir_link, link1, MAXLINKNAMELEN);
      424 +                dir.dir_zoneinit = B_FALSE;
 415  425                  (void) ioctl(dladm_dld_fd(handle), DLDIOC_RENAME, &dir);
 416  426          }
 417  427          return (status);
 418  428  }
 419  429  
 420  430  typedef struct link_hold_arg_s {
 421  431          datalink_id_t   linkid;
 422  432          datalink_id_t   holder;
 423  433          uint32_t        flags;
 424  434  } link_hold_arg_t;
↓ open down ↓ 76 lines elided ↑ open up ↑
 501  511                  return (DLADM_STATUS_LINKBUSY);
 502  512  
 503  513          /*
 504  514           * Send DLDIOC_RENAME to request to rename link1's linkid to
 505  515           * be linkid2. This will check whether link1 is used by any
 506  516           * aggregations or VLANs, or is held by any application. If yes,
 507  517           * return failure.
 508  518           */
 509  519          dir.dir_linkid1 = linkid1;
 510  520          dir.dir_linkid2 = linkid2;
      521 +        dir.dir_zoneinit = B_FALSE;
 511  522          if (ioctl(dladm_dld_fd(handle), DLDIOC_RENAME, &dir) < 0)
 512  523                  status = dladm_errno2status(errno);
 513  524  
 514  525          if (status != DLADM_STATUS_OK) {
 515  526                  return (status);
 516  527          }
 517  528  
 518  529          /*
 519  530           * Now change the phymaj, phyinst and devname associated with linkid1
 520  531           * to be associated with linkid2. Before doing that, the old active
↓ open down ↓ 89 lines elided ↑ open up ↑
 610  621                  status = dladm_write_conf(handle, conf);
 611  622          }
 612  623  
 613  624          dladm_destroy_conf(handle, conf);
 614  625  
 615  626  done:
 616  627          return (status);
 617  628  }
 618  629  
 619  630  dladm_status_t
 620      -dladm_rename_link(dladm_handle_t handle, const char *link1, const char *link2)
      631 +dladm_rename_link(dladm_handle_t handle, const char *zonename,
      632 +    const char *link1, const char *link2)
 621  633  {
 622  634          datalink_id_t           linkid1 = DATALINK_INVALID_LINKID;
 623  635          datalink_id_t           linkid2 = DATALINK_INVALID_LINKID;
 624  636          uint32_t                flags1, flags2;
 625  637          datalink_class_t        class1, class2;
 626  638          uint32_t                media1, media2;
 627  639          boolean_t               remphy2 = B_FALSE;
 628  640          dladm_status_t          status;
 629  641  
 630      -        (void) dladm_name2info(handle, link1, &linkid1, &flags1, &class1,
 631      -            &media1);
 632      -        if ((dladm_name2info(handle, link2, &linkid2, &flags2, &class2,
 633      -            &media2) == DLADM_STATUS_OK) && (class2 == DATALINK_CLASS_PHYS) &&
 634      -            (flags2 == DLADM_OPT_PERSIST)) {
      642 +        (void) dladm_zname2info(handle, zonename, link1, &linkid1, &flags1,
      643 +            &class1, &media1);
      644 +        if ((dladm_zname2info(handle, zonename, link2, &linkid2, &flags2,
      645 +            &class2, &media2) == DLADM_STATUS_OK) &&
      646 +            (class2 == DATALINK_CLASS_PHYS) && (flags2 == DLADM_OPT_PERSIST)) {
 635  647                  /*
 636  648                   * see whether link2 is a removed physical link.
 637  649                   */
 638  650                  remphy2 = B_TRUE;
 639  651          }
 640  652  
 641  653          if (linkid1 != DATALINK_INVALID_LINKID) {
 642  654                  if (linkid2 == DATALINK_INVALID_LINKID) {
 643  655                          /*
 644  656                           * case 1: rename an existing link to a link that
 645  657                           * does not exist.
 646  658                           */
 647  659                          status = i_dladm_rename_link_c1(handle, linkid1, link1,
 648      -                            link2, flags1);
      660 +                            link2, flags1, zonename);
 649  661                  } else if (remphy2) {
 650  662                          /*
 651  663                           * case 2: rename an available link to a REMOVED
 652  664                           * physical link. Return failure if link1 is not
 653  665                           * an active physical link.
 654  666                           */
 655  667                          if ((class1 != class2) || (media1 != media2) ||
 656  668                              !(flags1 & DLADM_OPT_ACTIVE)) {
 657  669                                  status = DLADM_STATUS_BADARG;
 658  670                          } else {
↓ open down ↓ 368 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX