Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Sep 2009 18:49:45 +0000 (UTC)
From:      Kip Macy <kmacy@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r196899 - in user/kmacy/releng_7_2_fcs_1/sys: kern sys
Message-ID:  <200909061849.n86InjVw091602@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kmacy
Date: Sun Sep  6 18:49:45 2009
New Revision: 196899
URL: http://svn.freebsd.org/changeset/base/196899

Log:
  clean up byte accounting

Modified:
  user/kmacy/releng_7_2_fcs_1/sys/kern/uipc_socket.c
  user/kmacy/releng_7_2_fcs_1/sys/kern/uipc_syscalls.c
  user/kmacy/releng_7_2_fcs_1/sys/sys/sockstate.h

Modified: user/kmacy/releng_7_2_fcs_1/sys/kern/uipc_socket.c
==============================================================================
--- user/kmacy/releng_7_2_fcs_1/sys/kern/uipc_socket.c	Sun Sep  6 18:48:18 2009	(r196898)
+++ user/kmacy/releng_7_2_fcs_1/sys/kern/uipc_socket.c	Sun Sep  6 18:49:45 2009	(r196899)
@@ -3170,7 +3170,7 @@ socketref_free(struct socketref *sr)
 void
 soissending(struct socket *so, struct thread *td,
     struct sendfile_args *uap, struct uio *hdr_uio,
-    struct uio *trl_uio, int compat, int sbytes)
+    struct uio *trl_uio, int compat, off_t sbytes)
 {
 	struct socketref *ref;
 	int error;
@@ -3190,7 +3190,7 @@ soissending(struct socket *so, struct th
 	PROC_LOCK(td->td_proc);
 	td->td_proc->p_lock++;
 	PROC_UNLOCK(td->td_proc);
-   
+
 	ref->sr_proc = td->td_proc;
 
 	if ((error = getsock(td->td_proc->p_fd, uap->s, &ref->sr_sock_fp,
@@ -3222,6 +3222,7 @@ soissending(struct socket *so, struct th
 	bcopy(uap, &ref->sr_uap, sizeof(*uap));
 	ref->sr_uap.sbytes = NULL;
 	ref->sr_uap.offset += sbytes;
+	ref->sr_sock_fp->f_sfbytes = 0;
 	if (uap->nbytes)
 		ref->sr_uap.nbytes -= sbytes;
 	/*
@@ -3237,6 +3238,8 @@ soissending(struct socket *so, struct th
 	ref->sr_compat = compat;
 	ref->sr_magic = 0xCAFEBABE;
 	TASK_INIT(&ref->sr_task, 0, sendfile_task_func, ref);
+	CTR4(KTR_SPARE1, "sock %p off %ld sbytes %ld total_sbytes %ld",
+	    so, ref->sr_uap.offset, sbytes, ref->sr_fp->f_sfbytes);
 
 	CTR3(KTR_SPARE2, "enqueueing socket %p sock_fp %p s %d", so, ref->sr_sock_fp, uap->s);
 	mtx_lock(&sendfile_bg_lock);
@@ -3258,9 +3261,9 @@ sendfile_task_func(void *context, int pe
 	struct socket *so;
 	struct sockbuf *sb;
 	struct file *sock_fp, *fp;
-	int error, writeable;
+	int error = EAGAIN;
 	struct uio *hdr_uio = NULL, *trl_uio = NULL;
-	off_t sbytes;
+	off_t sbytes = 0;
 
 	sr = context;
 	CTR0(KTR_SPARE2, "task_func running");
@@ -3313,18 +3316,18 @@ sendfile_task_func(void *context, int pe
 		sr->sr_uap.offset += sbytes;
 		if (sr->sr_uap.nbytes)
 			sr->sr_uap.nbytes -= sbytes;
-		/*
-		 * XXX we have a race here 
-		 * - if sbdrop is called before a re-enqueue,
-		 *   we'll have a lost wakeup ... maybe call
-		 * sosendingwakup? Or check for sowriteable(so)	
-		 */
+
+		CTR4(KTR_SPARE1, "sock %p off %ld sbytes %ld total_sbytes %ld",
+		    so, sr->sr_uap.offset, sbytes, fp->f_sfbytes);
 		SOCKBUF_LOCK(sb);
-		if (error == EAGAIN && srsendingwakeup(sr) != ENOTCONN) {
-			SOCKBUF_UNLOCK(sb);
-			return;
-		}
-	} 
+	}
+
+	if (error == EAGAIN && srsendingwakeup(sr) != ENOTCONN) {
+		SOCKBUF_UNLOCK(sb);
+		return;
+	} else if (error != EAGAIN) 
+		CTR1(KTR_SPARE1, "error %d", error); 
+
 	sb->sb_flags &= ~SB_SENDING;
 	sowwakeup_locked(so);
 done:
@@ -3352,25 +3355,27 @@ srsendingwakeup(struct socketref *sr) 
 	fp = sr->sr_sock_fp;
 	CTR2(KTR_SPARE2, "processing s %d sock_fp %p", sr->sr_uap.s, fp);
 	if (fp->f_type != DTYPE_SOCKET) {
-		CTR1(KTR_SPARE2, "not socket - type %d", fp->f_type);
+		CTR1(KTR_SPARE1, "not socket - type %d", fp->f_type);
 		goto error;
 	}
 	so = fp->f_data;
 	if ((so->so_state & SS_ISCONNECTED) == 0) {
-		CTR0(KTR_SPARE2, "not connected %p");
+		CTR1(KTR_SPARE1, "not connected %p", so);
 		goto error;
 	}
 
 	CTR1(KTR_SPARE2, "processing socket %p", so);
 	sb = &so->so_snd;
 	SOCKBUF_LOCK_ASSERT(sb);
+	sb->sb_flags &= ~SB_SENDING;
 	if (sb->sb_state & SBS_CANTSENDMORE) {
-		;
+		CTR1(KTR_SPARE1, "SBS_CANTSENDMORE %p", so);
 	} else if (sowriteable(so)) {
 		CTR2(KTR_SPARE2, "enqueue socket to task %p sr %p", so, sr);
 		sb->sb_flags |= SB_SENDING;
 		taskqueue_enqueue(sendfile_tq, &sr->sr_task);
 	} else {
+		sb->sb_flags |= SB_SENDING;
 		mtx_lock(&sendfile_bg_lock);
 		TAILQ_INSERT_TAIL(sendfile_bg_queue, sr, entry);
 		mtx_unlock(&sendfile_bg_lock);

Modified: user/kmacy/releng_7_2_fcs_1/sys/kern/uipc_syscalls.c
==============================================================================
--- user/kmacy/releng_7_2_fcs_1/sys/kern/uipc_syscalls.c	Sun Sep  6 18:48:18 2009	(r196898)
+++ user/kmacy/releng_7_2_fcs_1/sys/kern/uipc_syscalls.c	Sun Sep  6 18:49:45 2009	(r196899)
@@ -1873,7 +1873,6 @@ kern_sendfile(struct thread *td, struct 
 		so = bgso;
 	}
 
-	SOCKBUF_LOCK(&so->so_snd);
 	if ((uap->flags & SF_TASKQ) == 0 &&
 	    sock_fp->f_sfbytes != 0) {
 		SOCKBUF_UNLOCK(&so->so_snd);
@@ -1884,7 +1883,7 @@ kern_sendfile(struct thread *td, struct 
 		error = 0;
 		goto out;
 	}
-	SOCKBUF_UNLOCK(&so->so_snd);
+
 	
 	/*
 	 * Do not wait on memory allocations but return ENOMEM for
@@ -2246,7 +2245,10 @@ out:
 		td->td_retval[0] = 0;
 	}
 	if (uap->sbytes != NULL) {
-		copyout(&sbytes, uap->sbytes, sizeof(off_t));
+		if ((uap->flags & SF_TASKQ) == 0)
+			copyout(&sbytes, uap->sbytes, sizeof(off_t));
+		else
+			*(uap->sbytes) = sbytes;
 	}
 	if (obj != NULL)
 		vm_object_deallocate(obj);

Modified: user/kmacy/releng_7_2_fcs_1/sys/sys/sockstate.h
==============================================================================
--- user/kmacy/releng_7_2_fcs_1/sys/sys/sockstate.h	Sun Sep  6 18:48:18 2009	(r196898)
+++ user/kmacy/releng_7_2_fcs_1/sys/sys/sockstate.h	Sun Sep  6 18:49:45 2009	(r196899)
@@ -81,7 +81,7 @@ void	soisdisconnecting(struct socket *so
 void	soissending(struct socket *so,
     struct thread *td, struct sendfile_args *uap,
     struct uio *hdr_uio, struct uio *trl_uio,
-    int compat, int sbytes);
+    int compat, off_t sbytes);
 void	sosendingwakeup(struct sockbuf *sb);
 void	socantrcvmore(struct socket *so);
 void	socantrcvmore_locked(struct socket *so);



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