Print this page
3996 want a libzfs_core API to rollback to latest snapshot
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Reviewed by: Adam Leventhal <ahl@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>


3476 zfs_ioc_destroy(zfs_cmd_t *zc)
3477 {
3478         int err;
3479 
3480         if (zc->zc_objset_type == DMU_OST_ZFS) {
3481                 err = zfs_unmount_snap(zc->zc_name);
3482                 if (err != 0)
3483                         return (err);
3484         }
3485 
3486         if (strchr(zc->zc_name, '@'))
3487                 err = dsl_destroy_snapshot(zc->zc_name, zc->zc_defer_destroy);
3488         else
3489                 err = dsl_destroy_head(zc->zc_name);
3490         if (zc->zc_objset_type == DMU_OST_ZVOL && err == 0)
3491                 (void) zvol_remove_minor(zc->zc_name);
3492         return (err);
3493 }
3494 
3495 /*
3496  * inputs:
3497  * zc_name      name of dataset to rollback (to most recent snapshot)
3498  *
3499  * outputs:     none



3500  */

3501 static int
3502 zfs_ioc_rollback(zfs_cmd_t *zc)
3503 {
3504         zfsvfs_t *zfsvfs;
3505         int error;
3506 
3507         if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
3508                 error = zfs_suspend_fs(zfsvfs);
3509                 if (error == 0) {
3510                         int resume_err;
3511 
3512                         error = dsl_dataset_rollback(zc->zc_name, zfsvfs);
3513                         resume_err = zfs_resume_fs(zfsvfs, zc->zc_name);
3514                         error = error ? error : resume_err;
3515                 }
3516                 VFS_RELE(zfsvfs->z_vfs);
3517         } else {
3518                 error = dsl_dataset_rollback(zc->zc_name, NULL);
3519         }
3520         return (error);
3521 }
3522 
3523 static int
3524 recursive_unmount(const char *fsname, void *arg)
3525 {
3526         const char *snapname = arg;
3527         char fullname[MAXNAMELEN];
3528 
3529         (void) snprintf(fullname, sizeof (fullname), "%s@%s", fsname, snapname);
3530         return (zfs_unmount_snap(fullname));
3531 }
3532 
3533 /*
3534  * inputs:
3535  * zc_name      old name of dataset
3536  * zc_value     new name of dataset
3537  * zc_cookie    recursive flag (only valid for snapshots)
3538  *


5310 
5311         zfs_ioctl_register("clone", ZFS_IOC_CLONE,
5312             zfs_ioc_clone, zfs_secpolicy_create_clone, DATASET_NAME,
5313             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5314 
5315         zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS,
5316             zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, POOL_NAME,
5317             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5318 
5319         zfs_ioctl_register("hold", ZFS_IOC_HOLD,
5320             zfs_ioc_hold, zfs_secpolicy_hold, POOL_NAME,
5321             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5322         zfs_ioctl_register("release", ZFS_IOC_RELEASE,
5323             zfs_ioc_release, zfs_secpolicy_release, POOL_NAME,
5324             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5325 
5326         zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS,
5327             zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
5328             POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5329 




5330         /* IOCTLS that use the legacy function signature */
5331 
5332         zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
5333             zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_READONLY);
5334 
5335         zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE, zfs_ioc_pool_create,
5336             zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5337         zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN,
5338             zfs_ioc_pool_scan);
5339         zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE,
5340             zfs_ioc_pool_upgrade);
5341         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD,
5342             zfs_ioc_vdev_add);
5343         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE,
5344             zfs_ioc_vdev_remove);
5345         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE,
5346             zfs_ioc_vdev_set_state);
5347         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH,
5348             zfs_ioc_vdev_attach);
5349         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH,


