Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Apr 2005 17:23:14 +0200
From:      Marc Olzheim <marcolz@stack.nl>
To:        Marc Olzheim <marcolz@stack.nl>, freebsd-hackers@freebsd.org
Subject:   Re: preadv() / pwritev()
Message-ID:  <20050425152314.GB58044@stack.nl>
In-Reply-To: <20050425135044.GD769@empiric.icir.org>
References:  <20050425101008.GA57542@stack.nl> <20050425135044.GD769@empiric.icir.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--NMuMz9nt05w80d4+
Content-Type: multipart/mixed; boundary="XsQoSWH+UP9D9v3l"
Content-Disposition: inline


--XsQoSWH+UP9D9v3l
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Mon, Apr 25, 2005 at 02:50:45PM +0100, Bruce M Simpson wrote:
> I don't do enough thread-based programming at the moment to make this worth
> my while, though, but I'm happy to look at a patch.

Ok, something like this ?
I'm a bit puzzled by the coding style in the file, but I think I got the
spirit of it. ;-)

Possibly more of dofileread() and dopreadv() and their write-cousins
could be merged into each other, but this patch is better readable...

Marc

--XsQoSWH+UP9D9v3l
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="preadv.patch"
Content-Transfer-Encoding: quoted-printable

--- sys/kern/syscalls.master	Mon Apr 25 16:56:40 2005
+++ sys/kern/syscalls.master	Mon Apr 25 17:05:07 2005
@@ -646,6 +646,10 @@
 454	MSTD	{ int _umtx_op(struct umtx *umtx, int op, long id, void *uaddr,\
 		    void *uaddr2); }
 455	MSTD	{ int thr_new(struct thr_param *param, int param_size); }
+456	MSTD	{ ssize_t preadv(struct thread *td, int fd, struct uio * auio,\
+		    u_int iovcnt, off_t offset, int flags); }
+457	MSTD	{ ssize_t pwritev(struct thread *td, int fd, struct uio * auio,\
+		    u_int iovcnt, off_t offset, int flags); }
=20
 ; Please copy any additions and changes to the following compatability tab=
les:
 ; sys/compat/freebsd32/syscalls.master
--- sys/compat/freebsd32/syscalls.master	Mon Apr 25 16:56:52 2005
+++ sys/compat/freebsd32/syscalls.master	Mon Apr 25 17:05:31 2005
@@ -620,3 +620,9 @@
 452	UNIMPL	setaudit_addr
 453	UNIMPL	auditctl
 454	UNIMPL	_umtx_op
+456	STD { ssize_t freebsd32_preadv(struct thread *td, int fd,\
+		    u_int iovcnt, struct uio * auio, off_t offset, int flags); }
+; XXX note - bigendian is different
+457	STD { ssize_t freebsd32_pwritev(struct thread *td, int fd,\
+		    u_int iovcnt, struct uio * auio, off_t offset, int flags); }
+; XXX note - bigendian is different
--- sys/kern/sys_generic.c	Mon Apr 25 16:12:58 2005
+++ sys/kern/sys_generic.c	Mon Apr 25 17:19:49 2005
@@ -80,6 +80,8 @@
 		    size_t, off_t, int);
 static int	dofilewrite(struct thread *, struct file *, int,
 		    const void *, size_t, off_t, int);
+static int	dopreadv(struct thread *, int, struct uio *, off_t, int);
+static int	dopwritev(struct thread *, int, struct uio *, off_t, int);
 static void	doselwakeup(struct selinfo *, int);
=20
 /*
@@ -233,9 +235,48 @@
 	return (error);
 }
=20
+/*
+ * Scatter positioned read system call.
+ */
+#ifndef _SYS_SYSPROTO_H_
+struct preadv_args {
+	struct thread	*td;
+	int	fd;
+	struct	iovec *iovp;
+	u_int	iovcnt;
+	off_t	offset;
+};
+#endif
+/*
+ * MPSAFE
+ */
+int
+preadv(struct thread *td, struct preadv_args *uap)
+{
+	struct uio *auio;
+	int error;
+
+	error =3D copyinuio(uap->iovp, uap->iovcnt, &auio);
+	if (error)
+		return (error);
+	error =3D dopreadv(td, uap->fd, auio, uap->offset, FOF_OFFSET);
+	free(auio, M_IOV);
+	return (error);
+}
+
 int
 kern_readv(struct thread *td, int fd, struct uio *auio)
 {
+	return (preadv(td, fd, auio, (off_t)-1, 0));
+}
+
+static int
+dopreadv(td, fd, auio, offset, flags)
+	struct thread *td;
+	struct uio *auio;
+	int fd, flags;
+	off_t offset;
+{
 	struct file *fp;
 	long cnt;
 	int error;
@@ -253,13 +294,14 @@
 		return(0);
 	}
 	auio->uio_rw =3D UIO_READ;
+	auio->uio_offset =3D offset;
 	auio->uio_td =3D td;
 #ifdef KTRACE
 	if (KTRPOINT(td, KTR_GENIO))=20
 		ktruio =3D cloneuio(auio);
 #endif
 	cnt =3D auio->uio_resid;
-	if ((error =3D fo_read(fp, auio, td->td_ucred, 0, td))) {
+	if ((error =3D fo_read(fp, auio, td->td_ucred, flags, td))) {
 		if (auio->uio_resid !=3D cnt && (error =3D=3D ERESTART ||
 		    error =3D=3D EINTR || error =3D=3D EWOULDBLOCK))
 			error =3D 0;
@@ -430,9 +472,48 @@
 	return (error);
 }
=20
+/*
+ * Gather posiotioned write system call
+ */
+#ifndef _SYS_SYSPROTO_H_
+struct pwritev_args {
+	struct thread	*td;
+	int	fd;
+	struct	iovec *iovp;
+	u_int	iovcnt;
+	off_t	offset;
+};
+#endif
+/*
+ * MPSAFE
+ */
+int
+pwritev(struct thread *td, struct pwritev_args *uap)
+{
+	struct uio *auio;
+	int error;
+
+	error =3D copyinuio(uap->iovp, uap->iovcnt, &auio);
+	if (error)
+		return (error);
+	error =3D dopwritev(td, uap->fd, auio, uap->offset, FOF_OFFSET);
+	free(auio, M_IOV);
+	return (error);
+}
+
 int
 kern_writev(struct thread *td, int fd, struct uio *auio)
 {
+	return (dopwritev(td, fd, auio, (off_t)-1 , 0));
+}
+
+static int
+dopwritev(td, fd, auio, offset, flags)
+	struct thread *td;
+	struct uio *auio;
+	int fd, flags;
+	off_t offset;
+{
 	struct file *fp;
 	long cnt;
 	int error;
@@ -445,6 +526,7 @@
 		return (EBADF);
 	auio->uio_rw =3D UIO_WRITE;
 	auio->uio_td =3D td;
+	auio->uio_offset =3D offset;
 #ifdef KTRACE
 	if (KTRPOINT(td, KTR_GENIO))
 		ktruio =3D cloneuio(auio);
@@ -452,7 +534,7 @@
 	cnt =3D auio->uio_resid;
 	if (fp->f_type =3D=3D DTYPE_VNODE)
 		bwillwrite();
-	if ((error =3D fo_write(fp, auio, td->td_ucred, 0, td))) {
+	if ((error =3D fo_write(fp, auio, td->td_ucred, flags, td))) {
 		if (auio->uio_resid !=3D cnt && (error =3D=3D ERESTART ||
 		    error =3D=3D EINTR || error =3D=3D EWOULDBLOCK))
 			error =3D 0;

--XsQoSWH+UP9D9v3l--

--NMuMz9nt05w80d4+
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (FreeBSD)

iD8DBQFCbQtiezjnobFOgrERAqF/AKDOtzDvrS4zI9zI3OtQi+0RjLnH4gCgxtSJ
meh9Z7M+aIVDjZWl6fvYzKA=
=DuNq
-----END PGP SIGNATURE-----

--NMuMz9nt05w80d4+--



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