/*
* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
- * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2006 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/vmalloc.h>
#include <linux/blkdev.h>
#include <linux/kthread.h>
-#include <asm/semaphore.h>
+#include <linux/gfs2_ondisk.h>
#include "gfs2.h"
+#include "lm_interface.h"
+#include "incore.h"
#include "daemon.h"
#include "glock.h"
#include "glops.h"
#include "super.h"
#include "unlinked.h"
#include "sys.h"
+#include "util.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;
memset(sdp, 0, sizeof(struct gfs2_sbd));
- set_v2sdp(sb, sdp);
+ sb->s_fs_info = sdp;
sdp->sd_vfs = sb;
gfs2_tune_init(&sdp->sd_tune);
INIT_LIST_HEAD(&sdp->sd_reclaim_list);
spin_lock_init(&sdp->sd_reclaim_lock);
init_waitqueue_head(&sdp->sd_reclaim_wq);
- init_MUTEX(&sdp->sd_invalidate_inodes_mutex);
+ mutex_init(&sdp->sd_invalidate_inodes_mutex);
- init_MUTEX(&sdp->sd_inum_mutex);
+ mutex_init(&sdp->sd_inum_mutex);
spin_lock_init(&sdp->sd_statfs_spin);
- init_MUTEX(&sdp->sd_statfs_mutex);
+ mutex_init(&sdp->sd_statfs_mutex);
spin_lock_init(&sdp->sd_rindex_spin);
- init_MUTEX(&sdp->sd_rindex_mutex);
+ mutex_init(&sdp->sd_rindex_mutex);
INIT_LIST_HEAD(&sdp->sd_rindex_list);
INIT_LIST_HEAD(&sdp->sd_rindex_mru_list);
INIT_LIST_HEAD(&sdp->sd_rindex_recent_list);
INIT_LIST_HEAD(&sdp->sd_jindex_list);
spin_lock_init(&sdp->sd_jindex_spin);
- init_MUTEX(&sdp->sd_jindex_mutex);
+ mutex_init(&sdp->sd_jindex_mutex);
INIT_LIST_HEAD(&sdp->sd_unlinked_list);
spin_lock_init(&sdp->sd_unlinked_spin);
- init_MUTEX(&sdp->sd_unlinked_mutex);
+ mutex_init(&sdp->sd_unlinked_mutex);
INIT_LIST_HEAD(&sdp->sd_quota_list);
spin_lock_init(&sdp->sd_quota_spin);
- init_MUTEX(&sdp->sd_quota_mutex);
+ mutex_init(&sdp->sd_quota_mutex);
spin_lock_init(&sdp->sd_log_lock);
- init_waitqueue_head(&sdp->sd_log_trans_wq);
- init_waitqueue_head(&sdp->sd_log_flush_wq);
INIT_LIST_HEAD(&sdp->sd_log_le_gl);
INIT_LIST_HEAD(&sdp->sd_log_le_buf);
INIT_LIST_HEAD(&sdp->sd_log_le_rg);
INIT_LIST_HEAD(&sdp->sd_log_le_databuf);
- INIT_LIST_HEAD(&sdp->sd_log_blks_list);
- init_waitqueue_head(&sdp->sd_log_blks_wait);
-
+ mutex_init(&sdp->sd_log_reserve_mutex);
INIT_LIST_HEAD(&sdp->sd_ail1_list);
INIT_LIST_HEAD(&sdp->sd_ail2_list);
- init_MUTEX(&sdp->sd_log_flush_lock);
+ init_rwsem(&sdp->sd_log_flush_lock);
INIT_LIST_HEAD(&sdp->sd_log_flush_list);
INIT_LIST_HEAD(&sdp->sd_revoke_list);
- init_MUTEX(&sdp->sd_freeze_lock);
+ mutex_init(&sdp->sd_freeze_lock);
return sdp;
}
-static void init_vfs(struct gfs2_sbd *sdp)
+static void init_vfs(struct super_block *sb, unsigned noatime)
{
- struct super_block *sb = sdp->sd_vfs;
+ struct gfs2_sbd *sdp = sb->s_fs_info;
sb->s_magic = GFS2_MAGIC;
sb->s_op = &gfs2_super_ops;
sb->s_maxbytes = MAX_LFS_FILESIZE;
if (sb->s_flags & (MS_NOATIME | MS_NODIRATIME))
- set_bit(SDF_NOATIME, &sdp->sd_flags);
+ set_bit(noatime, &sdp->sd_flags);
/* Don't let the VFS update atimes. GFS2 handles this itself. */
sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
-
- /* Set up the buffer cache and fill in some fake block size values
- to allow us to read-in the on-disk superblock. */
- sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
- sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
- sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift - GFS2_BASIC_BLOCK_SHIFT;
- sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
}
static int init_names(struct gfs2_sbd *sdp, int silent)
error = gfs2_glock_nq_num(sdp,
GFS2_LIVE_LOCK, &gfs2_nondisk_glops,
LM_ST_SHARED,
- LM_FLAG_NOEXP | GL_EXACT | GL_NEVER_RECURSE,
+ LM_FLAG_NOEXP | GL_EXACT,
&sdp->sd_live_gh);
if (error) {
fs_err(sdp, "can't acquire live glock: %d\n", error);
return error;
}
-int gfs2_lookup_root(struct gfs2_sbd *sdp)
+static struct inode *gfs2_lookup_root(struct gfs2_sbd *sdp,
+ const struct gfs2_inum *inum)
{
int error;
struct gfs2_glock *gl;
struct gfs2_inode *ip;
+ struct inode *inode;
- error = gfs2_glock_get(sdp, sdp->sd_sb.sb_root_dir.no_addr,
- &gfs2_inode_glops, CREATE, &gl);
+ error = gfs2_glock_get(sdp, inum->no_addr, &gfs2_inode_glops,
+ CREATE, &gl);
if (!error) {
- error = gfs2_inode_get(gl, &sdp->sd_sb.sb_root_dir,
- CREATE, &ip);
+ error = gfs2_inode_get(gl, inum, CREATE, &ip);
if (!error) {
- if (!error)
- gfs2_inode_min_init(ip, DT_DIR);
- sdp->sd_root_dir = gfs2_ip2v(ip);
+ gfs2_inode_min_init(ip, DT_DIR);
+ inode = gfs2_ip2v(ip);
gfs2_inode_put(ip);
+ gfs2_glock_put(gl);
+ return inode;
}
gfs2_glock_put(gl);
}
-
- return error;
+ return ERR_PTR(error);
}
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;
struct inode *inode;
int error = 0;
if (undo) {
- iput(sdp->sd_master_dir);
return 0;
}
}
/* Set up the buffer cache and SB for real */
- error = -EINVAL;
if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) {
+ error = -EINVAL;
fs_err(sdp, "FS block size (%u) is too small for device "
"block size (%u)\n",
sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev));
goto out;
}
if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
+ error = -EINVAL;
fs_err(sdp, "FS block size (%u) is too big for machine "
"page size (%u)\n",
sdp->sd_sb.sb_bsize, (unsigned int)PAGE_SIZE);
sb_set_blocksize(sb, sdp->sd_sb.sb_bsize);
/* Get the root inode */
- error = gfs2_lookup_root(sdp);
- if (error) {
+ inum = &sdp->sd_sb.sb_root_dir;
+ if (sb->s_type == &gfs2meta_fs_type)
+ inum = &sdp->sd_sb.sb_master_dir;
+ inode = gfs2_lookup_root(sdp, inum);
+ if (IS_ERR(inode)) {
+ error = PTR_ERR(inode);
fs_err(sdp, "can't read in root inode: %d\n", error);
goto out;
}
- /* Get the root inode/dentry */
- inode = sdp->sd_root_dir;
- if (!inode) {
- fs_err(sdp, "can't get root inode\n");
- error = -ENOMEM;
- goto out_rooti;
- }
-
sb->s_root = d_alloc_root(inode);
if (!sb->s_root) {
fs_err(sdp, "can't get root dentry\n");
error = -ENOMEM;
- goto out_rooti;
+ iput(inode);
}
-
+ sb->s_root->d_op = &gfs2_dops;
out:
gfs2_glock_dq_uninit(&sb_gh);
-
return error;
-out_rooti:
- iput(sdp->sd_root_dir);
- goto out;
}
static int init_journal(struct gfs2_sbd *sdp, int undo)
{
struct gfs2_holder ji_gh;
struct task_struct *p;
+ struct gfs2_inode *ip;
int jindex = 1;
int error = 0;
goto fail_recoverd;
}
- error = gfs2_lookup_simple(sdp->sd_master_dir, "jindex",
- &sdp->sd_jindex);
- if (error) {
+ sdp->sd_jindex = gfs2_lookup_simple(sdp->sd_master_dir, "jindex");
+ if (IS_ERR(sdp->sd_jindex)) {
fs_err(sdp, "can't lookup journal index: %d\n", error);
- return error;
+ return PTR_ERR(sdp->sd_jindex);
}
- set_bit(GLF_STICKY, &get_v2ip(sdp->sd_jindex)->i_gl->gl_flags);
+ ip = sdp->sd_jindex->u.generic_ip;
+ set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
/* Load in the journal index special file */
goto fail_jindex;
}
- error = gfs2_glock_nq_init(sdp->sd_jdesc->jd_inode->i_gl,
+ ip = sdp->sd_jdesc->jd_inode->u.generic_ip;
+ error = gfs2_glock_nq_init(ip->i_gl,
LM_ST_SHARED,
LM_FLAG_NOEXP | GL_EXACT,
&sdp->sd_jinode_gh);
if (sdp->sd_lockstruct.ls_first) {
unsigned int x;
for (x = 0; x < sdp->sd_journals; x++) {
- error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x),
- WAIT);
+ error = gfs2_recover_journal(gfs2_jdesc_find(sdp, x));
if (error) {
fs_err(sdp, "error recovering journal %u: %d\n",
x, error);
gfs2_lm_others_may_mount(sdp);
} else if (!sdp->sd_args.ar_spectator) {
- error = gfs2_recover_journal(sdp->sd_jdesc, WAIT);
+ error = gfs2_recover_journal(sdp->sd_jdesc);
if (error) {
fs_err(sdp, "error recovering my journal: %d\n", error);
goto fail_jinode_gh;
gfs2_glock_dq_uninit(&ji_gh);
jindex = 0;
- /* Disown my Journal glock */
-
- sdp->sd_journal_gh.gh_owner = NULL;
- sdp->sd_jinode_gh.gh_owner = NULL;
-
p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
error = IS_ERR(p);
if (error) {
static int init_inodes(struct gfs2_sbd *sdp, int undo)
{
int error = 0;
+ struct gfs2_inode *ip;
+ struct inode *inode;
if (undo)
goto fail_qinode;
- error = gfs2_lookup_master_dir(sdp);
- if (error) {
+ inode = gfs2_lookup_root(sdp, &sdp->sd_sb.sb_master_dir);
+ if (IS_ERR(inode)) {
+ error = PTR_ERR(inode);
fs_err(sdp, "can't read in master directory: %d\n", error);
goto fail;
}
+ sdp->sd_master_dir = inode;
error = init_journal(sdp, undo);
if (error)
goto fail_master;
/* Read in the master inode number inode */
- error = gfs2_lookup_simple(sdp->sd_master_dir, "inum",
- &sdp->sd_inum_inode);
- if (error) {
+ sdp->sd_inum_inode = gfs2_lookup_simple(sdp->sd_master_dir, "inum");
+ if (IS_ERR(sdp->sd_inum_inode)) {
+ error = PTR_ERR(sdp->sd_inum_inode);
fs_err(sdp, "can't read in inum inode: %d\n", error);
goto fail_journal;
}
/* Read in the master statfs inode */
- error = gfs2_lookup_simple(sdp->sd_master_dir, "statfs",
- &sdp->sd_statfs_inode);
- if (error) {
+ sdp->sd_statfs_inode = gfs2_lookup_simple(sdp->sd_master_dir, "statfs");
+ if (IS_ERR(sdp->sd_statfs_inode)) {
+ error = PTR_ERR(sdp->sd_statfs_inode);
fs_err(sdp, "can't read in statfs inode: %d\n", error);
goto fail_inum;
}
/* Read in the resource index inode */
- error = gfs2_lookup_simple(sdp->sd_master_dir, "rindex",
- &sdp->sd_rindex);
- if (error) {
+ sdp->sd_rindex = gfs2_lookup_simple(sdp->sd_master_dir, "rindex");
+ if (IS_ERR(sdp->sd_rindex)) {
+ error = PTR_ERR(sdp->sd_rindex);
fs_err(sdp, "can't get resource index inode: %d\n", error);
goto fail_statfs;
}
- set_bit(GLF_STICKY, &get_v2ip(sdp->sd_rindex)->i_gl->gl_flags);
- sdp->sd_rindex_vn = get_v2ip(sdp->sd_rindex)->i_gl->gl_vn - 1;
+ ip = sdp->sd_rindex->u.generic_ip;
+ set_bit(GLF_STICKY, &ip->i_gl->gl_flags);
+ sdp->sd_rindex_vn = ip->i_gl->gl_vn - 1;
/* Read in the quota inode */
- error = gfs2_lookup_simple(sdp->sd_master_dir, "quota",
- &sdp->sd_quota_inode);
- if (error) {
+ sdp->sd_quota_inode = gfs2_lookup_simple(sdp->sd_master_dir, "quota");
+ if (IS_ERR(sdp->sd_quota_inode)) {
+ error = PTR_ERR(sdp->sd_quota_inode);
fs_err(sdp, "can't get quota file inode: %d\n", error);
goto fail_rindex;
}
struct inode *pn = NULL;
char buf[30];
int error = 0;
+ struct gfs2_inode *ip;
if (sdp->sd_args.ar_spectator)
return 0;
if (undo)
goto fail_qc_gh;
- error = gfs2_lookup_simple(sdp->sd_master_dir, "per_node", &pn);
- if (error) {
+ pn = gfs2_lookup_simple(sdp->sd_master_dir, "per_node");
+ if (IS_ERR(pn)) {
+ error = PTR_ERR(pn);
fs_err(sdp, "can't find per_node directory: %d\n", error);
return error;
}
sprintf(buf, "inum_range%u", sdp->sd_jdesc->jd_jid);
- error = gfs2_lookup_simple(pn, buf, &sdp->sd_ir_inode);
- if (error) {
+ sdp->sd_ir_inode = gfs2_lookup_simple(pn, buf);
+ if (IS_ERR(sdp->sd_ir_inode)) {
+ error = PTR_ERR(sdp->sd_ir_inode);
fs_err(sdp, "can't find local \"ir\" file: %d\n", error);
goto fail;
}
sprintf(buf, "statfs_change%u", sdp->sd_jdesc->jd_jid);
- error = gfs2_lookup_simple(pn, buf, &sdp->sd_sc_inode);
- if (error) {
+ sdp->sd_sc_inode = gfs2_lookup_simple(pn, buf);
+ if (IS_ERR(sdp->sd_sc_inode)) {
+ error = PTR_ERR(sdp->sd_sc_inode);
fs_err(sdp, "can't find local \"sc\" file: %d\n", error);
goto fail_ir_i;
}
sprintf(buf, "unlinked_tag%u", sdp->sd_jdesc->jd_jid);
- error = gfs2_lookup_simple(pn, buf, &sdp->sd_ut_inode);
- if (error) {
+ sdp->sd_ut_inode = gfs2_lookup_simple(pn, buf);
+ if (IS_ERR(sdp->sd_ut_inode)) {
+ error = PTR_ERR(sdp->sd_ut_inode);
fs_err(sdp, "can't find local \"ut\" file: %d\n", error);
goto fail_sc_i;
}
sprintf(buf, "quota_change%u", sdp->sd_jdesc->jd_jid);
- error = gfs2_lookup_simple(pn, buf, &sdp->sd_qc_inode);
- if (error) {
+ sdp->sd_qc_inode = gfs2_lookup_simple(pn, buf);
+ if (IS_ERR(sdp->sd_qc_inode)) {
+ error = PTR_ERR(sdp->sd_qc_inode);
fs_err(sdp, "can't find local \"qc\" file: %d\n", error);
goto fail_ut_i;
}
iput(pn);
pn = NULL;
- error = gfs2_glock_nq_init(get_v2ip(sdp->sd_ir_inode)->i_gl,
- LM_ST_EXCLUSIVE, GL_NEVER_RECURSE,
+ ip = sdp->sd_ir_inode->u.generic_ip;
+ error = gfs2_glock_nq_init(ip->i_gl,
+ LM_ST_EXCLUSIVE, 0,
&sdp->sd_ir_gh);
if (error) {
fs_err(sdp, "can't lock local \"ir\" file: %d\n", error);
goto fail_qc_i;
}
- error = gfs2_glock_nq_init(get_v2ip(sdp->sd_sc_inode)->i_gl,
- LM_ST_EXCLUSIVE, GL_NEVER_RECURSE,
+ ip = sdp->sd_sc_inode->u.generic_ip;
+ error = gfs2_glock_nq_init(ip->i_gl,
+ LM_ST_EXCLUSIVE, 0,
&sdp->sd_sc_gh);
if (error) {
fs_err(sdp, "can't lock local \"sc\" file: %d\n", error);
goto fail_ir_gh;
}
- error = gfs2_glock_nq_init(get_v2ip(sdp->sd_ut_inode)->i_gl,
- LM_ST_EXCLUSIVE, GL_NEVER_RECURSE,
+ ip = sdp->sd_ut_inode->u.generic_ip;
+ error = gfs2_glock_nq_init(ip->i_gl,
+ LM_ST_EXCLUSIVE, 0,
&sdp->sd_ut_gh);
if (error) {
fs_err(sdp, "can't lock local \"ut\" file: %d\n", error);
goto fail_sc_gh;
}
- error = gfs2_glock_nq_init(get_v2ip(sdp->sd_qc_inode)->i_gl,
- LM_ST_EXCLUSIVE, GL_NEVER_RECURSE,
+ ip = sdp->sd_qc_inode->u.generic_ip;
+ error = gfs2_glock_nq_init(ip->i_gl,
+ LM_ST_EXCLUSIVE, 0,
&sdp->sd_qc_gh);
if (error) {
fs_err(sdp, "can't lock local \"qc\" file: %d\n", error);
sdp = init_sbd(sb);
if (!sdp) {
- printk("GFS2: can't alloc struct gfs2_sbd\n");
+ printk(KERN_WARNING "GFS2: can't alloc struct gfs2_sbd\n");
return -ENOMEM;
}
error = gfs2_mount_args(sdp, (char *)data, 0);
if (error) {
- printk("GFS2: can't parse mount arguments\n");
+ printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
goto fail;
}
- init_vfs(sdp);
+ init_vfs(sb, SDF_NOATIME);
+
+ /* Set up the buffer cache and fill in some fake block size values
+ to allow us to read-in the on-disk superblock. */
+ sdp->sd_sb.sb_bsize = sb_min_blocksize(sb, GFS2_BASIC_BLOCK);
+ sdp->sd_sb.sb_bsize_shift = sb->s_blocksize_bits;
+ sdp->sd_fsb2bb_shift = sdp->sd_sb.sb_bsize_shift -
+ GFS2_BASIC_BLOCK_SHIFT;
+ sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
error = init_names(sdp, silent);
if (error)
fail:
vfree(sdp);
- set_v2sdp(sb, NULL);
+ sb->s_fs_info = NULL;
return error;
}
return get_sb_bdev(fs_type, flags, dev_name, data, fill_super);
}
+static void gfs2_kill_sb(struct super_block *sb)
+{
+ kill_block_super(sb);
+}
+
struct file_system_type gfs2_fs_type = {
.name = "gfs2",
.fs_flags = FS_REQUIRES_DEV,
.get_sb = gfs2_get_sb,
- .kill_sb = kill_block_super,
+ .kill_sb = gfs2_kill_sb,
+ .owner = THIS_MODULE,
+};
+
+struct file_system_type gfs2meta_fs_type = {
+ .name = "gfs2meta",
+ .fs_flags = FS_REQUIRES_DEV,
+ .get_sb = gfs2_get_sb,
+ .kill_sb = gfs2_kill_sb,
.owner = THIS_MODULE,
};