nfsd4: nfsd4_destroy_session must set callback client under the state lock
[safe/jmp/linux-2.6] / fs / jfs / super.c
index 929fcec..157382f 100644 (file)
 #include <linux/parser.h>
 #include <linux/completion.h>
 #include <linux/vfs.h>
+#include <linux/quotaops.h>
 #include <linux/mount.h>
 #include <linux/moduleparam.h>
 #include <linux/kthread.h>
 #include <linux/posix_acl.h>
 #include <linux/buffer_head.h>
 #include <linux/exportfs.h>
+#include <linux/crc32.h>
+#include <linux/slab.h>
 #include <asm/uaccess.h>
 #include <linux/seq_file.h>
+#include <linux/smp_lock.h>
 
 #include "jfs_incore.h"
 #include "jfs_filsys.h"
@@ -48,7 +52,7 @@ MODULE_LICENSE("GPL");
 static struct kmem_cache * jfs_inode_cachep;
 
 static const struct super_operations jfs_super_operations;
-static struct export_operations jfs_export_operations;
+static const struct export_operations jfs_export_operations;
 static struct file_system_type jfs_fs_type;
 
 #define MAX_COMMIT_THREADS 64
@@ -125,21 +129,14 @@ static void jfs_destroy_inode(struct inode *inode)
                ji->active_ag = -1;
        }
        spin_unlock_irq(&ji->ag_lock);
-
-#ifdef CONFIG_JFS_POSIX_ACL
-       if (ji->i_acl != JFS_ACL_NOT_CACHED) {
-               posix_acl_release(ji->i_acl);
-               ji->i_acl = JFS_ACL_NOT_CACHED;
-       }
-       if (ji->i_default_acl != JFS_ACL_NOT_CACHED) {
-               posix_acl_release(ji->i_default_acl);
-               ji->i_default_acl = JFS_ACL_NOT_CACHED;
-       }
-#endif
-
        kmem_cache_free(jfs_inode_cachep, ji);
 }
 
+static void jfs_clear_inode(struct inode *inode)
+{
+       dquot_drop(inode);
+}
+
 static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
        struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb);
@@ -167,6 +164,9 @@ static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        buf->f_files = maxinodes;
        buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) -
                                    atomic_read(&imap->im_numfree));
+       buf->f_fsid.val[0] = (u32)crc32_le(0, sbi->uuid, sizeof(sbi->uuid)/2);
+       buf->f_fsid.val[1] = (u32)crc32_le(0, sbi->uuid + sizeof(sbi->uuid)/2,
+                                       sizeof(sbi->uuid)/2);
 
        buf->f_namelen = JFS_NAME_MAX;
        return 0;
@@ -178,18 +178,21 @@ static void jfs_put_super(struct super_block *sb)
        int rc;
 
        jfs_info("In jfs_put_super");
+
+       lock_kernel();
+
        rc = jfs_umount(sb);
        if (rc)
                jfs_err("jfs_umount failed with return code %d", rc);
-       if (sbi->nls_tab)
-               unload_nls(sbi->nls_tab);
-       sbi->nls_tab = NULL;
+
+       unload_nls(sbi->nls_tab);
 
        truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
        iput(sbi->direct_inode);
-       sbi->direct_inode = NULL;
 
        kfree(sbi);
+
+       unlock_kernel();
 }
 
 enum {
@@ -198,7 +201,7 @@ enum {
        Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
 };
 
-static match_table_t tokens = {
+static const match_table_t tokens = {
        {Opt_integrity, "integrity"},
        {Opt_nointegrity, "nointegrity"},
        {Opt_iocharset, "iocharset=%s"},
@@ -348,8 +351,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
 
        if (nls_map != (void *) -1) {
                /* Discard old (if remount) */
-               if (sbi->nls_tab)
-                       unload_nls(sbi->nls_tab);
+               unload_nls(sbi->nls_tab);
                sbi->nls_tab = nls_map;
        }
        return 1;
@@ -365,19 +367,24 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data)
        s64 newLVSize = 0;
        int rc = 0;
        int flag = JFS_SBI(sb)->flag;
+       int ret;
 
        if (!parse_options(data, sb, &newLVSize, &flag)) {
                return -EINVAL;
        }
+       lock_kernel();
        if (newLVSize) {
                if (sb->s_flags & MS_RDONLY) {
                        printk(KERN_ERR
                  "JFS: resize requires volume to be mounted read-write\n");
+                       unlock_kernel();
                        return -EROFS;
                }
                rc = jfs_extendfs(sb, newLVSize, 0);
-               if (rc)
+               if (rc) {
+                       unlock_kernel();
                        return rc;
+               }
        }
 
        if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) {
@@ -388,23 +395,31 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data)
                truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0);
 
                JFS_SBI(sb)->flag = flag;
-               return jfs_mount_rw(sb, 1);
+               ret = jfs_mount_rw(sb, 1);
+               unlock_kernel();
+               return ret;
        }
        if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) {
                rc = jfs_umount_rw(sb);
                JFS_SBI(sb)->flag = flag;
+               unlock_kernel();
                return rc;
        }
        if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
                if (!(sb->s_flags & MS_RDONLY)) {
                        rc = jfs_umount_rw(sb);
-                       if (rc)
+                       if (rc) {
+                               unlock_kernel();
                                return rc;
+                       }
                        JFS_SBI(sb)->flag = flag;
-                       return jfs_mount_rw(sb, 1);
+                       ret = jfs_mount_rw(sb, 1);
+                       unlock_kernel();
+                       return ret;
                }
        JFS_SBI(sb)->flag = flag;
 
+       unlock_kernel();
        return 0;
 }
 
@@ -414,7 +429,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
        struct inode *inode;
        int rc;
        s64 newLVSize = 0;
-       int flag;
+       int flag, ret = -EINVAL;
 
        jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
 
@@ -461,8 +476,10 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
         * Initialize direct-mapping inode/address-space
         */
        inode = new_inode(sb);
-       if (inode == NULL)
+       if (inode == NULL) {
+               ret = -ENOMEM;
                goto out_kfree;
+       }
        inode->i_ino = 0;
        inode->i_nlink = 1;
        inode->i_size = sb->s_bdev->bd_inode->i_size;
@@ -494,9 +511,11 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
 
        sb->s_magic = JFS_SUPER_MAGIC;
 
-       inode = iget(sb, ROOT_I);
-       if (!inode || is_bad_inode(inode))
-               goto out_no_root;
+       inode = jfs_iget(sb, ROOT_I);
+       if (IS_ERR(inode)) {
+               ret = PTR_ERR(inode);
+               goto out_no_rw;
+       }
        sb->s_root = d_alloc_root(inode);
        if (!sb->s_root)
                goto out_no_root;
@@ -511,15 +530,14 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
         * Page cache is indexed by long.
         * I would use MAX_LFS_FILESIZE, but it's only half as big
         */
-       sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, sb->s_maxbytes);
+       sb->s_maxbytes = min(((u64) PAGE_CACHE_SIZE << 32) - 1, (u64)sb->s_maxbytes);
 #endif
        sb->s_time_gran = 1;
        return 0;
 
 out_no_root:
-       jfs_err("jfs_read_super: get root inode failed");
-       if (inode)
-               iput(inode);
+       jfs_err("jfs_read_super: get root dentry failed");
+       iput(inode);
 
 out_no_rw:
        rc = jfs_umount(sb);
@@ -536,10 +554,10 @@ out_kfree:
        if (sbi->nls_tab)
                unload_nls(sbi->nls_tab);
        kfree(sbi);
-       return -EINVAL;
+       return ret;
 }
 
-static void jfs_write_super_lockfs(struct super_block *sb)
+static int jfs_freeze(struct super_block *sb)
 {
        struct jfs_sb_info *sbi = JFS_SBI(sb);
        struct jfs_log *log = sbi->log;
@@ -549,9 +567,10 @@ static void jfs_write_super_lockfs(struct super_block *sb)
                lmLogShutdown(log);
                updateSuper(sb, FM_CLEAN);
        }
+       return 0;
 }
 
-static void jfs_unlockfs(struct super_block *sb)
+static int jfs_unfreeze(struct super_block *sb)
 {
        struct jfs_sb_info *sbi = JFS_SBI(sb);
        struct jfs_log *log = sbi->log;
@@ -564,6 +583,7 @@ static void jfs_unlockfs(struct super_block *sb)
                else
                        txResume(sb);
        }
+       return 0;
 }
 
 static int jfs_get_sb(struct file_system_type *fs_type,
@@ -598,6 +618,12 @@ static int jfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
                seq_printf(seq, ",umask=%03o", sbi->umask);
        if (sbi->flag & JFS_NOINTEGRITY)
                seq_puts(seq, ",nointegrity");
+       if (sbi->nls_tab)
+               seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset);
+       if (sbi->flag & JFS_ERR_CONTINUE)
+               seq_printf(seq, ",errors=continue");
+       if (sbi->flag & JFS_ERR_PANIC)
+               seq_printf(seq, ",errors=panic");
 
 #ifdef CONFIG_QUOTA
        if (sbi->flag & JFS_USRQUOTA)
@@ -704,8 +730,10 @@ static ssize_t jfs_quota_write(struct super_block *sb, int type,
                blk++;
        }
 out:
-       if (len == towrite)
+       if (len == towrite) {
+               mutex_unlock(&inode->i_mutex);
                return err;
+       }
        if (inode->i_size < off+len-towrite)
                i_size_write(inode, off+len-towrite);
        inode->i_version++;
@@ -720,14 +748,14 @@ out:
 static const struct super_operations jfs_super_operations = {
        .alloc_inode    = jfs_alloc_inode,
        .destroy_inode  = jfs_destroy_inode,
-       .read_inode     = jfs_read_inode,
        .dirty_inode    = jfs_dirty_inode,
        .write_inode    = jfs_write_inode,
        .delete_inode   = jfs_delete_inode,
+       .clear_inode    = jfs_clear_inode,
        .put_super      = jfs_put_super,
        .sync_fs        = jfs_sync_fs,
-       .write_super_lockfs = jfs_write_super_lockfs,
-       .unlockfs       = jfs_unlockfs,
+       .freeze_fs      = jfs_freeze,
+       .unfreeze_fs    = jfs_unfreeze,
        .statfs         = jfs_statfs,
        .remount_fs     = jfs_remount,
        .show_options   = jfs_show_options,
@@ -737,8 +765,9 @@ static const struct super_operations jfs_super_operations = {
 #endif
 };
 
-static struct export_operations jfs_export_operations = {
-       .get_dentry     = jfs_get_dentry,
+static const struct export_operations jfs_export_operations = {
+       .fh_to_dentry   = jfs_fh_to_dentry,
+       .fh_to_parent   = jfs_fh_to_parent,
        .get_parent     = jfs_get_parent,
 };
 
@@ -750,7 +779,7 @@ static struct file_system_type jfs_fs_type = {
        .fs_flags       = FS_REQUIRES_DEV,
 };
 
-static void init_once(void *foo, struct kmem_cache * cachep, unsigned long flags)
+static void init_once(void *foo)
 {
        struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
 
@@ -761,10 +790,6 @@ static void init_once(void *foo, struct kmem_cache * cachep, unsigned long flags
        init_rwsem(&jfs_ip->xattr_sem);
        spin_lock_init(&jfs_ip->ag_lock);
        jfs_ip->active_ag = -1;
-#ifdef CONFIG_JFS_POSIX_ACL
-       jfs_ip->i_acl = JFS_ACL_NOT_CACHED;
-       jfs_ip->i_default_acl = JFS_ACL_NOT_CACHED;
-#endif
        inode_init_once(&jfs_ip->vfs_inode);
 }
 
@@ -776,7 +801,7 @@ static int __init init_jfs_fs(void)
        jfs_inode_cachep =
            kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
                            SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
-                           init_once, NULL);
+                           init_once);
        if (jfs_inode_cachep == NULL)
                return -ENOMEM;