]> err.no Git - linux-2.6/blobdiff - fs/9p/vfs_inode.c
Merge git://git.tuxdriver.com/git/netdev-jwl
[linux-2.6] / fs / 9p / vfs_inode.c
index 6d2357d1dacd75987f45bedd5c8b624ef9b093c2..be7288184fa9de0a580f7ec64d86f29fec5d3ce3 100644 (file)
@@ -44,6 +44,7 @@
 #include "fid.h"
 
 static struct inode_operations v9fs_dir_inode_operations;
+static struct inode_operations v9fs_dir_inode_operations_ext;
 static struct inode_operations v9fs_file_inode_operations;
 static struct inode_operations v9fs_symlink_inode_operations;
 
@@ -232,6 +233,7 @@ v9fs_mistat2unix(struct v9fs_stat *mistat, struct stat *buf,
 struct inode *v9fs_get_inode(struct super_block *sb, int mode)
 {
        struct inode *inode = NULL;
+       struct v9fs_session_info *v9ses = sb->s_fs_info;
 
        dprintk(DEBUG_VFS, "super block: %p mode: %o\n", sb, mode);
 
@@ -250,18 +252,32 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
                case S_IFBLK:
                case S_IFCHR:
                case S_IFSOCK:
+                       if(!v9ses->extended) {
+                               dprintk(DEBUG_ERROR, "special files without extended mode\n");
+                               return ERR_PTR(-EINVAL);
+                       }
+                       init_special_inode(inode, inode->i_mode,
+                                          inode->i_rdev);
+                       break;
                case S_IFREG:
                        inode->i_op = &v9fs_file_inode_operations;
                        inode->i_fop = &v9fs_file_operations;
                        break;
+               case S_IFLNK:
+                       if(!v9ses->extended) {
+                               dprintk(DEBUG_ERROR, "extended modes used w/o 9P2000.u\n");
+                               return ERR_PTR(-EINVAL);
+                       }
+                       inode->i_op = &v9fs_symlink_inode_operations;
+                       break;
                case S_IFDIR:
                        inode->i_nlink++;
-                       inode->i_op = &v9fs_dir_inode_operations;
+                       if(v9ses->extended)
+                               inode->i_op = &v9fs_dir_inode_operations_ext;
+                       else
+                               inode->i_op = &v9fs_dir_inode_operations;
                        inode->i_fop = &v9fs_dir_operations;
                        break;
-               case S_IFLNK:
-                       inode->i_op = &v9fs_symlink_inode_operations;
-                       break;
                default:
                        dprintk(DEBUG_ERROR, "BAD mode 0x%x S_IFMT 0x%x\n",
                                mode, mode & S_IFMT);
@@ -291,7 +307,7 @@ v9fs_create(struct inode *dir,
        struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
        struct super_block *sb = dir->i_sb;
        struct v9fs_fid *dirfid =
-           v9fs_fid_lookup(file_dentry->d_parent, FID_WALK);
+           v9fs_fid_lookup(file_dentry->d_parent);
        struct v9fs_fid *fid = NULL;
        struct inode *file_inode = NULL;
        struct v9fs_fcall *fcall = NULL;
@@ -301,6 +317,7 @@ v9fs_create(struct inode *dir,
        long newfid = -1;
        int result = 0;
        unsigned int iounit = 0;
+       int wfidno = -1;
 
        perm = unixmode2p9mode(v9ses, perm);
 
@@ -334,7 +351,7 @@ v9fs_create(struct inode *dir,
        if (result < 0) {
                dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall));
                v9fs_put_idpool(newfid, &v9ses->fidpool);
-               newfid = 0;
+               newfid = -1;
                goto CleanUpFid;
        }
 
@@ -353,20 +370,39 @@ v9fs_create(struct inode *dir,
        qid = fcall->params.rcreate.qid;
        kfree(fcall);
 
-       fid = v9fs_fid_create(file_dentry);
+       fid = v9fs_fid_create(file_dentry, v9ses, newfid, 1);
+       dprintk(DEBUG_VFS, "fid %p %d\n", fid, fid->fidcreate);
        if (!fid) {
                result = -ENOMEM;
                goto CleanUpFid;
        }
 
-       fid->fid = newfid;
-       fid->fidopen = 0;
-       fid->fidcreate = 1;
        fid->qid = qid;
        fid->iounit = iounit;
-       fid->rdir_pos = 0;
-       fid->rdir_fcall = NULL;
-       fid->v9ses = v9ses;
+
+       /* walk to the newly created file and put the fid in the dentry */
+       wfidno = v9fs_get_idpool(&v9ses->fidpool);
+       if (newfid < 0) {
+               eprintk(KERN_WARNING, "no free fids available\n");
+               return -ENOSPC;
+       }
+
+       result = v9fs_t_walk(v9ses, dirfidnum, wfidno,
+               (char *) file_dentry->d_name.name, NULL);
+       if (result < 0) {
+               dprintk(DEBUG_ERROR, "clone error: %s\n", FCALL_ERROR(fcall));
+               v9fs_put_idpool(wfidno, &v9ses->fidpool);
+               wfidno = -1;
+               goto CleanUpFid;
+       }
+
+       if (!v9fs_fid_create(file_dentry, v9ses, wfidno, 0)) {
+               if (!v9fs_t_clunk(v9ses, newfid, &fcall)) {
+                       v9fs_put_idpool(wfidno, &v9ses->fidpool);
+               }
+
+               goto CleanUpFid;
+       }
 
        if ((perm & V9FS_DMSYMLINK) || (perm & V9FS_DMLINK) ||
            (perm & V9FS_DMNAMEDPIPE) || (perm & V9FS_DMSOCKET) ||
@@ -394,11 +430,11 @@ v9fs_create(struct inode *dir,
        d_instantiate(file_dentry, file_inode);
 
        if (perm & V9FS_DMDIR) {
-               if (v9fs_t_clunk(v9ses, newfid, &fcall))
+               if (!v9fs_t_clunk(v9ses, newfid, &fcall))
+                       v9fs_put_idpool(newfid, &v9ses->fidpool);
+               else
                        dprintk(DEBUG_ERROR, "clunk for mkdir failed: %s\n",
                                FCALL_ERROR(fcall));
-
-               v9fs_put_idpool(newfid, &v9ses->fidpool);
                kfree(fcall);
                fid->fidopen = 0;
                fid->fidcreate = 0;
@@ -410,12 +446,22 @@ v9fs_create(struct inode *dir,
       CleanUpFid:
        kfree(fcall);
 
-       if (newfid) {
-               if (v9fs_t_clunk(v9ses, newfid, &fcall))
+       if (newfid >= 0) {
+               if (!v9fs_t_clunk(v9ses, newfid, &fcall))
+                       v9fs_put_idpool(newfid, &v9ses->fidpool);
+               else
+                       dprintk(DEBUG_ERROR, "clunk failed: %s\n",
+                               FCALL_ERROR(fcall));
+
+               kfree(fcall);
+       }
+       if (wfidno >= 0) {
+               if (!v9fs_t_clunk(v9ses, wfidno, &fcall))
+                       v9fs_put_idpool(wfidno, &v9ses->fidpool);
+               else
                        dprintk(DEBUG_ERROR, "clunk failed: %s\n",
                                FCALL_ERROR(fcall));
 
-               v9fs_put_idpool(newfid, &v9ses->fidpool);
                kfree(fcall);
        }
        return result;
@@ -445,7 +491,7 @@ static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
        file_inode = file->d_inode;
        sb = file_inode->i_sb;
        v9ses = v9fs_inode2v9ses(file_inode);
-       v9fid = v9fs_fid_lookup(file, FID_OP);
+       v9fid = v9fs_fid_lookup(file);
 
        if (!v9fid) {
                dprintk(DEBUG_ERROR,
@@ -529,7 +575,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
 
        sb = dir->i_sb;
        v9ses = v9fs_inode2v9ses(dir);
-       dirfid = v9fs_fid_lookup(dentry->d_parent, FID_WALK);
+       dirfid = v9fs_fid_lookup(dentry->d_parent);
 
        if (!dirfid) {
                dprintk(DEBUG_ERROR, "no dirfid\n");
@@ -557,7 +603,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
                v9fs_put_idpool(newfid, &v9ses->fidpool);
                if (result == -ENOENT) {
                        d_add(dentry, NULL);
-                       dprintk(DEBUG_ERROR,
+                       dprintk(DEBUG_VFS,
                                "Return negative dentry %p count %d\n",
                                dentry, atomic_read(&dentry->d_count));
                        return NULL;
@@ -585,16 +631,13 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
 
        inode->i_ino = v9fs_qid2ino(&fcall->params.rstat.stat->qid);
 
-       fid = v9fs_fid_create(dentry);
+       fid = v9fs_fid_create(dentry, v9ses, newfid, 0);
        if (fid == NULL) {
                dprintk(DEBUG_ERROR, "couldn't insert\n");
                result = -ENOMEM;
                goto FreeFcall;
        }
 
-       fid->fid = newfid;
-       fid->fidopen = 0;
-       fid->v9ses = v9ses;
        fid->qid = fcall->params.rstat.stat->qid;
 
        dentry->d_op = &v9fs_dentry_operations;
@@ -649,11 +692,11 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 {
        struct inode *old_inode = old_dentry->d_inode;
        struct v9fs_session_info *v9ses = v9fs_inode2v9ses(old_inode);
-       struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry, FID_WALK);
+       struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry);
        struct v9fs_fid *olddirfid =
-           v9fs_fid_lookup(old_dentry->d_parent, FID_WALK);
+           v9fs_fid_lookup(old_dentry->d_parent);
        struct v9fs_fid *newdirfid =
-           v9fs_fid_lookup(new_dentry->d_parent, FID_WALK);
+           v9fs_fid_lookup(new_dentry->d_parent);
        struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
        struct v9fs_fcall *fcall = NULL;
        int fid = -1;
@@ -728,7 +771,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 {
        struct v9fs_fcall *fcall = NULL;
        struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
-       struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
+       struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
        int err = -EPERM;
 
        dprintk(DEBUG_VFS, "dentry: %p\n", dentry);
@@ -762,7 +805,7 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
 static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
 {
        struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
-       struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
+       struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
        struct v9fs_fcall *fcall = NULL;
        struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
        int res = -EPERM;
@@ -944,7 +987,7 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
        if (retval != 0)
                goto FreeFcall;
 
-       newfid = v9fs_fid_lookup(dentry, FID_OP);
+       newfid = v9fs_fid_lookup(dentry);
 
        /* issue a twstat */
        v9fs_blank_mistat(v9ses, mistat);
@@ -988,7 +1031,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
 
        struct v9fs_fcall *fcall = NULL;
        struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode);
-       struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP);
+       struct v9fs_fid *fid = v9fs_fid_lookup(dentry);
 
        if (!fid) {
                dprintk(DEBUG_ERROR, "could not resolve fid from dentry\n");
@@ -1047,8 +1090,8 @@ static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
        int ret;
        char *link = __getname();
 
-       if (strlen(link) < buflen)
-               buflen = strlen(link);
+       if (buflen > PATH_MAX)
+               buflen = PATH_MAX;
 
        dprintk(DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_iname, dentry);
 
@@ -1062,7 +1105,7 @@ static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
                }
        }
 
-       putname(link);
+       __putname(link);
        return retval;
 }
 
@@ -1086,7 +1129,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
                len = v9fs_readlink(dentry, link, strlen(link));
 
                if (len < 0) {
-                       putname(link);
+                       __putname(link);
                        link = ERR_PTR(len);
                } else
                        link[len] = 0;
@@ -1109,7 +1152,7 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void
 
        dprintk(DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
        if (!IS_ERR(s))
-               putname(s);
+               __putname(s);
 }
 
 /**
@@ -1132,7 +1175,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
        struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
        struct v9fs_fcall *fcall = NULL;
        struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL);
-       struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry, FID_OP);
+       struct v9fs_fid *oldfid = v9fs_fid_lookup(old_dentry);
        struct v9fs_fid *newfid = NULL;
        char *symname = __getname();
 
@@ -1152,7 +1195,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
        if (retval != 0)
                goto FreeMem;
 
-       newfid = v9fs_fid_lookup(dentry, FID_OP);
+       newfid = v9fs_fid_lookup(dentry);
        if (!newfid) {
                dprintk(DEBUG_ERROR, "couldn't resolve fid from dentry\n");
                goto FreeMem;
@@ -1185,7 +1228,7 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
       FreeMem:
        kfree(mistat);
        kfree(fcall);
-       putname(symname);
+       __putname(symname);
        return retval;
 }
 
@@ -1230,7 +1273,7 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
        if (retval != 0)
                goto FreeMem;
 
-       newfid = v9fs_fid_lookup(dentry, FID_OP);
+       newfid = v9fs_fid_lookup(dentry);
        if (!newfid) {
                dprintk(DEBUG_ERROR, "coudn't resove fid from dentry\n");
                retval = -EINVAL;
@@ -1276,12 +1319,12 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
       FreeMem:
        kfree(mistat);
        kfree(fcall);
-       putname(symname);
+       __putname(symname);
 
        return retval;
 }
 
-static struct inode_operations v9fs_dir_inode_operations = {
+static struct inode_operations v9fs_dir_inode_operations_ext = {
        .create = v9fs_vfs_create,
        .lookup = v9fs_vfs_lookup,
        .symlink = v9fs_vfs_symlink,
@@ -1296,6 +1339,18 @@ static struct inode_operations v9fs_dir_inode_operations = {
        .setattr = v9fs_vfs_setattr,
 };
 
+static struct inode_operations v9fs_dir_inode_operations = {
+       .create = v9fs_vfs_create,
+       .lookup = v9fs_vfs_lookup,
+       .unlink = v9fs_vfs_unlink,
+       .mkdir = v9fs_vfs_mkdir,
+       .rmdir = v9fs_vfs_rmdir,
+       .mknod = v9fs_vfs_mknod,
+       .rename = v9fs_vfs_rename,
+       .getattr = v9fs_vfs_getattr,
+       .setattr = v9fs_vfs_setattr,
+};
+
 static struct inode_operations v9fs_file_inode_operations = {
        .getattr = v9fs_vfs_getattr,
        .setattr = v9fs_vfs_setattr,