Print this page
OS-3342+co
OS-722
OS-478 -- lint
OS-375-1
OS-328 dlmgmtd/mac_link_flow_add() deadlock
OS-249

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/dlmgmtd/dlmgmt_door.c
          +++ new/usr/src/cmd/dlmgmtd/dlmgmt_door.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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright (c) 2011, Joyent Inc. All rights reserved.
  24   25   */
  25   26  
  26   27  /*
  27   28   * Main door handler functions used by dlmgmtd to process the different door
  28   29   * call requests. Door call requests can come from the user-land applications,
  29   30   * or from the kernel.
  30   31   *
  31   32   * Note on zones handling:
  32   33   *
  33   34   * There are two zoneid's associated with a link.  One is the zoneid of the
↓ open down ↓ 17 lines elided ↑ open up ↑
  51   52  #include <errno.h>
  52   53  #include <priv_utils.h>
  53   54  #include <stdlib.h>
  54   55  #include <strings.h>
  55   56  #include <syslog.h>
  56   57  #include <sys/sysevent/eventdefs.h>
  57   58  #include <zone.h>
  58   59  #include <libsysevent.h>
  59   60  #include <libdlmgmt.h>
  60   61  #include <librcm.h>
       62 +#include <sys/types.h>
       63 +#include <sys/stat.h>
       64 +#include <fcntl.h>
       65 +#include <unistd.h>
  61   66  #include "dlmgmt_impl.h"
  62   67  
  63   68  typedef void dlmgmt_door_handler_t(void *, void *, size_t *, zoneid_t,
  64   69      ucred_t *);
  65   70  
  66   71  typedef struct dlmgmt_door_info_s {
  67   72          uint_t                  di_cmd;
  68   73          size_t                  di_reqsz;
  69   74          size_t                  di_acksz;
  70   75          dlmgmt_door_handler_t   *di_handler;
↓ open down ↓ 301 lines elided ↑ open up ↑
 372  377          dlmgmt_table_lock(B_TRUE);
 373  378  
 374  379          if ((linkp = link_by_id(linkid, zoneid)) == NULL) {
 375  380                  err = ENOENT;
 376  381                  goto done;
 377  382          }
 378  383  
 379  384          if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
 380  385                  goto done;
 381  386  
      387 +        if (linkp->ll_tomb == B_TRUE) {
      388 +                err = EINPROGRESS;
      389 +                goto done;
      390 +        }
      391 +
 382  392          if (((linkp->ll_flags & flags) & DLMGMT_ACTIVE) != 0) {
 383  393                  if ((err = dlmgmt_delete_db_entry(linkp, DLMGMT_ACTIVE)) != 0)
 384  394                          goto done;
 385  395                  dflags |= DLMGMT_ACTIVE;
 386  396          }
 387  397  
 388  398          if (((linkp->ll_flags & flags) & DLMGMT_PERSIST) != 0) {
 389  399                  if ((err = dlmgmt_delete_db_entry(linkp, DLMGMT_PERSIST)) != 0)
 390  400                          goto done;
 391  401                  dflags |= DLMGMT_PERSIST;
↓ open down ↓ 40 lines elided ↑ open up ↑
 432  442  /* ARGSUSED */
 433  443  static void
 434  444  dlmgmt_getlinkid(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
 435  445      ucred_t *cred)
 436  446  {
 437  447          dlmgmt_door_getlinkid_t *getlinkid = argp;
 438  448          dlmgmt_getlinkid_retval_t *retvalp = retp;
 439  449          dlmgmt_link_t           *linkp;
 440  450          int                     err = 0;
 441  451  
      452 +        /* Enable the global zone to lookup links it has given away. */
      453 +        if (zoneid == GLOBAL_ZONEID && getlinkid->ld_zoneid != -1)
      454 +                zoneid = getlinkid->ld_zoneid;
      455 +
 442  456          /*
 443  457           * Hold the reader lock to access the link
 444  458           */
 445  459          dlmgmt_table_lock(B_FALSE);
 446  460  
 447  461          if ((linkp = link_by_name(getlinkid->ld_link, zoneid)) == NULL) {
 448  462                  /*
 449  463                   * The link does not exist in this zone.
 450  464                   */
 451  465                  err = ENOENT;
↓ open down ↓ 189 lines elided ↑ open up ↑
 641  655           */
 642  656          dlmgmt_table_lock(B_TRUE);
 643  657          if ((linkp = link_by_id(remapid->ld_linkid, zoneid)) == NULL) {
 644  658                  err = ENOENT;
 645  659                  goto done;
 646  660          }
 647  661  
 648  662          if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
 649  663                  goto done;
 650  664  
      665 +        if (linkp->ll_tomb == B_TRUE) {
      666 +                err = EBUSY;
      667 +                goto done;
      668 +        }
      669 +
      670 +
 651  671          if (link_by_name(remapid->ld_link, linkp->ll_zoneid) != NULL) {
 652  672                  err = EEXIST;
 653  673                  goto done;
 654  674          }
 655  675  
 656  676          (void) strlcpy(oldname, linkp->ll_link, MAXLINKNAMELEN);
 657  677          avl_remove(&dlmgmt_name_avl, linkp);
 658  678          (void) strlcpy(linkp->ll_link, remapid->ld_link, MAXLINKNAMELEN);
 659  679          avl_add(&dlmgmt_name_avl, linkp);
 660  680          renamed = B_TRUE;
↓ open down ↓ 41 lines elided ↑ open up ↑
 702  722           */
 703  723          dlmgmt_table_lock(B_TRUE);
 704  724          if ((linkp = link_by_id(upid->ld_linkid, zoneid)) == NULL) {
 705  725                  err = ENOENT;
 706  726                  goto done;
 707  727          }
 708  728  
 709  729          if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
 710  730                  goto done;
 711  731  
      732 +        if (linkp->ll_tomb == B_TRUE) {
      733 +                err = EBUSY;
      734 +                goto done;
      735 +        }
      736 +
 712  737          if (linkp->ll_flags & DLMGMT_ACTIVE) {
 713  738                  err = EINVAL;
 714  739                  goto done;
 715  740          }
 716  741  
 717  742          if ((err = link_activate(linkp)) == 0) {
 718  743                  (void) dlmgmt_write_db_entry(linkp->ll_link, linkp,
 719  744                      DLMGMT_ACTIVE);
 720  745          }
 721  746  done:
↓ open down ↓ 487 lines elided ↑ open up ↑
1209 1234          }
1210 1235  
1211 1236          if ((linkp = link_by_id(linkid, zoneid)) == NULL) {
1212 1237                  err = ENOENT;
1213 1238                  goto done;
1214 1239          }
1215 1240  
1216 1241          if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
1217 1242                  goto done;
1218 1243  
     1244 +        if (linkp->ll_tomb == B_TRUE) {
     1245 +                err = EBUSY;
     1246 +                goto done;
     1247 +        }
     1248 +
1219 1249          /* We can only assign an active link to a zone. */
1220 1250          if (!(linkp->ll_flags & DLMGMT_ACTIVE)) {
1221 1251                  err = EINVAL;
1222 1252                  goto done;
1223 1253          }
1224 1254  
1225 1255          oldzoneid = linkp->ll_zoneid;
1226 1256          newzoneid = setzoneid->ld_zoneid;
1227 1257  
1228 1258          if (oldzoneid == newzoneid)
↓ open down ↓ 9 lines elided ↑ open up ↑
1238 1268                  goto done;
1239 1269          }
1240 1270  
1241 1271          if (oldzoneid != GLOBAL_ZONEID) {
1242 1272                  if (zone_remove_datalink(oldzoneid, linkid) != 0) {
1243 1273                          err = errno;
1244 1274                          dlmgmt_log(LOG_WARNING, "unable to remove link %d from "
1245 1275                              "zone %d: %s", linkid, oldzoneid, strerror(err));
1246 1276                          goto done;
1247 1277                  }
1248      -                avl_remove(&dlmgmt_loan_avl, linkp);
     1278 +
     1279 +                if (newzoneid == GLOBAL_ZONEID && linkp->ll_onloan) {
     1280 +                        /*
     1281 +                         * We can only reassign a loaned VNIC back to the
     1282 +                         * global zone when the zone is shutting down, since
     1283 +                         * otherwise the VNIC is in use by the zone and will be
     1284 +                         * busy.  Leave the VNIC assigned to the zone so we can
     1285 +                         * still see it and delete it when dlmgmt_zonehalt()
     1286 +                         * runs.
     1287 +                         */
     1288 +                        goto done;
     1289 +                }
     1290 +
1249 1291                  linkp->ll_onloan = B_FALSE;
1250 1292          }
1251 1293          if (newzoneid != GLOBAL_ZONEID) {
1252 1294                  if (zone_add_datalink(newzoneid, linkid) != 0) {
1253 1295                          err = errno;
1254 1296                          dlmgmt_log(LOG_WARNING, "unable to add link %d to zone "
1255 1297                              "%d: %s", linkid, newzoneid, strerror(err));
1256 1298                          (void) zone_add_datalink(oldzoneid, linkid);
1257 1299                          goto done;
1258 1300                  }
1259      -                avl_add(&dlmgmt_loan_avl, linkp);
1260 1301                  linkp->ll_onloan = B_TRUE;
1261 1302          }
1262 1303  
1263 1304          avl_remove(&dlmgmt_name_avl, linkp);
1264 1305          linkp->ll_zoneid = newzoneid;
1265 1306          avl_add(&dlmgmt_name_avl, linkp);
1266 1307  
1267 1308  done:
1268 1309          dlmgmt_table_unlock();
1269 1310          retvalp->lr_err = err;
↓ open down ↓ 32 lines elided ↑ open up ↑
1302 1343  }
1303 1344  
1304 1345  /* ARGSUSED */
1305 1346  static void
1306 1347  dlmgmt_zonehalt(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
1307 1348      ucred_t *cred)
1308 1349  {
1309 1350          int                     err = 0;
1310 1351          dlmgmt_door_zonehalt_t  *zonehalt = argp;
1311 1352          dlmgmt_zonehalt_retval_t *retvalp = retp;
     1353 +        static char my_pid[10];
1312 1354  
     1355 +        if (my_pid[0] == NULL)
     1356 +                (void) snprintf(my_pid, sizeof (my_pid), "%d\n", getpid());
     1357 +
1313 1358          if ((err = dlmgmt_checkprivs(0, cred)) == 0) {
1314 1359                  if (zoneid != GLOBAL_ZONEID) {
1315 1360                          err = EACCES;
1316 1361                  } else if (zonehalt->ld_zoneid == GLOBAL_ZONEID) {
1317 1362                          err = EINVAL;
1318 1363                  } else {
     1364 +                        /*
     1365 +                         * dls and mac don't honor the locking rules defined in
     1366 +                         * mac. In order to try and make that case less likely
     1367 +                         * to happen, we try to serialize some of the zone
     1368 +                         * activity here between dlmgmtd and the brands on
     1369 +                         * /etc/dladm/zone.lck
     1370 +                         */
     1371 +                        int fd;
     1372 +
     1373 +                        while ((fd = open(ZONE_LOCK, O_WRONLY |
     1374 +                            O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0)
     1375 +                        (void) sleep(1);
     1376 +                        (void) write(fd, my_pid, sizeof (my_pid));
     1377 +                        (void) close(fd);
     1378 +
1319 1379                          dlmgmt_table_lock(B_TRUE);
1320 1380                          dlmgmt_db_fini(zonehalt->ld_zoneid);
1321 1381                          dlmgmt_table_unlock();
     1382 +
     1383 +                        (void) unlink(ZONE_LOCK);
1322 1384                  }
1323 1385          }
1324 1386          retvalp->lr_err = err;
1325 1387  }
1326 1388  
1327 1389  static dlmgmt_door_info_t i_dlmgmt_door_info_tbl[] = {
1328 1390          { DLMGMT_CMD_DLS_CREATE, sizeof (dlmgmt_upcall_arg_create_t),
1329 1391              sizeof (dlmgmt_create_retval_t), dlmgmt_upcall_create },
1330 1392          { DLMGMT_CMD_DLS_GETATTR, sizeof (dlmgmt_upcall_arg_getattr_t),
1331 1393              sizeof (dlmgmt_getattr_retval_t), dlmgmt_upcall_getattr },
↓ open down ↓ 117 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX