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 +                if (!enoent_ok) {
     4125 +                        (void) snprintf(errbuf, sizeof (errbuf),
     4126 +                            dgettext(TEXT_DOMAIN,
     4127 +                            "cannot hold snapshot '%s@%s'"),
     4128 +                            zhp->zfs_name, snapname);
     4129 +                        (void) zfs_standard_error(hdl, ret, errbuf);
     4130 +                }
     4131 +                return (ret);
     4132 +        }
     4133 +
4119 4134          ret = lzc_hold(ha.nvl, cleanup_fd, &errors);
4120 4135          fnvlist_free(ha.nvl);
4121 4136  
4122 4137          if (ret == 0)
4123 4138                  return (0);
4124 4139  
4125 4140          if (nvlist_next_nvpair(errors, NULL) == NULL) {
4126 4141                  /* no hold-specific errors */
4127 4142                  (void) snprintf(errbuf, sizeof (errbuf),
4128 4143                      dgettext(TEXT_DOMAIN, "cannot hold"));
↓ open down ↓ 81 lines elided ↑ open up ↑
4210 4225  
4211 4226  int
4212 4227  zfs_release(zfs_handle_t *zhp, const char *snapname, const char *tag,
4213 4228      boolean_t recursive)
4214 4229  {
4215 4230          int ret;
4216 4231          struct holdarg ha;
4217 4232          nvlist_t *errors;
4218 4233          nvpair_t *elem;
4219 4234          libzfs_handle_t *hdl = zhp->zfs_hdl;
     4235 +        char errbuf[1024];
4220 4236  
4221 4237          ha.nvl = fnvlist_alloc();
4222 4238          ha.snapname = snapname;
4223 4239          ha.tag = tag;
4224 4240          ha.recursive = recursive;
4225 4241          (void) zfs_release_one(zfs_handle_dup(zhp), &ha);
     4242 +
     4243 +        if (nvlist_next_nvpair(ha.nvl, NULL) == NULL) {
     4244 +                fnvlist_free(ha.nvl);
     4245 +                ret = ENOENT;
     4246 +                (void) snprintf(errbuf, sizeof (errbuf),
     4247 +                    dgettext(TEXT_DOMAIN,
     4248 +                    "cannot release hold from snapshot '%s@%s'"),
     4249 +                    zhp->zfs_name, snapname);
     4250 +                (void) zfs_standard_error(hdl, ret, errbuf);
     4251 +                return (ret);
     4252 +        }
     4253 +
4226 4254          ret = lzc_release(ha.nvl, &errors);
4227 4255          fnvlist_free(ha.nvl);
4228 4256  
4229 4257          if (ret == 0)
4230 4258                  return (0);
4231 4259  
4232 4260          if (nvlist_next_nvpair(errors, NULL) == NULL) {
4233 4261                  /* no hold-specific errors */
4234      -                char errbuf[1024];
4235      -
4236 4262                  (void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
4237 4263                      "cannot release"));
4238 4264                  switch (errno) {
4239 4265                  case ENOTSUP:
4240 4266                          zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
4241 4267                              "pool must be upgraded"));
4242 4268                          (void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
4243 4269                          break;
4244 4270                  default:
4245 4271                          (void) zfs_standard_error_fmt(hdl, errno, errbuf);
4246 4272                  }
4247 4273          }
4248 4274  
4249 4275          for (elem = nvlist_next_nvpair(errors, NULL);
4250 4276              elem != NULL;
4251 4277              elem = nvlist_next_nvpair(errors, elem)) {
4252      -                char errbuf[1024];
4253      -
4254 4278                  (void) snprintf(errbuf, sizeof (errbuf),
4255 4279                      dgettext(TEXT_DOMAIN,
4256 4280                      "cannot release hold from snapshot '%s'"),
4257 4281                      nvpair_name(elem));
4258 4282                  switch (fnvpair_value_int32(elem)) {
4259 4283                  case ESRCH:
4260 4284                          (void) zfs_error(hdl, EZFS_REFTAG_RELE, errbuf);
4261 4285                          break;
4262 4286                  case EINVAL:
4263 4287                          (void) zfs_error(hdl, EZFS_BADTYPE, errbuf);
↓ open down ↓ 204 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX