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_core/common/libzfs_core.c
          +++ new/usr/src/lib/libzfs_core/common/libzfs_core.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23      - * Copyright (c) 2012 by Delphix. All rights reserved.
       23 + * Copyright (c) 2013 by Delphix. All rights reserved.
  24   24   * Copyright (c) 2013 Steven Hartland. All rights reserved.
  25   25   */
  26   26  
  27   27  /*
  28   28   * LibZFS_Core (lzc) is intended to replace most functionality in libzfs.
  29   29   * It has the following characteristics:
  30   30   *
  31   31   *  - Thread Safe.  libzfs_core is accessible concurrently from multiple
  32   32   *  threads.  This is accomplished primarily by avoiding global data
  33   33   *  (e.g. caching).  Since it's thread-safe, there is no reason for a
↓ open down ↓ 539 lines elided ↑ open up ↑
 573  573  
 574  574          error = ioctl(g_fd, ZFS_IOC_RECV, &zc);
 575  575          if (error != 0)
 576  576                  error = errno;
 577  577  
 578  578  out:
 579  579          if (packed != NULL)
 580  580                  fnvlist_pack_free(packed, size);
 581  581          free((void*)(uintptr_t)zc.zc_nvlist_dst);
 582  582          return (error);
      583 +}
      584 +
      585 +/*
      586 + * Roll back this filesystem or volume to its most recent snapshot.
      587 + * If snapnamebuf is not NULL, it will be filled in with the name
      588 + * of the most recent snapshot.
      589 + *
      590 + * Return 0 on success or an errno on failure.
      591 + */
      592 +int
      593 +lzc_rollback(const char *fsname, char *snapnamebuf, int snapnamelen)
      594 +{
      595 +        nvlist_t *args;
      596 +        nvlist_t *result;
      597 +        int err;
      598 +
      599 +        args = fnvlist_alloc();
      600 +        err = lzc_ioctl(ZFS_IOC_ROLLBACK, fsname, args, &result);
      601 +        nvlist_free(args);
      602 +        if (err == 0 && snapnamebuf != NULL) {
      603 +                const char *snapname = fnvlist_lookup_string(result, "target");
      604 +                (void) strlcpy(snapnamebuf, snapname, snapnamelen);
      605 +        }
      606 +        return (err);
 583  607  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX