Release 4.7 fs/block_dev.c
/*
* linux/fs/block_dev.c
*
* Copyright (C) 1991, 1992 Linus Torvalds
* Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
*/
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fcntl.h>
#include <linux/slab.h>
#include <linux/kmod.h>
#include <linux/major.h>
#include <linux/device_cgroup.h>
#include <linux/highmem.h>
#include <linux/blkdev.h>
#include <linux/backing-dev.h>
#include <linux/module.h>
#include <linux/blkpg.h>
#include <linux/magic.h>
#include <linux/buffer_head.h>
#include <linux/swap.h>
#include <linux/pagevec.h>
#include <linux/writeback.h>
#include <linux/mpage.h>
#include <linux/mount.h>
#include <linux/uio.h>
#include <linux/namei.h>
#include <linux/log2.h>
#include <linux/cleancache.h>
#include <linux/dax.h>
#include <linux/badblocks.h>
#include <asm/uaccess.h>
#include "internal.h"
struct bdev_inode {
struct block_device bdev;
struct inode vfs_inode;
};
static const struct address_space_operations def_blk_aops;
static inline struct bdev_inode *BDEV_I(struct inode *inode)
{
return container_of(inode, struct bdev_inode, vfs_inode);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 25 | 100.00% | 1 | 100.00% |
| Total | 25 | 100.00% | 1 | 100.00% |
struct block_device *I_BDEV(struct inode *inode)
{
return &BDEV_I(inode)->bdev;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 21 | 100.00% | 1 | 100.00% |
| Total | 21 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(I_BDEV);
void __vfs_msg(struct super_block *sb, const char *prefix, const char *fmt, ...)
{
struct va_format vaf;
va_list args;
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
printk_ratelimited("%sVFS (%s): %pV\n", prefix, sb->s_id, &vaf);
va_end(args);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
toshi kani | toshi kani | 68 | 100.00% | 1 | 100.00% |
| Total | 68 | 100.00% | 1 | 100.00% |
static void bdev_write_inode(struct block_device *bdev)
{
struct inode *inode = bdev->bd_inode;
int ret;
spin_lock(&inode->i_lock);
while (inode->i_state & I_DIRTY) {
spin_unlock(&inode->i_lock);
ret = write_inode_now(inode, true);
if (ret) {
char name[BDEVNAME_SIZE];
pr_warn_ratelimited("VFS: Dirty inode writeback failed "
"for block device %s (err=%d).\n",
bdevname(bdev, name), ret);
}
spin_lock(&inode->i_lock);
}
spin_unlock(&inode->i_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
vivek goyal | vivek goyal | 42 | 41.58% | 1 | 16.67% |
dave chinner | dave chinner | 36 | 35.64% | 2 | 33.33% |
christoph hellwig | christoph hellwig | 17 | 16.83% | 1 | 16.67% |
jan kara | jan kara | 4 | 3.96% | 1 | 16.67% |
tejun heo | tejun heo | 2 | 1.98% | 1 | 16.67% |
| Total | 101 | 100.00% | 6 | 100.00% |
/* Kill _all_ buffers and pagecache , dirty or not.. */
void kill_bdev(struct block_device *bdev)
{
struct address_space *mapping = bdev->bd_inode->i_mapping;
if (mapping->nrpages == 0 && mapping->nrexceptional == 0)
return;
invalidate_bh_lrus();
truncate_inode_pages(mapping, 0);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 15 | 32.61% | 1 | 20.00% |
linus torvalds | linus torvalds | 13 | 28.26% | 1 | 20.00% |
peter zijlstra | peter zijlstra | 12 | 26.09% | 1 | 20.00% |
johannes weiner | johannes weiner | 5 | 10.87% | 1 | 20.00% |
ross zwisler | ross zwisler | 1 | 2.17% | 1 | 20.00% |
| Total | 46 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL(kill_bdev);
/* Invalidate clean unused buffers and pagecache. */
void invalidate_bdev(struct block_device *bdev)
{
struct address_space *mapping = bdev->bd_inode->i_mapping;
if (mapping->nrpages == 0)
return;
invalidate_bh_lrus();
lru_add_drain_all(); /* make sure all lru add caches are flushed */
invalidate_mapping_pages(mapping, 0, -1);
/* 99% of the time, we don't need to flush the cleancache on the bdev.
* But, for the strange corners, lets be cautious
*/
cleancache_invalidate_inode(mapping);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 42 | 79.25% | 1 | 33.33% |
linus torvalds | linus torvalds | 10 | 18.87% | 1 | 33.33% |
dan magenheimer | dan magenheimer | 1 | 1.89% | 1 | 33.33% |
| Total | 53 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(invalidate_bdev);
int set_blocksize(struct block_device *bdev, int size)
{
/* Size must be a power of two, and between 512 and PAGE_SIZE */
if (size > PAGE_SIZE || size < 512 || !is_power_of_2(size))
return -EINVAL;
/* Size cannot be smaller than the size supported by the device */
if (size < bdev_logical_block_size(bdev))
return -EINVAL;
/* Don't change the size if it is same as current */
if (bdev->bd_block_size != size) {
sync_blockdev(bdev);
bdev->bd_block_size = size;
bdev->bd_inode->i_blkbits = blksize_bits(size);
kill_bdev(bdev);
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 65 | 73.03% | 2 | 20.00% |
al viro | al viro | 12 | 13.48% | 4 | 40.00% |
mika kukkonen | mika kukkonen | 6 | 6.74% | 1 | 10.00% |
vignesh babu | vignesh babu | 4 | 4.49% | 1 | 10.00% |
martin k. petersen | martin k. petersen | 1 | 1.12% | 1 | 10.00% |
andrew morton | andrew morton | 1 | 1.12% | 1 | 10.00% |
| Total | 89 | 100.00% | 10 | 100.00% |
EXPORT_SYMBOL(set_blocksize);
int sb_set_blocksize(struct super_block *sb, int size)
{
if (set_blocksize(sb->s_bdev, size))
return 0;
/* If we get here, we know size is power of two
* and it's value is between 512 and PAGE_SIZE */
sb->s_blocksize = size;
sb->s_blocksize_bits = blksize_bits(size);
return sb->s_blocksize;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 42 | 87.50% | 1 | 25.00% |
coywolf qi hunt | coywolf qi hunt | 4 | 8.33% | 1 | 25.00% |
al viro | al viro | 1 | 2.08% | 1 | 25.00% |
mika kukkonen | mika kukkonen | 1 | 2.08% | 1 | 25.00% |
| Total | 48 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(sb_set_blocksize);
int sb_min_blocksize(struct super_block *sb, int size)
{
int minsize = bdev_logical_block_size(sb->s_bdev);
if (size < minsize)
size = minsize;
return sb_set_blocksize(sb, size);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 39 | 95.12% | 1 | 33.33% |
martin k. petersen | martin k. petersen | 1 | 2.44% | 1 | 33.33% |
al viro | al viro | 1 | 2.44% | 1 | 33.33% |
| Total | 41 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(sb_min_blocksize);
static int
blkdev_get_block(struct inode *inode, sector_t iblock,
struct buffer_head *bh, int create)
{
bh->b_bdev = I_BDEV(inode);
bh->b_blocknr = iblock;
set_buffer_mapped(bh);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 18 | 40.00% | 2 | 22.22% |
linus torvalds | linus torvalds | 13 | 28.89% | 3 | 33.33% |
pre-git | pre-git | 8 | 17.78% | 3 | 33.33% |
kenneth w. chen | kenneth w. chen | 6 | 13.33% | 1 | 11.11% |
| Total | 45 | 100.00% | 9 | 100.00% |
static struct inode *bdev_file_inode(struct file *file)
{
return file->f_mapping->host;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
dan williams | dan williams | 20 | 100.00% | 1 | 100.00% |
| Total | 20 | 100.00% | 1 | 100.00% |
static ssize_t
blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
{
struct file *file = iocb->ki_filp;
struct inode *inode = bdev_file_inode(file);
if (IS_DAX(inode))
return dax_do_io(iocb, inode, iter, blkdev_get_block,
NULL, DIO_SKIP_DIO_COUNT);
return __blockdev_direct_IO(iocb, inode, I_BDEV(inode), iter,
blkdev_get_block, NULL, NULL,
DIO_SKIP_DIO_COUNT);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 34 | 41.98% | 7 | 43.75% |
matthew wilcox | matthew wilcox | 23 | 28.40% | 1 | 6.25% |
linus torvalds | linus torvalds | 10 | 12.35% | 2 | 12.50% |
christoph hellwig | christoph hellwig | 4 | 4.94% | 1 | 6.25% |
al viro | al viro | 3 | 3.70% | 1 | 6.25% |
dan williams | dan williams | 3 | 3.70% | 1 | 6.25% |
chuck lever | chuck lever | 2 | 2.47% | 1 | 6.25% |
kenneth w. chen | kenneth w. chen | 1 | 1.23% | 1 | 6.25% |
jens axboe | jens axboe | 1 | 1.23% | 1 | 6.25% |
| Total | 81 | 100.00% | 16 | 100.00% |
int __sync_blockdev(struct block_device *bdev, int wait)
{
if (!bdev)
return 0;
if (!wait)
return filemap_flush(bdev->bd_inode->i_mapping);
return filemap_write_and_wait(bdev->bd_inode->i_mapping);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jan kara | jan kara | 26 | 56.52% | 1 | 50.00% |
nick piggin | nick piggin | 20 | 43.48% | 1 | 50.00% |
| Total | 46 | 100.00% | 2 | 100.00% |
/*
* Write out and wait upon all the dirty data associated with a block
* device via its mapping. Does not take the superblock lock.
*/
int sync_blockdev(struct block_device *bdev)
{
return __sync_blockdev(bdev, 1);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jan kara | jan kara | 15 | 83.33% | 1 | 50.00% |
nick piggin | nick piggin | 3 | 16.67% | 1 | 50.00% |
| Total | 18 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(sync_blockdev);
/*
* Write out and wait upon all dirty data associated with this
* device. Filesystem data as well as the underlying block
* device. Takes the superblock lock.
*/
int fsync_bdev(struct block_device *bdev)
{
struct super_block *sb = get_super(bdev);
if (sb) {
int res = sync_filesystem(sb);
drop_super(sb);
return res;
}
return sync_blockdev(bdev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nick piggin | nick piggin | 47 | 97.92% | 1 | 50.00% |
jan kara | jan kara | 1 | 2.08% | 1 | 50.00% |
| Total | 48 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(fsync_bdev);
/**
* freeze_bdev -- lock a filesystem and force it into a consistent state
* @bdev: blockdevice to lock
*
* If a superblock is found on this device, we take the s_umount semaphore
* on it to make sure nobody unmounts until the snapshot creation is done.
* The reference counter (bd_fsfreeze_count) guarantees that only the last
* unfreeze process can unfreeze the frozen filesystem actually when multiple
* freeze requests arrive simultaneously. It counts up in freeze_bdev() and
* count down in thaw_bdev(). When it becomes 0, thaw_bdev() will unfreeze
* actually.
*/
struct super_block *freeze_bdev(struct block_device *bdev)
{
struct super_block *sb;
int error = 0;
mutex_lock(&bdev->bd_fsfreeze_mutex);
if (++bdev->bd_fsfreeze_count > 1) {
/*
* We don't even need to grab a reference - the first call
* to freeze_bdev grab an active reference and only the last
* thaw_bdev drops it.
*/
sb = get_super(bdev);
drop_super(sb);
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return sb;
}
sb = get_active_super(bdev);
if (!sb)
goto out;
if (sb->s_op->freeze_super)
error = sb->s_op->freeze_super(sb);
else
error = freeze_super(sb);
if (error) {
deactivate_super(sb);
bdev->bd_fsfreeze_count--;
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return ERR_PTR(error);
}
deactivate_super(sb);
out:
sync_blockdev(bdev);
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return sb; /* thaw_bdev releases s->s_umount */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nick piggin | nick piggin | 117 | 72.67% | 1 | 20.00% |
christoph hellwig | christoph hellwig | 21 | 13.04% | 2 | 40.00% |
benjamin marzinski | benjamin marzinski | 20 | 12.42% | 1 | 20.00% |
josef bacik | josef bacik | 3 | 1.86% | 1 | 20.00% |
| Total | 161 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL(freeze_bdev);
/**
* thaw_bdev -- unlock filesystem
* @bdev: blockdevice to unlock
* @sb: associated superblock
*
* Unlocks the filesystem and marks it writeable again after freeze_bdev().
*/
int thaw_bdev(struct block_device *bdev, struct super_block *sb)
{
int error = -EINVAL;
mutex_lock(&bdev->bd_fsfreeze_mutex);
if (!bdev->bd_fsfreeze_count)
goto out;
error = 0;
if (--bdev->bd_fsfreeze_count > 0)
goto out;
if (!sb)
goto out;
if (sb->s_op->thaw_super)
error = sb->s_op->thaw_super(sb);
else
error = thaw_super(sb);
if (error) {
bdev->bd_fsfreeze_count++;
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return error;
}
out:
mutex_unlock(&bdev->bd_fsfreeze_mutex);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nick piggin | nick piggin | 86 | 68.80% | 1 | 25.00% |
benjamin marzinski | benjamin marzinski | 20 | 16.00% | 1 | 25.00% |
christoph hellwig | christoph hellwig | 14 | 11.20% | 1 | 25.00% |
josef bacik | josef bacik | 5 | 4.00% | 1 | 25.00% |
| Total | 125 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(thaw_bdev);
static int blkdev_writepage(struct page *page, struct writeback_control *wbc)
{
return block_write_full_page(page, blkdev_get_block, wbc);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 19 | 73.08% | 2 | 66.67% |
andrew morton | andrew morton | 7 | 26.92% | 1 | 33.33% |
| Total | 26 | 100.00% | 3 | 100.00% |
static int blkdev_readpage(struct file * file, struct page * page)
{
return block_read_full_page(page, blkdev_get_block);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 20 | 83.33% | 2 | 50.00% |
pre-git | pre-git | 4 | 16.67% | 2 | 50.00% |
| Total | 24 | 100.00% | 4 | 100.00% |
static int blkdev_readpages(struct file *file, struct address_space *mapping,
struct list_head *pages, unsigned nr_pages)
{
return mpage_readpages(mapping, pages, nr_pages, blkdev_get_block);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
akinobu mita | akinobu mita | 36 | 100.00% | 1 | 100.00% |
| Total | 36 | 100.00% | 1 | 100.00% |
static int blkdev_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{
return block_write_begin(mapping, pos, len, flags, pagep,
blkdev_get_block);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nick piggin | nick piggin | 28 | 53.85% | 1 | 16.67% |
linus torvalds | linus torvalds | 21 | 40.38% | 3 | 50.00% |
pre-git | pre-git | 2 | 3.85% | 1 | 16.67% |
christoph hellwig | christoph hellwig | 1 | 1.92% | 1 | 16.67% |
| Total | 52 | 100.00% | 6 | 100.00% |
static int blkdev_write_end(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned copied,
struct page *page, void *fsdata)
{
int ret;
ret = block_write_end(file, mapping, pos, len, copied, page, fsdata);
unlock_page(page);
put_page(page);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nick piggin | nick piggin | 46 | 66.67% | 1 | 25.00% |
linus torvalds | linus torvalds | 20 | 28.99% | 1 | 25.00% |
pre-git | pre-git | 2 | 2.90% | 1 | 25.00% |
kirill a. shutemov | kirill a. shutemov | 1 | 1.45% | 1 | 25.00% |
| Total | 69 | 100.00% | 4 | 100.00% |
/*
* private llseek:
* for a block special file file_inode(file)->i_size is zero
* so we compute the size by hand (just as in block_read/write above)
*/
static loff_t block_llseek(struct file *file, loff_t offset, int whence)
{
struct inode *bd_inode = bdev_file_inode(file);
loff_t retval;
inode_lock(bd_inode);
retval = fixed_size_llseek(file, offset, whence, i_size_read(bd_inode));
inode_unlock(bd_inode);
return retval;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 22 | 37.29% | 4 | 40.00% |
pre-git | pre-git | 19 | 32.20% | 1 | 10.00% |
al viro | al viro | 12 | 20.34% | 2 | 20.00% |
dan williams | dan williams | 3 | 5.08% | 1 | 10.00% |
linus torvalds | linus torvalds | 3 | 5.08% | 2 | 20.00% |
| Total | 59 | 100.00% | 10 | 100.00% |
int blkdev_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
{
struct inode *bd_inode = bdev_file_inode(filp);
struct block_device *bdev = I_BDEV(bd_inode);
int error;
error = filemap_write_and_wait_range(filp->f_mapping, start, end);
if (error)
return error;
/*
* There is no need to serialise calls to blkdev_issue_flush with
* i_mutex and doing so causes performance issues with concurrent
* O_SYNC writers to a block device.
*/
error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL);
if (error == -EOPNOTSUPP)
error = 0;
return error;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christoph hellwig | christoph hellwig | 29 | 32.95% | 1 | 9.09% |
rafael j. wysocki | rafael j. wysocki | 20 | 22.73% | 1 | 9.09% |
pre-git | pre-git | 13 | 14.77% | 3 | 27.27% |
anton blanchard | anton blanchard | 12 | 13.64% | 1 | 9.09% |
josef bacik | josef bacik | 6 | 6.82% | 1 | 9.09% |
andrew morton | andrew morton | 3 | 3.41% | 2 | 18.18% |
dan williams | dan williams | 3 | 3.41% | 1 | 9.09% |
dmitriy monakhov | dmitriy monakhov | 2 | 2.27% | 1 | 9.09% |
| Total | 88 | 100.00% | 11 | 100.00% |
EXPORT_SYMBOL(blkdev_fsync);
/**
* bdev_read_page() - Start reading a page from a block device
* @bdev: The device to read the page from
* @sector: The offset on the device to read the page to (need not be aligned)
* @page: The page to read
*
* On entry, the page should be locked. It will be unlocked when the page
* has been read. If the block driver implements rw_page synchronously,
* that will be true on exit from this function, but it need not be.
*
* Errors returned by this function are usually "soft", eg out of memory, or
* queue full; callers should try a different route to read this page rather
* than propagate an error back up the stack.
*
* Return: negative errno if an error occurs, 0 if submission was successful.
*/
int bdev_read_page(struct block_device *bdev, sector_t sector,
struct page *page)
{
const struct block_device_operations *ops = bdev->bd_disk->fops;
int result = -EOPNOTSUPP;
if (!ops->rw_page || bdev_get_integrity(bdev))
return result;
result = blk_queue_enter(bdev->bd_queue, false);
if (result)
return result;
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, READ);
blk_queue_exit(bdev->bd_queue);
return result;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
matthew wilcox | matthew wilcox | 58 | 58.59% | 1 | 25.00% |
dan williams | dan williams | 35 | 35.35% | 1 | 25.00% |
vishal verma | vishal verma | 5 | 5.05% | 1 | 25.00% |
christoph hellwig | christoph hellwig | 1 | 1.01% | 1 | 25.00% |
| Total | 99 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL_GPL(bdev_read_page);
/**
* bdev_write_page() - Start writing a page to a block device
* @bdev: The device to write the page to
* @sector: The offset on the device to write the page to (need not be aligned)
* @page: The page to write
* @wbc: The writeback_control for the write
*
* On entry, the page should be locked and not currently under writeback.
* On exit, if the write started successfully, the page will be unlocked and
* under writeback. If the write failed already (eg the driver failed to
* queue the page to the device), the page will still be locked. If the
* caller is a ->writepage implementation, it will need to unlock the page.
*
* Errors returned by this function are usually "soft", eg out of memory, or
* queue full; callers should try a different route to write this page rather
* than propagate an error back up the stack.
*
* Return: negative errno if an error occurs, 0 if submission was successful.
*/
int bdev_write_page(struct block_device *bdev, sector_t sector,
struct page *page, struct writeback_control *wbc)
{
int result;
int rw = (wbc->sync_mode == WB_SYNC_ALL) ? WRITE_SYNC : WRITE;
const struct block_device_operations *ops = bdev->bd_disk->fops;
if (!ops->rw_page || bdev_get_integrity(bdev))
return -EOPNOTSUPP;
result = blk_queue_enter(bdev->bd_queue, false);
if (result)
return result;
set_page_writeback(page);
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, rw);
if (result)
end_page_writeback(page);
else
unlock_page(page);
blk_queue_exit(bdev->bd_queue);
return result;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
matthew wilcox | matthew wilcox | 107 | 78.10% | 1 | 25.00% |
dan williams | dan williams | 24 | 17.52% | 1 | 25.00% |
vishal verma | vishal verma | 5 | 3.65% | 1 | 25.00% |
christoph hellwig | christoph hellwig | 1 | 0.73% | 1 | 25.00% |
| Total | 137 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL_GPL(bdev_write_page);
/**
* bdev_direct_access() - Get the address for directly-accessibly memory
* @bdev: The device containing the memory
* @dax: control and output parameters for ->direct_access
*
* If a block device is made up of directly addressable memory, this function
* will tell the caller the PFN and the address of the memory. The address
* may be directly dereferenced within the kernel without the need to call
* ioremap(), kmap() or similar. The PFN is suitable for inserting into
* page tables.
*
* Return: negative errno if an error occurs, otherwise the number of bytes
* accessible at this address.
*/
long bdev_direct_access(struct block_device *bdev, struct blk_dax_ctl *dax)
{
sector_t sector = dax->sector;
long avail, size = dax->size;
const struct block_device_operations *ops = bdev->bd_disk->fops;
/*
* The device driver is allowed to sleep, in order to make the
* memory directly accessible.
*/
might_sleep();
if (size < 0)
return size;
if (!ops->direct_access)
return -EOPNOTSUPP;
if ((sector + DIV_ROUND_UP(size, 512)) >
part_nr_sects_read(bdev->bd_part))
return -ERANGE;
sector += get_start_sect(bdev);
if (sector % (PAGE_SIZE / 512))
return -EINVAL;
avail = ops->direct_access(bdev, sector, &dax->addr, &dax->pfn, size);
if (!avail)
return -ERANGE;
if (avail > 0 && avail & ~PAGE_MASK)
return -ENXIO;
return min(avail, size);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
matthew wilcox | matthew wilcox | 128 | 76.65% | 2 | 40.00% |
dan williams | dan williams | 39 | 23.35% | 3 | 60.00% |
| Total | 167 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(bdev_direct_access);
/**
* bdev_dax_supported() - Check if the device supports dax for filesystem
* @sb: The superblock of the device
* @blocksize: The block size of the device
*
* This is a library function for filesystems to check if the block device
* can be mounted with dax option.
*
* Return: negative errno if unsupported, 0 if supported.
*/
int bdev_dax_supported(struct super_block *sb, int blocksize)
{
struct blk_dax_ctl dax = {
.sector = 0,
.size = PAGE_SIZE,
};
int err;
if (blocksize != PAGE_SIZE) {
vfs_msg(sb, KERN_ERR, "error: unsupported blocksize for dax");
return -EINVAL;
}
err = bdev_direct_access(sb->s_bdev, &dax);
if (err < 0) {
switch (err) {
case -EOPNOTSUPP:
vfs_msg(sb, KERN_ERR,
"error: device does not support dax");
break;
case -EINVAL:
vfs_msg(sb, KERN_ERR,
"error: unaligned partition for dax");
break;
default:
vfs_msg(sb, KERN_ERR,
"error: dax access failed (%d)", err);
}
return err;
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
toshi kani | toshi kani | 125 | 100.00% | 1 | 100.00% |
| Total | 125 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(bdev_dax_supported);
/**
* bdev_dax_capable() - Return if the raw device is capable for dax
* @bdev: The device for raw block device access
*/
bool bdev_dax_capable(struct block_device *bdev)
{
struct blk_dax_ctl dax = {
.size = PAGE_SIZE,
};
if (!IS_ENABLED(CONFIG_FS_DAX))
return false;
dax.sector = 0;
if (bdev_direct_access(bdev, &dax) < 0)
return false;
dax.sector = bdev->bd_part->nr_sects - (PAGE_SIZE / 512);
if (bdev_direct_access(bdev, &dax) < 0)
return false;
return true;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
toshi kani | toshi kani | 87 | 100.00% | 1 | 100.00% |
| Total | 87 | 100.00% | 1 | 100.00% |
/*
* pseudo-fs
*/
static __cacheline_aligned_in_smp DEFINE_SPINLOCK(bdev_lock);
static struct kmem_cache * bdev_cachep __read_mostly;
static struct inode *bdev_alloc_inode(struct super_block *sb)
{
struct bdev_inode *ei = kmem_cache_alloc(bdev_cachep, GFP_KERNEL);
if (!ei)
return NULL;
return &ei->vfs_inode;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 28 | 71.79% | 1 | 20.00% |
pre-git | pre-git | 4 | 10.26% | 1 | 20.00% |
andrew morton | andrew morton | 3 | 7.69% | 1 | 20.00% |
linus torvalds | linus torvalds | 3 | 7.69% | 1 | 20.00% |
christoph lameter | christoph lameter | 1 | 2.56% | 1 | 20.00% |
| Total | 39 | 100.00% | 5 | 100.00% |
static void bdev_i_callback(struct rcu_head *head)
{
struct inode *inode = container_of(head, struct inode, i_rcu);
struct bdev_inode *bdi = BDEV_I(inode);
kmem_cache_free(bdev_cachep, bdi);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nick piggin | nick piggin | 20 | 46.51% | 1 | 25.00% |
andrew morton | andrew morton | 11 | 25.58% | 1 | 25.00% |
al viro | al viro | 10 | 23.26% | 1 | 25.00% |
pre-git | pre-git | 2 | 4.65% | 1 | 25.00% |
| Total | 43 | 100.00% | 4 | 100.00% |
static void bdev_destroy_inode(struct inode *inode)
{
call_rcu(&inode->i_rcu, bdev_i_callback);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
nick piggin | nick piggin | 19 | 90.48% | 1 | 50.00% |
al viro | al viro | 2 | 9.52% | 1 | 50.00% |
| Total | 21 | 100.00% | 2 | 100.00% |
static void init_once(void *foo)
{
struct bdev_inode *ei = (struct bdev_inode *) foo;
struct block_device *bdev = &ei->bdev;
memset(bdev, 0, sizeof(*bdev));
mutex_init(&bdev->bd_mutex);
INIT_LIST_HEAD(&bdev->bd_inodes);
INIT_LIST_HEAD(&bdev->bd_list);
#ifdef CONFIG_SYSFS
INIT_LIST_HEAD(&bdev->bd_holder_disks);
#endif
inode_init_once(&ei->vfs_inode);
/* Initialize mutex for freeze. */
mutex_init(&bdev->bd_fsfreeze_mutex);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 57 | 57.58% | 1 | 16.67% |
pre-git | pre-git | 15 | 15.15% | 1 | 16.67% |
tejun heo | tejun heo | 13 | 13.13% | 1 | 16.67% |
takashi sato | takashi sato | 9 | 9.09% | 1 | 16.67% |
christoph lameter | christoph lameter | 3 | 3.03% | 1 | 16.67% |
arjan van de ven | arjan van de ven | 2 | 2.02% | 1 | 16.67% |
| Total | 99 | 100.00% | 6 | 100.00% |
static inline void __bd_forget(struct inode *inode)
{
list_del_init(&inode->i_devices);
inode->i_bdev = NULL;
inode->i_mapping = &inode->i_data;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 35 | 100.00% | 1 | 100.00% |
| Total | 35 | 100.00% | 1 | 100.00% |
static void bdev_evict_inode(struct inode *inode)
{
struct block_device *bdev = &BDEV_I(inode)->bdev;
struct list_head *p;
truncate_inode_pages_final(&inode->i_data);
invalidate_inode_buffers(inode); /* is it needed here? */
clear_inode(inode);
spin_lock(&bdev_lock);
while ( (p = bdev->bd_inodes.next) != &bdev->bd_inodes ) {
__bd_forget(list_entry(p, struct inode, i_devices));
}
list_del_init(&bdev->bd_list);
spin_unlock(&bdev_lock);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 98 | 98.00% | 2 | 50.00% |
jan kara | jan kara | 1 | 1.00% | 1 | 25.00% |
johannes weiner | johannes weiner | 1 | 1.00% | 1 | 25.00% |
| Total | 100 | 100.00% | 4 | 100.00% |
static const struct super_operations bdev_sops = {
.statfs = simple_statfs,
.alloc_inode = bdev_alloc_inode,
.destroy_inode = bdev_destroy_inode,
.drop_inode = generic_delete_inode,
.evict_inode = bdev_evict_inode,
};
static struct dentry *bd_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
struct dentry *dent;
dent = mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, BDEVFS_MAGIC);
if (dent)
dent->d_sb->s_iflags |= SB_I_CGROUPWB;
return dent;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 31 | 50.82% | 3 | 42.86% |
shaohua li | shaohua li | 22 | 36.07% | 1 | 14.29% |
pre-git | pre-git | 6 | 9.84% | 1 | 14.29% |
muthu kumar | muthu kumar | 1 | 1.64% | 1 | 14.29% |
linus torvalds | linus torvalds | 1 | 1.64% | 1 | 14.29% |
| Total | 61 | 100.00% | 7 | 100.00% |
static struct file_system_type bd_type = {
.name = "bdev",
.mount = bd_mount,
.kill_sb = kill_anon_super,
};
struct super_block *blockdev_superblock __read_mostly;
EXPORT_SYMBOL_GPL(blockdev_superblock);
void __init bdev_cache_init(void)
{
int err;
static struct vfsmount *bd_mnt;
bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode),
0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
SLAB_MEM_SPREAD|SLAB_ACCOUNT|SLAB_PANIC),
init_once);
err = register_filesystem(&bd_type);
if (err)
panic("Cannot register bdev pseudo-fs");
bd_mnt = kern_mount(&bd_type);
if (IS_ERR(bd_mnt))
panic("Cannot create bdev pseudo-fs");
blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 40 | 44.44% | 2 | 16.67% |
pre-git | pre-git | 26 | 28.89% | 2 | 16.67% |
andrew morton | andrew morton | 9 | 10.00% | 2 | 16.67% |
cheng renquan | cheng renquan | 5 | 5.56% | 1 | 8.33% |
paul jackson | paul jackson | 4 | 4.44% | 2 | 16.67% |
al viro | al viro | 3 | 3.33% | 1 | 8.33% |
vladimir davydov | vladimir davydov | 2 | 2.22% | 1 | 8.33% |
sergey senozhatsky | sergey senozhatsky | 1 | 1.11% | 1 | 8.33% |
| Total | 90 | 100.00% | 12 | 100.00% |
/*
* Most likely _very_ bad one - but then it's hardly critical for small
* /dev and can be fixed when somebody will need really large one.
* Keep in mind that it will be fed through icache hash function too.
*/
static inline unsigned long hash(dev_t dev)
{
return MAJOR(dev)+MINOR(dev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 11 | 50.00% | 1 | 33.33% |
al viro | al viro | 8 | 36.36% | 1 | 33.33% |
pre-git | pre-git | 3 | 13.64% | 1 | 33.33% |
| Total | 22 | 100.00% | 3 | 100.00% |
static int bdev_test(struct inode *inode, void *data)
{
return BDEV_I(inode)->bdev.bd_dev == *(dev_t *)data;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 25 | 78.12% | 1 | 50.00% |
pre-git | pre-git | 7 | 21.88% | 1 | 50.00% |
| Total | 32 | 100.00% | 2 | 100.00% |
static int bdev_set(struct inode *inode, void *data)
{
BDEV_I(inode)->bdev.bd_dev = *(dev_t *)data;
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 22 | 64.71% | 1 | 50.00% |
pre-git | pre-git | 12 | 35.29% | 1 | 50.00% |
| Total | 34 | 100.00% | 2 | 100.00% |
static LIST_HEAD(all_bdevs);
struct block_device *bdget(dev_t dev)
{
struct block_device *bdev;
struct inode *inode;
inode = iget5_locked(blockdev_superblock, hash(dev),
bdev_test, bdev_set, &dev);
if (!inode)
return NULL;
bdev = &BDEV_I(inode)->bdev;
if (inode->i_state & I_NEW) {
bdev->bd_contains = NULL;
bdev->bd_super = NULL;
bdev->bd_inode = inode;
bdev->bd_block_size = (1 << inode->i_blkbits);
bdev->bd_part_count = 0;
bdev->bd_invalidated = 0;
inode->i_mode = S_IFBLK;
inode->i_rdev = dev;
inode->i_bdev = bdev;
inode->i_data.a_ops = &def_blk_aops;
mapping_set_gfp_mask(&inode->i_data, GFP_USER);
spin_lock(&bdev_lock);
list_add(&bdev->bd_list, &all_bdevs);
spin_unlock(&bdev_lock);
unlock_new_inode(inode);
}
return bdev;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 62 | 35.03% | 4 | 26.67% |
linus torvalds | linus torvalds | 47 | 26.55% | 5 | 33.33% |
pre-git | pre-git | 45 | 25.42% | 2 | 13.33% |
andrew morton | andrew morton | 16 | 9.04% | 2 | 13.33% |
lachlan mcilroy | lachlan mcilroy | 6 | 3.39% | 1 | 6.67% |
cheng renquan | cheng renquan | 1 | 0.56% | 1 | 6.67% |
| Total | 177 | 100.00% | 15 | 100.00% |
EXPORT_SYMBOL(bdget);
/**
* bdgrab -- Grab a reference to an already referenced block device
* @bdev: Block device to grab a reference to.
*/
struct block_device *bdgrab(struct block_device *bdev)
{
ihold(bdev->bd_inode);
return bdev;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
alan jenkins | alan jenkins | 21 | 95.45% | 1 | 50.00% |
al viro | al viro | 1 | 4.55% | 1 | 50.00% |
| Total | 22 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(bdgrab);
long nr_blockdev_pages(void)
{
struct block_device *bdev;
long ret = 0;
spin_lock(&bdev_lock);
list_for_each_entry(bdev, &all_bdevs, bd_list) {
ret += bdev->bd_inode->i_mapping->nrpages;
}
spin_unlock(&bdev_lock);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 42 | 80.77% | 1 | 33.33% |
matthias kaehlcke | matthias kaehlcke | 6 | 11.54% | 1 | 33.33% |
al viro | al viro | 4 | 7.69% | 1 | 33.33% |
| Total | 52 | 100.00% | 3 | 100.00% |
void bdput(struct block_device *bdev)
{
iput(bdev->bd_inode);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 9 | 52.94% | 1 | 33.33% |
linus torvalds | linus torvalds | 8 | 47.06% | 2 | 66.67% |
| Total | 17 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(bdput);
static struct block_device *bd_acquire(struct inode *inode)
{
struct block_device *bdev;
spin_lock(&bdev_lock);
bdev = inode->i_bdev;
if (bdev) {
bdgrab(bdev);
spin_unlock(&bdev_lock);
return bdev;
}
spin_unlock(&bdev_lock);
bdev = bdget(inode->i_rdev);
if (bdev) {
spin_lock(&bdev_lock);
if (!inode->i_bdev) {
/*
* We take an additional reference to bd_inode,
* and it's released in clear_inode() of inode.
* So, we can access it via ->i_mapping always
* without igrab().
*/
bdgrab(bdev);
inode->i_bdev = bdev;
inode->i_mapping = bdev->bd_inode->i_mapping;
list_add(&inode->i_devices, &bdev->bd_inodes);
}
spin_unlock(&bdev_lock);
}
return bdev;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 90 | 69.23% | 3 | 33.33% |
andrew morton | andrew morton | 15 | 11.54% | 1 | 11.11% |
pre-git | pre-git | 12 | 9.23% | 1 | 11.11% |
hirofumi ogawa | hirofumi ogawa | 7 | 5.38% | 1 | 11.11% |
al viro | al viro | 4 | 3.08% | 2 | 22.22% |
ilya dryomov | ilya dryomov | 2 | 1.54% | 1 | 11.11% |
| Total | 130 | 100.00% | 9 | 100.00% |
/* Call when you free inode */
void bd_forget(struct inode *inode)
{
struct block_device *bdev = NULL;
spin_lock(&bdev_lock);
if (!sb_is_blkdev_sb(inode->i_sb))
bdev = inode->i_bdev;
__bd_forget(inode);
spin_unlock(&bdev_lock);
if (bdev)
bdput(bdev);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 28 | 47.46% | 2 | 33.33% |
hirofumi ogawa | hirofumi ogawa | 25 | 42.37% | 1 | 16.67% |
cheng renquan | cheng renquan | 4 | 6.78% | 1 | 16.67% |
pre-git | pre-git | 1 | 1.69% | 1 | 16.67% |
ilya dryomov | ilya dryomov | 1 | 1.69% | 1 | 16.67% |
| Total | 59 | 100.00% | 6 | 100.00% |
/**
* bd_may_claim - test whether a block device can be claimed
* @bdev: block device of interest
* @whole: whole block device containing @bdev, may equal @bdev
* @holder: holder trying to claim @bdev
*
* Test whether @bdev can be claimed by @holder.
*
* CONTEXT:
* spin_lock(&bdev_lock).
*
* RETURNS:
* %true if @bdev can be claimed, %false otherwise.
*/
static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
void *holder)
{
if (bdev->bd_holder == holder)
return true; /* already a holder */
else if (bdev->bd_holder != NULL)
return false; /* held by someone else */
else if (bdev->bd_contains == bdev)
return true; /* is a whole device which isn't held */
else if (whole->bd_holder == bd_may_claim)
return true; /* is a partition of a device that is being partitioned */
else if (whole->bd_holder != NULL)
return false; /* is a partition of a held device */
else
return true; /* is a partition of an un-held device */
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew morton | andrew morton | 40 | 44.94% | 1 | 25.00% |
tejun heo | tejun heo | 31 | 34.83% | 2 | 50.00% |
al viro | al viro | 18 | 20.22% | 1 | 25.00% |
| Total | 89 | 100.00% | 4 | 100.00% |
/**
* bd_prepare_to_claim - prepare to claim a block device
* @bdev: block device of interest
* @whole: the whole device containing @bdev, may equal @bdev
* @holder: holder trying to claim @bdev
*
* Prepare to claim @bdev. This function fails if @bdev is already
* claimed by another holder and waits if another claiming is in
* progress. This function doesn't actually claim. On successful
* return, the caller has ownership of bd_claiming and bd_holder[s].
*
* CONTEXT:
* spin_lock(&bdev_lock). Might release bdev_lock, sleep and regrab
* it multiple times.
*
* RETURNS:
* 0 if @bdev can be claimed, -EBUSY otherwise.
*/
static int bd_prepare_to_claim(struct block_device *bdev,
struct block_device *whole, void *holder)
{
retry:
/* if someone else claimed, fail */
if (!bd_may_claim(bdev, whole, holder))
return -EBUSY;
/* if claiming is already in progress, wait for it to finish */
if (whole->bd_claiming) {
wait_queue_head_t *wq = bit_waitqueue(&whole->bd_claiming, 0);
DEFINE_WAIT(wait);
prepare_to_wait(wq, &wait, TASK_UNINTERRUPTIBLE);
spin_unlock(&bdev_lock);
schedule();
finish_wait(wq, &wait);
spin_lock(&bdev_lock);
goto retry;
}
/* yay, all mine */
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 107 | 100.00% | 2 | 100.00% |
| Total | 107 | 100.00% | 2 | 100.00% |
/**
* bd_start_claiming - start claiming a block device
* @bdev: block device of interest
* @holder: holder trying to claim @bdev
*
* @bdev is about to be opened exclusively. Check @bdev can be opened
* exclusively and mark that an exclusive open is in progress. Each
* successful call to this function must be matched with a call to
* either bd_finish_claiming() or bd_abort_claiming() (which do not
* fail).
*
* This function is used to gain exclusive access to the block device
* without actually causing other exclusive open attempts to fail. It
* should be used when the open sequence itself requires exclusive
* access but may subsequently fail.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* Pointer to the block device containing @bdev on success, ERR_PTR()
* value on failure.
*/
static struct block_device *bd_start_claiming(struct block_device *bdev,
void *holder)
{
struct gendisk *disk;
struct block_device *whole;
int partno, err;
might_sleep();
/*
* @bdev might not have been initialized properly yet, look up
* and grab the outer block device the hard way.
*/
disk = get_gendisk(bdev->bd_dev, &partno);
if (!disk)
return ERR_PTR(-ENXIO);
/*
* Normally, @bdev should equal what's returned from bdget_disk()
* if partno is 0; however, some drivers (floppy) use multiple
* bdev's for the same physical device and @bdev may be one of the
* aliases. Keep @bdev if partno is 0. This means claimer
* tracking is broken for those devices but it has always been that
* way.
*/
if (partno)
whole = bdget_disk(disk, 0);
else
whole = bdgrab(bdev);
module_put(disk->fops->owner);
put_disk(disk);
if (!whole)
return ERR_PTR(-ENOMEM);
/* prepare to claim, if successful, mark claiming in progress */
spin_lock(&bdev_lock);
err = bd_prepare_to_claim(bdev, whole, holder);
if (err == 0) {
whole->bd_claiming = holder;
spin_unlock(&bdev_lock);
return whole;
} else {
spin_unlock(&bdev_lock);
bdput(whole);
return ERR_PTR(err);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 160 | 94.67% | 2 | 66.67% |
nick piggin | nick piggin | 9 | 5.33% | 1 | 33.33% |
| Total | 169 | 100.00% | 3 | 100.00% |
#ifdef CONFIG_SYSFS
struct bd_holder_disk {
struct list_head list;
struct gendisk *disk;
int refcnt;
};
static struct bd_holder_disk *bd_find_holder_disk(struct block_device *bdev,
struct gendisk *disk)
{
struct bd_holder_disk *holder;
list_for_each_entry(holder, &bdev->bd_holder_disks, list)
if (holder->disk == disk)
return holder;
return NULL;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 45 | 100.00% | 1 | 100.00% |
| Total | 45 | 100.00% | 1 | 100.00% |
static int add_symlink(struct kobject *from, struct kobject *to)
{
return sysfs_create_link(from, to, kobject_name(to));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 14 | 48.28% | 1 | 33.33% |
jun'ichi nomura | jun'ichi nomura | 12 | 41.38% | 1 | 33.33% |
andrew morton | andrew morton | 3 | 10.34% | 1 | 33.33% |
| Total | 29 | 100.00% | 3 | 100.00% |
static void del_symlink(struct kobject *from, struct kobject *to)
{
sysfs_remove_link(from, kobject_name(to));
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 14 | 53.85% | 1 | 50.00% |
jun'ichi nomura | jun'ichi nomura | 12 | 46.15% | 1 | 50.00% |
| Total | 26 | 100.00% | 2 | 100.00% |
/**
* bd_link_disk_holder - create symlinks between holding disk and slave bdev
* @bdev: the claimed slave bdev
* @disk: the holding disk
*
* DON'T USE THIS UNLESS YOU'RE ALREADY USING IT.
*
* This functions creates the following sysfs symlinks.
*
* - from "slaves" directory of the holder @disk to the claimed @bdev
* - from "holders" directory of the @bdev to the holder @disk
*
* For example, if /dev/dm-0 maps to /dev/sda and disk for dm-0 is
* passed to bd_link_disk_holder(), then:
*
* /sys/block/dm-0/slaves/sda --> /sys/block/sda
* /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
*
* The caller must have claimed @bdev before calling this function and
* ensure that both @bdev and @disk are valid during the creation and
* lifetime of these symlinks.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* 0 on success, -errno on failure.
*/
int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
{
struct bd_holder_disk *holder;
int ret = 0;
mutex_lock(&bdev->bd_mutex);
WARN_ON_ONCE(!bdev->bd_holder);
/* FIXME: remove the following once add_disk() handles errors */
if (WARN_ON(!disk->slave_dir || !bdev->bd_part->holder_dir))
goto out_unlock;
holder = bd_find_holder_disk(bdev, disk);
if (holder) {
holder->refcnt++;
goto out_unlock;
}
holder = kzalloc(sizeof(*holder), GFP_KERNEL);
if (!holder) {
ret = -ENOMEM;
goto out_unlock;
}
INIT_LIST_HEAD(&holder->list);
holder->disk = disk;
holder->refcnt = 1;
ret = add_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
if (ret)
goto out_free;
ret = add_symlink(bdev->bd_part->holder_dir, &disk_to_dev(disk)->kobj);
if (ret)
goto out_del;
/*
* bdev could be deleted beneath us which would implicitly destroy
* the holder directory. Hold on to it.
*/
kobject_get(bdev->bd_part->holder_dir);
list_add(&holder->list, &bdev->bd_holder_disks);
goto out_unlock;
out_del:
del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
out_free:
kfree(holder);
out_unlock:
mutex_unlock(&bdev->bd_mutex);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 181 | 72.40% | 6 | 66.67% |
nick piggin | nick piggin | 34 | 13.60% | 1 | 11.11% |
jun'ichi nomura | jun'ichi nomura | 28 | 11.20% | 1 | 11.11% |
al viro | al viro | 7 | 2.80% | 1 | 11.11% |
| Total | 250 | 100.00% | 9 | 100.00% |
EXPORT_SYMBOL_GPL(bd_link_disk_holder);
/**
* bd_unlink_disk_holder - destroy symlinks created by bd_link_disk_holder()
* @bdev: the calimed slave bdev
* @disk: the holding disk
*
* DON'T USE THIS UNLESS YOU'RE ALREADY USING IT.
*
* CONTEXT:
* Might sleep.
*/
void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk)
{
struct bd_holder_disk *holder;
mutex_lock(&bdev->bd_mutex);
holder = bd_find_holder_disk(bdev, disk);
if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) {
del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj);
del_symlink(bdev->bd_part->holder_dir,
&disk_to_dev(disk)->kobj);
kobject_put(bdev->bd_part->holder_dir);
list_del_init(&holder->list);
kfree(holder);
}
mutex_unlock(&bdev->bd_mutex);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 82 | 68.91% | 4 | 57.14% |
al viro | al viro | 15 | 12.61% | 1 | 14.29% |
jun'ichi nomura | jun'ichi nomura | 15 | 12.61% | 1 | 14.29% |
andrew morton | andrew morton | 7 | 5.88% | 1 | 14.29% |
| Total | 119 | 100.00% | 7 | 100.00% |
EXPORT_SYMBOL_GPL(bd_unlink_disk_holder);
#endif
/**
* flush_disk - invalidates all buffer-cache entries on a disk
*
* @bdev: struct block device to be flushed
* @kill_dirty: flag to guide handling of dirty inodes
*
* Invalidates all buffer-cache entries on a disk. It should be called
* when a disk has been changed -- either by a media change or online
* resize.
*/
static void flush_disk(struct block_device *bdev, bool kill_dirty)
{
if (__invalidate_device(bdev, kill_dirty)) {
printk(KERN_WARNING "VFS: busy inodes on changed media or "
"resized disk %s\n",
bdev->bd_disk ? bdev->bd_disk->disk_name : "");
}
if (!bdev->bd_disk)
return;
if (disk_part_scan_enabled(bdev->bd_disk))
bdev->bd_invalidated = 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew patterson | andrew patterson | 32 | 47.76% | 1 | 20.00% |
jun'ichi nomura | jun'ichi nomura | 18 | 26.87% | 1 | 20.00% |
dmitriy monakhov | dmitriy monakhov | 11 | 16.42% | 1 | 20.00% |
neil brown | neil brown | 5 | 7.46% | 1 | 20.00% |
tejun heo | tejun heo | 1 | 1.49% | 1 | 20.00% |
| Total | 67 | 100.00% | 5 | 100.00% |
/**
* check_disk_size_change - checks for disk size change and adjusts bdev size.
* @disk: struct gendisk to check
* @bdev: struct bdev to adjust.
*
* This routine checks to see if the bdev size does not match the disk size
* and adjusts it if it differs.
*/
void check_disk_size_change(struct gendisk *disk, struct block_device *bdev)
{
loff_t disk_size, bdev_size;
disk_size = (loff_t)get_capacity(disk) << 9;
bdev_size = i_size_read(bdev->bd_inode);
if (disk_size != bdev_size) {
printk(KERN_INFO
"%s: detected capacity change from %lld to %lld\n",
disk->disk_name, bdev_size, disk_size);
i_size_write(bdev->bd_inode, disk_size);
flush_disk(bdev, false);
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew patterson | andrew patterson | 50 | 63.29% | 2 | 33.33% |
jun'ichi nomura | jun'ichi nomura | 22 | 27.85% | 1 | 16.67% |
dmitriy monakhov | dmitriy monakhov | 3 | 3.80% | 1 | 16.67% |
tejun heo | tejun heo | 2 | 2.53% | 1 | 16.67% |
neil brown | neil brown | 2 | 2.53% | 1 | 16.67% |
| Total | 79 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL(check_disk_size_change);
/**
* revalidate_disk - wrapper for lower-level driver's revalidate_disk call-back
* @disk: struct gendisk to be revalidated
*
* This routine is a wrapper for lower-level driver's revalidate_disk
* call-backs. It is used to do common pre and post operations needed
* for all revalidate_disk operations.
*/
int revalidate_disk(struct gendisk *disk)
{
struct block_device *bdev;
int ret = 0;
if (disk->fops->revalidate_disk)
ret = disk->fops->revalidate_disk(disk);
blk_integrity_revalidate(disk);
bdev = bdget_disk(disk, 0);
if (!bdev)
return ret;
mutex_lock(&bdev->bd_mutex);
check_disk_size_change(disk, bdev);
bdev->bd_invalidated = 0;
mutex_unlock(&bdev->bd_mutex);
bdput(bdev);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
andrew patterson | andrew patterson | 58 | 59.18% | 2 | 33.33% |
jun'ichi nomura | jun'ichi nomura | 27 | 27.55% | 1 | 16.67% |
mitsunari shigeo | mitsunari shigeo | 6 | 6.12% | 1 | 16.67% |
martin k. petersen | martin k. petersen | 5 | 5.10% | 1 | 16.67% |
tejun heo | tejun heo | 2 | 2.04% | 1 | 16.67% |
| Total | 98 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL(revalidate_disk);
/*
* This routine checks whether a removable media has been changed,
* and invalidates all buffer-cache-entries in that case. This
* is a relatively slow routine, so we have to try to minimize using
* it. Thus it is called only upon a 'mount' or 'open'. This
* is the best way of combining speed and utility, I think.
* People changing diskettes in the middle of an operation deserve
* to lose :-)
*/
int check_disk_change(struct block_device *bdev)
{
struct gendisk *disk = bdev->bd_disk;
const struct block_device_operations *bdops = disk->fops;
unsigned int events;
events = disk_clear_events(disk, DISK_EVENT_MEDIA_CHANGE |
DISK_EVENT_EJECT_REQUEST);
if (!(events & DISK_EVENT_MEDIA_CHANGE))
return 0;
flush_disk(bdev, true);
if (bdops->revalidate_disk)
bdops->revalidate_disk(bdev->bd_disk);
return 1;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 32 | 39.51% | 6 | 42.86% |
tejun heo | tejun heo | 18 | 22.22% | 1 | 7.14% |
jun'ichi nomura | jun'ichi nomura | 17 | 20.99% | 1 | 7.14% |
pre-git | pre-git | 10 | 12.35% | 3 | 21.43% |
neil brown | neil brown | 2 | 2.47% | 1 | 7.14% |
andrew patterson | andrew patterson | 1 | 1.23% | 1 | 7.14% |
alexey dobriyan | alexey dobriyan | 1 | 1.23% | 1 | 7.14% |
| Total | 81 | 100.00% | 14 | 100.00% |
EXPORT_SYMBOL(check_disk_change);
void bd_set_size(struct block_device *bdev, loff_t size)
{
unsigned bsize = bdev_logical_block_size(bdev);
inode_lock(bdev->bd_inode);
i_size_write(bdev->bd_inode, size);
inode_unlock(bdev->bd_inode);
while (bsize < PAGE_SIZE) {
if (size & bsize)
break;
bsize <<= 1;
}
bdev->bd_block_size = bsize;
bdev->bd_inode->i_blkbits = blksize_bits(bsize);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 44 | 55.00% | 2 | 33.33% |
jun'ichi nomura | jun'ichi nomura | 18 | 22.50% | 1 | 16.67% |
guo chao | guo chao | 16 | 20.00% | 1 | 16.67% |
kirill a. shutemov | kirill a. shutemov | 1 | 1.25% | 1 | 16.67% |
martin k. petersen | martin k. petersen | 1 | 1.25% | 1 | 16.67% |
| Total | 80 | 100.00% | 6 | 100.00% |
EXPORT_SYMBOL(bd_set_size);
static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
/*
* bd_mutex locking:
*
* mutex_lock(part->bd_mutex)
* mutex_lock_nested(whole->bd_mutex, 1)
*/
static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
{
struct gendisk *disk;
struct module *owner;
int ret;
int partno;
int perm = 0;
if (mode & FMODE_READ)
perm |= MAY_READ;
if (mode & FMODE_WRITE)
perm |= MAY_WRITE;
/*
* hooks: /n/, see "layering violations".
*/
if (!for_part) {
ret = devcgroup_inode_permission(bdev->bd_inode, perm);
if (ret != 0) {
bdput(bdev);
return ret;
}
}
restart:
ret = -ENXIO;
disk = get_gendisk(bdev->bd_dev, &partno);
if (!disk)
goto out;
owner = disk->fops->owner;
disk_block_events(disk);
mutex_lock_nested(&bdev->bd_mutex, for_part);
if (!bdev->bd_openers) {
bdev->bd_disk = disk;
bdev->bd_queue = disk->queue;
bdev->bd_contains = bdev;
if (IS_ENABLED(CONFIG_BLK_DEV_DAX) && disk->fops->direct_access)
bdev->bd_inode->i_flags = S_DAX;
else
bdev->bd_inode->i_flags = 0;
if (!partno) {
ret = -ENXIO;
bdev->bd_part = disk_get_part(disk, partno);
if (!bdev->bd_part)
goto out_clear;
ret = 0;
if (disk->fops->open) {
ret = disk->fops->open(bdev, mode);
if (ret == -ERESTARTSYS) {
/* Lost a race with 'disk' being
* deleted, try again.
* See md.c
*/
disk_put_part(bdev->bd_part);
bdev->bd_part = NULL;
bdev->bd_disk = NULL;
bdev->bd_queue = NULL;
mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk);
put_disk(disk);
module_put(owner);
goto restart;
}
}
if (!ret) {
bd_set_size(bdev,(loff_t)get_capacity(disk)<<9);
if (!bdev_dax_capable(bdev))
bdev->bd_inode->i_flags &= ~S_DAX;
}
/*
* If the device is invalidated, rescan partition
* if open succeeded or failed with -ENOMEDIUM.
* The latter is necessary to prevent ghost
* partitions on a removed medium.
*/
if (bdev->bd_invalidated) {
if (!ret)
rescan_partitions(disk, bdev);
else if (ret == -ENOMEDIUM)
invalidate_partitions(disk, bdev);
}
if (ret)
goto out_clear;
} else {
struct block_device *whole;
whole = bdget_disk(disk, 0);
ret = -ENOMEM;
if (!whole)
goto out_clear;
BUG_ON(for_part);
ret = __blkdev_get(whole, mode, 1);
if (ret)
goto out_clear;
bdev->bd_contains = whole;
bdev->bd_part = disk_get_part(disk, partno);
if (!(disk->flags & GENHD_FL_UP) ||
!bdev->bd_part || !bdev->bd_part->nr_sects) {
ret = -ENXIO;
goto out_clear;
}
bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9);
if (!bdev_dax_capable(bdev))
bdev->bd_inode->i_flags &= ~S_DAX;
}
} else {
if (bdev->bd_contains == bdev) {
ret = 0;
if (bdev->bd_disk->fops->open)
ret = bdev->bd_disk->fops->open(bdev, mode);
/* the same as first opener case, read comment there */
if (bdev->bd_invalidated) {
if (!ret)
rescan_partitions(bdev->bd_disk, bdev);
else if (ret == -ENOMEDIUM)
invalidate_partitions(bdev->bd_disk, bdev);
}
if (ret)
goto out_unlock_bdev;
}
/* only one opener holds refs to the module and disk */
put_disk(disk);
module_put(owner);
}
bdev->bd_openers++;
if (for_part)
bdev->bd_part_count++;
mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk);
return 0;
out_clear:
disk_put_part(bdev->bd_part);
bdev->bd_disk = NULL;
bdev->bd_part = NULL;
bdev->bd_queue = NULL;
if (bdev != bdev->bd_contains)
__blkdev_put(bdev->bd_contains, mode, 1);
bdev->bd_contains = NULL;
out_unlock_bdev:
mutex_unlock(&bdev->bd_mutex);
disk_unblock_events(disk);
put_disk(disk);
module_put(owner);
out:
bdput(bdev);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 166 | 21.90% | 7 | 12.73% |
peter zijlstra | peter zijlstra | 156 | 20.58% | 3 | 5.45% |
jun'ichi nomura | jun'ichi nomura | 131 | 17.28% | 5 | 9.09% |
al viro | al viro | 85 | 11.21% | 12 | 21.82% |
neil brown | neil brown | 59 | 7.78% | 3 | 5.45% |
dan williams | dan williams | 41 | 5.41% | 2 | 3.64% |
andrew morton | andrew morton | 24 | 3.17% | 6 | 10.91% |
andi kleen | andi kleen | 20 | 2.64% | 1 | 1.82% |
pavel emelianov | pavel emelianov | 17 | 2.24% | 1 | 1.82% |
jeff moyer | jeff moyer | 13 | 1.72% | 1 | 1.82% |
matthew wilcox | matthew wilcox | 10 | 1.32% | 1 | 1.82% |
ingo molnar | ingo molnar | 9 | 1.19% | 1 | 1.82% |
linus torvalds | linus torvalds | 6 | 0.79% | 4 | 7.27% |
johannes weiner | johannes weiner | 5 | 0.66% | 1 | 1.82% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 3 | 0.40% | 1 | 1.82% |
andrew patterson | andrew patterson | 3 | 0.40% | 1 | 1.82% |
chris wright | chris wright | 3 | 0.40% | 1 | 1.82% |
dave chinner | dave chinner | 2 | 0.26% | 1 | 1.82% |
dan carpenter | dan carpenter | 2 | 0.26% | 1 | 1.82% |
toshi kani | toshi kani | 2 | 0.26% | 1 | 1.82% |
arnd bergmann | arnd bergmann | 1 | 0.13% | 1 | 1.82% |
| Total | 758 | 100.00% | 55 | 100.00% |
/**
* blkdev_get - open a block device
* @bdev: block_device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open @bdev with @mode. If @mode includes %FMODE_EXCL, @bdev is
* open with exclusive access. Specifying %FMODE_EXCL with %NULL
* @holder is invalid. Exclusive opens may nest for the same @holder.
*
* On success, the reference count of @bdev is unchanged. On failure,
* @bdev is put.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* 0 on success, -errno on failure.
*/
int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
{
struct block_device *whole = NULL;
int res;
WARN_ON_ONCE((mode & FMODE_EXCL) && !holder);
if ((mode & FMODE_EXCL) && holder) {
whole = bd_start_claiming(bdev, holder);
if (IS_ERR(whole)) {
bdput(bdev);
return PTR_ERR(whole);
}
}
res = __blkdev_get(bdev, mode, 0);
if (whole) {
struct gendisk *disk = whole->bd_disk;
/* finish claiming */
mutex_lock(&bdev->bd_mutex);
spin_lock(&bdev_lock);
if (!res) {
BUG_ON(!bd_may_claim(bdev, whole, holder));
/*
* Note that for a whole device bd_holders
* will be incremented twice, and bd_holder
* will be set to bd_may_claim before being
* set to holder
*/
whole->bd_holders++;
whole->bd_holder = bd_may_claim;
bdev->bd_holders++;
bdev->bd_holder = holder;
}
/* tell others that we're done */
BUG_ON(whole->bd_claiming != holder);
whole->bd_claiming = NULL;
wake_up_bit(&whole->bd_claiming, 0);
spin_unlock(&bdev_lock);
/*
* Block event polling for write claims if requested. Any
* write holder makes the write_holder state stick until
* all are released. This is good enough and tracking
* individual writeable reference is too fragile given the
* way @mode is used in blkdev_get/put().
*/
if (!res && (mode & FMODE_WRITE) && !bdev->bd_write_holder &&
(disk->flags & GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE)) {
bdev->bd_write_holder = true;
disk_block_events(disk);
}
mutex_unlock(&bdev->bd_mutex);
bdput(whole);
}
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 158 | 63.20% | 7 | 31.82% |
peter zijlstra | peter zijlstra | 32 | 12.80% | 1 | 4.55% |
al viro | al viro | 18 | 7.20% | 7 | 31.82% |
neil brown | neil brown | 17 | 6.80% | 1 | 4.55% |
linus torvalds | linus torvalds | 11 | 4.40% | 3 | 13.64% |
dave chinner | dave chinner | 5 | 2.00% | 1 | 4.55% |
andrew morton | andrew morton | 5 | 2.00% | 1 | 4.55% |
pre-git | pre-git | 4 | 1.60% | 1 | 4.55% |
| Total | 250 | 100.00% | 22 | 100.00% |
EXPORT_SYMBOL(blkdev_get);
/**
* blkdev_get_by_path - open a block device by name
* @path: path to the block device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open the blockdevice described by the device file at @path. @mode
* and @holder are identical to blkdev_get().
*
* On success, the returned block_device has reference count of one.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* Pointer to block_device on success, ERR_PTR(-errno) on failure.
*/
struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
void *holder)
{
struct block_device *bdev;
int err;
bdev = lookup_bdev(path);
if (IS_ERR(bdev))
return bdev;
err = blkdev_get(bdev, mode, holder);
if (err)
return ERR_PTR(err);
if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) {
blkdev_put(bdev, mode);
return ERR_PTR(-EACCES);
}
return bdev;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 61 | 62.89% | 1 | 33.33% |
chuck ebbert | chuck ebbert | 29 | 29.90% | 1 | 33.33% |
peter zijlstra | peter zijlstra | 7 | 7.22% | 1 | 33.33% |
| Total | 97 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL(blkdev_get_by_path);
/**
* blkdev_get_by_dev - open a block device by device number
* @dev: device number of block device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open the blockdevice described by device number @dev. @mode and
* @holder are identical to blkdev_get().
*
* Use it ONLY if you really do not have anything better - i.e. when
* you are behind a truly sucky interface and all you are given is a
* device number. _Never_ to be used for internal purposes. If you
* ever need it - reconsider your API.
*
* On success, the returned block_device has reference count of one.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* Pointer to block_device on success, ERR_PTR(-errno) on failure.
*/
struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)
{
struct block_device *bdev;
int err;
bdev = bdget(dev);
if (!bdev)
return ERR_PTR(-ENOMEM);
err = blkdev_get(bdev, mode, holder);
if (err)
return ERR_PTR(err);
return bdev;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 51 | 75.00% | 1 | 25.00% |
neil brown | neil brown | 13 | 19.12% | 1 | 25.00% |
peter zijlstra | peter zijlstra | 3 | 4.41% | 1 | 25.00% |
al viro | al viro | 1 | 1.47% | 1 | 25.00% |
| Total | 68 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(blkdev_get_by_dev);
static int blkdev_open(struct inode * inode, struct file * filp)
{
struct block_device *bdev;
/*
* Preserve backwards compatibility and allow large file access
* even if userspace doesn't ask for it explicitly. Some mkfs
* binary needs it. We might want to drop this workaround
* during an unstable branch.
*/
filp->f_flags |= O_LARGEFILE;
if (filp->f_flags & O_NDELAY)
filp->f_mode |= FMODE_NDELAY;
if (filp->f_flags & O_EXCL)
filp->f_mode |= FMODE_EXCL;
if ((filp->f_flags & O_ACCMODE) == 3)
filp->f_mode |= FMODE_WRITE_IOCTL;
bdev = bd_acquire(inode);
if (bdev == NULL)
return -ENOMEM;
filp->f_mapping = bdev->bd_inode->i_mapping;
return blkdev_get(bdev, filp->f_mode, filp);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 61 | 53.98% | 2 | 33.33% |
peter zijlstra | peter zijlstra | 34 | 30.09% | 1 | 16.67% |
pavel emelianov | pavel emelianov | 10 | 8.85% | 1 | 16.67% |
ingo molnar | ingo molnar | 7 | 6.19% | 1 | 16.67% |
tejun heo | tejun heo | 1 | 0.88% | 1 | 16.67% |
| Total | 113 | 100.00% | 6 | 100.00% |
static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
{
struct gendisk *disk = bdev->bd_disk;
struct block_device *victim = NULL;
mutex_lock_nested(&bdev->bd_mutex, for_part);
if (for_part)
bdev->bd_part_count--;
if (!--bdev->bd_openers) {
WARN_ON_ONCE(bdev->bd_holders);
sync_blockdev(bdev);
kill_bdev(bdev);
bdev_write_inode(bdev);
/*
* Detaching bdev inode from its wb in __destroy_inode()
* is too late: the queue which embeds its bdi (along with
* root wb) can be gone as soon as we put_disk() below.
*/
inode_detach_wb(bdev->bd_inode);
}
if (bdev->bd_contains == bdev) {
if (disk->fops->release)
disk->fops->release(disk, mode);
}
if (!bdev->bd_openers) {
struct module *owner = disk->fops->owner;
disk_put_part(bdev->bd_part);
bdev->bd_part = NULL;
bdev->bd_disk = NULL;
if (bdev != bdev->bd_contains)
victim = bdev->bd_contains;
bdev->bd_contains = NULL;
put_disk(disk);
module_put(owner);
}
mutex_unlock(&bdev->bd_mutex);
bdput(bdev);
if (victim)
__blkdev_put(victim, mode, 1);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
peter zijlstra | peter zijlstra | 140 | 64.81% | 1 | 9.09% |
neil brown | neil brown | 37 | 17.13% | 2 | 18.18% |
tejun heo | tejun heo | 18 | 8.33% | 3 | 27.27% |
al viro | al viro | 8 | 3.70% | 3 | 27.27% |
ilya dryomov | ilya dryomov | 8 | 3.70% | 1 | 9.09% |
christoph hellwig | christoph hellwig | 5 | 2.31% | 1 | 9.09% |
| Total | 216 | 100.00% | 11 | 100.00% |
void blkdev_put(struct block_device *bdev, fmode_t mode)
{
mutex_lock(&bdev->bd_mutex);
if (mode & FMODE_EXCL) {
bool bdev_free;
/*
* Release a claim on the device. The holder fields
* are protected with bdev_lock. bd_mutex is to
* synchronize disk_holder unlinking.
*/
spin_lock(&bdev_lock);
WARN_ON_ONCE(--bdev->bd_holders < 0);
WARN_ON_ONCE(--bdev->bd_contains->bd_holders < 0);
/* bd_contains might point to self, check in a separate step */
if ((bdev_free = !bdev->bd_holders))
bdev->bd_holder = NULL;
if (!bdev->bd_contains->bd_holders)
bdev->bd_contains->bd_holder = NULL;
spin_unlock(&bdev_lock);
/*
* If this was the last claim, remove holder link and
* unblock evpoll if it was a write holder.
*/
if (bdev_free && bdev->bd_write_holder) {
disk_unblock_events(bdev->bd_disk);
bdev->bd_write_holder = false;
}
}
/*
* Trigger event checking and tell drivers to flush MEDIA_CHANGE
* event. This is to ensure detection of media removal commanded
* from userland - e.g. eject(1).
*/
disk_flush_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE);
mutex_unlock(&bdev->bd_mutex);
__blkdev_put(bdev, mode, 0);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 120 | 78.43% | 5 | 55.56% |
neil brown | neil brown | 15 | 9.80% | 1 | 11.11% |
peter zijlstra | peter zijlstra | 11 | 7.19% | 1 | 11.11% |
al viro | al viro | 7 | 4.58% | 2 | 22.22% |
| Total | 153 | 100.00% | 9 | 100.00% |
EXPORT_SYMBOL(blkdev_put);
static int blkdev_close(struct inode * inode, struct file * filp)
{
struct block_device *bdev = I_BDEV(bdev_file_inode(filp));
blkdev_put(bdev, filp->f_mode);
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 19 | 46.34% | 1 | 20.00% |
andrew morton | andrew morton | 12 | 29.27% | 1 | 20.00% |
al viro | al viro | 7 | 17.07% | 2 | 40.00% |
dan williams | dan williams | 3 | 7.32% | 1 | 20.00% |
| Total | 41 | 100.00% | 5 | 100.00% |
static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg)
{
struct block_device *bdev = I_BDEV(bdev_file_inode(file));
fmode_t mode = file->f_mode;
/*
* O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have
* to updated it before every ioctl.
*/
if (file->f_flags & O_NDELAY)
mode |= FMODE_NDELAY;
else
mode &= ~FMODE_NDELAY;
return blkdev_ioctl(bdev, mode, cmd, arg);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 30 | 43.48% | 1 | 20.00% |
andrew morton | andrew morton | 27 | 39.13% | 1 | 20.00% |
christoph hellwig | christoph hellwig | 8 | 11.59% | 1 | 20.00% |
dan williams | dan williams | 3 | 4.35% | 1 | 20.00% |
arnd bergmann | arnd bergmann | 1 | 1.45% | 1 | 20.00% |
| Total | 69 | 100.00% | 5 | 100.00% |
/*
* Write data to the block device. Only intended for the block device itself
* and the raw driver which basically is a fake block device.
*
* Does not take i_mutex for the write and thus is not for general purpose
* use.
*/
ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
{
struct file *file = iocb->ki_filp;
struct inode *bd_inode = bdev_file_inode(file);
loff_t size = i_size_read(bd_inode);
struct blk_plug plug;
ssize_t ret;
if (bdev_read_only(I_BDEV(bd_inode)))
return -EPERM;
if (!iov_iter_count(from))
return 0;
if (iocb->ki_pos >= size)
return -ENOSPC;
iov_iter_truncate(from, size - iocb->ki_pos);
blk_start_plug(&plug);
ret = __generic_file_write_iter(iocb, from);
if (ret > 0)
ret = generic_write_sync(iocb, ret);
blk_finish_plug(&plug);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 68 | 50.00% | 3 | 37.50% |
christoph hellwig | christoph hellwig | 49 | 36.03% | 3 | 37.50% |
ma jianpeng | ma jianpeng | 16 | 11.76% | 1 | 12.50% |
dan williams | dan williams | 3 | 2.21% | 1 | 12.50% |
| Total | 136 | 100.00% | 8 | 100.00% |
EXPORT_SYMBOL_GPL(blkdev_write_iter);
ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct file *file = iocb->ki_filp;
struct inode *bd_inode = bdev_file_inode(file);
loff_t size = i_size_read(bd_inode);
loff_t pos = iocb->ki_pos;
if (pos >= size)
return 0;
size -= pos;
iov_iter_truncate(to, size);
return generic_file_read_iter(iocb, to);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
linus torvalds | linus torvalds | 60 | 77.92% | 1 | 25.00% |
al viro | al viro | 14 | 18.18% | 2 | 50.00% |
dan williams | dan williams | 3 | 3.90% | 1 | 25.00% |
| Total | 77 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL_GPL(blkdev_read_iter);
/*
* Try to release a page associated with block device when the system
* is under memory pressure.
*/
static int blkdev_releasepage(struct page *page, gfp_t wait)
{
struct super_block *super = BDEV_I(page->mapping->host)->bdev.bd_super;
if (super && super->s_op->bdev_try_to_free_page)
return super->s_op->bdev_try_to_free_page(super, page, wait);
return try_to_free_buffers(page);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
theodore tso | theodore tso | 62 | 100.00% | 1 | 100.00% |
| Total | 62 | 100.00% | 1 | 100.00% |
static int blkdev_writepages(struct address_space *mapping,
struct writeback_control *wbc)
{
if (dax_mapping(mapping)) {
struct block_device *bdev = I_BDEV(mapping->host);
return dax_writeback_mapping_range(mapping, bdev, wbc);
}
return generic_writepages(mapping, wbc);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
ross zwisler | ross zwisler | 55 | 100.00% | 1 | 100.00% |
| Total | 55 | 100.00% | 1 | 100.00% |
static const struct address_space_operations def_blk_aops = {
.readpage = blkdev_readpage,
.readpages = blkdev_readpages,
.writepage = blkdev_writepage,
.write_begin = blkdev_write_begin,
.write_end = blkdev_write_end,
.writepages = blkdev_writepages,
.releasepage = blkdev_releasepage,
.direct_IO = blkdev_direct_IO,
.is_dirty_writeback = buffer_check_dirty_writeback,
};
const struct file_operations def_blk_fops = {
.open = blkdev_open,
.release = blkdev_close,
.llseek = block_llseek,
.read_iter = blkdev_read_iter,
.write_iter = blkdev_write_iter,
.mmap = generic_file_mmap,
.fsync = blkdev_fsync,
.unlocked_ioctl = block_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_blkdev_ioctl,
#endif
.splice_read = generic_file_splice_read,
.splice_write = iter_file_splice_write,
};
int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg)
{
int res;
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
res = blkdev_ioctl(bdev, 0, cmd, arg);
set_fs(old_fs);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
al viro | al viro | 52 | 100.00% | 2 | 100.00% |
| Total | 52 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(ioctl_by_bdev);
/**
* lookup_bdev - lookup a struct block_device by name
* @pathname: special file representing the block device
*
* Get a reference to the blockdevice at @pathname in the current
* namespace if possible and return it. Return ERR_PTR(error)
* otherwise.
*/
struct block_device *lookup_bdev(const char *pathname)
{
struct block_device *bdev;
struct inode *inode;
struct path path;
int error;
if (!pathname || !*pathname)
return ERR_PTR(-EINVAL);
error = kern_path(pathname, LOOKUP_FOLLOW, &path);
if (error)
return ERR_PTR(error);
inode = d_backing_inode(path.dentry);
error = -ENOTBLK;
if (!S_ISBLK(inode->i_mode))
goto fail;
error = -EACCES;
if (path.mnt->mnt_flags & MNT_NODEV)
goto fail;
error = -ENOMEM;
bdev = bd_acquire(inode);
if (!bdev)
goto fail;
out:
path_put(&path);
return bdev;
fail:
bdev = ERR_PTR(error);
goto out;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
christoph hellwig | christoph hellwig | 131 | 84.52% | 2 | 28.57% |
al viro | al viro | 8 | 5.16% | 1 | 14.29% |
andrew morton | andrew morton | 7 | 4.52% | 1 | 14.29% |
jan blunck | jan blunck | 6 | 3.87% | 2 | 28.57% |
david howells | david howells | 3 | 1.94% | 1 | 14.29% |
| Total | 155 | 100.00% | 7 | 100.00% |
EXPORT_SYMBOL(lookup_bdev);
int __invalidate_device(struct block_device *bdev, bool kill_dirty)
{
struct super_block *sb = get_super(bdev);
int res = 0;
if (sb) {
/*
* no need to lock the super, get_super holds the
* read mutex so the filesystem cannot go away
* under us (->put_super runs with the write lock
* hold).
*/
shrink_dcache_sb(sb);
res = invalidate_inodes(sb, kill_dirty);
drop_super(sb);
}
invalidate_bdev(bdev);
return res;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
david howells | david howells | 57 | 91.94% | 1 | 50.00% |
neil brown | neil brown | 5 | 8.06% | 1 | 50.00% |
| Total | 62 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(__invalidate_device);
void iterate_bdevs(void (*func)(struct block_device *, void *), void *arg)
{
struct inode *inode, *old_inode = NULL;
spin_lock(&blockdev_superblock->s_inode_list_lock);
list_for_each_entry(inode, &blockdev_superblock->s_inodes, i_sb_list) {
struct address_space *mapping = inode->i_mapping;
spin_lock(&inode->i_lock);
if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW) ||
mapping->nrpages == 0) {
spin_unlock(&inode->i_lock);
continue;
}
__iget(inode);
spin_unlock(&inode->i_lock);
spin_unlock(&blockdev_superblock->s_inode_list_lock);
/*
* We hold a reference to 'inode' so it couldn't have been
* removed from s_inodes list while we dropped the
* s_inode_list_lock We cannot iput the inode now as we can
* be holding the last reference and we cannot iput it under
* s_inode_list_lock. So we keep the reference and iput it
* later.
*/
iput(old_inode);
old_inode = inode;
func(I_BDEV(inode), arg);
spin_lock(&blockdev_superblock->s_inode_list_lock);
}
spin_unlock(&blockdev_superblock->s_inode_list_lock);
iput(old_inode);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
jan kara | jan kara | 148 | 91.93% | 1 | 50.00% |
dave chinner | dave chinner | 13 | 8.07% | 1 | 50.00% |
| Total | 161 | 100.00% | 2 | 100.00% |
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
tejun heo | tejun heo | 1291 | 17.58% | 28 | 9.76% |
al viro | al viro | 1059 | 14.42% | 48 | 16.72% |
linus torvalds | linus torvalds | 634 | 8.63% | 20 | 6.97% |
nick piggin | nick piggin | 454 | 6.18% | 5 | 1.74% |
peter zijlstra | peter zijlstra | 415 | 5.65% | 5 | 1.74% |
andrew morton | andrew morton | 414 | 5.64% | 32 | 11.15% |
matthew wilcox | matthew wilcox | 346 | 4.71% | 5 | 1.74% |
jun'ichi nomura | jun'ichi nomura | 318 | 4.33% | 5 | 1.74% |
christoph hellwig | christoph hellwig | 301 | 4.10% | 18 | 6.27% |
toshi kani | toshi kani | 289 | 3.94% | 3 | 1.05% |
pre-git | pre-git | 241 | 3.28% | 15 | 5.23% |
jan kara | jan kara | 196 | 2.67% | 5 | 1.74% |
dan williams | dan williams | 185 | 2.52% | 8 | 2.79% |
neil brown | neil brown | 157 | 2.14% | 4 | 1.39% |
andrew patterson | andrew patterson | 152 | 2.07% | 4 | 1.39% |
david howells | david howells | 71 | 0.97% | 4 | 1.39% |
theodore tso | theodore tso | 68 | 0.93% | 1 | 0.35% |
ross zwisler | ross zwisler | 57 | 0.78% | 2 | 0.70% |
dave chinner | dave chinner | 56 | 0.76% | 3 | 1.05% |
vivek goyal | vivek goyal | 42 | 0.57% | 1 | 0.35% |
arnaldo carvalho de melo | arnaldo carvalho de melo | 41 | 0.56% | 1 | 0.35% |
akinobu mita | akinobu mita | 41 | 0.56% | 1 | 0.35% |
benjamin marzinski | benjamin marzinski | 40 | 0.54% | 1 | 0.35% |
hirofumi ogawa | hirofumi ogawa | 32 | 0.44% | 1 | 0.35% |
andi kleen | andi kleen | 30 | 0.41% | 2 | 0.70% |
pavel emelianov | pavel emelianov | 30 | 0.41% | 2 | 0.70% |
chuck ebbert | chuck ebbert | 29 | 0.39% | 1 | 0.35% |
shaohua li | shaohua li | 22 | 0.30% | 1 | 0.35% |
alan jenkins | alan jenkins | 22 | 0.30% | 1 | 0.35% |
rafael j. wysocki | rafael j. wysocki | 20 | 0.27% | 1 | 0.35% |
ingo molnar | ingo molnar | 16 | 0.22% | 1 | 0.35% |
dmitriy monakhov | dmitriy monakhov | 16 | 0.22% | 2 | 0.70% |
anton blanchard | anton blanchard | 16 | 0.22% | 2 | 0.70% |
ma jianpeng | ma jianpeng | 16 | 0.22% | 1 | 0.35% |
guo chao | guo chao | 16 | 0.22% | 1 | 0.35% |
josef bacik | josef bacik | 14 | 0.19% | 2 | 0.70% |
jeff moyer | jeff moyer | 13 | 0.18% | 1 | 0.35% |
ilya dryomov | ilya dryomov | 11 | 0.15% | 2 | 0.70% |
cheng renquan | cheng renquan | 11 | 0.15% | 1 | 0.35% |
johannes weiner | johannes weiner | 11 | 0.15% | 2 | 0.70% |
vishal verma | vishal verma | 10 | 0.14% | 1 | 0.35% |
takashi sato | takashi sato | 9 | 0.12% | 1 | 0.35% |
martin k. petersen | martin k. petersen | 8 | 0.11% | 2 | 0.70% |
vignesh babu | vignesh babu | 7 | 0.10% | 1 | 0.35% |
kenneth w. chen | kenneth w. chen | 7 | 0.10% | 1 | 0.35% |
mika kukkonen | mika kukkonen | 7 | 0.10% | 1 | 0.35% |
adrian bunk | adrian bunk | 7 | 0.10% | 1 | 0.35% |
jens axboe | jens axboe | 7 | 0.10% | 2 | 0.70% |
matthias kaehlcke | matthias kaehlcke | 6 | 0.08% | 1 | 0.35% |
lachlan mcilroy | lachlan mcilroy | 6 | 0.08% | 1 | 0.35% |
christoph lameter | christoph lameter | 6 | 0.08% | 3 | 1.05% |
jan blunck | jan blunck | 6 | 0.08% | 2 | 0.70% |
mitsunari shigeo | mitsunari shigeo | 6 | 0.08% | 1 | 0.35% |
mel gorman | mel gorman | 5 | 0.07% | 1 | 0.35% |
anatol pomozov | anatol pomozov | 5 | 0.07% | 1 | 0.35% |
thomas gleixner | thomas gleixner | 5 | 0.07% | 1 | 0.35% |
david jeffery | david jeffery | 5 | 0.07% | 1 | 0.35% |
coywolf qi hunt | coywolf qi hunt | 4 | 0.05% | 1 | 0.35% |
randy dunlap | randy dunlap | 4 | 0.05% | 3 | 1.05% |
muthu kumar | muthu kumar | 4 | 0.05% | 1 | 0.35% |
paul jackson | paul jackson | 4 | 0.05% | 2 | 0.70% |
chris wright | chris wright | 3 | 0.04% | 1 | 0.35% |
arnd bergmann | arnd bergmann | 3 | 0.04% | 2 | 0.70% |
arjan van de ven | arjan van de ven | 3 | 0.04% | 2 | 0.70% |
vladimir davydov | vladimir davydov | 2 | 0.03% | 1 | 0.35% |
dan carpenter | dan carpenter | 2 | 0.03% | 1 | 0.35% |
chuck lever | chuck lever | 2 | 0.03% | 1 | 0.35% |
kirill a. shutemov | kirill a. shutemov | 2 | 0.03% | 1 | 0.35% |
lucas de marchi | lucas de marchi | 1 | 0.01% | 1 | 0.35% |
josef 'jeff' sipek | josef 'jeff' sipek | 1 | 0.01% | 1 | 0.35% |
sergey senozhatsky | sergey senozhatsky | 1 | 0.01% | 1 | 0.35% |
dan magenheimer | dan magenheimer | 1 | 0.01% | 1 | 0.35% |
eric dumazet | eric dumazet | 1 | 0.01% | 1 | 0.35% |
alexey dobriyan | alexey dobriyan | 1 | 0.01% | 1 | 0.35% |
| Total | 7344 | 100.00% | 287 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.