Deleted Added
full compact
zap_micro.c (321545) zap_micro.c (321547)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 1517 unchanged lines hidden (view full) ---

1526 zs->zs_num_entries = zap->zap_m.zap_num_entries;
1527 zs->zs_num_blocks = 1;
1528 } else {
1529 fzap_get_stats(zap, zs);
1530 }
1531 zap_unlockdir(zap, FTAG);
1532 return (0);
1533}
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 1517 unchanged lines hidden (view full) ---

1526 zs->zs_num_entries = zap->zap_m.zap_num_entries;
1527 zs->zs_num_blocks = 1;
1528 } else {
1529 fzap_get_stats(zap, zs);
1530 }
1531 zap_unlockdir(zap, FTAG);
1532 return (0);
1533}
1534
1535int
1536zap_count_write_by_dnode(dnode_t *dn, const char *name, int add,
1537 refcount_t *towrite, refcount_t *tooverwrite)
1538{
1539 zap_t *zap;
1540 int err = 0;
1541
1542 /*
1543 * Since, we don't have a name, we cannot figure out which blocks will
1544 * be affected in this operation. So, account for the worst case :
1545 * - 3 blocks overwritten: target leaf, ptrtbl block, header block
1546 * - 4 new blocks written if adding:
1547 * - 2 blocks for possibly split leaves,
1548 * - 2 grown ptrtbl blocks
1549 *
1550 * This also accommodates the case where an add operation to a fairly
1551 * large microzap results in a promotion to fatzap.
1552 */
1553 if (name == NULL) {
1554 (void) refcount_add_many(towrite,
1555 (3 + (add ? 4 : 0)) * SPA_OLD_MAXBLOCKSIZE, FTAG);
1556 return (err);
1557 }
1558
1559 /*
1560 * We lock the zap with adding == FALSE. Because, if we pass
1561 * the actual value of add, it could trigger a mzap_upgrade().
1562 * At present we are just evaluating the possibility of this operation
1563 * and hence we do not want to trigger an upgrade.
1564 */
1565 err = zap_lockdir_by_dnode(dn, NULL, RW_READER, TRUE, FALSE,
1566 FTAG, &zap);
1567 if (err != 0)
1568 return (err);
1569
1570 if (!zap->zap_ismicro) {
1571 zap_name_t *zn = zap_name_alloc(zap, name, 0);
1572 if (zn) {
1573 err = fzap_count_write(zn, add, towrite,
1574 tooverwrite);
1575 zap_name_free(zn);
1576 } else {
1577 /*
1578 * We treat this case as similar to (name == NULL)
1579 */
1580 (void) refcount_add_many(towrite,
1581 (3 + (add ? 4 : 0)) * SPA_OLD_MAXBLOCKSIZE, FTAG);
1582 }
1583 } else {
1584 /*
1585 * We are here if (name != NULL) and this is a micro-zap.
1586 * We account for the header block depending on whether it
1587 * is freeable.
1588 *
1589 * Incase of an add-operation it is hard to find out
1590 * if this add will promote this microzap to fatzap.
1591 * Hence, we consider the worst case and account for the
1592 * blocks assuming this microzap would be promoted to a
1593 * fatzap.
1594 *
1595 * 1 block overwritten : header block
1596 * 4 new blocks written : 2 new split leaf, 2 grown
1597 * ptrtbl blocks
1598 */
1599 if (dmu_buf_freeable(zap->zap_dbuf)) {
1600 (void) refcount_add_many(tooverwrite,
1601 MZAP_MAX_BLKSZ, FTAG);
1602 } else {
1603 (void) refcount_add_many(towrite,
1604 MZAP_MAX_BLKSZ, FTAG);
1605 }
1606
1607 if (add) {
1608 (void) refcount_add_many(towrite,
1609 4 * MZAP_MAX_BLKSZ, FTAG);
1610 }
1611 }
1612
1613 zap_unlockdir(zap, FTAG);
1614 return (err);
1615}