Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Feb 2018 18:01:35 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r330023 - head/stand/libsa
Message-ID:  <201802261801.w1QI1Z2c085018@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Feb 26 18:01:35 2018
New Revision: 330023
URL: https://svnweb.freebsd.org/changeset/base/330023

Log:
  libsa: Add MAXWAIT to net for establishing max total timeout
  
  Current timeout behavior is to progress in timeout values from MINTMO to
  MAXTMO in MINTMO steps before finally timing out. This results in a fairly
  long time before operations finally timeout, which may not be ideal for some
  use-cases.
  
  Add MAXWAIT that may be configured along with MINTMO/MAXTMO. If we attempt
  to start our send/recv cycle over again but MAXWAIT > 0 and MAXWAIT seconds
  have already passed, then go ahead and timeout.
  
  This is intended for those that just want to say "timeout after 180 seconds"
  rather than calculate and tweak MINTMO/MAXTMO to get their desired timeout.
  The default is 0, or "progress from MINTMO to MAXTMO with no exception."
  
  This has been modified since review to allow for it to be defined via CFLAGS
  and doing appropriate error checking. Future work may add some Makefile foo
  to respect LOADER_NET_MAXWAIT if it's specified in the environment and pass
  it in as MAXWAIT accordingly.
  
  Reviewed by:	imp, sbruno, tsoome (all previous version)
  MFC after:	1 week
  Differential Revision:	https://reviews.freebsd.org/D14389

Modified:
  head/stand/libsa/net.c
  head/stand/libsa/net.h

Modified: head/stand/libsa/net.c
==============================================================================
--- head/stand/libsa/net.c	Mon Feb 26 17:51:18 2018	(r330022)
+++ head/stand/libsa/net.c	Mon Feb 26 18:01:35 2018	(r330023)
@@ -77,6 +77,7 @@ sendrecv(struct iodesc *d,
 {
 	ssize_t cc;
 	time_t t, tmo, tlast;
+	time_t tref;
 	long tleft;
 
 #ifdef NET_DEBUG
@@ -87,13 +88,14 @@ sendrecv(struct iodesc *d,
 	tmo = MINTMO;
 	tlast = 0;
 	tleft = 0;
+	tref = getsecs();
 	t = getsecs();
 	for (;;) {
+		if (MAXWAIT > 0 && (getsecs() - tref) >= MAXWAIT) {
+			errno = ETIMEDOUT;
+			return -1;
+		}
 		if (tleft <= 0) {
-			if (tmo >= MAXTMO) {
-				errno = ETIMEDOUT;
-				return -1;
-			}
 			cc = (*sproc)(d, sbuf, ssize);
 			if (cc != -1 && cc < ssize)
 				panic("sendrecv: short write! (%zd < %zd)",

Modified: head/stand/libsa/net.h
==============================================================================
--- head/stand/libsa/net.h	Mon Feb 26 17:51:18 2018	(r330022)
+++ head/stand/libsa/net.h	Mon Feb 26 18:01:35 2018	(r330023)
@@ -61,6 +61,20 @@ enum net_proto {
 #define MAXTMO 120	/* seconds */
 #define MINTMO 2	/* seconds */
 
+/*
+ * Maximum wait time for sending and receiving before we give up and timeout.
+ * If set to 0, operations will eventually timeout completely, but send/recv
+ * timeouts must progress exponentially from MINTMO to MAXTMO before final
+ * timeout is hit.
+ */
+#ifndef MAXWAIT
+#define MAXWAIT 0	/* seconds */
+#endif
+
+#if MAXWAIT < 0
+#error MAXWAIT must not be a negative number
+#endif
+
 #define FNAME_SIZE 128
 #define	IFNAME_SIZE 16
 #define RECV_SIZE 1536	/* XXX delete this */



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