Print this page
8264 want support for promoting datasets in libzfs_core

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 ↓ 22 lines elided ↑ open up ↑
  23   23   * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  25   25   * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
  26   26   * Copyright (c) 2012 DEY Storage Systems, Inc.  All rights reserved.
  27   27   * Copyright (c) 2011-2012 Pawel Jakub Dawidek. All rights reserved.
  28   28   * Copyright (c) 2013 Martin Matuska. All rights reserved.
  29   29   * Copyright (c) 2013 Steven Hartland. All rights reserved.
  30   30   * Copyright (c) 2014 Integros [integros.com]
  31   31   * Copyright 2016 Nexenta Systems, Inc.
  32   32   * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
       33 + * Copyright 2017 RackTop Systems.
  33   34   */
  34   35  
  35   36  #include <ctype.h>
  36   37  #include <errno.h>
  37   38  #include <libintl.h>
  38   39  #include <math.h>
  39   40  #include <stdio.h>
  40   41  #include <stdlib.h>
  41   42  #include <strings.h>
  42   43  #include <unistd.h>
↓ open down ↓ 3578 lines elided ↑ open up ↑
3621 3622          return (ret);
3622 3623  }
3623 3624  
3624 3625  /*
3625 3626   * Promotes the given clone fs to be the clone parent.
3626 3627   */
3627 3628  int
3628 3629  zfs_promote(zfs_handle_t *zhp)
3629 3630  {
3630 3631          libzfs_handle_t *hdl = zhp->zfs_hdl;
3631      -        zfs_cmd_t zc = { 0 };
3632      -        char parent[MAXPATHLEN];
     3632 +        char snapname[MAXPATHLEN];
3633 3633          int ret;
3634 3634          char errbuf[1024];
3635 3635  
3636 3636          (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
3637 3637              "cannot promote '%s'"), zhp->zfs_name);
3638 3638  
3639 3639          if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) {
3640 3640                  zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3641 3641                      "snapshots can not be promoted"));
3642 3642                  return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
3643 3643          }
3644 3644  
3645      -        (void) strlcpy(parent, zhp->zfs_dmustats.dds_origin, sizeof (parent));
3646      -        if (parent[0] == '\0') {
     3645 +        if (zhp->zfs_dmustats.dds_origin[0] == '\0') {
3647 3646                  zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3648 3647                      "not a cloned filesystem"));
3649 3648                  return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
3650 3649          }
3651 3650  
3652      -        (void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_origin,
3653      -            sizeof (zc.zc_value));
3654      -        (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
3655      -        ret = zfs_ioctl(hdl, ZFS_IOC_PROMOTE, &zc);
     3651 +        ret = lzc_promote(zhp->zfs_name, snapname, sizeof(snapname));
3656 3652  
3657 3653          if (ret != 0) {
3658 3654                  int save_errno = errno;
3659 3655  
3660 3656                  switch (save_errno) {
3661 3657                  case EEXIST:
3662 3658                          /* There is a conflicting snapshot name. */
3663 3659                          zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3664 3660                              "conflicting snapshot '%s' from parent '%s'"),
3665      -                            zc.zc_string, parent);
     3661 +                            snapname, zhp->zfs_dmustats.dds_origin);
3666 3662                          return (zfs_error(hdl, EZFS_EXISTS, errbuf));
3667 3663  
3668 3664                  default:
3669 3665                          return (zfs_standard_error(hdl, save_errno, errbuf));
3670 3666                  }
3671 3667          }
3672 3668          return (ret);
3673 3669  }
3674 3670  
3675 3671  typedef struct snapdata {
↓ open down ↓ 1194 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX