786 uint64_t dsobj;
787 objset_t *mos = dp->dp_meta_objset;
788
789 if (origin == NULL)
790 origin = dp->dp_origin_snap;
791
792 ASSERT(origin == NULL || origin->ds_dir->dd_pool == dp);
793 ASSERT(origin == NULL || origin->ds_phys->ds_num_children > 0);
794 ASSERT(dmu_tx_is_syncing(tx));
795 ASSERT(dd->dd_phys->dd_head_dataset_obj == 0);
796
797 dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0,
798 DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx);
799 VERIFY(0 == dmu_bonus_hold(mos, dsobj, FTAG, &dbuf));
800 dmu_buf_will_dirty(dbuf, tx);
801 dsphys = dbuf->db_data;
802 bzero(dsphys, sizeof (dsl_dataset_phys_t));
803 dsphys->ds_dir_obj = dd->dd_object;
804 dsphys->ds_flags = flags;
805 dsphys->ds_fsid_guid = unique_create();
806 (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid,
807 sizeof (dsphys->ds_guid));
808 dsphys->ds_snapnames_zapobj =
809 zap_create_norm(mos, U8_TEXTPREP_TOUPPER, DMU_OT_DSL_DS_SNAP_MAP,
810 DMU_OT_NONE, 0, tx);
811 dsphys->ds_creation_time = gethrestime_sec();
812 dsphys->ds_creation_txg = tx->tx_txg == TXG_INITIAL ? 1 : tx->tx_txg;
813
814 if (origin == NULL) {
815 dsphys->ds_deadlist_obj = dsl_deadlist_alloc(mos, tx);
816 } else {
817 dsl_dataset_t *ohds;
818
819 dsphys->ds_prev_snap_obj = origin->ds_object;
820 dsphys->ds_prev_snap_txg =
821 origin->ds_phys->ds_creation_txg;
822 dsphys->ds_referenced_bytes =
823 origin->ds_phys->ds_referenced_bytes;
824 dsphys->ds_compressed_bytes =
825 origin->ds_phys->ds_compressed_bytes;
826 dsphys->ds_uncompressed_bytes =
827 origin->ds_phys->ds_uncompressed_bytes;
2067 int err;
2068
2069 ASSERT(RW_WRITE_HELD(&dp->dp_config_rwlock));
2070
2071 /*
2072 * The origin's ds_creation_txg has to be < TXG_INITIAL
2073 */
2074 if (strcmp(snapname, ORIGIN_DIR_NAME) == 0)
2075 crtxg = 1;
2076 else
2077 crtxg = tx->tx_txg;
2078
2079 dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0,
2080 DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx);
2081 VERIFY(0 == dmu_bonus_hold(mos, dsobj, FTAG, &dbuf));
2082 dmu_buf_will_dirty(dbuf, tx);
2083 dsphys = dbuf->db_data;
2084 bzero(dsphys, sizeof (dsl_dataset_phys_t));
2085 dsphys->ds_dir_obj = ds->ds_dir->dd_object;
2086 dsphys->ds_fsid_guid = unique_create();
2087 (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid,
2088 sizeof (dsphys->ds_guid));
2089 dsphys->ds_prev_snap_obj = ds->ds_phys->ds_prev_snap_obj;
2090 dsphys->ds_prev_snap_txg = ds->ds_phys->ds_prev_snap_txg;
2091 dsphys->ds_next_snap_obj = ds->ds_object;
2092 dsphys->ds_num_children = 1;
2093 dsphys->ds_creation_time = gethrestime_sec();
2094 dsphys->ds_creation_txg = crtxg;
2095 dsphys->ds_deadlist_obj = ds->ds_phys->ds_deadlist_obj;
2096 dsphys->ds_referenced_bytes = ds->ds_phys->ds_referenced_bytes;
2097 dsphys->ds_compressed_bytes = ds->ds_phys->ds_compressed_bytes;
2098 dsphys->ds_uncompressed_bytes = ds->ds_phys->ds_uncompressed_bytes;
2099 dsphys->ds_flags = ds->ds_phys->ds_flags;
2100 dsphys->ds_bp = ds->ds_phys->ds_bp;
2101 dmu_buf_rele(dbuf, FTAG);
2102
2103 ASSERT3U(ds->ds_prev != 0, ==, ds->ds_phys->ds_prev_snap_obj != 0);
2104 if (ds->ds_prev) {
2105 uint64_t next_clones_obj =
2106 ds->ds_prev->ds_phys->ds_next_clones_obj;
2107 ASSERT(ds->ds_prev->ds_phys->ds_next_snap_obj ==
2108 ds->ds_object ||
|
786 uint64_t dsobj;
787 objset_t *mos = dp->dp_meta_objset;
788
789 if (origin == NULL)
790 origin = dp->dp_origin_snap;
791
792 ASSERT(origin == NULL || origin->ds_dir->dd_pool == dp);
793 ASSERT(origin == NULL || origin->ds_phys->ds_num_children > 0);
794 ASSERT(dmu_tx_is_syncing(tx));
795 ASSERT(dd->dd_phys->dd_head_dataset_obj == 0);
796
797 dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0,
798 DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx);
799 VERIFY(0 == dmu_bonus_hold(mos, dsobj, FTAG, &dbuf));
800 dmu_buf_will_dirty(dbuf, tx);
801 dsphys = dbuf->db_data;
802 bzero(dsphys, sizeof (dsl_dataset_phys_t));
803 dsphys->ds_dir_obj = dd->dd_object;
804 dsphys->ds_flags = flags;
805 dsphys->ds_fsid_guid = unique_create();
806 do {
807 (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid,
808 sizeof (dsphys->ds_guid));
809 } while (dsphys->ds_guid == 0);
810 dsphys->ds_snapnames_zapobj =
811 zap_create_norm(mos, U8_TEXTPREP_TOUPPER, DMU_OT_DSL_DS_SNAP_MAP,
812 DMU_OT_NONE, 0, tx);
813 dsphys->ds_creation_time = gethrestime_sec();
814 dsphys->ds_creation_txg = tx->tx_txg == TXG_INITIAL ? 1 : tx->tx_txg;
815
816 if (origin == NULL) {
817 dsphys->ds_deadlist_obj = dsl_deadlist_alloc(mos, tx);
818 } else {
819 dsl_dataset_t *ohds;
820
821 dsphys->ds_prev_snap_obj = origin->ds_object;
822 dsphys->ds_prev_snap_txg =
823 origin->ds_phys->ds_creation_txg;
824 dsphys->ds_referenced_bytes =
825 origin->ds_phys->ds_referenced_bytes;
826 dsphys->ds_compressed_bytes =
827 origin->ds_phys->ds_compressed_bytes;
828 dsphys->ds_uncompressed_bytes =
829 origin->ds_phys->ds_uncompressed_bytes;
2069 int err;
2070
2071 ASSERT(RW_WRITE_HELD(&dp->dp_config_rwlock));
2072
2073 /*
2074 * The origin's ds_creation_txg has to be < TXG_INITIAL
2075 */
2076 if (strcmp(snapname, ORIGIN_DIR_NAME) == 0)
2077 crtxg = 1;
2078 else
2079 crtxg = tx->tx_txg;
2080
2081 dsobj = dmu_object_alloc(mos, DMU_OT_DSL_DATASET, 0,
2082 DMU_OT_DSL_DATASET, sizeof (dsl_dataset_phys_t), tx);
2083 VERIFY(0 == dmu_bonus_hold(mos, dsobj, FTAG, &dbuf));
2084 dmu_buf_will_dirty(dbuf, tx);
2085 dsphys = dbuf->db_data;
2086 bzero(dsphys, sizeof (dsl_dataset_phys_t));
2087 dsphys->ds_dir_obj = ds->ds_dir->dd_object;
2088 dsphys->ds_fsid_guid = unique_create();
2089 do {
2090 (void) random_get_pseudo_bytes((void*)&dsphys->ds_guid,
2091 sizeof (dsphys->ds_guid));
2092 } while (dsphys->ds_guid == 0);
2093 dsphys->ds_prev_snap_obj = ds->ds_phys->ds_prev_snap_obj;
2094 dsphys->ds_prev_snap_txg = ds->ds_phys->ds_prev_snap_txg;
2095 dsphys->ds_next_snap_obj = ds->ds_object;
2096 dsphys->ds_num_children = 1;
2097 dsphys->ds_creation_time = gethrestime_sec();
2098 dsphys->ds_creation_txg = crtxg;
2099 dsphys->ds_deadlist_obj = ds->ds_phys->ds_deadlist_obj;
2100 dsphys->ds_referenced_bytes = ds->ds_phys->ds_referenced_bytes;
2101 dsphys->ds_compressed_bytes = ds->ds_phys->ds_compressed_bytes;
2102 dsphys->ds_uncompressed_bytes = ds->ds_phys->ds_uncompressed_bytes;
2103 dsphys->ds_flags = ds->ds_phys->ds_flags;
2104 dsphys->ds_bp = ds->ds_phys->ds_bp;
2105 dmu_buf_rele(dbuf, FTAG);
2106
2107 ASSERT3U(ds->ds_prev != 0, ==, ds->ds_phys->ds_prev_snap_obj != 0);
2108 if (ds->ds_prev) {
2109 uint64_t next_clones_obj =
2110 ds->ds_prev->ds_phys->ds_next_clones_obj;
2111 ASSERT(ds->ds_prev->ds_phys->ds_next_snap_obj ==
2112 ds->ds_object ||
|