Print this page
3699 zfs hold or release of a non-existent snapshot does not output error

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 ↓ 16 lines elided ↑ open up ↑
  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) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright (c) 2012 by Delphix. All rights reserved.
  25   25   * Copyright (c) 2012 DEY Storage Systems, Inc.  All rights reserved.
  26   26   * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
       27 + * Copyright (c) 2013 Martin Matuska. All rights reserved.
  27   28   */
  28   29  
  29   30  #include <ctype.h>
  30   31  #include <errno.h>
  31   32  #include <libintl.h>
  32   33  #include <math.h>
  33   34  #include <stdio.h>
  34   35  #include <stdlib.h>
  35   36  #include <strings.h>
  36   37  #include <unistd.h>
↓ open down ↓ 4072 lines elided ↑ open up ↑
4109 4110          nvlist_t *errors;
4110 4111          libzfs_handle_t *hdl = zhp->zfs_hdl;
4111 4112          char errbuf[1024];
4112 4113          nvpair_t *elem;
4113 4114  
4114 4115          ha.nvl = fnvlist_alloc();
4115 4116          ha.snapname = snapname;
4116 4117          ha.tag = tag;
4117 4118          ha.recursive = recursive;
4118 4119          (void) zfs_hold_one(zfs_handle_dup(zhp), &ha);
     4120 +
     4121 +        if (nvlist_next_nvpair(ha.nvl, NULL) == NULL) {
     4122 +                fnvlist_free(ha.nvl);
     4123 +                ret = ENOENT;
     4124 +                (void) snprintf(errbuf, sizeof (errbuf),
     4125 +                    dgettext(TEXT_DOMAIN, "cannot hold snapshot '%s@%s'"),
     4126 +                    zhp->zfs_name, snapname);
     4127 +                (void) zfs_standard_error(hdl, ret, errbuf);
     4128 +                return (ret);
     4129 +        }
     4130 +
4119 4131          ret = lzc_hold(ha.nvl, cleanup_fd, &errors);
4120 4132          fnvlist_free(ha.nvl);
4121 4133  
4122 4134          if (ret == 0)
4123 4135                  return (0);
4124 4136  
4125 4137          if (nvlist_next_nvpair(errors, NULL) == NULL) {
4126 4138                  /* no hold-specific errors */
4127 4139                  (void) snprintf(errbuf, sizeof (errbuf),
4128 4140                      dgettext(TEXT_DOMAIN, "cannot hold"));
↓ open down ↓ 81 lines elided ↑ open up ↑
4210 4222  
4211 4223  int
4212 4224  zfs_release(zfs_handle_t *zhp, const char *snapname, const char *tag,
4213 4225      boolean_t recursive)
4214 4226  {
4215 4227          int ret;
4216 4228          struct holdarg ha;
4217 4229          nvlist_t *errors;
4218 4230          nvpair_t *elem;
4219 4231          libzfs_handle_t *hdl = zhp->zfs_hdl;
     4232 +        char errbuf[1024];
4220 4233  
4221 4234          ha.nvl = fnvlist_alloc();
4222 4235          ha.snapname = snapname;
4223 4236          ha.tag = tag;
4224 4237          ha.recursive = recursive;
4225 4238          (void) zfs_release_one(zfs_handle_dup(zhp), &ha);
     4239 +
     4240 +        if (nvlist_next_nvpair(ha.nvl, NULL) == NULL) {
     4241 +                fnvlist_free(ha.nvl);
     4242 +                ret = ENOENT;
     4243 +                (void) snprintf(errbuf, sizeof (errbuf),
     4244 +                    dgettext(TEXT_DOMAIN,
     4245 +                    "cannot release hold from snapshot '%s@%s'"),
     4246 +                    zhp->zfs_name, snapname);
     4247 +                (void) zfs_standard_error(hdl, ret, errbuf);
     4248 +                return (ret);
     4249 +        }
     4250 +
4226 4251          ret = lzc_release(ha.nvl, &errors);
4227 4252          fnvlist_free(ha.nvl);
4228 4253  
4229 4254          if (ret == 0)
4230 4255                  return (0);
4231 4256  
4232 4257          if (nvlist_next_nvpair(errors, NULL) == NULL) {
4233 4258                  /* no hold-specific errors */
4234      -                char errbuf[1024];
4235      -
4236 4259                  (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
4237 4260                      "cannot release"));
4238 4261                  switch (errno) {
4239 4262                  case ENOTSUP:
4240 4263                          zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
4241 4264                              "pool must be upgraded"));
4242 4265                          (void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
4243 4266                          break;
4244 4267                  default:
4245 4268                          (void) zfs_standard_error_fmt(hdl, errno, errbuf);
4246 4269                  }
4247 4270          }
4248 4271  
4249 4272          for (elem = nvlist_next_nvpair(errors, NULL);
4250 4273              elem != NULL;
4251 4274              elem = nvlist_next_nvpair(errors, elem)) {
4252      -                char errbuf[1024];
4253      -
4254 4275                  (void) snprintf(errbuf, sizeof (errbuf),
4255 4276                      dgettext(TEXT_DOMAIN,
4256 4277                      "cannot release hold from snapshot '%s'"),
4257 4278                      nvpair_name(elem));
4258 4279                  switch (fnvpair_value_int32(elem)) {
4259 4280                  case ESRCH:
4260 4281                          (void) zfs_error(hdl, EZFS_REFTAG_RELE, errbuf);
4261 4282                          break;
4262 4283                  case EINVAL:
4263 4284                          (void) zfs_error(hdl, EZFS_BADTYPE, errbuf);
↓ open down ↓ 204 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX