fs/9p: Don't set stat.st_blocks based on nrpages
[deliverable/linux.git] / fs / 9p / vfs_inode.c
index b76a40bdf4c20e736fa908fa4d575cde91952d32..304904b406103778a015a203477572b62b966d1c 100644 (file)
@@ -243,26 +243,10 @@ void v9fs_destroy_inode(struct inode *inode)
 }
 #endif
 
-/**
- * v9fs_get_inode - helper function to setup an inode
- * @sb: superblock
- * @mode: mode to setup inode with
- *
- */
-
-struct inode *v9fs_get_inode(struct super_block *sb, int mode)
+int v9fs_init_inode(struct v9fs_session_info *v9ses,
+                   struct inode *inode, int mode)
 {
-       int err;
-       struct inode *inode;
-       struct v9fs_session_info *v9ses = sb->s_fs_info;
-
-       P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
-
-       inode = new_inode(sb);
-       if (!inode) {
-               P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
-               return ERR_PTR(-ENOMEM);
-       }
+       int err = 0;
 
        inode_init_owner(inode, NULL, mode);
        inode->i_blocks = 0;
@@ -292,14 +276,20 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
        case S_IFREG:
                if (v9fs_proto_dotl(v9ses)) {
                        inode->i_op = &v9fs_file_inode_operations_dotl;
-                       inode->i_fop = &v9fs_file_operations_dotl;
+                       if (v9ses->cache)
+                               inode->i_fop =
+                                       &v9fs_cached_file_operations_dotl;
+                       else
+                               inode->i_fop = &v9fs_file_operations_dotl;
                } else {
                        inode->i_op = &v9fs_file_inode_operations;
-                       inode->i_fop = &v9fs_file_operations;
+                       if (v9ses->cache)
+                               inode->i_fop = &v9fs_cached_file_operations;
+                       else
+                               inode->i_fop = &v9fs_file_operations;
                }
 
                break;
-
        case S_IFLNK:
                if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
                        P9_DPRINTK(P9_DEBUG_ERROR, "extended modes used with "
@@ -335,12 +325,37 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
                err = -EINVAL;
                goto error;
        }
+error:
+       return err;
 
-       return inode;
+}
 
-error:
-       iput(inode);
-       return ERR_PTR(err);
+/**
+ * v9fs_get_inode - helper function to setup an inode
+ * @sb: superblock
+ * @mode: mode to setup inode with
+ *
+ */
+
+struct inode *v9fs_get_inode(struct super_block *sb, int mode)
+{
+       int err;
+       struct inode *inode;
+       struct v9fs_session_info *v9ses = sb->s_fs_info;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
+
+       inode = new_inode(sb);
+       if (!inode) {
+               P9_EPRINTK(KERN_WARNING, "Problem allocating inode\n");
+               return ERR_PTR(-ENOMEM);
+       }
+       err = v9fs_init_inode(v9ses, inode, mode);
+       if (err) {
+               iput(inode);
+               return ERR_PTR(err);
+       }
+       return inode;
 }
 
 /*
@@ -410,41 +425,67 @@ void v9fs_evict_inode(struct inode *inode)
 #ifdef CONFIG_9P_FSCACHE
        v9fs_cache_inode_put_cookie(inode);
 #endif
+       /* clunk the fid stashed in inode->i_private */
+       if (inode->i_private) {
+               p9_client_clunk((struct p9_fid *)inode->i_private);
+               inode->i_private = NULL;
+       }
 }
 
-struct inode *
-v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid,
-       struct super_block *sb)
+static struct inode *v9fs_qid_iget(struct super_block *sb,
+                                  struct p9_qid *qid,
+                                  struct p9_wstat *st)
 {
-       int err, umode;
-       struct inode *ret = NULL;
-       struct p9_wstat *st;
-
-       st = p9_client_stat(fid);
-       if (IS_ERR(st))
-               return ERR_CAST(st);
+       int retval, umode;
+       unsigned long i_ino;
+       struct inode *inode;
+       struct v9fs_session_info *v9ses = sb->s_fs_info;
 
+       i_ino = v9fs_qid2ino(qid);
+       inode = iget_locked(sb, i_ino);
+       if (!inode)
+               return ERR_PTR(-ENOMEM);
+       if (!(inode->i_state & I_NEW))
+               return inode;
+       /*
+        * initialize the inode with the stat info
+        * FIXME!! we may need support for stale inodes
+        * later.
+        */
        umode = p9mode2unixmode(v9ses, st->mode);
-       ret = v9fs_get_inode(sb, umode);
-       if (IS_ERR(ret)) {
-               err = PTR_ERR(ret);
+       retval = v9fs_init_inode(v9ses, inode, umode);
+       if (retval)
                goto error;
-       }
-
-       v9fs_stat2inode(st, ret, sb);
-       ret->i_ino = v9fs_qid2ino(&st->qid);
 
+       v9fs_stat2inode(st, inode, sb);
 #ifdef CONFIG_9P_FSCACHE
        v9fs_vcookie_set_qid(ret, &st->qid);
-       v9fs_cache_inode_get_cookie(ret);
+       v9fs_cache_inode_get_cookie(inode);
 #endif
-       p9stat_free(st);
-       kfree(st);
-       return ret;
+       unlock_new_inode(inode);
+       return inode;
 error:
+       unlock_new_inode(inode);
+       iput(inode);
+       return ERR_PTR(retval);
+
+}
+
+struct inode *
+v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid,
+          struct super_block *sb)
+{
+       struct p9_wstat *st;
+       struct inode *inode = NULL;
+
+       st = p9_client_stat(fid);
+       if (IS_ERR(st))
+               return ERR_CAST(st);
+
+       inode = v9fs_qid_iget(sb, &st->qid, st);
        p9stat_free(st);
        kfree(st);
-       return ERR_PTR(err);
+       return inode;
 }
 
 /**
@@ -571,7 +612,7 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
        u32 perm;
        int flags;
        struct v9fs_session_info *v9ses;
-       struct p9_fid *fid;
+       struct p9_fid *fid, *inode_fid;
        struct file *filp;
 
        err = 0;
@@ -594,6 +635,21 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
 
        /* if we are opening a file, assign the open fid to the file */
        if (nd && nd->flags & LOOKUP_OPEN) {
+               if (v9ses->cache && !dentry->d_inode->i_private) {
+                       /*
+                        * clone a fid and add it to inode->i_private
+                        * we do it during open time instead of
+                        * page dirty time via write_begin/page_mkwrite
+                        * because we want write after unlink usecase
+                        * to work.
+                        */
+                       inode_fid = v9fs_writeback_fid(dentry);
+                       if (IS_ERR(inode_fid)) {
+                               err = PTR_ERR(inode_fid);
+                               goto error;
+                       }
+                       dentry->d_inode->i_private = (void *) inode_fid;
+               }
                filp = lookup_instantiate_filp(nd, dentry, generic_file_open);
                if (IS_ERR(filp)) {
                        err = PTR_ERR(filp);
@@ -601,6 +657,10 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
                }
 
                filp->private_data = fid;
+#ifdef CONFIG_9P_FSCACHE
+               if (v9ses->cache)
+                       v9fs_cache_inode_set_cookie(dentry->d_inode, filp);
+#endif
        } else
                p9_client_clunk(fid);
 
@@ -831,9 +891,10 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
        P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
        err = -EPERM;
        v9ses = v9fs_inode2v9ses(dentry->d_inode);
-       if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
-               return simple_getattr(mnt, dentry, stat);
-
+       if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+               generic_fillattr(dentry->d_inode, stat);
+               return 0;
+       }
        fid = v9fs_fid_lookup(dentry);
        if (IS_ERR(fid))
                return PTR_ERR(fid);
This page took 0.027777 seconds and 5 git commands to generate.