2006-01-17 00:50:04 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
|
[GFS2] kernel changes to support new gfs2_grow command
This is another revision of my gfs2 kernel patch that allows
gfs2_grow to function properly.
Steve Whitehouse expressed some concerns about the previous
patch and I restructured it based on his comments.
The previous patch was doing the statfs_change at file close time,
under its own transaction. The current patch does the statfs_change
inside the gfs2_commit_write function, which keeps it under the
umbrella of the inode transaction.
I can't call ri_update to re-read the rindex file during the
transaction because the transaction may have outstanding unwritten
buffers attached to the rgrps that would be otherwise blown away.
So instead, I created a new function, gfs2_ri_total, that will
re-read the rindex file just to total the file system space
for the sake of the statfs_change. The ri_update will happen
later, when gfs2 realizes the version number has changed, as it
happened before my patch.
Since the statfs_change is happening at write_commit time and there
may be multiple writes to the rindex file for one grow operation.
So one consequence of this restructuring is that instead of getting
one kernel message to indicate the change, you may see several.
For example, before when you did a gfs2_grow, you'd get a single
message like:
GFS2: File system extended by 247876 blocks (968MB)
Now you get something like:
GFS2: File system extended by 207896 blocks (812MB)
GFS2: File system extended by 39980 blocks (156MB)
This version has also been successfully run against the hours-long
"gfs2_fsck_hellfire" test that does several gfs2_grow and gfs2_fsck
while interjecting file system damage. It does this repeatedly
under a variety Resource Group conditions.
Signed-off-By: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
2007-05-09 22:37:57 +08:00
|
|
|
|
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
|
2006-01-17 00:50:04 +08:00
|
|
|
|
*
|
|
|
|
|
* This copyrighted material is made available to anyone wishing to use,
|
|
|
|
|
* modify, copy, or redistribute it subject to the terms and conditions
|
2006-09-01 23:05:15 +08:00
|
|
|
|
* of the GNU General Public License version 2.
|
2006-01-17 00:50:04 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
|
#include <linux/completion.h>
|
|
|
|
|
#include <linux/buffer_head.h>
|
2006-01-31 02:34:10 +08:00
|
|
|
|
#include <linux/fs.h>
|
2006-02-28 06:23:27 +08:00
|
|
|
|
#include <linux/gfs2_ondisk.h>
|
2006-09-19 13:56:29 +08:00
|
|
|
|
#include <linux/lm_interface.h>
|
2006-01-17 00:50:04 +08:00
|
|
|
|
|
|
|
|
|
#include "gfs2.h"
|
2006-02-28 06:23:27 +08:00
|
|
|
|
#include "incore.h"
|
2006-01-17 00:50:04 +08:00
|
|
|
|
#include "glock.h"
|
|
|
|
|
#include "glops.h"
|
|
|
|
|
#include "lops.h"
|
|
|
|
|
#include "meta_io.h"
|
|
|
|
|
#include "quota.h"
|
|
|
|
|
#include "rgrp.h"
|
|
|
|
|
#include "super.h"
|
|
|
|
|
#include "trans.h"
|
2006-01-31 02:34:10 +08:00
|
|
|
|
#include "ops_file.h"
|
2006-02-28 06:23:27 +08:00
|
|
|
|
#include "util.h"
|
[GFS2] flush the log if a transaction can't allocate space
This is a fix for bz #208514. When GFS2 frees up space, the freed blocks
aren't available for reuse until the resource group is successfully written
to the ondisk journal. So in rare cases, GFS2 operations will fail, saying
that the filesystem is out of space, when in reality, you are just waiting for
a log flush. For instance, on a 1Gig filesystem, if I continually write 10 Mb
to a file, and then truncate it, after a hundred interations, the write will
fail with -ENOSPC, even though the filesystem is just 1% full.
The attached patch calls a log flush in these cases. I tested this patch
fairly heavily to check if there were any locking issues that I missed, and
it seems to work just fine. Also, this patch only does the log flush if
get_local_rgrp makes a complete loop of resource groups without skipping
any do to locking issues. The code would be slightly simpler if it just always
did the log flush after the first failed pass, and you could only ever have
to go through the loop twice, instead of up to three times. However, I guessed
that failing to find a rg simply do to locking issues would be common enough
to skip the log flush in that case, but I'm not certain that this is the right
way to go. Either way, I don't suppose this code will be hit all that often.
Signed-off-by: Benjamin E. Marzinski <bmarzins@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
2007-03-24 04:51:56 +08:00
|
|
|
|
#include "log.h"
|
2007-06-08 17:05:33 +08:00
|
|
|
|
#include "inode.h"
|
2006-01-17 00:50:04 +08:00
|
|
|
|
|
2006-09-06 03:41:57 +08:00
|
|
|
|
#define BFITNOENT ((u32)~0)
|
2006-05-19 01:52:39 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* These routines are used by the resource group routines (rgrp.c)
|
|
|
|
|
* to keep track of block allocation. Each block is represented by two
|
2006-06-15 03:32:57 +08:00
|
|
|
|
* bits. So, each byte represents GFS2_NBBY (i.e. 4) blocks.
|
|
|
|
|
*
|
|
|
|
|
* 0 = Free
|
|
|
|
|
* 1 = Used (not metadata)
|
|
|
|
|
* 2 = Unlinked (still in use) inode
|
|
|
|
|
* 3 = Used (metadata)
|
2006-05-19 01:52:39 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static const char valid_change[16] = {
|
|
|
|
|
/* current */
|
2006-06-15 03:32:57 +08:00
|
|
|
|
/* n */ 0, 1, 1, 1,
|
2006-05-19 01:52:39 +08:00
|
|
|
|
/* e */ 1, 0, 0, 0,
|
2006-06-15 03:32:57 +08:00
|
|
|
|
/* w */ 0, 0, 0, 1,
|
2006-05-19 01:52:39 +08:00
|
|
|
|
1, 0, 0, 0
|
|
|
|
|
};
|
|
|
|
|
|
2007-06-08 17:05:33 +08:00
|
|
|
|
static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
|
|
|
|
|
unsigned char old_state, unsigned char new_state);
|
|
|
|
|
|
2006-05-19 01:52:39 +08:00
|
|
|
|
/**
|
|
|
|
|
* gfs2_setbit - Set a bit in the bitmaps
|
|
|
|
|
* @buffer: the buffer that holds the bitmaps
|
|
|
|
|
* @buflen: the length (in bytes) of the buffer
|
|
|
|
|
* @block: the block to set
|
|
|
|
|
* @new_state: the new state of the block
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2006-05-19 02:02:52 +08:00
|
|
|
|
static void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buffer,
|
2006-09-05 00:49:07 +08:00
|
|
|
|
unsigned int buflen, u32 block,
|
2006-05-19 02:02:52 +08:00
|
|
|
|
unsigned char new_state)
|
2006-05-19 01:52:39 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned char *byte, *end, cur_state;
|
|
|
|
|
unsigned int bit;
|
|
|
|
|
|
|
|
|
|
byte = buffer + (block / GFS2_NBBY);
|
|
|
|
|
bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE;
|
|
|
|
|
end = buffer + buflen;
|
|
|
|
|
|
|
|
|
|
gfs2_assert(rgd->rd_sbd, byte < end);
|
|
|
|
|
|
|
|
|
|
cur_state = (*byte >> bit) & GFS2_BIT_MASK;
|
|
|
|
|
|
|
|
|
|
if (valid_change[new_state * 4 + cur_state]) {
|
|
|
|
|
*byte ^= cur_state << bit;
|
|
|
|
|
*byte |= new_state << bit;
|
|
|
|
|
} else
|
|
|
|
|
gfs2_consist_rgrpd(rgd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gfs2_testbit - test a bit in the bitmaps
|
|
|
|
|
* @buffer: the buffer that holds the bitmaps
|
|
|
|
|
* @buflen: the length (in bytes) of the buffer
|
|
|
|
|
* @block: the block to read
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2006-05-19 02:02:52 +08:00
|
|
|
|
static unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer,
|
2006-09-05 00:49:07 +08:00
|
|
|
|
unsigned int buflen, u32 block)
|
2006-05-19 01:52:39 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned char *byte, *end, cur_state;
|
|
|
|
|
unsigned int bit;
|
|
|
|
|
|
|
|
|
|
byte = buffer + (block / GFS2_NBBY);
|
|
|
|
|
bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE;
|
|
|
|
|
end = buffer + buflen;
|
|
|
|
|
|
|
|
|
|
gfs2_assert(rgd->rd_sbd, byte < end);
|
|
|
|
|
|
|
|
|
|
cur_state = (*byte >> bit) & GFS2_BIT_MASK;
|
|
|
|
|
|
|
|
|
|
return cur_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing
|
|
|
|
|
* a block in a given allocation state.
|
|
|
|
|
* @buffer: the buffer that holds the bitmaps
|
|
|
|
|
* @buflen: the length (in bytes) of the buffer
|
|
|
|
|
* @goal: start search at this block's bit-pair (within @buffer)
|
|
|
|
|
* @old_state: GFS2_BLKST_XXX the state of the block we're looking for;
|
|
|
|
|
* bit 0 = alloc(1)/free(0), bit 1 = meta(1)/data(0)
|
|
|
|
|
*
|
|
|
|
|
* Scope of @goal and returned block number is only within this bitmap buffer,
|
|
|
|
|
* not entire rgrp or filesystem. @buffer will be offset from the actual
|
|
|
|
|
* beginning of a bitmap block buffer, skipping any header structures.
|
|
|
|
|
*
|
|
|
|
|
* Return: the block number (bitmap buffer scope) that was found
|
|
|
|
|
*/
|
|
|
|
|
|
2006-09-05 00:49:07 +08:00
|
|
|
|
static u32 gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer,
|
|
|
|
|
unsigned int buflen, u32 goal,
|
2006-05-19 02:02:52 +08:00
|
|
|
|
unsigned char old_state)
|
2006-05-19 01:52:39 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned char *byte, *end, alloc;
|
2006-09-05 00:49:07 +08:00
|
|
|
|
u32 blk = goal;
|
2006-05-19 01:52:39 +08:00
|
|
|
|
unsigned int bit;
|
|
|
|
|
|
|
|
|
|
byte = buffer + (goal / GFS2_NBBY);
|
|
|
|
|
bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE;
|
|
|
|
|
end = buffer + buflen;
|
|
|
|
|
alloc = (old_state & 1) ? 0 : 0x55;
|
|
|
|
|
|
|
|
|
|
while (byte < end) {
|
|
|
|
|
if ((*byte & 0x55) == alloc) {
|
|
|
|
|
blk += (8 - bit) >> 1;
|
|
|
|
|
|
|
|
|
|
bit = 0;
|
|
|
|
|
byte++;
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (((*byte >> bit) & GFS2_BIT_MASK) == old_state)
|
|
|
|
|
return blk;
|
|
|
|
|
|
|
|
|
|
bit += GFS2_BIT_SIZE;
|
|
|
|
|
if (bit >= 8) {
|
|
|
|
|
bit = 0;
|
|
|
|
|
byte++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blk++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BFITNOENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gfs2_bitcount - count the number of bits in a certain state
|
|
|
|
|
* @buffer: the buffer that holds the bitmaps
|
|
|
|
|
* @buflen: the length (in bytes) of the buffer
|
|
|
|
|
* @state: the state of the block we're looking for
|
|
|
|
|
*
|
|
|
|
|
* Returns: The number of bits
|
|
|
|
|
*/
|
|
|
|
|
|
2006-09-05 00:49:07 +08:00
|
|
|
|
static u32 gfs2_bitcount(struct gfs2_rgrpd *rgd, unsigned char *buffer,
|
2006-05-19 02:02:52 +08:00
|
|
|
|
unsigned int buflen, unsigned char state)
|
2006-05-19 01:52:39 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned char *byte = buffer;
|
|
|
|
|
unsigned char *end = buffer + buflen;
|
|
|
|
|
unsigned char state1 = state << 2;
|
|
|
|
|
unsigned char state2 = state << 4;
|
|
|
|
|
unsigned char state3 = state << 6;
|
2006-09-05 00:49:07 +08:00
|
|
|
|
u32 count = 0;
|
2006-05-19 01:52:39 +08:00
|
|
|
|
|
|
|
|
|
for (; byte < end; byte++) {
|
|
|
|
|
if (((*byte) & 0x03) == state)
|
|
|
|
|
count++;
|
|
|
|
|
if (((*byte) & 0x0C) == state1)
|
|
|
|
|
count++;
|
|
|
|
|
if (((*byte) & 0x30) == state2)
|
|
|
|
|
count++;
|
|
|
|
|
if (((*byte) & 0xC0) == state3)
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-17 00:50:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* gfs2_rgrp_verify - Verify that a resource group is consistent
|
|
|
|
|
* @sdp: the filesystem
|
|
|
|
|
* @rgd: the rgrp
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd)
|
|
|
|
|
{
|
|
|
|
|
struct gfs2_sbd *sdp = rgd->rd_sbd;
|
|
|
|
|
struct gfs2_bitmap *bi = NULL;
|
2007-06-01 21:11:58 +08:00
|
|
|
|
u32 length = rgd->rd_length;
|
2006-09-05 00:49:07 +08:00
|
|
|
|
u32 count[4], tmp;
|
2006-01-17 00:50:04 +08:00
|
|
|
|
int buf, x;
|
|
|
|
|
|
2006-09-05 00:49:07 +08:00
|
|
|
|
memset(count, 0, 4 * sizeof(u32));
|
2006-01-17 00:50:04 +08:00
|
|
|
|
|
|
|
|
|
/* Count # blocks in each of 4 possible allocation states */
|
|
|
|
|
for (buf = 0; buf < length; buf++) {
|
|
|
|
|
bi = rgd->rd_bits + buf;
|
|
|
|
|
for (x = 0; x < 4; x++)
|
|
|
|
|
count[x] += gfs2_bitcount(rgd,
|
|
|
|
|
bi->bi_bh->b_data +
|
|
|
|
|
bi->bi_offset,
|
|
|
|
|
bi->bi_len, x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count[0] != rgd->rd_rg.rg_free) {
|
|
|
|
|
if (gfs2_consist_rgrpd(rgd))
|
|
|
|
|
fs_err(sdp, "free data mismatch: %u != %u\n",
|
|
|
|
|
count[0], rgd->rd_rg.rg_free);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-01 21:11:58 +08:00
|
|
|
|
tmp = rgd->rd_data -
|
2006-01-17 00:50:04 +08:00
|
|
|
|
rgd->rd_rg.rg_free -
|
|
|
|
|
rgd->rd_rg.rg_dinodes;
|
2006-06-15 03:32:57 +08:00
|
|
|
|
if (count[1] + count[2] != tmp) {
|
2006-01-17 00:50:04 +08:00
|
|
|
|
if (gfs2_consist_rgrpd(rgd))
|
|
|
|
|
fs_err(sdp, "used data mismatch: %u != %u\n",
|
|
|
|
|
count[1], tmp);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-15 03:32:57 +08:00
|
|
|
|
if (count[3] != rgd->rd_rg.rg_dinodes) {
|
2006-01-17 00:50:04 +08:00
|
|
|
|
if (gfs2_consist_rgrpd(rgd))
|
2006-06-15 03:32:57 +08:00
|
|
|
|
fs_err(sdp, "used metadata mismatch: %u != %u\n",
|
|
|
|
|
count[3], rgd->rd_rg.rg_dinodes);
|
2006-01-17 00:50:04 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-15 03:32:57 +08:00
|
|
|
|
if (count[2] > count[3]) {
|
2006-01-17 00:50:04 +08:00
|
|
|
|
if (gfs2_consist_rgrpd(rgd))
|
2006-06-15 03:32:57 +08:00
|
|
|
|
fs_err(sdp, "unlinked inodes > inodes: %u\n",
|
|
|
|
|
count[2]);
|
2006-01-17 00:50:04 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2006-06-15 03:32:57 +08:00
|
|
|
|
|
2006-01-17 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-01 21:11:58 +08:00
|
|
|
|
static inline int rgrp_contains_block(struct gfs2_rgrpd *rgd, u64 block)
|
2006-01-17 00:50:04 +08:00
|
|
|
|
{
|
2007-06-01 21:11:58 +08:00
|
|
|
|
u64 first = rgd->rd_data0;
|
|
|
|
|
u64 last = first + rgd->rd_data;
|
2006-09-05 23:15:45 +08:00
|
|
|
|
return first <= block && block < last;
|
2006-01-17 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gfs2_blk2rgrpd - Find resource group for a given data/meta block number
|
|
|
|
|
* @sdp: The GFS2 superblock
|
|
|
|
|
* @n: The data block number
|
|
|
|
|
*
|
|
|
|
|
* Returns: The resource group, or NULL if not found
|
|
|
|
|
*/
|
|
|
|
|
|
2006-09-05 00:49:07 +08:00
|
|
|
|
struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk)
|
2006-01-17 00:50:04 +08:00
|
|
|
|
{
|
|
|
|
|
struct gfs2_rgrpd *rgd;
|
|
|
|
|
|
|
|
|
|
spin_lock(&sdp->sd_rindex_spin);
|
|
|
|
|
|
|
|
|
|
list_for_each_entry(rgd, &sdp->sd_rindex_mru_list, rd_list_mru) {
|
2007-06-01 21:11:58 +08:00
|
|
|
|
if (rgrp_contains_block(rgd, blk)) {
|
2006-01-17 00:50:04 +08:00
|
|
|
|
list_move(&rgd->rd_list_mru, &sdp->sd_rindex_mru_list);
|
|
|
|
|
spin_unlock(&sdp->sd_rindex_spin);
|
|
|
|
|
return rgd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spin_unlock(&sdp->sd_rindex_spin);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gfs2_rgrpd_get_first - get the first Resource Group in the filesystem
|
|
|
|
|
* @sdp: The GFS2 superblock
|
|
|
|
|
*
|
|
|
|
|
* Returns: The first rgrp in the filesystem
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp)
|
|
|
|
|
{
|
|
|
|
|
gfs2_assert(sdp, !list_empty(&sdp->sd_rindex_list));
|
|
|
|
|
return list_entry(sdp->sd_rindex_list.next, struct gfs2_rgrpd, rd_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gfs2_rgrpd_get_next - get the next RG
|
|
|
|
|
* @rgd: A RG
|
|
|
|
|
*
|
|
|
|
|
* Returns: The next rgrp
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd)
|
|
|
|
|
{
|
|
|
|
|
if (rgd->rd_list.next == &rgd->rd_sbd->sd_rindex_list)
|
|
|
|
|
return NULL;
|
|
|
|
|
return list_entry(rgd->rd_list.next, struct gfs2_rgrpd, rd_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void clear_rgrpdi(struct gfs2_sbd *sdp)
|
|
|
|
|
{
|
|
|
|
|
struct list_head *head;
|
|
|
|
|
struct gfs2_rgrpd *rgd;
|
|
|
|
|
struct gfs2_glock *gl;
|
|
|
|
|
|
|
|
|
|
spin_lock(&sdp->sd_rindex_spin);
|
|
|
|
|
sdp->sd_rindex_forward = NULL;
|
|
|
|
|
head = &sdp->sd_rindex_recent_list;
|
|
|
|
|
while (!list_empty(head)) {
|
|
|
|
|
rgd = list_entry(head->next, struct gfs2_rgrpd, rd_recent);
|
|
|
|
|
list_del(&rgd->rd_recent);
|
|
|
|
|
}
|
|
|
|
|
spin_unlock(&sdp->sd_rindex_spin);
|
|
|
|
|
|
|
|
|
|
head = &sdp->sd_rindex_list;
|
|
|
|
|
while (!list_empty(head)) {
|
|
|
|
|
rgd = list_entry(head->next, struct gfs2_rgrpd, rd_list);
|
|
|
|
|
gl = rgd->rd_gl;
|
|
|
|
|
|
|
|
|
|
list_del(&rgd->rd_list);
|
|
|
|
|
list_del(&rgd->rd_list_mru);
|
|
|
|
|
|
|
|
|
|
if (gl) {
|
2006-02-28 06:23:27 +08:00
|
|
|
|
gl->gl_object = NULL;
|
2006-01-17 00:50:04 +08:00
|
|
|
|
gfs2_glock_put(gl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
kfree(rgd->rd_bits);
|
|
|
|
|
kfree(rgd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gfs2_clear_rgrpd(struct gfs2_sbd *sdp)
|
|
|
|
|
{
|
2006-02-21 20:51:39 +08:00
|
|
|
|
mutex_lock(&sdp->sd_rindex_mutex);
|
2006-01-17 00:50:04 +08:00
|
|
|
|
clear_rgrpdi(sdp);
|
2006-02-21 20:51:39 +08:00
|
|
|
|
mutex_unlock(&sdp->sd_rindex_mutex);
|
2006-01-17 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-01 21:11:58 +08:00
|
|
|
|
static void gfs2_rindex_print(const struct gfs2_rgrpd *rgd)
|
|
|
|
|
{
|
|
|
|
|
printk(KERN_INFO " ri_addr = %llu\n", (unsigned long long)rgd->rd_addr);
|
|
|
|
|
printk(KERN_INFO " ri_length = %u\n", rgd->rd_length);
|
|
|
|
|
printk(KERN_INFO " ri_data0 = %llu\n", (unsigned long long)rgd->rd_data0);
|
|
|
|
|
printk(KERN_INFO " ri_data = %u\n", rgd->rd_data);
|
|
|
|
|
printk(KERN_INFO " ri_bitbytes = %u\n", rgd->rd_bitbytes);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-17 00:50:04 +08:00
|
|
|
|
/**
|
|
|
|
|
* gfs2_compute_bitstructs - Compute the bitmap sizes
|
|
|
|
|
* @rgd: The resource group descriptor
|
|
|
|
|
*
|
|
|
|
|
* Calculates bitmap descriptors, one for each block that contains bitmap data
|
|
|
|
|
*
|
|
|
|
|
* Returns: errno
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static int compute_bitstructs(struct gfs2_rgrpd *rgd)
|
|
|
|
|
{
|
|
|
|
|
struct gfs2_sbd *sdp = rgd->rd_sbd;
|
|
|
|
|
struct gfs2_bitmap *bi;
|
2007-06-01 21:11:58 +08:00
|
|
|
|
u32 length = rgd->rd_length; /* # blocks in hdr & bitmap */
|
2006-09-05 00:49:07 +08:00
|
|
|
|
u32 bytes_left, bytes;
|
2006-01-17 00:50:04 +08:00
|
|
|
|
int x;
|
|
|
|
|
|
2006-06-15 03:32:57 +08:00
|
|
|
|
if (!length)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2006-07-28 02:29:00 +08:00
|
|
|
|
rgd->rd_bits = kcalloc(length, sizeof(struct gfs2_bitmap), GFP_NOFS);
|
2006-01-17 00:50:04 +08:00
|
|
|
|
if (!rgd->rd_bits)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
2007-06-01 21:11:58 +08:00
|
|
|
|
bytes_left = rgd->rd_bitbytes;
|
2006-01-17 00:50:04 +08:00
|
|
|
|
|
|
|
|
|
for (x = 0; x < length; x++) {
|
|
|
|
|
bi = rgd->rd_bits + x;
|
|
|
|
|
|
|
|
|
|
/* small rgrp; bitmap stored completely in header block */
|
|
|
|
|
if (length == 1) {
|
|
|
|
|
bytes = bytes_left;
|
|
|
|
|
bi->bi_offset = sizeof(struct gfs2_rgrp);
|
|
|
|
|
bi->bi_start = 0;
|
|
|
|
|
bi->bi_len = bytes;
|
|
|
|
|
/* header block */
|
|
|
|
|
} else if (x == 0) {
|
|
|
|
|
bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_rgrp);
|
|
|
|
|
bi->bi_offset = sizeof(struct gfs2_rgrp);
|
|
|
|
|
bi->bi_start = 0;
|
|
|
|
|
bi->bi_len = bytes;
|
|
|
|
|
/* last block */
|
|
|
|
|
} else if (x + 1 == length) {
|
|
|
|
|
bytes = bytes_left;
|
|
|
|
|
bi->bi_offset = sizeof(struct gfs2_meta_header);
|
2007-06-01 21:11:58 +08:00
|
|
|
|
bi->bi_start = rgd->rd_bitbytes - bytes_left;
|
2006-01-17 00:50:04 +08:00
|
|
|
|
bi->bi_len = bytes;
|
|
|
|
|
/* other blocks */
|
|
|
|
|
} else {
|
2006-02-28 01:00:42 +08:00
|
|
|
|
bytes = sdp->sd_sb.sb_bsize -
|
|
|
|
|
sizeof(struct gfs2_meta_header);
|
2006-01-17 00:50:04 +08:00
|
|
|
|
bi->bi_offset = sizeof(struct gfs2_meta_header);
|
2007-06-01 21:11:58 +08:00
|
|
|
|
bi->bi_start = rgd->rd_bitbytes - bytes_left;
|
2006-01-17 00:50:04 +08:00
|
|
|
|
bi->bi_len = bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bytes_left -= bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bytes_left) {
|
|
|
|
|
gfs2_consist_rgrpd(rgd);
|
|
|
|
|
return -EIO;
|
|
|
|
|
}
|
|
|
|
|
bi = rgd->rd_bits + (length - 1);
|
2007-06-01 21:11:58 +08:00
|
|
|
|
if ((bi->bi_start + bi->bi_len) * GFS2_NBBY != rgd->rd_data) {
|
2006-01-17 00:50:04 +08:00
|
|
|
|
if (gfs2_consist_rgrpd(rgd)) {
|
2007-06-01 21:11:58 +08:00
|
|
|
|
gfs2_rindex_print(rgd);
|
2006-01-17 00:50:04 +08:00
|
|
|
|
fs_err(sdp, "start=%u len=%u offset=%u\n",
|
|
|
|
|
bi->bi_start, bi->bi_len, bi->bi_offset);
|
|
|
|
|
}
|
|
|
|
|
return -EIO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
[GFS2] kernel changes to support new gfs2_grow command
This is another revision of my gfs2 kernel patch that allows
gfs2_grow to function properly.
Steve Whitehouse expressed some concerns about the previous
patch and I restructured it based on his comments.
The previous patch was doing the statfs_change at file close time,
under its own transaction. The current patch does the statfs_change
inside the gfs2_commit_write function, which keeps it under the
umbrella of the inode transaction.
I can't call ri_update to re-read the rindex file during the
transaction because the transaction may have outstanding unwritten
buffers attached to the rgrps that would be otherwise blown away.
So instead, I created a new function, gfs2_ri_total, that will
re-read the rindex file just to total the file system space
for the sake of the statfs_change. The ri_update will happen
later, when gfs2 realizes the version number has changed, as it
happened before my patch.
Since the statfs_change is happening at write_commit time and there
may be multiple writes to the rindex file for one grow operation.
So one consequence of this restructuring is that instead of getting
one kernel message to indicate the change, you may see several.
For example, before when you did a gfs2_grow, you'd get a single
message like:
GFS2: File system extended by 247876 blocks (968MB)
Now you get something like:
GFS2: File system extended by 207896 blocks (812MB)
GFS2: File system extended by 39980 blocks (156MB)
This version has also been successfully run against the hours-long
"gfs2_fsck_hellfire" test that does several gfs2_grow and gfs2_fsck
while interjecting file system damage. It does this repeatedly
under a variety Resource Group conditions.
Signed-off-By: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
2007-05-09 22:37:57 +08:00
|
|
|
|
/**
|
2007-06-01 21:11:58 +08:00
|
|
|
|
|