ocfs2: add IO error check in ocfs2_get_sector()
[safe/jmp/linux-2.6] / fs / ocfs2 / super.c
index 479ac50..7ac83a8 100644 (file)
@@ -40,8 +40,8 @@
 #include <linux/crc32.h>
 #include <linux/debugfs.h>
 #include <linux/mount.h>
-
-#include <cluster/nodemanager.h>
+#include <linux/seq_file.h>
+#include <linux/quotaops.h>
 
 #define MLOG_MASK_PREFIX ML_SUPER
 #include <cluster/masklog.h>
@@ -52,6 +52,7 @@
 #include "ocfs1_fs_compat.h"
 
 #include "alloc.h"
+#include "blockcheck.h"
 #include "dlmglue.h"
 #include "export.h"
 #include "extent_map.h"
 #include "sysfile.h"
 #include "uptodate.h"
 #include "ver.h"
+#include "xattr.h"
+#include "quota.h"
 
 #include "buffer_head_io.h"
 
 static struct kmem_cache *ocfs2_inode_cachep = NULL;
+struct kmem_cache *ocfs2_dquot_cachep;
+struct kmem_cache *ocfs2_qf_chunk_cachep;
 
 /* OCFS2 needs to schedule several differnt types of work which
  * require cluster locking, disk I/O, recovery waits, etc. Since these
@@ -83,9 +88,12 @@ MODULE_LICENSE("GPL");
 
 struct mount_options
 {
+       unsigned long   commit_interval;
        unsigned long   mount_opt;
        unsigned int    atime_quantum;
        signed short    slot;
+       unsigned int    localalloc_opt;
+       char            cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
 };
 
 static int ocfs2_parse_options(struct super_block *sb, char *options,
@@ -107,7 +115,6 @@ static int ocfs2_sync_fs(struct super_block *sb, int wait);
 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
 static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
 static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
-static int ocfs2_fill_local_node_info(struct ocfs2_super *osb);
 static int ocfs2_check_volume(struct ocfs2_super *osb);
 static int ocfs2_verify_volume(struct ocfs2_dinode *di,
                               struct buffer_head *bh,
@@ -122,6 +129,9 @@ static int ocfs2_get_sector(struct super_block *sb,
 static void ocfs2_write_super(struct super_block *sb);
 static struct inode *ocfs2_alloc_inode(struct super_block *sb);
 static void ocfs2_destroy_inode(struct inode *inode);
+static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
+static int ocfs2_enable_quotas(struct ocfs2_super *osb);
+static void ocfs2_disable_quotas(struct ocfs2_super *osb);
 
 static const struct super_operations ocfs2_sops = {
        .statfs         = ocfs2_statfs,
@@ -135,6 +145,8 @@ static const struct super_operations ocfs2_sops = {
        .put_super      = ocfs2_put_super,
        .remount_fs     = ocfs2_remount,
        .show_options   = ocfs2_show_options,
+       .quota_read     = ocfs2_quota_read,
+       .quota_write    = ocfs2_quota_write,
 };
 
 enum {
@@ -149,10 +161,21 @@ enum {
        Opt_data_writeback,
        Opt_atime_quantum,
        Opt_slot,
+       Opt_commit,
+       Opt_localalloc,
+       Opt_localflocks,
+       Opt_stack,
+       Opt_user_xattr,
+       Opt_nouser_xattr,
+       Opt_inode64,
+       Opt_acl,
+       Opt_noacl,
+       Opt_usrquota,
+       Opt_grpquota,
        Opt_err,
 };
 
-static match_table_t tokens = {
+static const match_table_t tokens = {
        {Opt_barrier, "barrier=%u"},
        {Opt_err_panic, "errors=panic"},
        {Opt_err_ro, "errors=remount-ro"},
@@ -164,6 +187,17 @@ static match_table_t tokens = {
        {Opt_data_writeback, "data=writeback"},
        {Opt_atime_quantum, "atime_quantum=%u"},
        {Opt_slot, "preferred_slot=%u"},
+       {Opt_commit, "commit=%u"},
+       {Opt_localalloc, "localalloc=%d"},
+       {Opt_localflocks, "localflocks"},
+       {Opt_stack, "cluster_stack=%s"},
+       {Opt_user_xattr, "user_xattr"},
+       {Opt_nouser_xattr, "nouser_xattr"},
+       {Opt_inode64, "inode64"},
+       {Opt_acl, "acl"},
+       {Opt_noacl, "noacl"},
+       {Opt_usrquota, "usrquota"},
+       {Opt_grpquota, "grpquota"},
        {Opt_err, NULL}
 };
 
@@ -196,14 +230,28 @@ static int ocfs2_sync_fs(struct super_block *sb, int wait)
                ocfs2_schedule_truncate_log_flush(osb, 0);
        }
 
-       if (journal_start_commit(OCFS2_SB(sb)->journal->j_journal, &target)) {
+       if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
+                                     &target)) {
                if (wait)
-                       log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
-                                       target);
+                       jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
+                                            target);
        }
        return 0;
 }
 
+static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
+{
+       if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
+           && (ino == USER_QUOTA_SYSTEM_INODE
+               || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
+               return 0;
+       if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
+           && (ino == GROUP_QUOTA_SYSTEM_INODE
+               || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
+               return 0;
+       return 1;
+}
+
 static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
 {
        struct inode *new = NULL;
@@ -212,7 +260,7 @@ static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
 
        mlog_entry_void();
 
-       new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE);
+       new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
        if (IS_ERR(new)) {
                status = PTR_ERR(new);
                mlog_errno(status);
@@ -220,7 +268,7 @@ static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
        }
        osb->root_inode = new;
 
-       new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE);
+       new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
        if (IS_ERR(new)) {
                status = PTR_ERR(new);
                mlog_errno(status);
@@ -230,6 +278,8 @@ static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
 
        for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
             i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
+               if (!ocfs2_need_system_inode(osb, i))
+                       continue;
                new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
                if (!new) {
                        ocfs2_release_system_inodes(osb);
@@ -260,6 +310,8 @@ static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
        for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
             i < NUM_SYSTEM_INODES;
             i++) {
+               if (!ocfs2_need_system_inode(osb, i))
+                       continue;
                new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
                if (!new) {
                        ocfs2_release_system_inodes(osb);
@@ -316,6 +368,7 @@ static struct inode *ocfs2_alloc_inode(struct super_block *sb)
        if (!oi)
                return NULL;
 
+       jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
        return &oi->vfs_inode;
 }
 
@@ -397,8 +450,23 @@ static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
                goto out;
        }
 
+       /* Probably don't want this on remount; it might
+        * mess with other nodes */
+       if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
+           (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
+               ret = -EINVAL;
+               mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
+               goto out;
+       }
+
        /* We're going to/from readonly mode. */
        if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
+               /* Disable quota accounting before remounting RO */
+               if (*flags & MS_RDONLY) {
+                       ret = ocfs2_susp_quotas(osb, 0);
+                       if (ret < 0)
+                               goto out;
+               }
                /* Lock here so the check of HARD_RO and the potential
                 * setting of SOFT_RO is atomic. */
                spin_lock(&osb->osb_lock);
@@ -434,14 +502,33 @@ static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
                }
 unlock_osb:
                spin_unlock(&osb->osb_lock);
+               /* Enable quota accounting after remounting RW */
+               if (!ret && !(*flags & MS_RDONLY)) {
+                       if (sb_any_quota_suspended(sb))
+                               ret = ocfs2_susp_quotas(osb, 1);
+                       else
+                               ret = ocfs2_enable_quotas(osb);
+                       if (ret < 0) {
+                               /* Return back changes... */
+                               spin_lock(&osb->osb_lock);
+                               sb->s_flags |= MS_RDONLY;
+                               osb->osb_flags |= OCFS2_OSB_SOFT_RO;
+                               spin_unlock(&osb->osb_lock);
+                               goto out;
+                       }
+               }
        }
 
        if (!ret) {
                /* Only save off the new mount options in case of a successful
                 * remount. */
+               if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
+                       parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
                osb->s_mount_opt = parsed_options.mount_opt;
                osb->s_atime_quantum = parsed_options.atime_quantum;
                osb->preferred_slot = parsed_options.slot;
+               if (parsed_options.commit_interval)
+                       osb->osb_commit_interval = parsed_options.commit_interval;
 
                if (!ocfs2_is_hard_readonly(osb))
                        ocfs2_set_journal_params(osb);
@@ -541,8 +628,17 @@ static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
                }
        }
 
+       if (ocfs2_userspace_stack(osb)) {
+               if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
+                       mlog(ML_ERROR, "Userspace stack expected, but "
+                            "o2cb heartbeat arguments passed to mount\n");
+                       return -EINVAL;
+               }
+       }
+
        if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
-               if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb)) {
+               if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
+                   !ocfs2_userspace_stack(osb)) {
                        mlog(ML_ERROR, "Heartbeat has to be started to mount "
                             "a read-write clustered device.\n");
                        return -EINVAL;
@@ -552,6 +648,160 @@ static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
        return 0;
 }
 
+/*
+ * If we're using a userspace stack, mount should have passed
+ * a name that matches the disk.  If not, mount should not
+ * have passed a stack.
+ */
+static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
+                                       struct mount_options *mopt)
+{
+       if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
+               mlog(ML_ERROR,
+                    "cluster stack passed to mount, but this filesystem "
+                    "does not support it\n");
+               return -EINVAL;
+       }
+
+       if (ocfs2_userspace_stack(osb) &&
+           strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
+                   OCFS2_STACK_LABEL_LEN)) {
+               mlog(ML_ERROR,
+                    "cluster stack passed to mount (\"%s\") does not "
+                    "match the filesystem (\"%s\")\n",
+                    mopt->cluster_stack,
+                    osb->osb_cluster_stack);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
+{
+       int type;
+       struct super_block *sb = osb->sb;
+       unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
+                                            OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
+       int status = 0;
+
+       for (type = 0; type < MAXQUOTAS; type++) {
+               if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
+                       continue;
+               if (unsuspend)
+                       status = vfs_quota_enable(
+                                       sb_dqopt(sb)->files[type],
+                                       type, QFMT_OCFS2,
+                                       DQUOT_SUSPENDED);
+               else
+                       status = vfs_quota_disable(sb, type,
+                                                  DQUOT_SUSPENDED);
+               if (status < 0)
+                       break;
+       }
+       if (status < 0)
+               mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
+                    "remount (error = %d).\n", status);
+       return status;
+}
+
+static int ocfs2_enable_quotas(struct ocfs2_super *osb)
+{
+       struct inode *inode[MAXQUOTAS] = { NULL, NULL };
+       struct super_block *sb = osb->sb;
+       unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
+                                            OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
+       unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
+                                       LOCAL_GROUP_QUOTA_SYSTEM_INODE };
+       int status;
+       int type;
+
+       sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
+       for (type = 0; type < MAXQUOTAS; type++) {
+               if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
+                       continue;
+               inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
+                                                       osb->slot_num);
+               if (!inode[type]) {
+                       status = -ENOENT;
+                       goto out_quota_off;
+               }
+               status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
+                                               DQUOT_USAGE_ENABLED);
+               if (status < 0)
+                       goto out_quota_off;
+       }
+
+       for (type = 0; type < MAXQUOTAS; type++)
+               iput(inode[type]);
+       return 0;
+out_quota_off:
+       ocfs2_disable_quotas(osb);
+       for (type = 0; type < MAXQUOTAS; type++)
+               iput(inode[type]);
+       mlog_errno(status);
+       return status;
+}
+
+static void ocfs2_disable_quotas(struct ocfs2_super *osb)
+{
+       int type;
+       struct inode *inode;
+       struct super_block *sb = osb->sb;
+
+       /* We mostly ignore errors in this function because there's not much
+        * we can do when we see them */
+       for (type = 0; type < MAXQUOTAS; type++) {
+               if (!sb_has_quota_loaded(sb, type))
+                       continue;
+               inode = igrab(sb->s_dquot.files[type]);
+               /* Turn off quotas. This will remove all dquot structures from
+                * memory and so they will be automatically synced to global
+                * quota files */
+               vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
+                                           DQUOT_LIMITS_ENABLED);
+               if (!inode)
+                       continue;
+               iput(inode);
+       }
+}
+
+/* Handle quota on quotactl */
+static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
+                         char *path, int remount)
+{
+       unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
+                                            OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
+
+       if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
+               return -EINVAL;
+
+       if (remount)
+               return 0;       /* Just ignore it has been handled in
+                                * ocfs2_remount() */
+       return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
+                                   format_id, DQUOT_LIMITS_ENABLED);
+}
+
+/* Handle quota off quotactl */
+static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
+{
+       if (remount)
+               return 0;       /* Ignore now and handle later in
+                                * ocfs2_remount() */
+       return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
+}
+
+static struct quotactl_ops ocfs2_quotactl_ops = {
+       .quota_on       = ocfs2_quota_on,
+       .quota_off      = ocfs2_quota_off,
+       .quota_sync     = vfs_quota_sync,
+       .get_info       = vfs_get_dqinfo,
+       .set_info       = vfs_set_dqinfo,
+       .get_dqblk      = vfs_get_dqblk,
+       .set_dqblk      = vfs_set_dqblk,
+};
+
 static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
 {
        struct dentry *root;
@@ -569,15 +819,6 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
                goto read_super_error;
        }
 
-       /* for now we only have one cluster/node, make sure we see it
-        * in the heartbeat universe */
-       if (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL) {
-               if (!o2hb_check_local_node_heartbeating()) {
-                       status = -EINVAL;
-                       goto read_super_error;
-               }
-       }
-
        /* probe for superblock */
        status = ocfs2_sb_probe(sb, &bh, &sector_size);
        if (status < 0) {
@@ -593,12 +834,42 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
        }
        brelse(bh);
        bh = NULL;
+
+       if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
+               parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
+
        osb->s_mount_opt = parsed_options.mount_opt;
        osb->s_atime_quantum = parsed_options.atime_quantum;
        osb->preferred_slot = parsed_options.slot;
+       osb->osb_commit_interval = parsed_options.commit_interval;
+       osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
+       osb->local_alloc_bits = osb->local_alloc_default_bits;
+       if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA &&
+           !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
+                                        OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
+               status = -EINVAL;
+               mlog(ML_ERROR, "User quotas were requested, but this "
+                    "filesystem does not have the feature enabled.\n");
+               goto read_super_error;
+       }
+       if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA &&
+           !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
+                                        OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
+               status = -EINVAL;
+               mlog(ML_ERROR, "Group quotas were requested, but this "
+                    "filesystem does not have the feature enabled.\n");
+               goto read_super_error;
+       }
+
+       status = ocfs2_verify_userspace_stack(osb, &parsed_options);
+       if (status)
+               goto read_super_error;
 
        sb->s_magic = OCFS2_SUPER_MAGIC;
 
+       sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
+               ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
+
        /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
         * heartbeat=none */
        if (bdev_read_only(sb->s_bdev)) {
@@ -682,7 +953,7 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
        if (ocfs2_mount_local(osb))
                snprintf(nodestr, sizeof(nodestr), "local");
        else
-               snprintf(nodestr, sizeof(nodestr), "%d", osb->node_num);
+               snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
 
        printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
               "with %s data mode.\n",
@@ -693,12 +964,33 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
        atomic_set(&osb->vol_state, VOLUME_MOUNTED);
        wake_up(&osb->osb_mount_event);
 
+       /* Now we can initialize quotas because we can afford to wait
+        * for cluster locks recovery now. That also means that truncation
+        * log recovery can happen but that waits for proper quota setup */
+       if (!(sb->s_flags & MS_RDONLY)) {
+               status = ocfs2_enable_quotas(osb);
+               if (status < 0) {
+                       /* We have to err-out specially here because
+                        * s_root is already set */
+                       mlog_errno(status);
+                       atomic_set(&osb->vol_state, VOLUME_DISABLED);
+                       wake_up(&osb->osb_mount_event);
+                       mlog_exit(status);
+                       return status;
+               }
+       }
+
+       ocfs2_complete_quota_recovery(osb);
+
+       /* Now we wake up again for processes waiting for quotas */
+       atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
+       wake_up(&osb->osb_mount_event);
+
        mlog_exit(status);
        return status;
 
 read_super_error:
-       if (bh != NULL)
-               brelse(bh);
+       brelse(bh);
 
        if (inode)
                iput(inode);
@@ -746,9 +1038,12 @@ static int ocfs2_parse_options(struct super_block *sb,
        mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
                   options ? options : "(none)");
 
+       mopt->commit_interval = 0;
        mopt->mount_opt = 0;
        mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
        mopt->slot = OCFS2_INVALID_SLOT;
+       mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
+       mopt->cluster_stack[0] = '\0';
 
        if (!options) {
                status = 1;
@@ -798,6 +1093,12 @@ static int ocfs2_parse_options(struct super_block *sb,
                case Opt_data_writeback:
                        mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
                        break;
+               case Opt_user_xattr:
+                       mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
+                       break;
+               case Opt_nouser_xattr:
+                       mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
+                       break;
                case Opt_atime_quantum:
                        if (match_int(&args[0], &option)) {
                                status = 0;
@@ -815,6 +1116,98 @@ static int ocfs2_parse_options(struct super_block *sb,
                        if (option)
                                mopt->slot = (s16)option;
                        break;
+               case Opt_commit:
+                       option = 0;
+                       if (match_int(&args[0], &option)) {
+                               status = 0;
+                               goto bail;
+                       }
+                       if (option < 0)
+                               return 0;
+                       if (option == 0)
+                               option = JBD2_DEFAULT_MAX_COMMIT_AGE;
+                       mopt->commit_interval = HZ * option;
+                       break;
+               case Opt_localalloc:
+                       option = 0;
+                       if (match_int(&args[0], &option)) {
+                               status = 0;
+                               goto bail;
+                       }
+                       if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
+                               mopt->localalloc_opt = option;
+                       break;
+               case Opt_localflocks:
+                       /*
+                        * Changing this during remount could race
+                        * flock() requests, or "unbalance" existing
+                        * ones (e.g., a lock is taken in one mode but
+                        * dropped in the other). If users care enough
+                        * to flip locking modes during remount, we
+                        * could add a "local" flag to individual
+                        * flock structures for proper tracking of
+                        * state.
+                        */
+                       if (!is_remount)
+                               mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
+                       break;
+               case Opt_stack:
+                       /* Check both that the option we were passed
+                        * is of the right length and that it is a proper
+                        * string of the right length.
+                        */
+                       if (((args[0].to - args[0].from) !=
+                            OCFS2_STACK_LABEL_LEN) ||
+                           (strnlen(args[0].from,
+                                    OCFS2_STACK_LABEL_LEN) !=
+                            OCFS2_STACK_LABEL_LEN)) {
+                               mlog(ML_ERROR,
+                                    "Invalid cluster_stack option\n");
+                               status = 0;
+                               goto bail;
+                       }
+                       memcpy(mopt->cluster_stack, args[0].from,
+                              OCFS2_STACK_LABEL_LEN);
+                       mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
+                       break;
+               case Opt_inode64:
+                       mopt->mount_opt |= OCFS2_MOUNT_INODE64;
+                       break;
+               case Opt_usrquota:
+                       /* We check only on remount, otherwise features
+                        * aren't yet initialized. */
+                       if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
+                           OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
+                               mlog(ML_ERROR, "User quota requested but "
+                                    "filesystem feature is not set\n");
+                               status = 0;
+                               goto bail;
+                       }
+                       mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
+                       break;
+               case Opt_grpquota:
+                       if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
+                           OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
+                               mlog(ML_ERROR, "Group quota requested but "
+                                    "filesystem feature is not set\n");
+                               status = 0;
+                               goto bail;
+                       }
+                       mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
+                       break;
+#ifdef CONFIG_OCFS2_FS_POSIX_ACL
+               case Opt_acl:
+                       mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
+                       break;
+               case Opt_noacl:
+                       mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
+                       break;
+#else
+               case Opt_acl:
+               case Opt_noacl:
+                       printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
+                       break;
+#endif
                default:
                        mlog(ML_ERROR,
                             "Unrecognized mount option \"%s\" "
@@ -835,6 +1228,7 @@ static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
 {
        struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
        unsigned long opts = osb->s_mount_opt;
+       unsigned int local_alloc_megs;
 
        if (opts & OCFS2_MOUNT_HB_LOCAL)
                seq_printf(s, ",_netdev,heartbeat=local");
@@ -863,6 +1257,40 @@ static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
        if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
                seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
 
+       if (osb->osb_commit_interval)
+               seq_printf(s, ",commit=%u",
+                          (unsigned) (osb->osb_commit_interval / HZ));
+
+       local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
+       if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
+               seq_printf(s, ",localalloc=%d", local_alloc_megs);
+
+       if (opts & OCFS2_MOUNT_LOCALFLOCKS)
+               seq_printf(s, ",localflocks,");
+
+       if (osb->osb_cluster_stack[0])
+               seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
+                          osb->osb_cluster_stack);
+       if (opts & OCFS2_MOUNT_USRQUOTA)
+               seq_printf(s, ",usrquota");
+       if (opts & OCFS2_MOUNT_GRPQUOTA)
+               seq_printf(s, ",grpquota");
+
+       if (opts & OCFS2_MOUNT_NOUSERXATTR)
+               seq_printf(s, ",nouser_xattr");
+       else
+               seq_printf(s, ",user_xattr");
+
+       if (opts & OCFS2_MOUNT_INODE64)
+               seq_printf(s, ",inode64");
+
+#ifdef CONFIG_OCFS2_FS_POSIX_ACL
+       if (opts & OCFS2_MOUNT_POSIX_ACL)
+               seq_printf(s, ",acl");
+       else
+               seq_printf(s, ",noacl");
+#endif
+
        return 0;
 }
 
@@ -898,8 +1326,16 @@ static int __init ocfs2_init(void)
                mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
        }
 
+       status = ocfs2_quota_setup();
+       if (status)
+               goto leave;
+
+       ocfs2_set_locking_protocol();
+
+       status = register_quota_format(&ocfs2_quota_format);
 leave:
        if (status < 0) {
+               ocfs2_quota_shutdown();
                ocfs2_free_mem_caches();
                exit_ocfs2_uptodate_cache();
        }
@@ -916,11 +1352,15 @@ static void __exit ocfs2_exit(void)
 {
        mlog_entry_void();
 
+       ocfs2_quota_shutdown();
+
        if (ocfs2_wq) {
                flush_workqueue(ocfs2_wq);
                destroy_workqueue(ocfs2_wq);
        }
 
+       unregister_quota_format(&ocfs2_quota_format);
+
        debugfs_remove(ocfs2_debugfs_root);
 
        ocfs2_free_mem_caches();
@@ -999,7 +1439,7 @@ bail:
        return status;
 }
 
-static void ocfs2_inode_init_once(struct kmem_cache *cachep, void *data)
+static void ocfs2_inode_init_once(void *data)
 {
        struct ocfs2_inode_info *oi = data;
 
@@ -1013,6 +1453,7 @@ static void ocfs2_inode_init_once(struct kmem_cache *cachep, void *data)
        oi->ip_dir_start_lookup = 0;
 
        init_rwsem(&oi->ip_alloc_sem);
+       init_rwsem(&oi->ip_xattr_sem);
        mutex_init(&oi->ip_io_mutex);
 
        oi->ip_blkno = 0ULL;
@@ -1035,8 +1476,27 @@ static int ocfs2_initialize_mem_caches(void)
                                       (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
                                                SLAB_MEM_SPREAD),
                                       ocfs2_inode_init_once);
-       if (!ocfs2_inode_cachep)
+       ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
+                                       sizeof(struct ocfs2_dquot),
+                                       0,
+                                       (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
+                                               SLAB_MEM_SPREAD),
+                                       NULL);
+       ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
+                                       sizeof(struct ocfs2_quota_chunk),
+                                       0,
+                                       (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
+                                       NULL);
+       if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
+           !ocfs2_qf_chunk_cachep) {
+               if (ocfs2_inode_cachep)
+                       kmem_cache_destroy(ocfs2_inode_cachep);
+               if (ocfs2_dquot_cachep)
+                       kmem_cache_destroy(ocfs2_dquot_cachep);
+               if (ocfs2_qf_chunk_cachep)
+                       kmem_cache_destroy(ocfs2_qf_chunk_cachep);
                return -ENOMEM;
+       }
 
        return 0;
 }
@@ -1045,8 +1505,15 @@ static void ocfs2_free_mem_caches(void)
 {
        if (ocfs2_inode_cachep)
                kmem_cache_destroy(ocfs2_inode_cachep);
-
        ocfs2_inode_cachep = NULL;
+
+       if (ocfs2_dquot_cachep)
+               kmem_cache_destroy(ocfs2_dquot_cachep);
+       ocfs2_dquot_cachep = NULL;
+
+       if (ocfs2_qf_chunk_cachep)
+               kmem_cache_destroy(ocfs2_qf_chunk_cachep);
+       ocfs2_qf_chunk_cachep = NULL;
 }
 
 static int ocfs2_get_sector(struct super_block *sb,
@@ -1070,32 +1537,14 @@ static int ocfs2_get_sector(struct super_block *sb,
        unlock_buffer(*bh);
        ll_rw_block(READ, 1, bh);
        wait_on_buffer(*bh);
-       return 0;
-}
-
-/* ocfs2 1.0 only allows one cluster and node identity per kernel image. */
-static int ocfs2_fill_local_node_info(struct ocfs2_super *osb)
-{
-       int status;
-
-       /* XXX hold a ref on the node while mounte?  easy enough, if
-        * desirable. */
-       if (ocfs2_mount_local(osb))
-               osb->node_num = 0;
-       else
-               osb->node_num = o2nm_this_node();
-
-       if (osb->node_num == O2NM_MAX_NODES) {
-               mlog(ML_ERROR, "could not find this host's node number\n");
-               status = -ENOENT;
-               goto bail;
+       if (!buffer_uptodate(*bh)) {
+               mlog_errno(-EIO);
+               brelse(*bh);
+               *bh = NULL;
+               return -EIO;
        }
 
-       mlog(0, "I am node %d\n", osb->node_num);
-
-       status = 0;
-bail:
-       return status;
+       return 0;
 }
 
 static int ocfs2_mount_volume(struct super_block *sb)
@@ -1109,12 +1558,6 @@ static int ocfs2_mount_volume(struct super_block *sb)
        if (ocfs2_is_hard_readonly(osb))
                goto leave;
 
-       status = ocfs2_fill_local_node_info(osb);
-       if (status < 0) {
-               mlog_errno(status);
-               goto leave;
-       }
-
        status = ocfs2_dlm_init(osb);
        if (status < 0) {
                mlog_errno(status);
@@ -1165,18 +1608,9 @@ leave:
        return status;
 }
 
-/* we can't grab the goofy sem lock from inside wait_event, so we use
- * memory barriers to make sure that we'll see the null task before
- * being woken up */
-static int ocfs2_recovery_thread_running(struct ocfs2_super *osb)
-{
-       mb();
-       return osb->recovery_thread_task != NULL;
-}
-
 static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
 {
-       int tmp;
+       int tmp, hangup_needed = 0;
        struct ocfs2_super *osb = NULL;
        char nodestr[8];
 
@@ -1186,29 +1620,22 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
        osb = OCFS2_SB(sb);
        BUG_ON(!osb);
 
+       ocfs2_disable_quotas(osb);
+
        ocfs2_shutdown_local_alloc(osb);
 
        ocfs2_truncate_log_shutdown(osb);
 
-       /* disable any new recovery threads and wait for any currently
-        * running ones to exit. Do this before setting the vol_state. */
-       mutex_lock(&osb->recovery_lock);
-       osb->disable_recovery = 1;
-       mutex_unlock(&osb->recovery_lock);
-       wait_event(osb->recovery_event, !ocfs2_recovery_thread_running(osb));
-
-       /* At this point, we know that no more recovery threads can be
-        * launched, so wait for any recovery completion work to
-        * complete. */
-       flush_workqueue(ocfs2_wq);
+       /* This will disable recovery and flush any recovery work. */
+       ocfs2_recovery_exit(osb);
 
        ocfs2_journal_shutdown(osb);
 
        ocfs2_sync_blockdev(sb);
 
-       /* No dlm means we've failed during mount, so skip all the
-        * steps which depended on that to complete. */
-       if (osb->dlm) {
+       /* No cluster connection means we've failed during mount, so skip
+        * all the steps which depended on that to complete. */
+       if (osb->cconn) {
                tmp = ocfs2_super_lock(osb, 1);
                if (tmp < 0) {
                        mlog_errno(tmp);
@@ -1219,25 +1646,34 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
        if (osb->slot_num != OCFS2_INVALID_SLOT)
                ocfs2_put_slot(osb);
 
-       if (osb->dlm)
+       if (osb->cconn)
                ocfs2_super_unlock(osb, 1);
 
        ocfs2_release_system_inodes(osb);
 
-       if (osb->dlm)
-               ocfs2_dlm_shutdown(osb);
+       /*
+        * If we're dismounting due to mount error, mount.ocfs2 will clean
+        * up heartbeat.  If we're a local mount, there is no heartbeat.
+        * If we failed before we got a uuid_str yet, we can't stop
+        * heartbeat.  Otherwise, do it.
+        */
+       if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
+               hangup_needed = 1;
+
+       if (osb->cconn)
+               ocfs2_dlm_shutdown(osb, hangup_needed);
 
        debugfs_remove(osb->osb_debug_root);
 
-       if (!mnt_err)
-               ocfs2_stop_heartbeat(osb);
+       if (hangup_needed)
+               ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
 
        atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
 
        if (ocfs2_mount_local(osb))
                snprintf(nodestr, sizeof(nodestr), "local");
        else
-               snprintf(nodestr, sizeof(nodestr), "%d", osb->node_num);
+               snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
 
        printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
               osb->dev_str, nodestr);
@@ -1296,6 +1732,9 @@ static int ocfs2_initialize_super(struct super_block *sb,
        sb->s_fs_info = osb;
        sb->s_op = &ocfs2_sops;
        sb->s_export_op = &ocfs2_export_ops;
+       sb->s_qcop = &ocfs2_quotactl_ops;
+       sb->dq_op = &ocfs2_quota_operations;
+       sb->s_xattr = ocfs2_xattr_handlers;
        sb->s_time_gran = 1;
        sb->s_flags |= MS_NOATIME;
        /* this is needed to support O_LARGEFILE */
@@ -1308,7 +1747,6 @@ static int ocfs2_initialize_super(struct super_block *sb,
        osb->s_sectsize_bits = blksize_bits(sector_size);
        BUG_ON(!osb->s_sectsize_bits);
 
-       init_waitqueue_head(&osb->recovery_event);
        spin_lock_init(&osb->dc_task_lock);
        init_waitqueue_head(&osb->dc_event);
        osb->dc_work_sequence = 0;
@@ -1316,6 +1754,8 @@ static int ocfs2_initialize_super(struct super_block *sb,
        INIT_LIST_HEAD(&osb->blocked_lock_list);
        osb->blocked_lock_count = 0;
        spin_lock_init(&osb->osb_lock);
+       spin_lock_init(&osb->osb_xattr_lock);
+       ocfs2_init_inode_steal_slot(osb);
 
        atomic_set(&osb->alloc_stats.moves, 0);
        atomic_set(&osb->alloc_stats.local_data, 0);
@@ -1328,23 +1768,26 @@ static int ocfs2_initialize_super(struct super_block *sb,
        snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
                 MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
 
-       mutex_init(&osb->recovery_lock);
-
-       osb->disable_recovery = 0;
-       osb->recovery_thread_task = NULL;
+       status = ocfs2_recovery_init(osb);
+       if (status) {
+               mlog(ML_ERROR, "Unable to initialize recovery state\n");
+               mlog_errno(status);
+               goto bail;
+       }
 
        init_waitqueue_head(&osb->checkpoint_event);
        atomic_set(&osb->needs_checkpoint, 0);
 
        osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
 
-       osb->node_num = O2NM_INVALID_NODE_NUM;
        osb->slot_num = OCFS2_INVALID_SLOT;
 
+       osb->s_xattr_inline_size = le16_to_cpu(
+                                       di->id2.i_super.s_xattr_inline_size);
+
        osb->local_alloc_state = OCFS2_LA_UNUSED;
        osb->local_alloc_bh = NULL;
-
-       ocfs2_setup_hb_callbacks(osb);
+       INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
 
        init_waitqueue_head(&osb->osb_mount_event);
 
@@ -1364,6 +1807,15 @@ static int ocfs2_initialize_super(struct super_block *sb,
        }
        mlog(0, "max_slots for this device: %u\n", osb->max_slots);
 
+       osb->slot_recovery_generations =
+               kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
+                       GFP_KERNEL);
+       if (!osb->slot_recovery_generations) {
+               status = -ENOMEM;
+               mlog_errno(status);
+               goto bail;
+       }
+
        init_waitqueue_head(&osb->osb_wipe_event);
        osb->osb_orphan_wipes = kcalloc(osb->max_slots,
                                        sizeof(*osb->osb_orphan_wipes),
@@ -1395,6 +1847,25 @@ static int ocfs2_initialize_super(struct super_block *sb,
                goto bail;
        }
 
+       if (ocfs2_userspace_stack(osb)) {
+               memcpy(osb->osb_cluster_stack,
+                      OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
+                      OCFS2_STACK_LABEL_LEN);
+               osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
+               if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
+                       mlog(ML_ERROR,
+                            "couldn't mount because of an invalid "
+                            "cluster stack label (%s) \n",
+                            osb->osb_cluster_stack);
+                       status = -EINVAL;
+                       goto bail;
+               }
+       } else {
+               /* The empty string is identical with classic tools that
+                * don't know about s_cluster_info. */
+               osb->osb_cluster_stack[0] = '\0';
+       }
+
        get_random_bytes(&osb->s_next_generation, sizeof(u32));
 
        /* FIXME
@@ -1424,6 +1895,9 @@ static int ocfs2_initialize_super(struct super_block *sb,
        INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
        journal->j_state = OCFS2_JOURNAL_FREE;
 
+       INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
+       osb->dentry_lock_list = NULL;
+
        /* get some pseudo constants for clustersize bits */
        osb->s_clustersize_bits =
                le32_to_cpu(di->id2.i_super.s_clustersize_bits);
@@ -1462,6 +1936,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
        osb->first_cluster_group_blkno =
                le64_to_cpu(di->id2.i_super.s_first_cluster_group);
        osb->fs_generation = le32_to_cpu(di->i_fs_generation);
+       osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
        mlog(0, "vol_label: %s\n", osb->vol_label);
        mlog(0, "uuid: %s\n", osb->uuid_str);
        mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
@@ -1526,6 +2001,15 @@ static int ocfs2_verify_volume(struct ocfs2_dinode *di,
 
        if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
                   strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
+               /* We have to do a raw check of the feature here */
+               if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
+                   OCFS2_FEATURE_INCOMPAT_META_ECC) {
+                       status = ocfs2_block_check_validate(bh->b_data,
+                                                           bh->b_size,
+                                                           &di->i_check);
+                       if (status)
+                               goto out;
+               }
                status = -EINVAL;
                if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
                        mlog(ML_ERROR, "found superblock with incorrect block "
@@ -1567,6 +2051,7 @@ static int ocfs2_verify_volume(struct ocfs2_dinode *di,
                }
        }
 
+out:
        mlog_exit(status);
        return status;
 }
@@ -1606,7 +2091,11 @@ static int ocfs2_check_volume(struct ocfs2_super *osb)
        local = ocfs2_mount_local(osb);
 
        /* will play back anything left in the journal. */
-       ocfs2_journal_load(osb->journal, local);
+       status = ocfs2_journal_load(osb->journal, local, dirty);
+       if (status < 0) {
+               mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
+               goto finally;
+       }
 
        if (dirty) {
                /* recover my local alloc if we didn't unmount cleanly. */
@@ -1664,10 +2153,10 @@ static void ocfs2_delete_osb(struct ocfs2_super *osb)
 
        /* This function assumes that the caller has the main osb resource */
 
-       if (osb->slot_info)
-               ocfs2_free_slot_info(osb->slot_info);
+       ocfs2_free_slot_info(osb);
 
        kfree(osb->osb_orphan_wipes);
+       kfree(osb->slot_recovery_generations);
        /* FIXME
         * This belongs in journal shutdown, but because we have to
         * allocate osb->journal at the start of ocfs2_initalize_osb(),