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>

@@ -25,10 +25,12 @@
 
 #include <sys/dmu.h>
 #include <sys/dmu_objset.h>
 #include <sys/dmu_tx.h>
 #include <sys/dnode.h>
+#include <sys/zap.h>
+#include <sys/zfeature.h>
 
 uint64_t
 dmu_object_alloc(objset_t *os, dmu_object_type_t ot, int blocksize,
     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
 {

@@ -192,6 +194,57 @@
             (hole ? DNODE_FIND_HOLE : 0), &offset, 0, DNODES_PER_BLOCK, txg);
 
         *objectp = offset >> DNODE_SHIFT;
 
         return (error);
+}
+
+/*
+ * Turn this object from old_type into DMU_OTN_ZAP_METADATA, and bump the
+ * refcount on SPA_FEATURE_EXTENSIBLE_DATASET.
+ *
+ * Only for use from syncing context, on MOS objects.
+ */
+void
+dmu_object_zapify(objset_t *mos, uint64_t object, dmu_object_type_t old_type,
+    dmu_tx_t *tx)
+{
+        dnode_t *dn;
+
+        ASSERT(dmu_tx_is_syncing(tx));
+
+        VERIFY0(dnode_hold(mos, object, FTAG, &dn));
+        if (dn->dn_type == DMU_OTN_ZAP_METADATA) {
+                dnode_rele(dn, FTAG);
+                return;
+        }
+        ASSERT3U(dn->dn_type, ==, old_type);
+        ASSERT0(dn->dn_maxblkid);
+        dn->dn_next_type[tx->tx_txg & TXG_MASK] = dn->dn_type =
+            DMU_OTN_ZAP_METADATA;
+        dnode_setdirty(dn, tx);
+        dnode_rele(dn, FTAG);
+
+        mzap_create_impl(mos, object, 0, 0, tx);
+
+        spa_feature_incr(dmu_objset_spa(mos),
+            SPA_FEATURE_EXTENSIBLE_DATASET, tx);
+}
+
+void
+dmu_object_free_zapified(objset_t *mos, uint64_t object, dmu_tx_t *tx)
+{
+        dnode_t *dn;
+        dmu_object_type_t t;
+
+        ASSERT(dmu_tx_is_syncing(tx));
+
+        VERIFY0(dnode_hold(mos, object, FTAG, &dn));
+        t = dn->dn_type;
+        dnode_rele(dn, FTAG);
+
+        if (t == DMU_OTN_ZAP_METADATA) {
+                spa_feature_decr(dmu_objset_spa(mos),
+                    SPA_FEATURE_EXTENSIBLE_DATASET, tx);
+        }
+        VERIFY0(dmu_object_free(mos, object, tx));
 }