mem: cdev lock_kernel() pushdown
[safe/jmp/linux-2.6] / fs / gfs2 / super.c
index 0ef8317..7aeacbc 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
@@ -51,14 +51,9 @@ void gfs2_tune_init(struct gfs2_tune *gt)
 {
        spin_lock_init(&gt->gt_spin);
 
-       gt->gt_ilimit = 100;
-       gt->gt_ilimit_tries = 3;
-       gt->gt_ilimit_min = 1;
        gt->gt_demote_secs = 300;
        gt->gt_incore_log_blocks = 1024;
        gt->gt_log_flush_secs = 60;
-       gt->gt_jindex_refresh_secs = 60;
-       gt->gt_scand_secs = 15;
        gt->gt_recoverd_secs = 60;
        gt->gt_logd_secs = 1;
        gt->gt_quotad_secs = 5;
@@ -71,17 +66,9 @@ void gfs2_tune_init(struct gfs2_tune *gt)
        gt->gt_atime_quantum = 3600;
        gt->gt_new_files_jdata = 0;
        gt->gt_new_files_directio = 0;
-       gt->gt_max_atomic_write = 4 << 20;
        gt->gt_max_readahead = 1 << 18;
-       gt->gt_lockdump_size = 131072;
        gt->gt_stall_secs = 600;
        gt->gt_complain_secs = 10;
-       gt->gt_reclaim_limit = 5000;
-       gt->gt_entries_per_readdir = 32;
-       gt->gt_prefetch_secs = 10;
-       gt->gt_greedy_default = HZ / 10;
-       gt->gt_greedy_quantum = HZ / 40;
-       gt->gt_greedy_max = HZ / 4;
        gt->gt_statfs_quantum = 30;
        gt->gt_statfs_slow = 0;
 }
@@ -101,8 +88,8 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb_host *sb, int silent)
 {
        unsigned int x;
 
-       if (sb->sb_header.mh_magic != GFS2_MAGIC ||
-           sb->sb_header.mh_type != GFS2_METATYPE_SB) {
+       if (sb->sb_magic != GFS2_MAGIC ||
+           sb->sb_type != GFS2_METATYPE_SB) {
                if (!silent)
                        printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n");
                return -EINVAL;
@@ -166,40 +153,78 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb_host *sb, int silent)
 }
 
 
-static int end_bio_io_page(struct bio *bio, unsigned int bytes_done, int error)
+static void end_bio_io_page(struct bio *bio, int error)
 {
        struct page *page = bio->bi_private;
-       if (bio->bi_size)
-               return 1;
 
        if (!error)
                SetPageUptodate(page);
        else
                printk(KERN_WARNING "gfs2: error %d reading superblock\n", error);
        unlock_page(page);
-       return 0;
 }
 
-struct page *gfs2_read_super(struct super_block *sb, sector_t sector)
+static void gfs2_sb_in(struct gfs2_sb_host *sb, const void *buf)
+{
+       const struct gfs2_sb *str = buf;
+
+       sb->sb_magic = be32_to_cpu(str->sb_header.mh_magic);
+       sb->sb_type = be32_to_cpu(str->sb_header.mh_type);
+       sb->sb_format = be32_to_cpu(str->sb_header.mh_format);
+       sb->sb_fs_format = be32_to_cpu(str->sb_fs_format);
+       sb->sb_multihost_format = be32_to_cpu(str->sb_multihost_format);
+       sb->sb_bsize = be32_to_cpu(str->sb_bsize);
+       sb->sb_bsize_shift = be32_to_cpu(str->sb_bsize_shift);
+       sb->sb_master_dir.no_addr = be64_to_cpu(str->sb_master_dir.no_addr);
+       sb->sb_master_dir.no_formal_ino = be64_to_cpu(str->sb_master_dir.no_formal_ino);
+       sb->sb_root_dir.no_addr = be64_to_cpu(str->sb_root_dir.no_addr);
+       sb->sb_root_dir.no_formal_ino = be64_to_cpu(str->sb_root_dir.no_formal_ino);
+
+       memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN);
+       memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN);
+}
+
+/**
+ * gfs2_read_super - Read the gfs2 super block from disk
+ * @sdp: The GFS2 super block
+ * @sector: The location of the super block
+ * @error: The error code to return
+ *
+ * This uses the bio functions to read the super block from disk
+ * because we want to be 100% sure that we never read cached data.
+ * A super block is read twice only during each GFS2 mount and is
+ * never written to by the filesystem. The first time its read no
+ * locks are held, and the only details which are looked at are those
+ * relating to the locking protocol. Once locking is up and working,
+ * the sb is read again under the lock to establish the location of
+ * the master directory (contains pointers to journals etc) and the
+ * root directory.
+ *
+ * Returns: 0 on success or error
+ */
+
+int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector)
 {
+       struct super_block *sb = sdp->sd_vfs;
+       struct gfs2_sb *p;
        struct page *page;
        struct bio *bio;
 
-       page = alloc_page(GFP_KERNEL);
+       page = alloc_page(GFP_NOFS);
        if (unlikely(!page))
-               return NULL;
+               return -ENOBUFS;
 
        ClearPageUptodate(page);
        ClearPageDirty(page);
        lock_page(page);
 
-       bio = bio_alloc(GFP_KERNEL, 1);
+       bio = bio_alloc(GFP_NOFS, 1);
        if (unlikely(!bio)) {
                __free_page(page);
-               return NULL;
+               return -ENOBUFS;
        }
 
-       bio->bi_sector = sector;
+       bio->bi_sector = sector * (sb->s_blocksize >> 9);
        bio->bi_bdev = sb->s_bdev;
        bio_add_page(bio, page, PAGE_SIZE, 0);
 
@@ -210,9 +235,13 @@ struct page *gfs2_read_super(struct super_block *sb, sector_t sector)
        bio_put(bio);
        if (!PageUptodate(page)) {
                __free_page(page);
-               return NULL;
+               return -EIO;
        }
-       return page;
+       p = kmap(page);
+       gfs2_sb_in(&sdp->sd_sb, p);
+       kunmap(page);
+       __free_page(page);
+       return 0;
 }
 
 /**
@@ -229,19 +258,13 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent)
        u32 tmp_blocks;
        unsigned int x;
        int error;
-       struct page *page;
-       char *sb;
 
-       page = gfs2_read_super(sdp->sd_vfs, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
-       if (!page) {
+       error = gfs2_read_super(sdp, GFS2_SB_ADDR >> sdp->sd_fsb2bb_shift);
+       if (error) {
                if (!silent)
                        fs_err(sdp, "can't read superblock\n");
-               return -EIO;
+               return error;
        }
-       sb = kmap(page);
-       gfs2_sb_in(&sdp->sd_sb, sb);
-       kunmap(page);
-       __free_page(page);
 
        error = gfs2_check_sb(sdp, &sdp->sd_sb, silent);
        if (error)
@@ -293,6 +316,7 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent)
                sdp->sd_heightsize[x] = space;
        }
        sdp->sd_max_height = x;
+       sdp->sd_heightsize[x] = ~0;
        gfs2_assert(sdp, sdp->sd_max_height <= GFS2_MAX_META_HEIGHT);
 
        sdp->sd_jheightsize[0] = sdp->sd_sb.sb_bsize -
@@ -311,6 +335,7 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent)
                sdp->sd_jheightsize[x] = space;
        }
        sdp->sd_max_jheight = x;
+       sdp->sd_jheightsize[x] = ~0;
        gfs2_assert(sdp, sdp->sd_max_jheight <= GFS2_MAX_META_HEIGHT);
 
        return 0;
@@ -341,15 +366,14 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
        mutex_lock(&sdp->sd_jindex_mutex);
 
        for (;;) {
-               error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED,
-                                          GL_LOCAL_EXCL, ji_gh);
+               error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, ji_gh);
                if (error)
                        break;
 
                name.len = sprintf(buf, "journal%u", sdp->sd_journals);
                name.hash = gfs2_disk_hash(name.name, name.len);
 
-               error = gfs2_dir_search(sdp->sd_jindex, &name, NULL, NULL);
+               error = gfs2_dir_check(sdp->sd_jindex, &name, NULL);
                if (error == -ENOENT) {
                        error = 0;
                        break;
@@ -365,6 +389,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
                if (!jd)
                        break;
 
+               INIT_LIST_HEAD(&jd->extent_list);
                jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1, NULL);
                if (!jd->jd_inode || IS_ERR(jd->jd_inode)) {
                        if (!jd->jd_inode)
@@ -394,8 +419,9 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
 
 void gfs2_jindex_free(struct gfs2_sbd *sdp)
 {
-       struct list_head list;
+       struct list_head list, *head;
        struct gfs2_jdesc *jd;
+       struct gfs2_journal_extent *jext;
 
        spin_lock(&sdp->sd_jindex_spin);
        list_add(&list, &sdp->sd_jindex_list);
@@ -405,6 +431,14 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp)
 
        while (!list_empty(&list)) {
                jd = list_entry(list.next, struct gfs2_jdesc, jd_list);
+               head = &jd->extent_list;
+               while (!list_empty(head)) {
+                       jext = list_entry(head->next,
+                                         struct gfs2_journal_extent,
+                                         extent_list);
+                       list_del(&jext->extent_list);
+                       kfree(jext);
+               }
                list_del(&jd->jd_list);
                iput(jd->jd_inode);
                kfree(jd);
@@ -511,13 +545,11 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
        struct gfs2_log_header_host head;
        int error;
 
-       error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED,
-                                  GL_LOCAL_EXCL, &t_gh);
+       error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &t_gh);
        if (error)
                return error;
 
-       gfs2_meta_cache_flush(ip);
-       j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA);
+       j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
 
        error = gfs2_find_jhead(sdp->sd_jdesc, &head);
        if (error)
@@ -565,9 +597,8 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
        gfs2_quota_sync(sdp);
        gfs2_statfs_sync(sdp);
 
-       error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED,
-                               GL_LOCAL_EXCL | GL_NOCACHE,
-                               &t_gh);
+       error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
+                                  &t_gh);
        if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
                return error;
 
@@ -584,6 +615,24 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
        return error;
 }
 
+static void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf)
+{
+       const struct gfs2_statfs_change *str = buf;
+
+       sc->sc_total = be64_to_cpu(str->sc_total);
+       sc->sc_free = be64_to_cpu(str->sc_free);
+       sc->sc_dinodes = be64_to_cpu(str->sc_dinodes);
+}
+
+static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf)
+{
+       struct gfs2_statfs_change *str = buf;
+
+       str->sc_total = cpu_to_be64(sc->sc_total);
+       str->sc_free = cpu_to_be64(sc->sc_free);
+       str->sc_dinodes = cpu_to_be64(sc->sc_dinodes);
+}
+
 int gfs2_statfs_init(struct gfs2_sbd *sdp)
 {
        struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
@@ -642,9 +691,7 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
        if (error)
                return;
 
-       mutex_lock(&sdp->sd_statfs_mutex);
        gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
-       mutex_unlock(&sdp->sd_statfs_mutex);
 
        spin_lock(&sdp->sd_statfs_spin);
        l_sc->sc_total += total;
@@ -692,9 +739,7 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp)
        if (error)
                goto out_bh2;
 
-       mutex_lock(&sdp->sd_statfs_mutex);
        gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
-       mutex_unlock(&sdp->sd_statfs_mutex);
 
        spin_lock(&sdp->sd_statfs_spin);
        m_sc->sc_total += l_sc->sc_total;
@@ -763,7 +808,7 @@ static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
                            struct gfs2_statfs_change_host *sc)
 {
        gfs2_rgrp_verify(rgd);
-       sc->sc_total += rgd->rd_ri.ri_data;
+       sc->sc_total += rgd->rd_data;
        sc->sc_free += rgd->rd_rg.rg_free;
        sc->sc_dinodes += rgd->rd_rg.rg_dinodes;
        return 0;