Pull ec into release branch
[powerpc.git] / fs / 9p / vfs_file.c
index e86a071..c7b6772 100644 (file)
@@ -42,6 +42,8 @@
 #include "v9fs_vfs.h"
 #include "fid.h"
 
+static const struct file_operations v9fs_cached_file_operations;
+
 /**
  * v9fs_file_open - open a file (or directory)
  * @inode: inode to be opened
@@ -55,53 +57,22 @@ int v9fs_file_open(struct inode *inode, struct file *file)
        struct v9fs_fid *vfid;
        struct v9fs_fcall *fcall = NULL;
        int omode;
-       int fid = V9FS_NOFID;
        int err;
 
        dprintk(DEBUG_VFS, "inode: %p file: %p \n", inode, file);
 
-       vfid = v9fs_fid_lookup(file->f_path.dentry);
-       if (!vfid) {
-               dprintk(DEBUG_ERROR, "Couldn't resolve fid from dentry\n");
-               return -EBADF;
-       }
-
-       fid = v9fs_get_idpool(&v9ses->fidpool);
-       if (fid < 0) {
-               eprintk(KERN_WARNING, "newfid fails!\n");
-               return -ENOSPC;
-       }
+       vfid = v9fs_fid_clone(file->f_path.dentry);
+       if (IS_ERR(vfid))
+               return PTR_ERR(vfid);
 
-       err = v9fs_t_walk(v9ses, vfid->fid, fid, NULL, &fcall);
-       if (err < 0) {
-               dprintk(DEBUG_ERROR, "rewalk didn't work\n");
-               if (fcall && fcall->id == RWALK)
-                       goto clunk_fid;
-               else {
-                       v9fs_put_idpool(fid, &v9ses->fidpool);
-                       goto free_fcall;
-               }
-       }
-       kfree(fcall);
-
-       /* TODO: do special things for O_EXCL, O_NOFOLLOW, O_SYNC */
-       /* translate open mode appropriately */
        omode = v9fs_uflags2omode(file->f_flags);
-       err = v9fs_t_open(v9ses, fid, omode, &fcall);
+       err = v9fs_t_open(v9ses, vfid->fid, omode, &fcall);
        if (err < 0) {
                PRINT_FCALL_ERROR("open failed", fcall);
-               goto clunk_fid;
-       }
-
-       vfid = kmalloc(sizeof(struct v9fs_fid), GFP_KERNEL);
-       if (vfid == NULL) {
-               dprintk(DEBUG_ERROR, "out of memory\n");
-               err = -ENOMEM;
-               goto clunk_fid;
+               goto Clunk_Fid;
        }
 
        file->private_data = vfid;
-       vfid->fid = fid;
        vfid->fidopen = 1;
        vfid->fidclunked = 0;
        vfid->iounit = fcall->params.ropen.iounit;
@@ -110,12 +81,17 @@ int v9fs_file_open(struct inode *inode, struct file *file)
        vfid->filp = file;
        kfree(fcall);
 
-       return 0;
+       if((vfid->qid.version) && (v9ses->cache)) {
+               dprintk(DEBUG_VFS, "cached");
+               /* enable cached file options */
+               if(file->f_op == &v9fs_file_operations)
+                       file->f_op = &v9fs_cached_file_operations;
+       }
 
-clunk_fid:
-       v9fs_t_clunk(v9ses, fid);
+       return 0;
 
-free_fcall:
+Clunk_Fid:
+       v9fs_fid_clunk(v9ses, vfid);
        kfree(fcall);
 
        return err;
@@ -143,7 +119,7 @@ static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
 
        if ((IS_SETLK(cmd) || IS_SETLKW(cmd)) && fl->fl_type != F_UNLCK) {
                filemap_write_and_wait(inode->i_mapping);
-               invalidate_inode_pages(&inode->i_data);
+               invalidate_mapping_pages(&inode->i_data, 0, -1);
        }
 
        return res;
@@ -267,10 +243,21 @@ v9fs_file_write(struct file *filp, const char __user * data,
                total += result;
        } while (count);
 
-               invalidate_inode_pages2(inode->i_mapping);
+       invalidate_inode_pages2(inode->i_mapping);
        return total;
 }
 
+static const struct file_operations v9fs_cached_file_operations = {
+       .llseek = generic_file_llseek,
+       .read = do_sync_read,
+       .aio_read = generic_file_aio_read,
+       .write = v9fs_file_write,
+       .open = v9fs_file_open,
+       .release = v9fs_dir_release,
+       .lock = v9fs_file_lock,
+       .mmap = generic_file_mmap,
+};
+
 const struct file_operations v9fs_file_operations = {
        .llseek = generic_file_llseek,
        .read = v9fs_file_read,