History

block: introduce bdev_file_inode()

Similar to the file_inode() helper, provide a helper to lookup the inode for a raw block device itself.

Dan Williams committed 11 years ago

Commit 4ebb16c1 parent 90a545e1 file · +12 −7Browse files

Unified · Split

fs/block_dev.c+12−7
@@ -156,11 +156,16 @@ blkdev_get_block(struct inode *inode, sector_t iblock, · 155 unmodified lines
156156 return 0;
157157 }
158158
159+static struct inode *bdev_file_inode(struct file *file)
160+{
161+ return file->f_mapping->host;
162+}
163+
159164 static ssize_t
160165 blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter, loff_t offset)
161166 {
162167 struct file *file = iocb->ki_filp;
163− struct inode *inode = file->f_mapping->host;
168+ struct inode *inode = bdev_file_inode(file);
164169
165170 if (IS_DAX(inode))
166171 return dax_do_io(iocb, inode, iter, offset, blkdev_get_block,
@@ -338,7 +343,7 @@ static int blkdev_write_end(struct file *file, struct address_space *mapping, · 171 unmodified lines
338343 */
339344 static loff_t block_llseek(struct file *file, loff_t offset, int whence)
340345 {
341− struct inode *bd_inode = file->f_mapping->host;
346+ struct inode *bd_inode = bdev_file_inode(file);
342347 loff_t retval;
343348
344349 mutex_lock(&bd_inode->i_mutex);
@@ -349,7 +354,7 @@ static loff_t block_llseek(struct file *file, loff_t offset, int whence) · 4 unmodified lines
349354
350355 int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
351356 {
352− struct inode *bd_inode = filp->f_mapping->host;
357+ struct inode *bd_inode = bdev_file_inode(filp);
353358 struct block_device *bdev = I_BDEV(bd_inode);
354359 int error;
355360
@@ -1605,14 +1610,14 @@ EXPORT_SYMBOL(blkdev_put); · 1249 unmodified lines
16051610
16061611 static int blkdev_close(struct inode * inode, struct file * filp)
16071612 {
1608− struct block_device *bdev = I_BDEV(filp->f_mapping->host);
1613+ struct block_device *bdev = I_BDEV(bdev_file_inode(filp));
16091614 blkdev_put(bdev, filp->f_mode);
16101615 return 0;
16111616 }
16121617
16131618 static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg)
16141619 {
1615− struct block_device *bdev = I_BDEV(file->f_mapping->host);
1620+ struct block_device *bdev = I_BDEV(bdev_file_inode(file));
16161621 fmode_t mode = file->f_mode;
16171622
16181623 /*
@@ -1637,7 +1642,7 @@ static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) · 18 unmodified lines
16371642 ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
16381643 {
16391644 struct file *file = iocb->ki_filp;
1640− struct inode *bd_inode = file->f_mapping->host;
1645+ struct inode *bd_inode = bdev_file_inode(file);
16411646 loff_t size = i_size_read(bd_inode);
16421647 struct blk_plug plug;
16431648 ssize_t ret;
@@ -1669,7 +1674,7 @@ EXPORT_SYMBOL_GPL(blkdev_write_iter); · 25 unmodified lines
16691674 ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
16701675 {
16711676 struct file *file = iocb->ki_filp;
1672− struct inode *bd_inode = file->f_mapping->host;
1677+ struct inode *bd_inode = bdev_file_inode(file);
16731678 loff_t size = i_size_read(bd_inode);
16741679 loff_t pos = iocb->ki_pos;
16751680

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t