Merge ../linux-2.6
[safe/jmp/linux-2.6] / fs / jfs / namei.c
index 49ccde3..09ea03f 100644 (file)
@@ -39,6 +39,24 @@ struct dentry_operations jfs_ci_dentry_operations;
 static s64 commitZeroLink(tid_t, struct inode *);
 
 /*
+ * NAME:       free_ea_wmap(inode)
+ *
+ * FUNCTION:   free uncommitted extended attributes from working map 
+ *
+ */
+static inline void free_ea_wmap(struct inode *inode)
+{
+       dxd_t *ea = &JFS_IP(inode)->ea;
+
+       if (ea->flag & DXD_EXTENT) {
+               /* free EA pages from cache */
+               invalidate_dxd_metapages(inode, *ea);
+               dbFree(inode, addressDXD(ea), lengthDXD(ea));
+       }
+       ea->flag = 0;
+}
+
+/*
  * NAME:       jfs_create(dip, dentry, mode)
  *
  * FUNCTION:   create a regular file in the parent directory <dip>
@@ -86,11 +104,22 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock(&JFS_IP(dip)->commit_mutex);
+       mutex_lock(&JFS_IP(ip)->commit_mutex);
+
+       rc = jfs_init_acl(tid, ip, dip);
+       if (rc)
+               goto out3;
+
+       rc = jfs_init_security(tid, ip, dip);
+       if (rc) {
+               txAbort(tid, 0);
+               goto out3;
+       }
 
        if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) {
                jfs_err("jfs_create: dtSearch returned %d", rc);
+               txAbort(tid, 0);
                goto out3;
        }
 
@@ -136,9 +165,10 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
 
       out3:
        txEnd(tid);
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
        if (rc) {
+               free_ea_wmap(ip);
                ip->i_nlink = 0;
                iput(ip);
        } else
@@ -147,11 +177,6 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, int mode,
       out2:
        free_UCSname(&dname);
 
-#ifdef CONFIG_JFS_POSIX_ACL
-       if (rc == 0)
-               jfs_init_acl(ip, dip);
-#endif
-
       out1:
 
        jfs_info("jfs_create: rc:%d", rc);
@@ -213,11 +238,22 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock(&JFS_IP(dip)->commit_mutex);
+       mutex_lock(&JFS_IP(ip)->commit_mutex);
+
+       rc = jfs_init_acl(tid, ip, dip);
+       if (rc)
+               goto out3;
+
+       rc = jfs_init_security(tid, ip, dip);
+       if (rc) {
+               txAbort(tid, 0);
+               goto out3;
+       }
 
        if ((rc = dtSearch(dip, &dname, &ino, &btstack, JFS_CREATE))) {
                jfs_err("jfs_mkdir: dtSearch returned %d", rc);
+               txAbort(tid, 0);
                goto out3;
        }
 
@@ -264,9 +300,10 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
 
       out3:
        txEnd(tid);
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
        if (rc) {
+               free_ea_wmap(ip);
                ip->i_nlink = 0;
                iput(ip);
        } else
@@ -275,10 +312,6 @@ static int jfs_mkdir(struct inode *dip, struct dentry *dentry, int mode)
       out2:
        free_UCSname(&dname);
 
-#ifdef CONFIG_JFS_POSIX_ACL
-       if (rc == 0)
-               jfs_init_acl(ip, dip);
-#endif
 
       out1:
 
@@ -332,8 +365,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock(&JFS_IP(dip)->commit_mutex);
+       mutex_lock(&JFS_IP(ip)->commit_mutex);
 
        iplist[0] = dip;
        iplist[1] = ip;
@@ -351,8 +384,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
                if (rc == -EIO)
                        txAbort(tid, 1);
                txEnd(tid);
-               up(&JFS_IP(dip)->commit_sem);
-               up(&JFS_IP(ip)->commit_sem);
+               mutex_unlock(&JFS_IP(dip)->commit_mutex);
+               mutex_unlock(&JFS_IP(ip)->commit_mutex);
 
                goto out2;
        }
@@ -389,8 +422,8 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
 
        txEnd(tid);
 
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
 
        /*
         * Truncating the directory index table is not guaranteed.  It
@@ -455,8 +488,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock(&JFS_IP(dip)->commit_mutex);
+       mutex_lock(&JFS_IP(ip)->commit_mutex);
 
        iplist[0] = dip;
        iplist[1] = ip;
@@ -470,8 +503,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
                if (rc == -EIO)
                        txAbort(tid, 1);        /* Marks FS Dirty */
                txEnd(tid);
-               up(&JFS_IP(dip)->commit_sem);
-               up(&JFS_IP(ip)->commit_sem);
+               mutex_unlock(&JFS_IP(dip)->commit_mutex);
+               mutex_unlock(&JFS_IP(ip)->commit_mutex);
                IWRITE_UNLOCK(ip);
                goto out1;
        }
@@ -494,8 +527,8 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
                if ((new_size = commitZeroLink(tid, ip)) < 0) {
                        txAbort(tid, 1);        /* Marks FS Dirty */
                        txEnd(tid);
-                       up(&JFS_IP(dip)->commit_sem);
-                       up(&JFS_IP(ip)->commit_sem);
+                       mutex_unlock(&JFS_IP(dip)->commit_mutex);
+                       mutex_unlock(&JFS_IP(ip)->commit_mutex);
                        IWRITE_UNLOCK(ip);
                        rc = new_size;
                        goto out1;
@@ -523,13 +556,13 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
 
        txEnd(tid);
 
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
 
 
        while (new_size && (rc == 0)) {
                tid = txBegin(dip->i_sb, 0);
-               down(&JFS_IP(ip)->commit_sem);
+               mutex_lock(&JFS_IP(ip)->commit_mutex);
                new_size = xtTruncate_pmap(tid, ip, new_size);
                if (new_size < 0) {
                        txAbort(tid, 1);        /* Marks FS Dirty */
@@ -537,7 +570,7 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
                } else
                        rc = txCommit(tid, 2, &iplist[0], COMMIT_SYNC);
                txEnd(tid);
-               up(&JFS_IP(ip)->commit_sem);
+               mutex_unlock(&JFS_IP(ip)->commit_mutex);
        }
 
        if (ip->i_nlink == 0)
@@ -772,8 +805,8 @@ static int jfs_link(struct dentry *old_dentry,
 
        tid = txBegin(ip->i_sb, 0);
 
-       down(&JFS_IP(dir)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock(&JFS_IP(dir)->commit_mutex);
+       mutex_lock(&JFS_IP(ip)->commit_mutex);
 
        /*
         * scan parent directory for entry/freespace
@@ -794,6 +827,7 @@ static int jfs_link(struct dentry *old_dentry,
        /* update object inode */
        ip->i_nlink++;          /* for new link */
        ip->i_ctime = CURRENT_TIME;
+       dir->i_ctime = dir->i_mtime = CURRENT_TIME;
        mark_inode_dirty(dir);
        atomic_inc(&ip->i_count);
 
@@ -813,8 +847,8 @@ static int jfs_link(struct dentry *old_dentry,
       out:
        txEnd(tid);
 
-       up(&JFS_IP(dir)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(dir)->commit_mutex);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
 
        jfs_info("jfs_link: rc:%d", rc);
        return rc;
@@ -882,8 +916,12 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
 
        tid = txBegin(dip->i_sb, 0);
 
-       down(&JFS_IP(dip)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock(&JFS_IP(dip)->commit_mutex);
+       mutex_lock(&JFS_IP(ip)->commit_mutex);
+
+       rc = jfs_init_security(tid, ip, dip);
+       if (rc)
+               goto out3;
 
        tblk = tid_to_tblock(tid);
        tblk->xflag |= COMMIT_CREATE;
@@ -987,6 +1025,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
        insert_inode_hash(ip);
        mark_inode_dirty(ip);
 
+       dip->i_ctime = dip->i_mtime = CURRENT_TIME;
+       mark_inode_dirty(dip);
        /*
         * commit update of parent directory and link object
         */
@@ -997,9 +1037,10 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
 
       out3:
        txEnd(tid);
-       up(&JFS_IP(dip)->commit_sem);
-       up(&JFS_IP(ip)->commit_sem);
+       mutex_unlock(&JFS_IP(dip)->commit_mutex);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
        if (rc) {
+               free_ea_wmap(ip);
                ip->i_nlink = 0;
                iput(ip);
        } else
@@ -1008,11 +1049,6 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
       out2:
        free_UCSname(&dname);
 
-#ifdef CONFIG_JFS_POSIX_ACL
-       if (rc == 0)
-               jfs_init_acl(ip, dip);
-#endif
-
       out1:
        jfs_info("jfs_symlink: rc:%d", rc);
        return rc;
@@ -1105,13 +1141,13 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
         */
        tid = txBegin(new_dir->i_sb, 0);
 
-       down(&JFS_IP(new_dir)->commit_sem);
-       down(&JFS_IP(old_ip)->commit_sem);
+       mutex_lock(&JFS_IP(new_dir)->commit_mutex);
+       mutex_lock(&JFS_IP(old_ip)->commit_mutex);
        if (old_dir != new_dir)
-               down(&JFS_IP(old_dir)->commit_sem);
+               mutex_lock(&JFS_IP(old_dir)->commit_mutex);
 
        if (new_ip) {
-               down(&JFS_IP(new_ip)->commit_sem);
+               mutex_lock(&JFS_IP(new_ip)->commit_mutex);
                /*
                 * Change existing directory entry to new inode number
                 */
@@ -1124,10 +1160,10 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                if (S_ISDIR(new_ip->i_mode)) {
                        new_ip->i_nlink--;
                        if (new_ip->i_nlink) {
-                               up(&JFS_IP(new_dir)->commit_sem);
-                               up(&JFS_IP(old_ip)->commit_sem);
+                               mutex_unlock(&JFS_IP(new_dir)->commit_mutex);
+                               mutex_unlock(&JFS_IP(old_ip)->commit_mutex);
                                if (old_dir != new_dir)
-                                       up(&JFS_IP(old_dir)->commit_sem);
+                                       mutex_unlock(&JFS_IP(old_dir)->commit_mutex);
                                if (!S_ISDIR(old_ip->i_mode) && new_ip)
                                        IWRITE_UNLOCK(new_ip);
                                jfs_error(new_ip->i_sb,
@@ -1246,16 +1282,16 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
       out4:
        txEnd(tid);
 
-       up(&JFS_IP(new_dir)->commit_sem);
-       up(&JFS_IP(old_ip)->commit_sem);
+       mutex_unlock(&JFS_IP(new_dir)->commit_mutex);
+       mutex_unlock(&JFS_IP(old_ip)->commit_mutex);
        if (old_dir != new_dir)
-               up(&JFS_IP(old_dir)->commit_sem);
+               mutex_unlock(&JFS_IP(old_dir)->commit_mutex);
        if (new_ip)
-               up(&JFS_IP(new_ip)->commit_sem);
+               mutex_unlock(&JFS_IP(new_ip)->commit_mutex);
 
        while (new_size && (rc == 0)) {
                tid = txBegin(new_ip->i_sb, 0);
-               down(&JFS_IP(new_ip)->commit_sem);
+               mutex_lock(&JFS_IP(new_ip)->commit_mutex);
                new_size = xtTruncate_pmap(tid, new_ip, new_size);
                if (new_size < 0) {
                        txAbort(tid, 1);
@@ -1263,7 +1299,7 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                } else
                        rc = txCommit(tid, 1, &new_ip, COMMIT_SYNC);
                txEnd(tid);
-               up(&JFS_IP(new_ip)->commit_sem);
+               mutex_unlock(&JFS_IP(new_ip)->commit_mutex);
        }
        if (new_ip && (new_ip->i_nlink == 0))
                set_cflag(COMMIT_Nolink, new_ip);
@@ -1325,20 +1361,34 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
 
        tid = txBegin(dir->i_sb, 0);
 
-       down(&JFS_IP(dir)->commit_sem);
-       down(&JFS_IP(ip)->commit_sem);
+       mutex_lock(&JFS_IP(dir)->commit_mutex);
+       mutex_lock(&JFS_IP(ip)->commit_mutex);
 
-       if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE)))
+       rc = jfs_init_acl(tid, ip, dir);
+       if (rc)
                goto out3;
 
+       rc = jfs_init_security(tid, ip, dir);
+       if (rc) {
+               txAbort(tid, 0);
+               goto out3;
+       }
+
+       if ((rc = dtSearch(dir, &dname, &ino, &btstack, JFS_CREATE))) {
+               txAbort(tid, 0);
+               goto out3;
+       }
+
        tblk = tid_to_tblock(tid);
        tblk->xflag |= COMMIT_CREATE;
        tblk->ino = ip->i_ino;
        tblk->u.ixpxd = JFS_IP(ip)->ixpxd;
 
        ino = ip->i_ino;
-       if ((rc = dtInsert(tid, dir, &dname, &ino, &btstack)))
+       if ((rc = dtInsert(tid, dir, &dname, &ino, &btstack))) {
+               txAbort(tid, 0);
                goto out3;
+       }
 
        ip->i_op = &jfs_file_inode_operations;
        jfs_ip->dev = new_encode_dev(rdev);
@@ -1357,9 +1407,10 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
 
       out3:
        txEnd(tid);
-       up(&JFS_IP(ip)->commit_sem);
-       up(&JFS_IP(dir)->commit_sem);
+       mutex_unlock(&JFS_IP(ip)->commit_mutex);
+       mutex_unlock(&JFS_IP(dir)->commit_mutex);
        if (rc) {
+               free_ea_wmap(ip);
                ip->i_nlink = 0;
                iput(ip);
        } else
@@ -1368,11 +1419,6 @@ static int jfs_mknod(struct inode *dir, struct dentry *dentry,
       out1:
        free_UCSname(&dname);
 
-#ifdef CONFIG_JFS_POSIX_ACL
-       if (rc == 0)
-               jfs_init_acl(ip, dir);
-#endif
-
       out:
        jfs_info("jfs_mknod: returning %d", rc);
        return rc;
@@ -1473,10 +1519,11 @@ struct inode_operations jfs_dir_inode_operations = {
 #endif
 };
 
-struct file_operations jfs_dir_operations = {
+const struct file_operations jfs_dir_operations = {
        .read           = generic_read_dir,
        .readdir        = jfs_readdir,
        .fsync          = jfs_fsync,
+       .ioctl          = jfs_ioctl,
 };
 
 static int jfs_ci_hash(struct dentry *dir, struct qstr *this)