[POWERPC] Fix up after irq changes
[powerpc.git] / fs / 9p / vfs_inode.c
index dce729d..5241c60 100644 (file)
@@ -7,9 +7,8 @@
  *  Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  *
  *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ *  it under the terms of the GNU General Public License version 2
+ *  as published by the Free Software Foundation.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -205,7 +204,6 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
                inode->i_mode = mode;
                inode->i_uid = current->fsuid;
                inode->i_gid = current->fsgid;
-               inode->i_blksize = sb->s_blocksize;
                inode->i_blocks = 0;
                inode->i_rdev = 0;
                inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
@@ -235,7 +233,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
                        inode->i_op = &v9fs_symlink_inode_operations;
                        break;
                case S_IFDIR:
-                       inode->i_nlink++;
+                       inc_nlink(inode);
                        if(v9ses->extended)
                                inode->i_op = &v9fs_dir_inode_operations_ext;
                        else
@@ -255,8 +253,8 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
 }
 
 static int
-v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name,
-       u32 perm, u8 mode, u32 *fidp, struct v9fs_qid *qid, u32 *iounit)
+v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name, u32 perm,
+       u8 mode, char *extension, u32 *fidp, struct v9fs_qid *qid, u32 *iounit)
 {
        u32 fid;
        int err;
@@ -265,21 +263,23 @@ v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name,
        fid = v9fs_get_idpool(&v9ses->fidpool);
        if (fid < 0) {
                eprintk(KERN_WARNING, "no free fids available\n");
-               err = -ENOSPC;
-               goto error;
+               return -ENOSPC;
        }
 
        err = v9fs_t_walk(v9ses, pfid, fid, NULL, &fcall);
        if (err < 0) {
                PRINT_FCALL_ERROR("clone error", fcall);
-               goto error;
+               if (fcall && fcall->id == RWALK)
+                       goto clunk_fid;
+               else
+                       goto put_fid;
        }
        kfree(fcall);
 
-       err = v9fs_t_create(v9ses, fid, name, perm, mode, &fcall);
+       err = v9fs_t_create(v9ses, fid, name, perm, mode, extension, &fcall);
        if (err < 0) {
                PRINT_FCALL_ERROR("create fails", fcall);
-               goto error;
+               goto clunk_fid;
        }
 
        if (iounit)
@@ -294,8 +294,12 @@ v9fs_create(struct v9fs_session_info *v9ses, u32 pfid, char *name,
        kfree(fcall);
        return 0;
 
-error:
-       if (fid >= 0)
+clunk_fid:
+       v9fs_t_clunk(v9ses, fid);
+       fid = V9FS_NOFID;
+
+put_fid:
+       if (fid != V9FS_NOFID)
                v9fs_put_idpool(fid, &v9ses->fidpool);
 
        kfree(fcall);
@@ -313,14 +317,16 @@ v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
        nfid = v9fs_get_idpool(&v9ses->fidpool);
        if (nfid < 0) {
                eprintk(KERN_WARNING, "no free fids available\n");
-               err = -ENOSPC;
-               goto error;
+               return ERR_PTR(-ENOSPC);
        }
 
        err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
                &fcall);
 
        if (err < 0) {
+               if (fcall && fcall->id == RWALK)
+                       goto clunk_fid;
+
                PRINT_FCALL_ERROR("walk error", fcall);
                v9fs_put_idpool(nfid, &v9ses->fidpool);
                goto error;
@@ -350,7 +356,7 @@ error:
        return ERR_PTR(err);
 }
 
-struct inode *
+static struct inode *
 v9fs_inode_from_fid(struct v9fs_session_info *v9ses, u32 fid,
        struct super_block *sb)
 {
@@ -427,11 +433,11 @@ static int v9fs_remove(struct inode *dir, struct dentry *file, int rmdir)
        result = v9fs_t_remove(v9ses, fid, &fcall);
        if (result < 0) {
                PRINT_FCALL_ERROR("remove fails", fcall);
-       } else {
-               v9fs_put_idpool(fid, &v9ses->fidpool);
-               v9fs_fid_destroy(v9fid);
        }
 
+       v9fs_put_idpool(fid, &v9ses->fidpool);
+       v9fs_fid_destroy(v9fid);
+
        kfree(fcall);
        return result;
 }
@@ -476,7 +482,7 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, int mode,
                flags = O_RDWR;
 
        err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
-               perm, v9fs_uflags2omode(flags), &fid, &qid, &iounit);
+               perm, v9fs_uflags2omode(flags), NULL, &fid, &qid, &iounit);
 
        if (err)
                goto error;
@@ -523,9 +529,6 @@ error:
        if (vfid)
                v9fs_fid_destroy(vfid);
 
-       if (inode)
-               iput(inode);
-
        return err;
 }
 
@@ -552,7 +555,7 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        perm = unixmode2p9mode(v9ses, mode | S_IFDIR);
 
        err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
-               perm, V9FS_OREAD, &fid, NULL, NULL);
+               perm, V9FS_OREAD, NULL, &fid, NULL, NULL);
 
        if (err) {
                dprintk(DEBUG_ERROR, "create error %d\n", err);
@@ -612,10 +615,11 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
        int result = 0;
 
        dprintk(DEBUG_VFS, "dir: %p dentry: (%s) %p nameidata: %p\n",
-               dir, dentry->d_iname, dentry, nameidata);
+               dir, dentry->d_name.name, dentry, nameidata);
 
        sb = dir->i_sb;
        v9ses = v9fs_inode2v9ses(dir);
+       dentry->d_op = &v9fs_dentry_operations;
        dirfid = v9fs_fid_lookup(dentry->d_parent);
 
        if (!dirfid) {
@@ -638,19 +642,26 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
        }
 
        result = v9fs_t_walk(v9ses, dirfidnum, newfid,
-               (char *)dentry->d_name.name, NULL);
+               (char *)dentry->d_name.name, &fcall);
+
        if (result < 0) {
-               v9fs_put_idpool(newfid, &v9ses->fidpool);
+               if (fcall && fcall->id == RWALK)
+                       v9fs_t_clunk(v9ses, newfid);
+               else
+                       v9fs_put_idpool(newfid, &v9ses->fidpool);
+
                if (result == -ENOENT) {
                        d_add(dentry, NULL);
                        dprintk(DEBUG_VFS,
                                "Return negative dentry %p count %d\n",
                                dentry, atomic_read(&dentry->d_count));
+                       kfree(fcall);
                        return NULL;
                }
                dprintk(DEBUG_ERROR, "walk error:%d\n", result);
                goto FreeFcall;
        }
+       kfree(fcall);
 
        result = v9fs_t_stat(v9ses, newfid, &fcall);
        if (result < 0) {
@@ -683,8 +694,6 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
                goto FreeFcall;
 
        fid->qid = fcall->params.rstat.stat.qid;
-
-       dentry->d_op = &v9fs_dentry_operations;
        v9fs_stat2inode(&fcall->params.rstat.stat, inode, inode->i_sb);
 
        d_add(dentry, inode);
@@ -940,9 +949,8 @@ v9fs_stat2inode(struct v9fs_stat *stat, struct inode *inode,
 
        inode->i_size = stat->length;
 
-       inode->i_blksize = sb->s_blocksize;
        inode->i_blocks =
-           (inode->i_size + inode->i_blksize - 1) >> sb->s_blocksize_bits;
+           (inode->i_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
 }
 
 /**
@@ -1011,11 +1019,13 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
 
        /* copy extension buffer into buffer */
        if (fcall->params.rstat.stat.extension.len < buflen)
-               buflen = fcall->params.rstat.stat.extension.len;
+               buflen = fcall->params.rstat.stat.extension.len + 1;
 
-       memcpy(buffer, fcall->params.rstat.stat.extension.str, buflen - 1);
+       memmove(buffer, fcall->params.rstat.stat.extension.str, buflen - 1);
        buffer[buflen-1] = 0;
 
+       dprintk(DEBUG_ERROR, "%s -> %.*s (%s)\n", dentry->d_name.name, fcall->params.rstat.stat.extension.len,
+               fcall->params.rstat.stat.extension.str, buffer);
        retval = buflen;
 
       FreeFcall:
@@ -1039,6 +1049,9 @@ static int v9fs_vfs_readlink(struct dentry *dentry, char __user * buffer,
        int ret;
        char *link = __getname();
 
+       if (unlikely(!link))
+               return -ENOMEM;
+
        if (buflen > PATH_MAX)
                buflen = PATH_MAX;
 
@@ -1075,7 +1088,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
        if (!link)
                link = ERR_PTR(-ENOMEM);
        else {
-               len = v9fs_readlink(dentry, link, strlen(link));
+               len = v9fs_readlink(dentry, link, PATH_MAX);
 
                if (len < 0) {
                        __putname(link);
@@ -1112,10 +1125,7 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
        struct v9fs_session_info *v9ses;
        struct v9fs_fid *dfid, *vfid;
        struct inode *inode;
-       struct v9fs_fcall *fcall;
-       struct v9fs_wstat wstat;
 
-       fcall = NULL;
        inode = NULL;
        vfid = NULL;
        v9ses = v9fs_inode2v9ses(dir);
@@ -1128,7 +1138,7 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
        }
 
        err = v9fs_create(v9ses, dfid->fid, (char *) dentry->d_name.name,
-               perm, V9FS_OREAD, &fid, NULL, NULL);
+               perm, V9FS_OREAD, (char *) extension, &fid, NULL, NULL);
 
        if (err)
                goto error;
@@ -1151,29 +1161,14 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
                goto error;
        }
 
-       /* issue a Twstat */
-       v9fs_blank_wstat(&wstat);
-       wstat.muid = v9ses->name;
-       wstat.extension = (char *) extension;
-       err = v9fs_t_wstat(v9ses, vfid->fid, &wstat, &fcall);
-       if (err < 0) {
-               PRINT_FCALL_ERROR("wstat error", fcall);
-               goto error;
-       }
-
-       kfree(fcall);
        dentry->d_op = &v9fs_dentry_operations;
        d_instantiate(dentry, inode);
        return 0;
 
 error:
-       kfree(fcall);
        if (vfid)
                v9fs_fid_destroy(vfid);
 
-       if (inode)
-               iput(inode);
-
        return err;
 
 }
@@ -1227,7 +1222,10 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,
        }
 
        name = __getname();
-       sprintf(name, "hardlink(%d)\n", oldfid->fid);
+       if (unlikely(!name))
+               return -ENOMEM;
+
+       sprintf(name, "%d\n", oldfid->fid);
        retval = v9fs_vfs_mkspecial(dir, dentry, V9FS_DMLINK, name);
        __putname(name);
 
@@ -1256,6 +1254,8 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
                return -EINVAL;
 
        name = __getname();
+       if (!name)
+               return -ENOMEM;
        /* build extension */
        if (S_ISBLK(mode))
                sprintf(name, "b %u %u", MAJOR(rdev), MINOR(rdev));