Fix races around the access to ->s_options
[safe/jmp/linux-2.6] / fs / reiserfs / super.c
index 6d10f81..1215a4f 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/mnt_namespace.h>
 #include <linux/mount.h>
 #include <linux/namei.h>
+#include <linux/crc32.h>
 
 struct file_system_type reiserfs_fs_type;
 
@@ -248,7 +249,7 @@ static int finish_unfinished(struct super_block *s)
                        retval = remove_save_link_only(s, &save_link_key, 0);
                        continue;
                }
-               DQUOT_INIT(inode);
+               vfs_dq_init(inode);
 
                if (truncate && S_ISDIR(inode->i_mode)) {
                        /* We got a truncate request for a dir which is impossible.
@@ -628,8 +629,6 @@ static const struct super_operations reiserfs_sops = {
 #ifdef CONFIG_QUOTA
 #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
 
-static int reiserfs_dquot_initialize(struct inode *, int);
-static int reiserfs_dquot_drop(struct inode *);
 static int reiserfs_write_dquot(struct dquot *);
 static int reiserfs_acquire_dquot(struct dquot *);
 static int reiserfs_release_dquot(struct dquot *);
@@ -638,8 +637,8 @@ static int reiserfs_write_info(struct super_block *, int);
 static int reiserfs_quota_on(struct super_block *, int, int, char *, int);
 
 static struct dquot_operations reiserfs_quota_operations = {
-       .initialize = reiserfs_dquot_initialize,
-       .drop = reiserfs_dquot_drop,
+       .initialize = dquot_initialize,
+       .drop = dquot_drop,
        .alloc_space = dquot_alloc_space,
        .alloc_inode = dquot_alloc_inode,
        .free_space = dquot_free_space,
@@ -758,7 +757,7 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
                           char **opt_arg, unsigned long *bit_flags)
 {
        char *p;
-       /* foo=bar, 
+       /* foo=bar,
           ^   ^  ^
           |   |  +-- option_end
           |   +-- arg_start
@@ -1317,8 +1316,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
        }
 
 out_ok:
-       kfree(s->s_options);
-       s->s_options = new_opts;
+       replace_mount_options(s, new_opts);
        return 0;
 
 out_err:
@@ -1348,7 +1346,7 @@ static int read_super_block(struct super_block *s, int offset)
        }
        //
        // ok, reiserfs signature (old or new) found in at the given offset
-       //    
+       //
        fs_blocksize = sb_blocksize(rs);
        brelse(bh);
        sb_set_blocksize(s, fs_blocksize);
@@ -1534,8 +1532,8 @@ static int what_hash(struct super_block *s)
                code = find_hash_out(s);
 
        if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
-               /* detection has found the hash, and we must check against the 
-                ** mount options 
+               /* detection has found the hash, and we must check against the
+                ** mount options
                 */
                if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
                        reiserfs_warning(s, "reiserfs-2507",
@@ -1567,7 +1565,7 @@ static int what_hash(struct super_block *s)
                }
        }
 
-       /* if we are mounted RW, and we have a new valid hash code, update 
+       /* if we are mounted RW, and we have a new valid hash code, update
         ** the super
         */
        if (code != UNSET_HASH &&
@@ -1843,7 +1841,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
                        goto error;
                }
 
-               if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
+               if ((errval = reiserfs_lookup_privroot(s)) ||
+                   (errval = reiserfs_xattr_init(s, s->s_flags))) {
                        dput(s->s_root);
                        s->s_root = NULL;
                        goto error;
@@ -1856,7 +1855,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
                        reiserfs_info(s, "using 3.5.x disk format\n");
                }
 
-               if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
+               if ((errval = reiserfs_lookup_privroot(s)) ||
+                   (errval = reiserfs_xattr_init(s, s->s_flags))) {
                        dput(s->s_root);
                        s->s_root = NULL;
                        goto error;
@@ -1906,62 +1906,14 @@ static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        buf->f_bsize = dentry->d_sb->s_blocksize;
        /* changed to accommodate gcc folks. */
        buf->f_type = REISERFS_SUPER_MAGIC;
+       buf->f_fsid.val[0] = (u32)crc32_le(0, rs->s_uuid, sizeof(rs->s_uuid)/2);
+       buf->f_fsid.val[1] = (u32)crc32_le(0, rs->s_uuid + sizeof(rs->s_uuid)/2,
+                               sizeof(rs->s_uuid)/2);
+
        return 0;
 }
 
 #ifdef CONFIG_QUOTA
-static int reiserfs_dquot_initialize(struct inode *inode, int type)
-{
-       struct reiserfs_transaction_handle th;
-       int ret, err;
-
-       /* We may create quota structure so we need to reserve enough blocks */
-       reiserfs_write_lock(inode->i_sb);
-       ret =
-           journal_begin(&th, inode->i_sb,
-                         2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
-       if (ret)
-               goto out;
-       ret = dquot_initialize(inode, type);
-       err =
-           journal_end(&th, inode->i_sb,
-                       2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
-       if (!ret && err)
-               ret = err;
-      out:
-       reiserfs_write_unlock(inode->i_sb);
-       return ret;
-}
-
-static int reiserfs_dquot_drop(struct inode *inode)
-{
-       struct reiserfs_transaction_handle th;
-       int ret, err;
-
-       /* We may delete quota structure so we need to reserve enough blocks */
-       reiserfs_write_lock(inode->i_sb);
-       ret =
-           journal_begin(&th, inode->i_sb,
-                         2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
-       if (ret) {
-               /*
-                * We call dquot_drop() anyway to at least release references
-                * to quota structures so that umount does not hang.
-                */
-               dquot_drop(inode);
-               goto out;
-       }
-       ret = dquot_drop(inode);
-       err =
-           journal_end(&th, inode->i_sb,
-                       2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
-       if (!ret && err)
-               ret = err;
-      out:
-       reiserfs_write_unlock(inode->i_sb);
-       return ret;
-}
-
 static int reiserfs_write_dquot(struct dquot *dquot)
 {
        struct reiserfs_transaction_handle th;
@@ -2263,9 +2215,6 @@ static int __init init_reiserfs_fs(void)
                return ret;
        }
 
-       if ((ret = reiserfs_xattr_register_handlers()))
-               goto failed_reiserfs_xattr_register_handlers;
-
        reiserfs_proc_info_global_init();
        reiserfs_proc_register_global("version",
                                      reiserfs_global_version_in_proc);
@@ -2276,9 +2225,6 @@ static int __init init_reiserfs_fs(void)
                return 0;
        }
 
-       reiserfs_xattr_unregister_handlers();
-
-      failed_reiserfs_xattr_register_handlers:
        reiserfs_proc_unregister_global("version");
        reiserfs_proc_info_global_done();
        destroy_inodecache();
@@ -2288,7 +2234,6 @@ static int __init init_reiserfs_fs(void)
 
 static void __exit exit_reiserfs_fs(void)
 {
-       reiserfs_xattr_unregister_handlers();
        reiserfs_proc_unregister_global("version");
        reiserfs_proc_info_global_done();
        unregister_filesystem(&reiserfs_fs_type);