From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Piggin Subject: Re: [patch|rfc] block: don't mark buffers beyond end of disk as mapped Date: Wed, 2 May 2012 09:23:35 +1000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, jaxboe@fusionio.com, Kyle McMartin To: Jeff Moyer Return-path: Received: from mail-ob0-f174.google.com ([209.85.214.174]:53857 "EHLO mail-ob0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756954Ab2EAXXg convert rfc822-to-8bit (ORCPT ); Tue, 1 May 2012 19:23:36 -0400 In-Reply-To: Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 2 May 2012 07:40, Jeff Moyer wrote: > Jeff Moyer writes: > >> Nick Piggin writes: >> >>> On 2 May 2012 00:08, Jeff Moyer wrote: >>>> Nick Piggin writes: >>>> >>>>> Not a bad fix. But it's kind of sad to have i_size checking logic= also in >>>>> block_read_full_page, that does not cope with this. >>>>> >>>>> I have found there are parts of the kernel (readahead) that try t= o read >>>>> beyond EOF and seem to get angry if we return an error (by not >>>>> marking uptodate in readpage) in that case though :( >>>>> >>>>> But, either way, I think it's very reasonable to not mark buffers= beyond >>>>> end of device as mapped. So I think your patch is fine. >>>>> >>>>> I guess for ext[234], it does not read metadata close to the end = of the >>>>> device or you were using 4K sized blocks? >>>> >>>> Well, the test case just reads directly from the loop device, bypa= ssing >>>> the file system, and I did use 1KB blocks when making the file sys= tem, so >>>> it is quite puzzling. >>> >>> It's because buffer_head creation does not go through the same path= s >>> for bdev file access versus getblk APIs. >>> >>> blkdev_get_block does the right thing there >>> >>> In fact, it's probably good to unify the checks here, i.e., use max= _blocks() >> >> You really think it's worth it? =C2=A0I mean, it's just an i_size_re= ad and a >> shift, and there is precedent for it inside fs/buffer.c. =C2=A0I'd p= refer to >> keep the patch as-is, but will change it if you feel that strongly a= bout >> it. > > Anyway, here is the other version of the patch, using max_block as yo= u > suggested. > > Cheers, > Jeff > > Signed-off-by: Jeff Moyer Thanks! Acked-by: Nick Piggin > > diff --git a/fs/block_dev.c b/fs/block_dev.c > index e08f6a2..ba11c30 100644 > --- a/fs/block_dev.c > +++ b/fs/block_dev.c > @@ -70,7 +70,7 @@ static void bdev_inode_switch_bdi(struct inode *ino= de, > =C2=A0 =C2=A0 =C2=A0 =C2=A0spin_unlock(&dst->wb.list_lock); > =C2=A0} > > -static sector_t max_block(struct block_device *bdev) > +sector_t blkdev_max_block(struct block_device *bdev) > =C2=A0{ > =C2=A0 =C2=A0 =C2=A0 =C2=A0sector_t retval =3D ~((sector_t)0); > =C2=A0 =C2=A0 =C2=A0 =C2=A0loff_t sz =3D i_size_read(bdev->bd_inode); > @@ -163,7 +163,7 @@ static int > =C2=A0blkdev_get_block(struct inode *inode, sector_t iblock, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct buffer_= head *bh, int create) > =C2=A0{ > - =C2=A0 =C2=A0 =C2=A0 if (iblock >=3D max_block(I_BDEV(inode))) { > + =C2=A0 =C2=A0 =C2=A0 if (iblock >=3D blkdev_max_block(I_BDEV(inode)= )) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (create) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0return -EIO; > > @@ -185,7 +185,7 @@ static int > =C2=A0blkdev_get_blocks(struct inode *inode, sector_t iblock, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0struct buffer_= head *bh, int create) > =C2=A0{ > - =C2=A0 =C2=A0 =C2=A0 sector_t end_block =3D max_block(I_BDEV(inode)= ); > + =C2=A0 =C2=A0 =C2=A0 sector_t end_block =3D blkdev_max_block(I_BDEV= (inode)); > =C2=A0 =C2=A0 =C2=A0 =C2=A0unsigned long max_blocks =3D bh->b_size >>= inode->i_blkbits; > > =C2=A0 =C2=A0 =C2=A0 =C2=A0if ((iblock + max_blocks) > end_block) { > diff --git a/fs/buffer.c b/fs/buffer.c > index 351e18e..ad5938c 100644 > --- a/fs/buffer.c > +++ b/fs/buffer.c > @@ -921,6 +921,7 @@ init_page_buffers(struct page *page, struct block= _device *bdev, > =C2=A0 =C2=A0 =C2=A0 =C2=A0struct buffer_head *head =3D page_buffers(= page); > =C2=A0 =C2=A0 =C2=A0 =C2=A0struct buffer_head *bh =3D head; > =C2=A0 =C2=A0 =C2=A0 =C2=A0int uptodate =3D PageUptodate(page); > + =C2=A0 =C2=A0 =C2=A0 sector_t end_block =3D blkdev_max_block(I_BDEV= (bdev->bd_inode)); > > =C2=A0 =C2=A0 =C2=A0 =C2=A0do { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if (!buffer_ma= pped(bh)) { > @@ -929,7 +930,8 @@ init_page_buffers(struct page *page, struct block= _device *bdev, > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0bh->b_blocknr =3D block; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0if (uptodate) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0set_buffer_uptodate(bh); > - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 set_buffer_mapped(bh); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 if (block < end_block) > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 set_buffer_mapped(bh); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0block++; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0bh =3D bh->b_t= his_page; > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 8de6755..25c40b9 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -2051,6 +2051,7 @@ extern void unregister_blkdev(unsigned int, con= st char *); > =C2=A0extern struct block_device *bdget(dev_t); > =C2=A0extern struct block_device *bdgrab(struct block_device *bdev); > =C2=A0extern void bd_set_size(struct block_device *, loff_t size); > +extern sector_t blkdev_max_block(struct block_device *bdev); > =C2=A0extern void bd_forget(struct inode *inode); > =C2=A0extern void bdput(struct block_device *); > =C2=A0extern void invalidate_bdev(struct block_device *); -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel= " in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html