Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Sep 2004 02:18:14 -0700
From:      Alfred Perlstein <alfred@freebsd.org>
To:        alc@freebsd.org
Cc:        net@freebsd.org
Subject:   aio patch for review.
Message-ID:  <20040930091814.GG39252@elvis.mu.org>

next in thread | raw e-mail | index | archive | help
properly cover the socket buffer for operations that need locking.

please review.


Index: vfs_aio.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/vfs_aio.c,v
retrieving revision 1.176
diff -u -r1.176 vfs_aio.c
--- vfs_aio.c	23 Sep 2004 14:45:04 -0000	1.176
+++ vfs_aio.c	30 Sep 2004 09:15:10 -0000
@@ -1297,6 +1297,7 @@
 	struct kevent kev;
 	struct kqueue *kq;
 	struct file *kq_fp;
+	struct sockbuf *sb;
 
 	aiocbe = uma_zalloc(aiocb_zone, M_WAITOK);
 	aiocbe->inputcharge = 0;
@@ -1451,29 +1452,28 @@
 		 * If it is not ready for io, then queue the aiocbe on the
 		 * socket, and set the flags so we get a call when sbnotify()
 		 * happens.
+		 *
+		 * Note if opcode is neither LIO_WRITE nor LIO_READ we lock
+		 * and unlock the snd sockbuf for no reason.
 		 */
 		so = fp->f_data;
+		sb = (opcode == LIO_READ) ? &so->so_rcv : &so->so_snd;
+		SOCKBUF_LOCK(sb);
 		s = splnet();
 		if (((opcode == LIO_READ) && (!soreadable(so))) || ((opcode ==
 		    LIO_WRITE) && (!sowriteable(so)))) {
 			TAILQ_INSERT_TAIL(&so->so_aiojobq, aiocbe, list);
 			TAILQ_INSERT_TAIL(&ki->kaio_sockqueue, aiocbe, plist);
-			if (opcode == LIO_READ) {
-				SOCKBUF_LOCK(&so->so_rcv);
-				so->so_rcv.sb_flags |= SB_AIO;
-				SOCKBUF_UNLOCK(&so->so_rcv);
-			} else {
-				SOCKBUF_LOCK(&so->so_snd);
-				so->so_snd.sb_flags |= SB_AIO;
-				SOCKBUF_UNLOCK(&so->so_snd);
-			}
+			sb->sb_flags |= SB_AIO;
 			aiocbe->jobstate = JOBST_JOBQGLOBAL; /* XXX */
 			ki->kaio_queue_count++;
 			num_queue_count++;
+			SOCKBUF_UNLOCK(sb);
 			splx(s);
 			error = 0;
 			goto done;
 		}
+		SOCKBUF_UNLOCK(sb);
 		splx(s);
 	}
 
-- 
- Alfred Perlstein
- Research Engineering Development Inc.
- email: bright@mu.org cell: 408-480-4684



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