2004-03-04 06:09:56

by Eric Sandeen

[permalink] [raw]
Subject: [PATCH] LBD fix for 2.6.3

A couple xfs users stumbled upon this problem while trying to
use 2.6 + CONFIG_LBD on ia32 boxes - mkfs.xfs followed by
xfs_repair was failing. At first we thought it was
a raid/md problem, but it's more generic than that. There's
a problem in __block_write_full_page():

--- linux-2.6.3/fs/buffer.c.orig 2004-03-04 00:01:42.000000000 -0600
+++ linux-2.6.3/fs/buffer.c 2004-03-03 23:46:56.000000000 -0600
@@ -1738,8 +1738,8 @@
get_block_t *get_block, struct writeback_control *wbc)
{
int err;
- unsigned long block;
- unsigned long last_block;
+ sector_t block;
+ sector_t last_block;
struct buffer_head *bh, *head;
int nr_underway = 0;

later in the function we do:
last_block = (i_size_read(inode) - 1) >> inode->i_blkbits;
and
block = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);

... these overflow 32 bits for large devices.

The sophisticated mkfs/repair test works with that patch in place. ;)

-Eric


2004-03-04 07:05:06

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] LBD fix for 2.6.3

Eric Sandeen <[email protected]> wrote:
>
> - unsigned long block;
> - unsigned long last_block;
> + sector_t block;
> + sector_t last_block;

egads. That bug has been there from day one. CONFIG_LBD cannot possibly
work correctly due to this error.

Thanks.

Actually, there more instances of this bug in buffer.c. This should fix them
up, and also let's be clearer about discriminating between block numbers,
pagecache indices and offsets-within-pages.


diff -puN fs/buffer.c~writepage-lbd-fix fs/buffer.c
--- 25/fs/buffer.c~writepage-lbd-fix 2004-03-03 22:53:48.000000000 -0800
+++ 25-akpm/fs/buffer.c 2004-03-03 23:02:39.000000000 -0800
@@ -404,7 +404,7 @@ __find_get_block_slow(struct block_devic
struct inode *bd_inode = bdev->bd_inode;
struct address_space *bd_mapping = bd_inode->i_mapping;
struct buffer_head *ret = NULL;
- unsigned long index;
+ pgoff_t index;
struct buffer_head *bh;
struct buffer_head *head;
struct page *page;
@@ -1125,8 +1125,8 @@ init_page_buffers(struct page *page, str
* This is user purely for blockdev mappings.
*/
static struct page *
-grow_dev_page(struct block_device *bdev, unsigned long block,
- unsigned long index, int size)
+grow_dev_page(struct block_device *bdev, sector_t block,
+ pgoff_t index, int size)
{
struct inode *inode = bdev->bd_inode;
struct page *page;
@@ -1182,10 +1182,10 @@ failed:
* grow_dev_page() will go BUG() if this happens.
*/
static inline int
-grow_buffers(struct block_device *bdev, unsigned long block, int size)
+grow_buffers(struct block_device *bdev, sector_t block, int size)
{
struct page *page;
- unsigned long index;
+ pgoff_t index;
int sizebits;

/* Size must be multiple of hard sectorsize */
@@ -1742,8 +1742,8 @@ static int __block_write_full_page(struc
get_block_t *get_block, struct writeback_control *wbc)
{
int err;
- unsigned long block;
- unsigned long last_block;
+ sector_t block;
+ sector_t last_block;
struct buffer_head *bh, *head;
int nr_underway = 0;

@@ -2211,7 +2211,7 @@ int cont_prepare_write(struct page *page
struct address_space *mapping = page->mapping;
struct inode *inode = mapping->host;
struct page *new_page;
- unsigned long pgpos;
+ pgoff_t pgpos;
long status;
unsigned zerofrom;
unsigned blocksize = 1 << inode->i_blkbits;
@@ -2516,9 +2516,11 @@ EXPORT_SYMBOL(nobh_truncate_page);
int block_truncate_page(struct address_space *mapping,
loff_t from, get_block_t *get_block)
{
- unsigned long index = from >> PAGE_CACHE_SHIFT;
+ pgoff_t index = from >> PAGE_CACHE_SHIFT;
unsigned offset = from & (PAGE_CACHE_SIZE-1);
- unsigned blocksize, iblock, length, pos;
+ unsigned blocksize;
+ pgoff_t iblock;
+ unsigned length, pos;
struct inode *inode = mapping->host;
struct page *page;
struct buffer_head *bh;
@@ -2598,7 +2600,7 @@ int block_write_full_page(struct page *p
{
struct inode * const inode = page->mapping->host;
loff_t i_size = i_size_read(inode);
- const unsigned long end_index = i_size >> PAGE_CACHE_SHIFT;
+ const pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
unsigned offset;
void *kaddr;


_

2004-03-04 23:41:37

by Eric Sandeen

[permalink] [raw]
Subject: Re: [PATCH] LBD fix for 2.6.3

On Thu, 2004-03-04 at 01:04, Andrew Morton wrote:
> Actually, there more instances of this bug in buffer.c.

Another one, I think, unless I've missed something...


--- fs/buffer.c_1.3 2004-03-04 17:38:49.000000000 -0600
+++ fs/buffer.c 2004-03-04 17:37:13.000000000 -0600
@@ -1093,7 +1093,7 @@
*/
static void
init_page_buffers(struct page *page, struct block_device *bdev,
- int block, int size)
+ sector_t block, int size)
{
struct buffer_head *head = page_buffers(page);
struct buffer_head *bh = head;

--
Eric Sandeen [C]XFS for Linux http://oss.sgi.com/projects/xfs
[email protected] SGI, Inc. 651-683-3102