From owner-svn-src-head@FreeBSD.ORG Fri Mar 7 23:35:54 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 978A1939 for ; Fri, 7 Mar 2014 23:35:54 +0000 (UTC) Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 68FC7CF3 for ; Fri, 7 Mar 2014 23:35:54 +0000 (UTC) Received: by mail-pa0-f42.google.com with SMTP id fb1so4836990pad.29 for ; Fri, 07 Mar 2014 15:35:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=NmyJVDB3A8YmQDIMbt5tOkuVZN5Avm9X+2XguYsZ98w=; b=azVLd3x9YzyPiigXjTIfQAzltjHdk5GF94Hqs0HzTtAvjroAgrcIgAdQAWaC3E8Abz h1/g2UdYRa/CyGuCQdFP6p+TUGXypb8z1/mlHDCgdiQzvhbjrYda9JXEJfJ9JxODrJz3 iw+f59IVnrV/trf+qSrxk730fY2THksMS2Tl0V1UImjHpVkl8VR9tGD90OYBf8Fmn/gi +M4BHxWhIM+CdFEF//UOJGzGtuyTOk5bzF8hveQlxsb+51VWf4vQT+95rkiJb6KMZrJQ ce3g8XjlA/0LP/wagerjIjG5llkt6o4YL5sTk3yUZsZLEE2i31Cn7TJpJyb+cCCD+RJP tbIQ== X-Gm-Message-State: ALoCoQkqlL4FG+WFuQUkFbD5fFjbEqL9rDrCwaBVZFTkaU/hMm6sDEmx5/XmMgUk+gZxWxBuS2pW X-Received: by 10.68.250.3 with SMTP id yy3mr25382879pbc.56.1394235348430; Fri, 07 Mar 2014 15:35:48 -0800 (PST) Received: from lgmac-cvenus.corp.netflix.com (dc1-prod.netflix.com. [69.53.236.251]) by mx.google.com with ESMTPSA id nz11sm15585507pab.6.2014.03.07.15.35.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Mar 2014 15:35:47 -0800 (PST) Sender: Warner Losh Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Subject: Re: svn commit: r262914 - in head: sbin/devd sys/kern sys/sys From: Warner Losh In-Reply-To: <201403072330.s27NUmO5008051@svn.freebsd.org> Date: Fri, 7 Mar 2014 16:35:45 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: References: <201403072330.s27NUmO5008051@svn.freebsd.org> To: Alan Somers X-Mailer: Apple Mail (2.1874) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 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: Fri, 07 Mar 2014 23:35:54 -0000 On Mar 7, 2014, at 4:30 PM, Alan Somers wrote: > Author: asomers > Date: Fri Mar 7 23:30:48 2014 > New Revision: 262914 > URL: http://svnweb.freebsd.org/changeset/base/262914 >=20 > Log: > sbin/devd/devd.8 > sbin/devd/devd.cc > Add a -q flag to devd that will suppress syslog logging at > LOG_NOTICE or below. This also changes the logging from debug to no_daemon=85 Was that = intentional? > Requested by: ian@ and imp@ > MFC after: 3 weeks > Sponsored by: Spectra Logic Corporation >=20 > Modified: > head/sbin/devd/devd.8 > head/sbin/devd/devd.cc > head/sys/kern/uipc_usrreq.c > head/sys/sys/sockbuf.h > head/sys/sys/unpcb.h I don=92t think the sys files should have been committed in the same = commit, since those are clearly unrelated. Warner > Modified: head/sbin/devd/devd.8 > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/sbin/devd/devd.8 Fri Mar 7 23:26:14 2014 = (r262913) > +++ head/sbin/devd/devd.8 Fri Mar 7 23:30:48 2014 = (r262914) > @@ -33,7 +33,7 @@ > .Nd "device state change daemon" > .Sh SYNOPSIS > .Nm > -.Op Fl dn > +.Op Fl dnq > .Op Fl f Ar file > .Op Fl l Ar num > .Sh DESCRIPTION > @@ -63,6 +63,8 @@ The default connection limit is 10. > .It Fl n > Do not process all pending events before becoming a daemon. > Instead, call daemon right away. > +.It Fl q > +Quiet mode. Only log messages at priority LOG_WARNING or above. > .El > .Sh IMPLEMENTATION NOTES > The >=20 > Modified: head/sbin/devd/devd.cc > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/sbin/devd/devd.cc Fri Mar 7 23:26:14 2014 = (r262913) > +++ head/sbin/devd/devd.cc Fri Mar 7 23:30:48 2014 = (r262914) > @@ -129,8 +129,9 @@ static const char detach =3D '-'; >=20 > static struct pidfh *pfh; >=20 > -int dflag; > -int nflag; > +static int no_daemon =3D 0; > +static int daemonize_quick =3D 0; > +static int quiet_mode =3D 0; > static unsigned total_events =3D 0; > static volatile sig_atomic_t got_siginfo =3D 0; > static volatile sig_atomic_t romeo_must_die =3D 0; > @@ -291,7 +292,7 @@ match::do_match(config &c) > * can consume excessive amounts of systime inside of connect(). = Only > * log when we're in -d mode. > */ > - if (dflag) { > + if (no_daemon) { > devdlog(LOG_DEBUG, "Testing %s=3D%s against %s, = invert=3D%d\n", > _var.c_str(), value.c_str(), _re.c_str(), _inv); > } > @@ -401,7 +402,7 @@ var_list::set_variable(const string &var > * can consume excessive amounts of systime inside of connect(). = Only > * log when we're in -d mode. > */ > - if (dflag) > + if (no_daemon) > devdlog(LOG_DEBUG, "setting %s=3D%s\n", var.c_str(), = val.c_str()); > _vars[var] =3D val; > } > @@ -945,7 +946,7 @@ event_loop(void) > accepting =3D 1; > max_fd =3D max(fd, server_fd) + 1; > while (!romeo_must_die) { > - if (!once && !dflag && !nflag) { > + if (!once && !no_daemon && !daemonize_quick) { > // Check to see if we have any events pending. > tv.tv_sec =3D 0; > tv.tv_usec =3D 0; > @@ -1139,9 +1140,9 @@ devdlog(int priority, const char* fmt, . > va_list argp; >=20 > va_start(argp, fmt); > - if (dflag) > + if (no_daemon) > vfprintf(stderr, fmt, argp); > - else > + else if ((! quiet_mode) || (priority <=3D LOG_WARNING)) > vsyslog(priority, fmt, argp); > va_end(argp); > } > @@ -1149,7 +1150,7 @@ devdlog(int priority, const char* fmt, . > static void > usage() > { > - fprintf(stderr, "usage: %s [-dn] [-l connlimit] [-f file]\n", > + fprintf(stderr, "usage: %s [-dnq] [-l connlimit] [-f file]\n", > getprogname()); > exit(1); > } > @@ -1179,10 +1180,10 @@ main(int argc, char **argv) > int ch; >=20 > check_devd_enabled(); > - while ((ch =3D getopt(argc, argv, "df:l:n")) !=3D -1) { > + while ((ch =3D getopt(argc, argv, "df:l:nq")) !=3D -1) { > switch (ch) { > case 'd': > - dflag++; > + no_daemon =3D 1; > break; > case 'f': > configfile =3D optarg; > @@ -1191,7 +1192,10 @@ main(int argc, char **argv) > max_clients =3D MAX(1, strtoul(optarg, NULL, = 0)); > break; > case 'n': > - nflag++; > + daemonize_quick =3D 1; > + break; > + case 'q': > + quiet_mode =3D 1; > break; > default: > usage(); > @@ -1199,7 +1203,7 @@ main(int argc, char **argv) > } >=20 > cfg.parse(); > - if (!dflag && nflag) { > + if (!no_daemon && daemonize_quick) { > cfg.open_pidfile(); > daemon(0, 0); > cfg.write_pidfile(); >=20 > Modified: head/sys/kern/uipc_usrreq.c > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/sys/kern/uipc_usrreq.c Fri Mar 7 23:26:14 2014 = (r262913) > +++ head/sys/kern/uipc_usrreq.c Fri Mar 7 23:30:48 2014 = (r262914) > @@ -51,7 +51,6 @@ > * > * TODO: > * RDM > - * distinguish datagram size limits from flow control limits in = SEQPACKET > * rethink name space problems > * need a proper out-of-band > */ > @@ -789,7 +788,6 @@ uipc_rcvd(struct socket *so, int flags) > struct unpcb *unp, *unp2; > struct socket *so2; > u_int mbcnt, sbcc; > - u_long newhiwat; >=20 > unp =3D sotounpcb(so); > KASSERT(unp !=3D NULL, ("uipc_rcvd: unp =3D=3D NULL")); > @@ -811,6 +809,15 @@ uipc_rcvd(struct socket *so, int flags) > mbcnt =3D so->so_rcv.sb_mbcnt; > sbcc =3D so->so_rcv.sb_cc; > SOCKBUF_UNLOCK(&so->so_rcv); > + /* > + * There is a benign race condition at this point. If we're = planning to > + * clear SB_STOP, but uipc_send is called on the connected = socket at > + * this instant, it might add data to the sockbuf and set = SB_STOP. Then > + * we would erroneously clear SB_STOP below, even though the = sockbuf is > + * full. The race is benign because the only ill effect is to = allow the > + * sockbuf to exceed its size limit, and the size limits are not > + * strictly guaranteed anyway. > + */ > UNP_PCB_LOCK(unp); > unp2 =3D unp->unp_conn; > if (unp2 =3D=3D NULL) { > @@ -819,13 +826,9 @@ uipc_rcvd(struct socket *so, int flags) > } > so2 =3D unp2->unp_socket; > SOCKBUF_LOCK(&so2->so_snd); > - so2->so_snd.sb_mbmax +=3D unp->unp_mbcnt - mbcnt; > - newhiwat =3D so2->so_snd.sb_hiwat + unp->unp_cc - sbcc; > - (void)chgsbsize(so2->so_cred->cr_uidinfo, &so2->so_snd.sb_hiwat, > - newhiwat, RLIM_INFINITY); > + if (sbcc < so2->so_snd.sb_hiwat && mbcnt < so2->so_snd.sb_mbmax) > + so2->so_snd.sb_flags &=3D ~SB_STOP; > sowwakeup_locked(so2); > - unp->unp_mbcnt =3D mbcnt; > - unp->unp_cc =3D sbcc; > UNP_PCB_UNLOCK(unp); > return (0); > } > @@ -836,8 +839,7 @@ uipc_send(struct socket *so, int flags,=20 > { > struct unpcb *unp, *unp2; > struct socket *so2; > - u_int mbcnt_delta, sbcc; > - u_int newhiwat; > + u_int mbcnt, sbcc; > int error =3D 0; >=20 > unp =3D sotounpcb(so); > @@ -991,27 +993,21 @@ uipc_send(struct socket *so, int flags,=20 > } > } >=20 > - /* > - * XXXRW: While fine for SOCK_STREAM, this conflates = maximum > - * datagram size and back-pressure for SOCK_SEQPACKET, = which > - * can lead to undesired return of EMSGSIZE on send = instead > - * of more desirable blocking. > - */ > - mbcnt_delta =3D so2->so_rcv.sb_mbcnt - unp2->unp_mbcnt; > - unp2->unp_mbcnt =3D so2->so_rcv.sb_mbcnt; > + mbcnt =3D so2->so_rcv.sb_mbcnt; > sbcc =3D so2->so_rcv.sb_cc; > sorwakeup_locked(so2); >=20 > + /*=20 > + * The PCB lock on unp2 protects the SB_STOP flag. = Without it, > + * it would be possible for uipc_rcvd to be called at = this > + * point, drain the receiving sockbuf, clear SB_STOP, = and then > + * we would set SB_STOP below. That could lead to an = empty > + * sockbuf having SB_STOP set > + */ > SOCKBUF_LOCK(&so->so_snd); > - if ((int)so->so_snd.sb_hiwat >=3D (int)(sbcc - = unp2->unp_cc)) > - newhiwat =3D so->so_snd.sb_hiwat - (sbcc - = unp2->unp_cc); > - else > - newhiwat =3D 0; > - (void)chgsbsize(so->so_cred->cr_uidinfo, = &so->so_snd.sb_hiwat, > - newhiwat, RLIM_INFINITY); > - so->so_snd.sb_mbmax -=3D mbcnt_delta; > + if (sbcc >=3D so->so_snd.sb_hiwat || mbcnt >=3D = so->so_snd.sb_mbmax) > + so->so_snd.sb_flags |=3D SB_STOP; > SOCKBUF_UNLOCK(&so->so_snd); > - unp2->unp_cc =3D sbcc; > UNP_PCB_UNLOCK(unp2); > m =3D NULL; > break; > @@ -1049,27 +1045,18 @@ release: > static int > uipc_sense(struct socket *so, struct stat *sb) > { > - struct unpcb *unp, *unp2; > - struct socket *so2; > + struct unpcb *unp; >=20 > unp =3D sotounpcb(so); > KASSERT(unp !=3D NULL, ("uipc_sense: unp =3D=3D NULL")); >=20 > sb->st_blksize =3D so->so_snd.sb_hiwat; > - UNP_LINK_RLOCK(); > UNP_PCB_LOCK(unp); > - unp2 =3D unp->unp_conn; > - if ((so->so_type =3D=3D SOCK_STREAM || so->so_type =3D=3D = SOCK_SEQPACKET) && > - unp2 !=3D NULL) { > - so2 =3D unp2->unp_socket; > - sb->st_blksize +=3D so2->so_rcv.sb_cc; > - } > sb->st_dev =3D NODEV; > if (unp->unp_ino =3D=3D 0) > unp->unp_ino =3D (++unp_ino =3D=3D 0) ? ++unp_ino : = unp_ino; > sb->st_ino =3D unp->unp_ino; > UNP_PCB_UNLOCK(unp); > - UNP_LINK_RUNLOCK(); > return (0); > } >=20 > @@ -2497,8 +2484,7 @@ DB_SHOW_COMMAND(unpcb, db_show_unpcb) > /* XXXRW: Would be nice to print the full address, if any. */ > db_printf("unp_addr: %p\n", unp->unp_addr); >=20 > - db_printf("unp_cc: %d unp_mbcnt: %d unp_gencnt: %llu\n", > - unp->unp_cc, unp->unp_mbcnt, > + db_printf("unp_gencnt: %llu\n", > (unsigned long long)unp->unp_gencnt); >=20 > db_printf("unp_flags: %x (", unp->unp_flags); >=20 > Modified: head/sys/sys/sockbuf.h > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/sys/sys/sockbuf.h Fri Mar 7 23:26:14 2014 = (r262913) > +++ head/sys/sys/sockbuf.h Fri Mar 7 23:30:48 2014 = (r262914) > @@ -52,6 +52,7 @@ > #define SB_NOCOALESCE 0x200 /* don't coalesce new = data into existing mbufs */ > #define SB_IN_TOE 0x400 /* socket buffer is in = the middle of an operation */ > #define SB_AUTOSIZE 0x800 /* automatically size = socket buffer */ > +#define SB_STOP 0x1000 /* backpressure = indicator */ >=20 > #define SBS_CANTSENDMORE 0x0010 /* can't send more data = to peer */ > #define SBS_CANTRCVMORE 0x0020 /* can't receive more = data from peer */ > @@ -168,9 +169,19 @@ void sbunlock(struct sockbuf *sb); > * still be negative (cc > hiwat or mbcnt > mbmax). Should detect > * overflow and return 0. Should use "lmin" but it doesn't exist now. > */ > -#define sbspace(sb) \ > - ((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \ > - (int)((sb)->sb_mbmax - (sb)->sb_mbcnt))) > +static __inline > +long > +sbspace(struct sockbuf *sb) > +{ > + long bleft; > + long mleft; > + > + if (sb->sb_flags & SB_STOP) > + return(0); > + bleft =3D sb->sb_hiwat - sb->sb_cc; > + mleft =3D sb->sb_mbmax - sb->sb_mbcnt; > + return((bleft < mleft) ? bleft : mleft); > +} >=20 > /* adjust counters in sb reflecting allocation of m */ > #define sballoc(sb, m) { \ >=20 > Modified: head/sys/sys/unpcb.h > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/sys/sys/unpcb.h Fri Mar 7 23:26:14 2014 = (r262913) > +++ head/sys/sys/unpcb.h Fri Mar 7 23:30:48 2014 = (r262914) > @@ -74,8 +74,8 @@ struct unpcb { > struct unp_head unp_refs; /* referencing socket linked = list */ > LIST_ENTRY(unpcb) unp_reflink; /* link in unp_refs list */ > struct sockaddr_un *unp_addr; /* bound address of socket */ > - int unp_cc; /* copy of rcv.sb_cc */ > - int unp_mbcnt; /* copy of rcv.sb_mbcnt */ > + int reserved1; > + int reserved2; > unp_gen_t unp_gencnt; /* generation count of this = instance */ > short unp_flags; /* flags */ > short unp_gcflag; /* Garbage collector flags. */ >=20