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/uts/common/fs/zfs/dsl_dataset.c
          +++ new/usr/src/uts/common/fs/zfs/dsl_dataset.c
↓ open down ↓ 1714 lines elided ↑ open up ↑
1715 1715  
1716 1716          if (held)
1717 1717                  return (SET_ERROR(EBUSY));
1718 1718  
1719 1719          return (0);
1720 1720  }
1721 1721  
1722 1722  typedef struct dsl_dataset_rollback_arg {
1723 1723          const char *ddra_fsname;
1724 1724          void *ddra_owner;
     1725 +        nvlist_t *ddra_result;
1725 1726  } dsl_dataset_rollback_arg_t;
1726 1727  
1727 1728  static int
1728 1729  dsl_dataset_rollback_check(void *arg, dmu_tx_t *tx)
1729 1730  {
1730 1731          dsl_dataset_rollback_arg_t *ddra = arg;
1731 1732          dsl_pool_t *dp = dmu_tx_pool(tx);
1732 1733          dsl_dataset_t *ds;
1733 1734          int64_t unused_refres_delta;
1734 1735          int error;
↓ open down ↓ 51 lines elided ↑ open up ↑
1786 1787          return (0);
1787 1788  }
1788 1789  
1789 1790  static void
1790 1791  dsl_dataset_rollback_sync(void *arg, dmu_tx_t *tx)
1791 1792  {
1792 1793          dsl_dataset_rollback_arg_t *ddra = arg;
1793 1794          dsl_pool_t *dp = dmu_tx_pool(tx);
1794 1795          dsl_dataset_t *ds, *clone;
1795 1796          uint64_t cloneobj;
     1797 +        char namebuf[ZFS_MAXNAMELEN];
1796 1798  
1797 1799          VERIFY0(dsl_dataset_hold(dp, ddra->ddra_fsname, FTAG, &ds));
1798 1800  
     1801 +        dsl_dataset_name(ds->ds_prev, namebuf);
     1802 +        fnvlist_add_string(ddra->ddra_result, "target", namebuf);
     1803 +
1799 1804          cloneobj = dsl_dataset_create_sync(ds->ds_dir, "%rollback",
1800 1805              ds->ds_prev, DS_CREATE_FLAG_NODIRTY, kcred, tx);
1801 1806  
1802 1807          VERIFY0(dsl_dataset_hold_obj(dp, cloneobj, FTAG, &clone));
1803 1808  
1804 1809          dsl_dataset_clone_swap_sync_impl(clone, ds, tx);
1805 1810          dsl_dataset_zero_zil(ds, tx);
1806 1811  
1807 1812          dsl_destroy_head_sync_impl(clone, tx);
1808 1813  
1809 1814          dsl_dataset_rele(clone, FTAG);
1810 1815          dsl_dataset_rele(ds, FTAG);
1811 1816  }
1812 1817  
1813 1818  /*
1814      - * If owner != NULL:
     1819 + * Rolls back the given filesystem or volume to the most recent snapshot.
     1820 + * The name of the most recent snapshot will be returned under key "target"
     1821 + * in the result nvlist.
1815 1822   *
     1823 + * If owner != NULL:
1816 1824   * - The existing dataset MUST be owned by the specified owner at entry
1817 1825   * - Upon return, dataset will still be held by the same owner, whether we
1818 1826   *   succeed or not.
1819 1827   *
1820 1828   * This mode is required any time the existing filesystem is mounted.  See
1821 1829   * notes above zfs_suspend_fs() for further details.
1822 1830   */
1823 1831  int
1824      -dsl_dataset_rollback(const char *fsname, void *owner)
     1832 +dsl_dataset_rollback(const char *fsname, void *owner, nvlist_t *result)
1825 1833  {
1826 1834          dsl_dataset_rollback_arg_t ddra;
1827 1835  
1828 1836          ddra.ddra_fsname = fsname;
1829 1837          ddra.ddra_owner = owner;
     1838 +        ddra.ddra_result = result;
1830 1839  
1831 1840          return (dsl_sync_task(fsname, dsl_dataset_rollback_check,
1832      -            dsl_dataset_rollback_sync, (void *)&ddra, 1));
     1841 +            dsl_dataset_rollback_sync, &ddra, 1));
1833 1842  }
1834 1843  
1835 1844  struct promotenode {
1836 1845          list_node_t link;
1837 1846          dsl_dataset_t *ds;
1838 1847  };
1839 1848  
1840 1849  typedef struct dsl_dataset_promote_arg {
1841 1850          const char *ddpa_clonename;
1842 1851          dsl_dataset_t *ddpa_clone;
↓ open down ↓ 1152 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX