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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24 /*
25 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 */
27
28 #include <sys/dmu.h>
29 #include <sys/dmu_impl.h>
30 #include <sys/dbuf.h>
31 #include <sys/dmu_tx.h>
32 #include <sys/dmu_objset.h>
33 #include <sys/dsl_dataset.h> /* for dsl_dataset_block_freeable() */
34 #include <sys/dsl_dir.h> /* for dsl_dir_tempreserve_*() */
35 #include <sys/dsl_pool.h>
36 #include <sys/zap_impl.h> /* for fzap_default_block_shift */
37 #include <sys/spa.h>
38 #include <sys/sa.h>
39 #include <sys/sa_impl.h>
40 #include <sys/zfs_context.h>
41 #include <sys/varargs.h>
42
43 typedef void (*dmu_tx_hold_func_t)(dmu_tx_t *tx, struct dnode *dn,
44 uint64_t arg1, uint64_t arg2);
45
659 ASSERT(tx->tx_txg == 0);
660
661 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
662 object, THT_ZAP, add, (uintptr_t)name);
663 if (txh == NULL)
664 return;
665 dn = txh->txh_dnode;
666
667 dmu_tx_count_dnode(txh);
668
669 if (dn == NULL) {
670 /*
671 * We will be able to fit a new object's entries into one leaf
672 * block. So there will be at most 2 blocks total,
673 * including the header block.
674 */
675 dmu_tx_count_write(txh, 0, 2 << fzap_default_block_shift);
676 return;
677 }
678
679 ASSERT3P(dmu_ot[dn->dn_type].ot_byteswap, ==, zap_byteswap);
680
681 if (dn->dn_maxblkid == 0 && !add) {
682 blkptr_t *bp;
683
684 /*
685 * If there is only one block (i.e. this is a micro-zap)
686 * and we are not adding anything, the accounting is simple.
687 */
688 err = dmu_tx_check_ioerr(NULL, dn, 0, 0);
689 if (err) {
690 tx->tx_err = err;
691 return;
692 }
693
694 /*
695 * Use max block size here, since we don't know how much
696 * the size will change between now and the dbuf dirty call.
697 */
698 bp = &dn->dn_phys->dn_blkptr[0];
699 if (dsl_dataset_block_freeable(dn->dn_objset->os_dsl_dataset,
|
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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 */
26
27 #include <sys/dmu.h>
28 #include <sys/dmu_impl.h>
29 #include <sys/dbuf.h>
30 #include <sys/dmu_tx.h>
31 #include <sys/dmu_objset.h>
32 #include <sys/dsl_dataset.h> /* for dsl_dataset_block_freeable() */
33 #include <sys/dsl_dir.h> /* for dsl_dir_tempreserve_*() */
34 #include <sys/dsl_pool.h>
35 #include <sys/zap_impl.h> /* for fzap_default_block_shift */
36 #include <sys/spa.h>
37 #include <sys/sa.h>
38 #include <sys/sa_impl.h>
39 #include <sys/zfs_context.h>
40 #include <sys/varargs.h>
41
42 typedef void (*dmu_tx_hold_func_t)(dmu_tx_t *tx, struct dnode *dn,
43 uint64_t arg1, uint64_t arg2);
44
658 ASSERT(tx->tx_txg == 0);
659
660 txh = dmu_tx_hold_object_impl(tx, tx->tx_objset,
661 object, THT_ZAP, add, (uintptr_t)name);
662 if (txh == NULL)
663 return;
664 dn = txh->txh_dnode;
665
666 dmu_tx_count_dnode(txh);
667
668 if (dn == NULL) {
669 /*
670 * We will be able to fit a new object's entries into one leaf
671 * block. So there will be at most 2 blocks total,
672 * including the header block.
673 */
674 dmu_tx_count_write(txh, 0, 2 << fzap_default_block_shift);
675 return;
676 }
677
678 ASSERT3P(DMU_OT_BYTESWAP(dn->dn_type), ==, DMU_BSWAP_ZAP);
679
680 if (dn->dn_maxblkid == 0 && !add) {
681 blkptr_t *bp;
682
683 /*
684 * If there is only one block (i.e. this is a micro-zap)
685 * and we are not adding anything, the accounting is simple.
686 */
687 err = dmu_tx_check_ioerr(NULL, dn, 0, 0);
688 if (err) {
689 tx->tx_err = err;
690 return;
691 }
692
693 /*
694 * Use max block size here, since we don't know how much
695 * the size will change between now and the dbuf dirty call.
696 */
697 bp = &dn->dn_phys->dn_blkptr[0];
698 if (dsl_dataset_block_freeable(dn->dn_objset->os_dsl_dataset,
|