ARM64: dts: rk3328-evb: add support for internal codec sound
[firefly-linux-kernel-4.4.55.git] / fs / reiserfs / super.c
index 460f762a85c0f1feada7b819f15614cf249b4ca2..f9f3be50081a3c719a589f92479d274be82e9772 100644 (file)
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/time.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include "reiserfs.h"
 #include "acl.h"
 #include "xattr.h"
 #include <linux/init.h>
 #include <linux/blkdev.h>
+#include <linux/backing-dev.h>
 #include <linux/buffer_head.h>
 #include <linux/exportfs.h>
 #include <linux/quotaops.h>
@@ -62,7 +63,6 @@ static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
 
 static int reiserfs_remount(struct super_block *s, int *flags, char *data);
 static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
-void show_alloc_options(struct seq_file *seq, struct super_block *s);
 
 static int reiserfs_sync_fs(struct super_block *s, int wait)
 {
@@ -75,7 +75,7 @@ static int reiserfs_sync_fs(struct super_block *s, int wait)
        dquot_writeback_dquots(s, -1);
        reiserfs_write_lock(s);
        if (!journal_begin(&th, s, 1))
-               if (!journal_end_sync(&th, s, 1))
+               if (!journal_end_sync(&th))
                        reiserfs_flush_old_commits(s);
        reiserfs_write_unlock(s);
        return 0;
@@ -101,7 +101,11 @@ void reiserfs_schedule_old_flush(struct super_block *s)
        struct reiserfs_sb_info *sbi = REISERFS_SB(s);
        unsigned long delay;
 
-       if (s->s_flags & MS_RDONLY)
+       /*
+        * Avoid scheduling flush when sb is being shut down. It can race
+        * with journal shutdown and free still queued delayed work.
+        */
+       if (s->s_flags & MS_RDONLY || !(s->s_flags & MS_ACTIVE))
                return;
 
        spin_lock(&sbi->old_work_lock);
@@ -137,9 +141,9 @@ static int reiserfs_freeze(struct super_block *s)
                } else {
                        reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
                                                     1);
-                       journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
+                       journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
                        reiserfs_block_writes(&th);
-                       journal_end_sync(&th, s, 1);
+                       journal_end_sync(&th);
                }
        }
        reiserfs_write_unlock(s);
@@ -154,13 +158,15 @@ static int reiserfs_unfreeze(struct super_block *s)
 
 extern const struct in_core_key MAX_IN_CORE_KEY;
 
-/* this is used to delete "save link" when there are no items of a
-   file it points to. It can either happen if unlink is completed but
-   "save unlink" removal, or if file has both unlink and truncate
-   pending and as unlink completes first (because key of "save link"
-   protecting unlink is bigger that a key lf "save link" which
-   protects truncate), so there left no items to make truncate
-   completion on */
+/*
+ * this is used to delete "save link" when there are no items of a
+ * file it points to. It can either happen if unlink is completed but
+ * "save unlink" removal, or if file has both unlink and truncate
+ * pending and as unlink completes first (because key of "save link"
+ * protecting unlink is bigger that a key lf "save link" which
+ * protects truncate), so there left no items to make truncate
+ * completion on
+ */
 static int remove_save_link_only(struct super_block *s,
                                 struct reiserfs_key *key, int oid_free)
 {
@@ -177,14 +183,22 @@ static int remove_save_link_only(struct super_block *s,
                /* removals are protected by direct items */
                reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
 
-       return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
+       return journal_end(&th);
 }
 
 #ifdef CONFIG_QUOTA
 static int reiserfs_quota_on_mount(struct super_block *, int);
 #endif
 
-/* look for uncompleted unlinks and truncates and complete them */
+/*
+ * Look for uncompleted unlinks and truncates and complete them
+ *
+ * Called with superblock write locked.  If quotas are enabled, we have to
+ * release/retake lest we call dquot_quota_on_mount(), proceed to
+ * schedule_on_each_cpu() in invalidate_bdev() and deadlock waiting for the per
+ * cpu worklets to complete flush_async_commits() that in turn wait for the
+ * superblock write lock.
+ */
 static int finish_unfinished(struct super_block *s)
 {
        INITIALIZE_PATH(path);
@@ -201,7 +215,7 @@ static int finish_unfinished(struct super_block *s)
 #ifdef CONFIG_QUOTA
        int i;
        int ms_active_set;
-       int quota_enabled[MAXQUOTAS];
+       int quota_enabled[REISERFS_MAXQUOTAS];
 #endif
 
        /* compose key to look for "save" links */
@@ -222,7 +236,7 @@ static int finish_unfinished(struct super_block *s)
                s->s_flags |= MS_ACTIVE;
        }
        /* Turn on quotas so that they are updated correctly */
-       for (i = 0; i < MAXQUOTAS; i++) {
+       for (i = 0; i < REISERFS_MAXQUOTAS; i++) {
                quota_enabled[i] = 1;
                if (REISERFS_SB(s)->s_qf_names[i]) {
                        int ret;
@@ -231,7 +245,9 @@ static int finish_unfinished(struct super_block *s)
                                quota_enabled[i] = 0;
                                continue;
                        }
+                       reiserfs_write_unlock(s);
                        ret = reiserfs_quota_on_mount(s, i);
+                       reiserfs_write_lock(s);
                        if (ret < 0)
                                reiserfs_warning(s, "reiserfs-2500",
                                                 "cannot turn on journaled "
@@ -243,6 +259,7 @@ static int finish_unfinished(struct super_block *s)
        done = 0;
        REISERFS_SB(s)->s_is_unlinked_ok = 1;
        while (!retval) {
+               int depth;
                retval = search_item(s, &max_cpu_key, &path);
                if (retval != ITEM_NOT_FOUND) {
                        reiserfs_error(s, "vs-2140",
@@ -258,7 +275,7 @@ static int finish_unfinished(struct super_block *s)
                        break;
                }
                item_pos--;
-               ih = B_N_PITEM_HEAD(bh, item_pos);
+               ih = item_head(bh, item_pos);
 
                if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
                        /* there are no "save" links anymore */
@@ -271,7 +288,7 @@ static int finish_unfinished(struct super_block *s)
                        truncate = 0;
 
                /* reiserfs_iget needs k_dirid and k_objectid only */
-               item = B_I_PITEM(bh, ih);
+               item = ih_item_body(bh, ih);
                obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
                obj_key.on_disk_key.k_objectid =
                    le32_to_cpu(ih->ih_key.k_objectid);
@@ -282,8 +299,10 @@ static int finish_unfinished(struct super_block *s)
 
                inode = reiserfs_iget(s, &obj_key);
                if (!inode) {
-                       /* the unlink almost completed, it just did not manage to remove
-                          "save" link and release objectid */
+                       /*
+                        * the unlink almost completed, it just did not
+                        * manage to remove "save" link and release objectid
+                        */
                        reiserfs_warning(s, "vs-2180", "iget failed for %K",
                                         &obj_key);
                        retval = remove_save_link_only(s, &save_link_key, 1);
@@ -298,15 +317,18 @@ static int finish_unfinished(struct super_block *s)
                        retval = remove_save_link_only(s, &save_link_key, 0);
                        continue;
                }
-               reiserfs_write_unlock(s);
+               depth = reiserfs_write_unlock_nested(inode->i_sb);
                dquot_initialize(inode);
-               reiserfs_write_lock(s);
+               reiserfs_write_lock_nested(inode->i_sb, depth);
 
                if (truncate && S_ISDIR(inode->i_mode)) {
-                       /* We got a truncate request for a dir which is impossible.
-                          The only imaginable way is to execute unfinished truncate request
-                          then boot into old kernel, remove the file and create dir with
-                          the same key. */
+                       /*
+                        * We got a truncate request for a dir which
+                        * is impossible.  The only imaginable way is to
+                        * execute unfinished truncate request then boot
+                        * into old kernel, remove the file and create dir
+                        * with the same key.
+                        */
                        reiserfs_warning(s, "green-2101",
                                         "impossible truncate on a "
                                         "directory %k. Please report",
@@ -320,14 +342,16 @@ static int finish_unfinished(struct super_block *s)
                if (truncate) {
                        REISERFS_I(inode)->i_flags |=
                            i_link_saved_truncate_mask;
-                       /* not completed truncate found. New size was committed together
-                          with "save" link */
-                       reiserfs_info(s, "Truncating %k to %Ld ..",
+                       /*
+                        * not completed truncate found. New size was
+                        * committed together with "save" link
+                        */
+                       reiserfs_info(s, "Truncating %k to %lld ..",
                                      INODE_PKEY(inode), inode->i_size);
-                       reiserfs_truncate_file(inode,
-                                              0
-                                              /*don't update modification time */
-                                              );
+
+                       /* don't update modification time */
+                       reiserfs_truncate_file(inode, 0);
+
                        retval = remove_save_link(inode, truncate);
                } else {
                        REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
@@ -356,10 +380,12 @@ static int finish_unfinished(struct super_block *s)
 
 #ifdef CONFIG_QUOTA
        /* Turn quotas off */
-       for (i = 0; i < MAXQUOTAS; i++) {
+       reiserfs_write_unlock(s);
+       for (i = 0; i < REISERFS_MAXQUOTAS; i++) {
                if (sb_dqopt(s)->files[i] && quota_enabled[i])
                        dquot_quota_off(s, i);
        }
+       reiserfs_write_lock(s);
        if (ms_active_set)
                /* Restore the flag back */
                s->s_flags &= ~MS_ACTIVE;
@@ -371,10 +397,12 @@ static int finish_unfinished(struct super_block *s)
        return retval;
 }
 
-/* to protect file being unlinked from getting lost we "safe" link files
-   being unlinked. This link will be deleted in the same transaction with last
-   item of file. mounting the filesystem we scan all these links and remove
-   files which almost got lost */
+/*
+ * to protect file being unlinked from getting lost we "safe" link files
+ * being unlinked. This link will be deleted in the same transaction with last
+ * item of file. mounting the filesystem we scan all these links and remove
+ * files which almost got lost
+ */
 void add_save_link(struct reiserfs_transaction_handle *th,
                   struct inode *inode, int truncate)
 {
@@ -493,7 +521,7 @@ int remove_save_link(struct inode *inode, int truncate)
        } else
                REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
 
-       return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
+       return journal_end(&th);
 }
 
 static void reiserfs_kill_sb(struct super_block *s)
@@ -528,19 +556,23 @@ static void reiserfs_put_super(struct super_block *s)
 
        reiserfs_write_lock(s);
 
-       /* change file system state to current state if it was mounted with read-write permissions */
+       /*
+        * 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)) {
                        reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
                                                     1);
                        set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
                                            REISERFS_SB(s)->s_mount_state);
-                       journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
+                       journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
                }
        }
 
-       /* note, journal_release checks for readonly mount, and can decide not
-        ** to do a journal_end
+       /*
+        * note, journal_release checks for readonly mount, and can
+        * decide not to do a journal_end
         */
        journal_release(&th, s);
 
@@ -557,6 +589,7 @@ static void reiserfs_put_super(struct super_block *s)
 
        reiserfs_write_unlock(s);
        mutex_destroy(&REISERFS_SB(s)->lock);
+       destroy_workqueue(REISERFS_SB(s)->commit_wq);
        kfree(s->s_fs_info);
        s->s_fs_info = NULL;
 }
@@ -566,12 +599,15 @@ static struct kmem_cache *reiserfs_inode_cachep;
 static struct inode *reiserfs_alloc_inode(struct super_block *sb)
 {
        struct reiserfs_inode_info *ei;
-       ei = (struct reiserfs_inode_info *)
-           kmem_cache_alloc(reiserfs_inode_cachep, GFP_KERNEL);
+       ei = kmem_cache_alloc(reiserfs_inode_cachep, GFP_KERNEL);
        if (!ei)
                return NULL;
        atomic_set(&ei->openers, 0);
        mutex_init(&ei->tailpack);
+#ifdef CONFIG_QUOTA
+       memset(&ei->i_dquot, 0, sizeof(ei->i_dquot));
+#endif
+
        return &ei->vfs_inode;
 }
 
@@ -594,7 +630,7 @@ static void init_once(void *foo)
        inode_init_once(&ei->vfs_inode);
 }
 
-static int init_inodecache(void)
+static int __init init_inodecache(void)
 {
        reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
                                                  sizeof(struct
@@ -623,7 +659,6 @@ static void reiserfs_dirty_inode(struct inode *inode, int flags)
        struct reiserfs_transaction_handle th;
 
        int err = 0;
-       int lock_depth;
 
        if (inode->i_sb->s_flags & MS_RDONLY) {
                reiserfs_warning(inode->i_sb, "clm-6006",
@@ -631,20 +666,21 @@ static void reiserfs_dirty_inode(struct inode *inode, int flags)
                                 inode->i_ino);
                return;
        }
-       lock_depth = reiserfs_write_lock_once(inode->i_sb);
+       reiserfs_write_lock(inode->i_sb);
 
-       /* this is really only used for atime updates, so they don't have
-        ** to be included in O_SYNC or fsync
+       /*
+        * this is really only used for atime updates, so they don't have
+        * to be included in O_SYNC or fsync
         */
        err = journal_begin(&th, inode->i_sb, 1);
        if (err)
                goto out;
 
        reiserfs_update_sd(&th, inode);
-       journal_end(&th, inode->i_sb, 1);
+       journal_end(&th);
 
 out:
-       reiserfs_write_unlock_once(inode->i_sb, lock_depth);
+       reiserfs_write_unlock(inode->i_sb);
 }
 
 static int reiserfs_show_options(struct seq_file *seq, struct dentry *root)
@@ -688,18 +724,20 @@ static int reiserfs_show_options(struct seq_file *seq, struct dentry *root)
                seq_puts(seq, ",acl");
 
        if (REISERFS_SB(s)->s_jdev)
-               seq_printf(seq, ",jdev=%s", REISERFS_SB(s)->s_jdev);
+               seq_show_option(seq, "jdev", REISERFS_SB(s)->s_jdev);
 
        if (journal->j_max_commit_age != journal->j_default_max_commit_age)
                seq_printf(seq, ",commit=%d", journal->j_max_commit_age);
 
 #ifdef CONFIG_QUOTA
        if (REISERFS_SB(s)->s_qf_names[USRQUOTA])
-               seq_printf(seq, ",usrjquota=%s", REISERFS_SB(s)->s_qf_names[USRQUOTA]);
+               seq_show_option(seq, "usrjquota",
+                               REISERFS_SB(s)->s_qf_names[USRQUOTA]);
        else if (opts & (1 << REISERFS_USRQUOTA))
                seq_puts(seq, ",usrquota");
        if (REISERFS_SB(s)->s_qf_names[GRPQUOTA])
-               seq_printf(seq, ",grpjquota=%s", REISERFS_SB(s)->s_qf_names[GRPQUOTA]);
+               seq_show_option(seq, "grpjquota",
+                               REISERFS_SB(s)->s_qf_names[GRPQUOTA]);
        else if (opts & (1 << REISERFS_GRPQUOTA))
                seq_puts(seq, ",grpquota");
        if (REISERFS_SB(s)->s_jquota_fmt) {
@@ -728,6 +766,11 @@ static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
                                    size_t, loff_t);
 static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
                                   loff_t);
+
+static struct dquot **reiserfs_get_dquots(struct inode *inode)
+{
+       return REISERFS_I(inode)->i_dquot;
+}
 #endif
 
 static const struct super_operations reiserfs_sops = {
@@ -746,6 +789,7 @@ static const struct super_operations reiserfs_sops = {
 #ifdef CONFIG_QUOTA
        .quota_read = reiserfs_quota_read,
        .quota_write = reiserfs_quota_write,
+       .get_dquots = reiserfs_get_dquots,
 #endif
 };
 
@@ -773,7 +817,7 @@ static const struct quotactl_ops reiserfs_qctl_operations = {
        .quota_on = reiserfs_quota_on,
        .quota_off = dquot_quota_off,
        .quota_sync = dquot_quota_sync,
-       .get_info = dquot_get_dqinfo,
+       .get_state = dquot_get_state,
        .set_info = dquot_set_dqinfo,
        .get_dqblk = dquot_get_dqblk,
        .set_dqblk = dquot_set_dqblk,
@@ -787,31 +831,53 @@ static const struct export_operations reiserfs_export_ops = {
        .get_parent = reiserfs_get_parent,
 };
 
-/* this struct is used in reiserfs_getopt () for containing the value for those
-   mount options that have values rather than being toggles. */
+/*
+ * this struct is used in reiserfs_getopt () for containing the value for
+ * those mount options that have values rather than being toggles.
+ */
 typedef struct {
        char *value;
-       int setmask;            /* bitmask which is to set on mount_options bitmask when this
-                                  value is found, 0 is no bits are to be changed. */
-       int clrmask;            /* bitmask which is to clear on mount_options bitmask when  this
-                                  value is found, 0 is no bits are to be changed. This is
-                                  applied BEFORE setmask */
+       /*
+        * bitmask which is to set on mount_options bitmask
+        * when this value is found, 0 is no bits are to be changed.
+        */
+       int setmask;
+       /*
+        * bitmask which is to clear on mount_options bitmask
+        * when this value is found, 0 is no bits are to be changed.
+        * This is applied BEFORE setmask
+        */
+       int clrmask;
 } arg_desc_t;
 
 /* Set this bit in arg_required to allow empty arguments */
 #define REISERFS_OPT_ALLOWEMPTY 31
 
-/* this struct is used in reiserfs_getopt() for describing the set of reiserfs
-   mount options */
+/*
+ * this struct is used in reiserfs_getopt() for describing the
+ * set of reiserfs mount options
+ */
 typedef struct {
        char *option_name;
-       int arg_required;       /* 0 if argument is not required, not 0 otherwise */
-       const arg_desc_t *values;       /* list of values accepted by an option */
-       int setmask;            /* bitmask which is to set on mount_options bitmask when this
-                                  value is found, 0 is no bits are to be changed. */
-       int clrmask;            /* bitmask which is to clear on mount_options bitmask when  this
-                                  value is found, 0 is no bits are to be changed. This is
-                                  applied BEFORE setmask */
+
+       /* 0 if argument is not required, not 0 otherwise */
+       int arg_required;
+
+       /* list of values accepted by an option */
+       const arg_desc_t *values;
+
+       /*
+        * bitmask which is to set on mount_options bitmask
+        * when this value is found, 0 is no bits are to be changed.
+        */
+       int setmask;
+
+       /*
+        * bitmask which is to clear on mount_options bitmask
+        * when this value is found, 0 is no bits are to be changed.
+        * This is applied BEFORE setmask
+        */
+       int clrmask;
 } opt_desc_t;
 
 /* possible values for -o data= */
@@ -832,8 +898,10 @@ static const arg_desc_t barrier_mode[] = {
        {.value = NULL}
 };
 
-/* possible values for "-o block-allocator=" and bits which are to be set in
-   s_mount_opt of reiserfs specific part of in-core super block */
+/*
+ * possible values for "-o block-allocator=" and bits which are to be set in
+ * s_mount_opt of reiserfs specific part of in-core super block
+ */
 static const arg_desc_t balloc[] = {
        {"noborder", 1 << REISERFS_NO_BORDER, 0},
        {"border", 0, 1 << REISERFS_NO_BORDER},
@@ -863,21 +931,25 @@ static const arg_desc_t error_actions[] = {
        {NULL, 0, 0},
 };
 
-/* proceed only one option from a list *cur - string containing of mount options
-   opts - array of options which are accepted
-   opt_arg - if option is found and requires an argument and if it is specifed
-   in the input - pointer to the argument is stored here
-   bit_flags - if option requires to set a certain bit - it is set here
-   return -1 if unknown option is found, opt->arg_required otherwise */
+/*
+ * proceed only one option from a list *cur - string containing of mount
+ * options
+ * opts - array of options which are accepted
+ * opt_arg - if option is found and requires an argument and if it is specifed
+ * in the input - pointer to the argument is stored here
+ * bit_flags - if option requires to set a certain bit - it is set here
+ * return -1 if unknown option is found, opt->arg_required otherwise
+ */
 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,
-          ^   ^  ^
-          |   |  +-- option_end
-          |   +-- arg_start
-          +-- option_start
+       /*
+        * foo=bar,
+        * ^   ^  ^
+        * |   |  +-- option_end
+        * |   +-- arg_start
+        * +-- option_start
         */
        const opt_desc_t *opt;
        const arg_desc_t *arg;
@@ -892,9 +964,12 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
        }
 
        if (!strncmp(p, "alloc=", 6)) {
-               /* Ugly special case, probably we should redo options parser so that
-                  it can understand several arguments for some options, also so that
-                  it can fill several bitfields with option values. */
+               /*
+                * Ugly special case, probably we should redo options
+                * parser so that it can understand several arguments for
+                * some options, also so that it can fill several bitfields
+                * with option values.
+                */
                if (reiserfs_parse_alloc_options(s, p + 6)) {
                        return -1;
                } else {
@@ -957,7 +1032,10 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
                return -1;
        }
 
-       /* move to the argument, or to next option if argument is not required */
+       /*
+        * move to the argument, or to next option if argument is not
+        * required
+        */
        p++;
 
        if (opt->arg_required
@@ -994,12 +1072,20 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
 }
 
 /* returns 0 if something is wrong in option string, 1 - otherwise */
-static int reiserfs_parse_options(struct super_block *s, char *options,        /* string given via mount's -o */
+static int reiserfs_parse_options(struct super_block *s,
+
+                                 /* string given via mount's -o */
+                                 char *options,
+
+                                 /*
+                                  * after the parsing phase, contains the
+                                  * collection of bitflags defining what
+                                  * mount options were selected.
+                                  */
                                  unsigned long *mount_options,
-                                 /* after the parsing phase, contains the
-                                    collection of bitflags defining what
-                                    mount options were selected. */
-                                 unsigned long *blocks,        /* strtol-ed from NNN of resize=NNN */
+
+                                 /* strtol-ed from NNN of resize=NNN */
+                                 unsigned long *blocks,
                                  char **jdev_name,
                                  unsigned int *commit_max_age,
                                  char **qf_names,
@@ -1009,7 +1095,10 @@ static int reiserfs_parse_options(struct super_block *s, char *options,  /* strin
        char *arg = NULL;
        char *pos;
        opt_desc_t opts[] = {
-               /* Compatibility stuff, so that -o notail for old setups still work */
+               /*
+                * Compatibility stuff, so that -o notail for old
+                * setups still work
+                */
                {"tails",.arg_required = 't',.values = tails},
                {"notail",.clrmask =
                 (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
@@ -1054,8 +1143,10 @@ static int reiserfs_parse_options(struct super_block *s, char *options,  /* strin
 
        *blocks = 0;
        if (!options || !*options)
-               /* use default configuration: create tails, journaling on, no
-                  conversion to newest format */
+               /*
+                * use default configuration: create tails, journaling on, no
+                * conversion to newest format
+                */
                return 1;
 
        for (pos = options; pos;) {
@@ -1108,7 +1199,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options,   /* strin
 
                if (c == 'j') {
                        if (arg && *arg && jdev_name) {
-                               if (*jdev_name) {       //Hm, already assigned?
+                               /* Hm, already assigned? */
+                               if (*jdev_name) {
                                        reiserfs_warning(s, "super-6510",
                                                         "journal device was "
                                                         "already specified to "
@@ -1290,7 +1382,7 @@ static void handle_quota_files(struct super_block *s, char **qf_names,
 {
        int i;
 
-       for (i = 0; i < MAXQUOTAS; i++) {
+       for (i = 0; i < REISERFS_MAXQUOTAS; i++) {
                if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i])
                        kfree(REISERFS_SB(s)->s_qf_names[i]);
                REISERFS_SB(s)->s_qf_names[i] = qf_names[i];
@@ -1311,7 +1403,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
        struct reiserfs_journal *journal = SB_JOURNAL(s);
        char *new_opts = kstrdup(arg, GFP_KERNEL);
        int err;
-       char *qf_names[MAXQUOTAS];
+       char *qf_names[REISERFS_MAXQUOTAS];
        unsigned int qfmt = 0;
 #ifdef CONFIG_QUOTA
        int i;
@@ -1330,12 +1422,12 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
            (s, arg, &mount_options, &blocks, NULL, &commit_max_age,
            qf_names, &qfmt)) {
 #ifdef CONFIG_QUOTA
-               for (i = 0; i < MAXQUOTAS; i++)
+               for (i = 0; i < REISERFS_MAXQUOTAS; i++)
                        if (qf_names[i] != REISERFS_SB(s)->s_qf_names[i])
                                kfree(qf_names[i]);
 #endif
                err = -EINVAL;
-               goto out_unlock;
+               goto out_err_unlock;
        }
 #ifdef CONFIG_QUOTA
        handle_quota_files(s, qf_names, &qfmt);
@@ -1361,8 +1453,10 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
        safe_mask |= 1 << REISERFS_USRQUOTA;
        safe_mask |= 1 << REISERFS_GRPQUOTA;
 
-       /* Update the bitmask, taking care to keep
-        * the bits we're not allowed to change here */
+       /*
+        * Update the bitmask, taking care to keep
+        * the bits we're not allowed to change here
+        */
        REISERFS_SB(s)->s_mount_opt =
            (REISERFS_SB(s)->
             s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
@@ -1379,59 +1473,59 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
        if (blocks) {
                err = reiserfs_resize(s, blocks);
                if (err != 0)
-                       goto out_unlock;
+                       goto out_err_unlock;
        }
 
        if (*mount_flags & MS_RDONLY) {
+               reiserfs_write_unlock(s);
                reiserfs_xattr_init(s, *mount_flags);
                /* remount read-only */
                if (s->s_flags & MS_RDONLY)
                        /* it is read-only already */
-                       goto out_ok;
+                       goto out_ok_unlocked;
 
-               /*
-                * Drop write lock. Quota will retake it when needed and lock
-                * ordering requires calling dquot_suspend() without it.
-                */
-               reiserfs_write_unlock(s);
                err = dquot_suspend(s, -1);
                if (err < 0)
                        goto out_err;
-               reiserfs_write_lock(s);
 
                /* try to remount file system with read-only permissions */
                if (sb_umount_state(rs) == REISERFS_VALID_FS
                    || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
-                       goto out_ok;
+                       goto out_ok_unlocked;
                }
 
+               reiserfs_write_lock(s);
+
                err = journal_begin(&th, s, 10);
                if (err)
-                       goto out_unlock;
+                       goto out_err_unlock;
 
                /* Mounting a rw partition read-only. */
                reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
                set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
-               journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
+               journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
        } else {
                /* remount read-write */
                if (!(s->s_flags & MS_RDONLY)) {
+                       reiserfs_write_unlock(s);
                        reiserfs_xattr_init(s, *mount_flags);
-                       goto out_ok   /* We are read-write already */
+                       goto out_ok_unlocked;   /* We are read-write already */
                }
 
                if (reiserfs_is_journal_aborted(journal)) {
                        err = journal->j_errno;
-                       goto out_unlock;
+                       goto out_err_unlock;
                }
 
                handle_data_mode(s, mount_options);
                handle_barrier_mode(s, mount_options);
                REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
-               s->s_flags &= ~MS_RDONLY;       /* now it is safe to call journal_begin */
+
+               /* now it is safe to call journal_begin */
+               s->s_flags &= ~MS_RDONLY;
                err = journal_begin(&th, s, 10);
                if (err)
-                       goto out_unlock;
+                       goto out_err_unlock;
 
                /* Mount a partition which is read-only, read-write */
                reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
@@ -1441,33 +1535,29 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
                if (!old_format_only(s))
                        set_sb_mnt_count(rs, sb_mnt_count(rs) + 1);
                /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
-               journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
+               journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
                REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
        }
        /* this will force a full flush of all journal lists */
        SB_JOURNAL(s)->j_must_wait = 1;
-       err = journal_end(&th, s, 10);
+       err = journal_end(&th);
        if (err)
-               goto out_unlock;
+               goto out_err_unlock;
 
+       reiserfs_write_unlock(s);
        if (!(*mount_flags & MS_RDONLY)) {
-               /*
-                * Drop write lock. Quota will retake it when needed and lock
-                * ordering requires calling dquot_resume() without it.
-                */
-               reiserfs_write_unlock(s);
                dquot_resume(s, -1);
                reiserfs_write_lock(s);
                finish_unfinished(s);
+               reiserfs_write_unlock(s);
                reiserfs_xattr_init(s, *mount_flags);
        }
 
-out_ok:
+out_ok_unlocked:
        replace_mount_options(s, new_opts);
-       reiserfs_write_unlock(s);
        return 0;
 
-out_unlock:
+out_err_unlock:
        reiserfs_write_unlock(s);
 out_err:
        kfree(new_opts);
@@ -1484,7 +1574,7 @@ static int read_super_block(struct super_block *s, int offset)
        if (!bh) {
                reiserfs_warning(s, "sh-2006",
                                 "bread failed (dev %s, block %lu, size %lu)",
-                                reiserfs_bdevname(s), offset / s->s_blocksize,
+                                s->s_id, offset / s->s_blocksize,
                                 s->s_blocksize);
                return 1;
        }
@@ -1494,9 +1584,9 @@ static int read_super_block(struct super_block *s, int offset)
                brelse(bh);
                return 1;
        }
-       //
-       // ok, reiserfs signature (old or new) found in at the given 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);
@@ -1505,7 +1595,7 @@ static int read_super_block(struct super_block *s, int offset)
        if (!bh) {
                reiserfs_warning(s, "sh-2007",
                                 "bread failed (dev %s, block %lu, size %lu)",
-                                reiserfs_bdevname(s), offset / s->s_blocksize,
+                                s->s_id, offset / s->s_blocksize,
                                 s->s_blocksize);
                return 1;
        }
@@ -1513,8 +1603,8 @@ static int read_super_block(struct super_block *s, int offset)
        rs = (struct reiserfs_super_block *)bh->b_data;
        if (sb_blocksize(rs) != s->s_blocksize) {
                reiserfs_warning(s, "sh-2011", "can't find a reiserfs "
-                                "filesystem on (dev %s, block %Lu, size %lu)",
-                                reiserfs_bdevname(s),
+                                "filesystem on (dev %s, block %llu, size %lu)",
+                                s->s_id,
                                 (unsigned long long)bh->b_blocknr,
                                 s->s_blocksize);
                brelse(bh);
@@ -1534,9 +1624,11 @@ static int read_super_block(struct super_block *s, int offset)
        SB_BUFFER_WITH_SB(s) = bh;
        SB_DISK_SUPER_BLOCK(s) = rs;
 
+       /*
+        * magic is of non-standard journal filesystem, look at s_version to
+        * find which format is in use
+        */
        if (is_reiserfs_jr(rs)) {
-               /* magic is of non-standard journal filesystem, look at s_version to
-                  find which format is in use */
                if (sb_version(rs) == REISERFS_VERSION_2)
                        reiserfs_info(s, "found reiserfs format \"3.6\""
                                      " with non-standard journal\n");
@@ -1550,8 +1642,10 @@ static int read_super_block(struct super_block *s, int offset)
                        return 1;
                }
        } else
-               /* s_version of standard format may contain incorrect information,
-                  so we just look at the magic string */
+               /*
+                * s_version of standard format may contain incorrect
+                * information, so we just look at the magic string
+                */
                reiserfs_info(s,
                              "found reiserfs format \"%s\" with standard journal\n",
                              is_reiserfs_3_5(rs) ? "3.5" : "3.6");
@@ -1561,10 +1655,12 @@ static int read_super_block(struct super_block *s, int offset)
 #ifdef CONFIG_QUOTA
        s->s_qcop = &reiserfs_qctl_operations;
        s->dq_op = &reiserfs_quota_operations;
+       s->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
 #endif
 
-       /* new format is limited by the 32 bit wide i_blocks field, want to
-        ** be one full block below that.
+       /*
+        * new format is limited by the 32 bit wide i_blocks field, want to
+        * be one full block below that.
         */
        s->s_maxbytes = (512LL << 32) - s->s_blocksize;
        return 0;
@@ -1573,7 +1669,7 @@ static int read_super_block(struct super_block *s, int offset)
 /* after journal replay, reread all bitmap and super blocks */
 static int reread_meta_blocks(struct super_block *s)
 {
-       ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
+       ll_rw_block(READ, 1, &SB_BUFFER_WITH_SB(s));
        wait_on_buffer(SB_BUFFER_WITH_SB(s));
        if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
                reiserfs_warning(s, "reiserfs-2504", "error reading the super");
@@ -1583,14 +1679,15 @@ static int reread_meta_blocks(struct super_block *s)
        return 0;
 }
 
-/////////////////////////////////////////////////////
-// hash detection stuff
+/* hash detection stuff */
 
-// if root directory is empty - we set default - Yura's - hash and
-// warn about it
-// FIXME: we look for only one name in a directory. If tea and yura
-// bith have the same value - we ask user to send report to the
-// mailing list
+/*
+ * if root directory is empty - we set default - Yura's - hash and
+ * warn about it
+ * FIXME: we look for only one name in a directory. If tea and yura
+ * both have the same value - we ask user to send report to the
+ * mailing list
+ */
 static __u32 find_hash_out(struct super_block *s)
 {
        int retval;
@@ -1598,92 +1695,83 @@ static __u32 find_hash_out(struct super_block *s)
        struct cpu_key key;
        INITIALIZE_PATH(path);
        struct reiserfs_dir_entry de;
+       struct reiserfs_de_head *deh;
        __u32 hash = DEFAULT_HASH;
+       __u32 deh_hashval, teahash, r5hash, yurahash;
 
-       inode = s->s_root->d_inode;
+       inode = d_inode(s->s_root);
 
-       do {                    // Some serious "goto"-hater was there ;)
-               u32 teahash, r5hash, yurahash;
+       make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
+       retval = search_by_entry_key(s, &key, &path, &de);
+       if (retval == IO_ERROR) {
+               pathrelse(&path);
+               return UNSET_HASH;
+       }
+       if (retval == NAME_NOT_FOUND)
+               de.de_entry_num--;
 
-               make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
-               retval = search_by_entry_key(s, &key, &path, &de);
-               if (retval == IO_ERROR) {
-                       pathrelse(&path);
-                       return UNSET_HASH;
-               }
-               if (retval == NAME_NOT_FOUND)
-                       de.de_entry_num--;
-               set_de_name_and_namelen(&de);
-               if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
-                       /* allow override in this case */
-                       if (reiserfs_rupasov_hash(s)) {
-                               hash = YURA_HASH;
-                       }
-                       reiserfs_info(s, "FS seems to be empty, autodetect "
-                                        "is using the default hash\n");
-                       break;
-               }
-               r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
-               teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
-               yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
-               if (((teahash == r5hash)
-                    &&
-                    (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
-                     == r5hash)) || ((teahash == yurahash)
-                                     && (yurahash ==
-                                         GET_HASH_VALUE(deh_offset
-                                                        (&
-                                                         (de.
-                                                          de_deh[de.
-                                                                 de_entry_num])))))
-                   || ((r5hash == yurahash)
-                       && (yurahash ==
-                           GET_HASH_VALUE(deh_offset
-                                          (&(de.de_deh[de.de_entry_num])))))) {
-                       reiserfs_warning(s, "reiserfs-2506", "Unable to "
-                                        "automatically detect hash function. "
-                                        "Please mount with -o "
-                                        "hash={tea,rupasov,r5}");
-                       hash = UNSET_HASH;
-                       break;
-               }
-               if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
-                   yurahash)
+       set_de_name_and_namelen(&de);
+       deh = de.de_deh + de.de_entry_num;
+
+       if (deh_offset(deh) == DOT_DOT_OFFSET) {
+               /* allow override in this case */
+               if (reiserfs_rupasov_hash(s))
                        hash = YURA_HASH;
-               else if (GET_HASH_VALUE
-                        (deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
-                       hash = TEA_HASH;
-               else if (GET_HASH_VALUE
-                        (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
-                       hash = R5_HASH;
-               else {
-                       reiserfs_warning(s, "reiserfs-2506",
-                                        "Unrecognised hash function");
-                       hash = UNSET_HASH;
-               }
-       } while (0);
+               reiserfs_info(s, "FS seems to be empty, autodetect is using the default hash\n");
+               goto out;
+       }
 
+       deh_hashval = GET_HASH_VALUE(deh_offset(deh));
+       r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
+       teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
+       yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
+
+       if ((teahash == r5hash && deh_hashval == r5hash) ||
+           (teahash == yurahash && deh_hashval == yurahash) ||
+           (r5hash == yurahash && deh_hashval == yurahash)) {
+               reiserfs_warning(s, "reiserfs-2506",
+                                "Unable to automatically detect hash "
+                                "function. Please mount with -o "
+                                "hash={tea,rupasov,r5}");
+               hash = UNSET_HASH;
+               goto out;
+       }
+
+       if (deh_hashval == yurahash)
+               hash = YURA_HASH;
+       else if (deh_hashval == teahash)
+               hash = TEA_HASH;
+       else if (deh_hashval == r5hash)
+               hash = R5_HASH;
+       else {
+               reiserfs_warning(s, "reiserfs-2506",
+                                "Unrecognised hash function");
+               hash = UNSET_HASH;
+       }
+out:
        pathrelse(&path);
        return hash;
 }
 
-// finds out which hash names are sorted with
+/* finds out which hash names are sorted with */
 static int what_hash(struct super_block *s)
 {
        __u32 code;
 
        code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
 
-       /* reiserfs_hash_detect() == true if any of the hash mount options
-        ** were used.  We must check them to make sure the user isn't
-        ** using a bad hash value
+       /*
+        * reiserfs_hash_detect() == true if any of the hash mount options
+        * were used.  We must check them to make sure the user isn't
+        * using a bad hash value
         */
        if (code == UNSET_HASH || reiserfs_hash_detect(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",
@@ -1705,7 +1793,10 @@ static int what_hash(struct super_block *s)
                        code = UNSET_HASH;
                }
        } else {
-               /* find_hash_out was not called or could not determine the hash */
+               /*
+                * find_hash_out was not called or
+                * could not determine the hash
+                */
                if (reiserfs_rupasov_hash(s)) {
                        code = YURA_HASH;
                } else if (reiserfs_tea_hash(s)) {
@@ -1715,8 +1806,9 @@ static int what_hash(struct super_block *s)
                }
        }
 
-       /* if we are mounted RW, and we have a new valid hash code, update
-        ** the super
+       /*
+        * if we are mounted RW, and we have a new valid hash code, update
+        * the super
         */
        if (code != UNSET_HASH &&
            !(s->s_flags & MS_RDONLY) &&
@@ -1726,7 +1818,7 @@ static int what_hash(struct super_block *s)
        return code;
 }
 
-// return pointer to appropriate function
+/* return pointer to appropriate function */
 static hashf_t hash_function(struct super_block *s)
 {
        switch (what_hash(s)) {
@@ -1743,7 +1835,7 @@ static hashf_t hash_function(struct super_block *s)
        return NULL;
 }
 
-// this is used to set up correct value for old partitions
+/* this is used to set up correct value for old partitions */
 static int function2code(hashf_t func)
 {
        if (func == keyed_hash)
@@ -1753,7 +1845,7 @@ static int function2code(hashf_t func)
        if (func == r5_hash)
                return R5_HASH;
 
-       BUG();                  // should never happen
+       BUG();                  /* should never happen */
 
        return 0;
 }
@@ -1775,7 +1867,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
        char *jdev_name;
        struct reiserfs_sb_info *sbi;
        int errval = -EINVAL;
-       char *qf_names[MAXQUOTAS] = {};
+       char *qf_names[REISERFS_MAXQUOTAS] = {};
        unsigned int qfmt = 0;
 
        save_mount_options(s, data);
@@ -1788,8 +1880,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
        sbi->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
        sbi->s_mount_opt |= (1 << REISERFS_ERROR_RO);
        sbi->s_mount_opt |= (1 << REISERFS_BARRIER_FLUSH);
-       /* no preallocation minimum, be smart in
-          reiserfs_file_write instead */
+       /* no preallocation minimum, be smart in reiserfs_file_write instead */
        sbi->s_alloc_options.preallocmin = 0;
        /* Preallocate by 16 blocks (17-1) at once */
        sbi->s_alloc_options.preallocsize = 17;
@@ -1801,9 +1892,17 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
        mutex_init(&sbi->lock);
        sbi->lock_depth = -1;
 
+       sbi->commit_wq = alloc_workqueue("reiserfs/%s", WQ_MEM_RECLAIM, 0,
+                                        s->s_id);
+       if (!sbi->commit_wq) {
+               SWARN(silent, s, "", "Cannot allocate commit workqueue");
+               errval = -ENOMEM;
+               goto error_unlocked;
+       }
+
        jdev_name = NULL;
        if (reiserfs_parse_options
-           (s, (char *)data, &(sbi->s_mount_opt), &blocks, &jdev_name,
+           (s, (char *)data, &sbi->s_mount_opt, &blocks, &jdev_name,
             &commit_max_age, qf_names, &qfmt) == 0) {
                goto error_unlocked;
        }
@@ -1824,20 +1923,29 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
                goto error_unlocked;
        }
 
-       /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
+       /*
+        * try old format (undistributed bitmap, super block in 8-th 1k
+        * block of a device)
+        */
        if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
                old_format = 1;
-       /* try new format (64-th 1k block), which can contain reiserfs super block */
+
+       /*
+        * try new format (64-th 1k block), which can contain reiserfs
+        * super block
+        */
        else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
                SWARN(silent, s, "sh-2021", "can not find reiserfs on %s",
-                     reiserfs_bdevname(s));
+                     s->s_id);
                goto error_unlocked;
        }
 
        rs = SB_DISK_SUPER_BLOCK(s);
-       /* Let's do basic sanity check to verify that underlying device is not
-          smaller than the filesystem. If the check fails then abort and scream,
-          because bad stuff will happen otherwise. */
+       /*
+        * Let's do basic sanity check to verify that underlying device is not
+        * smaller than the filesystem. If the check fails then abort and
+        * scream, because bad stuff will happen otherwise.
+        */
        if (s->s_bdev && s->s_bdev->bd_inode
            && i_size_read(s->s_bdev->bd_inode) <
            sb_block_count(rs) * sb_blocksize(rs)) {
@@ -1881,15 +1989,16 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
                printk("reiserfs: using flush barriers\n");
        }
 
-       // set_device_ro(s->s_dev, 1) ;
        if (journal_init(s, jdev_name, old_format, commit_max_age)) {
                SWARN(silent, s, "sh-2022",
                      "unable to initialize journal space");
                goto error_unlocked;
        } else {
-               jinit_done = 1; /* once this is set, journal_release must be called
-                                ** if we error out of the mount
-                                */
+               /*
+                * once this is set, journal_release must be called
+                * if we error out of the mount
+                */
+               jinit_done = 1;
        }
 
        if (reread_meta_blocks(s)) {
@@ -1910,7 +2019,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
        args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
        root_inode =
            iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
-                        reiserfs_init_locked_inode, (void *)(&args));
+                        reiserfs_init_locked_inode, (void *)&args);
        if (!root_inode) {
                SWARN(silent, s, "jmacd-10", "get root inode failed");
                goto error_unlocked;
@@ -1934,7 +2043,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
        s->s_root = d_make_root(root_inode);
        if (!s->s_root)
                goto error;
-       // define and initialize hash function
+       /* define and initialize hash function */
        sbi->s_hash_function = hash_function(s);
        if (sbi->s_hash_function == NULL) {
                dput(s->s_root);
@@ -1944,11 +2053,11 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
 
        if (is_reiserfs_3_5(rs)
            || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
-               set_bit(REISERFS_3_5, &(sbi->s_properties));
+               set_bit(REISERFS_3_5, &sbi->s_properties);
        else if (old_format)
-               set_bit(REISERFS_OLD_FORMAT, &(sbi->s_properties));
+               set_bit(REISERFS_OLD_FORMAT, &sbi->s_properties);
        else
-               set_bit(REISERFS_3_6, &(sbi->s_properties));
+               set_bit(REISERFS_3_6, &sbi->s_properties);
 
        if (!(s->s_flags & MS_RDONLY)) {
 
@@ -1963,10 +2072,12 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
                set_sb_umount_state(rs, REISERFS_ERROR_FS);
                set_sb_fs_state(rs, 0);
 
-               /* Clear out s_bmap_nr if it would wrap. We can handle this
+               /*
+                * Clear out s_bmap_nr if it would wrap. We can handle this
                 * case, but older revisions can't. This will cause the
                 * file system to fail mount on those older implementations,
-                * avoiding corruption. -jeffm */
+                * avoiding corruption. -jeffm
+                */
                if (bmap_would_wrap(reiserfs_bmap_count(s)) &&
                    sb_bmap_nr(rs) != 0) {
                        reiserfs_warning(s, "super-2030", "This file system "
@@ -1979,8 +2090,10 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
                }
 
                if (old_format_only(s)) {
-                       /* filesystem of format 3.5 either with standard or non-standard
-                          journal */
+                       /*
+                        * filesystem of format 3.5 either with standard
+                        * or non-standard journal
+                        */
                        if (convert_reiserfs(s)) {
                                /* and -o conv is given */
                                if (!silent)
@@ -1988,8 +2101,11 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
                                                      "converting 3.5 filesystem to the 3.6 format");
 
                                if (is_reiserfs_3_5(rs))
-                                       /* put magic string of 3.6 format. 2.2 will not be able to
-                                          mount this filesystem anymore */
+                                       /*
+                                        * put magic string of 3.6 format.
+                                        * 2.2 will not be able to
+                                        * mount this filesystem anymore
+                                        */
                                        memcpy(rs->s_v1.s_magic,
                                               reiserfs_3_6_magic_string,
                                               sizeof
@@ -1997,8 +2113,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
 
                                set_sb_version(rs, REISERFS_VERSION_2);
                                reiserfs_convert_objectid_map_v1(s);
-                               set_bit(REISERFS_3_6, &(sbi->s_properties));
-                               clear_bit(REISERFS_3_5, &(sbi->s_properties));
+                               set_bit(REISERFS_3_6, &sbi->s_properties);
+                               clear_bit(REISERFS_3_5, &sbi->s_properties);
                        } else if (!silent) {
                                reiserfs_info(s, "using 3.5.x disk format\n");
                        }
@@ -2006,36 +2122,44 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
                        set_sb_mnt_count(rs, sb_mnt_count(rs) + 1);
 
 
-               journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
-               errval = journal_end(&th, s, 1);
+               journal_mark_dirty(&th, SB_BUFFER_WITH_SB(s));
+               errval = journal_end(&th);
                if (errval) {
                        dput(s->s_root);
                        s->s_root = NULL;
                        goto error;
                }
 
+               reiserfs_write_unlock(s);
                if ((errval = reiserfs_lookup_privroot(s)) ||
                    (errval = reiserfs_xattr_init(s, s->s_flags))) {
                        dput(s->s_root);
                        s->s_root = NULL;
-                       goto error;
+                       goto error_unlocked;
                }
+               reiserfs_write_lock(s);
 
-               /* look for files which were to be removed in previous session */
+               /*
+                * look for files which were to be removed in previous session
+                */
                finish_unfinished(s);
        } else {
                if (old_format_only(s) && !silent) {
                        reiserfs_info(s, "using 3.5.x disk format\n");
                }
 
+               reiserfs_write_unlock(s);
                if ((errval = reiserfs_lookup_privroot(s)) ||
                    (errval = reiserfs_xattr_init(s, s->s_flags))) {
                        dput(s->s_root);
                        s->s_root = NULL;
-                       goto error;
+                       goto error_unlocked;
                }
+               reiserfs_write_lock(s);
        }
-       // mark hash in super block: it could be unset. overwrite should be ok
+       /*
+        * mark hash in super block: it could be unset. overwrite should be ok
+        */
        set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
 
        handle_attrs(s);
@@ -2060,6 +2184,9 @@ error_unlocked:
                reiserfs_write_unlock(s);
        }
 
+       if (sbi->commit_wq)
+               destroy_workqueue(sbi->commit_wq);
+
        cancel_delayed_work_sync(&REISERFS_SB(s)->old_work);
 
        reiserfs_free_bitmap_cache(s);
@@ -2068,7 +2195,7 @@ error_unlocked:
 #ifdef CONFIG_QUOTA
        {
                int j;
-               for (j = 0; j < MAXQUOTAS; j++)
+               for (j = 0; j < REISERFS_MAXQUOTAS; j++)
                        kfree(qf_names[j]);
        }
 #endif
@@ -2101,6 +2228,7 @@ static int reiserfs_write_dquot(struct dquot *dquot)
 {
        struct reiserfs_transaction_handle th;
        int ret, err;
+       int depth;
 
        reiserfs_write_lock(dquot->dq_sb);
        ret =
@@ -2108,12 +2236,10 @@ static int reiserfs_write_dquot(struct dquot *dquot)
                          REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
        if (ret)
                goto out;
-       reiserfs_write_unlock(dquot->dq_sb);
+       depth = reiserfs_write_unlock_nested(dquot->dq_sb);
        ret = dquot_commit(dquot);
-       reiserfs_write_lock(dquot->dq_sb);
-       err =
-           journal_end(&th, dquot->dq_sb,
-                       REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
+       reiserfs_write_lock_nested(dquot->dq_sb, depth);
+       err = journal_end(&th);
        if (!ret && err)
                ret = err;
 out:
@@ -2125,6 +2251,7 @@ static int reiserfs_acquire_dquot(struct dquot *dquot)
 {
        struct reiserfs_transaction_handle th;
        int ret, err;
+       int depth;
 
        reiserfs_write_lock(dquot->dq_sb);
        ret =
@@ -2132,12 +2259,10 @@ static int reiserfs_acquire_dquot(struct dquot *dquot)
                          REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
        if (ret)
                goto out;
-       reiserfs_write_unlock(dquot->dq_sb);
+       depth = reiserfs_write_unlock_nested(dquot->dq_sb);
        ret = dquot_acquire(dquot);
-       reiserfs_write_lock(dquot->dq_sb);
-       err =
-           journal_end(&th, dquot->dq_sb,
-                       REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
+       reiserfs_write_lock_nested(dquot->dq_sb, depth);
+       err = journal_end(&th);
        if (!ret && err)
                ret = err;
 out:
@@ -2162,9 +2287,7 @@ static int reiserfs_release_dquot(struct dquot *dquot)
        }
        ret = dquot_release(dquot);
        reiserfs_write_lock(dquot->dq_sb);
-       err =
-           journal_end(&th, dquot->dq_sb,
-                       REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
+       err = journal_end(&th);
        if (!ret && err)
                ret = err;
        reiserfs_write_unlock(dquot->dq_sb);
@@ -2187,16 +2310,17 @@ static int reiserfs_write_info(struct super_block *sb, int type)
 {
        struct reiserfs_transaction_handle th;
        int ret, err;
+       int depth;
 
        /* Data block + inode block */
        reiserfs_write_lock(sb);
        ret = journal_begin(&th, sb, 2);
        if (ret)
                goto out;
-       reiserfs_write_unlock(sb);
+       depth = reiserfs_write_unlock_nested(sb);
        ret = dquot_commit_info(sb, type);
-       reiserfs_write_lock(sb);
-       err = journal_end(&th, sb, 2);
+       reiserfs_write_lock_nested(sb, depth);
+       err = journal_end(&th);
        if (!ret && err)
                ret = err;
 out:
@@ -2235,8 +2359,11 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
                err = -EXDEV;
                goto out;
        }
-       inode = path->dentry->d_inode;
-       /* We must not pack tails for quota files on reiserfs for quota IO to work */
+       inode = d_inode(path->dentry);
+       /*
+        * We must not pack tails for quota files on reiserfs for quota
+        * IO to work
+        */
        if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) {
                err = reiserfs_unpack(inode, NULL);
                if (err) {
@@ -2266,7 +2393,7 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
                err = journal_begin(&th, sb, 1);
                if (err)
                        goto out;
-               err = journal_end_sync(&th, sb, 1);
+               err = journal_end_sync(&th);
                if (err)
                        goto out;
        }
@@ -2277,10 +2404,12 @@ out:
        return err;
 }
 
-/* Read data from quotafile - avoid pagecache and such because we cannot afford
+/*
+ * Read data from quotafile - avoid pagecache and such because we cannot afford
  * acquiring the locks... As quota files are never truncated and quota code
  * itself serializes the operations (and no one else should touch the files)
- * we don't have to be afraid of races */
+ * we don't have to be afraid of races
+ */
 static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
                                   size_t len, loff_t off)
 {
@@ -2301,7 +2430,10 @@ static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
                    sb->s_blocksize - offset <
                    toread ? sb->s_blocksize - offset : toread;
                tmp_bh.b_state = 0;
-               /* Quota files are without tails so we can safely use this function */
+               /*
+                * Quota files are without tails so we can safely
+                * use this function
+                */
                reiserfs_write_lock(sb);
                err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
                reiserfs_write_unlock(sb);
@@ -2324,8 +2456,10 @@ static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
        return len;
 }
 
-/* Write to quotafile (we know the transaction is already started and has
- * enough credits) */
+/*
+ * Write to quotafile (we know the transaction is already started and has
+ * enough credits)
+ */
 static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
                                    const char *data, size_t len, loff_t off)
 {
@@ -2337,8 +2471,7 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
        struct buffer_head tmp_bh, *bh;
 
        if (!current->journal_info) {
-               printk(KERN_WARNING "reiserfs: Quota write (off=%Lu, len=%Lu)"
-                       " cancelled because transaction is not started.\n",
+               printk(KERN_WARNING "reiserfs: Quota write (off=%llu, len=%llu) cancelled because transaction is not started.\n",
                        (unsigned long long)off, (unsigned long long)len);
                return -EIO;
        }
@@ -2366,7 +2499,7 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
                unlock_buffer(bh);
                reiserfs_write_lock(sb);
                reiserfs_prepare_for_journal(sb, bh, 1);
-               journal_mark_dirty(current->journal_info, sb, bh);
+               journal_mark_dirty(current->journal_info, bh);
                if (!journal_quota)
                        reiserfs_add_ordered_list(inode, bh);
                reiserfs_write_unlock(sb);
@@ -2400,18 +2533,18 @@ static int __init init_reiserfs_fs(void)
 {
        int ret;
 
-       if ((ret = init_inodecache())) {
+       ret = init_inodecache();
+       if (ret)
                return ret;
-       }
 
        reiserfs_proc_info_global_init();
 
        ret = register_filesystem(&reiserfs_fs_type);
+       if (ret)
+               goto out;
 
-       if (ret == 0) {
-               return 0;
-       }
-
+       return 0;
+out:
        reiserfs_proc_info_global_done();
        destroy_inodecache();