Print this page
cstyle fixes
dsl_dataset_set_fsid_guid should use ZFS_SPACE_CHECK_RESERVED
dsl_dataset_set_fsid_guid _check and _sync func declared static,
removed from dsl_dataset.h
rewrite unique_valid
6333 ZFS should let the user specify or modify the fsid_guid of a dataset


1781                         dsl_prop_nvlist_add_string(nv, ZFS_PROP_PREV_SNAP, buf);
1782                 }
1783 
1784                 dsl_dir_stats(ds->ds_dir, nv);
1785         }
1786 
1787         dsl_dataset_space(ds, &refd, &avail, &uobjs, &aobjs);
1788         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_AVAILABLE, avail);
1789         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFERENCED, refd);
1790 
1791         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATION,
1792             dsl_dataset_phys(ds)->ds_creation_time);
1793         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATETXG,
1794             dsl_dataset_phys(ds)->ds_creation_txg);
1795         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFQUOTA,
1796             ds->ds_quota);
1797         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRESERVATION,
1798             ds->ds_reserved);
1799         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_GUID,
1800             dsl_dataset_phys(ds)->ds_guid);


1801         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_UNIQUE,
1802             dsl_dataset_phys(ds)->ds_unique_bytes);
1803         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_OBJSETID,
1804             ds->ds_object);
1805         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERREFS,
1806             ds->ds_userrefs);
1807         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_DEFER_DESTROY,
1808             DS_IS_DEFER_DESTROY(ds) ? 1 : 0);
1809 
1810         if (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
1811                 uint64_t written, comp, uncomp;
1812                 dsl_pool_t *dp = ds->ds_dir->dd_pool;
1813                 dsl_dataset_t *prev;
1814 
1815                 int err = dsl_dataset_hold_obj(dp,
1816                     dsl_dataset_phys(ds)->ds_prev_snap_obj, FTAG, &prev);
1817                 if (err == 0) {
1818                         err = dsl_dataset_space_written(prev, ds, &written,
1819                             &comp, &uncomp);
1820                         dsl_dataset_rele(prev, FTAG);


3487 {
3488         objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
3489         dmu_object_zapify(mos, ds->ds_object, DMU_OT_DSL_DATASET, tx);
3490 }
3491 
3492 boolean_t
3493 dsl_dataset_is_zapified(dsl_dataset_t *ds)
3494 {
3495         dmu_object_info_t doi;
3496 
3497         dmu_object_info_from_db(ds->ds_dbuf, &doi);
3498         return (doi.doi_type == DMU_OTN_ZAP_METADATA);
3499 }
3500 
3501 boolean_t
3502 dsl_dataset_has_resume_receive_state(dsl_dataset_t *ds)
3503 {
3504         return (dsl_dataset_is_zapified(ds) &&
3505             zap_contains(ds->ds_dir->dd_pool->dp_meta_objset,
3506             ds->ds_object, DS_FIELD_RESUME_TOGUID) == 0);




































































3507 }


1781                         dsl_prop_nvlist_add_string(nv, ZFS_PROP_PREV_SNAP, buf);
1782                 }
1783 
1784                 dsl_dir_stats(ds->ds_dir, nv);
1785         }
1786 
1787         dsl_dataset_space(ds, &refd, &avail, &uobjs, &aobjs);
1788         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_AVAILABLE, avail);
1789         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFERENCED, refd);
1790 
1791         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATION,
1792             dsl_dataset_phys(ds)->ds_creation_time);
1793         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATETXG,
1794             dsl_dataset_phys(ds)->ds_creation_txg);
1795         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFQUOTA,
1796             ds->ds_quota);
1797         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRESERVATION,
1798             ds->ds_reserved);
1799         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_GUID,
1800             dsl_dataset_phys(ds)->ds_guid);
1801         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_FSID_GUID,
1802             dsl_dataset_phys(ds)->ds_fsid_guid);
1803         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_UNIQUE,
1804             dsl_dataset_phys(ds)->ds_unique_bytes);
1805         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_OBJSETID,
1806             ds->ds_object);
1807         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERREFS,
1808             ds->ds_userrefs);
1809         dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_DEFER_DESTROY,
1810             DS_IS_DEFER_DESTROY(ds) ? 1 : 0);
1811 
1812         if (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
1813                 uint64_t written, comp, uncomp;
1814                 dsl_pool_t *dp = ds->ds_dir->dd_pool;
1815                 dsl_dataset_t *prev;
1816 
1817                 int err = dsl_dataset_hold_obj(dp,
1818                     dsl_dataset_phys(ds)->ds_prev_snap_obj, FTAG, &prev);
1819                 if (err == 0) {
1820                         err = dsl_dataset_space_written(prev, ds, &written,
1821                             &comp, &uncomp);
1822                         dsl_dataset_rele(prev, FTAG);


3489 {
3490         objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
3491         dmu_object_zapify(mos, ds->ds_object, DMU_OT_DSL_DATASET, tx);
3492 }
3493 
3494 boolean_t
3495 dsl_dataset_is_zapified(dsl_dataset_t *ds)
3496 {
3497         dmu_object_info_t doi;
3498 
3499         dmu_object_info_from_db(ds->ds_dbuf, &doi);
3500         return (doi.doi_type == DMU_OTN_ZAP_METADATA);
3501 }
3502 
3503 boolean_t
3504 dsl_dataset_has_resume_receive_state(dsl_dataset_t *ds)
3505 {
3506         return (dsl_dataset_is_zapified(ds) &&
3507             zap_contains(ds->ds_dir->dd_pool->dp_meta_objset,
3508             ds->ds_object, DS_FIELD_RESUME_TOGUID) == 0);
3509 }
3510 
3511 typedef struct dsl_dataset_set_fsid_guid_arg {
3512         const char *ddsfg_name;
3513         uint64_t ddsfg_value;
3514 } dsl_dataset_set_fsid_guid_arg_t;
3515 
3516 static int
3517 dsl_dataset_set_fsid_guid_check(void *arg, dmu_tx_t *tx)
3518 {
3519         int err = 0;
3520         dsl_dataset_set_fsid_guid_arg_t *ddsfg = arg;
3521         dsl_pool_t *dp = dmu_tx_pool(tx);
3522         dsl_dataset_t *ds;
3523         uint64_t newval;
3524 
3525         newval = ddsfg->ddsfg_value;
3526 
3527         err = dsl_dataset_hold(dp, ddsfg->ddsfg_name, FTAG, &ds);
3528         if (err != 0)
3529                 return (err);
3530 
3531         /* Check if the FS is mounted */
3532         if (ds->ds_owner != NULL) {
3533                 dsl_dataset_rele(ds, FTAG);
3534                 return (SET_ERROR(EBUSY));
3535         }
3536         dsl_dataset_rele(ds, FTAG);
3537 
3538         if (!unique_valid(newval))
3539                 return (SET_ERROR(EEXIST));
3540 
3541         return (err);
3542 }
3543 
3544 static void
3545 dsl_dataset_set_fsid_guid_sync(void *arg, dmu_tx_t *tx)
3546 {
3547         dsl_dataset_set_fsid_guid_arg_t *ddsfg = arg;
3548         dsl_pool_t *dp = dmu_tx_pool(tx);
3549         dsl_dataset_t *ds;
3550         uint64_t newval;
3551 
3552         VERIFY0(dsl_dataset_hold(dp, ddsfg->ddsfg_name, FTAG, &ds));
3553 
3554         newval = ddsfg->ddsfg_value;
3555 
3556         dmu_buf_will_dirty(ds->ds_dbuf, tx);
3557         mutex_enter(&ds->ds_lock);
3558         ds->ds_fsid_guid = newval;
3559         dsl_dataset_phys(ds)->ds_fsid_guid = newval;
3560         mutex_exit(&ds->ds_lock);
3561 
3562         dsl_dataset_rele(ds, FTAG);
3563 }
3564 
3565 int
3566 dsl_dataset_set_fsid_guid(const char *ddname, zprop_source_t source,
3567     uint64_t fsid_guid)
3568 {
3569         dsl_dataset_set_fsid_guid_arg_t ddsfg;
3570 
3571         ddsfg.ddsfg_name = ddname;
3572         ddsfg.ddsfg_value = fsid_guid;
3573 
3574         return (dsl_sync_task(ddname, dsl_dataset_set_fsid_guid_check,
3575             dsl_dataset_set_fsid_guid_sync, &ddsfg, 0,
3576             ZFS_SPACE_CHECK_RESERVED));
3577 }