5421         zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS,
5422             zfs_ioc_send_progress);
5423 
5424         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF,
5425             zfs_ioc_diff, zfs_secpolicy_diff);
5426         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS,
5427             zfs_ioc_obj_to_stats, zfs_secpolicy_diff);
5428         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH,
5429             zfs_ioc_obj_to_path, zfs_secpolicy_diff);
5430         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE,
5431             zfs_ioc_userspace_one, zfs_secpolicy_userspace_one);
5432         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY,
5433             zfs_ioc_userspace_many, zfs_secpolicy_userspace_many);
5434         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND,
5435             zfs_ioc_send, zfs_secpolicy_send);
5436 
5437         zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP, zfs_ioc_set_prop,
5438             zfs_secpolicy_none);
5439         zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY, zfs_ioc_destroy,
5440             zfs_secpolicy_destroy);
5441         zfs_ioctl_register_dataset_modify(ZFS_IOC_ROLLBACK, zfs_ioc_rollback,
5442             zfs_secpolicy_rollback);
5443         zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME, zfs_ioc_rename,
5444             zfs_secpolicy_rename);
5445         zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV, zfs_ioc_recv,
5446             zfs_secpolicy_recv);
5447         zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE, zfs_ioc_promote,
5448             zfs_secpolicy_promote);
5449         zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP,
5450             zfs_ioc_inherit_prop, zfs_secpolicy_inherit_prop);
5451         zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL, zfs_ioc_set_fsacl,
5452             zfs_secpolicy_set_fsacl);
5453 
5454         zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE, zfs_ioc_share,
5455             zfs_secpolicy_share, POOL_CHECK_NONE);
5456         zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL, zfs_ioc_smb_acl,
5457             zfs_secpolicy_smb_acl, POOL_CHECK_NONE);
5458         zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE,
5459             zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
5460             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5461         zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT,
5462             zfs_ioc_tmp_snapshot, zfs_secpolicy_tmp_snapshot,




3476 zfs_ioc_destroy(zfs_cmd_t *zc)
3477 {
3478         int err;
3479 
3480         if (zc->zc_objset_type == DMU_OST_ZFS) {
3481                 err = zfs_unmount_snap(zc->zc_name);
3482                 if (err != 0)
3483                         return (err);
3484         }
3485 
3486         if (strchr(zc->zc_name, '@'))
3487                 err = dsl_destroy_snapshot(zc->zc_name, zc->zc_defer_destroy);
3488         else
3489                 err = dsl_destroy_head(zc->zc_name);
3490         if (zc->zc_objset_type == DMU_OST_ZVOL && err == 0)
3491                 (void) zvol_remove_minor(zc->zc_name);
3492         return (err);
3493 }
3494 
3495 /*
3496  * fsname is name of dataset to rollback (to most recent snapshot)

3497  *
3498  * innvl is not used.
3499  *
3500  * outnvl: "target" -> name of most recent snapshot
3501  * }
3502  */
3503 /* ARGSUSED */
3504 static int
3505 zfs_ioc_rollback(const char *fsname, nvlist_t *args, nvlist_t *outnvl)
3506 {
3507         zfsvfs_t *zfsvfs;
3508         int error;
3509 
3510         if (getzfsvfs(fsname, &zfsvfs) == 0) {
3511                 error = zfs_suspend_fs(zfsvfs);
3512                 if (error == 0) {
3513                         int resume_err;
3514 
3515                         error = dsl_dataset_rollback(fsname, zfsvfs, outnvl);
3516                         resume_err = zfs_resume_fs(zfsvfs, fsname);
3517                         error = error ? error : resume_err;
3518                 }
3519                 VFS_RELE(zfsvfs->z_vfs);
3520         } else {
3521                 error = dsl_dataset_rollback(fsname, NULL, outnvl);
3522         }
3523         return (error);
3524 }
3525 
3526 static int
3527 recursive_unmount(const char *fsname, void *arg)
3528 {
3529         const char *snapname = arg;
3530         char fullname[MAXNAMELEN];
3531 
3532         (void) snprintf(fullname, sizeof (fullname), "%s@%s", fsname, snapname);
3533         return (zfs_unmount_snap(fullname));
3534 }
3535 
3536 /*
3537  * inputs:
3538  * zc_name      old name of dataset
3539  * zc_value     new name of dataset
3540  * zc_cookie    recursive flag (only valid for snapshots)
3541  *


5313 
5314         zfs_ioctl_register("clone", ZFS_IOC_CLONE,
5315             zfs_ioc_clone, zfs_secpolicy_create_clone, DATASET_NAME,
5316             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5317 
5318         zfs_ioctl_register("destroy_snaps", ZFS_IOC_DESTROY_SNAPS,
5319             zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, POOL_NAME,
5320             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5321 
5322         zfs_ioctl_register("hold", ZFS_IOC_HOLD,
5323             zfs_ioc_hold, zfs_secpolicy_hold, POOL_NAME,
5324             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5325         zfs_ioctl_register("release", ZFS_IOC_RELEASE,
5326             zfs_ioc_release, zfs_secpolicy_release, POOL_NAME,
5327             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_TRUE, B_TRUE);
5328 
5329         zfs_ioctl_register("get_holds", ZFS_IOC_GET_HOLDS,
5330             zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME,
5331             POOL_CHECK_SUSPENDED, B_FALSE, B_FALSE);
5332 
5333         zfs_ioctl_register("rollback", ZFS_IOC_ROLLBACK,
5334             zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME,
5335             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY, B_FALSE, B_TRUE);
5336 
5337         /* IOCTLS that use the legacy function signature */
5338 
5339         zfs_ioctl_register_legacy(ZFS_IOC_POOL_FREEZE, zfs_ioc_pool_freeze,
5340             zfs_secpolicy_config, NO_NAME, B_FALSE, POOL_CHECK_READONLY);
5341 
5342         zfs_ioctl_register_pool(ZFS_IOC_POOL_CREATE, zfs_ioc_pool_create,
5343             zfs_secpolicy_config, B_TRUE, POOL_CHECK_NONE);
5344         zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_SCAN,
5345             zfs_ioc_pool_scan);
5346         zfs_ioctl_register_pool_modify(ZFS_IOC_POOL_UPGRADE,
5347             zfs_ioc_pool_upgrade);
5348         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ADD,
5349             zfs_ioc_vdev_add);
5350         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_REMOVE,
5351             zfs_ioc_vdev_remove);
5352         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_SET_STATE,
5353             zfs_ioc_vdev_set_state);
5354         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_ATTACH,
5355             zfs_ioc_vdev_attach);
5356         zfs_ioctl_register_pool_modify(ZFS_IOC_VDEV_DETACH,


5428         zfs_ioctl_register_dataset_read(ZFS_IOC_SEND_PROGRESS,
5429             zfs_ioc_send_progress);
5430 
5431         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_DIFF,
5432             zfs_ioc_diff, zfs_secpolicy_diff);
5433         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_STATS,
5434             zfs_ioc_obj_to_stats, zfs_secpolicy_diff);
5435         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_OBJ_TO_PATH,
5436             zfs_ioc_obj_to_path, zfs_secpolicy_diff);
5437         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_ONE,
5438             zfs_ioc_userspace_one, zfs_secpolicy_userspace_one);
5439         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_USERSPACE_MANY,
5440             zfs_ioc_userspace_many, zfs_secpolicy_userspace_many);
5441         zfs_ioctl_register_dataset_read_secpolicy(ZFS_IOC_SEND,
5442             zfs_ioc_send, zfs_secpolicy_send);
5443 
5444         zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_PROP, zfs_ioc_set_prop,
5445             zfs_secpolicy_none);
5446         zfs_ioctl_register_dataset_modify(ZFS_IOC_DESTROY, zfs_ioc_destroy,
5447             zfs_secpolicy_destroy);


