* [PATCH 2/3] reiserfs: ignore s_bmap_nr on disk for file systems >= 8 TiB
@ 2007-08-07 15:28 Jeff Mahoney
0 siblings, 0 replies; 5+ messages in thread
From: Jeff Mahoney @ 2007-08-07 15:28 UTC (permalink / raw)
To: ReiserFS Mailing List; +Cc: Vladimir V. Saveliev
The reiserfs disk format is designed to handle file systems up to
2^32-1 blocks, which at 4KiB blocks means ~ 16 TiB - 4KiB.
Unfortunately, the superblock's s_bmap_nr value, which contains a
count of the number of bitmap blocks in the file system is a 16 bit
value. This limits the usable size of the file system to
8 TiB (4096^2 * 8 * 65536).
Changing the disk format this late in the game, especially with a file
system without sane superblock versioning, is a tough sell. This patch
implements the following changes:
* The s_bmap_nr value is no longer accessed directly. Instead, an
in-core 32-bit value is used instead. The real value is only
accessed directly during mount and resize.
* If the value of s_bmap_nr is valid, then the value is used as-is.
* If the value of s_bmap_nr has overflowed, the on-disk value is
zeroed out and the number of bitmaps is calculate on mount and
resize.
The reason for zeroing it out is simple. If it has overflowed, it's
invalid anyway. Kernels mounting these file systems may end up
with unpredictible results, the most obvious of which occurs in
kernels with dynamic bitmaps: it will BUG almost immediately.
Alternatively, if the value is zeroed, the memory allocation for
tracking the bitmap blocks will end up being vmalloc(0), causing
mount to fail when a NULL pointer is returned. Since the
ZERO_SIZE_PTR changes haven't been merged in these older kernels,
the failure won't result in an Oops, just a failed mount.
A matching change for reiserfsprogs will also be submitted to support
the s_bmap_nr == 0 value as valid.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/reiserfs/bitmap.c | 44 +++++++++++++++++++++++++----------------
fs/reiserfs/journal.c | 6 ++---
fs/reiserfs/resize.c | 9 ++++++--
include/linux/reiserfs_fs.h | 3 ++
include/linux/reiserfs_fs_sb.h | 1
5 files changed, 41 insertions(+), 22 deletions(-)
--- a/fs/reiserfs/bitmap.c 2007-08-07 11:07:22.000000000 -0400
+++ b/fs/reiserfs/bitmap.c 2007-08-07 11:07:29.000000000 -0400
@@ -77,25 +77,26 @@ int is_reusable(struct super_block *s, b
if (unlikely(test_bit(REISERFS_OLD_FORMAT,
&(REISERFS_SB(s)->s_properties)))) {
b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1;
- if (block >= bmap1 && block <= bmap1 + SB_BMAP_NR(s)) {
+ if (block >= bmap1 &&
+ block <= bmap1 + REISERFS_SB(s)->s_bmap_nr) {
reiserfs_warning(s, "vs: 4019: is_reusable: "
"bitmap block %lu(%u) can't be freed or reused",
- block, SB_BMAP_NR(s));
+ block, REISERFS_SB(s)->s_bmap_nr);
return 0;
}
} else {
if (offset == 0) {
reiserfs_warning(s, "vs: 4020: is_reusable: "
"bitmap block %lu(%u) can't be freed or reused",
- block, SB_BMAP_NR(s));
+ block, REISERFS_SB(s)->s_bmap_nr);
return 0;
}
}
- if (bmap >= SB_BMAP_NR(s)) {
+ if (bmap >= REISERFS_SB(s)->s_bmap_nr) {
reiserfs_warning(s,
"vs-4030: is_reusable: there is no so many bitmap blocks: "
- "block=%lu, bitmap_nr=%d", block, bmap);
+ "block=%lu, bitmap_nr=%u", block, bmap);
return 0;
}
@@ -145,8 +146,8 @@ static int scan_bitmap_block(struct reis
BUG_ON(!th->t_trans_id);
- RFALSE(bmap_n >= SB_BMAP_NR(s), "Bitmap %d is out of range (0..%d)",
- bmap_n, SB_BMAP_NR(s) - 1);
+ RFALSE(bmap_n >= REISERFS_SB(s)->s_bmap_nr, "Bitmap %u is out of range (0..%u)",
+ bmap_n, REISERFS_SB(s)->s_bmap_nr - 1);
PROC_INFO_INC(s, scan_bitmap.bmap);
/* this is unclear and lacks comments, explain how journal bitmaps
work here for the reader. Convey a sense of the design here. What
@@ -251,12 +252,12 @@ static int bmap_hash_id(struct super_blo
} else {
hash_in = (char *)(&id);
hash = keyed_hash(hash_in, 4);
- bm = hash % SB_BMAP_NR(s);
+ bm = hash % REISERFS_SB(s)->s_bmap_nr;
if (!bm)
bm = 1;
}
/* this can only be true when SB_BMAP_NR = 1 */
- if (bm >= SB_BMAP_NR(s))
+ if (bm >= REISERFS_SB(s)->s_bmap_nr)
bm = 0;
return bm;
}
@@ -330,10 +331,10 @@ static int scan_bitmap(struct reiserfs_t
get_bit_address(s, *start, &bm, &off);
get_bit_address(s, finish, &end_bm, &end_off);
- if (bm > SB_BMAP_NR(s))
+ if (bm > REISERFS_SB(s)->s_bmap_nr)
return 0;
- if (end_bm > SB_BMAP_NR(s))
- end_bm = SB_BMAP_NR(s);
+ if (end_bm > REISERFS_SB(s)->s_bmap_nr)
+ end_bm = REISERFS_SB(s)->s_bmap_nr;
/* When the bitmap is more than 10% free, anyone can allocate.
* When it's less than 10% free, only files that already use the
@@ -399,10 +400,12 @@ static void _reiserfs_free_block(struct
get_bit_address(s, block, &nr, &offset);
- if (nr >= sb_bmap_nr(rs)) {
+ if (nr >= REISERFS_SB(s)->s_bmap_nr) {
reiserfs_warning(s, "vs-4075: reiserfs_free_block: "
- "block %lu is out of range on %s",
- block, reiserfs_bdevname(s));
+ "block %lu is out of range on %s "
+ "(nr=%u,max=%u)", block,
+ reiserfs_bdevname(s), nr,
+ REISERFS_SB(s)->s_bmap_nr);
return;
}
@@ -1326,14 +1329,21 @@ struct buffer_head *reiserfs_read_bitmap
int reiserfs_init_bitmap_cache(struct super_block *sb)
{
struct reiserfs_bitmap_info *bitmap;
+ unsigned int blocks = SB_BLOCK_COUNT(sb);
+ unsigned int bmap_nr = blocks >> (sb->s_blocksize_bits + 3);
- bitmap = vmalloc(sizeof (*bitmap) * SB_BMAP_NR(sb));
+ if (blocks & ~(sb->s_blocksize << 3))
+ ++bmap_nr;
+
+
+ bitmap = vmalloc(sizeof (*bitmap) * bmap_nr);
if (bitmap == NULL)
return -ENOMEM;
- memset(bitmap, 0, sizeof (*bitmap) * SB_BMAP_NR(sb));
+ memset(bitmap, 0, sizeof (*bitmap) * bmap_nr);
SB_AP_BITMAP(sb) = bitmap;
+ REISERFS_SB(sb)->s_bmap_nr = bmap_nr;
return 0;
}
--- a/fs/reiserfs/journal.c 2007-08-07 11:07:22.000000000 -0400
+++ b/fs/reiserfs/journal.c 2007-08-07 11:07:29.000000000 -0400
@@ -240,7 +240,7 @@ static void cleanup_bitmap_list(struct s
if (jb->bitmaps == NULL)
return;
- for (i = 0; i < SB_BMAP_NR(p_s_sb); i++) {
+ for (i = 0; i < REISERFS_SB(p_s_sb)->s_bmap_nr; i++) {
if (jb->bitmaps[i]) {
free_bitmap_node(p_s_sb, jb->bitmaps[i]);
jb->bitmaps[i] = NULL;
@@ -2651,7 +2651,7 @@ int journal_init(struct super_block *p_s
journal->j_persistent_trans = 0;
if (reiserfs_allocate_list_bitmaps(p_s_sb,
journal->j_list_bitmap,
- SB_BMAP_NR(p_s_sb)))
+ REISERFS_SB(p_s_sb)->s_bmap_nr))
goto free_and_return;
allocate_bitmap_nodes(p_s_sb);
@@ -2659,7 +2659,7 @@ int journal_init(struct super_block *p_s
SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ?
REISERFS_OLD_DISK_OFFSET_IN_BYTES
/ p_s_sb->s_blocksize +
- SB_BMAP_NR(p_s_sb) +
+ REISERFS_SB(p_s_sb)->s_bmap_nr +
1 :
REISERFS_DISK_OFFSET_IN_BYTES /
p_s_sb->s_blocksize + 2);
--- a/fs/reiserfs/resize.c 2007-08-07 11:07:25.000000000 -0400
+++ b/fs/reiserfs/resize.c 2007-08-07 11:07:29.000000000 -0400
@@ -61,7 +61,7 @@ int reiserfs_resize(struct super_block *
}
/* count used bits in last bitmap block */
- block_r = SB_BLOCK_COUNT(s) - (SB_BMAP_NR(s) - 1) * s->s_blocksize * 8;
+ block_r = SB_BLOCK_COUNT(s) - (REISERFS_SB(s)->s_bmap_nr - 1) * s->s_blocksize * 8;
/* count bitmap blocks in new fs */
bmap_nr_new = block_count_new / (s->s_blocksize * 8);
@@ -73,7 +73,7 @@ int reiserfs_resize(struct super_block *
/* save old values */
block_count = SB_BLOCK_COUNT(s);
- bmap_nr = SB_BMAP_NR(s);
+ bmap_nr = REISERFS_SB(s)->s_bmap_nr;
/* resizing of reiserfs bitmaps (journal and real), if needed */
if (bmap_nr_new > bmap_nr) {
@@ -206,6 +206,11 @@ int reiserfs_resize(struct super_block *
free_blocks + (block_count_new - block_count -
(bmap_nr_new - bmap_nr)));
PUT_SB_BLOCK_COUNT(s, block_count_new);
+
+ REISERFS_SB(s)->s_bmap_nr = bmap_nr_new;
+ if (bmap_would_wrap(bmap_nr_new))
+ bmap_nr_new = 0;
+
PUT_SB_BMAP_NR(s, bmap_nr_new);
s->s_dirt = 1;
--- a/include/linux/reiserfs_fs.h 2007-08-07 11:07:22.000000000 -0400
+++ b/include/linux/reiserfs_fs.h 2007-08-07 11:07:29.000000000 -0400
@@ -229,6 +229,9 @@ struct reiserfs_super_block {
((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \
SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s)))
+/* s_bmap_nr is a u16 */
+#define bmap_would_wrap(n) (n >= 65536)
+
int is_reiserfs_3_5(struct reiserfs_super_block *rs);
int is_reiserfs_3_6(struct reiserfs_super_block *rs);
int is_reiserfs_jr(struct reiserfs_super_block *rs);
--- a/include/linux/reiserfs_fs_sb.h 2007-08-07 11:07:14.000000000 -0400
+++ b/include/linux/reiserfs_fs_sb.h 2007-08-07 11:07:29.000000000 -0400
@@ -410,6 +410,7 @@ struct reiserfs_sb_info {
char *s_qf_names[MAXQUOTAS];
int s_jquota_fmt;
#endif
+ unsigned int s_bmap_nr;
};
/* Definitions of reiserfs on-disk properties: */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch 0/3] reiserfs: support for file systems > 8 TiB
@ 2007-08-09 1:19 Jeff Mahoney
2007-08-09 1:19 ` [patch 1/3] reiserfs: fix usage of signed ints for block numbers Jeff Mahoney
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jeff Mahoney @ 2007-08-09 1:19 UTC (permalink / raw)
To: ReiserFS Development Mailing List; +Cc: Vladimir Saveliev
Hi all -
When I was integrating my reiserfsprogs patches into 3.6.20, I realized
that it already understands larger bitmaps. Not only that, it zeroes them
out just as my patches did. Since that revision has been released for
nearly a year, I'd call that "standard."
This set of patches should be the final one. Rather than caching the
bitmap count in the superblock, we calculate it on the fly like
reiserfsprogs does.
I've integrated this patch set into the openSUSE 10.3 kernel, but I'm
confident they'll survive some heavier testing.
-Jeff
--
Jeff Mahoney
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch 1/3] reiserfs: fix usage of signed ints for block numbers
2007-08-09 1:19 [patch 0/3] reiserfs: support for file systems > 8 TiB Jeff Mahoney
@ 2007-08-09 1:19 ` Jeff Mahoney
2007-08-09 1:19 ` [patch 2/3] reiserfs: ignore s_bmap_nr on disk for file systems >= 8 TiB Jeff Mahoney
2007-08-09 1:19 ` [patch 3/3] reiserfs: fix memset byte count during resize Jeff Mahoney
2 siblings, 0 replies; 5+ messages in thread
From: Jeff Mahoney @ 2007-08-09 1:19 UTC (permalink / raw)
To: ReiserFS Development Mailing List; +Cc: Vladimir Saveliev
[-- Attachment #1: reiserfs-signedness-fixes.diff --]
[-- Type: text/plain, Size: 10869 bytes --]
This patch does a quick signedness check for block numbers. There are
a number of places where signed integers are used for block numbers,
which limits the usable file system size to 8 TiB. The disk format,
excepting a problem which will be fixed in the following patch,
supports file systems up to 16 TiB in size. This patch cleans up those
sites so that we can enable the full usable size.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/reiserfs/bitmap.c | 24 +++++++++++++-----------
fs/reiserfs/inode.c | 8 ++++----
fs/reiserfs/journal.c | 18 ++++++++++--------
fs/reiserfs/stree.c | 6 +++---
include/linux/reiserfs_fs.h | 14 ++++++++------
5 files changed, 38 insertions(+), 32 deletions(-)
--- a/fs/reiserfs/bitmap.c 2007-08-07 12:28:32.000000000 -0400
+++ b/fs/reiserfs/bitmap.c 2007-08-07 12:58:58.000000000 -0400
@@ -47,7 +47,9 @@
test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s))
static inline void get_bit_address(struct super_block *s,
- b_blocknr_t block, int *bmap_nr, int *offset)
+ b_blocknr_t block,
+ unsigned int *bmap_nr,
+ unsigned int *offset)
{
/* It is in the bitmap block number equal to the block
* number divided by the number of bits in a block. */
@@ -59,7 +61,7 @@ static inline void get_bit_address(struc
#ifdef CONFIG_REISERFS_CHECK
int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
{
- int bmap, offset;
+ unsigned int bmap, offset;
if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
reiserfs_warning(s,
@@ -110,8 +112,8 @@ int is_reusable(struct super_block *s, b
/* searches in journal structures for a given block number (bmap, off). If block
is found in reiserfs journal it suggests next free block candidate to test. */
-static inline int is_block_in_journal(struct super_block *s, int bmap, int
- off, int *next)
+static inline int is_block_in_journal(struct super_block *s, unsigned int bmap,
+ int off, int *next)
{
b_blocknr_t tmp;
@@ -132,8 +134,8 @@ static inline int is_block_in_journal(st
/* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap
* block; */
static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
- int bmap_n, int *beg, int boundary, int min,
- int max, int unfm)
+ unsigned int bmap_n, int *beg, int boundary,
+ int min, int max, int unfm)
{
struct super_block *s = th->t_super;
struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n];
@@ -309,16 +311,16 @@ __le32 reiserfs_choose_packing(struct in
* bitmap and place new blocks there. Returns number of allocated blocks. */
static int scan_bitmap(struct reiserfs_transaction_handle *th,
b_blocknr_t * start, b_blocknr_t finish,
- int min, int max, int unfm, unsigned long file_block)
+ int min, int max, int unfm, sector_t file_block)
{
int nr_allocated = 0;
struct super_block *s = th->t_super;
/* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr
* - Hans, it is not a block number - Zam. */
- int bm, off;
- int end_bm, end_off;
- int off_max = s->s_blocksize << 3;
+ unsigned int bm, off;
+ unsigned int end_bm, end_off;
+ unsigned int off_max = s->s_blocksize << 3;
BUG_ON(!th->t_trans_id);
@@ -385,7 +387,7 @@ static void _reiserfs_free_block(struct
struct reiserfs_super_block *rs;
struct buffer_head *sbh, *bmbh;
struct reiserfs_bitmap_info *apbi;
- int nr, offset;
+ unsigned int nr, offset;
BUG_ON(!th->t_trans_id);
--- a/fs/reiserfs/inode.c 2007-08-07 12:28:32.000000000 -0400
+++ b/fs/reiserfs/inode.c 2007-08-07 12:47:33.000000000 -0400
@@ -197,7 +197,7 @@ static inline void set_block_dev_mapped(
// files which were created in the earlier version can not be longer,
// than 2 gb
//
-static int file_capable(struct inode *inode, long block)
+static int file_capable(struct inode *inode, sector_t block)
{
if (get_inode_item_key_version(inode) != KEY_FORMAT_3_5 || // it is new file.
block < (1 << (31 - inode->i_sb->s_blocksize_bits))) // old file, but 'block' is inside of 2gb
@@ -240,7 +240,7 @@ static int file_capable(struct inode *in
// Please improve the english/clarity in the comment above, as it is
// hard to understand.
-static int _get_block_create_0(struct inode *inode, long block,
+static int _get_block_create_0(struct inode *inode, sector_t block,
struct buffer_head *bh_result, int args)
{
INITIALIZE_PATH(path);
@@ -248,7 +248,7 @@ static int _get_block_create_0(struct in
struct buffer_head *bh;
struct item_head *ih, tmp_ih;
int fs_gen;
- int blocknr;
+ b_blocknr_t blocknr;
char *p = NULL;
int chars;
int ret;
@@ -567,7 +567,7 @@ static int convert_tail_for_hole(struct
}
static inline int _allocate_block(struct reiserfs_transaction_handle *th,
- long block,
+ sector_t block,
struct inode *inode,
b_blocknr_t * allocated_block_nr,
struct treepath *path, int flags)
--- a/fs/reiserfs/journal.c 2007-08-07 12:28:32.000000000 -0400
+++ b/fs/reiserfs/journal.c 2007-08-07 12:57:40.000000000 -0400
@@ -219,11 +219,12 @@ static void allocate_bitmap_nodes(struct
}
}
-static int set_bit_in_list_bitmap(struct super_block *p_s_sb, int block,
+static int set_bit_in_list_bitmap(struct super_block *p_s_sb,
+ b_blocknr_t block,
struct reiserfs_list_bitmap *jb)
{
- int bmap_nr = block / (p_s_sb->s_blocksize << 3);
- int bit_nr = block % (p_s_sb->s_blocksize << 3);
+ unsigned int bmap_nr = block / (p_s_sb->s_blocksize << 3);
+ unsigned int bit_nr = block % (p_s_sb->s_blocksize << 3);
if (!jb->bitmaps[bmap_nr]) {
jb->bitmaps[bmap_nr] = get_bitmap_node(p_s_sb);
@@ -289,7 +290,7 @@ static int free_bitmap_nodes(struct supe
*/
int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb,
struct reiserfs_list_bitmap *jb_array,
- int bmap_nr)
+ unsigned int bmap_nr)
{
int i;
int failed = 0;
@@ -483,7 +484,7 @@ static inline struct reiserfs_journal_cn
**
*/
int reiserfs_in_journal(struct super_block *p_s_sb,
- int bmap_nr, int bit_nr, int search_all,
+ unsigned int bmap_nr, int bit_nr, int search_all,
b_blocknr_t * next_zero_bit)
{
struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
@@ -986,7 +987,7 @@ static int flush_commit_list(struct supe
struct reiserfs_journal_list *jl, int flushall)
{
int i;
- int bn;
+ b_blocknr_t bn;
struct buffer_head *tbh = NULL;
unsigned long trans_id = jl->j_trans_id;
struct reiserfs_journal *journal = SB_JOURNAL(s);
@@ -2279,8 +2280,9 @@ static int journal_read_transaction(stru
Right now it is only used from journal code. But later we might use it
from other places.
Note: Do not use journal_getblk/sb_getblk functions here! */
-static struct buffer_head *reiserfs_breada(struct block_device *dev, int block,
- int bufsize, unsigned int max_block)
+static struct buffer_head *reiserfs_breada(struct block_device *dev,
+ b_blocknr_t block, int bufsize,
+ b_blocknr_t max_block)
{
struct buffer_head *bhlist[BUFNR];
unsigned int blocks = BUFNR;
--- a/fs/reiserfs/stree.c 2007-08-07 12:28:32.000000000 -0400
+++ b/fs/reiserfs/stree.c 2007-08-07 13:02:57.000000000 -0400
@@ -559,7 +559,7 @@ static int is_tree_node(struct buffer_he
/* The function is NOT SCHEDULE-SAFE! */
static void search_by_key_reada(struct super_block *s,
struct buffer_head **bh,
- unsigned long *b, int num)
+ b_blocknr_t *b, int num)
{
int i, j;
@@ -611,7 +611,7 @@ int search_by_key(struct super_block *p_
DISK_LEAF_NODE_LEVEL */
)
{
- int n_block_number;
+ b_blocknr_t n_block_number;
int expected_level;
struct buffer_head *p_s_bh;
struct path_element *p_s_last_element;
@@ -619,7 +619,7 @@ int search_by_key(struct super_block *p_
int right_neighbor_of_leaf_node;
int fs_gen;
struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
- unsigned long reada_blocks[SEARCH_BY_KEY_READA];
+ b_blocknr_t reada_blocks[SEARCH_BY_KEY_READA];
int reada_count = 0;
#ifdef CONFIG_REISERFS_CHECK
--- a/include/linux/reiserfs_fs.h 2007-08-07 12:28:32.000000000 -0400
+++ b/include/linux/reiserfs_fs.h 2007-08-07 13:08:19.000000000 -0400
@@ -1734,8 +1734,8 @@ int journal_end_sync(struct reiserfs_tra
int journal_mark_freed(struct reiserfs_transaction_handle *,
struct super_block *, b_blocknr_t blocknr);
int journal_transaction_should_end(struct reiserfs_transaction_handle *, int);
-int reiserfs_in_journal(struct super_block *p_s_sb, int bmap_nr, int bit_nr,
- int searchall, b_blocknr_t * next);
+int reiserfs_in_journal(struct super_block *p_s_sb, unsigned int bmap_nr,
+ int bit_nr, int searchall, b_blocknr_t * next);
int journal_begin(struct reiserfs_transaction_handle *,
struct super_block *p_s_sb, unsigned long);
int journal_join_abort(struct reiserfs_transaction_handle *,
@@ -1743,7 +1743,7 @@ int journal_join_abort(struct reiserfs_t
void reiserfs_journal_abort(struct super_block *sb, int errno);
void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...);
int reiserfs_allocate_list_bitmaps(struct super_block *s,
- struct reiserfs_list_bitmap *, int);
+ struct reiserfs_list_bitmap *, unsigned int);
void add_save_link(struct reiserfs_transaction_handle *th,
struct inode *inode, int truncate);
@@ -2043,7 +2043,7 @@ struct buffer_head *get_FEB(struct tree_
* arguments, such as node, search path, transaction_handle, etc. */
struct __reiserfs_blocknr_hint {
struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */
- long block; /* file offset, in blocks */
+ sector_t block; /* file offset, in blocks */
struct in_core_key key;
struct treepath *path; /* search path, used by allocator to deternine search_start by
* various ways */
@@ -2101,7 +2101,8 @@ static inline int reiserfs_new_form_bloc
static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
*th, struct inode *inode,
b_blocknr_t * new_blocknrs,
- struct treepath *path, long block)
+ struct treepath *path,
+ sector_t block)
{
reiserfs_blocknr_hint_t hint = {
.th = th,
@@ -2118,7 +2119,8 @@ static inline int reiserfs_new_unf_block
static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle
*th, struct inode *inode,
b_blocknr_t * new_blocknrs,
- struct treepath *path, long block)
+ struct treepath *path,
+ sector_t block)
{
reiserfs_blocknr_hint_t hint = {
.th = th,
--
Jeff Mahoney
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch 2/3] reiserfs: ignore s_bmap_nr on disk for file systems >= 8 TiB
2007-08-09 1:19 [patch 0/3] reiserfs: support for file systems > 8 TiB Jeff Mahoney
2007-08-09 1:19 ` [patch 1/3] reiserfs: fix usage of signed ints for block numbers Jeff Mahoney
@ 2007-08-09 1:19 ` Jeff Mahoney
2007-08-09 1:19 ` [patch 3/3] reiserfs: fix memset byte count during resize Jeff Mahoney
2 siblings, 0 replies; 5+ messages in thread
From: Jeff Mahoney @ 2007-08-09 1:19 UTC (permalink / raw)
To: ReiserFS Development Mailing List; +Cc: Vladimir Saveliev
[-- Attachment #1: reiserfs-fix-large-fs.diff --]
[-- Type: text/plain, Size: 9205 bytes --]
The reiserfs disk format is designed to handle file systems up to
2^32-1 blocks, which at 4KiB blocks means ~ 16 TiB - 4KiB.
Unfortunately, the superblock's s_bmap_nr value, which contains a
count of the number of bitmap blocks in the file system is a 16 bit
value. This limits the usable size of the file system to
8 TiB (4096^2 * 8 * 65536).
This patch implements the changes introduced with reiserfsprogs 3.6.20,
where s_bmap_nr is zeroed out if the value would overflow.
Older implementations will see the zero value of s_bmap_nr and abort
the mount due to a vmalloc(0) before reading the bitmaps. This is safer
than the current behavior which can result in corruption or BUG's.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/reiserfs/bitmap.c | 39 ++++++++++++++++++++++-----------------
fs/reiserfs/journal.c | 6 +++---
fs/reiserfs/resize.c | 6 +++---
fs/reiserfs/super.c | 15 +++++++++++++++
include/linux/reiserfs_fs.h | 5 +++++
include/linux/reiserfs_fs_sb.h | 1 +
6 files changed, 49 insertions(+), 23 deletions(-)
--- a/fs/reiserfs/bitmap.c 2007-08-08 15:59:01.000000000 -0400
+++ b/fs/reiserfs/bitmap.c 2007-08-08 16:09:59.000000000 -0400
@@ -62,6 +62,7 @@ static inline void get_bit_address(struc
int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
{
unsigned int bmap, offset;
+ unsigned int bmap_count = reiserfs_bmap_count(s);
if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
reiserfs_warning(s,
@@ -77,25 +78,26 @@ int is_reusable(struct super_block *s, b
if (unlikely(test_bit(REISERFS_OLD_FORMAT,
&(REISERFS_SB(s)->s_properties)))) {
b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1;
- if (block >= bmap1 && block <= bmap1 + SB_BMAP_NR(s)) {
+ if (block >= bmap1 &&
+ block <= bmap1 + bmap_count) {
reiserfs_warning(s, "vs: 4019: is_reusable: "
"bitmap block %lu(%u) can't be freed or reused",
- block, SB_BMAP_NR(s));
+ block, bmap_count);
return 0;
}
} else {
if (offset == 0) {
reiserfs_warning(s, "vs: 4020: is_reusable: "
"bitmap block %lu(%u) can't be freed or reused",
- block, SB_BMAP_NR(s));
+ block, bmap_count);
return 0;
}
}
- if (bmap >= SB_BMAP_NR(s)) {
+ if (bmap >= bmap_count) {
reiserfs_warning(s,
"vs-4030: is_reusable: there is no so many bitmap blocks: "
- "block=%lu, bitmap_nr=%d", block, bmap);
+ "block=%lu, bitmap_nr=%u", block, bmap);
return 0;
}
@@ -145,8 +147,8 @@ static int scan_bitmap_block(struct reis
BUG_ON(!th->t_trans_id);
- RFALSE(bmap_n >= SB_BMAP_NR(s), "Bitmap %d is out of range (0..%d)",
- bmap_n, SB_BMAP_NR(s) - 1);
+ RFALSE(bmap_n >= reiserfs_bmap_count(s), "Bitmap %u is out of "
+ "range (0..%u)", bmap_n, reiserfs_bmap_count(s) - 1);
PROC_INFO_INC(s, scan_bitmap.bmap);
/* this is unclear and lacks comments, explain how journal bitmaps
work here for the reader. Convey a sense of the design here. What
@@ -251,12 +253,12 @@ static int bmap_hash_id(struct super_blo
} else {
hash_in = (char *)(&id);
hash = keyed_hash(hash_in, 4);
- bm = hash % SB_BMAP_NR(s);
+ bm = hash % reiserfs_bmap_count(s);
if (!bm)
bm = 1;
}
/* this can only be true when SB_BMAP_NR = 1 */
- if (bm >= SB_BMAP_NR(s))
+ if (bm >= reiserfs_bmap_count(s))
bm = 0;
return bm;
}
@@ -330,10 +332,10 @@ static int scan_bitmap(struct reiserfs_t
get_bit_address(s, *start, &bm, &off);
get_bit_address(s, finish, &end_bm, &end_off);
- if (bm > SB_BMAP_NR(s))
+ if (bm > reiserfs_bmap_count(s))
return 0;
- if (end_bm > SB_BMAP_NR(s))
- end_bm = SB_BMAP_NR(s);
+ if (end_bm > reiserfs_bmap_count(s))
+ end_bm = reiserfs_bmap_count(s);
/* When the bitmap is more than 10% free, anyone can allocate.
* When it's less than 10% free, only files that already use the
@@ -399,10 +401,12 @@ static void _reiserfs_free_block(struct
get_bit_address(s, block, &nr, &offset);
- if (nr >= sb_bmap_nr(rs)) {
+ if (nr >= reiserfs_bmap_count(s)) {
reiserfs_warning(s, "vs-4075: reiserfs_free_block: "
- "block %lu is out of range on %s",
- block, reiserfs_bdevname(s));
+ "block %lu is out of range on %s "
+ "(nr=%u,max=%u)", block,
+ reiserfs_bdevname(s), nr,
+ reiserfs_bmap_count(s));
return;
}
@@ -1326,12 +1330,13 @@ struct buffer_head *reiserfs_read_bitmap
int reiserfs_init_bitmap_cache(struct super_block *sb)
{
struct reiserfs_bitmap_info *bitmap;
+ unsigned int bmap_nr = reiserfs_bmap_count(sb);
- bitmap = vmalloc(sizeof (*bitmap) * SB_BMAP_NR(sb));
+ bitmap = vmalloc(sizeof (*bitmap) * bmap_nr);
if (bitmap == NULL)
return -ENOMEM;
- memset(bitmap, 0, sizeof (*bitmap) * SB_BMAP_NR(sb));
+ memset(bitmap, 0, sizeof (*bitmap) * bmap_nr);
SB_AP_BITMAP(sb) = bitmap;
--- a/fs/reiserfs/journal.c 2007-08-08 15:59:01.000000000 -0400
+++ b/fs/reiserfs/journal.c 2007-08-08 16:03:29.000000000 -0400
@@ -240,7 +240,7 @@ static void cleanup_bitmap_list(struct s
if (jb->bitmaps == NULL)
return;
- for (i = 0; i < SB_BMAP_NR(p_s_sb); i++) {
+ for (i = 0; i < reiserfs_bmap_count(p_s_sb); i++) {
if (jb->bitmaps[i]) {
free_bitmap_node(p_s_sb, jb->bitmaps[i]);
jb->bitmaps[i] = NULL;
@@ -2651,7 +2651,7 @@ int journal_init(struct super_block *p_s
journal->j_persistent_trans = 0;
if (reiserfs_allocate_list_bitmaps(p_s_sb,
journal->j_list_bitmap,
- SB_BMAP_NR(p_s_sb)))
+ reiserfs_bmap_count(p_s_sb)))
goto free_and_return;
allocate_bitmap_nodes(p_s_sb);
@@ -2659,7 +2659,7 @@ int journal_init(struct super_block *p_s
SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ?
REISERFS_OLD_DISK_OFFSET_IN_BYTES
/ p_s_sb->s_blocksize +
- SB_BMAP_NR(p_s_sb) +
+ reiserfs_bmap_count(p_s_sb) +
1 :
REISERFS_DISK_OFFSET_IN_BYTES /
p_s_sb->s_blocksize + 2);
--- a/fs/reiserfs/resize.c 2007-08-08 15:59:01.000000000 -0400
+++ b/fs/reiserfs/resize.c 2007-08-08 16:04:14.000000000 -0400
@@ -61,7 +61,7 @@ int reiserfs_resize(struct super_block *
}
/* count used bits in last bitmap block */
- block_r = SB_BLOCK_COUNT(s) - (SB_BMAP_NR(s) - 1) * s->s_blocksize * 8;
+ block_r = SB_BLOCK_COUNT(s) - (reiserfs_bmap_count(s) - 1) * s->s_blocksize * 8;
/* count bitmap blocks in new fs */
bmap_nr_new = block_count_new / (s->s_blocksize * 8);
@@ -73,7 +73,7 @@ int reiserfs_resize(struct super_block *
/* save old values */
block_count = SB_BLOCK_COUNT(s);
- bmap_nr = SB_BMAP_NR(s);
+ bmap_nr = reiserfs_bmap_count(s);
/* resizing of reiserfs bitmaps (journal and real), if needed */
if (bmap_nr_new > bmap_nr) {
@@ -206,7 +206,7 @@ int reiserfs_resize(struct super_block *
free_blocks + (block_count_new - block_count -
(bmap_nr_new - bmap_nr)));
PUT_SB_BLOCK_COUNT(s, block_count_new);
- PUT_SB_BMAP_NR(s, bmap_nr_new);
+ PUT_SB_BMAP_NR(s, bmap_would_wrap(bmap_nr_new) ? : bmap_nr_new );
s->s_dirt = 1;
journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
--- a/fs/reiserfs/super.c 2007-08-08 15:59:01.000000000 -0400
+++ b/fs/reiserfs/super.c 2007-08-08 16:04:51.000000000 -0400
@@ -1713,6 +1713,21 @@ static int reiserfs_fill_super(struct su
set_sb_umount_state(rs, REISERFS_ERROR_FS);
set_sb_fs_state(rs, 0);
+ /* Clear out s_bmap_nr if it would wrap. We can handle this
+ * case, but older revisions can't. This will cause the
+ * file system to fail mount on those older implementations,
+ * avoiding corruption. -jeffm */
+ if (bmap_would_wrap(reiserfs_bmap_count(s)) &&
+ sb_bmap_nr(rs) != 0) {
+ reiserfs_warning(s, "super-2030: This file system "
+ "claims to use %u bitmap blocks in "
+ "its super block, but requires %u. "
+ "Clearing to zero.", sb_bmap_nr(rs),
+ reiserfs_bmap_count(s));
+
+ set_sb_bmap_nr(rs, 0);
+ }
+
if (old_format_only(s)) {
/* filesystem of format 3.5 either with standard or non-standard
journal */
--- a/include/linux/reiserfs_fs.h 2007-08-08 15:59:01.000000000 -0400
+++ b/include/linux/reiserfs_fs.h 2007-08-08 16:10:59.000000000 -0400
@@ -229,6 +229,11 @@ struct reiserfs_super_block {
((!is_reiserfs_jr(SB_DISK_SUPER_BLOCK(s)) ? \
SB_ONDISK_JOURNAL_SIZE(s) + 1 : SB_ONDISK_RESERVED_FOR_JOURNAL(s)))
+/* s_bmap_nr is a u16 */
+#define reiserfs_bmap_count(sb) reiserfs_bmap_nr(SB_BLOCK_COUNT(sb), sb->s_blocksize)
+#define reiserfs_bmap_nr(count, blk_size) ((count - 1) / (blk_size * 8) + 1)
+#define bmap_would_wrap(n) (n > ((1LL << 16) - 1))
+
int is_reiserfs_3_5(struct reiserfs_super_block *rs);
int is_reiserfs_3_6(struct reiserfs_super_block *rs);
int is_reiserfs_jr(struct reiserfs_super_block *rs);
--- a/include/linux/reiserfs_fs_sb.h 2007-08-08 15:59:01.000000000 -0400
+++ b/include/linux/reiserfs_fs_sb.h 2007-08-08 15:59:03.000000000 -0400
@@ -410,6 +410,7 @@ struct reiserfs_sb_info {
char *s_qf_names[MAXQUOTAS];
int s_jquota_fmt;
#endif
+ unsigned int s_bmap_nr;
};
/* Definitions of reiserfs on-disk properties: */
--
Jeff Mahoney
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch 3/3] reiserfs: fix memset byte count during resize
2007-08-09 1:19 [patch 0/3] reiserfs: support for file systems > 8 TiB Jeff Mahoney
2007-08-09 1:19 ` [patch 1/3] reiserfs: fix usage of signed ints for block numbers Jeff Mahoney
2007-08-09 1:19 ` [patch 2/3] reiserfs: ignore s_bmap_nr on disk for file systems >= 8 TiB Jeff Mahoney
@ 2007-08-09 1:19 ` Jeff Mahoney
2 siblings, 0 replies; 5+ messages in thread
From: Jeff Mahoney @ 2007-08-09 1:19 UTC (permalink / raw)
To: ReiserFS Development Mailing List; +Cc: Vladimir Saveliev
[-- Attachment #1: reiserfs-fix-resize-meminit.diff --]
[-- Type: text/plain, Size: 899 bytes --]
The following patch corrects the memset in reiserfs_resize to clear
the memory allocated for the new bitmap info structs. Previously,
it would clear the memory used by the old size. Depending on the
contents of memory, this could cause incorrect caching behavior for
bitmap blocks in the newly allocated area.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/reiserfs/resize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/fs/reiserfs/resize.c 2007-08-07 11:07:15.000000000 -0400
+++ b/fs/reiserfs/resize.c 2007-08-07 11:07:25.000000000 -0400
@@ -119,7 +119,7 @@ int reiserfs_resize(struct super_block *
return -ENOMEM;
}
memset(bitmap, 0,
- sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
+ sizeof(struct reiserfs_bitmap_info) * bmap_nr_new);
for (i = 0; i < bmap_nr; i++)
bitmap[i] = old_bitmap[i];
--
Jeff Mahoney
SUSE Labs
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-08-09 1:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-09 1:19 [patch 0/3] reiserfs: support for file systems > 8 TiB Jeff Mahoney
2007-08-09 1:19 ` [patch 1/3] reiserfs: fix usage of signed ints for block numbers Jeff Mahoney
2007-08-09 1:19 ` [patch 2/3] reiserfs: ignore s_bmap_nr on disk for file systems >= 8 TiB Jeff Mahoney
2007-08-09 1:19 ` [patch 3/3] reiserfs: fix memset byte count during resize Jeff Mahoney
-- strict thread matches above, loose matches on Subject: below --
2007-08-07 15:28 [PATCH 2/3] reiserfs: ignore s_bmap_nr on disk for file systems >= 8 TiB Jeff Mahoney
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.