From owner-svn-src-head@freebsd.org Mon Feb 26 18:01:36 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 91844F37017; Mon, 26 Feb 2018 18:01:36 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3FC3C80808; Mon, 26 Feb 2018 18:01:36 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 204D71ED2A; Mon, 26 Feb 2018 18:01:36 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1QI1aDr085020; Mon, 26 Feb 2018 18:01:36 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1QI1Z2c085018; Mon, 26 Feb 2018 18:01:35 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201802261801.w1QI1Z2c085018@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 26 Feb 2018 18:01:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r330023 - head/stand/libsa X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/libsa X-SVN-Commit-Revision: 330023 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Feb 2018 18:01:36 -0000 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 */