PERFORCE change 120082 for review
John Baldwin
jhb at FreeBSD.org
Sat May 19 21:37:50 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=120082
Change 120082 by jhb at jhb_mutex on 2007/05/19 21:37:04
IFC @120081
Affected files ...
.. //depot/projects/smpng/sys/kern/kern_sx.c#50 integrate
.. //depot/projects/smpng/sys/kern/uipc_syscalls.c#106 integrate
.. //depot/projects/smpng/sys/sys/sx.h#29 integrate
Differences ...
==== //depot/projects/smpng/sys/kern/kern_sx.c#50 (text+ko) ====
@@ -40,7 +40,7 @@
#include "opt_ddb.h"
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/kern_sx.c,v 1.49 2007/05/19 20:18:12 jhb Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/kern_sx.c,v 1.50 2007/05/19 21:26:05 jhb Exp $");
#include <sys/param.h>
#include <sys/ktr.h>
@@ -139,7 +139,7 @@
struct sx *sx;
sx = (struct sx *)lock;
- sx_assert(sx, SX_LOCKED | SX_NOTRECURSED);
+ sx_assert(sx, SA_LOCKED | SA_NOTRECURSED);
if (sx_xlocked(sx)) {
sx_xunlock(sx);
return (1);
@@ -273,7 +273,7 @@
MPASS(curthread != NULL);
KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
("sx_sunlock() of destroyed sx @ %s:%d", file, line));
- _sx_assert(sx, SX_SLOCKED, file, line);
+ _sx_assert(sx, SA_SLOCKED, file, line);
curthread->td_locks--;
WITNESS_UNLOCK(&sx->lock_object, 0, file, line);
LOCK_LOG_LOCK("SUNLOCK", &sx->lock_object, 0, 0, file, line);
@@ -289,7 +289,7 @@
MPASS(curthread != NULL);
KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
("sx_xunlock() of destroyed sx @ %s:%d", file, line));
- _sx_assert(sx, SX_XLOCKED, file, line);
+ _sx_assert(sx, SA_XLOCKED, file, line);
curthread->td_locks--;
WITNESS_UNLOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line);
LOCK_LOG_LOCK("XUNLOCK", &sx->lock_object, 0, sx->sx_recurse, file,
@@ -312,7 +312,7 @@
KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
("sx_try_upgrade() of destroyed sx @ %s:%d", file, line));
- _sx_assert(sx, SX_SLOCKED, file, line);
+ _sx_assert(sx, SA_SLOCKED, file, line);
/*
* Try to switch from one shared lock to an exclusive lock. We need
@@ -339,7 +339,7 @@
KASSERT(sx->sx_lock != SX_LOCK_DESTROYED,
("sx_downgrade() of destroyed sx @ %s:%d", file, line));
- _sx_assert(sx, SX_XLOCKED | SX_NOTRECURSED, file, line);
+ _sx_assert(sx, SA_XLOCKED | SA_NOTRECURSED, file, line);
#ifndef INVARIANTS
if (sx_recursed(sx))
panic("downgrade of a recursed lock");
@@ -845,16 +845,16 @@
if (panicstr != NULL)
return;
switch (what) {
- case SX_SLOCKED:
- case SX_SLOCKED | SX_NOTRECURSED:
- case SX_SLOCKED | SX_RECURSED:
+ case SA_SLOCKED:
+ case SA_SLOCKED | SA_NOTRECURSED:
+ case SA_SLOCKED | SA_RECURSED:
#ifndef WITNESS
slocked = 1;
/* FALLTHROUGH */
#endif
- case SX_LOCKED:
- case SX_LOCKED | SX_NOTRECURSED:
- case SX_LOCKED | SX_RECURSED:
+ case SA_LOCKED:
+ case SA_LOCKED | SA_NOTRECURSED:
+ case SA_LOCKED | SA_RECURSED:
#ifdef WITNESS
witness_assert(&sx->lock_object, what, file, line);
#else
@@ -872,31 +872,31 @@
if (!(sx->sx_lock & SX_LOCK_SHARED)) {
if (sx_recursed(sx)) {
- if (what & SX_NOTRECURSED)
+ if (what & SA_NOTRECURSED)
panic("Lock %s recursed @ %s:%d\n",
sx->lock_object.lo_name, file,
line);
- } else if (what & SX_RECURSED)
+ } else if (what & SA_RECURSED)
panic("Lock %s not recursed @ %s:%d\n",
sx->lock_object.lo_name, file, line);
}
#endif
break;
- case SX_XLOCKED:
- case SX_XLOCKED | SX_NOTRECURSED:
- case SX_XLOCKED | SX_RECURSED:
+ case SA_XLOCKED:
+ case SA_XLOCKED | SA_NOTRECURSED:
+ case SA_XLOCKED | SA_RECURSED:
if (sx_xholder(sx) != curthread)
panic("Lock %s not exclusively locked @ %s:%d\n",
sx->lock_object.lo_name, file, line);
if (sx_recursed(sx)) {
- if (what & SX_NOTRECURSED)
+ if (what & SA_NOTRECURSED)
panic("Lock %s recursed @ %s:%d\n",
sx->lock_object.lo_name, file, line);
- } else if (what & SX_RECURSED)
+ } else if (what & SA_RECURSED)
panic("Lock %s not recursed @ %s:%d\n",
sx->lock_object.lo_name, file, line);
break;
- case SX_UNLOCKED:
+ case SA_UNLOCKED:
#ifdef WITNESS
witness_assert(&sx->lock_object, what, file, line);
#else
==== //depot/projects/smpng/sys/kern/uipc_syscalls.c#106 (text+ko) ====
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/uipc_syscalls.c,v 1.255 2007/05/16 20:41:08 rwatson Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/uipc_syscalls.c,v 1.256 2007/05/19 20:50:59 andre Exp $");
#include "opt_sctp.h"
#include "opt_compat.h"
@@ -1819,8 +1819,8 @@
struct mbuf *m = NULL;
struct sf_buf *sf;
struct vm_page *pg;
- off_t off, xfsize, sbytes = 0, rem = 0;
- int error, mnw = 0;
+ off_t off, xfsize, fsbytes = 0, sbytes = 0, rem = 0;
+ int error, hdrlen = 0, mnw = 0;
int vfslocked;
NET_LOCK_GIANT();
@@ -1916,6 +1916,7 @@
error = mnw ? EAGAIN : ENOBUFS;
goto out;
}
+ hdrlen = m_length(m, NULL);
}
}
@@ -1933,7 +1934,7 @@
* The outer loop checks the state and available space of the socket
* and takes care of the overall progress.
*/
- for (off = uap->offset; ; ) {
+ for (off = uap->offset, rem = uap->nbytes; ; ) {
int loopbytes = 0;
int space = 0;
int done = 0;
@@ -1998,6 +1999,13 @@
SOCKBUF_UNLOCK(&so->so_snd);
/*
+ * Reduce space in the socket buffer by the size of
+ * the header mbuf chain.
+ * hdrlen is set to 0 after the first loop.
+ */
+ space -= hdrlen;
+
+ /*
* Loop and construct maximum sized mbuf chain to be bulk
* dumped into socket buffer.
*/
@@ -2015,12 +2023,12 @@
pgoff = (vm_offset_t)(off & PAGE_MASK);
xfsize = omin(PAGE_SIZE - pgoff,
obj->un_pager.vnp.vnp_size - uap->offset -
- sbytes - loopbytes);
+ fsbytes - loopbytes);
if (uap->nbytes)
- rem = (uap->nbytes - sbytes - loopbytes);
+ rem = (uap->nbytes - fsbytes - loopbytes);
else
- rem = obj->un_pager.vnp.vnp_size - uap->offset -
- sbytes - loopbytes;
+ rem = obj->un_pager.vnp.vnp_size -
+ uap->offset - fsbytes - loopbytes;
xfsize = omin(rem, xfsize);
if (xfsize <= 0) {
VM_OBJECT_UNLOCK(obj);
@@ -2038,9 +2046,8 @@
}
/*
- * Attempt to look up the page.
- * Allocate if not found or
- * wait and loop if busy.
+ * Attempt to look up the page. Allocate
+ * if not found or wait and loop if busy.
*/
pindex = OFF_TO_IDX(off);
pg = vm_page_grab(obj, pindex, VM_ALLOC_NOBUSY |
@@ -2161,7 +2168,7 @@
/* Add the buffer chain to the socket buffer. */
if (m != NULL) {
- int mlen;
+ int mlen, err;
mlen = m_length(m, NULL);
SOCKBUF_LOCK(&so->so_snd);
@@ -2171,10 +2178,27 @@
goto done;
}
SOCKBUF_UNLOCK(&so->so_snd);
- error = (*so->so_proto->pr_usrreqs->pru_send)
+ /* Avoid error aliasing. */
+ err = (*so->so_proto->pr_usrreqs->pru_send)
(so, 0, m, NULL, NULL, td);
- if (!error)
+ if (err == 0) {
+ /*
+ * We need two counters to get the
+ * file offset and nbytes to send
+ * right:
+ * - sbytes contains the total amount
+ * of bytes sent, including headers.
+ * - fsbytes contains the total amount
+ * of bytes sent from the file.
+ */
sbytes += mlen;
+ fsbytes += mlen;
+ if (hdrlen) {
+ fsbytes -= hdrlen;
+ hdrlen = 0;
+ }
+ } else if (error == 0)
+ error = err;
m = NULL; /* pru_send always consumes */
}
==== //depot/projects/smpng/sys/sys/sx.h#29 (text+ko) ====
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
- * $FreeBSD: src/sys/sys/sx.h,v 1.33 2007/05/19 20:18:12 jhb Exp $
+ * $FreeBSD: src/sys/sys/sx.h,v 1.34 2007/05/19 21:26:05 jhb Exp $
*/
#ifndef _SYS_SX_H_
@@ -245,10 +245,15 @@
#define SX_ADAPTIVESPIN 0x10
#define SX_RECURSE 0x20
-/*
- * XXX: These options should be renamed as SA_*
- */
#if defined(INVARIANTS) || defined(INVARIANT_SUPPORT)
+#define SA_LOCKED LA_LOCKED
+#define SA_SLOCKED LA_SLOCKED
+#define SA_XLOCKED LA_XLOCKED
+#define SA_UNLOCKED LA_UNLOCKED
+#define SA_RECURSED LA_RECURSED
+#define SA_NOTRECURSED LA_NOTRECURSED
+
+/* Backwards compatability. */
#define SX_LOCKED LA_LOCKED
#define SX_SLOCKED LA_SLOCKED
#define SX_XLOCKED LA_XLOCKED
More information about the p4-projects
mailing list