[Libsysio-commit] RedStorm_merge: libsysio/drivers/native Makefile.am fs_native.c fs_native.h
Brought to you by:
lward
From: Sonja T. <so...@us...> - 2003-10-09 15:04:18
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1:/tmp/cvs-serv7240/drivers/native Modified Files: Tag: RedStorm_merge Makefile.am fs_native.c fs_native.h Log Message: Merging redstorm changes Index: Makefile.am =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/Makefile.am,v retrieving revision 1.2 retrieving revision 1.2.8.1 diff -u -w -b -B -p -r1.2 -r1.2.8.1 --- Makefile.am 7 Mar 2003 03:31:36 -0000 1.2 +++ Makefile.am 9 Oct 2003 15:04:09 -0000 1.2.8.1 @@ -1,7 +1,7 @@ lib_LIBRARIES = libsysio_native.a -EXTRA_DIST = fs_native.h - libsysio_native_a_SOURCES = fs_native.c + +EXTRA_DIST = fs_native.h include $(top_srcdir)/Rules.make Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.11.4.6 retrieving revision 1.11.4.6.2.1 diff -u -w -b -B -p -r1.11.4.6 -r1.11.4.6.2.1 --- fs_native.c 4 Aug 2003 15:37:05 -0000 1.11.4.6 +++ fs_native.c 9 Oct 2003 15:04:09 -0000 1.11.4.6.2.1 @@ -57,12 +57,9 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/fcntl.h> -#if 0 -#include <sys/vfs.h> -#endif -#ifdef _HAVE_STATVFS #include <sys/statvfs.h> -#endif + +#include <sys/vfs.h> #include <utime.h> #include <sys/queue.h> @@ -73,6 +70,12 @@ #include "fs_native.h" +#ifdef REDSTORM +#include <sys/syscall.h> +#include <sys/uio.h> +#include <catamount/syscall.h> +#endif + /* * Local host file system driver. */ @@ -120,23 +123,39 @@ do { (dest)->st_gen = (src)->st_gen; \ } while (0); +/* SYS_lseek has a different interface on alpha + */ +#define CALL_LSEEK(fd, off, rc, wh) \ + (rc = syscall(SYS_lseek, fd, off, wh)) + #else + #define __native_stat intnl_stat #define COPY_STAT(src, dest) *(dest) = *(src) + +#define CALL_LSEEK(fd, off, rc, wh) \ + (syscall(SYS_lseek, fd, off, &rc, wh)) + #endif #if defined(USE_NATIVE_STAT) -#define __SYS_STAT SYS_stat +#define __SYS_STAT SYS_lstat #define __SYS_FSTAT SYS_fstat #define __SYS_TRUNCATE SYS_truncate #define __SYS_FTRUNCATE SYS_ftruncate #else -#define __SYS_STAT SYS_stat64 +#define __SYS_STAT SYS_lstat64 #define __SYS_FSTAT SYS_fstat64 #define __SYS_TRUNCATE SYS_truncate64 #define __SYS_FTRUNCATE SYS_ftruncate64 #endif +#if defined(USE_NATIVE_FDATASYNC) +#define __SYS_FDATASYNC SYS_osf_fdatasync +#else +#define __SYS_FDATASYNC SYS_fdatasync +#endif + #if defined(USE_NATIVE_UTIME) #define __SYS_UTIME SYS_utimes #else @@ -180,17 +199,53 @@ static int native_inop_setattr(struct pn struct inode *ino, unsigned mask, struct intnl_stat *stbuf); -static ssize_t native_getdirentries(struct inode *ino, +static int doio_orig(ssize_t (*f)(int, const struct iovec *, int), + struct inode *ino, + struct io_arguments *ioargs, + struct ioctx **ioctxp); +static ssize_t _pread(int fd, void *buf, size_t count, off_t offset); +static ssize_t _pwrite(int fd, void *buf, size_t count, off_t offset); +static ssize_t _readv(int fd, const struct iovec *vector, int count); +static ssize_t _writev(int fd, const struct iovec *vector, int count); + +/* + * Stupid hacks to combine redstorm and native drivers. Attempt + * to alias all functions where redstrom and native differ so + * that, ideally, the only #ifdef REDSTORM is here + */ +#ifdef REDSTORM +static int doio_redstorm(ssize_t (*f)(int, void*, size_t, off_t ), + struct inode *ino, + struct io_arguments *ioargs, + struct ioctx **ioctxp); +static ssize_t redstorm_getdirentries(struct inode *ino, + char *buf, + size_t nbytes, + _SYSIO_OFF_T *basep); +#define native_getdirentries redstorm_getdirentries +#define doio doio_redstorm +#define doio_read _pread +#define doio_write _pwrite +#else +static ssize_t original_getdirentries(struct inode *ino, char *buf, size_t nbytes, _SYSIO_OFF_T *basep); +#define native_getdirentries original_getdirentries +#define doio doio_orig +#define doio_read _readv +#define doio_write _writev +#endif + static int native_inop_mkdir(struct pnode *pno, mode_t mode); static int native_inop_rmdir(struct pnode *pno); static int native_inop_symlink(struct pnode *pno, const char *data); static int native_inop_readlink(struct pnode *pno, char *buf, size_t bufsiz); static int native_inop_open(struct pnode *pno, int flags, mode_t mode); static int native_inop_close(struct inode *ino); +static int native_inop_link(struct pnode *old, struct pnode *new); static int native_inop_unlink(struct pnode *pno); +static int native_inop_rename(struct pnode *old, struct pnode *new); static int native_inop_ipreadv(struct inode *ino, struct io_arguments *ioargs, struct ioctx **ioctxp); @@ -205,11 +260,9 @@ static int native_inop_ioctl(struct inod unsigned long int request, va_list ap); static int native_inop_mknod(struct pnode *pno, mode_t mode, dev_t dev); -#ifdef _HAVE_STATVFS static int native_inop_statvfs(struct pnode *pno, struct inode *ino, struct intnl_statvfs *buf); -#endif static void native_inop_gone(struct inode *ino); static struct inode_ops native_i_ops = { @@ -223,7 +276,9 @@ static struct inode_ops native_i_ops = { native_inop_readlink, native_inop_open, native_inop_close, + native_inop_link, native_inop_unlink, + native_inop_rename, native_inop_ipreadv, native_inop_ipwritev, native_inop_iodone, @@ -232,9 +287,7 @@ static struct inode_ops native_i_ops = { native_inop_datasync, native_inop_ioctl, native_inop_mknod, -#ifdef _HAVE_STATVFS native_inop_statvfs, -#endif native_inop_gone }; @@ -295,11 +348,14 @@ static int native_fstat(int fd, struct intnl_stat *buf) { int err; + struct __native_stat stbuf; - err = syscall(__SYS_FSTAT, fd, buf); + err = syscall(__SYS_FSTAT, fd, &stbuf); if (err) err = -errno; + COPY_STAT(&stbuf, buf); + COPY_STAT(&stbuf, buf); return err; } @@ -506,24 +562,24 @@ native_fsswop_mount(const char *source, } static int -native_i_validate(struct inode *inop, struct intnl_stat stbuf) +native_i_invalid(struct inode *inop, struct intnl_stat stbuf) { /* * Validate passed in inode against stat struct info */ struct native_inode *nino = I2NI(inop); - if ((nino->ni_ident.dev == stbuf.st_dev && - nino->ni_ident.ino == stbuf.st_ino && + if ((nino->ni_ident.dev != stbuf.st_dev || + nino->ni_ident.ino != stbuf.st_ino || #ifdef HAVE_GENERATION - nino->ni_ident.gen == stbuf.st_gen && + nino->ni_ident.gen != stbuf.st_gen || #endif - ((inop)->i_mode & stbuf.st_mode) == (inop)->i_mode) && - ((!(S_ISCHR((inop)->i_mode) || S_ISBLK((inop)->i_mode)) || - (inop)->i_rdev == stbuf.st_rdev))) - return 0; - + ((inop)->i_mode & S_IFMT) != (stbuf.st_mode & S_IFMT)) || + (((inop)->i_rdev != stbuf.st_rdev) && + (S_ISCHR((inop)->i_mode) || S_ISBLK((inop)->i_mode)))) return 1; + + return 0; } /* @@ -555,7 +611,7 @@ native_iget(struct filesys *fs, * Validate? */ if (*inop) { - if (!native_i_validate(*inop, stbuf)) + if (!native_i_invalid(*inop, stbuf)) return 0; /* * Invalidate. @@ -579,7 +635,7 @@ native_iget(struct filesys *fs, /* * Insertion was forced but it's already present! */ - if (native_i_validate(ino, stbuf)) { + if (native_i_invalid(ino, stbuf)) { /* * Cached inode has stale attrs * make way for the new one @@ -817,9 +873,10 @@ out: return err; } + static int native_pos(int fd, -#ifdef _LARGEFILE64_SOURCE +#if _LARGEFILE64_SOURCE loff_t *offset #else _SYSIO_OFF_T *offset @@ -830,7 +887,7 @@ native_pos(int fd, assert(fd >= 0); assert(*offset >= 0); -#ifdef _LARGEFILE64_SOURCE +#if _LARGEFILE64_SOURCE && defined(SYS__llseek) { int err; err = @@ -856,31 +913,62 @@ native_pos(int fd, return 0; } +#ifdef REDSTORM +static ssize_t +redstorm_getdirentries(struct inode *ino, + char *buf, + size_t nbytes, + _SYSIO_OFF_T *basep) +{ + struct native_inode *nino = I2NI(ino); + ssize_t cc; + + assert(nino->ni_fd >= 0); + +#ifndef USE_NATURAL_GETDENTS + cc = syscall(SYS_getdirentries64, nino->ni_fd, buf, nbytes, + basep, &nino->ni_fpos ); +#else + cc = syscall(SYS_getdirentries, nino->ni_fd, buf, nbytes, + basep, &nino->ni_fpos ); +#endif + + if (cc < 0) + return -errno; + + return cc; +} + +#else static ssize_t -native_getdirentries(struct inode *ino, +original_getdirentries(struct inode *ino, char *buf, size_t nbytes, _SYSIO_OFF_T *basep) { struct native_inode *nino = I2NI(ino); + ssize_t cc; int err; -#ifdef _LARGEFILE64_SOURCE +#if _LARGEFILE64_SOURCE loff_t result; #else _SYSIO_OFF_T result; #endif - ssize_t cc; + assert(nino->ni_fd >= 0); result = *basep; - if (*basep != nino->ni_fpos) { - err = native_pos(nino->ni_fd, &result); - if (err) - return err; - } + + if (*basep != nino->ni_fpos && + CALL_LSEEK(nino->ni_fd, + *basep, + result, + SEEK_SET) == -1) + return -errno; nino->ni_fpos = result; + #ifndef USE_NATURAL_GETDENTS cc = syscall(SYS_getdents64, nino->ni_fd, buf, nbytes); #else @@ -886,11 +974,12 @@ native_getdirentries(struct inode *ino, #else cc = syscall(SYS_getdents, nino->ni_fd, buf, nbytes); #endif + if (cc < 0) return -errno; - nino->ni_fpos += cc; return cc; } +#endif static int native_inop_mkdir(struct pnode *pno, mode_t mode) @@ -1052,10 +1141,36 @@ native_inop_close(struct inode *ino) } static int +native_inop_link(struct pnode *old, struct pnode *new) +{ + int err; + char *opath, *npath; + + err = 0; + + opath = _sysio_pb_path(old->p_base, '/'); + npath = _sysio_pb_path(new->p_base, '/'); + if (!(opath && npath)) { + err = -ENOMEM; + goto out; + } + + err = syscall(SYS_link, opath, npath); + +out: + if (opath) + free(opath); + if (npath) + free(npath); + + return err; +} + +static int native_inop_unlink(struct pnode *pno) { char *path; - int err; + int err = 0; path = _sysio_pb_path(pno->p_base, '/'); if (!path) @@ -1073,8 +1188,9 @@ native_inop_unlink(struct pnode *pno) * (usually .NFSXXXXXX, where the X's are replaced by the PID and some * unique characters) in order to simulate the proper semantic. */ - if (!syscall(SYS_unlink, path)) + if (syscall(SYS_unlink, path) != 0) err = -errno; + free(path); return err; } @@ -1085,15 +1201,58 @@ native_inop_unlink(struct pnode *pno) * We don't really have async IO. We'll just perform the function * now. */ +#ifdef REDSTORM +static int +doio_redstorm(ssize_t (*f)(int, void*, size_t, off_t ), + struct inode *ino, + struct io_arguments *ioargs, + struct ioctx **ioctxp) +{ + struct native_inode *nino = I2NI(ino); + struct ioctx *ioctx; + + + assert(nino->ni_fd >= 0); + + /* + * Get a new IO context. + */ + ioctx = _sysio_ioctx_new(ino, ioargs); + if (!ioctx) + return -ENOMEM; + + if ((ioargs->ioarg_iovlen && (int )ioargs->ioarg_iovlen != 1) || + !(S_ISREG(ino->i_mode) || + S_ISCHR(ino->i_mode) || + S_ISSOCK(ino->i_mode) || + S_ISFIFO(ino->i_mode))) + return -EINVAL; + + ioctx->ioctx_cc = (*f)( nino->ni_fd, + ioctx->ioctx_iovec[0].iov_base, + ioctx->ioctx_iovec[0].iov_len, + ioctx->ioctx_offset ); + if (ioctx->ioctx_cc < 0) + ioctx->ioctx_errno = errno; + if (ioctx->ioctx_cc > 0) + nino->ni_fpos += ioctx->ioctx_cc; + + *ioctxp = ioctx; + + out: + return 0; +} +#endif + static int -doio(ssize_t (*f)(int, const struct iovec *, int), +doio_orig(ssize_t (*f)(int, const struct iovec *, int), struct inode *ino, struct io_arguments *ioargs, struct ioctx **ioctxp) { struct native_inode *nino = I2NI(ino); struct ioctx *ioctx; -#ifdef _LARGEFILE64_SOURCE +#if _LARGEFILE64_SOURCE loff_t result; #else _SYSIO_OFF_T result; @@ -1101,6 +1260,9 @@ doio(ssize_t (*f)(int, const struct iove assert(nino->ni_fd >= 0); + if (ioargs->ioarg_iovlen && (int )ioargs->ioarg_iovlen < 0) + return -EINVAL; + /* * Get a new IO context. */ @@ -1156,6 +1318,21 @@ out: return 0; } + +static ssize_t +_pread(int fd, void *buf, size_t count, off_t offset) +{ + return syscall(SYS_pread, fd, buf, count, offset); +} + +static ssize_t +_pwrite(int fd, void *buf, size_t count, off_t offset) +{ + + return syscall(SYS_pwrite, fd, buf, count, offset); +} + + /* * Helper function passed to doio(), above, to accomplish a real readv. */ @@ -1167,12 +1344,35 @@ _readv(int fd, const struct iovec *vecto } static int +native_inop_rename(struct pnode *old, struct pnode *new) +{ + int err; + char *opath, *npath; + + opath = _sysio_pb_path(old->p_base, '/'); + npath = _sysio_pb_path(new->p_base, '/'); + if (!(opath && npath)) { + err = -ENOMEM; + goto out; + } + + err = syscall(SYS_rename, opath, npath); + +out: + if (opath) + free(opath); + if (npath) + free(npath); + + return err; +} + +static int native_inop_ipreadv(struct inode *ino, struct io_arguments *ioargs, struct ioctx **ioctxp) { - - return doio(_readv, ino, ioargs, ioctxp); + return doio(doio_read, ino, ioargs, ioctxp); } /* @@ -1190,8 +1390,7 @@ native_inop_ipwritev(struct inode *ino, struct io_arguments *ioargs, struct ioctx **ioctxp) { - - return doio(_writev, ino, ioargs, ioctxp); + return doio(doio_write, ino, ioargs, ioctxp); } static int @@ -1226,7 +1425,6 @@ native_inop_mknod(struct pnode *pno __IS return -ENOSYS; } -#ifdef _HAVE_STATVFS static int native_inop_statvfs(struct pnode *pno, struct inode *ino, @@ -1267,12 +1465,24 @@ native_inop_statvfs(struct pnode *pno, buf->f_files = fs.f_files; /* Total number serial numbers */ buf->f_ffree = fs.f_ffree; /* Number free serial numbers */ buf->f_favail = fs.f_ffree; /* Number free ser num for non-privileged*/ +#if defined(BSD) || defined(REDSTORM) + buf->f_fsid = fs.f_fsid.val[1]; + /* + * REVISIT: + * There is no fs.f_namelen in the structure defined in + * the RedStorm headers. For lack of a better answer, I + * just statically set this to 255. This may cause problems + * later on. + */ + buf->f_namemax = 255; +#else buf->f_fsid = fs.f_fsid.__val[1]; - buf->f_flag = 0; /* No equiv in statfs; maybe use type? */ buf->f_namemax = fs.f_namelen; +#endif + buf->f_flag = 0; /* No equiv in statfs; maybe use type? */ + return 0; } -#endif static int native_inop_sync(struct inode *ino) Index: fs_native.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.h,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.1.10.1 diff -u -w -b -B -p -r1.1.1.1 -r1.1.1.1.10.1 --- fs_native.h 22 Feb 2003 16:33:14 -0000 1.1.1.1 +++ fs_native.h 9 Oct 2003 15:04:09 -0000 1.1.1.1.10.1 @@ -45,4 +45,9 @@ * Native file system driver support. */ + extern int _sysio_native_init(void); +#ifdef IS_REDSTORM +extern void start_sysio(void); +extern void mountFiles(void); +#endif |