From 4ddc74c26c98acb0ab8a8599e1433cc882257672 Mon Sep 17 00:00:00 2001
From: Mike Hibler <hibler@cs.utah.edu>
Date: Mon, 16 Dec 2013 14:34:07 -0700
Subject: [PATCH] Changes to support non-racy NFS exports.

As of FreeBSD 9, the race condition in mountd has been addressed.
We automatically (based on the OS running) add the option to mountd (-S)
as part of ops-install. There is also a configuration variable, NFSRACY,
that we auto-detect and set in elabinelab setup. For regular installs,
you need to set this manually in the defs-* file. Note that the setting
in the defs file does not affect very much. It is passed to the client-side
which uses it in one copy function (used as a fall back for getting the
topology file).

There are still a couple of places in the Emulab code where handling
the race condition is hardwired into the code (most notably, imagezip).
These remain.
---
 clientside/tmcc/common/config/rc.mkelab | 16 ++++++++++++++++
 defs-elabinelab                         |  1 +
 install/phases/ops/rcconf               |  8 +++++++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/clientside/tmcc/common/config/rc.mkelab b/clientside/tmcc/common/config/rc.mkelab
index 254053b591..92e84561e5 100755
--- a/clientside/tmcc/common/config/rc.mkelab
+++ b/clientside/tmcc/common/config/rc.mkelab
@@ -178,6 +178,9 @@ my $SINGLE_CONTROLNET = 0;
 # Support a shared filesystem between fs server and nodes
 my $SHAREDFS   = 1;
 
+# When there is a shared FS via NFS, does it have the mountd race?
+my $NFSRACY = 1;
+
 # Start up the frisbee master server to act as an IGMP querier
 # so that frisbee works (if there is no other querier running).
 # -1 means let the system decide.
@@ -242,6 +245,7 @@ my %emulabconfig = (
     "CONFIG_USERDB"     => !$NOCOLLAB,
     "CONFIG_WIKI"       => !$NOCOLLAB,
     "CONFIG_SHAREDFS"	=> $SHAREDFS,
+    "CONFIG_NFSRACY"	=> $NFSRACY,
     "CONFIG_QUERIER"	=> $NEEDQUERIER,
     "CONFIG_OPSVM"	=> $OPSVM,
     "CONFIG_NODBINIT"   => 0,
@@ -393,6 +397,10 @@ sub doboot()
 	$emulabconfig{"MFSVERSION"} = "62";
     }
 
+    if ($FBSD_VERSION >= 9.2) {
+	$emulabconfig{"CONFIG_NFSRACY"} = 0;
+    }
+
     # Determine if a XEN VM.
     if (system("sysctl -n kern.vm_guest >/dev/null 2>&1") == 0) {
 	my $vm_guest = `sysctl -n kern.vm_guest`;
@@ -3282,6 +3290,14 @@ sub CreateDefsFile($)
 		    }
 		    last SWITCH;
 		};
+		/^NFSRACY$/ && do {
+		    if ($emulabconfig{"CONFIG_NFSRACY"}) {
+			print OUTDEFS "NFSRACY=1\n";
+		    } else {
+			print OUTDEFS "NFSRACY=0\n";
+		    }
+		    last SWITCH;
+		};
 		/^SELFLOADER_DATA$/ && do {
 		    #
 		    # Use the SelfLoader in perl 5.8 or beyond (though note
diff --git a/defs-elabinelab b/defs-elabinelab
index b6409ed44b..0605646b5c 100644
--- a/defs-elabinelab
+++ b/defs-elabinelab
@@ -42,6 +42,7 @@ OPSDBSUPPORT=changeme
 WINSUPPORT=0
 NSVERIFY=changeme
 NOSHAREDFS=changeme
+NFSRACY=changeme
 SFSSUPPORT=0
 CVSSUPPORT=changeme
 NFSTRACESUPPORT=0
diff --git a/install/phases/ops/rcconf b/install/phases/ops/rcconf
index eeefa4972f..daf4e1ca83 100755
--- a/install/phases/ops/rcconf
+++ b/install/phases/ops/rcconf
@@ -21,9 +21,15 @@ sub Install($$$)
 		qq|mountd_enable="YES"|,
 		qq|nfs_server_enable="YES"|,
 		qq|nfs_server_flags="-u -t -n 16"|,
-		qq|mountd_flags="-r -p 900"|,
 		qq|syslogd_flags=""|);
 
+    # No more NFS races as of 9.2!
+    if ($FBSD_MAJOR > 9 || ($FBSD_MAJOR == 9 && $FBSD_MINOR > 1)) {
+	push(@adds, qq|mountd_flags="-r -p 900 -S"|);
+    } else {
+	push(@adds, qq|mountd_flags="-r -p 900"|);
+    }
+
     if (ISFS($server)) {
 	if ($WINSUPPORT) {
 	    if ($FBSD_MAJOR > 8 || ($FBSD_MAJOR == 8 && $FBSD_MINOR > 2)) {
-- 
GitLab