Print this page
4171 clean up spa_feature_*() interfaces
4172 implement extensible_dataset feature for use by other zpool features
Reviewed by: Max Grossman <max.grossman@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>


  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 (c) 2013 by Delphix. All rights reserved.
  24  */
  25 
  26 #include <sys/dmu.h>
  27 #include <sys/dmu_objset.h>
  28 #include <sys/dmu_tx.h>
  29 #include <sys/dnode.h>


  30 
  31 uint64_t
  32 dmu_object_alloc(objset_t *os, dmu_object_type_t ot, int blocksize,
  33     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
  34 {
  35         uint64_t object;
  36         uint64_t L2_dnode_count = DNODES_PER_BLOCK <<
  37             (DMU_META_DNODE(os)->dn_indblkshift - SPA_BLKPTRSHIFT);
  38         dnode_t *dn = NULL;
  39         int restarted = B_FALSE;
  40 
  41         mutex_enter(&os->os_obj_lock);
  42         for (;;) {
  43                 object = os->os_obj_next;
  44                 /*
  45                  * Each time we polish off an L2 bp worth of dnodes
  46                  * (2^13 objects), move to another L2 bp that's still
  47                  * reasonably sparse (at most 1/4 full).  Look from the
  48                  * beginning once, but after that keep looking from here.
  49                  * If we can't find one, just keep going from here.


 177         ASSERT(dn->dn_type != DMU_OT_NONE);
 178         dnode_free_range(dn, 0, DMU_OBJECT_END, tx);
 179         dnode_free(dn, tx);
 180         dnode_rele(dn, FTAG);
 181 
 182         return (0);
 183 }
 184 
 185 int
 186 dmu_object_next(objset_t *os, uint64_t *objectp, boolean_t hole, uint64_t txg)
 187 {
 188         uint64_t offset = (*objectp + 1) << DNODE_SHIFT;
 189         int error;
 190 
 191         error = dnode_next_offset(DMU_META_DNODE(os),
 192             (hole ? DNODE_FIND_HOLE : 0), &offset, 0, DNODES_PER_BLOCK, txg);
 193 
 194         *objectp = offset >> DNODE_SHIFT;
 195 
 196         return (error);



















































 197 }


  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 (c) 2013 by Delphix. All rights reserved.
  24  */
  25 
  26 #include <sys/dmu.h>
  27 #include <sys/dmu_objset.h>
  28 #include <sys/dmu_tx.h>
  29 #include <sys/dnode.h>
  30 #include <sys/zap.h>
  31 #include <sys/zfeature.h>
  32 
  33 uint64_t
  34 dmu_object_alloc(objset_t *os, dmu_object_type_t ot, int blocksize,
  35     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
  36 {
  37         uint64_t object;
  38         uint64_t L2_dnode_count = DNODES_PER_BLOCK <<
  39             (DMU_META_DNODE(os)->dn_indblkshift - SPA_BLKPTRSHIFT);
  40         dnode_t *dn = NULL;
  41         int restarted = B_FALSE;
  42 
  43         mutex_enter(&os->os_obj_lock);
  44         for (;;) {
  45                 object = os->os_obj_next;
  46                 /*
  47                  * Each time we polish off an L2 bp worth of dnodes
  48                  * (2^13 objects), move to another L2 bp that's still
  49                  * reasonably sparse (at most 1/4 full).  Look from the
  50                  * beginning once, but after that keep looking from here.
  51                  * If we can't find one, just keep going from here.


 179         ASSERT(dn->dn_type != DMU_OT_NONE);
 180         dnode_free_range(dn, 0, DMU_OBJECT_END, tx);
 181         dnode_free(dn, tx);
 182         dnode_rele(dn, FTAG);
 183 
 184         return (0);
 185 }
 186 
 187 int
 188 dmu_object_next(objset_t *os, uint64_t *objectp, boolean_t hole, uint64_t txg)
 189 {
 190         uint64_t offset = (*objectp + 1) << DNODE_SHIFT;
 191         int error;
 192 
 193         error = dnode_next_offset(DMU_META_DNODE(os),
 194             (hole ? DNODE_FIND_HOLE : 0), &offset, 0, DNODES_PER_BLOCK, txg);
 195 
 196         *objectp = offset >> DNODE_SHIFT;
 197 
 198         return (error);
 199 }
 200 
 201 /*
 202  * Turn this object from old_type into DMU_OTN_ZAP_METADATA, and bump the
 203  * refcount on SPA_FEATURE_EXTENSIBLE_DATASET.
 204  *
 205  * Only for use from syncing context, on MOS objects.
 206  */
 207 void
 208 dmu_object_zapify(objset_t *mos, uint64_t object, dmu_object_type_t old_type,
 209     dmu_tx_t *tx)
 210 {
 211         dnode_t *dn;
 212 
 213         ASSERT(dmu_tx_is_syncing(tx));
 214 
 215         VERIFY0(dnode_hold(mos, object, FTAG, &dn));
 216         if (dn->dn_type == DMU_OTN_ZAP_METADATA) {
 217                 dnode_rele(dn, FTAG);
 218                 return;
 219         }
 220         ASSERT3U(dn->dn_type, ==, old_type);
 221         ASSERT0(dn->dn_maxblkid);
 222         dn->dn_next_type[tx->tx_txg & TXG_MASK] = dn->dn_type =
 223             DMU_OTN_ZAP_METADATA;
 224         dnode_setdirty(dn, tx);
 225         dnode_rele(dn, FTAG);
 226 
 227         mzap_create_impl(mos, object, 0, 0, tx);
 228 
 229         spa_feature_incr(dmu_objset_spa(mos),
 230             SPA_FEATURE_EXTENSIBLE_DATASET, tx);
 231 }
 232 
 233 void
 234 dmu_object_free_zapified(objset_t *mos, uint64_t object, dmu_tx_t *tx)
 235 {
 236         dnode_t *dn;
 237         dmu_object_type_t t;
 238 
 239         ASSERT(dmu_tx_is_syncing(tx));
 240 
 241         VERIFY0(dnode_hold(mos, object, FTAG, &dn));
 242         t = dn->dn_type;
 243         dnode_rele(dn, FTAG);
 244 
 245         if (t == DMU_OTN_ZAP_METADATA) {
 246                 spa_feature_decr(dmu_objset_spa(mos),
 247                     SPA_FEATURE_EXTENSIBLE_DATASET, tx);
 248         }
 249         VERIFY0(dmu_object_free(mos, object, tx));
 250 }