From dbda836ace177f4d2acf61ba1d216d2a4c39d134 Mon Sep 17 00:00:00 2001
From: Evan Layton <evan.layton@nexenta.com>
Date: Tue, 4 Jun 2019 13:58:59 -0600
Subject: [PATCH 22/34] NEX-18681 NFS does not quiesce client state to the pool

Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
---
 usr/src/cmd/fs.d/nfs/svc/nlockmgr.xml         |  4 +++-
 .../pkg/manifests/system-file-system-nfs.mf   |  1 +
 usr/src/uts/common/Makefile.files             |  2 ++
 usr/src/uts/common/fs/nfs/nfs4_srv.c          | 13 ++++++++++++-
 usr/src/uts/common/fs/nfs/nfs4_state.c        | 19 ++++++++++++++++++-
 usr/src/uts/common/fs/nfs/nfs_server.c        |  9 +++++++--
 usr/src/uts/common/nfs/nfs4.h                 |  3 ++-
 7 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/usr/src/cmd/fs.d/nfs/svc/nlockmgr.xml b/usr/src/cmd/fs.d/nfs/svc/nlockmgr.xml
index 9ca641d319..ac50bbc4ee 100644
--- a/usr/src/cmd/fs.d/nfs/svc/nlockmgr.xml
+++ b/usr/src/cmd/fs.d/nfs/svc/nlockmgr.xml
@@ -22,6 +22,8 @@
 
 	Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
 	Copyright (c) 2012, 2015 by Delphix. All rights reserved.
+	Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
+	Copyright 2019 Nexenta by DDN, Inc.  All rights reserved.
 
 	NOTE:  This service manifest is not editable; its contents will
 	be overwritten by package or patch operations, including
@@ -93,7 +95,7 @@
 	</property_group>
 	<instance name='default' enabled='false'>
 	  <property_group name='nfs-props' type='com.oracle.nfs,props'>
-	    <propval name='grace_period' type='integer' value='30'/>
+	    <propval name='grace_period' type='integer' value='60'/>
 	    <propval name='lockd_listen_backlog' type='integer' value='32'/>
 	    <propval name='lockd_retransmit_timeout' type='integer' value='5'/>
 	    <propval name='lockd_servers' type='integer' value='256'/>
diff --git a/usr/src/pkg/manifests/system-file-system-nfs.mf b/usr/src/pkg/manifests/system-file-system-nfs.mf
index 7c4e786f97..3ad5e073da 100644
--- a/usr/src/pkg/manifests/system-file-system-nfs.mf
+++ b/usr/src/pkg/manifests/system-file-system-nfs.mf
@@ -22,6 +22,7 @@
 #
 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
 # Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
+# Copyright 2019 Nexenta by DDN, Inc.  All rights reserved.
 #
 
 set name=pkg.fmri value=pkg:/system/file-system/nfs@$(PKGVERS)
diff --git a/usr/src/uts/common/Makefile.files b/usr/src/uts/common/Makefile.files
index 5c7ed57fe3..c71a5bfd5c 100644
--- a/usr/src/uts/common/Makefile.files
+++ b/usr/src/uts/common/Makefile.files
@@ -28,6 +28,8 @@
 # Copyright 2019 Joyent, Inc.
 # Copyright 2016 OmniTI Computer Consulting, Inc.  All rights reserved.
 # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
+# Copyright 2018 Nexenta Systems, Inc.
+# Copyright 2019 Nexenta by DDN, Inc.
 #
 
 #
diff --git a/usr/src/uts/common/fs/nfs/nfs4_srv.c b/usr/src/uts/common/fs/nfs/nfs4_srv.c
index 8b27a4be2a..eec31aff6c 100644
--- a/usr/src/uts/common/fs/nfs/nfs4_srv.c
+++ b/usr/src/uts/common/fs/nfs/nfs4_srv.c
@@ -29,8 +29,9 @@
  */
 
 /*
- * Copyright 2019 Nexenta Systems, Inc.
  * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
+ * Copyright 2019 Nexenta Systems, Inc.
+ * Copyright 2019 Nexenta by DDN, Inc.
  */
 
 #include <sys/param.h>
@@ -630,6 +631,16 @@ rfs4_do_server_start(int server_upordown,
 		rfs4_state_zone_init(nsrv4);
 		nsrv4->nfs4_drc = rfs4_init_drc(nfs4_drc_max,
 		    nfs4_drc_hash);
+
+		/*
+		 * The nfsd service was started with the -s option
+		 * we need to pull in any state from the paths indicated.
+		 */
+		if (curzone == global_zone && rfs4_dss_numnewpaths > 0) {
+			/* read in the stable storage state from these paths */
+			rfs4_dss_readstate(nsrv4, rfs4_dss_numnewpaths,
+			    rfs4_dss_newpaths);
+		}
 	}
 
 	/* Check if delegation is to be enabled */
diff --git a/usr/src/uts/common/fs/nfs/nfs4_state.c b/usr/src/uts/common/fs/nfs/nfs4_state.c
index 89678b6318..d3bce3d057 100644
--- a/usr/src/uts/common/fs/nfs/nfs4_state.c
+++ b/usr/src/uts/common/fs/nfs/nfs4_state.c
@@ -25,6 +25,7 @@
 
 /*
  * Copyright 2018 Nexenta Systems, Inc.
+ * Copyright 2019 Nexenta by DDN, Inc.
  */
 
 #include <sys/systm.h>
@@ -1251,7 +1252,23 @@ rfs4_state_zone_init(nfs4_srv_t *nsrv4)
 	 * clients' recovery window.
 	 */
 	start_grace = 0;
-	rfs4_servinst_create(nsrv4, start_grace, 1, &dss_path);
+	if (curzone == global_zone && rfs4_dss_numnewpaths > 0) {
+		int i;
+		char **dss_allpaths = NULL;
+		dss_allpaths = kmem_alloc(sizeof (char *) * (rfs4_dss_numnewpaths + 1), KM_SLEEP);
+		/*
+		 * Add the default path into the list of paths for saving
+		 * state informantion.
+		 */
+		dss_allpaths[0] = dss_path;
+		for ( i = 0; i < rfs4_dss_numnewpaths; i++) {
+			dss_allpaths[i + 1] = rfs4_dss_newpaths[i];
+		}
+		rfs4_servinst_create(nsrv4, start_grace, (rfs4_dss_numnewpaths + 1), dss_allpaths);
+		kmem_free(dss_allpaths, (sizeof (char *) * (rfs4_dss_numnewpaths + 1)));
+	} else {
+		rfs4_servinst_create(nsrv4, start_grace, 1, &dss_path);
+	}
 
 	/* reset the "first NFSv4 request" status */
 	nsrv4->seen_first_compound = 0;
diff --git a/usr/src/uts/common/fs/nfs/nfs_server.c b/usr/src/uts/common/fs/nfs/nfs_server.c
index 151c1c6aff..b61522a63b 100644
--- a/usr/src/uts/common/fs/nfs/nfs_server.c
+++ b/usr/src/uts/common/fs/nfs/nfs_server.c
@@ -22,8 +22,8 @@
  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
  * Copyright (c) 2013 by Delphix. All rights reserved.
- * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2017 Joyent Inc
+ * Copyright 2019 Nexenta by DDN, Inc.
  */
 
 /*
@@ -320,7 +320,7 @@ nfs_srv_shutdown_all(int quiesce)
 			ng->nfs_server_upordown = NFS_SERVER_QUIESCED;
 			cv_signal(&ng->nfs_server_upordown_cv);
 
-			/* reset DSS state, for subsequent warm restart */
+			/* reset DSS state */
 			rfs4_dss_numnewpaths = 0;
 			rfs4_dss_newpaths = NULL;
 
@@ -335,6 +335,11 @@ nfs_srv_shutdown_all(int quiesce)
 			rfs4_fini_drc();
 			mutex_enter(&ng->nfs_server_upordown_lock);
 			ng->nfs_server_upordown = NFS_SERVER_STOPPED;
+
+			/* reset DSS state */
+			rfs4_dss_numnewpaths = 0;
+			rfs4_dss_newpaths = NULL;
+
 			cv_signal(&ng->nfs_server_upordown_cv);
 		}
 	}
diff --git a/usr/src/uts/common/nfs/nfs4.h b/usr/src/uts/common/nfs/nfs4.h
index 1a9ec7c7a5..d17515343c 100644
--- a/usr/src/uts/common/nfs/nfs4.h
+++ b/usr/src/uts/common/nfs/nfs4.h
@@ -26,6 +26,7 @@
 
 /*
  * Copyright 2018 Nexenta Systems, Inc.
+ * Copyright 2019 Nexenta by DDN, Inc.
  */
 
 #ifndef _NFS4_H
@@ -801,7 +802,7 @@ typedef struct nfs4_srv {
 	int		seen_first_compound;
 	/*
 	 * Circular double-linked list of paths for currently-served RGs.
-	 * No locking required -- only changed on warmstart.
+	 * No locking required -- only changed on server start.
 	 * Managed with insque/remque.
 	 */
 	rfs4_dss_path_t	*dss_pathlist;
-- 
2.20.1 (Apple Git-117)

