Print this page
4347 ZPL can use dmu_tx_assign(TXG_WAIT)
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/zfs_znode.c
          +++ new/usr/src/uts/common/fs/zfs/zfs_znode.c
↓ open down ↓ 1461 lines elided ↑ open up ↑
1462 1462           */
1463 1463          rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
1464 1464  
1465 1465          /*
1466 1466           * Nothing to do if file already at desired length.
1467 1467           */
1468 1468          if (end <= zp->z_size) {
1469 1469                  zfs_range_unlock(rl);
1470 1470                  return (0);
1471 1471          }
1472      -top:
1473 1472          tx = dmu_tx_create(zfsvfs->z_os);
1474 1473          dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1475 1474          zfs_sa_upgrade_txholds(tx, zp);
1476 1475          if (end > zp->z_blksz &&
1477 1476              (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
1478 1477                  /*
1479 1478                   * We are growing the file past the current block size.
1480 1479                   */
1481 1480                  if (zp->z_blksz > zp->z_zfsvfs->z_max_blksz) {
1482 1481                          ASSERT(!ISP2(zp->z_blksz));
1483 1482                          newblksz = MIN(end, SPA_MAXBLOCKSIZE);
1484 1483                  } else {
1485 1484                          newblksz = MIN(end, zp->z_zfsvfs->z_max_blksz);
1486 1485                  }
1487 1486                  dmu_tx_hold_write(tx, zp->z_id, 0, newblksz);
1488 1487          } else {
1489 1488                  newblksz = 0;
1490 1489          }
1491 1490  
1492      -        error = dmu_tx_assign(tx, TXG_NOWAIT);
     1491 +        error = dmu_tx_assign(tx, TXG_WAIT);
1493 1492          if (error) {
1494      -                if (error == ERESTART) {
1495      -                        dmu_tx_wait(tx);
1496      -                        dmu_tx_abort(tx);
1497      -                        goto top;
1498      -                }
1499 1493                  dmu_tx_abort(tx);
1500 1494                  zfs_range_unlock(rl);
1501 1495                  return (error);
1502 1496          }
1503 1497  
1504 1498          if (newblksz)
1505 1499                  zfs_grow_blocksize(zp, newblksz, tx);
1506 1500  
1507 1501          zp->z_size = end;
1508 1502  
↓ open down ↓ 76 lines elided ↑ open up ↑
1585 1579          if (end >= zp->z_size) {
1586 1580                  zfs_range_unlock(rl);
1587 1581                  return (0);
1588 1582          }
1589 1583  
1590 1584          error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end,  -1);
1591 1585          if (error) {
1592 1586                  zfs_range_unlock(rl);
1593 1587                  return (error);
1594 1588          }
1595      -top:
1596 1589          tx = dmu_tx_create(zfsvfs->z_os);
1597 1590          dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1598 1591          zfs_sa_upgrade_txholds(tx, zp);
1599      -        error = dmu_tx_assign(tx, TXG_NOWAIT);
     1592 +        error = dmu_tx_assign(tx, TXG_WAIT);
1600 1593          if (error) {
1601      -                if (error == ERESTART) {
1602      -                        dmu_tx_wait(tx);
1603      -                        dmu_tx_abort(tx);
1604      -                        goto top;
1605      -                }
1606 1594                  dmu_tx_abort(tx);
1607 1595                  zfs_range_unlock(rl);
1608 1596                  return (error);
1609 1597          }
1610 1598  
1611 1599          zp->z_size = end;
1612 1600          SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs),
1613 1601              NULL, &zp->z_size, sizeof (zp->z_size));
1614 1602  
1615 1603          if (end == 0) {
↓ open down ↓ 86 lines elided ↑ open up ↑
1702 1690                  if ((error = zfs_free_range(zp, off, len)) == 0 &&
1703 1691                      off + len > zp->z_size)
1704 1692                          error = zfs_extend(zp, off+len);
1705 1693          }
1706 1694          if (error || !log)
1707 1695                  return (error);
1708 1696  log:
1709 1697          tx = dmu_tx_create(zfsvfs->z_os);
1710 1698          dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1711 1699          zfs_sa_upgrade_txholds(tx, zp);
1712      -        error = dmu_tx_assign(tx, TXG_NOWAIT);
     1700 +        error = dmu_tx_assign(tx, TXG_WAIT);
1713 1701          if (error) {
1714      -                if (error == ERESTART) {
1715      -                        dmu_tx_wait(tx);
1716      -                        dmu_tx_abort(tx);
1717      -                        goto log;
1718      -                }
1719 1702                  dmu_tx_abort(tx);
1720 1703                  return (error);
1721 1704          }
1722 1705  
1723 1706          SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, mtime, 16);
1724 1707          SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, ctime, 16);
1725 1708          SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
1726 1709              NULL, &zp->z_pflags, 8);
1727 1710          zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime, B_TRUE);
1728 1711          error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
↓ open down ↓ 415 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX