/*
* 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/spinlock.h>
#include <linux/completion.h>
#include <linux/buffer_head.h>
-#include <asm/semaphore.h>
+#include <linux/gfs2_ondisk.h>
#include "gfs2.h"
+#include "lm_interface.h"
+#include "incore.h"
#include "glock.h"
#include "log.h"
#include "lops.h"
#include "recovery.h"
#include "rgrp.h"
#include "trans.h"
+#include "util.h"
static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
{
struct gfs2_glock *gl;
+ struct gfs2_trans *tr = current->journal_info;
- get_transaction->tr_touched = 1;
+ tr->tr_touched = 1;
if (!list_empty(&le->le_list))
return;
if (!list_empty(&bd->bd_list_tr))
return;
- tr = get_transaction;
+ tr = current->journal_info;
tr->tr_touched = 1;
tr->tr_num_buf++;
list_add(&bd->bd_list_tr, &tr->tr_list_buf);
if (total > limit)
num = limit;
bh = gfs2_log_get_buf(sdp);
+ sdp->sd_log_num_hdrs++;
ld = (struct gfs2_log_descriptor *)bh->b_data;
ptr = (__be64 *)(bh->b_data + offset);
ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
- ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD);
- ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD);
+ ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD);
+ ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD);
ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_METADATA);
ld->ld_length = cpu_to_be32(num + 1);
ld->ld_data1 = cpu_to_be32(num);
memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved));
n = 0;
- list_for_each_entry_continue(bd1, &sdp->sd_log_le_buf, bd_le.le_list) {
+ list_for_each_entry_continue(bd1, &sdp->sd_log_le_buf,
+ bd_le.le_list) {
*ptr++ = cpu_to_be64(bd1->bd_bh->b_blocknr);
if (++n >= num)
break;
ll_rw_block(WRITE, 1, &bh);
n = 0;
- list_for_each_entry_continue(bd2, &sdp->sd_log_le_buf, bd_le.le_list) {
+ list_for_each_entry_continue(bd2, &sdp->sd_log_le_buf,
+ bd_le.le_list) {
bh = gfs2_log_fake_buf(sdp, bd2->bd_bh);
set_buffer_dirty(bh);
ll_rw_block(WRITE, 1, &bh);
static void buf_lo_before_scan(struct gfs2_jdesc *jd,
struct gfs2_log_header *head, int pass)
{
- struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
if (pass != 0)
return;
struct gfs2_log_descriptor *ld, __be64 *ptr,
int pass)
{
- struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd;
- struct gfs2_glock *gl = get_v2ip(jd->jd_inode)->i_gl;
+ struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
+ struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
+ struct gfs2_glock *gl = ip->i_gl;
unsigned int blks = be32_to_cpu(ld->ld_data1);
struct buffer_head *bh_log, *bh_ip;
uint64_t blkno;
static void buf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
{
- struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd;
+ struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
+ struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
if (error) {
- gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT);
+ gfs2_meta_sync(ip->i_gl,
+ DIO_START | DIO_WAIT);
return;
}
if (pass != 1)
return;
- gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT);
+ gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT);
fs_info(sdp, "jid=%u: Replayed %u of %u blocks\n",
jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks);
{
struct gfs2_trans *tr;
- tr = get_transaction;
+ tr = current->journal_info;
tr->tr_touched = 1;
tr->tr_num_revoke++;
bh = gfs2_log_get_buf(sdp);
ld = (struct gfs2_log_descriptor *)bh->b_data;
ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
- ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD);
- ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD);
+ ld->ld_header.mh_type = cpu_to_be32(GFS2_METATYPE_LD);
+ ld->ld_header.mh_format = cpu_to_be32(GFS2_FORMAT_LD);
ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_REVOKE);
- ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke, sizeof(uint64_t)));
+ ld->ld_length = cpu_to_be32(gfs2_struct2blk(sdp, sdp->sd_log_num_revoke,
+ sizeof(uint64_t)));
ld->ld_data1 = cpu_to_be32(sdp->sd_log_num_revoke);
ld->ld_data2 = cpu_to_be32(0);
memset(ld->ld_reserved, 0, sizeof(ld->ld_reserved));
while (!list_empty(head)) {
rv = list_entry(head->next, struct gfs2_revoke, rv_le.le_list);
- list_del(&rv->rv_le.le_list);
+ list_del_init(&rv->rv_le.le_list);
sdp->sd_log_num_revoke--;
if (offset + sizeof(uint64_t) > sdp->sd_sb.sb_bsize) {
bh = gfs2_log_get_buf(sdp);
mh = (struct gfs2_meta_header *)bh->b_data;
mh->mh_magic = cpu_to_be32(GFS2_MAGIC);
- mh->mh_type = cpu_to_be16(GFS2_METATYPE_LB);
- mh->mh_format = cpu_to_be16(GFS2_FORMAT_LB);
+ mh->mh_type = cpu_to_be32(GFS2_METATYPE_LB);
+ mh->mh_format = cpu_to_be32(GFS2_FORMAT_LB);
offset = sizeof(struct gfs2_meta_header);
}
static void revoke_lo_before_scan(struct gfs2_jdesc *jd,
struct gfs2_log_header *head, int pass)
{
- struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
if (pass != 0)
return;
struct gfs2_log_descriptor *ld, __be64 *ptr,
int pass)
{
- struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
unsigned int blks = be32_to_cpu(ld->ld_length);
unsigned int revokes = be32_to_cpu(ld->ld_data1);
struct buffer_head *bh;
static void revoke_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
{
- struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd;
+ struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
if (error) {
gfs2_revoke_clean(sdp);
static void rg_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
{
struct gfs2_rgrpd *rgd;
+ struct gfs2_trans *tr = current->journal_info;
- get_transaction->tr_touched = 1;
+ tr->tr_touched = 1;
if (!list_empty(&le->le_list))
return;
static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
{
struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le);
- struct gfs2_trans *tr = get_transaction;
+ struct gfs2_trans *tr = current->journal_info;
struct address_space *mapping = bd->bd_bh->b_page->mapping;
- struct gfs2_inode *ip = get_v2ip(mapping->host);
+ struct gfs2_inode *ip = GFS2_I(mapping->host);
tr->tr_touched = 1;
- if (!list_empty(&bd->bd_list_tr) &&
+ if (list_empty(&bd->bd_list_tr) &&
(ip->i_di.di_flags & GFS2_DIF_JDATA)) {
tr->tr_num_buf++;
- gfs2_trans_add_gl(bd->bd_gl);
list_add(&bd->bd_list_tr, &tr->tr_list_buf);
gfs2_pin(sdp, bd->bd_bh);
+ tr->tr_num_buf_new++;
}
+ gfs2_trans_add_gl(bd->bd_gl);
gfs2_log_lock(sdp);
- if (ip->i_di.di_flags & GFS2_DIF_JDATA)
- sdp->sd_log_num_jdata++;
- sdp->sd_log_num_databuf++;
- list_add(&le->le_list, &sdp->sd_log_le_databuf);
+ if (list_empty(&le->le_list)) {
+ if (ip->i_di.di_flags & GFS2_DIF_JDATA)
+ sdp->sd_log_num_jdata++;
+ sdp->sd_log_num_databuf++;
+ list_add(&le->le_list, &sdp->sd_log_le_databuf);
+ }
gfs2_log_unlock(sdp);
}
unsigned int total_dbuf = sdp->sd_log_num_databuf;
unsigned int total_jdata = sdp->sd_log_num_jdata;
unsigned int num, n;
- __be64 *ptr;
+ __be64 *ptr = NULL;
offset += (2*sizeof(__be64) - 1);
offset &= ~(2*sizeof(__be64) - 1);
limit = (sdp->sd_sb.sb_bsize - offset)/sizeof(__be64);
- /* printk(KERN_INFO "totals: jdata=%u dbuf=%u\n", total_jdata, total_dbuf); */
/*
* Start writing ordered buffers, write journaled buffers
* into the log along with a header
*/
- bd2 = bd1 = list_prepare_entry(bd1, &sdp->sd_log_le_databuf, bd_le.le_list);
+ gfs2_log_lock(sdp);
+ bd2 = bd1 = list_prepare_entry(bd1, &sdp->sd_log_le_databuf,
+ bd_le.le_list);
while(total_dbuf) {
num = total_jdata;
if (num > limit)
num = limit;
n = 0;
- list_for_each_entry_safe_continue(bd1, bdt, &sdp->sd_log_le_databuf, bd_le.le_list) {
- gfs2_log_lock(sdp);
+ list_for_each_entry_safe_continue(bd1, bdt,
+ &sdp->sd_log_le_databuf,
+ bd_le.le_list) {
/* An ordered write buffer */
if (bd1->bd_bh && !buffer_pinned(bd1->bd_bh)) {
list_move(&bd1->bd_le.le_list, &started);
if (bd1 == bd2) {
bd2 = NULL;
- bd2 = list_prepare_entry(bd2, &sdp->sd_log_le_databuf, bd_le.le_list);
+ bd2 = list_prepare_entry(bd2,
+ &sdp->sd_log_le_databuf,
+ bd_le.le_list);
}
total_dbuf--;
if (bd1->bd_bh) {
get_bh(bd1->bd_bh);
- gfs2_log_unlock(sdp);
if (buffer_dirty(bd1->bd_bh)) {
+ gfs2_log_unlock(sdp);
wait_on_buffer(bd1->bd_bh);
- ll_rw_block(WRITE, 1, &bd1->bd_bh);
+ ll_rw_block(WRITE, 1,
+ &bd1->bd_bh);
+ gfs2_log_lock(sdp);
}
brelse(bd1->bd_bh);
continue;
}
- gfs2_log_unlock(sdp);
continue;
} else if (bd1->bd_bh) { /* A journaled buffer */
int magic;
gfs2_log_unlock(sdp);
- /* printk(KERN_INFO "journaled buffer\n"); */
if (!bh) {
bh = gfs2_log_get_buf(sdp);
- ld = (struct gfs2_log_descriptor *)bh->b_data;
+ sdp->sd_log_num_hdrs++;
+ ld = (struct gfs2_log_descriptor *)
+ bh->b_data;
ptr = (__be64 *)(bh->b_data + offset);
- ld->ld_header.mh_magic = cpu_to_be32(GFS2_MAGIC);
- ld->ld_header.mh_type = cpu_to_be16(GFS2_METATYPE_LD);
- ld->ld_header.mh_format = cpu_to_be16(GFS2_FORMAT_LD);
- ld->ld_type = cpu_to_be32(GFS2_LOG_DESC_JDATA);
+ ld->ld_header.mh_magic =
+ cpu_to_be32(GFS2_MAGIC);
+ ld->ld_header.mh_type =
+ cpu_to_be32(GFS2_METATYPE_LD);
+ ld->ld_header.mh_format =
+ cpu_to_be32(GFS2_FORMAT_LD);
+ ld->ld_type =
+ cpu_to_be32(GFS2_LOG_DESC_JDATA);
ld->ld_length = cpu_to_be32(num + 1);
ld->ld_data1 = cpu_to_be32(num);
ld->ld_data2 = cpu_to_be32(0);
clear_buffer_escaped(bd1->bd_bh);
if (unlikely(magic != 0))
set_buffer_escaped(bd1->bd_bh);
+ gfs2_log_lock(sdp);
if (n++ > num)
break;
}
}
+ gfs2_log_unlock(sdp);
if (bh) {
set_buffer_dirty(bh);
ll_rw_block(WRITE, 1, &bh);
bh = NULL;
}
n = 0;
- /* printk(KERN_INFO "totals2: jdata=%u dbuf=%u\n", total_jdata, total_dbuf); */
- list_for_each_entry_continue(bd2, &sdp->sd_log_le_databuf, bd_le.le_list) {
+ gfs2_log_lock(sdp);
+ list_for_each_entry_continue(bd2, &sdp->sd_log_le_databuf,
+ bd_le.le_list) {
if (!bd2->bd_bh)
continue;
/* copy buffer if it needs escaping */
+ gfs2_log_unlock(sdp);
if (unlikely(buffer_escaped(bd2->bd_bh))) {
void *kaddr;
struct page *page = bd2->bd_bh->b_page;
bh = gfs2_log_get_buf(sdp);
kaddr = kmap_atomic(page, KM_USER0);
- memcpy(bh->b_data, kaddr + bh_offset(bd2->bd_bh), sdp->sd_sb.sb_bsize);
+ memcpy(bh->b_data,
+ kaddr + bh_offset(bd2->bd_bh),
+ sdp->sd_sb.sb_bsize);
kunmap_atomic(page, KM_USER0);
*(__be32 *)bh->b_data = 0;
} else {
}
set_buffer_dirty(bh);
ll_rw_block(WRITE, 1, &bh);
+ gfs2_log_lock(sdp);
if (++n >= num)
break;
}
total_dbuf -= num;
total_jdata -= num;
}
- /* printk(KERN_INFO "wait on ordered data buffers\n"); */
+ gfs2_log_unlock(sdp);
+
/* Wait on all ordered buffers */
while (!list_empty(&started)) {
- bd1 = list_entry(started.next, struct gfs2_bufdata, bd_le.le_list);
- list_del(&bd1->bd_le.le_list);
- sdp->sd_log_num_databuf--;
-
gfs2_log_lock(sdp);
+ bd1 = list_entry(started.next, struct gfs2_bufdata,
+ bd_le.le_list);
+ list_del_init(&bd1->bd_le.le_list);
+ sdp->sd_log_num_databuf--;
bh = bd1->bd_bh;
if (bh) {
- set_v2bd(bh, NULL);
+ bh->b_private = NULL;
+ get_bh(bh);
gfs2_log_unlock(sdp);
wait_on_buffer(bh);
brelse(bh);
} else
gfs2_log_unlock(sdp);
- kfree(bd1);
+ kmem_cache_free(gfs2_bufdata_cachep, bd1);
}
- /* printk(KERN_INFO "sd_log_num_databuf %u sd_log_num_jdata %u\n", sdp->sd_log_num_databuf, sdp->sd_log_num_jdata); */
/* We've removed all the ordered write bufs here, so only jdata left */
gfs2_assert_warn(sdp, sdp->sd_log_num_databuf == sdp->sd_log_num_jdata);
}
struct gfs2_log_descriptor *ld,
__be64 *ptr, int pass)
{
- struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd;
- struct gfs2_glock *gl = get_v2ip(jd->jd_inode)->i_gl;
+ struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
+ struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
+ struct gfs2_glock *gl = ip->i_gl;
unsigned int blks = be32_to_cpu(ld->ld_data1);
struct buffer_head *bh_log, *bh_ip;
uint64_t blkno;
static void databuf_lo_after_scan(struct gfs2_jdesc *jd, int error, int pass)
{
- struct gfs2_sbd *sdp = get_v2ip(jd->jd_inode)->i_sbd;
+ struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
+ struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
if (error) {
- gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT);
+ gfs2_meta_sync(ip->i_gl,
+ DIO_START | DIO_WAIT);
return;
}
if (pass != 1)
return;
/* data sync? */
- gfs2_meta_sync(get_v2ip(jd->jd_inode)->i_gl, DIO_START | DIO_WAIT);
+ gfs2_meta_sync(ip->i_gl, DIO_START | DIO_WAIT);
fs_info(sdp, "jid=%u: Replayed %u of %u data blocks\n",
jd->jd_jid, sdp->sd_replayed_blocks, sdp->sd_found_blocks);
while (!list_empty(head)) {
bd = list_entry(head->next, struct gfs2_bufdata, bd_le.le_list);
- list_del_init(&bd->bd_le.le_list);
+ list_del(&bd->bd_le.le_list);
sdp->sd_log_num_databuf--;
sdp->sd_log_num_jdata--;
gfs2_unpin(sdp, bd->bd_bh, ai);
- brelse(bd->bd_bh);
- kfree(bd);
}
gfs2_assert_warn(sdp, !sdp->sd_log_num_databuf);
gfs2_assert_warn(sdp, !sdp->sd_log_num_jdata);
}
-struct gfs2_log_operations gfs2_glock_lops = {
+const struct gfs2_log_operations gfs2_glock_lops = {
.lo_add = glock_lo_add,
.lo_after_commit = glock_lo_after_commit,
.lo_name = "glock"
};
-struct gfs2_log_operations gfs2_buf_lops = {
+const struct gfs2_log_operations gfs2_buf_lops = {
.lo_add = buf_lo_add,
.lo_incore_commit = buf_lo_incore_commit,
.lo_before_commit = buf_lo_before_commit,
.lo_name = "buf"
};
-struct gfs2_log_operations gfs2_revoke_lops = {
+const struct gfs2_log_operations gfs2_revoke_lops = {
.lo_add = revoke_lo_add,
.lo_before_commit = revoke_lo_before_commit,
.lo_before_scan = revoke_lo_before_scan,
.lo_name = "revoke"
};
-struct gfs2_log_operations gfs2_rg_lops = {
+const struct gfs2_log_operations gfs2_rg_lops = {
.lo_add = rg_lo_add,
.lo_after_commit = rg_lo_after_commit,
.lo_name = "rg"
};
-struct gfs2_log_operations gfs2_databuf_lops = {
+const struct gfs2_log_operations gfs2_databuf_lops = {
.lo_add = databuf_lo_add,
.lo_incore_commit = buf_lo_incore_commit,
.lo_before_commit = databuf_lo_before_commit,
.lo_name = "databuf"
};
-struct gfs2_log_operations *gfs2_log_ops[] = {
+const struct gfs2_log_operations *gfs2_log_ops[] = {
&gfs2_glock_lops,
&gfs2_buf_lops,
&gfs2_revoke_lops,