switch reiserfs to inode->i_acl
[safe/jmp/linux-2.6] / fs / reiserfs / super.c
index bfc276c..d3aeb06 100644 (file)
@@ -27,6 +27,8 @@
 #include <linux/mnt_namespace.h>
 #include <linux/mount.h>
 #include <linux/namei.h>
+#include <linux/crc32.h>
+#include <linux/smp_lock.h>
 
 struct file_system_type reiserfs_fs_type;
 
@@ -63,18 +65,15 @@ static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
 
 static int reiserfs_sync_fs(struct super_block *s, int wait)
 {
-       if (!(s->s_flags & MS_RDONLY)) {
-               struct reiserfs_transaction_handle th;
-               reiserfs_write_lock(s);
-               if (!journal_begin(&th, s, 1))
-                       if (!journal_end_sync(&th, s, 1))
-                               reiserfs_flush_old_commits(s);
-               s->s_dirt = 0;  /* Even if it's not true.
-                                * We'll loop forever in sync_supers otherwise */
-               reiserfs_write_unlock(s);
-       } else {
-               s->s_dirt = 0;
-       }
+       struct reiserfs_transaction_handle th;
+
+       reiserfs_write_lock(s);
+       if (!journal_begin(&th, s, 1))
+               if (!journal_end_sync(&th, s, 1))
+                       reiserfs_flush_old_commits(s);
+       s->s_dirt = 0;  /* Even if it's not true.
+                        * We'll loop forever in sync_supers otherwise */
+       reiserfs_write_unlock(s);
        return 0;
 }
 
@@ -195,9 +194,8 @@ static int finish_unfinished(struct super_block *s)
        while (!retval) {
                retval = search_item(s, &max_cpu_key, &path);
                if (retval != ITEM_NOT_FOUND) {
-                       reiserfs_warning(s, "vs-2140",
-                                        "search_by_key returned %d",
-                                        retval);
+                       reiserfs_error(s, "vs-2140",
+                                      "search_by_key returned %d", retval);
                        break;
                }
 
@@ -249,7 +247,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.
@@ -378,9 +376,9 @@ void add_save_link(struct reiserfs_transaction_handle *th,
        retval = search_item(inode->i_sb, &key, &path);
        if (retval != ITEM_NOT_FOUND) {
                if (retval != -ENOSPC)
-                       reiserfs_warning(inode->i_sb, "vs-2100",
-                                        "search_by_key (%K) returned %d", &key,
-                                        retval);
+                       reiserfs_error(inode->i_sb, "vs-2100",
+                                      "search_by_key (%K) returned %d", &key,
+                                      retval);
                pathrelse(&path);
                return;
        }
@@ -393,8 +391,8 @@ void add_save_link(struct reiserfs_transaction_handle *th,
            reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
        if (retval) {
                if (retval != -ENOSPC)
-                       reiserfs_warning(inode->i_sb, "vs-2120",
-                                        "insert_item returned %d", retval);
+                       reiserfs_error(inode->i_sb, "vs-2120",
+                                      "insert_item returned %d", retval);
        } else {
                if (truncate)
                        REISERFS_I(inode)->i_flags |=
@@ -448,13 +446,11 @@ int remove_save_link(struct inode *inode, int truncate)
 static void reiserfs_kill_sb(struct super_block *s)
 {
        if (REISERFS_SB(s)) {
-#ifdef CONFIG_REISERFS_FS_XATTR
                if (REISERFS_SB(s)->xattr_root) {
                        d_invalidate(REISERFS_SB(s)->xattr_root);
                        dput(REISERFS_SB(s)->xattr_root);
                        REISERFS_SB(s)->xattr_root = NULL;
                }
-#endif
                if (REISERFS_SB(s)->priv_root) {
                        d_invalidate(REISERFS_SB(s)->priv_root);
                        dput(REISERFS_SB(s)->priv_root);
@@ -470,6 +466,11 @@ static void reiserfs_put_super(struct super_block *s)
        struct reiserfs_transaction_handle th;
        th.t_trans_id = 0;
 
+       lock_kernel();
+
+       if (s->s_dirt)
+               reiserfs_write_super(s);
+
        /* change file system state to current state if it was mounted with read-write permissions */
        if (!(s->s_flags & MS_RDONLY)) {
                if (!journal_begin(&th, s, 10)) {
@@ -502,7 +503,7 @@ static void reiserfs_put_super(struct super_block *s)
        kfree(s->s_fs_info);
        s->s_fs_info = NULL;
 
-       return;
+       unlock_kernel();
 }
 
 static struct kmem_cache *reiserfs_inode_cachep;
@@ -528,10 +529,6 @@ static void init_once(void *foo)
 
        INIT_LIST_HEAD(&ei->i_prealloc_list);
        inode_init_once(&ei->vfs_inode);
-#ifdef CONFIG_REISERFS_FS_POSIX_ACL
-       ei->i_acl_access = NULL;
-       ei->i_acl_default = NULL;
-#endif
 }
 
 static int init_inodecache(void)
@@ -579,25 +576,6 @@ static void reiserfs_dirty_inode(struct inode *inode)
        reiserfs_write_unlock(inode->i_sb);
 }
 
-#ifdef CONFIG_REISERFS_FS_POSIX_ACL
-static void reiserfs_clear_inode(struct inode *inode)
-{
-       struct posix_acl *acl;
-
-       acl = REISERFS_I(inode)->i_acl_access;
-       if (acl && !IS_ERR(acl))
-               posix_acl_release(acl);
-       REISERFS_I(inode)->i_acl_access = NULL;
-
-       acl = REISERFS_I(inode)->i_acl_default;
-       if (acl && !IS_ERR(acl))
-               posix_acl_release(acl);
-       REISERFS_I(inode)->i_acl_default = NULL;
-}
-#else
-#define reiserfs_clear_inode NULL
-#endif
-
 #ifdef CONFIG_QUOTA
 static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
                                    size_t, loff_t);
@@ -611,7 +589,6 @@ static const struct super_operations reiserfs_sops = {
        .write_inode = reiserfs_write_inode,
        .dirty_inode = reiserfs_dirty_inode,
        .delete_inode = reiserfs_delete_inode,
-       .clear_inode = reiserfs_clear_inode,
        .put_super = reiserfs_put_super,
        .write_super = reiserfs_write_super,
        .sync_fs = reiserfs_sync_fs,
@@ -629,8 +606,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 *);
@@ -639,8 +614,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,
@@ -759,7 +734,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
@@ -902,6 +877,7 @@ static int reiserfs_parse_options(struct super_block *s, char *options,     /* strin
                {"conv",.setmask = 1 << REISERFS_CONVERT},
                {"attrs",.setmask = 1 << REISERFS_ATTRS},
                {"noattrs",.clrmask = 1 << REISERFS_ATTRS},
+               {"expose_privroot", .setmask = 1 << REISERFS_EXPOSE_PRIVROOT},
 #ifdef CONFIG_REISERFS_FS_XATTR
                {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
                {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
@@ -1197,6 +1173,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
        memcpy(qf_names, REISERFS_SB(s)->s_qf_names, sizeof(qf_names));
 #endif
 
+       lock_kernel();
        rs = SB_DISK_SUPER_BLOCK(s);
 
        if (!reiserfs_parse_options
@@ -1318,12 +1295,13 @@ 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);
+       unlock_kernel();
        return 0;
 
 out_err:
        kfree(new_opts);
+       unlock_kernel();
        return err;
 }
 
@@ -1349,7 +1327,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);
@@ -1535,8 +1513,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",
@@ -1568,7 +1546,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 &&
@@ -1647,10 +1625,6 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
        REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
        /* Preallocate by 16 blocks (17-1) at once */
        REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
-#ifdef CONFIG_REISERFS_FS_XATTR
-       /* Initialize the rwsem for xattr dir */
-       init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
-#endif
        /* setup default block allocator options */
        reiserfs_init_alloc_options(s);
 
@@ -1848,7 +1822,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;
@@ -1861,7 +1836,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;
@@ -1911,62 +1887,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;
@@ -2268,9 +2196,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);
@@ -2281,9 +2206,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();
@@ -2293,7 +2215,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);