Print this page
7857 zfs/zpool commands print scary errors after 7741
7887 get_zfs_dataset() optimised path leaks zfs handle
Reviewed by: Sam Zaydel <szaydel@racktopsystems.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libshare/common/libshare_zfs.c
          +++ new/usr/src/lib/libshare/common/libshare_zfs.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   */
  25   25  /*
  26   26   * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
  27   27   * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
       28 + * Copyright 2017 RackTop Systems.
  28   29   */
  29   30  
  30   31  #include <stdio.h>
  31   32  #include <libzfs.h>
  32   33  #include <string.h>
  33   34  #include <strings.h>
  34   35  #include <errno.h>
  35   36  #include <libshare.h>
  36   37  #include "libshare_impl.h"
  37   38  #include <libintl.h>
↓ open down ↓ 291 lines elided ↑ open up ↑
 329  330           * First we optimistically assume that the mount path for the filesystem
 330  331           * is the same as the name of the filesystem (minus some number of
 331  332           * leading slashes). If this is true, then zfs_open should properly open
 332  333           * the filesystem. We duplicate the error checking done later in the
 333  334           * function for consistency. If anything fails, we resort to the
 334  335           * (extremely slow) search of all the filesystems.
 335  336           */
 336  337          cutpath = path + strspn(path, "/");
 337  338  
 338  339          assert(impl_handle->zfs_libhandle != NULL);
      340 +        libzfs_print_on_error(impl_handle->zfs_libhandle, B_FALSE);
 339  341          if ((handle_from_path = zfs_open(impl_handle->zfs_libhandle, cutpath,
 340      -            ZFS_TYPE_FILESYSTEM)) != NULL)
      342 +            ZFS_TYPE_FILESYSTEM)) != NULL) {
 341  343                  if ((ret = verify_zfs_handle(handle_from_path, path,
 342      -                    search_mnttab)) != NULL)
      344 +                    search_mnttab)) != NULL) {
      345 +                        zfs_close(handle_from_path);
      346 +                        libzfs_print_on_error(impl_handle->zfs_libhandle,
      347 +                            B_TRUE);
 343  348                          return (ret);
      349 +                }
      350 +                zfs_close(handle_from_path);
      351 +        }
      352 +        libzfs_print_on_error(impl_handle->zfs_libhandle, B_TRUE);
      353 +
 344  354          /*
 345  355           * Couldn't find a filesystem optimistically, check all the handles we
 346  356           * can.
 347  357           */
 348  358          get_all_filesystems(impl_handle, &zlist, &count);
 349  359          for (i = 0; i < count; i++) {
 350  360                  assert(zlist[i]);
 351  361                  if ((ret = verify_zfs_handle(zlist[i], path,
 352  362                      search_mnttab)) != NULL)
 353  363                          return (ret);
↓ open down ↓ 1270 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX