Print this page
8264 want support for promoting datasets in libzfs_core

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 ↓ 15 lines elided ↑ open up ↑
  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   23   * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
  24   24   * Copyright (c) 2013 Steven Hartland. All rights reserved.
  25   25   * Copyright (c) 2014 Integros [integros.com]
       26 + * Copyright 2017 RackTop Systems.
  26   27   */
  27   28  
  28   29  /*
  29   30   * LibZFS_Core (lzc) is intended to replace most functionality in libzfs.
  30   31   * It has the following characteristics:
  31   32   *
  32   33   *  - Thread Safe.  libzfs_core is accessible concurrently from multiple
  33   34   *  threads.  This is accomplished primarily by avoiding global data
  34   35   *  (e.g. caching).  Since it's thread-safe, there is no reason for a
  35   36   *  process to have multiple libzfs "instances".  Therefore, we store
↓ open down ↓ 160 lines elided ↑ open up ↑
 196  197          int error;
 197  198          nvlist_t *args = fnvlist_alloc();
 198  199          fnvlist_add_string(args, "origin", origin);
 199  200          if (props != NULL)
 200  201                  fnvlist_add_nvlist(args, "props", props);
 201  202          error = lzc_ioctl(ZFS_IOC_CLONE, fsname, args, NULL);
 202  203          nvlist_free(args);
 203  204          return (error);
 204  205  }
 205  206  
      207 +int
      208 +lzc_promote(const char *fsname, char *snapnamebuf, int snapnamelen)
      209 +{
      210 +        /*
      211 +         * The promote ioctl is still legacy, so we need to construct our
      212 +         * own zfs_cmd_t rather than using lzc_ioctl().
      213 +         */
      214 +        zfs_cmd_t zc = { 0 };
      215 +
      216 +        ASSERT3S(g_refcount, >, 0);
      217 +        VERIFY3S(g_fd, !=, -1);
      218 +
      219 +        (void) strlcpy(zc.zc_name, fsname, sizeof (zc.zc_name));
      220 +        if (ioctl(g_fd, ZFS_IOC_PROMOTE, &zc) != 0) {
      221 +                if (errno == EEXIST && snapnamebuf != NULL)
      222 +                        (void) strlcpy(snapnamebuf, zc.zc_string, snapnamelen);
      223 +                return (errno);
      224 +        }
      225 +        return (0);
      226 +}
      227 +
 206  228  /*
 207  229   * Creates snapshots.
 208  230   *
 209  231   * The keys in the snaps nvlist are the snapshots to be created.
 210  232   * They must all be in the same pool.
 211  233   *
 212  234   * The props nvlist is properties to set.  Currently only user properties
 213  235   * are supported.  { user:prop_name -> string value }
 214  236   *
 215  237   * The returned results nvlist will have an entry for each snapshot that failed.
↓ open down ↓ 107 lines elided ↑ open up ↑
 323  345          fnvlist_free(result);
 324  346  
 325  347          return (err);
 326  348  }
 327  349  
 328  350  boolean_t
 329  351  lzc_exists(const char *dataset)
 330  352  {
 331  353          /*
 332  354           * The objset_stats ioctl is still legacy, so we need to construct our
 333      -         * own zfs_cmd_t rather than using zfsc_ioctl().
      355 +         * own zfs_cmd_t rather than using lzc_ioctl().
 334  356           */
 335  357          zfs_cmd_t zc = { 0 };
 336  358  
 337  359          ASSERT3S(g_refcount, >, 0);
 338  360          VERIFY3S(g_fd, !=, -1);
 339  361  
 340  362          (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
 341  363          return (ioctl(g_fd, ZFS_IOC_OBJSET_STATS, &zc) == 0);
 342  364  }
 343  365  
↓ open down ↓ 479 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX