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

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/zfs/dsl_dataset.c
          +++ new/usr/src/uts/common/fs/zfs/dsl_dataset.c
↓ open down ↓ 1790 lines elided ↑ open up ↑
1791 1791          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATION,
1792 1792              dsl_dataset_phys(ds)->ds_creation_time);
1793 1793          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_CREATETXG,
1794 1794              dsl_dataset_phys(ds)->ds_creation_txg);
1795 1795          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFQUOTA,
1796 1796              ds->ds_quota);
1797 1797          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_REFRESERVATION,
1798 1798              ds->ds_reserved);
1799 1799          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_GUID,
1800 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);
1801 1803          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_UNIQUE,
1802 1804              dsl_dataset_phys(ds)->ds_unique_bytes);
1803 1805          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_OBJSETID,
1804 1806              ds->ds_object);
1805 1807          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_USERREFS,
1806 1808              ds->ds_userrefs);
1807 1809          dsl_prop_nvlist_add_uint64(nv, ZFS_PROP_DEFER_DESTROY,
1808 1810              DS_IS_DEFER_DESTROY(ds) ? 1 : 0);
1809 1811  
1810 1812          if (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
↓ open down ↓ 1686 lines elided ↑ open up ↑
3497 3499          dmu_object_info_from_db(ds->ds_dbuf, &doi);
3498 3500          return (doi.doi_type == DMU_OTN_ZAP_METADATA);
3499 3501  }
3500 3502  
3501 3503  boolean_t
3502 3504  dsl_dataset_has_resume_receive_state(dsl_dataset_t *ds)
3503 3505  {
3504 3506          return (dsl_dataset_is_zapified(ds) &&
3505 3507              zap_contains(ds->ds_dir->dd_pool->dp_meta_objset,
3506 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));
3507 3577  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX