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
   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 #include <sys/zfs_context.h>
  26 #include <sys/dbuf.h>
  27 #include <sys/dnode.h>
  28 #include <sys/dmu.h>
  29 #include <sys/dmu_tx.h>
  30 #include <sys/dmu_objset.h>
  31 #include <sys/dsl_dataset.h>
  32 #include <sys/spa.h>
  33 
  34 static void
  35 dnode_increase_indirection(dnode_t *dn, dmu_tx_t *tx)
  36 {
  37         dmu_buf_impl_t *db;
  38         int txgoff = tx->tx_txg & TXG_MASK;
  39         int nblkptr = dn->dn_phys->dn_nblkptr;
  40         int old_toplvl = dn->dn_phys->dn_nlevels - 1;
  41         int new_level = dn->dn_next_nlevels[txgoff];
  42         int i;
 
 577                 ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
 578                     dn->dn_maxblkid == 0 || list_head(list) != NULL ||
 579                     avl_last(&dn->dn_ranges[txgoff]) ||
 580                     dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT ==
 581                     dnp->dn_datablkszsec);
 582                 dnp->dn_datablkszsec =
 583                     dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT;
 584                 dn->dn_next_blksz[txgoff] = 0;
 585         }
 586 
 587         if (dn->dn_next_bonuslen[txgoff]) {
 588                 if (dn->dn_next_bonuslen[txgoff] == DN_ZERO_BONUSLEN)
 589                         dnp->dn_bonuslen = 0;
 590                 else
 591                         dnp->dn_bonuslen = dn->dn_next_bonuslen[txgoff];
 592                 ASSERT(dnp->dn_bonuslen <= DN_MAX_BONUSLEN);
 593                 dn->dn_next_bonuslen[txgoff] = 0;
 594         }
 595 
 596         if (dn->dn_next_bonustype[txgoff]) {
 597                 ASSERT(dn->dn_next_bonustype[txgoff] < DMU_OT_NUMTYPES);
 598                 dnp->dn_bonustype = dn->dn_next_bonustype[txgoff];
 599                 dn->dn_next_bonustype[txgoff] = 0;
 600         }
 601 
 602         /*
 603          * We will either remove a spill block when a file is being removed
 604          * or we have been asked to remove it.
 605          */
 606         if (dn->dn_rm_spillblk[txgoff] ||
 607             ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) &&
 608             dn->dn_free_txg > 0 && dn->dn_free_txg <= tx->tx_txg)) {
 609                 if ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR))
 610                         kill_spill = B_TRUE;
 611                 dn->dn_rm_spillblk[txgoff] = 0;
 612         }
 613 
 614         if (dn->dn_next_indblkshift[txgoff]) {
 615                 ASSERT(dnp->dn_nlevels == 1);
 616                 dnp->dn_indblkshift = dn->dn_next_indblkshift[txgoff];
 617                 dn->dn_next_indblkshift[txgoff] = 0;
 
 | 
   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
   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 /*
  23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.
  25  */
  26 
  27 #include <sys/zfs_context.h>
  28 #include <sys/dbuf.h>
  29 #include <sys/dnode.h>
  30 #include <sys/dmu.h>
  31 #include <sys/dmu_tx.h>
  32 #include <sys/dmu_objset.h>
  33 #include <sys/dsl_dataset.h>
  34 #include <sys/spa.h>
  35 
  36 static void
  37 dnode_increase_indirection(dnode_t *dn, dmu_tx_t *tx)
  38 {
  39         dmu_buf_impl_t *db;
  40         int txgoff = tx->tx_txg & TXG_MASK;
  41         int nblkptr = dn->dn_phys->dn_nblkptr;
  42         int old_toplvl = dn->dn_phys->dn_nlevels - 1;
  43         int new_level = dn->dn_next_nlevels[txgoff];
  44         int i;
 
 579                 ASSERT(BP_IS_HOLE(&dnp->dn_blkptr[0]) ||
 580                     dn->dn_maxblkid == 0 || list_head(list) != NULL ||
 581                     avl_last(&dn->dn_ranges[txgoff]) ||
 582                     dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT ==
 583                     dnp->dn_datablkszsec);
 584                 dnp->dn_datablkszsec =
 585                     dn->dn_next_blksz[txgoff] >> SPA_MINBLOCKSHIFT;
 586                 dn->dn_next_blksz[txgoff] = 0;
 587         }
 588 
 589         if (dn->dn_next_bonuslen[txgoff]) {
 590                 if (dn->dn_next_bonuslen[txgoff] == DN_ZERO_BONUSLEN)
 591                         dnp->dn_bonuslen = 0;
 592                 else
 593                         dnp->dn_bonuslen = dn->dn_next_bonuslen[txgoff];
 594                 ASSERT(dnp->dn_bonuslen <= DN_MAX_BONUSLEN);
 595                 dn->dn_next_bonuslen[txgoff] = 0;
 596         }
 597 
 598         if (dn->dn_next_bonustype[txgoff]) {
 599                 ASSERT(DMU_OT_IS_VALID(dn->dn_next_bonustype[txgoff]));
 600                 dnp->dn_bonustype = dn->dn_next_bonustype[txgoff];
 601                 dn->dn_next_bonustype[txgoff] = 0;
 602         }
 603 
 604         /*
 605          * We will either remove a spill block when a file is being removed
 606          * or we have been asked to remove it.
 607          */
 608         if (dn->dn_rm_spillblk[txgoff] ||
 609             ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) &&
 610             dn->dn_free_txg > 0 && dn->dn_free_txg <= tx->tx_txg)) {
 611                 if ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR))
 612                         kill_spill = B_TRUE;
 613                 dn->dn_rm_spillblk[txgoff] = 0;
 614         }
 615 
 616         if (dn->dn_next_indblkshift[txgoff]) {
 617                 ASSERT(dnp->dn_nlevels == 1);
 618                 dnp->dn_indblkshift = dn->dn_next_indblkshift[txgoff];
 619                 dn->dn_next_indblkshift[txgoff] = 0;
 
 |