[GFS2] Fix a ref count bug and other clean ups
[powerpc.git] / fs / gfs2 / super.c
index be80771..a4da649 100644 (file)
 #include <linux/spinlock.h>
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
+#include <linux/crc32.h>
+#include <linux/gfs2_ondisk.h>
 #include <asm/semaphore.h>
 
 #include "gfs2.h"
+#include "lm_interface.h"
+#include "incore.h"
 #include "bmap.h"
 #include "dir.h"
 #include "format.h"
@@ -29,6 +33,7 @@
 #include "super.h"
 #include "trans.h"
 #include "unlinked.h"
+#include "util.h"
 
 /**
  * gfs2_tune_init - Fill a gfs2_tune structure with default values
@@ -94,7 +99,7 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent)
        if (sb->sb_header.mh_magic != GFS2_MAGIC ||
            sb->sb_header.mh_type != GFS2_METATYPE_SB) {
                if (!silent)
-                       printk("GFS2: not a GFS2 filesystem\n");
+                       printk(KERN_WARNING "GFS2: not a GFS2 filesystem\n");
                return -EINVAL;
        }
 
@@ -110,38 +115,45 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb *sb, int silent)
                                break;
 
                if (!gfs2_old_fs_formats[x]) {
-                       printk("GFS2: code version (%u, %u) is incompatible "
+                       printk(KERN_WARNING
+                              "GFS2: code version (%u, %u) is incompatible "
                               "with ondisk format (%u, %u)\n",
                               GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
                               sb->sb_fs_format, sb->sb_multihost_format);
-                       printk("GFS2: I don't know how to upgrade this FS\n");
+                       printk(KERN_WARNING
+                              "GFS2: I don't know how to upgrade this FS\n");
                        return -EINVAL;
                }
        }
 
        if (sb->sb_multihost_format != GFS2_FORMAT_MULTI) {
                for (x = 0; gfs2_old_multihost_formats[x]; x++)
-                       if (gfs2_old_multihost_formats[x] == sb->sb_multihost_format)
+                       if (gfs2_old_multihost_formats[x] ==
+                           sb->sb_multihost_format)
                                break;
 
                if (!gfs2_old_multihost_formats[x]) {
-                       printk("GFS2: code version (%u, %u) is incompatible "
+                       printk(KERN_WARNING
+                              "GFS2: code version (%u, %u) is incompatible "
                               "with ondisk format (%u, %u)\n",
                               GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
                               sb->sb_fs_format, sb->sb_multihost_format);
-                       printk("GFS2: I don't know how to upgrade this FS\n");
+                       printk(KERN_WARNING
+                              "GFS2: I don't know how to upgrade this FS\n");
                        return -EINVAL;
                }
        }
 
        if (!sdp->sd_args.ar_upgrade) {
-               printk("GFS2: code version (%u, %u) is incompatible "
+               printk(KERN_WARNING
+                      "GFS2: code version (%u, %u) is incompatible "
                       "with ondisk format (%u, %u)\n",
                       GFS2_FORMAT_FS, GFS2_FORMAT_MULTI,
                       sb->sb_fs_format, sb->sb_multihost_format);
-               printk("GFS2: Use the \"upgrade\" mount option to upgrade "
+               printk(KERN_INFO
+                      "GFS2: Use the \"upgrade\" mount option to upgrade "
                       "the FS\n");
-               printk("GFS2: See the manual for more details\n");
+               printk(KERN_INFO "GFS2: See the manual for more details\n");
                return -EINVAL;
        }
 
@@ -200,12 +212,12 @@ int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent)
 
        /* Compute maximum reservation required to add a entry to a directory */
 
-       hash_blocks = DIV_RU(sizeof(uint64_t) * (1 << GFS2_DIR_MAX_DEPTH),
+       hash_blocks = DIV_ROUND_UP(sizeof(uint64_t) * (1 << GFS2_DIR_MAX_DEPTH),
                             sdp->sd_jbsize);
 
        ind_blocks = 0;
        for (tmp_blocks = hash_blocks; tmp_blocks > sdp->sd_diptrs;) {
-               tmp_blocks = DIV_RU(tmp_blocks, sdp->sd_inptrs);
+               tmp_blocks = DIV_ROUND_UP(tmp_blocks, sdp->sd_inptrs);
                ind_blocks += tmp_blocks;
        }
 
@@ -271,7 +283,7 @@ int gfs2_do_upgrade(struct gfs2_sbd *sdp, struct gfs2_glock *sb_gl)
 
 int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
 {
-       struct gfs2_inode *dip = get_v2ip(sdp->sd_jindex);
+       struct gfs2_inode *dip = sdp->sd_jindex->u.generic_ip;
        struct qstr name;
        char buf[20];
        struct gfs2_jdesc *jd;
@@ -288,8 +300,10 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
                        break;
 
                name.len = sprintf(buf, "journal%u", sdp->sd_journals);
+               name.hash = gfs2_disk_hash(name.name, name.len);
 
-               error = gfs2_dir_search(get_v2ip(sdp->sd_jindex), &name, NULL, NULL);
+               error = gfs2_dir_search(sdp->sd_jindex,
+                                       &name, NULL, NULL);
                if (error == -ENOENT) {
                        error = 0;
                        break;
@@ -305,8 +319,12 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
                if (!jd)
                        break;
 
-               error = gfs2_lookupi(sdp->sd_jindex, &name, 1, &jd->jd_inode);
-               if (error) {
+               jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1, NULL);
+               if (!jd->jd_inode || IS_ERR(jd->jd_inode)) {
+                       if (!jd->jd_inode)
+                               error = -ENOENT;
+                       else
+                               error = PTR_ERR(jd->jd_inode);
                        kfree(jd);
                        break;
                }
@@ -411,7 +429,7 @@ struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp)
 
 int gfs2_jdesc_check(struct gfs2_jdesc *jd)
 {
-       struct gfs2_inode *ip = get_v2ip(jd->jd_inode);
+       struct gfs2_inode *ip = jd->jd_inode->u.generic_ip;
        struct gfs2_sbd *sdp = ip->i_sbd;
        int ar;
        int error;
@@ -435,24 +453,6 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
        return error;
 }
 
-int gfs2_lookup_master_dir(struct gfs2_sbd *sdp)
-{
-       struct inode *inode = NULL;
-       struct gfs2_glock *gl;
-       int error;
-
-       error = gfs2_glock_get(sdp,
-                              sdp->sd_sb.sb_master_dir.no_addr,
-                              &gfs2_inode_glops, CREATE, &gl);
-       if (!error) {
-               error = gfs2_lookup_simple(sdp->sd_root_dir, ".gfs2_admin", &inode);
-               sdp->sd_master_dir = inode;
-               gfs2_glock_put(gl);
-       }
-
-       return error;
-}
-
 /**
  * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
  * @sdp: the filesystem
@@ -462,7 +462,8 @@ int gfs2_lookup_master_dir(struct gfs2_sbd *sdp)
 
 int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
 {
-       struct gfs2_glock *j_gl = get_v2ip(sdp->sd_jdesc->jd_inode)->i_gl;
+       struct gfs2_inode *ip = sdp->sd_jdesc->jd_inode->u.generic_ip;
+       struct gfs2_glock *j_gl = ip->i_gl;
        struct gfs2_holder t_gh;
        struct gfs2_log_header head;
        int error;
@@ -472,7 +473,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
        if (error)
                return error;
 
-       gfs2_meta_cache_flush(get_v2ip(sdp->sd_jdesc->jd_inode));
+       gfs2_meta_cache_flush(ip);
        j_gl->gl_ops->go_inval(j_gl, DIO_METADATA | DIO_DATA);
 
        error = gfs2_find_jhead(sdp->sd_jdesc, &head);
@@ -550,9 +551,9 @@ int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
 
 int gfs2_statfs_init(struct gfs2_sbd *sdp)
 {
-       struct gfs2_inode *m_ip = get_v2ip(sdp->sd_statfs_inode);
+       struct gfs2_inode *m_ip = sdp->sd_statfs_inode->u.generic_ip;
        struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master;
-       struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode);
+       struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip;
        struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
        struct buffer_head *m_bh, *l_bh;
        struct gfs2_holder gh;
@@ -599,7 +600,7 @@ int gfs2_statfs_init(struct gfs2_sbd *sdp)
 void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free,
                        int64_t dinodes)
 {
-       struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode);
+       struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip;
        struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
        struct buffer_head *l_bh;
        int error;
@@ -625,8 +626,8 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, int64_t total, int64_t free,
 
 int gfs2_statfs_sync(struct gfs2_sbd *sdp)
 {
-       struct gfs2_inode *m_ip = get_v2ip(sdp->sd_statfs_inode);
-       struct gfs2_inode *l_ip = get_v2ip(sdp->sd_sc_inode);
+       struct gfs2_inode *m_ip = sdp->sd_statfs_inode->u.generic_ip;
+       struct gfs2_inode *l_ip = sdp->sd_sc_inode->u.generic_ip;
        struct gfs2_statfs_change *m_sc = &sdp->sd_statfs_master;
        struct gfs2_statfs_change *l_sc = &sdp->sd_statfs_local;
        struct gfs2_holder gh;
@@ -786,7 +787,8 @@ int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change *sc)
                                        error = err;
                                } else {
                                        if (!error)
-                                               error = statfs_slow_fill(get_gl2rgd(gh->gh_gl), sc);
+                                               error = statfs_slow_fill(
+                                                       gh->gh_gl->gl_object, sc);
                                        gfs2_glock_dq_uninit(gh);
                                }
                        }
@@ -837,6 +839,7 @@ struct lfcc {
 
 int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh)
 {
+       struct gfs2_inode *ip;
        struct gfs2_holder ji_gh;
        struct gfs2_jdesc *jd;
        struct lfcc *lfcc;
@@ -854,7 +857,9 @@ int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp, struct gfs2_holder *t_gh)
                        error = -ENOMEM;
                        goto out;
                }
-               error = gfs2_glock_nq_init(get_v2ip(jd->jd_inode)->i_gl, LM_ST_SHARED, 0,
+               ip = jd->jd_inode->u.generic_ip;
+               error = gfs2_glock_nq_init(ip->i_gl,
+                                          LM_ST_SHARED, 0,
                                           &lfcc->gh);
                if (error) {
                        kfree(lfcc);