Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Mar 2018 23:49:54 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r331390 - stable/11/cddl/contrib/opensolaris/lib/libzfs/common
Message-ID:  <201803222349.w2MNnsqH095436@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Thu Mar 22 23:49:54 2018
New Revision: 331390
URL: https://svnweb.freebsd.org/changeset/base/331390

Log:
  MFC r329663: MFV r316876: 7542 zfs_unmount failed with EZFS_UNSHARENFSFAILED
  
  illumos/illumos-gate@09c9e6dc9b69d10b771bb87e01040ec320a0bfd3
  https://github.com/illumos/illumos-gate/commit/09c9e6dc9b69d10b771bb87e01040ec320a0bfd3
  
  https://www.illumos.org/issues/7542
    libshare keeps a cached copy of the sharetab listing in memory, which can
    become out of date if shares are destroyed or created while leaving a libzfs
    handle open. This results in a spurious unmounting failure when an NFS share
    exists but isn't in the stale libshare cache.
  
  Reviewed by: Matthew Ahrens <mahrens@delphix.com>
  Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
  Reviewed by: Matt Amdur <matt.amdur@delphix.com>
  Approved by: Robert Mustacchi <rm@joyent.com>
  Author: Chris Williamson <chris.williamson@delphix.com>

Modified:
  stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h
  stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h
==============================================================================
--- stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h	Thu Mar 22 23:48:07 2018	(r331389)
+++ stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_impl.h	Thu Mar 22 23:49:54 2018	(r331390)
@@ -22,7 +22,7 @@
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011 Pawel Jakub Dawidek. All rights reserved.
- * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
  * Copyright (c) 2013 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
  */
 
@@ -72,7 +72,6 @@ struct libzfs_handle {
 	int libzfs_printerr;
 	int libzfs_storeerr; /* stuff error messages into buffer */
 	void *libzfs_sharehdl; /* libshare handle */
-	uint_t libzfs_shareflags;
 	boolean_t libzfs_mnttab_enable;
 	avl_tree_t libzfs_mnttab_cache;
 	int libzfs_pool_iter;
@@ -81,8 +80,6 @@ struct libzfs_handle {
 	char libzfs_chassis_id[256];
 	boolean_t libzfs_prop_debug;
 };
-
-#define	ZFSSHARE_MISS	0x01	/* Didn't find entry in cache */
 
 struct zfs_handle {
 	libzfs_handle_t *zfs_hdl;

Modified: stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c
==============================================================================
--- stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c	Thu Mar 22 23:48:07 2018	(r331389)
+++ stable/11/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_mount.c	Thu Mar 22 23:49:54 2018	(r331390)
@@ -22,7 +22,7 @@
 /*
  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2014, 2015 by Delphix. All rights reserved.
+ * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
  * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
  * Copyright 2017 Joyent, Inc.
  * Copyright 2017 RackTop Systems.
@@ -672,8 +672,6 @@ _zfs_init_libshare(void)
 int
 zfs_init_libshare(libzfs_handle_t *zhandle, int service)
 {
-	int ret = SA_OK;
-
 #ifdef illumos
 	/*
 	 * libshare is either not installed or we're in a branded zone. The
@@ -684,31 +682,28 @@ zfs_init_libshare(libzfs_handle_t *zhandle, int servic
 	if (_sa_init == NULL)
 		return (SA_OK);
 
-	if (ret == SA_OK && zhandle->libzfs_shareflags & ZFSSHARE_MISS) {
-		/*
-		 * We had a cache miss. Most likely it is a new ZFS
-		 * dataset that was just created. We want to make sure
-		 * so check timestamps to see if a different process
-		 * has updated any of the configuration. If there was
-		 * some non-ZFS change, we need to re-initialize the
-		 * internal cache.
-		 */
-		zhandle->libzfs_shareflags &= ~ZFSSHARE_MISS;
-		if (_sa_needs_refresh != NULL &&
-		    _sa_needs_refresh(zhandle->libzfs_sharehdl)) {
-			zfs_uninit_libshare(zhandle);
-			zhandle->libzfs_sharehdl = _sa_init(service);
-		}
+	/*
+	 * Attempt to refresh libshare. This is necessary if there was a cache
+	 * miss for a new ZFS dataset that was just created, or if state of the
+	 * sharetab file has changed since libshare was last initialized. We
+	 * want to make sure so check timestamps to see if a different process
+	 * has updated any of the configuration. If there was some non-ZFS
+	 * change, we need to re-initialize the internal cache.
+	 */
+	if (_sa_needs_refresh != NULL &&
+	    _sa_needs_refresh(zhandle->libzfs_sharehdl)) {
+		zfs_uninit_libshare(zhandle);
+		zhandle->libzfs_sharehdl = _sa_init(service);
 	}
 
-	if (ret == SA_OK && zhandle && zhandle->libzfs_sharehdl == NULL)
+	if (zhandle && zhandle->libzfs_sharehdl == NULL)
 		zhandle->libzfs_sharehdl = _sa_init(service);
 
-	if (ret == SA_OK && zhandle->libzfs_sharehdl == NULL)
-		ret = SA_NO_MEMORY;
+	if (zhandle->libzfs_sharehdl == NULL)
+		return (SA_NO_MEMORY);
 #endif
 
-	return (ret);
+	return (SA_OK);
 }
 
 /*
@@ -864,7 +859,6 @@ zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *
 				    zfs_get_name(zhp));
 				return (-1);
 			}
-			hdl->libzfs_shareflags |= ZFSSHARE_MISS;
 			share = zfs_sa_find_share(hdl->libzfs_sharehdl,
 			    mountpoint);
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803222349.w2MNnsqH095436>