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>


   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 /*
  26  * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
  27  * Copyright (c) 2012, 2016 by Delphix. All rights reserved.

  28  */
  29 
  30 #include <stdio.h>
  31 #include <libzfs.h>
  32 #include <string.h>
  33 #include <strings.h>
  34 #include <errno.h>
  35 #include <libshare.h>
  36 #include "libshare_impl.h"
  37 #include <libintl.h>
  38 #include <sys/mnttab.h>
  39 #include <sys/mntent.h>
  40 #include <assert.h>
  41 
  42 extern sa_share_t _sa_add_share(sa_group_t, char *, int, int *, uint64_t);
  43 extern sa_group_t _sa_create_zfs_group(sa_group_t, char *);
  44 extern char *sa_fstype(char *);
  45 extern void set_node_attr(void *, char *, char *);
  46 extern int sa_is_share(void *);
  47 extern void sa_update_sharetab_ts(sa_handle_t);


 319 get_zfs_dataset(sa_handle_impl_t impl_handle, char *path,
 320     boolean_t search_mnttab)
 321 {
 322         size_t i, count = 0;
 323         zfs_handle_t **zlist;
 324         char *cutpath;
 325         zfs_handle_t *handle_from_path;
 326         char *ret = NULL;
 327 
 328         /*
 329          * First we optimistically assume that the mount path for the filesystem
 330          * is the same as the name of the filesystem (minus some number of
 331          * leading slashes). If this is true, then zfs_open should properly open
 332          * the filesystem. We duplicate the error checking done later in the
 333          * function for consistency. If anything fails, we resort to the
 334          * (extremely slow) search of all the filesystems.
 335          */
 336         cutpath = path + strspn(path, "/");
 337 
 338         assert(impl_handle->zfs_libhandle != NULL);

 339         if ((handle_from_path = zfs_open(impl_handle->zfs_libhandle, cutpath,
 340             ZFS_TYPE_FILESYSTEM)) != NULL)
 341                 if ((ret = verify_zfs_handle(handle_from_path, path,
 342                     search_mnttab)) != NULL)



 343                         return (ret);





 344         /*
 345          * Couldn't find a filesystem optimistically, check all the handles we
 346          * can.
 347          */
 348         get_all_filesystems(impl_handle, &zlist, &count);
 349         for (i = 0; i < count; i++) {
 350                 assert(zlist[i]);
 351                 if ((ret = verify_zfs_handle(zlist[i], path,
 352                     search_mnttab)) != NULL)
 353                         return (ret);
 354         }
 355 
 356         /* Couldn't find a matching dataset */
 357         return (NULL);
 358 }
 359 
 360 /*
 361  * get_zfs_property(dataset, property)
 362  *
 363  * Get the file system property specified from the ZFS dataset.




   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 /*
  26  * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
  27  * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  28  * Copyright 2017 RackTop Systems.
  29  */
  30 
  31 #include <stdio.h>
  32 #include <libzfs.h>
  33 #include <string.h>
  34 #include <strings.h>
  35 #include <errno.h>
  36 #include <libshare.h>
  37 #include "libshare_impl.h"
  38 #include <libintl.h>
  39 #include <sys/mnttab.h>
  40 #include <sys/mntent.h>
  41 #include <assert.h>
  42 
  43 extern sa_share_t _sa_add_share(sa_group_t, char *, int, int *, uint64_t);
  44 extern sa_group_t _sa_create_zfs_group(sa_group_t, char *);
  45 extern char *sa_fstype(char *);
  46 extern void set_node_attr(void *, char *, char *);
  47 extern int sa_is_share(void *);
  48 extern void sa_update_sharetab_ts(sa_handle_t);


 320 get_zfs_dataset(sa_handle_impl_t impl_handle, char *path,
 321     boolean_t search_mnttab)
 322 {
 323         size_t i, count = 0;
 324         zfs_handle_t **zlist;
 325         char *cutpath;
 326         zfs_handle_t *handle_from_path;
 327         char *ret = NULL;
 328 
 329         /*
 330          * First we optimistically assume that the mount path for the filesystem
 331          * is the same as the name of the filesystem (minus some number of
 332          * leading slashes). If this is true, then zfs_open should properly open
 333          * the filesystem. We duplicate the error checking done later in the
 334          * function for consistency. If anything fails, we resort to the
 335          * (extremely slow) search of all the filesystems.
 336          */
 337         cutpath = path + strspn(path, "/");
 338 
 339         assert(impl_handle->zfs_libhandle != NULL);
 340         libzfs_print_on_error(impl_handle->zfs_libhandle, B_FALSE);
 341         if ((handle_from_path = zfs_open(impl_handle->zfs_libhandle, cutpath,
 342             ZFS_TYPE_FILESYSTEM)) != NULL) {
 343                 if ((ret = verify_zfs_handle(handle_from_path, path,
 344                     search_mnttab)) != NULL) {
 345                         zfs_close(handle_from_path);
 346                         libzfs_print_on_error(impl_handle->zfs_libhandle,
 347                             B_TRUE);
 348                         return (ret);
 349                 }
 350                 zfs_close(handle_from_path);
 351         }
 352         libzfs_print_on_error(impl_handle->zfs_libhandle, B_TRUE);
 353 
 354         /*
 355          * Couldn't find a filesystem optimistically, check all the handles we
 356          * can.
 357          */
 358         get_all_filesystems(impl_handle, &zlist, &count);
 359         for (i = 0; i < count; i++) {
 360                 assert(zlist[i]);
 361                 if ((ret = verify_zfs_handle(zlist[i], path,
 362                     search_mnttab)) != NULL)
 363                         return (ret);
 364         }
 365 
 366         /* Couldn't find a matching dataset */
 367         return (NULL);
 368 }
 369 
 370 /*
 371  * get_zfs_property(dataset, property)
 372  *
 373  * Get the file system property specified from the ZFS dataset.