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
This commit is contained in:
Kyle Evans 2018-02-26 18:01:35 +00:00
parent fe3f4a580a
commit 95c61459f3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=330023
2 changed files with 20 additions and 4 deletions

View File

@ -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)",

View File

@ -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 */