mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	blkdev_max_block: make private to fs/buffer.c
We really don't want to look at the block size for the raw block device accesses in fs/block-dev.c, because it may be changing from under us. So get rid of the max_block logic entirely, since the caller should already have done it anyway. That leaves the only user of this function in fs/buffer.c, so move the whole function there and make it static. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									ab73857e35
								
							
						
					
					
						commit
						bbec0270bd
					
				
					 3 changed files with 14 additions and 56 deletions
				
			
		| 
						 | 
					@ -70,19 +70,6 @@ static void bdev_inode_switch_bdi(struct inode *inode,
 | 
				
			||||||
	spin_unlock(&dst->wb.list_lock);
 | 
						spin_unlock(&dst->wb.list_lock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sector_t blkdev_max_block(struct block_device *bdev)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	sector_t retval = ~((sector_t)0);
 | 
					 | 
				
			||||||
	loff_t sz = i_size_read(bdev->bd_inode);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (sz) {
 | 
					 | 
				
			||||||
		unsigned int size = block_size(bdev);
 | 
					 | 
				
			||||||
		unsigned int sizebits = blksize_bits(size);
 | 
					 | 
				
			||||||
		retval = (sz >> sizebits);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return retval;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* Kill _all_ buffers and pagecache , dirty or not.. */
 | 
					/* Kill _all_ buffers and pagecache , dirty or not.. */
 | 
				
			||||||
void kill_bdev(struct block_device *bdev)
 | 
					void kill_bdev(struct block_device *bdev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -163,52 +150,12 @@ static int
 | 
				
			||||||
blkdev_get_block(struct inode *inode, sector_t iblock,
 | 
					blkdev_get_block(struct inode *inode, sector_t iblock,
 | 
				
			||||||
		struct buffer_head *bh, int create)
 | 
							struct buffer_head *bh, int create)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (iblock >= blkdev_max_block(I_BDEV(inode))) {
 | 
					 | 
				
			||||||
		if (create)
 | 
					 | 
				
			||||||
			return -EIO;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		/*
 | 
					 | 
				
			||||||
		 * for reads, we're just trying to fill a partial page.
 | 
					 | 
				
			||||||
		 * return a hole, they will have to call get_block again
 | 
					 | 
				
			||||||
		 * before they can fill it, and they will get -EIO at that
 | 
					 | 
				
			||||||
		 * time
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	bh->b_bdev = I_BDEV(inode);
 | 
						bh->b_bdev = I_BDEV(inode);
 | 
				
			||||||
	bh->b_blocknr = iblock;
 | 
						bh->b_blocknr = iblock;
 | 
				
			||||||
	set_buffer_mapped(bh);
 | 
						set_buffer_mapped(bh);
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int
 | 
					 | 
				
			||||||
blkdev_get_blocks(struct inode *inode, sector_t iblock,
 | 
					 | 
				
			||||||
		struct buffer_head *bh, int create)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	sector_t end_block = blkdev_max_block(I_BDEV(inode));
 | 
					 | 
				
			||||||
	unsigned long max_blocks = bh->b_size >> inode->i_blkbits;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if ((iblock + max_blocks) > end_block) {
 | 
					 | 
				
			||||||
		max_blocks = end_block - iblock;
 | 
					 | 
				
			||||||
		if ((long)max_blocks <= 0) {
 | 
					 | 
				
			||||||
			if (create)
 | 
					 | 
				
			||||||
				return -EIO;	/* write fully beyond EOF */
 | 
					 | 
				
			||||||
			/*
 | 
					 | 
				
			||||||
			 * It is a read which is fully beyond EOF.  We return
 | 
					 | 
				
			||||||
			 * a !buffer_mapped buffer
 | 
					 | 
				
			||||||
			 */
 | 
					 | 
				
			||||||
			max_blocks = 0;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	bh->b_bdev = I_BDEV(inode);
 | 
					 | 
				
			||||||
	bh->b_blocknr = iblock;
 | 
					 | 
				
			||||||
	bh->b_size = max_blocks << inode->i_blkbits;
 | 
					 | 
				
			||||||
	if (max_blocks)
 | 
					 | 
				
			||||||
		set_buffer_mapped(bh);
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static ssize_t
 | 
					static ssize_t
 | 
				
			||||||
blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
 | 
					blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
 | 
				
			||||||
			loff_t offset, unsigned long nr_segs)
 | 
								loff_t offset, unsigned long nr_segs)
 | 
				
			||||||
| 
						 | 
					@ -217,7 +164,7 @@ blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
 | 
				
			||||||
	struct inode *inode = file->f_mapping->host;
 | 
						struct inode *inode = file->f_mapping->host;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return __blockdev_direct_IO(rw, iocb, inode, I_BDEV(inode), iov, offset,
 | 
						return __blockdev_direct_IO(rw, iocb, inode, I_BDEV(inode), iov, offset,
 | 
				
			||||||
				    nr_segs, blkdev_get_blocks, NULL, NULL, 0);
 | 
									    nr_segs, blkdev_get_block, NULL, NULL, 0);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int __sync_blockdev(struct block_device *bdev, int wait)
 | 
					int __sync_blockdev(struct block_device *bdev, int wait)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										14
									
								
								fs/buffer.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								fs/buffer.c
									
									
									
									
									
								
							| 
						 | 
					@ -911,6 +911,18 @@ link_dev_buffers(struct page *page, struct buffer_head *head)
 | 
				
			||||||
	attach_page_buffers(page, head);
 | 
						attach_page_buffers(page, head);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						sector_t retval = ~((sector_t)0);
 | 
				
			||||||
 | 
						loff_t sz = i_size_read(bdev->bd_inode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (sz) {
 | 
				
			||||||
 | 
							unsigned int sizebits = blksize_bits(size);
 | 
				
			||||||
 | 
							retval = (sz >> sizebits);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return retval;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Initialise the state of a blockdev page's buffers.
 | 
					 * Initialise the state of a blockdev page's buffers.
 | 
				
			||||||
 */ 
 | 
					 */ 
 | 
				
			||||||
| 
						 | 
					@ -921,7 +933,7 @@ init_page_buffers(struct page *page, struct block_device *bdev,
 | 
				
			||||||
	struct buffer_head *head = page_buffers(page);
 | 
						struct buffer_head *head = page_buffers(page);
 | 
				
			||||||
	struct buffer_head *bh = head;
 | 
						struct buffer_head *bh = head;
 | 
				
			||||||
	int uptodate = PageUptodate(page);
 | 
						int uptodate = PageUptodate(page);
 | 
				
			||||||
	sector_t end_block = blkdev_max_block(I_BDEV(bdev->bd_inode));
 | 
						sector_t end_block = blkdev_max_block(I_BDEV(bdev->bd_inode), size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	do {
 | 
						do {
 | 
				
			||||||
		if (!buffer_mapped(bh)) {
 | 
							if (!buffer_mapped(bh)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2047,7 +2047,6 @@ extern void unregister_blkdev(unsigned int, const char *);
 | 
				
			||||||
extern struct block_device *bdget(dev_t);
 | 
					extern struct block_device *bdget(dev_t);
 | 
				
			||||||
extern struct block_device *bdgrab(struct block_device *bdev);
 | 
					extern struct block_device *bdgrab(struct block_device *bdev);
 | 
				
			||||||
extern void bd_set_size(struct block_device *, loff_t size);
 | 
					extern void bd_set_size(struct block_device *, loff_t size);
 | 
				
			||||||
extern sector_t blkdev_max_block(struct block_device *bdev);
 | 
					 | 
				
			||||||
extern void bd_forget(struct inode *inode);
 | 
					extern void bd_forget(struct inode *inode);
 | 
				
			||||||
extern void bdput(struct block_device *);
 | 
					extern void bdput(struct block_device *);
 | 
				
			||||||
extern void invalidate_bdev(struct block_device *);
 | 
					extern void invalidate_bdev(struct block_device *);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue