From owner-svn-src-all@FreeBSD.ORG Wed Jan 21 18:52:34 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 38FB01065675; Wed, 21 Jan 2009 18:52:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2464A8FC2A; Wed, 21 Jan 2009 18:52:34 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n0LIqY3B087134; Wed, 21 Jan 2009 18:52:34 GMT (envelope-from jhb@svn.freebsd.org) Received: (from jhb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n0LIqYMS087131; Wed, 21 Jan 2009 18:52:34 GMT (envelope-from jhb@svn.freebsd.org) Message-Id: <200901211852.n0LIqYMS087131@svn.freebsd.org> From: John Baldwin Date: Wed, 21 Jan 2009 18:52:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r187559 - in stable/7/sys: . compat/freebsd32 contrib/pf dev/cxgb kern modules/aio X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jan 2009 18:52:35 -0000 Author: jhb Date: Wed Jan 21 18:52:33 2009 New Revision: 187559 URL: http://svn.freebsd.org/changeset/base/187559 Log: MFC: Add 32-bit compat system calls for VFS_AIO. Modified: stable/7/sys/ (props changed) stable/7/sys/compat/freebsd32/syscalls.master stable/7/sys/contrib/pf/ (props changed) stable/7/sys/dev/cxgb/ (props changed) stable/7/sys/kern/vfs_aio.c stable/7/sys/modules/aio/Makefile Modified: stable/7/sys/compat/freebsd32/syscalls.master ============================================================================== --- stable/7/sys/compat/freebsd32/syscalls.master Wed Jan 21 18:47:52 2009 (r187558) +++ stable/7/sys/compat/freebsd32/syscalls.master Wed Jan 21 18:52:33 2009 (r187559) @@ -456,9 +456,13 @@ u_int nfds, int timeout); } 253 AUE_ISSETUGID NOPROTO { int issetugid(void); } 254 AUE_LCHOWN NOPROTO { int lchown(char *path, int uid, int gid); } -255 AUE_NULL UNIMPL nosys -256 AUE_NULL UNIMPL nosys -257 AUE_NULL UNIMPL nosys +255 AUE_NULL NOSTD { int freebsd32_aio_read( \ + struct aiocb32 *aiocbp); } +256 AUE_NULL NOSTD { int freebsd32_aio_write( \ + struct aiocb32 *aiocbp); } +257 AUE_NULL NOSTD { int freebsd32_lio_listio(int mode, \ + struct aiocb32 * const *acb_list, \ + int nent, struct sigevent *sig); } 258 AUE_NULL UNIMPL nosys 259 AUE_NULL UNIMPL nosys 260 AUE_NULL UNIMPL nosys @@ -537,13 +541,22 @@ 312 AUE_SETRESGID NOPROTO { int setresgid(gid_t rgid, gid_t egid, \ gid_t sgid); } 313 AUE_NULL OBSOL signanosleep -314 AUE_NULL UNIMPL aio_return -315 AUE_NULL UNIMPL aio_suspend -316 AUE_NULL UNIMPL aio_cancel -317 AUE_NULL UNIMPL aio_error -318 AUE_NULL UNIMPL aio_read -319 AUE_NULL UNIMPL aio_write -320 AUE_NULL UNIMPL lio_listio +314 AUE_NULL NOSTD { int freebsd32_aio_return( \ + struct aiocb32 *aiocbp); } +315 AUE_NULL NOSTD { int freebsd32_aio_suspend( \ + struct aiocb32 * const * aiocbp, int nent, \ + const struct timespec32 *timeout); } +316 AUE_NULL NOSTD { int freebsd32_aio_cancel(int fd, \ + struct aiocb32 *aiocbp); } +317 AUE_NULL NOSTD { int freebsd32_aio_error( \ + struct aiocb32 *aiocbp); } +318 AUE_NULL NOSTD { int freebsd32_oaio_read( \ + struct oaiocb32 *aiocbp); } +319 AUE_NULL NOSTD { int freebsd32_oaio_write( \ + struct oaiocb32 *aiocbp); } +320 AUE_NULL NOSTD { int freebsd32_olio_listio(int mode, \ + struct oaiocb32 * const *acb_list, \ + int nent, struct osigevent32 *sig); } 321 AUE_NULL NOPROTO { int yield(void); } 322 AUE_NULL OBSOL thr_sleep 323 AUE_NULL OBSOL thr_wakeup @@ -620,7 +633,9 @@ 358 AUE_EXTATTR_DELETE_FILE NOPROTO { int extattr_delete_file( \ const char *path, int attrnamespace, \ const char *attrname); } -359 AUE_NULL UNIMPL aio_waitcomplete +359 AUE_NULL NOSTD { int freebsd32_aio_waitcomplete( \ + struct aiocb32 **aiocbp, \ + struct timespec32 *timeout); } 360 AUE_GETRESUID NOPROTO { int getresuid(uid_t *ruid, uid_t *euid, \ uid_t *suid); } 361 AUE_GETRESGID NOPROTO { int getresgid(gid_t *rgid, gid_t *egid, \ @@ -770,7 +785,8 @@ 462 AUE_NULL UNIMPL kmq_unlink 463 AUE_NULL NOPROTO { int abort2(const char *why, int nargs, void **args); } 464 AUE_NULL NOPROTO { int thr_set_name(long id, const char *name); } -465 AUE_NULL UNIMPL aio_fsync +465 AUE_NULL NOSTD { int freebsd32_aio_fsync(int op, \ + struct aiocb32 *aiocbp); } 466 AUE_RTPRIO NOPROTO { int rtprio_thread(int function, \ lwpid_t lwpid, struct rtprio *rtp); } 467 AUE_NULL UNIMPL nosys Modified: stable/7/sys/kern/vfs_aio.c ============================================================================== --- stable/7/sys/kern/vfs_aio.c Wed Jan 21 18:47:52 2009 (r187558) +++ stable/7/sys/kern/vfs_aio.c Wed Jan 21 18:52:33 2009 (r187559) @@ -21,6 +21,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_compat.h" + #include #include #include @@ -121,6 +123,8 @@ static uint64_t jobseqno; FEATURE(aio, "Asynchronous I/O"); +static MALLOC_DEFINE(M_LIO, "lio", "listio aio control block list"); + static SYSCTL_NODE(_vfs, OID_AUTO, aio, CTLFLAG_RW, 0, "Async IO management"); static int max_aio_procs = MAX_AIO_PROCS; @@ -308,6 +312,20 @@ struct kaioinfo { #define KAIO_RUNDOWN 0x1 /* process is being run down */ #define KAIO_WAKEUP 0x2 /* wakeup process when there is a significant event */ +/* + * Operations used to interact with userland aio control blocks. + * Different ABIs provide their own operations. + */ +struct aiocb_ops { + int (*copyin)(struct aiocb *ujob, struct aiocb *kjob); + long (*fetch_status)(struct aiocb *ujob); + long (*fetch_error)(struct aiocb *ujob); + int (*store_status)(struct aiocb *ujob, long status); + int (*store_error)(struct aiocb *ujob, long error); + int (*store_kernelinfo)(struct aiocb *ujob, long jobref); + int (*store_aiocb)(struct aiocb **ujobp, struct aiocb *ujob); +}; + static TAILQ_HEAD(,aiothreadlist) aio_freeproc; /* (c) Idle daemons */ static struct sema aio_newproc_sem; static struct mtx aio_job_mtx; @@ -321,7 +339,7 @@ static int aio_free_entry(struct aiocbli static void aio_process(struct aiocblist *aiocbe); static int aio_newproc(int *); int aio_aqueue(struct thread *td, struct aiocb *job, - struct aioliojob *lio, int type, int osigev); + struct aioliojob *lio, int type, struct aiocb_ops *ops); static void aio_physwakeup(struct buf *bp); static void aio_proc_rundown(void *arg, struct proc *p); static void aio_proc_rundown_exec(void *arg, struct proc *p, struct image_params *imgp); @@ -333,7 +351,6 @@ static int aio_unload(void); static void aio_bio_done_notify(struct proc *userp, struct aiocblist *aiocbe, int type); #define DONE_BUF 1 #define DONE_QUEUE 2 -static int do_lio_listio(struct thread *td, struct lio_listio_args *uap, int oldsigev); static int aio_kick(struct proc *userp); static void aio_kick_nowait(struct proc *userp); static void aio_kick_helper(void *context, int pending); @@ -1322,13 +1339,122 @@ aio_swake_cb(struct socket *so, struct s SOCKBUF_UNLOCK(sb); } +static int +convert_old_sigevent(struct osigevent *osig, struct sigevent *nsig) +{ + + /* + * Only SIGEV_NONE, SIGEV_SIGNAL, and SIGEV_KEVENT are + * supported by AIO with the old sigevent structure. + */ + nsig->sigev_notify = osig->sigev_notify; + switch (nsig->sigev_notify) { + case SIGEV_NONE: + break; + case SIGEV_SIGNAL: + nsig->sigev_signo = osig->__sigev_u.__sigev_signo; + break; + case SIGEV_KEVENT: + nsig->sigev_notify_kqueue = + osig->__sigev_u.__sigev_notify_kqueue; + nsig->sigev_value.sival_ptr = osig->sigev_value.sival_ptr; + break; + default: + return (EINVAL); + } + return (0); +} + +static int +aiocb_copyin_old_sigevent(struct aiocb *ujob, struct aiocb *kjob) +{ + struct oaiocb *ojob; + int error; + + bzero(kjob, sizeof(struct aiocb)); + error = copyin(ujob, kjob, sizeof(struct oaiocb)); + if (error) + return (error); + ojob = (struct oaiocb *)kjob; + return (convert_old_sigevent(&ojob->aio_sigevent, &kjob->aio_sigevent)); +} + +static int +aiocb_copyin(struct aiocb *ujob, struct aiocb *kjob) +{ + + return (copyin(ujob, kjob, sizeof(struct aiocb))); +} + +static long +aiocb_fetch_status(struct aiocb *ujob) +{ + + return (fuword(&ujob->_aiocb_private.status)); +} + +static long +aiocb_fetch_error(struct aiocb *ujob) +{ + + return (fuword(&ujob->_aiocb_private.error)); +} + +static int +aiocb_store_status(struct aiocb *ujob, long status) +{ + + return (suword(&ujob->_aiocb_private.status, status)); +} + +static int +aiocb_store_error(struct aiocb *ujob, long error) +{ + + return (suword(&ujob->_aiocb_private.error, error)); +} + +static int +aiocb_store_kernelinfo(struct aiocb *ujob, long jobref) +{ + + return (suword(&ujob->_aiocb_private.kernelinfo, jobref)); +} + +static int +aiocb_store_aiocb(struct aiocb **ujobp, struct aiocb *ujob) +{ + + return (suword(ujobp, (long)ujob)); +} + +static struct aiocb_ops aiocb_ops = { + .copyin = aiocb_copyin, + .fetch_status = aiocb_fetch_status, + .fetch_error = aiocb_fetch_error, + .store_status = aiocb_store_status, + .store_error = aiocb_store_error, + .store_kernelinfo = aiocb_store_kernelinfo, + .store_aiocb = aiocb_store_aiocb, +}; + +static struct aiocb_ops aiocb_ops_osigevent = { + .copyin = aiocb_copyin_old_sigevent, + .fetch_status = aiocb_fetch_status, + .fetch_error = aiocb_fetch_error, + .store_status = aiocb_store_status, + .store_error = aiocb_store_error, + .store_kernelinfo = aiocb_store_kernelinfo, + .store_aiocb = aiocb_store_aiocb, +}; + /* * Queue a new AIO request. Choosing either the threaded or direct physio VCHR * technique is done in this code. */ int aio_aqueue(struct thread *td, struct aiocb *job, struct aioliojob *lj, - int type, int oldsigev) + int type, struct aiocb_ops *ops) { struct proc *p = td->td_proc; struct file *fp; @@ -1347,13 +1473,13 @@ aio_aqueue(struct thread *td, struct aio ki = p->p_aioinfo; - suword(&job->_aiocb_private.status, -1); - suword(&job->_aiocb_private.error, 0); - suword(&job->_aiocb_private.kernelinfo, -1); + ops->store_status(job, -1); + ops->store_error(job, 0); + ops->store_kernelinfo(job, -1); if (num_queue_count >= max_queue_count || ki->kaio_count >= ki->kaio_qallowed_count) { - suword(&job->_aiocb_private.error, EAGAIN); + ops->store_error(job, EAGAIN); return (EAGAIN); } @@ -1362,16 +1488,9 @@ aio_aqueue(struct thread *td, struct aio aiocbe->outputcharge = 0; knlist_init(&aiocbe->klist, AIO_MTX(ki), NULL, NULL, NULL); - if (oldsigev) { - bzero(&aiocbe->uaiocb, sizeof(struct aiocb)); - error = copyin(job, &aiocbe->uaiocb, sizeof(struct oaiocb)); - bcopy(&aiocbe->uaiocb.__spare__, &aiocbe->uaiocb.aio_sigevent, - sizeof(struct osigevent)); - } else { - error = copyin(job, &aiocbe->uaiocb, sizeof(struct aiocb)); - } + error = ops->copyin(job, &aiocbe->uaiocb); if (error) { - suword(&job->_aiocb_private.error, error); + ops->store_error(job, error); uma_zfree(aiocb_zone, aiocbe); return (error); } @@ -1380,11 +1499,11 @@ aio_aqueue(struct thread *td, struct aio aiocbe->uaiocb.aio_sigevent.sigev_notify != SIGEV_SIGNAL && aiocbe->uaiocb.aio_sigevent.sigev_notify != SIGEV_THREAD_ID && aiocbe->uaiocb.aio_sigevent.sigev_notify != SIGEV_NONE) { - suword(&job->_aiocb_private.error, EINVAL); + ops->store_error(job, EINVAL); uma_zfree(aiocb_zone, aiocbe); return (EINVAL); } - + if ((aiocbe->uaiocb.aio_sigevent.sigev_notify == SIGEV_SIGNAL || aiocbe->uaiocb.aio_sigevent.sigev_notify == SIGEV_THREAD_ID) && !_SIG_VALID(aiocbe->uaiocb.aio_sigevent.sigev_signo)) { @@ -1416,7 +1535,7 @@ aio_aqueue(struct thread *td, struct aio } if (error) { uma_zfree(aiocb_zone, aiocbe); - suword(&job->_aiocb_private.error, error); + ops->store_error(job, error); return (error); } @@ -1436,7 +1555,7 @@ aio_aqueue(struct thread *td, struct aio jid = jobrefid++; aiocbe->seqno = jobseqno++; mtx_unlock(&aio_job_mtx); - error = suword(&job->_aiocb_private.kernelinfo, jid); + error = ops->store_kernelinfo(job, jid); if (error) { error = EINVAL; goto aqueue_fail; @@ -1467,12 +1586,12 @@ aqueue_fail: if (error) { fdrop(fp, td); uma_zfree(aiocb_zone, aiocbe); - suword(&job->_aiocb_private.error, error); + ops->store_error(job, error); goto done; } no_kqueue: - suword(&job->_aiocb_private.error, EINPROGRESS); + ops->store_error(job, EINPROGRESS); aiocbe->uaiocb._aiocb_private.error = EINPROGRESS; aiocbe->userproc = p; aiocbe->cred = crhold(td->td_ucred); @@ -1528,7 +1647,7 @@ no_kqueue: #if 0 if (error > 0) { aiocbe->uaiocb._aiocb_private.error = error; - suword(&job->_aiocb_private.error, error); + ops->store_error(job, error); goto done; } #endif @@ -1643,19 +1762,17 @@ aio_kick_helper(void *context, int pendi * Support the aio_return system call, as a side-effect, kernel resources are * released. */ -int -aio_return(struct thread *td, struct aio_return_args *uap) +static int +kern_aio_return(struct thread *td, struct aiocb *uaiocb, struct aiocb_ops *ops) { struct proc *p = td->td_proc; struct aiocblist *cb; - struct aiocb *uaiocb; struct kaioinfo *ki; int status, error; ki = p->p_aioinfo; if (ki == NULL) return (EINVAL); - uaiocb = uap->aiocbp; AIO_LOCK(ki); TAILQ_FOREACH(cb, &ki->kaio_done, plist) { if (cb->uuaiocb == uaiocb) @@ -1675,8 +1792,8 @@ aio_return(struct thread *td, struct aio } aio_free_entry(cb); AIO_UNLOCK(ki); - suword(&uaiocb->_aiocb_private.error, error); - suword(&uaiocb->_aiocb_private.status, status); + ops->store_error(uaiocb, error); + ops->store_status(uaiocb, status); } else { error = EINVAL; AIO_UNLOCK(ki); @@ -1684,37 +1801,32 @@ aio_return(struct thread *td, struct aio return (error); } +int +aio_return(struct thread *td, struct aio_return_args *uap) +{ + + return (kern_aio_return(td, uap->aiocbp, &aiocb_ops)); +} + /* * Allow a process to wakeup when any of the I/O requests are completed. */ -int -aio_suspend(struct thread *td, struct aio_suspend_args *uap) +static int +kern_aio_suspend(struct thread *td, int njoblist, struct aiocb **ujoblist, + struct timespec *ts) { struct proc *p = td->td_proc; struct timeval atv; - struct timespec ts; - struct aiocb *const *cbptr, *cbp; struct kaioinfo *ki; struct aiocblist *cb, *cbfirst; - struct aiocb **ujoblist; - int njoblist; - int error; - int timo; - int i; - - if (uap->nent < 0 || uap->nent > AIO_LISTIO_MAX) - return (EINVAL); + int error, i, timo; timo = 0; - if (uap->timeout) { - /* Get timespec struct. */ - if ((error = copyin(uap->timeout, &ts, sizeof(ts))) != 0) - return (error); - - if (ts.tv_nsec < 0 || ts.tv_nsec >= 1000000000) + if (ts) { + if (ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000) return (EINVAL); - TIMESPEC_TO_TIMEVAL(&atv, &ts); + TIMESPEC_TO_TIMEVAL(&atv, ts); if (itimerfix(&atv)) return (EINVAL); timo = tvtohz(&atv); @@ -1724,22 +1836,8 @@ aio_suspend(struct thread *td, struct ai if (ki == NULL) return (EAGAIN); - njoblist = 0; - ujoblist = uma_zalloc(aiol_zone, M_WAITOK); - cbptr = uap->aiocbp; - - for (i = 0; i < uap->nent; i++) { - cbp = (struct aiocb *)(intptr_t)fuword(&cbptr[i]); - if (cbp == 0) - continue; - ujoblist[njoblist] = cbp; - njoblist++; - } - - if (njoblist == 0) { - uma_zfree(aiol_zone, ujoblist); + if (njoblist == 0) return (0); - } AIO_LOCK(ki); for (;;) { @@ -1769,6 +1867,31 @@ aio_suspend(struct thread *td, struct ai } RETURN: AIO_UNLOCK(ki); + return (error); +} + +int +aio_suspend(struct thread *td, struct aio_suspend_args *uap) +{ + struct timespec ts, *tsp; + struct aiocb **ujoblist; + int error; + + if (uap->nent < 0 || uap->nent > AIO_LISTIO_MAX) + return (EINVAL); + + if (uap->timeout) { + /* Get timespec struct. */ + if ((error = copyin(uap->timeout, &ts, sizeof(ts))) != 0) + return (error); + tsp = &ts; + } else + tsp = NULL; + + ujoblist = uma_zalloc(aiol_zone, M_WAITOK); + error = copyin(uap->aiocbp, ujoblist, uap->nent * sizeof(ujoblist[0])); + if (error == 0) + error = kern_aio_suspend(td, uap->nent, ujoblist, tsp); uma_zfree(aiol_zone, ujoblist); return (error); } @@ -1876,8 +1999,8 @@ done: * only. For a user mode async implementation, it would be best to do it in * a userland subroutine. */ -int -aio_error(struct thread *td, struct aio_error_args *uap) +static int +kern_aio_error(struct thread *td, struct aiocb *aiocbp, struct aiocb_ops *ops) { struct proc *p = td->td_proc; struct aiocblist *cb; @@ -1892,7 +2015,7 @@ aio_error(struct thread *td, struct aio_ AIO_LOCK(ki); TAILQ_FOREACH(cb, &ki->kaio_all, allist) { - if (cb->uuaiocb == uap->aiocbp) { + if (cb->uuaiocb == aiocbp) { if (cb->jobstate == JOBST_JOBFINISHED) td->td_retval[0] = cb->uaiocb._aiocb_private.error; @@ -1907,9 +2030,9 @@ aio_error(struct thread *td, struct aio_ /* * Hack for failure of aio_aqueue. */ - status = fuword(&uap->aiocbp->_aiocb_private.status); + status = ops->fetch_status(aiocbp); if (status == -1) { - td->td_retval[0] = fuword(&uap->aiocbp->_aiocb_private.error); + td->td_retval[0] = ops->fetch_error(aiocbp); return (0); } @@ -1917,19 +2040,27 @@ aio_error(struct thread *td, struct aio_ return (0); } +int +aio_error(struct thread *td, struct aio_error_args *uap) +{ + + return (kern_aio_error(td, uap->aiocbp, &aiocb_ops)); +} + /* syscall - asynchronous read from a file (REALTIME) */ int oaio_read(struct thread *td, struct oaio_read_args *uap) { - return aio_aqueue(td, (struct aiocb *)uap->aiocbp, NULL, LIO_READ, 1); + return (aio_aqueue(td, (struct aiocb *)uap->aiocbp, NULL, LIO_READ, + &aiocb_ops_osigevent)); } int aio_read(struct thread *td, struct aio_read_args *uap) { - return aio_aqueue(td, uap->aiocbp, NULL, LIO_READ, 0); + return (aio_aqueue(td, uap->aiocbp, NULL, LIO_READ, &aiocb_ops)); } /* syscall - asynchronous write to a file (REALTIME) */ @@ -1937,47 +2068,34 @@ int oaio_write(struct thread *td, struct oaio_write_args *uap) { - return aio_aqueue(td, (struct aiocb *)uap->aiocbp, NULL, LIO_WRITE, 1); + return (aio_aqueue(td, (struct aiocb *)uap->aiocbp, NULL, LIO_WRITE, + &aiocb_ops_osigevent)); } int aio_write(struct thread *td, struct aio_write_args *uap) { - return aio_aqueue(td, uap->aiocbp, NULL, LIO_WRITE, 0); -} - -/* syscall - list directed I/O (REALTIME) */ -int -olio_listio(struct thread *td, struct olio_listio_args *uap) -{ - return do_lio_listio(td, (struct lio_listio_args *)uap, 1); -} - -/* syscall - list directed I/O (REALTIME) */ -int -lio_listio(struct thread *td, struct lio_listio_args *uap) -{ - return do_lio_listio(td, uap, 0); + return (aio_aqueue(td, uap->aiocbp, NULL, LIO_WRITE, &aiocb_ops)); } static int -do_lio_listio(struct thread *td, struct lio_listio_args *uap, int oldsigev) +kern_lio_listio(struct thread *td, int mode, struct aiocb * const *uacb_list, + struct aiocb **acb_list, int nent, struct sigevent *sig, + struct aiocb_ops *ops) { struct proc *p = td->td_proc; - struct aiocb *iocb, * const *cbptr; + struct aiocb *iocb; struct kaioinfo *ki; struct aioliojob *lj; struct kevent kev; - int nent; int error; int nerror; int i; - if ((uap->mode != LIO_NOWAIT) && (uap->mode != LIO_WAIT)) + if ((mode != LIO_NOWAIT) && (mode != LIO_WAIT)) return (EINVAL); - nent = uap->nent; if (nent < 0 || nent > AIO_LISTIO_MAX) return (EINVAL); @@ -1996,21 +2114,13 @@ do_lio_listio(struct thread *td, struct /* * Setup signal. */ - if (uap->sig && (uap->mode == LIO_NOWAIT)) { - bzero(&lj->lioj_signal, sizeof(&lj->lioj_signal)); - error = copyin(uap->sig, &lj->lioj_signal, - oldsigev ? sizeof(struct osigevent) : - sizeof(struct sigevent)); - if (error) { - uma_zfree(aiolio_zone, lj); - return (error); - } - + if (sig && (mode == LIO_NOWAIT)) { + bcopy(sig, &lj->lioj_signal, sizeof(lj->lioj_signal)); if (lj->lioj_signal.sigev_notify == SIGEV_KEVENT) { /* Assume only new style KEVENT */ kev.filter = EVFILT_LIO; kev.flags = EV_ADD | EV_ENABLE | EV_FLAG1; - kev.ident = (uintptr_t)uap->acb_list; /* something unique */ + kev.ident = (uintptr_t)uacb_list; /* something unique */ kev.data = (intptr_t)lj; /* pass user defined sigval data */ kev.udata = lj->lioj_signal.sigev_value.sival_ptr; @@ -2050,11 +2160,10 @@ do_lio_listio(struct thread *td, struct * Get pointers to the list of I/O requests. */ nerror = 0; - cbptr = uap->acb_list; - for (i = 0; i < uap->nent; i++) { - iocb = (struct aiocb *)(intptr_t)fuword(&cbptr[i]); - if (((intptr_t)iocb != -1) && ((intptr_t)iocb != 0)) { - error = aio_aqueue(td, iocb, lj, LIO_NOP, oldsigev); + for (i = 0; i < nent; i++) { + iocb = acb_list[i]; + if (iocb != NULL) { + error = aio_aqueue(td, iocb, lj, LIO_NOP, ops); if (error != 0) nerror++; } @@ -2062,7 +2171,7 @@ do_lio_listio(struct thread *td, struct error = 0; AIO_LOCK(ki); - if (uap->mode == LIO_WAIT) { + if (mode == LIO_WAIT) { while (lj->lioj_count - 1 != lj->lioj_finished_count) { ki->kaio_flags |= KAIO_WAKEUP; error = msleep(&p->p_aioinfo, AIO_MTX(ki), @@ -2105,6 +2214,75 @@ do_lio_listio(struct thread *td, struct return (error); } +/* syscall - list directed I/O (REALTIME) */ +int +olio_listio(struct thread *td, struct olio_listio_args *uap) +{ + struct aiocb **acb_list; + struct sigevent *sigp, sig; + struct osigevent osig; + int error, nent; + + if ((uap->mode != LIO_NOWAIT) && (uap->mode != LIO_WAIT)) + return (EINVAL); + + nent = uap->nent; + if (nent < 0 || nent > AIO_LISTIO_MAX) + return (EINVAL); + + if (uap->sig && (uap->mode == LIO_NOWAIT)) { + error = copyin(uap->sig, &osig, sizeof(osig)); + if (error) + return (error); + error = convert_old_sigevent(&osig, &sig); + if (error) + return (error); + sigp = &sig; + } else + sigp = NULL; + + acb_list = malloc(sizeof(struct aiocb *) * nent, M_LIO, M_WAITOK); + error = copyin(uap->acb_list, acb_list, nent * sizeof(acb_list[0])); + if (error == 0) + error = kern_lio_listio(td, uap->mode, + (struct aiocb * const *)uap->acb_list, acb_list, nent, sigp, + &aiocb_ops_osigevent); + free(acb_list, M_LIO); + return (error); +} + +/* syscall - list directed I/O (REALTIME) */ +int +lio_listio(struct thread *td, struct lio_listio_args *uap) +{ + struct aiocb **acb_list; + struct sigevent *sigp, sig; + int error, nent; + + if ((uap->mode != LIO_NOWAIT) && (uap->mode != LIO_WAIT)) + return (EINVAL); + + nent = uap->nent; + if (nent < 0 || nent > AIO_LISTIO_MAX) + return (EINVAL); + + if (uap->sig && (uap->mode == LIO_NOWAIT)) { + error = copyin(uap->sig, &sig, sizeof(sig)); + if (error) + return (error); + sigp = &sig; + } else + sigp = NULL; + + acb_list = malloc(sizeof(struct aiocb *) * nent, M_LIO, M_WAITOK); + error = copyin(uap->acb_list, acb_list, nent * sizeof(acb_list[0])); + if (error == 0) + error = kern_lio_listio(td, uap->mode, uap->acb_list, acb_list, + nent, sigp, &aiocb_ops); + free(acb_list, M_LIO); + return (error); +} + /* * Called from interrupt thread for physio, we should return as fast * as possible, so we schedule a biohelper task. @@ -2156,30 +2334,25 @@ biohelper(void *context, int pending) } /* syscall - wait for the next completion of an aio request */ -int -aio_waitcomplete(struct thread *td, struct aio_waitcomplete_args *uap) +static int +kern_aio_waitcomplete(struct thread *td, struct aiocb **aiocbp, + struct timespec *ts, struct aiocb_ops *ops) { struct proc *p = td->td_proc; struct timeval atv; - struct timespec ts; struct kaioinfo *ki; struct aiocblist *cb; struct aiocb *uuaiocb; int error, status, timo; - suword(uap->aiocbp, (long)NULL); + ops->store_aiocb(aiocbp, NULL); timo = 0; - if (uap->timeout) { - /* Get timespec struct. */ - error = copyin(uap->timeout, &ts, sizeof(ts)); - if (error) - return (error); - - if ((ts.tv_nsec < 0) || (ts.tv_nsec >= 1000000000)) + if (ts) { + if ((ts->tv_nsec < 0) || (ts->tv_nsec >= 1000000000)) return (EINVAL); - TIMESPEC_TO_TIMEVAL(&atv, &ts); + TIMESPEC_TO_TIMEVAL(&atv, ts); if (itimerfix(&atv)) return (EINVAL); timo = tvtohz(&atv); @@ -2217,9 +2390,9 @@ aio_waitcomplete(struct thread *td, stru } aio_free_entry(cb); AIO_UNLOCK(ki); - suword(uap->aiocbp, (long)uuaiocb); - suword(&uuaiocb->_aiocb_private.error, error); - suword(&uuaiocb->_aiocb_private.status, status); + ops->store_aiocb(aiocbp, uuaiocb); + ops->store_error(uuaiocb, error); + ops->store_status(uuaiocb, status); } else AIO_UNLOCK(ki); @@ -2227,17 +2400,43 @@ aio_waitcomplete(struct thread *td, stru } int -aio_fsync(struct thread *td, struct aio_fsync_args *uap) +aio_waitcomplete(struct thread *td, struct aio_waitcomplete_args *uap) +{ + struct timespec ts, *tsp; + int error; + + if (uap->timeout) { + /* Get timespec struct. */ + error = copyin(uap->timeout, &ts, sizeof(ts)); + if (error) + return (error); + tsp = &ts; + } else + tsp = NULL; + + return (kern_aio_waitcomplete(td, uap->aiocbp, tsp, &aiocb_ops)); +} + +static int +kern_aio_fsync(struct thread *td, int op, struct aiocb *aiocbp, + struct aiocb_ops *ops) { struct proc *p = td->td_proc; struct kaioinfo *ki; - if (uap->op != O_SYNC) /* XXX lack of O_DSYNC */ + if (op != O_SYNC) /* XXX lack of O_DSYNC */ return (EINVAL); ki = p->p_aioinfo; if (ki == NULL) aio_init_aioinfo(p); - return aio_aqueue(td, uap->aiocbp, NULL, LIO_SYNC, 0); + return (aio_aqueue(td, aiocbp, NULL, LIO_SYNC, ops)); +} + +int +aio_fsync(struct thread *td, struct aio_fsync_args *uap) +{ + + return (kern_aio_fsync(td, uap->op, uap->aiocbp, &aiocb_ops)); } /* kqueue attach function */ @@ -2325,3 +2524,433 @@ filt_lio(struct knote *kn, long hint) return (lj->lioj_flags & LIOJ_KEVENT_POSTED); } + +#ifdef COMPAT_IA32 +#include +#include +#include +#include +#include +#include +#include + +struct __aiocb_private32 { + int32_t status; + int32_t error; + uint32_t kernelinfo; +}; + +typedef struct oaiocb32 { + int aio_fildes; /* File descriptor */ + uint64_t aio_offset __packed; /* File offset for I/O */ + uint32_t aio_buf; /* I/O buffer in process space */ + uint32_t aio_nbytes; /* Number of bytes for I/O */ + struct osigevent32 aio_sigevent; /* Signal to deliver */ + int aio_lio_opcode; /* LIO opcode */ + int aio_reqprio; /* Request priority -- ignored */ + struct __aiocb_private32 _aiocb_private; +} oaiocb32_t; + +typedef struct aiocb32 { + int32_t aio_fildes; /* File descriptor */ + uint64_t aio_offset __packed; /* File offset for I/O */ + uint32_t aio_buf; /* I/O buffer in process space */ + uint32_t aio_nbytes; /* Number of bytes for I/O */ + int __spare__[2]; + uint32_t __spare2__; + int aio_lio_opcode; /* LIO opcode */ + int aio_reqprio; /* Request priority -- ignored */ + struct __aiocb_private32 _aiocb_private; + struct sigevent32 aio_sigevent; /* Signal to deliver */ +} aiocb32_t; + +static int +convert_old_sigevent32(struct osigevent32 *osig, struct sigevent *nsig) +{ + + /* + * Only SIGEV_NONE, SIGEV_SIGNAL, and SIGEV_KEVENT are + * supported by AIO with the old sigevent structure. + */ + CP(*osig, *nsig, sigev_notify); + switch (nsig->sigev_notify) { + case SIGEV_NONE: + break; + case SIGEV_SIGNAL: + nsig->sigev_signo = osig->__sigev_u.__sigev_signo; + break; + case SIGEV_KEVENT: + nsig->sigev_notify_kqueue = + osig->__sigev_u.__sigev_notify_kqueue; + PTRIN_CP(*osig, *nsig, sigev_value.sival_ptr); + break; + default: + return (EINVAL); + } + return (0); +} + +static int +aiocb32_copyin_old_sigevent(struct aiocb *ujob, struct aiocb *kjob) +{ + struct oaiocb32 job32; + int error; + + bzero(kjob, sizeof(struct aiocb)); + error = copyin(ujob, &job32, sizeof(job32)); + if (error) + return (error); + + CP(job32, *kjob, aio_fildes); + CP(job32, *kjob, aio_offset); + PTRIN_CP(job32, *kjob, aio_buf); + CP(job32, *kjob, aio_nbytes); + CP(job32, *kjob, aio_lio_opcode); + CP(job32, *kjob, aio_reqprio); + CP(job32, *kjob, _aiocb_private.status); + CP(job32, *kjob, _aiocb_private.error); + PTRIN_CP(job32, *kjob, _aiocb_private.kernelinfo); + return (convert_old_sigevent32(&job32.aio_sigevent, + &kjob->aio_sigevent)); +} + +static int +convert_sigevent32(struct sigevent32 *sig32, struct sigevent *sig) +{ + + CP(*sig32, *sig, sigev_notify); + switch (sig->sigev_notify) { + case SIGEV_NONE: + break; + case SIGEV_THREAD_ID: + CP(*sig32, *sig, sigev_notify_thread_id); + /* FALLTHROUGH */ + case SIGEV_SIGNAL: + CP(*sig32, *sig, sigev_signo); + break; + case SIGEV_KEVENT: + CP(*sig32, *sig, sigev_notify_kqueue); + PTRIN_CP(*sig32, *sig, sigev_value.sival_ptr); + break; + default: + return (EINVAL); + } + return (0); +} + +static int +aiocb32_copyin(struct aiocb *ujob, struct aiocb *kjob) +{ + struct aiocb32 job32; + int error; + + error = copyin(ujob, &job32, sizeof(job32)); + if (error) + return (error); + CP(job32, *kjob, aio_fildes); + CP(job32, *kjob, aio_offset); + PTRIN_CP(job32, *kjob, aio_buf); + CP(job32, *kjob, aio_nbytes); + CP(job32, *kjob, aio_lio_opcode); + CP(job32, *kjob, aio_reqprio); + CP(job32, *kjob, _aiocb_private.status); + CP(job32, *kjob, _aiocb_private.error); + PTRIN_CP(job32, *kjob, _aiocb_private.kernelinfo); + return (convert_sigevent32(&job32.aio_sigevent, &kjob->aio_sigevent)); +} + +static long +aiocb32_fetch_status(struct aiocb *ujob) +{ + struct aiocb32 *ujob32; + + ujob32 = (struct aiocb32 *)ujob; + return (fuword32(&ujob32->_aiocb_private.status)); +} + +static long +aiocb32_fetch_error(struct aiocb *ujob) +{ + struct aiocb32 *ujob32; + + ujob32 = (struct aiocb32 *)ujob; + return (fuword32(&ujob32->_aiocb_private.error)); +} + +static int +aiocb32_store_status(struct aiocb *ujob, long status) +{ + struct aiocb32 *ujob32; + + ujob32 = (struct aiocb32 *)ujob; + return (suword32(&ujob32->_aiocb_private.status, status)); +} + +static int +aiocb32_store_error(struct aiocb *ujob, long error) +{ + struct aiocb32 *ujob32; + + ujob32 = (struct aiocb32 *)ujob; *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***