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

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

--eJnRUKwClWJh1Khz
Content-Type: multipart/mixed; boundary="opJtzjQTFsWo+cga"
Content-Disposition: inline


--opJtzjQTFsWo+cga
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Apr 25, 2005 at 05:23:14PM +0200, Marc Olzheim wrote:
> 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 w=
orth
> > my while, though, but I'm happy to look at a patch.
>=20
> 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. ;-)

More like this then...

Marc

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

--- sys/sys/uio.h.orig	Mon Apr 25 18:23:58 2005
+++ sys/sys/uio.h	Mon Apr 25 18:30:54 2005
@@ -101,6 +101,8 @@
 __BEGIN_DECLS
 ssize_t	readv(int, const struct iovec *, int);
 ssize_t	writev(int, const struct iovec *, int);
+ssize_t	preadv(int, const struct iovec *, int, off_t);
+ssize_t	pwritev(int, const struct iovec *, int, off_t);
 __END_DECLS
=20
 #endif /* _KERNEL */
--- sys/compat/freebsd32/syscalls.master.orig	Mon Apr 25 16:56:52 2005
+++ sys/compat/freebsd32/syscalls.master	Mon Apr 25 18:45:38 2005
@@ -406,8 +406,13 @@
 286	UNIMPL	nosys
 287	UNIMPL	nosys
 288	UNIMPL	nosys
-289	UNIMPL	nosys
-290	UNIMPL	nosys
+; 289 and 290 from NetBSD (OpenBSD: 267 and 268)
+289	STD { ssize_t freebsd32_preadv(int fd, u_int iovcnt,\
+		    struct uio * auio, off_t offset); }
+; XXX note - bigendian is different
+290	STD { ssize_t freebsd32_pwritev(int fd, u_int iovcnt,\
+		    struct uio * auio, off_t offset); }
+; XXX note - bigendian is different
 291	UNIMPL	nosys
 292	UNIMPL	nosys
 293	UNIMPL	nosys
--- sys/kern/syscalls.master.orig	Mon Apr 25 16:56:40 2005
+++ sys/kern/syscalls.master	Mon Apr 25 18:45:47 2005
@@ -411,8 +411,11 @@
 286	UNIMPL	nosys
 287	UNIMPL	nosys
 288	UNIMPL	nosys
-289	UNIMPL	nosys
-290	UNIMPL	nosys
+; 289 and 290 from NetBSD (OpenBSD: 267 and 268)
+289	MSTD	{ ssize_t preadv(int fd, struct iovec *iovp, u_int iovcnt,\
+		    off_t offset); }
+290	MSTD	{ ssize_t pwritev(int fd, struct iovec *iovp, u_int iovcnt,\
+		    off_t offset); }
 291	UNIMPL	nosys
 292	UNIMPL	nosys
 293	UNIMPL	nosys
--- sys/kern/sys_generic.c.orig	Mon Apr 25 16:12:58 2005
+++ sys/kern/sys_generic.c	Mon Apr 25 18:32:03 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,47 @@
 	return (error);
 }
=20
+/*
+ * Scatter positioned read system call.
+ */
+#ifndef _SYS_SYSPROTO_H_
+struct preadv_args {
+	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 (dopreadv(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 +293,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 +471,47 @@
 	return (error);
 }
=20
+/*
+ * Gather posiotioned write system call
+ */
+#ifndef _SYS_SYSPROTO_H_
+struct pwritev_args {
+	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 +524,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 +532,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;

--opJtzjQTFsWo+cga--

--eJnRUKwClWJh1Khz
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iD8DBQFCbR/hezjnobFOgrERArm7AJ9SUMPqAnJNxu8gEzIbx79NQYnv3QCeKQiA
HCBATn7DpLpRueO8eOo2dLM=
=wSia
-----END PGP SIGNATURE-----

--eJnRUKwClWJh1Khz--



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