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>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libzfs/common/libzfs_dataset.c
          +++ new/usr/src/lib/libzfs/common/libzfs_dataset.c
↓ open down ↓ 3510 lines elided ↑ open up ↑
3511 3511   * data changes since then and making it the active dataset.
3512 3512   *
3513 3513   * Any snapshots more recent than the target are destroyed, along with
3514 3514   * their dependents.
3515 3515   */
3516 3516  int
3517 3517  zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
3518 3518  {
3519 3519          rollback_data_t cb = { 0 };
3520 3520          int err;
3521      -        zfs_cmd_t zc = { 0 };
3522 3521          boolean_t restore_resv = 0;
3523 3522          uint64_t old_volsize, new_volsize;
3524 3523          zfs_prop_t resv_prop;
3525 3524  
3526 3525          assert(zhp->zfs_type == ZFS_TYPE_FILESYSTEM ||
3527 3526              zhp->zfs_type == ZFS_TYPE_VOLUME);
3528 3527  
3529 3528          /*
3530 3529           * Destroy all recent snapshots and their dependents.
3531 3530           */
↓ open down ↓ 11 lines elided ↑ open up ↑
3543 3542           */
3544 3543  
3545 3544          if (zhp->zfs_type == ZFS_TYPE_VOLUME) {
3546 3545                  if (zfs_which_resv_prop(zhp, &resv_prop) < 0)
3547 3546                          return (-1);
3548 3547                  old_volsize = zfs_prop_get_int(zhp, ZFS_PROP_VOLSIZE);
3549 3548                  restore_resv =
3550 3549                      (old_volsize == zfs_prop_get_int(zhp, resv_prop));
3551 3550          }
3552 3551  
3553      -        (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
3554      -
3555      -        if (ZFS_IS_VOLUME(zhp))
3556      -                zc.zc_objset_type = DMU_OST_ZVOL;
3557      -        else
3558      -                zc.zc_objset_type = DMU_OST_ZFS;
3559      -
3560 3552          /*
3561 3553           * We rely on zfs_iter_children() to verify that there are no
3562 3554           * newer snapshots for the given dataset.  Therefore, we can
3563 3555           * simply pass the name on to the ioctl() call.  There is still
3564 3556           * an unlikely race condition where the user has taken a
3565 3557           * snapshot since we verified that this was the most recent.
3566      -         *
3567 3558           */
3568      -        if ((err = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_ROLLBACK, &zc)) != 0) {
     3559 +        err = lzc_rollback(zhp->zfs_name, NULL, 0);
     3560 +        if (err != 0) {
3569 3561                  (void) zfs_standard_error_fmt(zhp->zfs_hdl, errno,
3570 3562                      dgettext(TEXT_DOMAIN, "cannot rollback '%s'"),
3571 3563                      zhp->zfs_name);
3572 3564                  return (err);
3573 3565          }
3574 3566  
3575 3567          /*
3576 3568           * For volumes, if the pre-rollback volsize matched the pre-
3577 3569           * rollback reservation and the volsize has changed then set
3578 3570           * the reservation property to the post-rollback volsize.
↓ open down ↓ 933 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX