NLM: Fix a bogus 'return' in nlmclnt_rpc_release
[safe/jmp/linux-2.6] / fs / gfs2 / ops_fstype.c
index d39314d..43d511b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
- * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 2004-2007 Red Hat, Inc.  All rights reserved.
  *
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
 #include <linux/spinlock.h>
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
-#include <linux/vmalloc.h>
 #include <linux/blkdev.h>
 #include <linux/kthread.h>
 #include <linux/namei.h>
 #include <linux/mount.h>
 #include <linux/gfs2_ondisk.h>
+#include <linux/lm_interface.h>
 
 #include "gfs2.h"
-#include "lm_interface.h"
 #include "incore.h"
+#include "bmap.h"
 #include "daemon.h"
 #include "glock.h"
 #include "glops.h"
 #include "inode.h"
 #include "lm.h"
 #include "mount.h"
-#include "ops_export.h"
 #include "ops_fstype.h"
+#include "ops_dentry.h"
 #include "ops_super.h"
 #include "recovery.h"
 #include "rgrp.h"
 #include "super.h"
 #include "sys.h"
 #include "util.h"
+#include "log.h"
 
 #define DO 0
 #define UNDO 1
 
-extern struct dentry_operations gfs2_dops;
-
 static struct gfs2_sbd *init_sbd(struct super_block *sb)
 {
        struct gfs2_sbd *sdp;
-       unsigned int x;
 
-       sdp = vmalloc(sizeof(struct gfs2_sbd));
+       sdp = kzalloc(sizeof(struct gfs2_sbd), GFP_KERNEL);
        if (!sdp)
                return NULL;
 
-       memset(sdp, 0, sizeof(struct gfs2_sbd));
-
        sb->s_fs_info = sdp;
        sdp->sd_vfs = sb;
 
        gfs2_tune_init(&sdp->sd_tune);
 
-       for (x = 0; x < GFS2_GL_HASH_SIZE; x++) {
-               rwlock_init(&sdp->sd_gl_hash[x].hb_lock);
-               INIT_LIST_HEAD(&sdp->sd_gl_hash[x].hb_list);
-       }
        INIT_LIST_HEAD(&sdp->sd_reclaim_list);
        spin_lock_init(&sdp->sd_reclaim_lock);
        init_waitqueue_head(&sdp->sd_reclaim_wq);
 
        mutex_init(&sdp->sd_inum_mutex);
        spin_lock_init(&sdp->sd_statfs_spin);
-       mutex_init(&sdp->sd_statfs_mutex);
 
        spin_lock_init(&sdp->sd_rindex_spin);
        mutex_init(&sdp->sd_rindex_mutex);
@@ -86,18 +77,19 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
 
        spin_lock_init(&sdp->sd_log_lock);
 
-       INIT_LIST_HEAD(&sdp->sd_log_le_gl);
        INIT_LIST_HEAD(&sdp->sd_log_le_buf);
        INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
        INIT_LIST_HEAD(&sdp->sd_log_le_rg);
        INIT_LIST_HEAD(&sdp->sd_log_le_databuf);
+       INIT_LIST_HEAD(&sdp->sd_log_le_ordered);
 
        mutex_init(&sdp->sd_log_reserve_mutex);
        INIT_LIST_HEAD(&sdp->sd_ail1_list);
        INIT_LIST_HEAD(&sdp->sd_ail2_list);
 
        init_rwsem(&sdp->sd_log_flush_lock);
-       INIT_LIST_HEAD(&sdp->sd_log_flush_list);
+       atomic_set(&sdp->sd_log_in_flight, 0);
+       init_waitqueue_head(&sdp->sd_log_flush_wait);
 
        INIT_LIST_HEAD(&sdp->sd_revoke_list);
 
@@ -113,6 +105,7 @@ static void init_vfs(struct super_block *sb, unsigned noatime)
        sb->s_magic = GFS2_MAGIC;
        sb->s_op = &gfs2_super_ops;
        sb->s_export_op = &gfs2_export_ops;
+       sb->s_time_gran = 1;
        sb->s_maxbytes = MAX_LFS_FILESIZE;
 
        if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME))
@@ -124,7 +117,6 @@ static void init_vfs(struct super_block *sb, unsigned noatime)
 
 static int init_names(struct gfs2_sbd *sdp, int silent)
 {
-       struct gfs2_sb *sb = NULL;
        char *proto, *table;
        int error = 0;
 
@@ -134,37 +126,18 @@ static int init_names(struct gfs2_sbd *sdp, int silent)
        /*  Try to autodetect  */
 
        if (!proto[0] || !table[0]) {
-               struct buffer_head *bh;
-               bh = sb_getblk(sdp->sd_vfs,
-                              GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
-               lock_buffer(bh);
-               clear_buffer_uptodate(bh);
-               clear_buffer_dirty(bh);
-               unlock_buffer(bh);
-               ll_rw_block(READ, 1, &bh);
-               wait_on_buffer(bh);
-
-               if (!buffer_uptodate(bh)) {
-                       brelse(bh);
-                       return -EIO;
-               }
-
-               sb = kmalloc(sizeof(struct gfs2_sb), GFP_KERNEL);
-               if (!sb) {
-                       brelse(bh);
-                       return -ENOMEM;
-               }
-               gfs2_sb_in(sb, bh->b_data); 
-               brelse(bh);
+               error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
+               if (error)
+                       return error;
 
-               error = gfs2_check_sb(sdp, sb, silent);
+               error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
                if (error)
                        goto out;
 
                if (!proto[0])
-                       proto = sb->sb_lockproto;
+                       proto = sdp->sd_sb.sb_lockproto;
                if (!table[0])
-                       table = sb->sb_locktable;
+                       table = sdp->sd_sb.sb_locktable;
        }
 
        if (!table[0])
@@ -173,8 +146,11 @@ static int init_names(struct gfs2_sbd *sdp, int silent)
        snprintf(sdp->sd_proto_name, GFS2_FSNAME_LEN, "%s", proto);
        snprintf(sdp->sd_table_name, GFS2_FSNAME_LEN, "%s", table);
 
+       table = sdp->sd_table_name;
+       while ((table = strchr(table, '/')))
+               *table = '_';
+
 out:
-       kfree(sb);
        return error;
 }
 
@@ -187,14 +163,6 @@ static int init_locking(struct gfs2_sbd *sdp, struct gfs2_holder *mount_gh,
        if (undo)
                goto fail_trans;
 
-       p = kthread_run(gfs2_scand, sdp, "gfs2_scand");
-       error = IS_ERR(p);
-       if (error) {
-               fs_err(sdp, "can't start scand thread: %d\n", error);
-               return error;
-       }
-       sdp->sd_scand_process = p;
-
        for (sdp->sd_glockd_num = 0;
             sdp->sd_glockd_num < sdp->sd_args.ar_num_glockd;
             sdp->sd_glockd_num++) {
@@ -255,21 +223,20 @@ fail:
        while (sdp->sd_glockd_num--)
                kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
 
-       kthread_stop(sdp->sd_scand_process);
        return error;
 }
 
-static struct inode *gfs2_lookup_root(struct super_block *sb,
-                                     struct gfs2_inum *inum)
+static inline struct inode *gfs2_lookup_root(struct super_block *sb,
+                                            u64 no_addr)
 {
-       return gfs2_inode_lookup(sb, inum, DT_DIR);
+       return gfs2_inode_lookup(sb, DT_DIR, no_addr, 0, 0);
 }
 
 static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
 {
        struct super_block *sb = sdp->sd_vfs;
        struct gfs2_holder sb_gh;
-       struct gfs2_inum *inum;
+       u64 no_addr;
        struct inode *inode;
        int error = 0;
 
@@ -280,7 +247,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
                }
                return 0;
        }
-       
+
        error = gfs2_glock_nq_num(sdp, GFS2_SB_LOCK, &gfs2_meta_glops,
                                 LM_ST_SHARED, 0, &sb_gh);
        if (error) {
@@ -312,10 +279,10 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
        sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
 
        /* Get the root inode */
-       inum = &sdp->sd_sb.sb_root_dir;
+       no_addr = sdp->sd_sb.sb_root_dir.no_addr;
        if (sb->s_type == &gfs2meta_fs_type)
-               inum = &sdp->sd_sb.sb_master_dir;
-       inode = gfs2_lookup_root(sb, inum);
+               no_addr = sdp->sd_sb.sb_master_dir.no_addr;
+       inode = gfs2_lookup_root(sb, no_addr);
        if (IS_ERR(inode)) {
                error = PTR_ERR(inode);
                fs_err(sdp, "can't read in root inode: %d\n", error);
@@ -327,13 +294,75 @@ static int init_sb(struct gfs2_sbd *sdp, int silent, int undo)
                fs_err(sdp, "can't get root dentry\n");
                error = -ENOMEM;
                iput(inode);
-       }
-       sb->s_root->d_op = &gfs2_dops;
+       } else
+               sb->s_root->d_op = &gfs2_dops;
+       
 out:
        gfs2_glock_dq_uninit(&sb_gh);
        return error;
 }
 
+/**
+ * map_journal_extents - create a reusable "extent" mapping from all logical
+ * blocks to all physical blocks for the given journal.  This will save
+ * us time when writing journal blocks.  Most journals will have only one
+ * extent that maps all their logical blocks.  That's because gfs2.mkfs
+ * arranges the journal blocks sequentially to maximize performance.
+ * So the extent would map the first block for the entire file length.
+ * However, gfs2_jadd can happen while file activity is happening, so
+ * those journals may not be sequential.  Less likely is the case where
+ * the users created their own journals by mounting the metafs and
+ * laying it out.  But it's still possible.  These journals might have
+ * several extents.
+ *
+ * TODO: This should be done in bigger chunks rather than one block at a time,
+ *       but since it's only done at mount time, I'm not worried about the
+ *       time it takes.
+ */
+static int map_journal_extents(struct gfs2_sbd *sdp)
+{
+       struct gfs2_jdesc *jd = sdp->sd_jdesc;
+       unsigned int lb;
+       u64 db, prev_db; /* logical block, disk block, prev disk block */
+       struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
+       struct gfs2_journal_extent *jext = NULL;
+       struct buffer_head bh;
+       int rc = 0;
+
+       prev_db = 0;
+
+       for (lb = 0; lb < ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; lb++) {
+               bh.b_state = 0;
+               bh.b_blocknr = 0;
+               bh.b_size = 1 << ip->i_inode.i_blkbits;
+               rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0);
+               db = bh.b_blocknr;
+               if (rc || !db) {
+                       printk(KERN_INFO "GFS2 journal mapping error %d: lb="
+                              "%u db=%llu\n", rc, lb, (unsigned long long)db);
+                       break;
+               }
+               if (!prev_db || db != prev_db + 1) {
+                       jext = kzalloc(sizeof(struct gfs2_journal_extent),
+                                      GFP_KERNEL);
+                       if (!jext) {
+                               printk(KERN_INFO "GFS2 error: out of memory "
+                                      "mapping journal extents.\n");
+                               rc = -ENOMEM;
+                               break;
+                       }
+                       jext->dblock = db;
+                       jext->lblock = lb;
+                       jext->blocks = 1;
+                       list_add_tail(&jext->extent_list, &jd->extent_list);
+               } else {
+                       jext->blocks++;
+               }
+               prev_db = db;
+       }
+       return rc;
+}
+
 static int init_journal(struct gfs2_sbd *sdp, int undo)
 {
        struct gfs2_holder ji_gh;
@@ -366,12 +395,12 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
        error = -EINVAL;
        if (!gfs2_jindex_size(sdp)) {
                fs_err(sdp, "no journals!\n");
-               goto fail_jindex;               
+               goto fail_jindex;
        }
 
        if (sdp->sd_args.ar_spectator) {
                sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
-               sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks;
+               atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
        } else {
                if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
                        fs_err(sdp, "can't mount journal #%u\n",
@@ -394,7 +423,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
 
                ip = GFS2_I(sdp->sd_jdesc->jd_inode);
                error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
-                                          LM_FLAG_NOEXP | GL_EXACT,
+                                          LM_FLAG_NOEXP | GL_EXACT | GL_NOCACHE,
                                           &sdp->sd_jinode_gh);
                if (error) {
                        fs_err(sdp, "can't acquire journal inode glock: %d\n",
@@ -408,7 +437,10 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
                               sdp->sd_jdesc->jd_jid, error);
                        goto fail_jinode_gh;
                }
-               sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks;
+               atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
+
+               /* Map the extents for this journal's blocks */
+               map_journal_extents(sdp);
        }
 
        if (sdp->sd_lockstruct.ls_first) {
@@ -472,7 +504,7 @@ static int init_inodes(struct gfs2_sbd *sdp, int undo)
        if (undo)
                goto fail_qinode;
 
-       inode = gfs2_lookup_root(sdp->sd_vfs, &sdp->sd_sb.sb_master_dir);
+       inode = gfs2_lookup_root(sdp->sd_vfs, sdp->sd_sb.sb_master_dir.no_addr);
        if (IS_ERR(inode)) {
                error = PTR_ERR(inode);
                fs_err(sdp, "can't read in master directory: %d\n", error);
@@ -713,6 +745,8 @@ static int fill_super(struct super_block *sb, void *data, int silent)
        if (error)
                goto fail;
 
+       gfs2_create_debugfs_file(sdp);
+
        error = gfs2_sys_fs_add(sdp);
        if (error)
                goto fail;
@@ -777,7 +811,8 @@ fail_lm:
 fail_sys:
        gfs2_sys_fs_del(sdp);
 fail:
-       vfree(sdp);
+       gfs2_delete_debugfs_file(sdp);
+       kfree(sdp);
        sb->s_fs_info = NULL;
        return error;
 }
@@ -791,13 +826,13 @@ static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
        if (error)
                goto out;
        sb = mnt->mnt_sb;
-       sdp = (struct gfs2_sbd*)sb->s_fs_info;
+       sdp = sb->s_fs_info;
        sdp->sd_gfs2mnt = mnt;
 out:
        return error;
 }
 
-static int fill_super_meta(struct super_block *sb, struct super_block *new, 
+static int fill_super_meta(struct super_block *sb, struct super_block *new,
                           void *data, int silent)
 {
        struct gfs2_sbd *sdp = sb->s_fs_info;
@@ -817,8 +852,8 @@ static int fill_super_meta(struct super_block *sb, struct super_block *new,
                fs_err(sdp, "can't get root dentry\n");
                error = -ENOMEM;
                iput(inode);
-       }
-       new->s_root->d_op = &gfs2_dops;
+       } else
+               new->s_root->d_op = &gfs2_dops;
 
        return error;
 }
@@ -829,10 +864,10 @@ static int set_bdev_super(struct super_block *s, void *data)
        s->s_dev = s->s_bdev->bd_dev;
        return 0;
 }
+
 static int test_bdev_super(struct super_block *s, void *data)
 {
-       return (void *)s->s_bdev == data;
+       return s->s_bdev == data;
 }
 
 static struct super_block* get_gfs2_sb(const char *dev_name)
@@ -841,20 +876,18 @@ static struct super_block* get_gfs2_sb(const char *dev_name)
        struct nameidata nd;
        struct file_system_type *fstype;
        struct super_block *sb = NULL, *s;
-       struct list_head *l;
        int error;
-       
+
        error = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
        if (error) {
-               printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n", 
+               printk(KERN_WARNING "GFS2: path_lookup on %s returned error\n",
                       dev_name);
                goto out;
        }
        error = vfs_getattr(nd.mnt, nd.dentry, &stat);
 
        fstype = get_fs_type("gfs2");
-       list_for_each(l, &fstype->fs_supers) {
-               s = list_entry(l, struct super_block, s_instances);
+       list_for_each_entry(s, &fstype->fs_supers, s_instances) {
                if ((S_ISBLK(stat.mode) && s->s_dev == stat.rdev) ||
                    (S_ISDIR(stat.mode) && s == nd.dentry->d_inode->i_sb)) {
                        sb = s;
@@ -863,7 +896,7 @@ static struct super_block* get_gfs2_sb(const char *dev_name)
        }
 
        printk(KERN_WARNING "GFS2: Unrecognized block device or "
-              "mount point %s", dev_name);
+              "mount point %s\n", dev_name);
 
 free_nd:
        path_release(&nd);
@@ -877,7 +910,6 @@ static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
        int error = 0;
        struct super_block *sb = NULL, *new;
        struct gfs2_sbd *sdp;
-       char *gfs2mnt = NULL;
 
        sb = get_gfs2_sb(dev_name);
        if (!sb) {
@@ -885,15 +917,15 @@ static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
                error = -ENOENT;
                goto error;
        }
-       sdp = (struct gfs2_sbd*) sb->s_fs_info;
+       sdp = sb->s_fs_info;
        if (sdp->sd_vfs_meta) {
                printk(KERN_WARNING "GFS2: gfs2meta mount already exists\n");
                error = -EBUSY;
                goto error;
        }
-       mutex_lock(&sb->s_bdev->bd_mount_mutex);
+       down(&sb->s_bdev->bd_mount_sem);
        new = sget(fs_type, test_bdev_super, set_bdev_super, sb->s_bdev);
-       mutex_unlock(&sb->s_bdev->bd_mount_mutex);
+       up(&sb->s_bdev->bd_mount_sem);
        if (IS_ERR(new)) {
                error = PTR_ERR(new);
                goto error;
@@ -908,20 +940,22 @@ static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
                deactivate_super(new);
                goto error;
        }
-       
+
        new->s_flags |= MS_ACTIVE;
-       
+
        /* Grab a reference to the gfs2 mount point */
        atomic_inc(&sdp->sd_gfs2mnt->mnt_count);
        return simple_set_mnt(mnt, new);
 error:
-       if (gfs2mnt)
-               kfree(gfs2mnt);
        return error;
 }
 
 static void gfs2_kill_sb(struct super_block *sb)
 {
+       if (sb->s_fs_info) {
+               gfs2_delete_debugfs_file(sb->s_fs_info);
+               gfs2_meta_syncfs(sb->s_fs_info);
+       }
        kill_block_super(sb);
 }