ext4: use i_size_read in ext4_unaligned_aio()
[linux-3.10.git] / fs / jfs / super.c
index 68eee2b..788e0a9 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/slab.h>
 #include <asm/uaccess.h>
 #include <linux/seq_file.h>
+#include <linux/blkdev.h>
 
 #include "jfs_incore.h"
 #include "jfs_filsys.h"
@@ -100,7 +101,7 @@ void jfs_error(struct super_block *sb, const char * function, ...)
        vsnprintf(error_buf, sizeof(error_buf), function, args);
        va_end(args);
 
-       printk(KERN_ERR "ERROR: (device %s): %s\n", sb->s_id, error_buf);
+       pr_err("ERROR: (device %s): %s\n", sb->s_id, error_buf);
 
        jfs_handle_error(sb);
 }
@@ -115,6 +116,13 @@ static struct inode *jfs_alloc_inode(struct super_block *sb)
        return &jfs_inode->vfs_inode;
 }
 
+static void jfs_i_callback(struct rcu_head *head)
+{
+       struct inode *inode = container_of(head, struct inode, i_rcu);
+       struct jfs_inode_info *ji = JFS_IP(inode);
+       kmem_cache_free(jfs_inode_cachep, ji);
+}
+
 static void jfs_destroy_inode(struct inode *inode)
 {
        struct jfs_inode_info *ji = JFS_IP(inode);
@@ -128,7 +136,7 @@ static void jfs_destroy_inode(struct inode *inode)
                ji->active_ag = -1;
        }
        spin_unlock_irq(&ji->ag_lock);
-       kmem_cache_free(jfs_inode_cachep, ji);
+       call_rcu(&inode->i_rcu, jfs_i_callback);
 }
 
 static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
@@ -146,7 +154,7 @@ static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        /*
         * If we really return the number of allocated & free inodes, some
         * applications will fail because they won't see enough free inodes.
-        * We'll try to calculate some guess as to how may inodes we can
+        * We'll try to calculate some guess as to how many inodes we can
         * really allocate
         *
         * buf->f_files = atomic_read(&imap->im_numinos);
@@ -190,7 +198,8 @@ static void jfs_put_super(struct super_block *sb)
 enum {
        Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
        Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
-       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
+       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
+       Opt_discard, Opt_nodiscard, Opt_discard_minblk
 };
 
 static const match_table_t tokens = {
@@ -207,6 +216,9 @@ static const match_table_t tokens = {
        {Opt_uid, "uid=%u"},
        {Opt_gid, "gid=%u"},
        {Opt_umask, "umask=%u"},
+       {Opt_discard, "discard"},
+       {Opt_nodiscard, "nodiscard"},
+       {Opt_discard_minblk, "discard=%u"},
        {Opt_err, NULL}
 };
 
@@ -248,8 +260,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
                        else {
                                nls_map = load_nls(args[0].from);
                                if (!nls_map) {
-                                       printk(KERN_ERR
-                                              "JFS: charset not found\n");
+                                       pr_err("JFS: charset not found\n");
                                        goto cleanup;
                                }
                        }
@@ -265,8 +276,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
                        *newLVSize = sb->s_bdev->bd_inode->i_size >>
                                sb->s_blocksize_bits;
                        if (*newLVSize == 0)
-                               printk(KERN_ERR
-                                      "JFS: Cannot determine volume size\n");
+                               pr_err("JFS: Cannot determine volume size\n");
                        break;
                }
                case Opt_errors:
@@ -287,8 +297,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
                                *flag &= ~JFS_ERR_REMOUNT_RO;
                                *flag |= JFS_ERR_PANIC;
                        } else {
-                               printk(KERN_ERR
-                                      "JFS: %s is an invalid error handler\n",
+                               pr_err("JFS: %s is an invalid error handler\n",
                                       errors);
                                goto cleanup;
                        }
@@ -307,33 +316,76 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
                case Opt_usrquota:
                case Opt_grpquota:
                case Opt_quota:
-                       printk(KERN_ERR
-                              "JFS: quota operations not supported\n");
+                       pr_err("JFS: quota operations not supported\n");
                        break;
 #endif
                case Opt_uid:
                {
                        char *uid = args[0].from;
-                       sbi->uid = simple_strtoul(uid, &uid, 0);
+                       uid_t val = simple_strtoul(uid, &uid, 0);
+                       sbi->uid = make_kuid(current_user_ns(), val);
+                       if (!uid_valid(sbi->uid))
+                               goto cleanup;
                        break;
                }
+
                case Opt_gid:
                {
                        char *gid = args[0].from;
-                       sbi->gid = simple_strtoul(gid, &gid, 0);
+                       gid_t val = simple_strtoul(gid, &gid, 0);
+                       sbi->gid = make_kgid(current_user_ns(), val);
+                       if (!gid_valid(sbi->gid))
+                               goto cleanup;
                        break;
                }
+
                case Opt_umask:
                {
                        char *umask = args[0].from;
                        sbi->umask = simple_strtoul(umask, &umask, 8);
                        if (sbi->umask & ~0777) {
-                               printk(KERN_ERR
-                                      "JFS: Invalid value of umask\n");
+                               pr_err("JFS: Invalid value of umask\n");
                                goto cleanup;
                        }
                        break;
                }
+
+               case Opt_discard:
+               {
+                       struct request_queue *q = bdev_get_queue(sb->s_bdev);
+                       /* if set to 1, even copying files will cause
+                        * trimming :O
+                        * -> user has more control over the online trimming
+                        */
+                       sbi->minblks_trim = 64;
+                       if (blk_queue_discard(q)) {
+                               *flag |= JFS_DISCARD;
+                       } else {
+                               pr_err("JFS: discard option " \
+                                       "not supported on device\n");
+                       }
+                       break;
+               }
+
+               case Opt_nodiscard:
+                       *flag &= ~JFS_DISCARD;
+                       break;
+
+               case Opt_discard_minblk:
+               {
+                       struct request_queue *q = bdev_get_queue(sb->s_bdev);
+                       char *minblks_trim = args[0].from;
+                       if (blk_queue_discard(q)) {
+                               *flag |= JFS_DISCARD;
+                               sbi->minblks_trim = simple_strtoull(
+                                       minblks_trim, &minblks_trim, 0);
+                       } else {
+                               pr_err("JFS: discard option " \
+                                       "not supported on device\n");
+                       }
+                       break;
+               }
+
                default:
                        printk("jfs: Unrecognized mount option \"%s\" "
                                        " or missing value\n", p);
@@ -367,8 +419,8 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data)
 
        if (newLVSize) {
                if (sb->s_flags & MS_RDONLY) {
-                       printk(KERN_ERR
-                 "JFS: resize requires volume to be mounted read-write\n");
+                       pr_err("JFS: resize requires volume" \
+                               " to be mounted read-write\n");
                        return -EROFS;
                }
                rc = jfs_extendfs(sb, newLVSize, 0);
@@ -434,8 +486,11 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
                return -ENOMEM;
 
        sb->s_fs_info = sbi;
+       sb->s_max_links = JFS_LINK_MAX;
        sbi->sb = sb;
-       sbi->uid = sbi->gid = sbi->umask = -1;
+       sbi->uid = INVALID_UID;
+       sbi->gid = INVALID_GID;
+       sbi->umask = -1;
 
        /* initialize the mount flag and determine the default error handler */
        flag = JFS_ERR_REMOUNT_RO;
@@ -449,7 +504,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
 #endif
 
        if (newLVSize) {
-               printk(KERN_ERR "resize option for remount only\n");
+               pr_err("resize option for remount only\n");
                goto out_kfree;
        }
 
@@ -477,7 +532,6 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
                goto out_unload;
        }
        inode->i_ino = 0;
-       inode->i_nlink = 1;
        inode->i_size = sb->s_bdev->bd_inode->i_size;
        inode->i_mapping->a_ops = &jfs_metapage_aops;
        insert_inode_hash(inode);
@@ -507,18 +561,18 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
 
        sb->s_magic = JFS_SUPER_MAGIC;
 
+       if (sbi->mntflag & JFS_OS2)
+               sb->s_d_op = &jfs_ci_dentry_operations;
+
        inode = jfs_iget(sb, ROOT_I);
        if (IS_ERR(inode)) {
                ret = PTR_ERR(inode);
                goto out_no_rw;
        }
-       sb->s_root = d_alloc_root(inode);
+       sb->s_root = d_make_root(inode);
        if (!sb->s_root)
                goto out_no_root;
 
-       if (sbi->mntflag & JFS_OS2)
-               sb->s_root->d_op = &jfs_ci_dentry_operations;
-
        /* logical blocks are represented by 40 bits in pxd_t, etc. */
        sb->s_maxbytes = ((u64) sb->s_blocksize) << 40;
 #if BITS_PER_LONG == 32
@@ -533,7 +587,6 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent)
 
 out_no_root:
        jfs_err("jfs_read_super: get root dentry failed");
-       iput(inode);
 
 out_no_rw:
        rc = jfs_umount(sb);
@@ -558,11 +611,28 @@ static int jfs_freeze(struct super_block *sb)
 {
        struct jfs_sb_info *sbi = JFS_SBI(sb);
        struct jfs_log *log = sbi->log;
+       int rc = 0;
 
        if (!(sb->s_flags & MS_RDONLY)) {
                txQuiesce(sb);
-               lmLogShutdown(log);
-               updateSuper(sb, FM_CLEAN);
+               rc = lmLogShutdown(log);
+               if (rc) {
+                       jfs_error(sb, "jfs_freeze: lmLogShutdown failed");
+
+                       /* let operations fail rather than hang */
+                       txResume(sb);
+
+                       return rc;
+               }
+               rc = updateSuper(sb, FM_CLEAN);
+               if (rc) {
+                       jfs_err("jfs_freeze: updateSuper failed\n");
+                       /*
+                        * Don't fail here. Everything succeeded except
+                        * marking the superblock clean, so there's really
+                        * no harm in leaving it frozen for now.
+                        */
+               }
        }
        return 0;
 }
@@ -574,20 +644,24 @@ static int jfs_unfreeze(struct super_block *sb)
        int rc = 0;
 
        if (!(sb->s_flags & MS_RDONLY)) {
-               updateSuper(sb, FM_MOUNT);
-               if ((rc = lmLogInit(log)))
-                       jfs_err("jfs_unlock failed with return code %d", rc);
-               else
-                       txResume(sb);
+               rc = updateSuper(sb, FM_MOUNT);
+               if (rc) {
+                       jfs_error(sb, "jfs_unfreeze: updateSuper failed");
+                       goto out;
+               }
+               rc = lmLogInit(log);
+               if (rc)
+                       jfs_error(sb, "jfs_unfreeze: lmLogInit failed");
+out:
+               txResume(sb);
        }
-       return 0;
+       return rc;
 }
 
-static int jfs_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
+static struct dentry *jfs_do_mount(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data)
 {
-       return get_sb_bdev(fs_type, flags, dev_name, data, jfs_fill_super,
-                          mnt);
+       return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super);
 }
 
 static int jfs_sync_fs(struct super_block *sb, int wait)
@@ -596,6 +670,11 @@ static int jfs_sync_fs(struct super_block *sb, int wait)
 
        /* log == NULL indicates read-only mount */
        if (log) {
+               /*
+                * Write quota structures to quota file, sync_blockdev() will
+                * write them to disk later
+                */
+               dquot_writeback_dquots(sb, -1);
                jfs_flush_journal(log, wait);
                jfs_syncpt(log, 0);
        }
@@ -603,18 +682,20 @@ static int jfs_sync_fs(struct super_block *sb, int wait)
        return 0;
 }
 
-static int jfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
+static int jfs_show_options(struct seq_file *seq, struct dentry *root)
 {
-       struct jfs_sb_info *sbi = JFS_SBI(vfs->mnt_sb);
+       struct jfs_sb_info *sbi = JFS_SBI(root->d_sb);
 
-       if (sbi->uid != -1)
-               seq_printf(seq, ",uid=%d", sbi->uid);
-       if (sbi->gid != -1)
-               seq_printf(seq, ",gid=%d", sbi->gid);
+       if (uid_valid(sbi->uid))
+               seq_printf(seq, ",uid=%d", from_kuid(&init_user_ns, sbi->uid));
+       if (gid_valid(sbi->gid))
+               seq_printf(seq, ",gid=%d", from_kgid(&init_user_ns, sbi->gid));
        if (sbi->umask != -1)
                seq_printf(seq, ",umask=%03o", sbi->umask);
        if (sbi->flag & JFS_NOINTEGRITY)
                seq_puts(seq, ",nointegrity");
+       if (sbi->flag & JFS_DISCARD)
+               seq_printf(seq, ",discard=%u", sbi->minblks_trim);
        if (sbi->nls_tab)
                seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset);
        if (sbi->flag & JFS_ERR_CONTINUE)
@@ -637,7 +718,7 @@ static int jfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
 
 /* 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 noone else should touch the files)
+ * itself serializes the operations (and no one else should touch the files)
  * we don't have to be afraid of races */
 static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data,
                              size_t len, loff_t off)
@@ -770,10 +851,11 @@ static const struct export_operations jfs_export_operations = {
 static struct file_system_type jfs_fs_type = {
        .owner          = THIS_MODULE,
        .name           = "jfs",
-       .get_sb         = jfs_get_sb,
+       .mount          = jfs_do_mount,
        .kill_sb        = kill_block_super,
        .fs_flags       = FS_REQUIRES_DEV,
 };
+MODULE_ALIAS_FS("jfs");
 
 static void init_once(void *foo)
 {
@@ -855,8 +937,14 @@ static int __init init_jfs_fs(void)
        jfs_proc_init();
 #endif
 
-       return register_filesystem(&jfs_fs_type);
+       rc = register_filesystem(&jfs_fs_type);
+       if (!rc)
+               return 0;
 
+#ifdef PROC_FS_JFS
+       jfs_proc_clean();
+#endif
+       kthread_stop(jfsSyncThread);
 kill_committask:
        for (i = 0; i < commit_threads; i++)
                kthread_stop(jfsCommitThread[i]);
@@ -887,6 +975,12 @@ static void __exit exit_jfs_fs(void)
        jfs_proc_clean();
 #endif
        unregister_filesystem(&jfs_fs_type);
+
+       /*
+        * Make sure all delayed rcu free inodes are flushed before we
+        * destroy cache.
+        */
+       rcu_barrier();
        kmem_cache_destroy(jfs_inode_cachep);
 }