Whamcloud - gitweb
b=20668
[fs/lustre-release.git] / libsysio / drivers / yod / fs_yod.c
index d651b88..ea0ce35 100644 (file)
@@ -53,7 +53,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <assert.h>
-#include <syscall.h>
+#include <sys/syscall.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/fcntl.h>
@@ -65,8 +65,8 @@
 #endif
 #include <utime.h>
 #include <sys/queue.h>
-#include <sys/uio.h>
 
+#include "xtio.h"
 #include "sysio.h"
 #include "fs.h"
 #include "mount.h"
@@ -103,7 +103,7 @@ do {                                            \
        (dest)->st_blocks  = (src)->st_blocks;  \
        (dest)->st_flags   = (src)->st_flags;   \
        (dest)->st_gen     = (src)->st_gen;     \
-} while (0);
+} while (0)
 #else
 #define COPY_STAT(src, dest)                    \
 do {                                            \
@@ -121,7 +121,7 @@ do {                                            \
        (dest)->st_ctime   = (src)->st_ctime;   \
        (dest)->st_blksize = (src)->st_blksize; \
        (dest)->st_blocks  = (src)->st_blocks;  \
-} while (0);
+} while (0)
 #endif
 
 /*
@@ -160,10 +160,10 @@ static int yod_inop_setattr(struct pnode *pno,
                               struct inode *ino,
                               unsigned mask,
                               struct intnl_stat *stbuf);
-static ssize_t yod_getdirentries(struct inode *ino,
-                                   char *buf,
-                                   size_t nbytes,
-                                   off64_t *basep);
+static ssize_t yod_filldirentries(struct inode *ino,
+                                 off64_t *posp,
+                                 char *buf,
+                                 size_t nbytes);
 static int yod_inop_mkdir(struct pnode *pno, mode_t mode);
 static int yod_inop_rmdir(struct pnode *pno);
 static int yod_inop_symlink(struct pnode *pno, const char *data);
@@ -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,
@@ -195,7 +195,7 @@ static struct inode_ops yod_i_ops = {
        yod_inop_lookup,
        yod_inop_getattr,
        yod_inop_setattr,
-       yod_getdirentries,
+       yod_filldirentries,
        yod_inop_mkdir,
        yod_inop_rmdir,
        yod_inop_symlink,
@@ -293,6 +293,7 @@ yod_i_new(struct filesys *fs, struct intnl_stat *buf)
        if (!nino)
                return NULL;
        bzero(&nino->ni_ident, sizeof(nino->ni_ident));
+       nino->ni_seekok = 0;
        nino->ni_ident.dev = buf->st_dev;
        nino->ni_ident.ino = buf->st_ino;
 #ifdef HAVE_GENERATION
@@ -307,12 +308,7 @@ yod_i_new(struct filesys *fs, struct intnl_stat *buf)
        ino =
            _sysio_i_new(fs,
                         &nino->ni_fileid,
-#ifndef AUTOMOUNT_FILE_NAME
-                        buf->st_mode & S_IFMT,
-#else
-                        buf->st_mode,                  /* all of the bits! */
-#endif
-                        0,
+                        buf,
                         0,
                         &yod_i_ops,
                         nino);
@@ -416,7 +412,6 @@ error:
                _sysio_pb_gone(rootpb);
        if (fs) {
                FS_RELE(fs);
-               _sysio_fs_gone(fs);
        }
 
        return err;
@@ -480,21 +475,22 @@ yod_fsswop_mount(const char *source,
 }
 
 static int
-yod_i_invalid(struct inode *inop, struct intnl_stat stbuf)
+yod_i_invalid(struct inode *inop, struct intnl_stat *stat)
 {
        /*
         * Validate passed in inode against stat struct info
         */
        struct yod_inode *nino = I2NI(inop);
        
-       if ((nino->ni_ident.dev != stbuf.st_dev ||
-            nino->ni_ident.ino != stbuf.st_ino ||
+       if ((nino->ni_ident.dev != stat->st_dev ||
+            nino->ni_ident.ino != stat->st_ino ||
 #ifdef HAVE_GENERATION
-            nino->ni_ident.gen != stbuf.st_gen ||
+            nino->ni_ident.gen != stat->st_gen ||
 #endif
-            ((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))))
+            ((inop)->i_stbuf.st_mode & S_IFMT) != (stat->st_mode & S_IFMT)) ||
+           (((inop)->i_stbuf.st_rdev != stat->st_rdev) &&
+              (S_ISCHR((inop)->i_stbuf.st_mode) ||
+               S_ISBLK((inop)->i_stbuf.st_mode))))
                return 1;
        
        return 0;
@@ -529,7 +525,7 @@ yod_iget(struct filesys *fs,
         * Validate?
         */
        if (*inop) {
-               if (!yod_i_invalid(*inop, stbuf))
+               if (!yod_i_invalid(*inop, &stbuf))
                        return 0;
                /*
                 * Invalidate.
@@ -553,7 +549,7 @@ yod_iget(struct filesys *fs,
                /*
                 * Insertion was forced but it's already present!
                 */
-               if (yod_i_invalid(ino, stbuf)) {
+               if (yod_i_invalid(ino, &stbuf)) {
                        /* 
                         * Cached inode has stale attrs
                         * make way for the new one
@@ -744,13 +740,13 @@ out:
 }
 
 static ssize_t
-yod_getdirentries(struct inode *ino,
-                    char *buf,
-                    size_t nbytes,
-                    off64_t *basep)
+yod_filldirentries(struct inode *ino,
+                  char *buf,
+                  _SYSIO_OFF_T *posp,
+                   size_t nbytes)
 {
        struct yod_inode *nino = I2NI(ino);
-       loff_t  result;
+       _SYSIO_OFF_T result;
        ssize_t cc;
 
        assert(nino->ni_fd >= 0);
@@ -758,14 +754,19 @@ yod_getdirentries(struct inode *ino,
        result = *basep;
        if (*basep != nino->ni_fpos &&
            (result = lseek_yod(nino->ni_fd,
-                               *basep,
+                               *posp,
                                SEEK_SET) == -1))
                return -errno;
        nino->ni_fpos = result;
+       memset(buf, 0, nbytes);
+       /*
+        * This is almost certainly broken. The resulting position parameter
+        * points to the block just filled, not the next.
+        */
        cc = getdirentries_yod(nino->ni_fd, buf, nbytes, &result);
        if (cc < 0)
                return -errno;
-       nino->ni_fpos += cc;
+       nino->ni_fpos = *posp = result;
        return cc;
 }
 
@@ -1101,18 +1102,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