• Home
  • Raw
  • Download

Lines Matching refs:bdev

36 	struct block_device bdev;  member
49 return &BDEV_I(inode)->bdev; in I_BDEV()
53 static void bdev_write_inode(struct block_device *bdev) in bdev_write_inode() argument
55 struct inode *inode = bdev->bd_inode; in bdev_write_inode()
66 bdevname(bdev, name), ret); in bdev_write_inode()
74 void kill_bdev(struct block_device *bdev) in kill_bdev() argument
76 struct address_space *mapping = bdev->bd_inode->i_mapping; in kill_bdev()
87 void invalidate_bdev(struct block_device *bdev) in invalidate_bdev() argument
89 struct address_space *mapping = bdev->bd_inode->i_mapping; in invalidate_bdev()
103 int set_blocksize(struct block_device *bdev, int size) in set_blocksize() argument
110 if (size < bdev_logical_block_size(bdev)) in set_blocksize()
114 if (bdev->bd_block_size != size) { in set_blocksize()
115 sync_blockdev(bdev); in set_blocksize()
116 bdev->bd_block_size = size; in set_blocksize()
117 bdev->bd_inode->i_blkbits = blksize_bits(size); in set_blocksize()
118 kill_bdev(bdev); in set_blocksize()
172 int __sync_blockdev(struct block_device *bdev, int wait) in __sync_blockdev() argument
174 if (!bdev) in __sync_blockdev()
177 return filemap_flush(bdev->bd_inode->i_mapping); in __sync_blockdev()
178 return filemap_write_and_wait(bdev->bd_inode->i_mapping); in __sync_blockdev()
185 int sync_blockdev(struct block_device *bdev) in sync_blockdev() argument
187 return __sync_blockdev(bdev, 1); in sync_blockdev()
196 int fsync_bdev(struct block_device *bdev) in fsync_bdev() argument
198 struct super_block *sb = get_super(bdev); in fsync_bdev()
204 return sync_blockdev(bdev); in fsync_bdev()
220 struct super_block *freeze_bdev(struct block_device *bdev) in freeze_bdev() argument
225 mutex_lock(&bdev->bd_fsfreeze_mutex); in freeze_bdev()
226 if (++bdev->bd_fsfreeze_count > 1) { in freeze_bdev()
232 sb = get_super(bdev); in freeze_bdev()
234 mutex_unlock(&bdev->bd_fsfreeze_mutex); in freeze_bdev()
238 sb = get_active_super(bdev); in freeze_bdev()
247 bdev->bd_fsfreeze_count--; in freeze_bdev()
248 mutex_unlock(&bdev->bd_fsfreeze_mutex); in freeze_bdev()
253 sync_blockdev(bdev); in freeze_bdev()
254 mutex_unlock(&bdev->bd_fsfreeze_mutex); in freeze_bdev()
266 int thaw_bdev(struct block_device *bdev, struct super_block *sb) in thaw_bdev() argument
270 mutex_lock(&bdev->bd_fsfreeze_mutex); in thaw_bdev()
271 if (!bdev->bd_fsfreeze_count) in thaw_bdev()
275 if (--bdev->bd_fsfreeze_count > 0) in thaw_bdev()
286 bdev->bd_fsfreeze_count++; in thaw_bdev()
287 mutex_unlock(&bdev->bd_fsfreeze_mutex); in thaw_bdev()
291 mutex_unlock(&bdev->bd_fsfreeze_mutex); in thaw_bdev()
352 struct block_device *bdev = I_BDEV(bd_inode); in blkdev_fsync() local
364 error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL); in blkdev_fsync()
388 int bdev_read_page(struct block_device *bdev, sector_t sector, in bdev_read_page() argument
391 const struct block_device_operations *ops = bdev->bd_disk->fops; in bdev_read_page()
394 if (!ops->rw_page || bdev_get_integrity(bdev)) in bdev_read_page()
397 result = blk_queue_enter(bdev->bd_queue, GFP_KERNEL); in bdev_read_page()
400 result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, READ); in bdev_read_page()
401 blk_queue_exit(bdev->bd_queue); in bdev_read_page()
425 int bdev_write_page(struct block_device *bdev, sector_t sector, in bdev_write_page() argument
430 const struct block_device_operations *ops = bdev->bd_disk->fops; in bdev_write_page()
432 if (!ops->rw_page || bdev_get_integrity(bdev)) in bdev_write_page()
434 result = blk_queue_enter(bdev->bd_queue, GFP_KERNEL); in bdev_write_page()
439 result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, rw); in bdev_write_page()
444 blk_queue_exit(bdev->bd_queue); in bdev_write_page()
466 long bdev_direct_access(struct block_device *bdev, sector_t sector, in bdev_direct_access() argument
470 const struct block_device_operations *ops = bdev->bd_disk->fops; in bdev_direct_access()
483 part_nr_sects_read(bdev->bd_part)) in bdev_direct_access()
485 sector += get_start_sect(bdev); in bdev_direct_access()
488 avail = ops->direct_access(bdev, sector, addr, pfn); in bdev_direct_access()
526 struct block_device *bdev = &ei->bdev; in init_once() local
528 memset(bdev, 0, sizeof(*bdev)); in init_once()
529 mutex_init(&bdev->bd_mutex); in init_once()
530 INIT_LIST_HEAD(&bdev->bd_inodes); in init_once()
531 INIT_LIST_HEAD(&bdev->bd_list); in init_once()
533 INIT_LIST_HEAD(&bdev->bd_holder_disks); in init_once()
537 mutex_init(&bdev->bd_fsfreeze_mutex); in init_once()
549 struct block_device *bdev = &BDEV_I(inode)->bdev; in bdev_evict_inode() local
555 while ( (p = bdev->bd_inodes.next) != &bdev->bd_inodes ) { in bdev_evict_inode()
558 list_del_init(&bdev->bd_list); in bdev_evict_inode()
615 return BDEV_I(inode)->bdev.bd_dev == *(dev_t *)data; in bdev_test()
620 BDEV_I(inode)->bdev.bd_dev = *(dev_t *)data; in bdev_set()
628 struct block_device *bdev; in bdget() local
637 bdev = &BDEV_I(inode)->bdev; in bdget()
640 bdev->bd_contains = NULL; in bdget()
641 bdev->bd_super = NULL; in bdget()
642 bdev->bd_inode = inode; in bdget()
643 bdev->bd_block_size = (1 << inode->i_blkbits); in bdget()
644 bdev->bd_part_count = 0; in bdget()
645 bdev->bd_invalidated = 0; in bdget()
648 inode->i_bdev = bdev; in bdget()
652 list_add(&bdev->bd_list, &all_bdevs); in bdget()
656 return bdev; in bdget()
665 struct block_device *bdgrab(struct block_device *bdev) in bdgrab() argument
667 ihold(bdev->bd_inode); in bdgrab()
668 return bdev; in bdgrab()
674 struct block_device *bdev; in nr_blockdev_pages() local
677 list_for_each_entry(bdev, &all_bdevs, bd_list) { in nr_blockdev_pages()
678 ret += bdev->bd_inode->i_mapping->nrpages; in nr_blockdev_pages()
684 void bdput(struct block_device *bdev) in bdput() argument
686 iput(bdev->bd_inode); in bdput()
693 struct block_device *bdev; in bd_acquire() local
696 bdev = inode->i_bdev; in bd_acquire()
697 if (bdev) { in bd_acquire()
698 ihold(bdev->bd_inode); in bd_acquire()
700 return bdev; in bd_acquire()
704 bdev = bdget(inode->i_rdev); in bd_acquire()
705 if (bdev) { in bd_acquire()
714 ihold(bdev->bd_inode); in bd_acquire()
715 inode->i_bdev = bdev; in bd_acquire()
716 inode->i_mapping = bdev->bd_inode->i_mapping; in bd_acquire()
717 list_add(&inode->i_devices, &bdev->bd_inodes); in bd_acquire()
721 return bdev; in bd_acquire()
728 struct block_device *bdev = NULL; in bd_forget() local
732 bdev = inode->i_bdev; in bd_forget()
736 if (bdev) in bd_forget()
737 iput(bdev->bd_inode); in bd_forget()
754 static bool bd_may_claim(struct block_device *bdev, struct block_device *whole, in bd_may_claim() argument
757 if (bdev->bd_holder == holder) in bd_may_claim()
759 else if (bdev->bd_holder != NULL) in bd_may_claim()
761 else if (whole == bdev) in bd_may_claim()
790 static int bd_prepare_to_claim(struct block_device *bdev, in bd_prepare_to_claim() argument
795 if (!bd_may_claim(bdev, whole, holder)) in bd_prepare_to_claim()
838 static struct block_device *bd_start_claiming(struct block_device *bdev, in bd_start_claiming() argument
851 disk = get_gendisk(bdev->bd_dev, &partno); in bd_start_claiming()
866 whole = bdgrab(bdev); in bd_start_claiming()
876 err = bd_prepare_to_claim(bdev, whole, holder); in bd_start_claiming()
895 static struct bd_holder_disk *bd_find_holder_disk(struct block_device *bdev, in bd_find_holder_disk() argument
900 list_for_each_entry(holder, &bdev->bd_holder_disks, list) in bd_find_holder_disk()
944 int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk) in bd_link_disk_holder() argument
949 mutex_lock(&bdev->bd_mutex); in bd_link_disk_holder()
951 WARN_ON_ONCE(!bdev->bd_holder); in bd_link_disk_holder()
954 if (WARN_ON(!disk->slave_dir || !bdev->bd_part->holder_dir)) in bd_link_disk_holder()
957 holder = bd_find_holder_disk(bdev, disk); in bd_link_disk_holder()
973 ret = add_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj); in bd_link_disk_holder()
977 ret = add_symlink(bdev->bd_part->holder_dir, &disk_to_dev(disk)->kobj); in bd_link_disk_holder()
984 kobject_get(bdev->bd_part->holder_dir); in bd_link_disk_holder()
986 list_add(&holder->list, &bdev->bd_holder_disks); in bd_link_disk_holder()
990 del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj); in bd_link_disk_holder()
994 mutex_unlock(&bdev->bd_mutex); in bd_link_disk_holder()
1009 void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk) in bd_unlink_disk_holder() argument
1013 mutex_lock(&bdev->bd_mutex); in bd_unlink_disk_holder()
1015 holder = bd_find_holder_disk(bdev, disk); in bd_unlink_disk_holder()
1018 del_symlink(disk->slave_dir, &part_to_dev(bdev->bd_part)->kobj); in bd_unlink_disk_holder()
1019 del_symlink(bdev->bd_part->holder_dir, in bd_unlink_disk_holder()
1021 kobject_put(bdev->bd_part->holder_dir); in bd_unlink_disk_holder()
1026 mutex_unlock(&bdev->bd_mutex); in bd_unlink_disk_holder()
1041 static void flush_disk(struct block_device *bdev, bool kill_dirty) in flush_disk() argument
1043 if (__invalidate_device(bdev, kill_dirty)) { in flush_disk()
1046 if (bdev->bd_disk) in flush_disk()
1047 disk_name(bdev->bd_disk, 0, name); in flush_disk()
1052 if (!bdev->bd_disk) in flush_disk()
1054 if (disk_part_scan_enabled(bdev->bd_disk)) in flush_disk()
1055 bdev->bd_invalidated = 1; in flush_disk()
1066 void check_disk_size_change(struct gendisk *disk, struct block_device *bdev) in check_disk_size_change() argument
1071 bdev_size = i_size_read(bdev->bd_inode); in check_disk_size_change()
1079 i_size_write(bdev->bd_inode, disk_size); in check_disk_size_change()
1080 flush_disk(bdev, false); in check_disk_size_change()
1095 struct block_device *bdev; in revalidate_disk() local
1100 bdev = bdget_disk(disk, 0); in revalidate_disk()
1101 if (!bdev) in revalidate_disk()
1104 mutex_lock(&bdev->bd_mutex); in revalidate_disk()
1105 check_disk_size_change(disk, bdev); in revalidate_disk()
1106 bdev->bd_invalidated = 0; in revalidate_disk()
1107 mutex_unlock(&bdev->bd_mutex); in revalidate_disk()
1108 bdput(bdev); in revalidate_disk()
1122 int check_disk_change(struct block_device *bdev) in check_disk_change() argument
1124 struct gendisk *disk = bdev->bd_disk; in check_disk_change()
1133 flush_disk(bdev, true); in check_disk_change()
1135 bdops->revalidate_disk(bdev->bd_disk); in check_disk_change()
1141 void bd_set_size(struct block_device *bdev, loff_t size) in bd_set_size() argument
1143 unsigned bsize = bdev_logical_block_size(bdev); in bd_set_size()
1145 mutex_lock(&bdev->bd_inode->i_mutex); in bd_set_size()
1146 i_size_write(bdev->bd_inode, size); in bd_set_size()
1147 mutex_unlock(&bdev->bd_inode->i_mutex); in bd_set_size()
1153 bdev->bd_block_size = bsize; in bd_set_size()
1154 bdev->bd_inode->i_blkbits = blksize_bits(bsize); in bd_set_size()
1158 static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
1167 static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) in __blkdev_get() argument
1183 ret = devcgroup_inode_permission(bdev->bd_inode, perm); in __blkdev_get()
1191 disk = get_gendisk(bdev->bd_dev, &partno); in __blkdev_get()
1197 mutex_lock_nested(&bdev->bd_mutex, for_part); in __blkdev_get()
1198 if (!bdev->bd_openers) { in __blkdev_get()
1199 bdev->bd_disk = disk; in __blkdev_get()
1200 bdev->bd_queue = disk->queue; in __blkdev_get()
1201 bdev->bd_contains = bdev; in __blkdev_get()
1202 bdev->bd_inode->i_flags = disk->fops->direct_access ? S_DAX : 0; in __blkdev_get()
1205 bdev->bd_part = disk_get_part(disk, partno); in __blkdev_get()
1206 if (!bdev->bd_part) in __blkdev_get()
1211 ret = disk->fops->open(bdev, mode); in __blkdev_get()
1217 disk_put_part(bdev->bd_part); in __blkdev_get()
1218 bdev->bd_part = NULL; in __blkdev_get()
1219 bdev->bd_disk = NULL; in __blkdev_get()
1220 bdev->bd_queue = NULL; in __blkdev_get()
1221 mutex_unlock(&bdev->bd_mutex); in __blkdev_get()
1230 bd_set_size(bdev,(loff_t)get_capacity(disk)<<9); in __blkdev_get()
1238 if (bdev->bd_invalidated) { in __blkdev_get()
1240 rescan_partitions(disk, bdev); in __blkdev_get()
1242 invalidate_partitions(disk, bdev); in __blkdev_get()
1258 bdev->bd_contains = whole; in __blkdev_get()
1259 bdev->bd_part = disk_get_part(disk, partno); in __blkdev_get()
1261 !bdev->bd_part || !bdev->bd_part->nr_sects) { in __blkdev_get()
1265 bd_set_size(bdev, (loff_t)bdev->bd_part->nr_sects << 9); in __blkdev_get()
1270 if ((bdev->bd_part->start_sect % (PAGE_SIZE / 512)) || in __blkdev_get()
1271 (bdev->bd_part->nr_sects % (PAGE_SIZE / 512))) in __blkdev_get()
1272 bdev->bd_inode->i_flags &= ~S_DAX; in __blkdev_get()
1275 if (bdev->bd_contains == bdev) { in __blkdev_get()
1277 if (bdev->bd_disk->fops->open) in __blkdev_get()
1278 ret = bdev->bd_disk->fops->open(bdev, mode); in __blkdev_get()
1280 if (bdev->bd_invalidated) { in __blkdev_get()
1282 rescan_partitions(bdev->bd_disk, bdev); in __blkdev_get()
1284 invalidate_partitions(bdev->bd_disk, bdev); in __blkdev_get()
1293 bdev->bd_openers++; in __blkdev_get()
1295 bdev->bd_part_count++; in __blkdev_get()
1296 mutex_unlock(&bdev->bd_mutex); in __blkdev_get()
1301 disk_put_part(bdev->bd_part); in __blkdev_get()
1302 bdev->bd_disk = NULL; in __blkdev_get()
1303 bdev->bd_part = NULL; in __blkdev_get()
1304 bdev->bd_queue = NULL; in __blkdev_get()
1305 if (bdev != bdev->bd_contains) in __blkdev_get()
1306 __blkdev_put(bdev->bd_contains, mode, 1); in __blkdev_get()
1307 bdev->bd_contains = NULL; in __blkdev_get()
1309 mutex_unlock(&bdev->bd_mutex); in __blkdev_get()
1337 int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) in blkdev_get() argument
1345 whole = bd_start_claiming(bdev, holder); in blkdev_get()
1347 bdput(bdev); in blkdev_get()
1352 res = __blkdev_get(bdev, mode, 0); in blkdev_get()
1358 mutex_lock(&bdev->bd_mutex); in blkdev_get()
1362 BUG_ON(!bd_may_claim(bdev, whole, holder)); in blkdev_get()
1371 bdev->bd_holders++; in blkdev_get()
1372 bdev->bd_holder = holder; in blkdev_get()
1389 if (!res && (mode & FMODE_WRITE) && !bdev->bd_write_holder && in blkdev_get()
1391 bdev->bd_write_holder = true; in blkdev_get()
1395 mutex_unlock(&bdev->bd_mutex); in blkdev_get()
1400 bdput(bdev); in blkdev_get()
1426 struct block_device *bdev; in blkdev_get_by_path() local
1429 bdev = lookup_bdev(path); in blkdev_get_by_path()
1430 if (IS_ERR(bdev)) in blkdev_get_by_path()
1431 return bdev; in blkdev_get_by_path()
1433 err = blkdev_get(bdev, mode, holder); in blkdev_get_by_path()
1437 if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) { in blkdev_get_by_path()
1438 blkdev_put(bdev, mode); in blkdev_get_by_path()
1442 return bdev; in blkdev_get_by_path()
1470 struct block_device *bdev; in blkdev_get_by_dev() local
1473 bdev = bdget(dev); in blkdev_get_by_dev()
1474 if (!bdev) in blkdev_get_by_dev()
1477 err = blkdev_get(bdev, mode, holder); in blkdev_get_by_dev()
1481 return bdev; in blkdev_get_by_dev()
1487 struct block_device *bdev; in blkdev_open() local
1504 bdev = bd_acquire(inode); in blkdev_open()
1505 if (bdev == NULL) in blkdev_open()
1508 filp->f_mapping = bdev->bd_inode->i_mapping; in blkdev_open()
1510 return blkdev_get(bdev, filp->f_mode, filp); in blkdev_open()
1513 static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) in __blkdev_put() argument
1515 struct gendisk *disk = bdev->bd_disk; in __blkdev_put()
1525 if (bdev->bd_openers == 1) in __blkdev_put()
1526 sync_blockdev(bdev); in __blkdev_put()
1528 mutex_lock_nested(&bdev->bd_mutex, for_part); in __blkdev_put()
1530 bdev->bd_part_count--; in __blkdev_put()
1532 if (!--bdev->bd_openers) { in __blkdev_put()
1533 WARN_ON_ONCE(bdev->bd_holders); in __blkdev_put()
1534 sync_blockdev(bdev); in __blkdev_put()
1535 kill_bdev(bdev); in __blkdev_put()
1537 bdev_write_inode(bdev); in __blkdev_put()
1543 inode_detach_wb(bdev->bd_inode); in __blkdev_put()
1545 if (bdev->bd_contains == bdev) { in __blkdev_put()
1549 if (!bdev->bd_openers) { in __blkdev_put()
1552 disk_put_part(bdev->bd_part); in __blkdev_put()
1553 bdev->bd_part = NULL; in __blkdev_put()
1554 bdev->bd_disk = NULL; in __blkdev_put()
1555 if (bdev != bdev->bd_contains) in __blkdev_put()
1556 victim = bdev->bd_contains; in __blkdev_put()
1557 bdev->bd_contains = NULL; in __blkdev_put()
1562 mutex_unlock(&bdev->bd_mutex); in __blkdev_put()
1563 bdput(bdev); in __blkdev_put()
1568 void blkdev_put(struct block_device *bdev, fmode_t mode) in blkdev_put() argument
1570 mutex_lock(&bdev->bd_mutex); in blkdev_put()
1582 WARN_ON_ONCE(--bdev->bd_holders < 0); in blkdev_put()
1583 WARN_ON_ONCE(--bdev->bd_contains->bd_holders < 0); in blkdev_put()
1586 if ((bdev_free = !bdev->bd_holders)) in blkdev_put()
1587 bdev->bd_holder = NULL; in blkdev_put()
1588 if (!bdev->bd_contains->bd_holders) in blkdev_put()
1589 bdev->bd_contains->bd_holder = NULL; in blkdev_put()
1597 if (bdev_free && bdev->bd_write_holder) { in blkdev_put()
1598 disk_unblock_events(bdev->bd_disk); in blkdev_put()
1599 bdev->bd_write_holder = false; in blkdev_put()
1608 disk_flush_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE); in blkdev_put()
1610 mutex_unlock(&bdev->bd_mutex); in blkdev_put()
1612 __blkdev_put(bdev, mode, 0); in blkdev_put()
1618 struct block_device *bdev = I_BDEV(filp->f_mapping->host); in blkdev_close() local
1619 blkdev_put(bdev, filp->f_mode); in blkdev_close()
1625 struct block_device *bdev = I_BDEV(file->f_mapping->host); in block_ioctl() local
1637 return blkdev_ioctl(bdev, mode, cmd, arg); in block_ioctl()
1701 struct super_block *super = BDEV_I(page->mapping->host)->bdev.bd_super; in blkdev_releasepage()
1737 int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg) in ioctl_by_bdev() argument
1742 res = blkdev_ioctl(bdev, 0, cmd, arg); in ioctl_by_bdev()
1759 struct block_device *bdev; in lookup_bdev() local
1779 bdev = bd_acquire(inode); in lookup_bdev()
1780 if (!bdev) in lookup_bdev()
1784 return bdev; in lookup_bdev()
1786 bdev = ERR_PTR(error); in lookup_bdev()
1791 int __invalidate_device(struct block_device *bdev, bool kill_dirty) in __invalidate_device() argument
1793 struct super_block *sb = get_super(bdev); in __invalidate_device()
1807 invalidate_bdev(bdev); in __invalidate_device()
1819 struct block_device *bdev; in iterate_bdevs() local
1840 bdev = I_BDEV(inode); in iterate_bdevs()
1842 mutex_lock(&bdev->bd_mutex); in iterate_bdevs()
1843 if (bdev->bd_openers) in iterate_bdevs()
1844 func(bdev, arg); in iterate_bdevs()
1845 mutex_unlock(&bdev->bd_mutex); in iterate_bdevs()