5448         zfs_ioctl_register_dataset_modify(ZFS_IOC_RENAME, zfs_ioc_rename,
5449             zfs_secpolicy_rename);
5450         zfs_ioctl_register_dataset_modify(ZFS_IOC_RECV, zfs_ioc_recv,
5451             zfs_secpolicy_recv);
5452         zfs_ioctl_register_dataset_modify(ZFS_IOC_PROMOTE, zfs_ioc_promote,
5453             zfs_secpolicy_promote);
5454         zfs_ioctl_register_dataset_modify(ZFS_IOC_INHERIT_PROP,
5455             zfs_ioc_inherit_prop, zfs_secpolicy_inherit_prop);
5456         zfs_ioctl_register_dataset_modify(ZFS_IOC_SET_FSACL, zfs_ioc_set_fsacl,
5457             zfs_secpolicy_set_fsacl);
5458 
5459         zfs_ioctl_register_dataset_nolog(ZFS_IOC_SHARE, zfs_ioc_share,
5460             zfs_secpolicy_share, POOL_CHECK_NONE);
5461         zfs_ioctl_register_dataset_nolog(ZFS_IOC_SMB_ACL, zfs_ioc_smb_acl,
5462             zfs_secpolicy_smb_acl, POOL_CHECK_NONE);
5463         zfs_ioctl_register_dataset_nolog(ZFS_IOC_USERSPACE_UPGRADE,
5464             zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
5465             POOL_CHECK_SUSPENDED | POOL_CHECK_READONLY);
5466         zfs_ioctl_register_dataset_nolog(ZFS_IOC_TMP_SNAPSHOT,
5467             zfs_ioc_tmp_snapshot, zfs_secpolicy_tmp_snapshot,