[Libsysio-commit] HEAD: libsysio/src file.c ioctx.c mount.c read.c write.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2003-10-13 01:04:43
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1:/tmp/cvs-serv31768/src Modified Files: file.c ioctx.c mount.c read.c write.c Log Message: The IO context record supported one call-back. It now supports a chain. This was changed to accommodate the Sandia-PVFS driver. Also, it's needed for the, coming, {read,write}_strided calls. To add a callback to the chain use: _sysio_ioctx_cb(struct ioctx *ioctx, void (*func)(struct ioctx *, void *), void *data) Callbacks are added to the end of the existing chain. When called, by _sysio_io_complete, they are run in order. So... If you're freeing things using callbacks be careful not to depend on something in a later callback that you previously free'd. Also, _sysio_io_complete no longer waits for the driver. To call this, now, is to signal completion. Index: file.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/file.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -w -b -B -p -r1.5 -r1.6 --- file.c 6 Aug 2003 19:12:46 -0000 1.5 +++ file.c 13 Oct 2003 01:04:35 -0000 1.6 @@ -97,14 +97,12 @@ _sysio_fgone(struct file *fil) * IO operation completion handler. */ void -_sysio_fcompletio(struct ioctx *ioctx) +_sysio_fcompletio(struct ioctx *ioctx, struct file *fil) { - struct file *fil; if (ioctx->ioctx_errno) return; - fil = (struct file *)ioctx->ioctx_data; assert(ioctx->ioctx_ino == fil->f_ino); fil->f_pos = ioctx->ioctx_offset + ioctx->ioctx_cc; } Index: ioctx.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/ioctx.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -b -B -p -r1.2 -r1.3 --- ioctx.c 7 Mar 2003 03:31:36 -0000 1.2 +++ ioctx.c 13 Oct 2003 01:04:35 -0000 1.3 @@ -78,40 +78,67 @@ _sysio_ioctx_init() * Allocate and initialisze a new IO context. */ struct ioctx * -_sysio_ioctx_new(struct inode *ino, struct io_arguments *ioargs) +_sysio_ioctx_new(struct inode *ino, + const struct iovec *iov, + size_t iovlen, + _SYSIO_OFF_T offset) { struct ioctx *ioctx; ioctx = - malloc(sizeof(struct ioctx) + - ioargs->ioarg_iovlen * sizeof(struct iovec)); + malloc(sizeof(struct ioctx) + iovlen * sizeof(struct iovec)); if (!ioctx) return NULL; I_REF(ino); + ioctx->ioctx_iovec = (void *)ioctx + sizeof(struct ioctx); + (void )memcpy((void *)ioctx->ioctx_iovec, + iov, + iovlen * sizeof(struct iovec)); + IOCTX_INIT(ioctx, + 0, + (ioid_t )ioctx, + ino, + ioctx->ioctx_iovec, + iovlen, + offset); + /* * Link request onto the outstanding requests queue. */ LIST_INSERT_HEAD(&aioq, ioctx, ioctx_link); - ioctx->ioctx_id = (ioid_t )ioctx; - ioctx->ioctx_ino = ino; - ioctx->ioctx_iovec = (void *)ioctx + sizeof(struct ioctx); - (void )memcpy((void *)ioctx->ioctx_iovec, - ioargs->ioarg_iovec, - ioargs->ioarg_iovlen * sizeof(struct iovec)); - ioctx->ioctx_iovlen = ioargs->ioarg_iovlen; - ioctx->ioctx_offset = ioargs->ioarg_offset; - ioctx->ioctx_cc = 0; - ioctx->ioctx_errno = 0; - ioctx->ioctx_cb = ioargs->ioarg_completion; - ioctx->ioctx_data = ioargs->ioarg_completion_arg; - return ioctx; } /* + * Add an IO completion call-back to the end of the context call-back queue. + * These are called in iowait() as the last thing, right before the context + * is destroyed. + * + * They are called in order. Beware. + */ +int +_sysio_ioctx_cb(struct ioctx *ioctx, + void (*f)(struct ioctx *, void *), + void *data) +{ + struct ioctx_callback *entry; + + entry = malloc(sizeof(struct ioctx_callback)); + if (!entry) + return -ENOMEM; + + entry->iocb_f = f; + entry->iocb_data = data; + + TAILQ_INSERT_TAIL(&ioctx->ioctx_cbq, entry, iocb_next); + + return 0; +} + +/* * Find an IO context given it's identifier. * * NB: This is dog-slow. If there are alot of these, we will need to change @@ -170,26 +197,36 @@ _sysio_ioctx_wait(struct ioctx *ioctx) void _sysio_ioctx_complete(struct ioctx *ioctx) { +#if 0 struct inode *ino; +#endif + struct ioctx_callback *entry; /* * Unlink from the file record's outstanding request queue. */ LIST_REMOVE(ioctx, ioctx_link); +#if 0 /* * Wait for IO to complete and remember completion values. */ ino = ioctx->ioctx_ino; while (ino && !(*ino->i_ops.inop_iodone)(ioctx)) ; +#endif + /* - * Notify interested parties. + * Run the call-back queue. */ - if (ioctx->ioctx_cb) - (*ioctx->ioctx_cb)(ioctx); + while ((entry = ioctx->ioctx_cbq.tqh_first)) { + TAILQ_REMOVE(&ioctx->ioctx_cbq, entry, iocb_next); + (*entry->iocb_f)(ioctx, entry->iocb_data); + free(entry); + } - I_RELE(ino); + I_RELE(ioctx->ioctx_ino); + if (!ioctx->ioctx_fast) free(ioctx); } Index: mount.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/mount.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -w -b -B -p -r1.7 -r1.8 --- mount.c 26 Aug 2003 15:53:59 -0000 1.7 +++ mount.c 13 Oct 2003 01:04:35 -0000 1.8 @@ -563,8 +563,7 @@ _sysio_automount(struct pnode *mntpno) struct inode *ino; struct intnl_stat stbuf; struct iovec iovec; - struct io_arguments ioarguments; - struct ioctx *ioctx; + struct ioctx iocontext; ssize_t cc; char *fstype, *source, *opts; unsigned flags; @@ -598,13 +597,14 @@ _sysio_automount(struct pnode *mntpno) err = _sysio_open(mntpno, O_RDONLY, 0); if (err) goto out; - IOARG_INIT(&ioarguments, &iovec, 1, 0, NULL, NULL); - err = (*ino->i_ops.inop_ipreadv)(ino, &ioarguments, &ioctx); + IOCTX_INIT(&iocontext, 1, (ioid_t )&iocontext, ino, &iovec, 1, 0); + err = (*ino->i_ops.inop_ipreadv)(ino, &iocontext); if (err) { + _sysio_ioctx_complete(&iocontext); (void )(*ino->i_ops.inop_close)(ino); goto out; } - cc = _sysio_ioctx_wait(ioctx); + cc = _sysio_ioctx_wait(&iocontext); err = (*ino->i_ops.inop_close)(ino); if (err) goto out; Index: read.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/read.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -b -B -p -r1.6 -r1.7 --- read.c 10 Oct 2003 18:50:31 -0000 1.6 +++ read.c 13 Oct 2003 01:04:35 -0000 1.7 @@ -62,11 +62,10 @@ static struct ioctx * do_ixreadv(struct file *fil, const struct iovec *iov, size_t count, _SYSIO_OFF_T offset, - void (*fcompletio)(struct ioctx *)) + void (*fcompletio)(struct ioctx *, struct file *)) { struct inode *ino; int err; - struct io_arguments ioarguments; struct ioctx *ioctx; if (fil->f_flags & O_WRONLY) { @@ -82,12 +81,21 @@ do_ixreadv(struct file *fil, errno = EBADF; return NULL; } - IOARG_INIT(&ioarguments, - iov, count, - offset, - (void (*)(void *))fcompletio, fil); - err = ino->i_ops.inop_ipreadv(fil->f_ino, &ioarguments, &ioctx); + ioctx = _sysio_ioctx_new(fil->f_ino, iov, count, offset); + if (!ioctx || + (fcompletio && + _sysio_ioctx_cb(ioctx, + (void (*)(struct ioctx *, void *))fcompletio, + fil) != 0)) { + err = -ENOMEM; + goto out; + } + err = ino->i_ops.inop_ipreadv(fil->f_ino, ioctx); +out: if (err) { + ioctx->ioctx_cc = -1; + ioctx->ioctx_errno = -err; + _sysio_ioctx_complete(ioctx); errno = -err; return NULL; } Index: write.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/write.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -b -B -p -r1.6 -r1.7 --- write.c 10 Oct 2003 18:50:31 -0000 1.6 +++ write.c 13 Oct 2003 01:04:35 -0000 1.7 @@ -64,11 +64,10 @@ static struct ioctx * do_ixwritev(struct file *fil, const struct iovec *iov, size_t count, _SYSIO_OFF_T offset, - void (*fcompletio)(struct ioctx *)) + void (*fcompletio)(struct ioctx *, struct file *)) { struct inode *ino; int err; - struct io_arguments ioarguments; struct ioctx *ioctx; if (fil->f_flags & O_RDONLY) { @@ -84,12 +83,21 @@ do_ixwritev(struct file *fil, errno = EBADF; return NULL; } - IOARG_INIT(&ioarguments, - iov, count, - offset, - (void (*)(void *))fcompletio, fil); - err = ino->i_ops.inop_ipwritev(fil->f_ino, &ioarguments, &ioctx); + ioctx = _sysio_ioctx_new(fil->f_ino, iov, count, offset); + if (!ioctx || + (fcompletio && + _sysio_ioctx_cb(ioctx, + (void (*)(struct ioctx *, void *))fcompletio, + fil) != 0)) { + err = -ENOMEM; + goto out; + } + err = ino->i_ops.inop_ipwritev(fil->f_ino, ioctx); +out: if (err) { + ioctx->ioctx_cc = -1; + ioctx->ioctx_errno = -err; + _sysio_ioctx_complete(ioctx); errno = -err; return NULL; } |