From 8692f4651696ff4324db3ad738d3fa62f68d7347 Mon Sep 17 00:00:00 2001 From: jacob Date: Sun, 19 Dec 2004 22:56:35 +0000 Subject: [PATCH] import libsysio for b_newsysio --- libsysio/Makefile.am | 8 +- libsysio/Rules.make | 1 + libsysio/dev/stdfd/stdfd.c | 2 +- libsysio/drivers/incore/fs_incore.c | 10 +- libsysio/drivers/native/fs_native.c | 167 ++++++++++++++------ libsysio/drivers/sockets/sockets.c | 59 +++++-- libsysio/drivers/yod/fs_yod.c | 47 ++++-- libsysio/include/dev.h | 5 +- libsysio/include/file.h | 4 +- libsysio/include/inode.h | 9 +- libsysio/include/sysio.h | 92 ++--------- libsysio/include/xtio.h | 298 +++++++++++++++++++++++++++++++----- libsysio/misc/init-env.sh | 3 + libsysio/src/access.c | 14 +- libsysio/src/dup.c | 4 +- libsysio/src/fcntl.c | 43 ++---- libsysio/src/file.c | 61 ++++---- libsysio/src/file_hack.c | 86 ++++++----- libsysio/src/init.c | 74 ++++++++- libsysio/src/inode.c | 13 +- libsysio/src/ioctx.c | 42 ++--- libsysio/src/iowait.c | 4 +- libsysio/src/lseek.c | 36 +++-- libsysio/src/module.mk | 2 +- libsysio/src/mount.c | 5 +- libsysio/src/namei.c | 2 +- libsysio/src/open.c | 4 +- libsysio/src/rename.c | 2 +- libsysio/src/rw.c | 26 ++-- libsysio/src/stdlib.c | 2 + libsysio/tests/helper.pm | 25 ++- libsysio/tests/startup.c | 30 +++- libsysio/tests/sysio_stubs.c | 5 +- libsysio/tests/sysio_tests.c | 4 +- libsysio/tests/test.h | 2 + libsysio/tests/test_all.pl | 3 + libsysio/tests/test_copy.c | 13 +- libsysio/tests/test_driver.c | 16 +- libsysio/tests/test_getcwd.c | 9 +- libsysio/tests/test_getcwd.pl | 2 +- libsysio/tests/test_link.c | 12 +- libsysio/tests/test_list.c | 15 +- libsysio/tests/test_path.c | 18 +-- libsysio/tests/test_path.pl | 2 +- libsysio/tests/test_regions.c | 11 +- libsysio/tests/test_rename.c | 13 +- libsysio/tests/test_stats.c | 11 +- libsysio/tests/test_unlink.c | 12 +- 48 files changed, 869 insertions(+), 459 deletions(-) diff --git a/libsysio/Makefile.am b/libsysio/Makefile.am index 11e6e3d..dfa4f9e 100644 --- a/libsysio/Makefile.am +++ b/libsysio/Makefile.am @@ -48,16 +48,14 @@ OPTIONAL_YOD_SRCS = endif if WITH_LUSTRE_HACK -OPTIONAL_LUSTRE_SRCDIR_SRCS = $(LUSTRE_SRCDIR_SRCS) # it would be better that let configure script check this -AM_CFLAGS = -fPIC -else -OPTIONAL_LUSTRE_SRCDIR_SRCS = +OPTIONAL_LUSTRE_CFLAGS = -fPIC endif +AM_CFLAGS = $(OPTIONAL_LUSTRE_CFLAGS) + __LIBBUILD_DIR__libsysio_a_SOURCES = \ $(SRCDIR_SRCS) \ - $(OPTIONAL_LUSTRE_SRCDIR_SRCS) \ $(OPTIONAL_STDFD_SRCS) \ $(OPTIONAL_INCORE_SRCS) \ $(OPTIONAL_SOCKETS_SRCS) \ diff --git a/libsysio/Rules.make b/libsysio/Rules.make index 45db68c..057611b 100644 --- a/libsysio/Rules.make +++ b/libsysio/Rules.make @@ -14,5 +14,6 @@ endif DEV_CPPFLAGS = $(STDFD_DEV_CPPFLAGS) AM_CPPFLAGS = \ + -D_POSIX_C_SOURCE=199506L -D_XOPEN_SOURCE=600 \ $(AUTOMOUNT) $(ZERO_SUM_MEMORY) $(DEV_CPPFLAGS) $(SOCKETS_CPPFLAGS) \ -I$(top_srcdir)/include diff --git a/libsysio/dev/stdfd/stdfd.c b/libsysio/dev/stdfd/stdfd.c index 5a14e8b..aa6bf85 100644 --- a/libsysio/dev/stdfd/stdfd.c +++ b/libsysio/dev/stdfd/stdfd.c @@ -48,10 +48,10 @@ #include #include #include -#include #include #include +#include "xtio.h" #include "sysio.h" #include "inode.h" #include "dev.h" diff --git a/libsysio/drivers/incore/fs_incore.c b/libsysio/drivers/incore/fs_incore.c index b6eb1c0..ca10b4f 100644 --- a/libsysio/drivers/incore/fs_incore.c +++ b/libsysio/drivers/incore/fs_incore.c @@ -61,6 +61,7 @@ #endif #include +#include "xtio.h" #include "sysio.h" #include "fs.h" #include "mount.h" @@ -147,7 +148,8 @@ static int _sysio_incore_filop_write(struct inode *ino, struct ioctx *ioctx); static _SYSIO_OFF_T _sysio_incore_filop_pos(struct inode *ino, _SYSIO_OFF_T off); static int _sysio_incore_filop_iodone(struct ioctx *ioctx); -static int _sysio_incore_filop_fcntl(struct inode *ino, int cmd, va_list ap); +static int _sysio_incore_filop_fcntl(struct inode *ino, + int cmd, va_list ap, int *rtn); static int _sysio_incore_inop_sync(struct inode *ino); static int _sysio_incore_filop_ioctl(struct inode *ino, unsigned long int request, @@ -176,7 +178,7 @@ static void _sysio_incore_inop_gone(struct inode *ino); #define _sysio_incore_dirop_iodone \ (int (*)(struct ioctx *))_sysio_do_illop #define _sysio_incore_dirop_fcntl \ - (int (*)(struct inode *, int, va_list))_sysio_do_eisdir + (int (*)(struct inode *, int, va_list, int *))_sysio_do_eisdir #define _sysio_incore_dirop_ioctl \ (int (*)(struct inode *, \ unsigned long int, \ @@ -1573,12 +1575,14 @@ _sysio_incore_filop_iodone(struct ioctx *iocp __IS_UNUSED) static int _sysio_incore_filop_fcntl(struct inode *ino __IS_UNUSED, int cmd __IS_UNUSED, - va_list ap __IS_UNUSED) + va_list ap __IS_UNUSED, + int *rtn) { /* * No fcntl's supported. */ + *rtn = -1; return -ENOTTY; } diff --git a/libsysio/drivers/native/fs_native.c b/libsysio/drivers/native/fs_native.c index c66c1ed..446d61e 100644 --- a/libsysio/drivers/native/fs_native.c +++ b/libsysio/drivers/native/fs_native.c @@ -51,6 +51,9 @@ #include #endif #include +#if !(defined(REDSTORM) || defined(MAX_IOVEC)) +#include +#endif #include #include #include @@ -65,16 +68,14 @@ #include #endif #include +#include #include -#if !(defined(REDSTORM) || defined(MAX_IOVEC)) -#include -#endif +#include "xtio.h" #include "sysio.h" #include "fs.h" #include "mount.h" #include "inode.h" -#include "xtio.h" #include "fs_native.h" @@ -209,6 +210,7 @@ struct native_inode { int ni_oflags; /* flags, from open */ unsigned ni_nopens; /* soft ref count */ _SYSIO_OFF_T ni_fpos; /* current pos */ + struct intnl_stat ni_stat; /* cached attrs */ }; /* @@ -247,7 +249,7 @@ static int native_inop_read(struct inode *ino, struct ioctx *ioctx); static int native_inop_write(struct inode *ino, struct ioctx *ioctx); static _SYSIO_OFF_T native_inop_pos(struct inode *ino, _SYSIO_OFF_T off); static int native_inop_iodone(struct ioctx *ioctx); -static int native_inop_fcntl(struct inode *ino, int cmd, va_list ap); +static int native_inop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn); static int native_inop_sync(struct inode *ino); static int native_inop_datasync(struct inode *ino); static int native_inop_ioctl(struct inode *ino, @@ -327,16 +329,25 @@ static struct mount *native_internal_mount = NULL; * stat -- by path. */ static int -native_stat(const char *path, struct intnl_stat *buf) +native_stat(const char *path, struct native_inode *nino, struct intnl_stat *buf) { int err; struct __native_stat stbuf; err = syscall(__SYS_STAT, path, &stbuf); - if (err) + if (err) { err = -errno; - COPY_STAT(&stbuf, buf); + goto out; + } + if (!nino) { + COPY_STAT(&stbuf, buf); + goto out; + } + COPY_STAT(&stbuf, &nino->ni_stat); + if (&nino->ni_stat != buf) + (void )memcpy(buf, &nino->ni_stat, sizeof(struct intnl_stat)); +out: return err; } @@ -344,16 +355,25 @@ native_stat(const char *path, struct intnl_stat *buf) * stat -- by fildes */ static int -native_fstat(int fd, struct intnl_stat *buf) +native_fstat(int fd, struct native_inode *nino, struct intnl_stat *buf) { int err; struct __native_stat stbuf; err = syscall(__SYS_FSTAT, fd, &stbuf); - if (err) + if (err) { err = -errno; - COPY_STAT(&stbuf, buf); + goto out; + } + if (!nino) { + COPY_STAT(&stbuf, buf); + goto out; + } + COPY_STAT(&stbuf, &nino->ni_stat); + if (&nino->ni_stat != buf) + (void )memcpy(buf, &nino->ni_stat, sizeof(struct intnl_stat)); +out: return err; } @@ -381,6 +401,7 @@ native_i_new(struct filesys *fs, struct intnl_stat *buf) nino->ni_oflags = 0; nino->ni_nopens = 0; nino->ni_fpos = 0; + (void )memcpy(&nino->ni_stat, buf, sizeof(struct intnl_stat)); ino = _sysio_i_new(fs, &nino->ni_fileid, @@ -389,7 +410,7 @@ native_i_new(struct filesys *fs, struct intnl_stat *buf) #else buf->st_mode, /* all of the bits! */ #endif - 0, + buf->st_rdev, 0, &native_i_ops, nino); @@ -453,7 +474,7 @@ create_internal_namespace() /* * Get root i-node. */ - err = native_stat("/", &stbuf); + err = native_stat("/", NULL, &stbuf); if (err) goto error; rootino = native_i_new(fs, &stbuf); @@ -596,7 +617,7 @@ native_iget(struct filesys *fs, /* * Get file status. */ - err = native_stat(path, &stbuf); + err = native_stat(path, *inop ? I2NI(*inop) : NULL, &stbuf); if (err) { *inop = NULL; return err; @@ -626,9 +647,10 @@ native_iget(struct filesys *fs, fileid.fid_data = &ident; fileid.fid_len = sizeof(ident); ino = _sysio_i_find(fs, &fileid); - if (ino && forced) { + if (ino && + (forced || (ino->i_mode & S_IFMT) != (stbuf.st_mode & S_IFMT))) { /* - * Insertion was forced but it's already present! + * Insertion was forced or dup inum but it's already present! */ if (native_i_invalid(ino, stbuf)) { /* @@ -709,23 +731,36 @@ native_inop_lookup(struct pnode *pno, } static int -native_inop_getattr(struct pnode *pno, struct inode *ino, struct intnl_stat *stbuf) +native_inop_getattr(struct pnode *pno, + struct inode *ino, + struct intnl_stat *stbuf) { char *path; + struct native_inode *nino; int err; - path = NULL; - if (!ino || I2NI(ino)->ni_fd < 0) { + nino = ino ? I2NI(ino) : NULL; + err = 0; /* compiler cookie */ + if (!ino) { path = _sysio_pb_path(pno->p_base, '/'); if (!path) return -ENOMEM; - } - err = - path - ? native_stat(path, stbuf) - : native_fstat(I2NI(ino)->ni_fd, stbuf); - if (path) + err = native_stat(path, nino, stbuf); free(path); + } else if (nino->ni_fd >= 0) + err = native_fstat(nino->ni_fd, nino, stbuf); + else { + /* + * Dev inodes don't open in this driver. We won't have + * a file descriptor with which to do the deed then. Satisfy + * the request from the cached copy of the attributes. + */ + (void )memcpy(stbuf, + &nino->ni_stat, + sizeof(struct intnl_stat)); + err = 0; + } + return err; } @@ -736,12 +771,19 @@ native_inop_setattr(struct pnode *pno, struct intnl_stat *stbuf) { char *path; + struct native_inode *nino; int fd; - struct intnl_stat st; + struct intnl_stat *stbp, _stbuf; int err; path = NULL; - fd = ino ? I2NI(ino)->ni_fd : -1; + nino = ino ? I2NI(ino) : NULL; + fd = -1; + stbp = &_stbuf; + if (nino) { + fd = nino->ni_fd; + stbp = &nino->ni_stat; + } if (fd < 0 || mask & (SETATTR_MTIME|SETATTR_ATIME)) { if (!pno) return -EEXIST; @@ -755,8 +797,8 @@ native_inop_setattr(struct pnode *pno, */ err = fd < 0 - ? native_stat(path, &st) - : native_fstat(fd, &st); + ? native_stat(path, nino, stbp) + : native_fstat(fd, nino, stbp); if (err) goto out; @@ -782,8 +824,8 @@ native_inop_setattr(struct pnode *pno, /* * Alter access and/or modify time attributes. */ - ut.actime = st.st_atime; - ut.modtime = st.st_mtime; + ut.actime = stbuf->st_atime; + ut.modtime = stbuf->st_mtime; if (mask & SETATTR_MTIME) ut.modtime = stbuf->st_mtime; if (mask & SETATTR_ATIME) @@ -841,33 +883,40 @@ native_inop_setattr(struct pnode *pno, ? syscall(SYS_chown, path, mask & SETATTR_UID - ? st.st_uid + ? stbp->st_uid : (uid_t )-1, mask & SETATTR_GID - ? st.st_gid + ? stbp->st_gid : (gid_t )-1) : syscall(SYS_fchown, fd, mask & SETATTR_UID - ? st.st_uid + ? stbp->st_uid : (uid_t )-1, mask & SETATTR_GID - ? st.st_gid + ? stbp->st_gid : (gid_t )-1)); } if (mask & (SETATTR_MTIME|SETATTR_ATIME)) { struct utimbuf ut; - ut.actime = st.st_atime; - ut.modtime = st.st_mtime; + ut.actime = stbp->st_atime; + ut.modtime = stbp->st_mtime; (void )syscall(__SYS_UTIME, path, &ut); } if (mask & SETATTR_MODE) { fd < 0 - ? syscall(SYS_chmod, path, st.st_mode & 07777) - : syscall(SYS_fchmod, fd, st.st_mode & 07777); + ? syscall(SYS_chmod, path, stbp->st_mode & 07777) + : syscall(SYS_fchmod, stbp->st_mode & 07777); } out: + /* + * We must refresh the cached attributes on success. + */ + if (!err && (fd < 0 + ? native_stat(path, nino, stbp) + : native_fstat(fd, nino, stbp)) != 0) + abort(); if (path) free(path); return err; @@ -1565,7 +1614,8 @@ native_inop_iodone(struct ioctx *ioctxp __IS_UNUSED) static int native_inop_fcntl(struct inode *ino, int cmd, - va_list ap) + va_list ap, + int *rtn) { struct native_inode *nino = I2NI(ino); long arg; @@ -1574,25 +1624,33 @@ native_inop_fcntl(struct inode *ino, if (nino->ni_fd < 0) abort(); + err = 0; switch (cmd) { case F_GETFD: case F_GETFL: +#ifdef F_GETOWN case F_GETOWN: - err = syscall(SYS_fcntl, nino->ni_fd, cmd); - if (err < 0) +#endif + *rtn = syscall(SYS_fcntl, nino->ni_fd, cmd); + if (*rtn == -1) err = -errno; + break; case F_DUPFD: case F_SETFD: case F_SETFL: case F_GETLK: case F_SETLK: case F_SETLKW: +#ifdef F_SETOWN case F_SETOWN: +#endif arg = va_arg(ap, long); - err = syscall(SYS_fcntl, nino->ni_fd, cmd, arg); - if (err) + *rtn = syscall(SYS_fcntl, nino->ni_fd, cmd, arg); + if (*rtn == -1) err = -errno; + break; default: + *rtn = -1; err = -EINVAL; } return err; @@ -1688,6 +1746,25 @@ native_inop_datasync(struct inode *ino) return err; } +#ifdef HAVE_LUSTRE_HACK +static int +native_inop_ioctl(struct inode *ino, + unsigned long int request, + va_list ap) +{ + long arg1, arg2, arg3, arg4; + + assert(I2NI(ino)->ni_fd >= 0); + + arg1 = va_arg(ap, long); + arg2 = va_arg(ap, long); + arg3 = va_arg(ap, long); + arg4 = va_arg(ap, long); + + return syscall(SYS_ioctl, I2NI(ino)->ni_fd, request, + arg1, arg2, arg3, arg4); +} +#else static int native_inop_ioctl(struct inode *ino __IS_UNUSED, unsigned long int request __IS_UNUSED, @@ -1700,6 +1777,7 @@ native_inop_ioctl(struct inode *ino __IS_UNUSED, errno = ENOTTY; return -1; } +#endif static void native_inop_gone(struct inode *ino) @@ -1708,6 +1786,7 @@ native_inop_gone(struct inode *ino) if (nino->ni_fd >= 0) (void )syscall(SYS_close, nino->ni_fd); + free(ino->i_private); } diff --git a/libsysio/drivers/sockets/sockets.c b/libsysio/drivers/sockets/sockets.c index b8da195..b037e60 100644 --- a/libsysio/drivers/sockets/sockets.c +++ b/libsysio/drivers/sockets/sockets.c @@ -57,11 +57,13 @@ #include #include #include -#include #include #include #include +#include +#include +#include "xtio.h" #include "sysio.h" #include "fs.h" #include "inode.h" @@ -98,7 +100,7 @@ static _SYSIO_OFF_T sockets_inop_pos(struct inode *ino, static int sockets_inop_iodone(struct ioctx *ioctx); static int sockets_inop_sync(struct inode *ino); static int sockets_inop_datasync(struct inode *ino); -static int sockets_inop_fcntl(struct inode *ino, int cmd, va_list ap); +static int sockets_inop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn); static int sockets_inop_ioctl(struct inode *ino, unsigned long int request, va_list ap); @@ -234,7 +236,7 @@ sockets_inop_write(struct inode *ino, } static _SYSIO_OFF_T -sockets_inop_pos(struct inode *ino, _SYSIO_OFF_T off) +sockets_inop_pos(struct inode *ino __IS_UNUSED, _SYSIO_OFF_T off __IS_UNUSED) { return -EINVAL; } @@ -252,7 +254,8 @@ sockets_inop_iodone(struct ioctx *ioctxp __IS_UNUSED) static int sockets_inop_fcntl(struct inode *ino __IS_UNUSED, int cmd __IS_UNUSED, - va_list ap __IS_UNUSED) + va_list ap __IS_UNUSED, + int *rtn) { long arg; @@ -262,7 +265,8 @@ sockets_inop_fcntl(struct inode *ino __IS_UNUSED, case F_GETFD: case F_GETFL: case F_GETOWN: - return syscall(SYS_fcntl, I2SKI(ino)->ski_fd, cmd); + *rtn = syscall(SYS_fcntl, I2SKI(ino)->ski_fd, cmd); + break; case F_DUPFD: case F_SETFD: case F_SETFL: @@ -271,12 +275,13 @@ sockets_inop_fcntl(struct inode *ino __IS_UNUSED, case F_SETLKW: case F_SETOWN: arg = va_arg(ap, long); - return syscall(SYS_fcntl, I2SKI(ino)->ski_fd, cmd, arg); + *rtn = syscall(SYS_fcntl, I2SKI(ino)->ski_fd, cmd, arg); + break; default: - printf("uncatched cmd %d\n", cmd); - abort(); + *rtn = -1; + errno = EINVAL; } - return -1; + return *rtn == -1 ? -errno : 0; } static int @@ -297,6 +302,29 @@ sockets_inop_datasync(struct inode *ino) return syscall(SYS_fdatasync, I2SKI(ino)->ski_fd); } +#ifdef HAVE_LUSTRE_HACK +/* + * we blindly extract 4 params and pass to host kernel, the stack + * should be ok. hope no ioctl will consume more then 4 params... + */ +static int +sockets_inop_ioctl(struct inode *ino, + unsigned long int request, + va_list ap) +{ + long arg1, arg2, arg3, arg4; + + assert(I2SKI(ino)->ski_fd >= 0); + + arg1 = va_arg(ap, long); + arg2 = va_arg(ap, long); + arg3 = va_arg(ap, long); + arg4 = va_arg(ap, long); + + return syscall(SYS_ioctl, I2SKI(ino)->ski_fd, request, + arg1, arg2, arg3, arg4); +} +#else static int sockets_inop_ioctl(struct inode *ino __IS_UNUSED, unsigned long int request __IS_UNUSED, @@ -307,6 +335,7 @@ sockets_inop_ioctl(struct inode *ino __IS_UNUSED, */ return -ENOTTY; } +#endif static void sockets_inop_gone(struct inode *ino) @@ -389,7 +418,11 @@ socket(int domain, int type, int protocol) goto error; } - err = _sysio_fd_set(fil, ski->ski_fd); +#ifdef HAVE_LUSTRE_HACK + err = _sysio_fd_set(fil, ski->ski_fd, 1); +#else + err = _sysio_fd_set(fil, -1, 0); +#endif if (err < 0) goto error; @@ -453,7 +486,11 @@ accept(int s, struct sockaddr *addr, socklen_t *addrlen) goto error; } - err = _sysio_fd_set(nfil, ski->ski_fd); +#ifdef HAVE_LUSTRE_HACK + err = _sysio_fd_set(nfil, ski->ski_fd, 1); +#else + err = _sysio_fd_set(nfil, -1, 0); +#endif if (err < 0) goto error; diff --git a/libsysio/drivers/yod/fs_yod.c b/libsysio/drivers/yod/fs_yod.c index d651b88..62eb9f2 100644 --- a/libsysio/drivers/yod/fs_yod.c +++ b/libsysio/drivers/yod/fs_yod.c @@ -65,8 +65,8 @@ #endif #include #include -#include +#include "xtio.h" #include "sysio.h" #include "fs.h" #include "mount.h" @@ -177,7 +177,7 @@ static _SYSIO_OFF_T yod_inop_pos (struct inode *ino, _SYSIO_OFF_T off); static int yod_inop_read(struct inode *ino, struct ioctx *ioctx); static int yod_inop_write(struct inode *ino, struct ioctx *ioctx); static int yod_inop_iodone(struct ioctx *ioctx); -static int yod_inop_fcntl(struct inode *ino, int cmd, va_list ap); +static int yod_inop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn); static int yod_inop_sync(struct inode *ino); static int yod_inop_datasync(struct inode *ino); static int yod_inop_ioctl(struct inode *ino, @@ -1101,18 +1101,45 @@ yod_inop_iodone(struct ioctx *ioctxp __IS_UNUSED) } static int -yod_inop_fcntl(struct inode *ino __IS_UNUSED, int cmd, va_list ap __IS_UNUSED) +yod_inop_fcntl(struct inode *ino, int cmd, va_list ap, int *rtn) { - switch (cmd) - { - case F_DUPFD: /* do something to the ino */ + struct yod_inode *nino = I2NI(ino); + long arg; + int err; + + if (nino->ni_fd < 0) + abort(); + + err = 0; + switch (cmd) { + case F_GETFD: + case F_GETFL: +#ifdef F_GETOWN + case F_GETOWN: +#endif + *rtn = syscall(SYS_fcntl, nino->ni_fd, cmd); + if (*rtn == -1) + err = -errno; + break; + case F_DUPFD: + case F_SETFD: + case F_SETFL: + case F_GETLK: + case F_SETLK: + case F_SETLKW: +#ifdef F_SETOWN + case F_SETOWN: +#endif + arg = va_arg(ap, long); + *rtn = syscall(SYS_fcntl, nino->ni_fd, cmd, arg); + if (*rtn == -1) + err = -errno; break; default: - errno = EINVAL; - return -1; + *rtn = -1; + err = -EINVAL; } - return 0; - + return err; } static int diff --git a/libsysio/include/dev.h b/libsysio/include/dev.h index 0fe459b..a62f581 100644 --- a/libsysio/include/dev.h +++ b/libsysio/include/dev.h @@ -100,7 +100,7 @@ extern const struct inode_ops _sysio_nodev_ops; #define _sysio_nodev_inop_open \ (int (*)(struct pnode *, \ int, \ - mode_t))_sysio_do_enoent + mode_t))_sysio_do_enodev #define _sysio_nodev_inop_close \ (int (*)(struct inode *))_sysio_do_ebadf #define _sysio_nodev_inop_link \ @@ -122,7 +122,8 @@ extern const struct inode_ops _sysio_nodev_ops; #define _sysio_nodev_inop_fcntl \ (int (*)(struct inode *, \ int, \ - va_list))_sysio_do_ebadf + va_list, \ + int *))_sysio_do_ebadf #define _sysio_nodev_inop_sync \ (int (*)(struct inode *))_sysio_do_ebadf #define _sysio_nodev_inop_datasync \ diff --git a/libsysio/include/file.h b/libsysio/include/file.h index ed15f6b..82317d5 100644 --- a/libsysio/include/file.h +++ b/libsysio/include/file.h @@ -102,8 +102,8 @@ extern void _sysio_fgone(struct file *fil); extern void _sysio_fcompletio(struct ioctx *ioctx, struct file *fil); extern int _sysio_fd_close(int fd); extern struct file *_sysio_fd_find(int fd); -extern int _sysio_fd_set(struct file *fil, int fd); -extern int _sysio_fd_dup2(int oldfd, int newfd); +extern int _sysio_fd_set(struct file *fil, int fd, int force); +extern int _sysio_fd_dup(int oldfd, int newfd, int force); extern int _sysio_fd_close_all(void); #if ZERO_SUM_MEMORY extern void _sysio_fd_shutdown(void); diff --git a/libsysio/include/inode.h b/libsysio/include/inode.h index d6ee2ff..9431734 100644 --- a/libsysio/include/inode.h +++ b/libsysio/include/inode.h @@ -103,7 +103,7 @@ struct inode_ops { int (*inop_write)(struct inode *ino, struct ioctx *ioctx); _SYSIO_OFF_T (*inop_pos)(struct inode *ino, _SYSIO_OFF_T off); int (*inop_iodone)(struct ioctx *iocp); - int (*inop_fcntl)(struct inode *ino, int cmd, va_list ap); + int (*inop_fcntl)(struct inode *ino, int cmd, va_list ap, int *rtn); int (*inop_sync)(struct inode *ino); int (*inop_datasync)(struct inode *ino); int (*inop_ioctl)(struct inode *ino, unsigned long int request, va_list ap); @@ -370,7 +370,6 @@ struct ioctx { ioctx_fast : 1, /* from stack space */ ioctx_done : 1, /* transfer complete */ ioctx_write : 1; /* op is a write */ - ioid_t ioctx_id; /* unique ident */ struct inode *ioctx_ino; /* i-node */ const struct iovec *ioctx_iov; /* scatter/gather vec */ size_t ioctx_iovlen; /* iovec length */ @@ -385,12 +384,11 @@ struct ioctx { /* * Init IO context record. */ -#define IOCTX_INIT(ioctx, fast, id, wr, ino, iov, iovlen, xtv, xtvlen) \ +#define IOCTX_INIT(ioctx, fast, wr, ino, iov, iovlen, xtv, xtvlen) \ do { \ (ioctx)->ioctx_fast = (fast); \ (ioctx)->ioctx_done = 0; \ (ioctx)->ioctx_write = (wr) ? 1 : 0; \ - (ioctx)->ioctx_id = (id); \ (ioctx)->ioctx_ino = (ino); \ (ioctx)->ioctx_iov = (iov); \ (ioctx)->ioctx_iovlen = (iovlen); \ @@ -460,6 +458,7 @@ extern void _sysio_do_illop(void); extern int _sysio_do_ebadf(void); extern int _sysio_do_einval(void); extern int _sysio_do_enoent(void); +extern int _sysio_do_enodev(void); extern int _sysio_do_espipe(void); extern int _sysio_do_eisdir(void); extern int _sysio_do_enosys(void); @@ -485,7 +484,7 @@ extern int _sysio_ioctx_cb(struct ioctx *ioctx, void (*f)(struct ioctx *, void *), void *data); extern void _sysio_ioctx_cb_free(struct ioctx_callback *cb); -extern struct ioctx *_sysio_ioctx_find(ioid_t id); +extern struct ioctx *_sysio_ioctx_find(void *id); extern ssize_t _sysio_ioctx_wait(struct ioctx *ioctx); extern void _sysio_ioctx_complete(struct ioctx *ioctx); extern ssize_t _sysio_validx(const struct intnl_xtvec *xtv, size_t xtvlen, diff --git a/libsysio/include/sysio.h b/libsysio/include/sysio.h index fb05d75..bd31365 100644 --- a/libsysio/include/sysio.h +++ b/libsysio/include/sysio.h @@ -48,18 +48,6 @@ #include #include -#ifndef _IOID_T_DEFINED -#define _IOID_T_DEFINED -/* - * FIXME: - * - * This section about ioid_t and it's failure belong in - */ -typedef void *ioid_t; - -#define IOID_FAIL 0 -#endif - #if !defined(__IS_UNUSED) && defined(__GNUC__) #define __IS_UNUSED __attribute__ ((unused)) #else @@ -259,71 +247,6 @@ extern int SYSIO_INTERFACE_NAME(rename)(const char *oldpath, extern int SYSIO_INTERFACE_NAME(fdatasync)(int fd); extern int SYSIO_INTERFACE_NAME(ioctl)(int fd, unsigned long request, ...); extern mode_t SYSIO_INTERFACE_NAME(umask)(mode_t mask); -extern int SYSIO_INTERFACE_NAME(iodone)(ioid_t ioid); -extern ssize_t SYSIO_INTERFACE_NAME(iowait)(ioid_t ioid); -extern ioid_t SYSIO_INTERFACE_NAME(ipreadv)(int fd, const struct iovec *iov, - size_t count, off_t offset); -#if _LARGEFILE64_SOURCE -extern ioid_t SYSIO_INTERFACE_NAME(ipread64v)(int fd, const struct iovec *iov, - size_t count, off64_t offset); -#endif -extern ioid_t SYSIO_INTERFACE_NAME(ipread)(int fd, void *buf, size_t count, - off_t offset); -#if _LARGEFILE64_SOURCE -extern ioid_t SYSIO_INTERFACE_NAME(ipread64)(int fd, void *buf, size_t count, - off64_t offset); -#endif -extern ssize_t SYSIO_INTERFACE_NAME(preadv)(int fd, const struct iovec *iov, - size_t count, off_t offset); -#if _LARGEFILE64_SOURCE -extern ssize_t SYSIO_INTERFACE_NAME(pread64v)(int fd, const struct iovec *iov, - size_t count, off64_t offset); -#endif -extern ssize_t SYSIO_INTERFACE_NAME(pread)(int fd, void *buf, size_t count, - off_t offset); -#if _LARGEFILE64_SOURCE -extern ssize_t SYSIO_INTERFACE_NAME(pread64)(int fd, void *buf, size_t count, - off64_t offset); -#endif -extern ioid_t SYSIO_INTERFACE_NAME(ireadv)(int fd, const struct iovec *iov, - int count); -extern ioid_t SYSIO_INTERFACE_NAME(iread)(int fd, void *buf, size_t count); -extern ssize_t SYSIO_INTERFACE_NAME(readv)(int fd, const struct iovec *iov, - int count); -extern ssize_t SYSIO_INTERFACE_NAME(read)(int fd, void *buf, size_t count); -extern ioid_t SYSIO_INTERFACE_NAME(ipwritev)(int fd, const struct iovec *iov, - size_t count, off_t offset); -#if _LARGEFILE64_SOURCE -extern ioid_t SYSIO_INTERFACE_NAME(ipwrite64v)(int fd, const struct iovec *iov, - size_t count, off64_t offset); -#endif -extern ioid_t SYSIO_INTERFACE_NAME(ipwrite)(int fd, const void *buf, - size_t count, off_t offset); -#if _LARGEFILE64_SOURCE -extern ioid_t SYSIO_INTERFACE_NAME(ipwrite64)(int fd, const void *buf, - size_t count, off64_t offset); -#endif -extern ssize_t SYSIO_INTERFACE_NAME(pwritev)(int fd, const struct iovec *iov, - size_t count, off_t offset); -#if _LARGEFILE64_SOURCE -extern ssize_t SYSIO_INTERFACE_NAME(pwrite64v)(int fd, const struct iovec *iov, - size_t count, off64_t offset); -#endif -extern ssize_t SYSIO_INTERFACE_NAME(pwrite)(int fd, const void *buf, - size_t count, off_t offset); -#if _LARGEFILE64_SOURCE -extern ssize_t SYSIO_INTERFACE_NAME(pwrite64)(int fd, const void *buf, - size_t count, off64_t offset); -#endif -extern ioid_t SYSIO_INTERFACE_NAME(iwritev)(int fd, - const struct iovec *iov, - int count); -extern ioid_t SYSIO_INTERFACE_NAME(iwrite)(int fd, const void *buf, - size_t count); -extern ssize_t SYSIO_INTERFACE_NAME(writev)(int fd, const struct iovec *iov, - int count); -extern ssize_t SYSIO_INTERFACE_NAME(write)(int fd, const void *buf, - size_t count); extern int SYSIO_INTERFACE_NAME(mknod)(const char *path, mode_t mode, dev_t dev); extern int SYSIO_INTERFACE_NAME(utime)(const char *path, @@ -398,3 +321,18 @@ extern void _sysio_sysleave(); #define SYSIO_LEAVE #endif + +/* accounting for IO stats read and write char count */ +#if defined(REDSTORM) +#define _SYSIO_UPDACCT(w, cc) \ + do { \ + if ((cc) < 0) \ + break; \ + if (!w) \ + _add_iostats(0, (size_t )(cc)); \ + else \ + _add_iostats((size_t )(cc), 0); \ + } while(0) +#else +#define _SYSIO_UPDACCT(w, cc) +#endif diff --git a/libsysio/include/xtio.h b/libsysio/include/xtio.h index 765aaf8..87cf981 100644 --- a/libsysio/include/xtio.h +++ b/libsysio/include/xtio.h @@ -42,6 +42,21 @@ */ /* + * Extended application programmers interface for IO as found on Cray RedStorm + * and the other current SUNMos/Puma/Cougar/Catamount systems. + */ + +#ifndef _XTIO_H_ +#define _XTIO_H_ + +#ifndef _IOID_T_DEFINED +#define _IOID_T_DEFINED +typedef void *ioid_t; + +#define IOID_FAIL 0 +#endif + +/* * Structure for strided I/O. */ struct xtvec { @@ -60,51 +75,254 @@ struct xtvec64 { }; #endif -extern ioid_t SYSIO_INTERFACE_NAME(ireadx)(int fd, - const struct iovec *iov, - size_t iov_count, - const struct xtvec *xtv, - size_t xtv_count); +struct iovec; + +/* + * Get status of previously posted async file IO operation. + */ +extern int iodone(ioid_t ioid); + +/* + * Wait for completion of a previously posted asynch file IO request. + */ +extern ssize_t iowait(ioid_t ioid); + +/* + * Post asynch read into buffers mapped by an iovec from file at given offset. + */ +extern ioid_t ipreadv(int fd, + const struct iovec *iov, + size_t count, + off_t offset); + +#if _LARGEFILE64_SOURCE +/* + * Post asynch read into buffers mapped by an iovec from file at given offset. + */ +extern ioid_t ipread64v(int fd, + const struct iovec *iov, + size_t count, + off64_t offset); +#endif + +/* + * Post asynch read into buffer from file at given offset. + */ +extern ioid_t ipread(int fd, + void *buf, + size_t count, + off_t offset); + +#if _LARGEFILE64_SOURCE +/* + * Post asynch read into buffer from file at given offset. + */ +extern ioid_t ipread64(int fd, + void *buf, + size_t count, + off64_t offset); +#endif + +/* + * Read into buffers mapped by an iovec from file at given offset. + */ +extern ssize_t preadv(int fd, + const struct iovec *iov, + size_t count, + off_t offset); + +#if _LARGEFILE64_SOURCE +/* + * Read into buffers mapped by an iovec from file at given offset. + */ +extern ssize_t pread64v(int fd, + const struct iovec *iov, + size_t count, + off64_t offset); +#endif + +/* + * Post asynch read into buffers mapped by an iovec. + */ +extern ioid_t ireadv(int fd, + const struct iovec *iov, + int count); + +/* + * Read into buffer. + */ +extern ioid_t iread(int fd, + void *buf, + size_t count); + +/* + * Post async read into buffers mapped by iovec from regions mapped + * by xtvec. + * + * NB: An adaptation of "listio" from Argonne's PVFS. + */ +extern ioid_t ireadx(int fd, + const struct iovec *iov, + size_t iov_count, + const struct xtvec *xtv, + size_t xtv_count); + #ifdef __USE_LARGEFILE64 -extern ioid_t SYSIO_INTERFACE_NAME(iread64x)(int fd, - const struct iovec *iov, - size_t iov_count, - const struct xtvec64 *xtv, - size_t xtv_count); +/* + * Post async read into buffers mapped by iovec from regions mapped + * by xtvec. + * + * NB: An adaptation of "listio" from Argonne's PVFS. + */ +extern ioid_t iread64x(int fd, + const struct iovec *iov, + size_t iov_count, + const struct xtvec64 *xtv, + size_t xtv_count); #endif -extern ssize_t SYSIO_INTERFACE_NAME(readx)(int fd, - const struct iovec *iov, - size_t iov_count, - const struct xtvec *xtv, - size_t xtv_count); + +/* + * Read into buffers mapped by iovec from regions mapped + * by xtvec. + * + * NB: An adaptation of "listio" from Argonne's PVFS. + */ +extern ssize_t readx(int fd, + const struct iovec *iov, + size_t iov_count, + const struct xtvec *xtv, + size_t xtv_count); + #ifdef __USE_LARGEFILE64 -extern ssize_t SYSIO_INTERFACE_NAME(read64x)(int fd, - const struct iovec *iov, - size_t iov_count, - const struct xtvec64 *xtv, - size_t xtv_count); +/* + * Read into buffers mapped by iovec from regions mapped + * by xtvec. + * + * NB: An adaptation of "listio" from Argonne's PVFS. + */ +extern ssize_t read64x(int fd, + const struct iovec *iov, + size_t iov_count, + const struct xtvec64 *xtv, + size_t xtv_count); +#endif + +/* + * Post asynch write from buffers mapped by an iovec to file at given offset. + */ +extern ioid_t ipwritev(int fd, + const struct iovec *iov, + size_t count, + off_t offset); +#if _LARGEFILE64_SOURCE +/* + * Post asynch write from buffers mapped by an iovec to file at given offset. + */ +extern ioid_t ipwrite64v(int fd, + const struct iovec *iov, + size_t count, + off64_t offset); #endif -extern ioid_t SYSIO_INTERFACE_NAME(iwritex)(int fd, - const struct iovec *iov, - size_t iov_count, - const struct xtvec *xtv, - size_t xtv_count); + +/* + * Post asynch write from buffer to file at given offset. + */ +extern ioid_t ipwrite(int fd, + const void *buf, + size_t count, + off_t offset); + +#if _LARGEFILE64_SOURCE +/* + * Post asynch write from buffer to file at given offset. + */ +extern ioid_t ipwrite64(int fd, + const void *buf, + size_t count, + off64_t offset); +#endif + +/* + * Write from buffers mapped by an iovec to file at given offset. + */ +extern ssize_t pwritev(int fd, + const struct iovec *iov, + size_t count, + off_t offset); + +#if _LARGEFILE64_SOURCE +/* + * Write from buffers mapped by an iovec to file at given offset. + */ +extern ssize_t pwrite64v(int fd, + const struct iovec *iov, + size_t count, + off64_t offset); +#endif + +/* + * Post asynch write from buffer to file at given offset. + */ +extern ioid_t iwritev(int fd, + const struct iovec *iov, + int count); + +/* + * Write from buffer to file at given offset. + */ +extern ioid_t iwrite(int fd, + const void *buf, + size_t count); + +/* + * Post async write from buffers mapped by iovec to regions mapped + * by xtvec. + * + * NB: An adaptation of "listio" from Argonne's PVFS. + */ +extern ioid_t iwritex(int fd, + const struct iovec *iov, + size_t iov_count, + const struct xtvec *xtv, + size_t xtv_count); + #ifdef __USE_LARGEFILE64 -extern ioid_t SYSIO_INTERFACE_NAME(iwrite64x)(int fd, - const struct iovec *iov, - size_t iov_count, - const struct xtvec64 *xtv, - size_t xtv_count); +/* + * Post async write from buffers mapped by iovec to regions mapped + * by xtvec. + * + * NB: An adaptation of "listio" from Argonne's PVFS. + */ +extern ioid_t iwrite64x(int fd, + const struct iovec *iov, + size_t iov_count, + const struct xtvec64 *xtv, + size_t xtv_count); #endif -extern ssize_t SYSIO_INTERFACE_NAME(writex)(int fd, - const struct iovec *iov, - size_t iov_count, - const struct xtvec *xtv, - size_t xtv_count); + +/* + * Write from buffers mapped by iovec to regions mapped + * by xtvec. + * + * NB: An adaptation of "listio" from Argonne's PVFS. + */ +extern ssize_t writex(int fd, + const struct iovec *iov, + size_t iov_count, + const struct xtvec *xtv, + size_t xtv_count); + #ifdef __USE_LARGEFILE64 -extern ssize_t SYSIO_INTERFACE_NAME(write64x)(int fd, - const struct iovec *iov, - size_t iov_count, - const struct xtvec64 *xtv, - size_t xtv_count); +/* + * Write from buffers mapped by iovec to regions mapped + * by xtvec. + * + * NB: An adaptation of "listio" from Argonne's PVFS. + */ +extern ssize_t write64x(int fd, + const struct iovec *iov, + size_t iov_count, + const struct xtvec64 *xtv, + size_t xtv_count); #endif +#endif /* ! _XTIO_H_ */ diff --git a/libsysio/misc/init-env.sh b/libsysio/misc/init-env.sh index 167f421..3e9861e 100644 --- a/libsysio/misc/init-env.sh +++ b/libsysio/misc/init-env.sh @@ -29,8 +29,11 @@ export SYSIO_NAMESPACE="\ {creat, ft=chr,nm=\"/dev/stderr\",pm=0200,mm=0+2} \ {creat, ft=dir,nm=\"/dev/fd\",pm=0755,ow=0,gr=0} \ {creat, ft=chr,nm=\"/dev/fd/0\",pm=0400,mm=0+0} \ + {open, nm=\"/dev/fd/0\",fd=0,m=0} \ {creat, ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \ + {open, nm=\"/dev/fd/1\",fd=1,m=1} \ {creat, ft=chr,nm=\"/dev/fd/2\",pm=0200,mm=0+2} \ + {open, nm=\"/dev/fd/2\",fd=2,m=1} \ {cd, dir=\"$HOME\"} \ ${_extras} \ " diff --git a/libsysio/src/access.c b/libsysio/src/access.c index e2f6211..9d2664f 100644 --- a/libsysio/src/access.c +++ b/libsysio/src/access.c @@ -43,12 +43,13 @@ #include #include +#include #include #include -#include +#include -#include "sysio-symbols.h" #include "sysio.h" +#include "sysio-symbols.h" int SYSIO_INTERFACE_NAME(access)(const char *path, int amode) @@ -63,6 +64,12 @@ SYSIO_INTERFACE_NAME(access)(const char *path, int amode) SYSIO_INTERFACE_ENTER; err = 0; + /* + * Check amode. + */ + if ((amode & (R_OK|W_OK|X_OK)) != amode) + SYSIO_INTERFACE_RETURN(-1, -EINVAL); + n = getgroups(0, NULL); list = NULL; if (n) { @@ -81,6 +88,9 @@ SYSIO_INTERFACE_NAME(access)(const char *path, int amode) err = -errno; goto out; } + if (!amode) + SYSIO_INTERFACE_RETURN(0, 0); + mask = 0; if (amode & R_OK) diff --git a/libsysio/src/dup.c b/libsysio/src/dup.c index 9226a5a..947d7f0 100644 --- a/libsysio/src/dup.c +++ b/libsysio/src/dup.c @@ -69,7 +69,7 @@ SYSIO_INTERFACE_NAME(dup2)(int oldfd, int newfd) SYSIO_INTERFACE_RETURN(newfd, 0); } - fd = _sysio_fd_dup2(oldfd, newfd); + fd = _sysio_fd_dup(oldfd, newfd, 1); SYSIO_INTERFACE_RETURN(fd < 0 ? -1 : fd, fd < 0 ? fd : 0); } @@ -86,7 +86,7 @@ SYSIO_INTERFACE_NAME(dup)(int oldfd) SYSIO_INTERFACE_DISPLAY_BLOCK; SYSIO_INTERFACE_ENTER; - fd = _sysio_fd_dup2(oldfd, -1); + fd = _sysio_fd_dup(oldfd, -1, 0); SYSIO_INTERFACE_RETURN(fd < 0 ? -1 : fd, fd < 0 ? fd : 0); } diff --git a/libsysio/src/fcntl.c b/libsysio/src/fcntl.c index 63fb920..c8a801a 100644 --- a/libsysio/src/fcntl.c +++ b/libsysio/src/fcntl.c @@ -57,29 +57,12 @@ #include static int -_sysio_fcntl(int fd, int cmd, va_list ap) +_sysio_fcntl(int fd, int cmd, va_list ap, int *rtn) { - int err; - long arg; - - switch (cmd) { - case F_GETFD: - case F_GETFL: - case F_GETOWN: - return syscall(SYS_fcntl, fd, cmd); - case F_DUPFD: - case F_SETFD: - case F_SETFL: - case F_GETLK: - case F_SETLK: - case F_SETLKW: - case F_SETOWN: - arg = va_arg(ap, long); - return syscall(SYS_fcntl, fd, cmd, arg); - } + long arg = va_arg(ap, long); - errno = ENOSYS; - return -1; + *rtn = syscall(SYS_fcntl, fd, cmd, arg); + return *rtn == -1 ? -errno : 0; } #endif @@ -87,6 +70,7 @@ int SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...) { int err; + int rtn; struct file *fil; va_list ap; SYSIO_INTERFACE_DISPLAY_BLOCK; @@ -97,12 +81,12 @@ SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...) if (!fil) { #ifdef HAVE_LUSTRE_HACK va_start(ap, cmd); - err = _sysio_fcntl(fd, cmd, ap); + err = _sysio_fcntl(fd, cmd, ap, &rtn); va_end(ap); - if (err == -1) - err = -errno; goto out; #else + + rtn = -1; err = -EBADF; goto out; #endif @@ -118,21 +102,26 @@ SYSIO_INTERFACE_NAME(fcntl)(int fd, int cmd, ...) newfd = va_arg(ap, long); va_end(ap); if (newfd != (int )newfd || newfd < 0) { + rtn = -1; err = -EBADF; goto out; } - err = _sysio_fd_dup2(fd, (int )newfd); + rtn = _sysio_fd_dup(fd, (int )newfd, 0); + if (rtn < 0) { + err = rtn; + rtn = -1; + } } break; default: va_start(ap, cmd); - err = fil->f_ino->i_ops.inop_fcntl(fil->f_ino, cmd, ap); + err = fil->f_ino->i_ops.inop_fcntl(fil->f_ino, cmd, ap, &rtn); va_end(ap); break; } out: - SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); + SYSIO_INTERFACE_RETURN(rtn, err); } #ifdef __GLIBC__ diff --git a/libsysio/src/file.c b/libsysio/src/file.c index 8d2c3a8..bffc3fd 100644 --- a/libsysio/src/file.c +++ b/libsysio/src/file.c @@ -50,7 +50,6 @@ #include "sysio.h" #include "file.h" #include "inode.h" -#include "xtio.h" /* * Support for file IO. @@ -119,29 +118,27 @@ _sysio_fcompletio(struct ioctx *ioctx, struct file *fil) static int fd_grow(size_t n) { - int fd; size_t count; struct file **noftab, **filp; /* * Sanity check the new size. */ - fd = (int )n; - if ((size_t )fd != n) + if ((int )n < 0) return -EMFILE; - if (n < 8) - n = 8; - if (n >= _sysio_oftab_size && n - _sysio_oftab_size < _sysio_oftab_size) - n = (n + 1) * 2; + /* + * We never shrink the table. + */ + if (n <= _sysio_oftab_size) + return 0; + noftab = realloc(_sysio_oftab, n * sizeof(struct file *)); if (!noftab) return -ENOMEM; _sysio_oftab = noftab; count = _sysio_oftab_size; _sysio_oftab_size = n; - if (n < count) - return 0; filp = _sysio_oftab + count; n -= count; while (n--) @@ -160,21 +157,24 @@ _sysio_fd_shutdown() #endif /* - * Find a free slot in the open files table. + * Find a free slot in the open files table greater than or equal to the + * argument. */ static int -find_free_fildes() +find_free_fildes(int low) { - size_t n; + int n; int err; struct file **filp; - for (n = 0, filp = _sysio_oftab; - n < _sysio_oftab_size && *filp; + for (n = low, filp = _sysio_oftab + low; + n >= 0 && (unsigned )n < _sysio_oftab_size && *filp; n++, filp++) ; - if (n >= _sysio_oftab_size) { - err = fd_grow(n); + if (n < 0) + return -ENFILE; + if ((unsigned )n >= _sysio_oftab_size) { + err = fd_grow((unsigned )n + 1); if (err) return err; filp = &_sysio_oftab[n]; @@ -216,26 +216,29 @@ _sysio_fd_close(int fd) } /* - * Associate open file record with given file descriptor or any available - * file descriptor if less than zero. + * Associate open file record with given file descriptor (if forced), or any + * available file descriptor if less than zero, or any available descriptor + * greater than or equal to the given one if not forced. */ int -_sysio_fd_set(struct file *fil, int fd) +_sysio_fd_set(struct file *fil, int fd, int force) { int err; struct file *ofil; /* - * New fd < 0 => any available descriptor. + * Search for a free descriptor if needed. */ - if (fd < 0) { - fd = find_free_fildes(); + if (fd < 0 || !force) { + if (fd < 0) + fd = 0; + fd = find_free_fildes(fd); if (fd < 0) return fd; } if ((unsigned )fd >= _sysio_oftab_size) { - err = fd_grow(fd); + err = fd_grow((unsigned )fd + 1); if (err) return err; } @@ -258,22 +261,24 @@ _sysio_fd_set(struct file *fil, int fd) * Duplicate old file descriptor. * * If the new file descriptor is less than zero, the new file descriptor - * is chosen freely. + * is chosen freely. Otherwise, choose an available descriptor greater + * than or equal to the new, if not forced. Otherwise, if forced, (re)use + * the new. */ int -_sysio_fd_dup2(int oldfd, int newfd) +_sysio_fd_dup(int oldfd, int newfd, int force) { struct file *fil; int fd; if (oldfd == newfd) - return 0; + return newfd; fil = _sysio_fd_find(oldfd); if (!fil) return -EBADF; - fd = _sysio_fd_set(fil, newfd); + fd = _sysio_fd_set(fil, newfd, force); if (fd >= 0) F_REF(fil); return fd; diff --git a/libsysio/src/file_hack.c b/libsysio/src/file_hack.c index bad70be..524fb55 100644 --- a/libsysio/src/file_hack.c +++ b/libsysio/src/file_hack.c @@ -51,7 +51,6 @@ #include "sysio.h" #include "file.h" #include "inode.h" -#include "xtio.h" /* * Support for file IO. @@ -204,24 +203,27 @@ _sysio_fd_shutdown() #endif /* - * Find a free slot in the open files table. - * target < 0: any free slot - * target >= 0: get slot [target] + * Find a free slot in the open files table which >= @low + * low < 0 means any */ static int -find_free_fildes(oftab_t *oftab, int target) +find_free_fildes(oftab_t *oftab, int low) { int n; int err; struct file **filp; - if (target < 0) { - for (n = 0, filp = oftab->table; - n < oftab->size && *filp; - n++, filp++) - ; - } else - n = target - oftab->offset; + if (low < 0) + low = oftab->offset; + + n = low - oftab->offset; + if (n < 0) + return -ENFILE; + + for (filp = oftab->table + n; + n < oftab->size && *filp; + n++, filp++) + ; if (n >= oftab->size) { err = fd_grow(oftab, n); @@ -231,18 +233,6 @@ find_free_fildes(oftab_t *oftab, int target) assert(!*filp); } -#ifdef HAVE_LUSTRE_HACK - /* FIXME sometimes we could intercept open/socket to create - * a fd, but missing close()? currently we have this problem - * with resolv lib. as a workaround simply destroy the file - * struct here. - */ - if (oftab->table[n]) { - free(oftab->table[n]); - oftab->table[n] = NULL; - } -#endif - return oftab->offset + n; } @@ -299,35 +289,55 @@ _sysio_fd_close(int fd) } /* - * Associate open file record with given file descriptor or any available - * file descriptor if less than zero. + * Associate open file record with given file descriptor (if forced), or any + * available file descriptor if less than zero, or any available descriptor + * greater than or equal to the given one if not forced. */ int -_sysio_fd_set(struct file *fil, int fd) +_sysio_fd_set(struct file *fil, int fd, int force) { int err; struct file *ofil; oftab_t *oftab; + if (force && fd < 0) + abort(); + init_oftab(); oftab = select_oftab(fd); /* - * New fd < 0 => any available descriptor. + * Search for a free descriptor if needed. */ - fd = find_free_fildes(oftab, fd); - if (fd < 0) - return fd; + if (!force) { + fd = find_free_fildes(oftab, fd); + if (fd < 0) + return fd; + } - assert(fd < oftab->offset + oftab->size); + if (fd - oftab->offset >= oftab->size) { + err = fd_grow(oftab, fd - oftab->offset); + if (err) + return err; + } /* * Remember old. */ ofil = __sysio_fd_get(fd, 1); - if (ofil) - F_RELE(ofil); + if (ofil) { + /* FIXME sometimes we could intercept open/socket to create + * a fd, but missing close()? currently we have this problem + * with resolv lib. as a workaround simply destroy the file + * struct here. And this hack will break the behavior of + * DUPFD. + */ + if (fd >= 0 && oftab == &_sysio_oftab[0]) + free(ofil); + else + F_RELE(ofil); + } oftab->table[fd - oftab->offset] = fil; @@ -338,10 +348,12 @@ _sysio_fd_set(struct file *fil, int fd) * Duplicate old file descriptor. * * If the new file descriptor is less than zero, the new file descriptor - * is chosen freely. + * is chosen freely. Otherwise, choose an available descriptor greater + * than or equal to the new, if not forced. Otherwise, if forced, (re)use + * the new. */ int -_sysio_fd_dup2(int oldfd, int newfd) +_sysio_fd_dup(int oldfd, int newfd, int force) { struct file *fil; int fd; @@ -359,7 +371,7 @@ _sysio_fd_dup2(int oldfd, int newfd) if (select_oftab(oldfd) != select_oftab(newfd)) return -EINVAL; - fd = _sysio_fd_set(fil, newfd); + fd = _sysio_fd_set(fil, newfd, force); if (fd >= 0) F_REF(fil); return fd; diff --git a/libsysio/src/init.c b/libsysio/src/init.c index 38d0794..5e3e793 100644 --- a/libsysio/src/init.c +++ b/libsysio/src/init.c @@ -51,19 +51,17 @@ #include #include #include -#include -#include - -#include #include +#include +#include +#include "xtio.h" #include "sysio.h" #include "inode.h" #include "fs.h" #include "mount.h" #include "file.h" #include "dev.h" -#include "xtio.h" #ifdef STDFD_DEV #include "stdfd.h" @@ -394,7 +392,6 @@ do_creat(char *args) xtvec.xtv_len = iovec.iov_len; IOCTX_INIT(&io_context, 1, - (ioid_t )&io_context, 1, ino, &iovec, 1, @@ -549,6 +546,69 @@ do_chmd(char *args) return err; } +static int +do_open(char *args) +{ + size_t len; + struct named_argument v[] = { + { "nm", NULL }, /* path */ + { "fd", NULL }, /* fildes */ + { "m", NULL }, /* mode */ + { NULL, NULL } + }; + char *cp; + int fd; + mode_t m; + struct pnode *dir, *pno; + struct intent intent; + int err; + struct file *fil; + + len = strlen(args); + if (get_args(args, v) - args != (ssize_t )len || + !(v[0].value && v[1].value && v[2].value)) + return -EINVAL; + fd = strtol(v[1].value, (char **)&cp, 0); + if (*cp || + (((fd == LONG_MIN || fd == LONG_MAX) && errno == ERANGE)) || + fd < 0) + return -EINVAL; + m = strtoul(v[1].value, (char **)&cp, 0); + if (*cp || + (m == LONG_MAX && errno == ERANGE)) + return -EINVAL; + m &= O_RDONLY|O_WRONLY|O_RDWR; + + if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) + return -ENOENT; + INTENT_INIT(&intent, INT_OPEN, &m, NULL); + pno = NULL; + err = _sysio_namei(dir, v[0].value, 0, &intent, &pno); + if (err) + return err; + fil = NULL; + do { + err = _sysio_open(pno, m, 0); + if (err) + break; + fil = _sysio_fnew(pno->p_base->pb_ino, m); + if (!fil) { + err = -ENOMEM; + break; + } + err = _sysio_fd_set(fil, fd, 1); + if (err < 0) + break; + P_RELE(pno); + return 0; + } while (0); + if (fil) + F_RELE(fil); + if (pno) + P_RELE(pno); + return err; +} + /* * Execute the given cmd. * @@ -571,6 +631,8 @@ do_command(char *buf) return do_cd(args); if (strcmp("chmd", cmd) == 0) return do_chmd(args); + if (strcmp("open", cmd) == 0) + return do_open(args); } return -EINVAL; } diff --git a/libsysio/src/inode.c b/libsysio/src/inode.c index 6615918..0fa2cd0 100644 --- a/libsysio/src/inode.c +++ b/libsysio/src/inode.c @@ -45,9 +45,9 @@ #include #include #include -#include #include #include +#include #include "sysio.h" #include "fs.h" @@ -956,3 +956,14 @@ _sysio_do_enosys() return -ENOSYS; } + + +/* + * Return -ENODEV + */ +int +_sysio_do_enodev() +{ + + return -ENODEV; +} diff --git a/libsysio/src/ioctx.c b/libsysio/src/ioctx.c index 70c1b3e..4daaf32 100644 --- a/libsysio/src/ioctx.c +++ b/libsysio/src/ioctx.c @@ -45,13 +45,19 @@ #include #include #include -#include #include +#include #include +#include "xtio.h" #include "sysio.h" #include "inode.h" -#include "xtio.h" + + +#if defined(REDSTORM) +#include +#endif + /* * Asynchronous IO context support. @@ -119,7 +125,6 @@ _sysio_ioctx_new(struct inode *ino, IOCTX_INIT(ioctx, 0, - (ioid_t )ioctx, wr, ino, iov, iovlen, @@ -166,12 +171,12 @@ _sysio_ioctx_cb(struct ioctx *ioctx, * this implementation. */ struct ioctx * -_sysio_ioctx_find(ioid_t id) +_sysio_ioctx_find(void *id) { struct ioctx *ioctx; for (ioctx = aioq.lh_first; ioctx; ioctx = ioctx->ioctx_link.le_next) - if (ioctx->ioctx_id == id) + if (ioctx == id) return ioctx; return NULL; @@ -229,6 +234,10 @@ _sysio_ioctx_complete(struct ioctx *ioctx) { struct ioctx_callback *entry; + + /* update IO stats */ + _SYSIO_UPDACCT(ioctx->ioctx_write, ioctx); + /* * Run the call-back queue. */ @@ -375,9 +384,8 @@ _sysio_enumerate_extents(const struct intnl_xtvec *xtv, size_t xtvlen, while (xtvec.xtv_len) { if (iovec.iov_len) { tmp = iovec.iov_len; - if (iovec.iov_len > xtvec.xtv_len) { + if (iovec.iov_len > xtvec.xtv_len) iovec.iov_len = xtvec.xtv_len; - } cc = (*f)(&iovec, 1, xtvec.xtv_off, @@ -394,7 +402,7 @@ _sysio_enumerate_extents(const struct intnl_xtvec *xtv, size_t xtvlen, if (acc && tmp <= acc) abort(); /* paranoia */ acc = tmp; - } else { + } else if (iovlen) { start = iov; n = xtvec.xtv_len; do { @@ -409,18 +417,14 @@ _sysio_enumerate_extents(const struct intnl_xtvec *xtv, size_t xtvlen, } while (--iovlen); if (iov == start) { iovec = *iov++; -#if 0 - if (iovec.iov_len > n) { - iovec.iov_len = n; - } -#endif + iovlen--; continue; } remain = xtvec.xtv_len - n; cc = (*f)(start, iov - start, - xtvec.xtv_off, - xtvec.xtv_len - n, + xtvec.xtv_off, + remain, arg); if (cc <= 0) { if (acc) @@ -432,14 +436,12 @@ _sysio_enumerate_extents(const struct intnl_xtvec *xtv, size_t xtvlen, if (acc && tmp <= acc) abort(); /* paranoia */ acc = tmp; - - if (remain && !iovlen) - return acc; - + remain -= cc; if (remain) return acc; /* short */ - } + } else + return acc; /* short out */ xtvec.xtv_off += cc; xtvec.xtv_len -= cc; } diff --git a/libsysio/src/iowait.c b/libsysio/src/iowait.c index 28035e3..e52ec2f 100644 --- a/libsysio/src/iowait.c +++ b/libsysio/src/iowait.c @@ -56,7 +56,7 @@ * Poll status of asynch IO request. */ int -SYSIO_INTERFACE_NAME(iodone)(ioid_t ioid) +SYSIO_INTERFACE_NAME(iodone)(void *ioid) { struct ioctx *ioctx; int rc; @@ -81,7 +81,7 @@ SYSIO_INTERFACE_NAME(iodone)(ioid_t ioid) * The identifier is no longer valid after return. */ ssize_t -SYSIO_INTERFACE_NAME(iowait)(ioid_t ioid) +SYSIO_INTERFACE_NAME(iowait)(void *ioid) { struct ioctx *ioctx; ssize_t cc; diff --git a/libsysio/src/lseek.c b/libsysio/src/lseek.c index d16efc4..b046ec4 100644 --- a/libsysio/src/lseek.c +++ b/libsysio/src/lseek.c @@ -60,9 +60,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset, int whence) struct file *fil; _SYSIO_OFF_T off, pos; struct intnl_stat stbuf; - SYSIO_INTERFACE_DISPLAY_BLOCK; - SYSIO_INTERFACE_ENTER; fil = _sysio_fd_find(fd); if (!fil) return -EBADF; @@ -85,7 +83,7 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset, int whence) fil->f_ino, &stbuf); if (err) - SYSIO_INTERFACE_RETURN((off_t )-1, (int )err); + return err; } off = stbuf.st_size; @@ -95,32 +93,48 @@ _sysio_lseek(int fd, _SYSIO_OFF_T offset, int whence) } pos = off + offset; if ((offset < 0 && -offset > off) || (offset > 0 && pos <= off)) - SYSIO_INTERFACE_RETURN((off_t )-1, -EINVAL); + return -EINVAL; #ifdef O_LARGEFILE if (pos >= ((fil->f_flags & O_LARGEFILE) ? _SYSIO_OFF_T_MAX : LONG_MAX)) - SYSIO_INTERFACE_RETURN((off_t )-1, -EOVERFLOW); + return -EOVERFLOW; #else if (pos >= _SYSIO_OFF_T_MAX) - SYSIO_INTERFACE_RETURN((off_t )-1, -EOVERFLOW); + return -EOVERFLOW; #endif pos = (fil->f_ino->i_ops.inop_pos)(fil->f_ino, pos); if (pos < 0) - SYSIO_INTERFACE_RETURN((off_t )-1, (int )pos); + return pos; fil->f_pos = pos; - SYSIO_INTERFACE_RETURN((off_t )pos, 0); + return pos; } #if _LARGEFILE64_SOURCE #undef lseek64 -sysio_sym_weak_alias(_sysio_lseek, SYSIO_INTERFACE_NAME(lseek64)) + +extern off64_t +SYSIO_INTERFACE_NAME(lseek64)(int fd, off64_t offset, int whence) +{ + _SYSIO_OFF_T off; + off_t rtn; + SYSIO_INTERFACE_DISPLAY_BLOCK; + + SYSIO_INTERFACE_ENTER; + off = _sysio_lseek(fd, offset, whence); + if (off < 0) + SYSIO_INTERFACE_RETURN((off_t )-1, (int )off); + rtn = (off64_t )off; + assert(rtn == off); + SYSIO_INTERFACE_RETURN(rtn, 0); +} #ifdef __GLIBC__ #undef __lseek64 -sysio_sym_weak_alias(_sysio_lseek, PREPEND(__, SYSIO_INTERFACE_NAME(lseek64))) +sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(lseek64), + PREPEND(__, SYSIO_INTERFACE_NAME(lseek64))) #endif #ifdef REDSTORM #undef __libc_lseek64 -sysio_sym_weak_alias(_sysio_lseek, +sysio_sym_weak_alias(SYSIO_INTERFACE_NAME(lseek64), PREPEND(__, SYSIO_INTERFACE_NAME(libc_lseek64))) #endif #endif diff --git a/libsysio/src/module.mk b/libsysio/src/module.mk index 306d18f..fc3208b 100644 --- a/libsysio/src/module.mk +++ b/libsysio/src/module.mk @@ -26,6 +26,6 @@ SRCDIR_SRCS = src/access.c src/chdir.c src/chmod.c \ src/rmdir.c src/stat64.c src/stat.c \ src/symlink.c src/readlink.c \ src/truncate.c src/unlink.c src/utime.c \ - $(FILE_SUPPORT) $(LUSTRE_SRCDIR_SOURCES) + $(FILE_SUPPORT) $(LUSTRE_SRCDIR_SRCS) SRCDIR_EXTRA = src/module.mk diff --git a/libsysio/src/mount.c b/libsysio/src/mount.c index 3e73832..8785bb0 100644 --- a/libsysio/src/mount.c +++ b/libsysio/src/mount.c @@ -53,13 +53,11 @@ #endif #include +#include "xtio.h" #include "sysio.h" #include "fs.h" #include "mount.h" #include "inode.h" -#ifdef AUTOMOUNT_FILE_NAME -#include "xtio.h" -#endif /* * File system and volume mount support. @@ -618,7 +616,6 @@ _sysio_automount(struct pnode *mntpno) xtvec.xtv_len = stbuf.st_size; IOCTX_INIT(&iocontext, 1, - (ioid_t )&iocontext, 0, ino, &iovec, 1, diff --git a/libsysio/src/namei.c b/libsysio/src/namei.c index 2d2e905..b4d8569 100644 --- a/libsysio/src/namei.c +++ b/libsysio/src/namei.c @@ -50,9 +50,9 @@ #include #include #include -#include #include #include +#include #include "sysio.h" #include "mount.h" diff --git a/libsysio/src/open.c b/libsysio/src/open.c index a7c3127..5845009 100644 --- a/libsysio/src/open.c +++ b/libsysio/src/open.c @@ -62,8 +62,6 @@ #include "mount.h" #include "sysio-symbols.h" -#include "sysio-symbols.h" - /* * Open file support. */ @@ -200,7 +198,7 @@ SYSIO_INTERFACE_NAME(open)(const char *path, int flags, ...) rtn = -ENOMEM; goto error; } - rtn = _sysio_fd_set(fil, -1); + rtn = _sysio_fd_set(fil, -1, 0); if (rtn < 0) goto error; diff --git a/libsysio/src/rename.c b/libsysio/src/rename.c index 167c74f..23e97b1 100644 --- a/libsysio/src/rename.c +++ b/libsysio/src/rename.c @@ -77,7 +77,7 @@ SYSIO_INTERFACE_NAME(rename)(const char *oldpath, const char *newpath) */ INTENT_INIT(&intent, INT_UPDPARENT, NULL, NULL); err = _sysio_namei(_sysio_cwd, newpath, ND_NEGOK, &intent, &new); - if (err && !new) + if (err) goto error2; if (old->p_mount->mnt_root == old || old->p_cover || diff --git a/libsysio/src/rw.c b/libsysio/src/rw.c index ad103b8..edc308b 100644 --- a/libsysio/src/rw.c +++ b/libsysio/src/rw.c @@ -50,10 +50,10 @@ #include #include +#include "xtio.h" #include "sysio.h" #include "file.h" #include "inode.h" -#include "xtio.h" #include "sysio-symbols.h" @@ -267,7 +267,7 @@ SYSIO_INTERFACE_NAME(ireadv)(int fd, const struct iovec *iov, int count) free(xtv); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } ssize_t @@ -351,7 +351,7 @@ SYSIO_INTERFACE_NAME(iread)(int fd, void *buf, size_t count) free(iov); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } ssize_t @@ -464,7 +464,7 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ipreadv))(int fd, free(xtv); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } #if _LARGEFILE64_SOURCE @@ -578,7 +578,7 @@ error: free(xtv); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } #if _LARGEFILE64_SOURCE @@ -693,7 +693,7 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ireadx))(int fd, NULL, &ioctx); - SYSIO_INTERFACE_RETURN(err ? IOID_FAIL : ioctx->ioctx_id, err); + SYSIO_INTERFACE_RETURN(err ? IOID_FAIL : ioctx, err); } #if _LARGEFILE64_SOURCE @@ -743,7 +743,7 @@ SYSIO_INTERFACE_NAME(ireadx)(int fd, free(ixtv); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } #else #undef ireadx @@ -833,7 +833,7 @@ SYSIO_INTERFACE_NAME(iwritev)(int fd, free(xtv); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } ssize_t @@ -909,7 +909,7 @@ SYSIO_INTERFACE_NAME(iwrite)(int fd, const void *buf, size_t count) free(iov); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } ssize_t @@ -983,7 +983,7 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ipwritev))(int fd, free(xtv); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } #if _LARGEFILE64_SOURCE @@ -1097,7 +1097,7 @@ error: free(xtv); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } #if _LARGEFILE64_SOURCE @@ -1212,7 +1212,7 @@ PREPEND(_, SYSIO_INTERFACE_NAME(iwritex))(int fd, NULL, &ioctx); - SYSIO_INTERFACE_RETURN(err ? IOID_FAIL : ioctx->ioctx_id, err); + SYSIO_INTERFACE_RETURN(err ? IOID_FAIL : ioctx, err); } #if _LARGEFILE64_SOURCE @@ -1262,7 +1262,7 @@ SYSIO_INTERFACE_NAME(iwritex)(int fd, free(ixtv); SYSIO_INTERFACE_RETURN(IOID_FAIL, err); } - SYSIO_INTERFACE_RETURN(ioctx->ioctx_id, 0); + SYSIO_INTERFACE_RETURN(ioctx, 0); } #else #undef iwritex diff --git a/libsysio/src/stdlib.c b/libsysio/src/stdlib.c index 7446f35..fcd463a 100644 --- a/libsysio/src/stdlib.c +++ b/libsysio/src/stdlib.c @@ -215,6 +215,7 @@ void rewinddir(DIR *dir) dir->effective = 0; } +#if 0 int scandir(const char *dir, struct dirent ***namelist, int(*select)(const struct dirent *), int(*compar)(const void *, const void *)) @@ -230,6 +231,7 @@ int scandir64(const char *dir, struct dirent64 ***namelist, errno = ENOSYS; return -1; } +#endif /*********************************************************** * FIXME workaround for linux only * diff --git a/libsysio/tests/helper.pm b/libsysio/tests/helper.pm index 306c40e..f656867 100644 --- a/libsysio/tests/helper.pm +++ b/libsysio/tests/helper.pm @@ -26,7 +26,10 @@ sub print_and_exit print $cmdfh $cmdstr; my $res = <$outfh>; - chop($res); + if (defined $res) { + chop($res); + } + print $cmdfh "exit\n"; close $outfh; @@ -47,7 +50,12 @@ sub send_cmd print $cmdfh $cmdstr; my $res = <$outfh>; - chop($res); + if (defined $res) { + chop($res); + } else { + print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n"); + } + if ($res ne "0000 ") { print_and_exit($cmdfh, $outfh, 1, "ERROR! Command $cmd failed with code $res\n"); } @@ -65,7 +73,11 @@ sub verify_cmd send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); my $res = <$outfh>; - chop($res); + if (defined $res) { + chop($res); + } else { + print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n"); + } if ($res eq "0xffffffff") { @@ -75,7 +87,12 @@ sub verify_cmd send_cmd($cmdfh, $outfh, "PRINT", $cmdstr); my $err = <$outfh>; - chop($err); + if (defined $err) { + chop($err); + } else { + print_and_exit($cmdfh, $outfh, 1, "ERROR! Cmd $cmdstr returned null value!\n"); + } + print_and_exit($cmdfh, $outfh, 1, "ERROR! $cmd returned $err\n"); } return $res; diff --git a/libsysio/tests/startup.c b/libsysio/tests/startup.c index 54c56d1..82a92cb 100644 --- a/libsysio/tests/startup.c +++ b/libsysio/tests/startup.c @@ -1,12 +1,14 @@ #include +#include #include #include #include -#include "sysio.h" - +#include "xtio.h" #include "test.h" +#include "sysio.h" + int _test_sysio_startup() { @@ -20,8 +22,30 @@ _test_sysio_startup() if (err) return err; s = getenv("SYSIO_NAMESPACE"); - err = s ? _sysio_boot(s) : -ENOTTY; + if (s) + err = _sysio_boot(s); + else if (!(s = getenv("SYSIO_MANUAL"))) { + /* + * Assume a native mount at root. + */ + err = _sysio_boot("{mnt,dev=\"native:/\",dir=/,fl=0}"); + } if (err) return err; + + s = getenv("SYSIO_CWD"); + if (s) { + err = chdir(s); + if (err) + return err; + } + return 0; } + +void +_test_sysio_shutdown() +{ + + _sysio_shutdown(); +} diff --git a/libsysio/tests/sysio_stubs.c b/libsysio/tests/sysio_stubs.c index 2fc5046..439804d 100644 --- a/libsysio/tests/sysio_stubs.c +++ b/libsysio/tests/sysio_stubs.c @@ -10,10 +10,11 @@ #include #include #include +#include -#include "test_driver.h" -#include "sysio.h" #include "xtio.h" +#include "sysio.h" +#include "test_driver.h" /* * ################################################ diff --git a/libsysio/tests/sysio_tests.c b/libsysio/tests/sysio_tests.c index 8f2f301..4077996 100644 --- a/libsysio/tests/sysio_tests.c +++ b/libsysio/tests/sysio_tests.c @@ -11,9 +11,11 @@ #include #include #include +#include #include +#include -#include "sysio.h" +#include "xtio.h" #include "mount.h" #include "test.h" #include "test_driver.h" diff --git a/libsysio/tests/test.h b/libsysio/tests/test.h index 3357802..781d59b 100644 --- a/libsysio/tests/test.h +++ b/libsysio/tests/test.h @@ -44,3 +44,5 @@ extern int (*drvinits[])(void); extern int drv_init_all(void); +extern int _test_sysio_startup(void); +extern void _test_sysio_shutdown(void); diff --git a/libsysio/tests/test_all.pl b/libsysio/tests/test_all.pl index 25586ba..65bf40e 100755 --- a/libsysio/tests/test_all.pl +++ b/libsysio/tests/test_all.pl @@ -62,8 +62,11 @@ $ENV{$namespace_env} = "\ {creat, ft=chr,nm=\"/dev/stderr\",pm=0200,mm=0+2} \ {creat, ft=dir,nm=\"/dev/fd\",pm=0755,ow=0,gr=0} \ {creat, ft=chr,nm=\"/dev/fd/0\",pm=0400,mm=0+0} \ + {open, nm=\"/dev/fd/0\",fd=0,m=0} \ {creat, ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \ + {open, nm=\"/dev/fd/1\",fd=1,m=1} \ {creat, ft=chr,nm=\"/dev/fd/2\",pm=0200,mm=0+2} \ + {open, nm=\"/dev/fd/2\",fd=2,m=1} \ {cd, dir=\"$home\"} \ $extras "; diff --git a/libsysio/tests/test_copy.c b/libsysio/tests/test_copy.c index bda0bd2..9ac97b1 100644 --- a/libsysio/tests/test_copy.c +++ b/libsysio/tests/test_copy.c @@ -46,20 +46,14 @@ #include #include #include -#ifndef REDSTORM -#include -#endif #include #include #include #include +#include #include -#include "sysio.h" -#include "mount.h" - -#include "fs_native.h" - +#include "xtio.h" #include "test.h" /* @@ -81,7 +75,6 @@ main(int argc, char * const argv[]) int i; int err; const char *spath, *dpath; - extern int _test_sysio_startup(void); /* * Parse command-line args. @@ -123,7 +116,7 @@ main(int argc, char * const argv[]) err = copy_file(spath, dpath); - _sysio_shutdown(); + _test_sysio_shutdown(); return err; } diff --git a/libsysio/tests/test_driver.c b/libsysio/tests/test_driver.c index 943cd85..cbc6415 100644 --- a/libsysio/tests/test_driver.c +++ b/libsysio/tests/test_driver.c @@ -1,5 +1,9 @@ +#ifndef _BSD_SOURCE #define _BSD_SOURCE -#define _XOPEN_SOURCE 600 +#endif +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 500 +#endif #include #include @@ -11,12 +15,13 @@ #include #include #include -#include #include #include #include +#include +#include -#include "sysio.h" +#include "xtio.h" #include "mount.h" #include "test.h" #include "test_driver.h" @@ -968,11 +973,6 @@ int main(int argc, char *argv[]) */ err = _test_sysio_startup(); - /* Temp. hack until I do the right thing to fix this...*/ - open("/dev/stdin",O_RDONLY); - open("/dev/stdout",O_WRONLY); - open("/dev/stderr",O_WRONLY); - infp = stdin; outfp = stdout; diff --git a/libsysio/tests/test_getcwd.c b/libsysio/tests/test_getcwd.c index 340180e..8cd160d 100644 --- a/libsysio/tests/test_getcwd.c +++ b/libsysio/tests/test_getcwd.c @@ -44,19 +44,16 @@ #include #include #include -#ifndef REDSTORM -#include -#else #include -#endif #include #include #include #include +#include #include #include -#include "sysio.h" +#include "xtio.h" #include "mount.h" #include "test.h" @@ -137,7 +134,7 @@ main(int argc, char *const argv[]) /* * Clean up. */ - _sysio_shutdown(); + _test_sysio_shutdown(); return 0; } diff --git a/libsysio/tests/test_getcwd.pl b/libsysio/tests/test_getcwd.pl index 94f33a3..4255a32 100755 --- a/libsysio/tests/test_getcwd.pl +++ b/libsysio/tests/test_getcwd.pl @@ -6,7 +6,7 @@ use strict; use FindBin; use lib "$FindBin::Bin"; use helper; -use Fcntl ':mode'; +use Fcntl; sub usage diff --git a/libsysio/tests/test_link.c b/libsysio/tests/test_link.c index ab4106f..218dd49 100644 --- a/libsysio/tests/test_link.c +++ b/libsysio/tests/test_link.c @@ -44,21 +44,17 @@ #include #include #include -#ifndef REDSTORM -#include -#endif #include #include #include #include -#include #if 0 #include #endif +#include +#include -#include "sysio.h" -#include "mount.h" - +#include "xtio.h" #include "test.h" /* @@ -123,7 +119,7 @@ main(int argc, char *const argv[]) /* * Clean up. */ - _sysio_shutdown(); + _test_sysio_shutdown(); return err ? -1 : 0; } diff --git a/libsysio/tests/test_list.c b/libsysio/tests/test_list.c index 4dc0a82..292bb54 100644 --- a/libsysio/tests/test_list.c +++ b/libsysio/tests/test_list.c @@ -41,24 +41,21 @@ * lee@sandia.gov */ +#define _BSD_SOURCE + #include #include #include -#ifndef REDSTORM -#include -#else #include -#endif #include #include #include #include -#include #include +#include +#include -#include "sysio.h" -#include "mount.h" - +#include "xtio.h" #include "test.h" /* @@ -138,7 +135,7 @@ main(int argc, char *const argv[]) /* * Clean up. */ - _sysio_shutdown(); + _test_sysio_shutdown(); return 0; } diff --git a/libsysio/tests/test_path.c b/libsysio/tests/test_path.c index a7469b3..80cc74e 100644 --- a/libsysio/tests/test_path.c +++ b/libsysio/tests/test_path.c @@ -41,24 +41,18 @@ * lee@sandia.gov */ +#define _BSD_SOURCE + #include #include #include -#ifndef REDSTORM -#include -#else -#include -#endif #include - -#include -#include #include #include +#include +#include -#include "sysio.h" -#include "mount.h" - +#include "xtio.h" #include "test.h" /* @@ -138,7 +132,7 @@ main(int argc, char *const argv[]) /* * Clean up. */ - _sysio_shutdown(); + _test_sysio_shutdown(); return 0; } diff --git a/libsysio/tests/test_path.pl b/libsysio/tests/test_path.pl index c68fdc8..67bdf73 100755 --- a/libsysio/tests/test_path.pl +++ b/libsysio/tests/test_path.pl @@ -12,7 +12,7 @@ use FindBin; use lib "$FindBin::Bin"; use helper; use POSIX; -use Fcntl ':mode'; +use Fcntl; sub usage { diff --git a/libsysio/tests/test_regions.c b/libsysio/tests/test_regions.c index c6120da..ba78800a 100644 --- a/libsysio/tests/test_regions.c +++ b/libsysio/tests/test_regions.c @@ -58,19 +58,14 @@ #include #include #include -#ifndef REDSTORM -#include -#endif #include #include #include #include #include -#include - -#include "sysio.h" -#include "mount.h" +#include +#include "xtio.h" #include "test.h" /* @@ -278,7 +273,7 @@ error: perror(path); free(buf); out: - _sysio_shutdown(); + _test_sysio_shutdown(); return err; } diff --git a/libsysio/tests/test_rename.c b/libsysio/tests/test_rename.c index 7b78429..8bc2ec82 100644 --- a/libsysio/tests/test_rename.c +++ b/libsysio/tests/test_rename.c @@ -46,20 +46,13 @@ #include #include #include -#ifndef REDSTORM -#include -#endif #include #include #include #include -#include - -#include "sysio.h" -#include "mount.h" - -#include "fs_native.h" +#include +#include "xtio.h" #include "test.h" /* @@ -121,7 +114,7 @@ main(int argc, char * const argv[]) if (err) perror("rename"); - _sysio_shutdown(); + _test_sysio_shutdown(); return err; } diff --git a/libsysio/tests/test_stats.c b/libsysio/tests/test_stats.c index 2865a02..951e7cf 100644 --- a/libsysio/tests/test_stats.c +++ b/libsysio/tests/test_stats.c @@ -46,21 +46,16 @@ #include #include #include -#ifndef REDSTORM -#include -#endif #include #include #include #include -#include #ifdef notdef #include #endif +#include -#include "sysio.h" -#include "mount.h" - +#include "xtio.h" #include "test.h" /* @@ -104,7 +99,7 @@ main(int argc, char * const argv[]) /* * Clean up. */ - _sysio_shutdown(); + _test_sysio_shutdown(); return 0; } diff --git a/libsysio/tests/test_unlink.c b/libsysio/tests/test_unlink.c index 9d019d5..d168b28 100644 --- a/libsysio/tests/test_unlink.c +++ b/libsysio/tests/test_unlink.c @@ -44,21 +44,15 @@ #include #include #include -#ifndef REDSTORM -#include -#else #include -#endif #include #include -#include #if 0 #include #endif +#include -#include "sysio.h" -#include "mount.h" - +#include "xtio.h" #include "test.h" /* @@ -138,7 +132,7 @@ main(int argc, char *const argv[]) /* * Clean up. */ - _sysio_shutdown(); + _test_sysio_shutdown(); return 0; } -- 1.8.3.1