MCPcopy Create free account
hub / github.com/F-Stack/f-stack / zfs_extend

Function zfs_extend

freebsd/contrib/openzfs/module/os/linux/zfs/zfs_znode.c:1479–1544  ·  view source on GitHub ↗

* Increase the file length * * IN: zp - znode of file to free data in. * end - new end-of-file * * RETURN: 0 on success, error code on failure */

Source from the content-addressed store, hash-verified

1477 * RETURN: 0 on success, error code on failure
1478 */
1479static int
1480zfs_extend(znode_t *zp, uint64_t end)
1481{
1482 zfsvfs_t *zfsvfs = ZTOZSB(zp);
1483 dmu_tx_t *tx;
1484 zfs_locked_range_t *lr;
1485 uint64_t newblksz;
1486 int error;
1487
1488 /*
1489 * We will change zp_size, lock the whole file.
1490 */
1491 lr = zfs_rangelock_enter(&zp->z_rangelock, 0, UINT64_MAX, RL_WRITER);
1492
1493 /*
1494 * Nothing to do if file already at desired length.
1495 */
1496 if (end <= zp->z_size) {
1497 zfs_rangelock_exit(lr);
1498 return (0);
1499 }
1500 tx = dmu_tx_create(zfsvfs->z_os);
1501 dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
1502 zfs_sa_upgrade_txholds(tx, zp);
1503 if (end > zp->z_blksz &&
1504 (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
1505 /*
1506 * We are growing the file past the current block size.
1507 */
1508 if (zp->z_blksz > ZTOZSB(zp)->z_max_blksz) {
1509 /*
1510 * File's blocksize is already larger than the
1511 * "recordsize" property. Only let it grow to
1512 * the next power of 2.
1513 */
1514 ASSERT(!ISP2(zp->z_blksz));
1515 newblksz = MIN(end, 1 << highbit64(zp->z_blksz));
1516 } else {
1517 newblksz = MIN(end, ZTOZSB(zp)->z_max_blksz);
1518 }
1519 dmu_tx_hold_write(tx, zp->z_id, 0, newblksz);
1520 } else {
1521 newblksz = 0;
1522 }
1523
1524 error = dmu_tx_assign(tx, TXG_WAIT);
1525 if (error) {
1526 dmu_tx_abort(tx);
1527 zfs_rangelock_exit(lr);
1528 return (error);
1529 }
1530
1531 if (newblksz)
1532 zfs_grow_blocksize(zp, newblksz, tx);
1533
1534 zp->z_size = end;
1535
1536 VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(ZTOZSB(zp)),

Callers 1

zfs_freespFunction · 0.70

Calls 12

zfs_rangelock_enterFunction · 0.85
zfs_rangelock_exitFunction · 0.85
dmu_tx_createFunction · 0.85
dmu_tx_hold_saFunction · 0.85
zfs_sa_upgrade_txholdsFunction · 0.85
dmu_tx_hold_writeFunction · 0.85
dmu_tx_assignFunction · 0.85
dmu_tx_abortFunction · 0.85
sa_updateFunction · 0.85
dmu_tx_commitFunction · 0.85
zfs_grow_blocksizeFunction · 0.70
highbit64Function · 0.50

Tested by

no test coverage detected