Lines Matching refs:bdev
34 struct block_device bdev; member
45 return &BDEV_I(inode)->bdev; in I_BDEV()
49 static void bdev_write_inode(struct block_device *bdev) in bdev_write_inode() argument
51 struct inode *inode = bdev->bd_inode; in bdev_write_inode()
62 bdevname(bdev, name), ret); in bdev_write_inode()
70 static void kill_bdev(struct block_device *bdev) in kill_bdev() argument
72 struct address_space *mapping = bdev->bd_inode->i_mapping; in kill_bdev()
82 void invalidate_bdev(struct block_device *bdev) in invalidate_bdev() argument
84 struct address_space *mapping = bdev->bd_inode->i_mapping; in invalidate_bdev()
102 int truncate_bdev_range(struct block_device *bdev, fmode_t mode, in truncate_bdev_range() argument
111 int err = bd_prepare_to_claim(bdev, truncate_bdev_range); in truncate_bdev_range()
116 truncate_inode_pages_range(bdev->bd_inode->i_mapping, lstart, lend); in truncate_bdev_range()
118 bd_abort_claiming(bdev, truncate_bdev_range); in truncate_bdev_range()
126 return invalidate_inode_pages2_range(bdev->bd_inode->i_mapping, in truncate_bdev_range()
131 static void set_init_blocksize(struct block_device *bdev) in set_init_blocksize() argument
133 unsigned int bsize = bdev_logical_block_size(bdev); in set_init_blocksize()
134 loff_t size = i_size_read(bdev->bd_inode); in set_init_blocksize()
141 bdev->bd_inode->i_blkbits = blksize_bits(bsize); in set_init_blocksize()
144 int set_blocksize(struct block_device *bdev, int size) in set_blocksize() argument
151 if (size < bdev_logical_block_size(bdev)) in set_blocksize()
155 if (bdev->bd_inode->i_blkbits != blksize_bits(size)) { in set_blocksize()
156 sync_blockdev(bdev); in set_blocksize()
157 bdev->bd_inode->i_blkbits = blksize_bits(size); in set_blocksize()
158 kill_bdev(bdev); in set_blocksize()
188 int sync_blockdev_nowait(struct block_device *bdev) in sync_blockdev_nowait() argument
190 if (!bdev) in sync_blockdev_nowait()
192 return filemap_flush(bdev->bd_inode->i_mapping); in sync_blockdev_nowait()
200 int sync_blockdev(struct block_device *bdev) in sync_blockdev() argument
202 if (!bdev) in sync_blockdev()
204 return filemap_write_and_wait(bdev->bd_inode->i_mapping); in sync_blockdev()
213 int fsync_bdev(struct block_device *bdev) in fsync_bdev() argument
215 struct super_block *sb = get_super(bdev); in fsync_bdev()
221 return sync_blockdev(bdev); in fsync_bdev()
237 int freeze_bdev(struct block_device *bdev) in freeze_bdev() argument
242 mutex_lock(&bdev->bd_fsfreeze_mutex); in freeze_bdev()
243 if (++bdev->bd_fsfreeze_count > 1) in freeze_bdev()
246 sb = get_active_super(bdev); in freeze_bdev()
256 bdev->bd_fsfreeze_count--; in freeze_bdev()
259 bdev->bd_fsfreeze_sb = sb; in freeze_bdev()
262 sync_blockdev(bdev); in freeze_bdev()
264 mutex_unlock(&bdev->bd_fsfreeze_mutex); in freeze_bdev()
275 int thaw_bdev(struct block_device *bdev) in thaw_bdev() argument
280 mutex_lock(&bdev->bd_fsfreeze_mutex); in thaw_bdev()
281 if (!bdev->bd_fsfreeze_count) in thaw_bdev()
285 if (--bdev->bd_fsfreeze_count > 0) in thaw_bdev()
288 sb = bdev->bd_fsfreeze_sb; in thaw_bdev()
297 bdev->bd_fsfreeze_count++; in thaw_bdev()
299 bdev->bd_fsfreeze_sb = NULL; in thaw_bdev()
301 mutex_unlock(&bdev->bd_fsfreeze_mutex); in thaw_bdev()
322 int bdev_read_page(struct block_device *bdev, sector_t sector, in bdev_read_page() argument
325 const struct block_device_operations *ops = bdev->bd_disk->fops; in bdev_read_page()
328 if (!ops->rw_page || bdev_get_integrity(bdev)) in bdev_read_page()
331 result = blk_queue_enter(bdev_get_queue(bdev), 0); in bdev_read_page()
334 result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, in bdev_read_page()
336 blk_queue_exit(bdev_get_queue(bdev)); in bdev_read_page()
359 int bdev_write_page(struct block_device *bdev, sector_t sector, in bdev_write_page() argument
363 const struct block_device_operations *ops = bdev->bd_disk->fops; in bdev_write_page()
365 if (!ops->rw_page || bdev_get_integrity(bdev)) in bdev_write_page()
367 result = blk_queue_enter(bdev_get_queue(bdev), 0); in bdev_write_page()
372 result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, in bdev_write_page()
380 blk_queue_exit(bdev_get_queue(bdev)); in bdev_write_page()
397 memset(&ei->bdev, 0, sizeof(ei->bdev)); in bdev_alloc_inode()
403 struct block_device *bdev = I_BDEV(inode); in bdev_free_inode() local
405 free_percpu(bdev->bd_stats); in bdev_free_inode()
406 kfree(bdev->bd_meta_info); in bdev_free_inode()
408 if (!bdev_is_partition(bdev)) { in bdev_free_inode()
409 if (bdev->bd_disk && bdev->bd_disk->bdi) in bdev_free_inode()
410 bdi_put(bdev->bd_disk->bdi); in bdev_free_inode()
411 kfree(bdev->bd_disk); in bdev_free_inode()
414 if (MAJOR(bdev->bd_dev) == BLOCK_EXT_MAJOR) in bdev_free_inode()
415 blk_free_ext_minor(MINOR(bdev->bd_dev)); in bdev_free_inode()
481 struct block_device *bdev; in bdev_alloc() local
492 bdev = I_BDEV(inode); in bdev_alloc()
493 mutex_init(&bdev->bd_fsfreeze_mutex); in bdev_alloc()
494 spin_lock_init(&bdev->bd_size_lock); in bdev_alloc()
495 bdev->bd_partno = partno; in bdev_alloc()
496 bdev->bd_inode = inode; in bdev_alloc()
497 bdev->bd_queue = disk->queue; in bdev_alloc()
498 bdev->bd_stats = alloc_percpu(struct disk_stats); in bdev_alloc()
499 if (!bdev->bd_stats) { in bdev_alloc()
503 bdev->bd_disk = disk; in bdev_alloc()
504 return bdev; in bdev_alloc()
507 void bdev_add(struct block_device *bdev, dev_t dev) in bdev_add() argument
509 bdev->bd_dev = dev; in bdev_add()
510 bdev->bd_inode->i_rdev = dev; in bdev_add()
511 bdev->bd_inode->i_ino = dev; in bdev_add()
512 insert_inode_hash(bdev->bd_inode); in bdev_add()
542 static bool bd_may_claim(struct block_device *bdev, struct block_device *whole, in bd_may_claim() argument
545 if (bdev->bd_holder == holder) in bd_may_claim()
547 else if (bdev->bd_holder != NULL) in bd_may_claim()
549 else if (whole == bdev) in bd_may_claim()
572 int bd_prepare_to_claim(struct block_device *bdev, void *holder) in bd_prepare_to_claim() argument
574 struct block_device *whole = bdev_whole(bdev); in bd_prepare_to_claim()
581 if (!bd_may_claim(bdev, whole, holder)) { in bd_prepare_to_claim()
622 static void bd_finish_claiming(struct block_device *bdev, void *holder) in bd_finish_claiming() argument
624 struct block_device *whole = bdev_whole(bdev); in bd_finish_claiming()
627 BUG_ON(!bd_may_claim(bdev, whole, holder)); in bd_finish_claiming()
634 bdev->bd_holders++; in bd_finish_claiming()
635 bdev->bd_holder = holder; in bd_finish_claiming()
649 void bd_abort_claiming(struct block_device *bdev, void *holder) in bd_abort_claiming() argument
652 bd_clear_claiming(bdev_whole(bdev), holder); in bd_abort_claiming()
657 static void blkdev_flush_mapping(struct block_device *bdev) in blkdev_flush_mapping() argument
659 WARN_ON_ONCE(bdev->bd_holders); in blkdev_flush_mapping()
660 sync_blockdev(bdev); in blkdev_flush_mapping()
661 kill_bdev(bdev); in blkdev_flush_mapping()
662 bdev_write_inode(bdev); in blkdev_flush_mapping()
665 static int blkdev_get_whole(struct block_device *bdev, fmode_t mode) in blkdev_get_whole() argument
667 struct gendisk *disk = bdev->bd_disk; in blkdev_get_whole()
671 ret = disk->fops->open(bdev, mode); in blkdev_get_whole()
681 if (!bdev->bd_openers) in blkdev_get_whole()
682 set_init_blocksize(bdev); in blkdev_get_whole()
685 bdev->bd_openers++; in blkdev_get_whole()
689 static void blkdev_put_whole(struct block_device *bdev, fmode_t mode) in blkdev_put_whole() argument
691 if (!--bdev->bd_openers) in blkdev_put_whole()
692 blkdev_flush_mapping(bdev); in blkdev_put_whole()
693 if (bdev->bd_disk->fops->release) in blkdev_put_whole()
694 bdev->bd_disk->fops->release(bdev->bd_disk, mode); in blkdev_put_whole()
737 struct block_device *bdev; in blkdev_get_no_open() local
749 bdev = &BDEV_I(inode)->bdev; in blkdev_get_no_open()
750 if (!kobject_get_unless_zero(&bdev->bd_device.kobj)) in blkdev_get_no_open()
751 bdev = NULL; in blkdev_get_no_open()
754 if (!bdev) in blkdev_get_no_open()
756 if ((bdev->bd_disk->flags & GENHD_FL_HIDDEN)) { in blkdev_get_no_open()
757 put_device(&bdev->bd_device); in blkdev_get_no_open()
761 return bdev; in blkdev_get_no_open()
764 void blkdev_put_no_open(struct block_device *bdev) in blkdev_put_no_open() argument
766 put_device(&bdev->bd_device); in blkdev_put_no_open()
793 struct block_device *bdev; in blkdev_get_by_dev() local
804 bdev = blkdev_get_no_open(dev); in blkdev_get_by_dev()
805 if (!bdev) in blkdev_get_by_dev()
807 disk = bdev->bd_disk; in blkdev_get_by_dev()
810 ret = bd_prepare_to_claim(bdev, holder); in blkdev_get_by_dev()
823 if (bdev_is_partition(bdev)) in blkdev_get_by_dev()
824 ret = blkdev_get_part(bdev, mode); in blkdev_get_by_dev()
826 ret = blkdev_get_whole(bdev, mode); in blkdev_get_by_dev()
830 bd_finish_claiming(bdev, holder); in blkdev_get_by_dev()
839 if ((mode & FMODE_WRITE) && !bdev->bd_write_holder && in blkdev_get_by_dev()
841 bdev->bd_write_holder = true; in blkdev_get_by_dev()
849 return bdev; in blkdev_get_by_dev()
854 bd_abort_claiming(bdev, holder); in blkdev_get_by_dev()
858 blkdev_put_no_open(bdev); in blkdev_get_by_dev()
883 struct block_device *bdev; in blkdev_get_by_path() local
891 bdev = blkdev_get_by_dev(dev, mode, holder); in blkdev_get_by_path()
892 if (!IS_ERR(bdev) && (mode & FMODE_WRITE) && bdev_read_only(bdev)) { in blkdev_get_by_path()
893 blkdev_put(bdev, mode); in blkdev_get_by_path()
897 return bdev; in blkdev_get_by_path()
901 void blkdev_put(struct block_device *bdev, fmode_t mode) in blkdev_put() argument
903 struct gendisk *disk = bdev->bd_disk; in blkdev_put()
912 if (bdev->bd_openers == 1) in blkdev_put()
913 sync_blockdev(bdev); in blkdev_put()
917 struct block_device *whole = bdev_whole(bdev); in blkdev_put()
927 WARN_ON_ONCE(--bdev->bd_holders < 0); in blkdev_put()
930 if ((bdev_free = !bdev->bd_holders)) in blkdev_put()
931 bdev->bd_holder = NULL; in blkdev_put()
941 if (bdev_free && bdev->bd_write_holder) { in blkdev_put()
943 bdev->bd_write_holder = false; in blkdev_put()
954 if (bdev_is_partition(bdev)) in blkdev_put()
955 blkdev_put_part(bdev, mode); in blkdev_put()
957 blkdev_put_whole(bdev, mode); in blkdev_put()
961 blkdev_put_no_open(bdev); in blkdev_put()
1005 int __invalidate_device(struct block_device *bdev, bool kill_dirty) in __invalidate_device() argument
1007 struct super_block *sb = get_super(bdev); in __invalidate_device()
1021 invalidate_bdev(bdev); in __invalidate_device()
1033 struct block_device *bdev; in sync_bdevs() local
1054 bdev = I_BDEV(inode); in sync_bdevs()
1056 mutex_lock(&bdev->bd_disk->open_mutex); in sync_bdevs()
1057 if (!bdev->bd_openers) { in sync_bdevs()
1070 mutex_unlock(&bdev->bd_disk->open_mutex); in sync_bdevs()