Lines Matching full:disk
43 static void disk_alloc_events(struct gendisk *disk);
44 static void disk_add_events(struct gendisk *disk);
45 static void disk_del_events(struct gendisk *disk);
46 static void disk_release_events(struct gendisk *disk);
49 * Set disk capacity and notify if the size is not currently
52 bool set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size, in set_capacity_revalidate_and_notify() argument
55 sector_t capacity = get_capacity(disk); in set_capacity_revalidate_and_notify()
57 set_capacity(disk, size); in set_capacity_revalidate_and_notify()
59 revalidate_disk_size(disk, true); in set_capacity_revalidate_and_notify()
64 kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp); in set_capacity_revalidate_and_notify()
74 * Format the device name of the indicated disk into the supplied buffer and
146 struct hd_struct *__disk_get_part(struct gendisk *disk, int partno) in __disk_get_part() argument
148 struct disk_part_tbl *ptbl = rcu_dereference(disk->part_tbl); in __disk_get_part()
157 * @disk: disk to look partition from
160 * Look for partition @partno from @disk. If found, increment
169 struct hd_struct *disk_get_part(struct gendisk *disk, int partno) in disk_get_part() argument
174 part = __disk_get_part(disk, partno); in disk_get_part()
185 * @disk: disk to iterate over
188 * Initialize @piter so that it iterates over partitions of @disk.
193 void disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk, in disk_part_iter_init() argument
199 ptbl = rcu_dereference(disk->part_tbl); in disk_part_iter_init()
201 piter->disk = disk; in disk_part_iter_init()
237 ptbl = rcu_dereference(piter->disk->part_tbl); in disk_part_iter_next()
301 * @disk: gendisk of interest
304 * Find out which partition @sector maps to on @disk. This is
310 * is same with the disk.
316 struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector) in disk_map_sector_rcu() argument
323 ptbl = rcu_dereference(disk->part_tbl); in disk_map_sector_rcu()
345 part = &disk->part0; in disk_map_sector_rcu()
353 * @disk: gendisk of interest
364 bool disk_has_partitions(struct gendisk *disk) in disk_has_partitions() argument
371 ptbl = rcu_dereference(disk->part_tbl); in disk_has_partitions()
573 struct gendisk *disk = part_to_disk(part); in blk_alloc_devt() local
577 if (part->partno < disk->minors) { in blk_alloc_devt()
578 *devt = MKDEV(disk->major, disk->first_minor + part->partno); in blk_alloc_devt()
679 static void disk_scan_partitions(struct gendisk *disk) in disk_scan_partitions() argument
683 if (!get_capacity(disk) || !disk_part_scan_enabled(disk)) in disk_scan_partitions()
686 set_bit(GD_NEED_PART_SCAN, &disk->state); in disk_scan_partitions()
687 bdev = blkdev_get_by_dev(disk_devt(disk), FMODE_READ, NULL); in disk_scan_partitions()
692 static void register_disk(struct device *parent, struct gendisk *disk, in register_disk() argument
695 struct device *ddev = disk_to_dev(disk); in register_disk()
702 dev_set_name(ddev, "%s", disk->disk_name); in register_disk()
729 disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj); in register_disk()
730 disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj); in register_disk()
732 if (disk->flags & GENHD_FL_HIDDEN) { in register_disk()
737 disk_scan_partitions(disk); in register_disk()
739 /* announce disk after possible partitions are created */ in register_disk()
744 disk_part_iter_init(&piter, disk, 0); in register_disk()
749 if (disk->queue->backing_dev_info->dev) { in register_disk()
751 &disk->queue->backing_dev_info->dev->kobj, in register_disk()
758 * __device_add_disk - add disk information to kernel list
759 * @parent: parent device for the disk
760 * @disk: per-device partitioning information
764 * This function registers the partitioning information in @disk
769 static void __device_add_disk(struct device *parent, struct gendisk *disk, in __device_add_disk() argument
777 * The disk queue should now be all set with enough information about in __device_add_disk()
783 elevator_init_mq(disk->queue); in __device_add_disk()
789 WARN_ON(disk->minors && !(disk->major || disk->first_minor)); in __device_add_disk()
790 WARN_ON(!disk->minors && in __device_add_disk()
791 !(disk->flags & (GENHD_FL_EXT_DEVT | GENHD_FL_HIDDEN))); in __device_add_disk()
793 disk->flags |= GENHD_FL_UP; in __device_add_disk()
795 retval = blk_alloc_devt(&disk->part0, &devt); in __device_add_disk()
800 disk->major = MAJOR(devt); in __device_add_disk()
801 disk->first_minor = MINOR(devt); in __device_add_disk()
803 disk_alloc_events(disk); in __device_add_disk()
805 if (disk->flags & GENHD_FL_HIDDEN) { in __device_add_disk()
810 disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; in __device_add_disk()
811 disk->flags |= GENHD_FL_NO_PART_SCAN; in __device_add_disk()
813 struct backing_dev_info *bdi = disk->queue->backing_dev_info; in __device_add_disk()
814 struct device *dev = disk_to_dev(disk); in __device_add_disk()
822 blk_register_region(disk_devt(disk), disk->minors, NULL, in __device_add_disk()
823 exact_match, exact_lock, disk); in __device_add_disk()
825 register_disk(parent, disk, groups); in __device_add_disk()
827 blk_register_queue(disk); in __device_add_disk()
831 * so that it sticks around as long as @disk is there. in __device_add_disk()
833 WARN_ON_ONCE(!blk_get_queue(disk->queue)); in __device_add_disk()
835 disk_add_events(disk); in __device_add_disk()
836 blk_integrity_add(disk); in __device_add_disk()
839 void device_add_disk(struct device *parent, struct gendisk *disk, in device_add_disk() argument
843 __device_add_disk(parent, disk, groups, true); in device_add_disk()
847 void device_add_disk_no_queue_reg(struct device *parent, struct gendisk *disk) in device_add_disk_no_queue_reg() argument
849 __device_add_disk(parent, disk, NULL, false); in device_add_disk_no_queue_reg()
853 static void invalidate_partition(struct gendisk *disk, int partno) in invalidate_partition() argument
857 bdev = bdget_disk(disk, partno); in invalidate_partition()
874 * @disk: the struct gendisk to remove
891 void del_gendisk(struct gendisk *disk) in del_gendisk() argument
898 blk_integrity_del(disk); in del_gendisk()
899 disk_del_events(disk); in del_gendisk()
902 * Block lookups of the disk until all bdevs are unhashed and the in del_gendisk()
903 * disk is marked as dead (GENHD_FL_UP cleared). in del_gendisk()
905 down_write(&disk->lookup_sem); in del_gendisk()
907 disk_part_iter_init(&piter, disk, in del_gendisk()
910 invalidate_partition(disk, part->partno); in del_gendisk()
915 invalidate_partition(disk, 0); in del_gendisk()
916 set_capacity(disk, 0); in del_gendisk()
917 disk->flags &= ~GENHD_FL_UP; in del_gendisk()
918 up_write(&disk->lookup_sem); in del_gendisk()
920 if (!(disk->flags & GENHD_FL_HIDDEN)) in del_gendisk()
921 sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi"); in del_gendisk()
922 if (disk->queue) { in del_gendisk()
927 if (!(disk->flags & GENHD_FL_HIDDEN)) in del_gendisk()
928 bdi_unregister(disk->queue->backing_dev_info); in del_gendisk()
929 blk_unregister_queue(disk); in del_gendisk()
934 if (!(disk->flags & GENHD_FL_HIDDEN)) in del_gendisk()
935 blk_unregister_region(disk_devt(disk), disk->minors); in del_gendisk()
942 blk_invalidate_devt(disk_devt(disk)); in del_gendisk()
944 kobject_put(disk->part0.holder_dir); in del_gendisk()
945 kobject_put(disk->slave_dir); in del_gendisk()
947 part_stat_set_all(&disk->part0, 0); in del_gendisk()
948 disk->part0.stamp = 0; in del_gendisk()
950 sysfs_remove_link(block_depr, dev_name(disk_to_dev(disk))); in del_gendisk()
951 pm_runtime_set_memalloc_noio(disk_to_dev(disk), false); in del_gendisk()
952 device_del(disk_to_dev(disk)); in del_gendisk()
961 struct gendisk *disk = dev_to_disk(dev); in disk_badblocks_show() local
963 if (!disk->bb) in disk_badblocks_show()
966 return badblocks_show(disk->bb, page, 0); in disk_badblocks_show()
973 struct gendisk *disk = dev_to_disk(dev); in disk_badblocks_store() local
975 if (!disk->bb) in disk_badblocks_store()
978 return badblocks_store(disk->bb, page, len, 0); in disk_badblocks_store()
993 struct gendisk *disk = NULL; in get_gendisk() local
1002 disk = dev_to_disk(kobj_to_dev(kobj)); in get_gendisk()
1010 disk = part_to_disk(part); in get_gendisk()
1015 if (!disk) in get_gendisk()
1019 * Synchronize with del_gendisk() to not return disk that is being in get_gendisk()
1022 down_read(&disk->lookup_sem); in get_gendisk()
1023 if (unlikely((disk->flags & GENHD_FL_HIDDEN) || in get_gendisk()
1024 !(disk->flags & GENHD_FL_UP))) { in get_gendisk()
1025 up_read(&disk->lookup_sem); in get_gendisk()
1026 put_disk_and_module(disk); in get_gendisk()
1027 disk = NULL; in get_gendisk()
1029 up_read(&disk->lookup_sem); in get_gendisk()
1031 return disk; in get_gendisk()
1036 * @disk: gendisk of interest
1039 * Find partition @partno from @disk, do bdget() on it.
1047 struct block_device *bdget_disk(struct gendisk *disk, int partno) in bdget_disk() argument
1052 part = disk_get_part(disk, partno); in bdget_disk()
1073 struct gendisk *disk = dev_to_disk(dev); in printk_all_partitions() local
1083 if (get_capacity(disk) == 0 || in printk_all_partitions()
1084 (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)) in printk_all_partitions()
1092 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0); in printk_all_partitions()
1094 bool is_part0 = part == &disk->part0; in printk_all_partitions()
1099 , disk_name(disk, part->partno, name_buf), in printk_all_partitions()
1186 /* show the full disk and all non-0 size partitions of it */ in show_partition()
1239 struct gendisk *disk = dev_to_disk(dev); in disk_range_show() local
1241 return sprintf(buf, "%d\n", disk->minors); in disk_range_show()
1247 struct gendisk *disk = dev_to_disk(dev); in disk_ext_range_show() local
1249 return sprintf(buf, "%d\n", disk_max_parts(disk)); in disk_ext_range_show()
1255 struct gendisk *disk = dev_to_disk(dev); in disk_removable_show() local
1258 (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0)); in disk_removable_show()
1264 struct gendisk *disk = dev_to_disk(dev); in disk_hidden_show() local
1267 (disk->flags & GENHD_FL_HIDDEN ? 1 : 0)); in disk_hidden_show()
1273 struct gendisk *disk = dev_to_disk(dev); in disk_ro_show() local
1275 return sprintf(buf, "%d\n", get_disk_ro(disk) ? 1 : 0); in disk_ro_show()
1349 struct gendisk *disk = dev_to_disk(dev); in disk_capability_show() local
1351 return sprintf(buf, "%x\n", disk->flags); in disk_capability_show()
1358 struct gendisk *disk = dev_to_disk(dev); in disk_alignment_offset_show() local
1360 return sprintf(buf, "%d\n", queue_alignment_offset(disk->queue)); in disk_alignment_offset_show()
1367 struct gendisk *disk = dev_to_disk(dev); in disk_discard_alignment_show() local
1369 return sprintf(buf, "%d\n", queue_discard_alignment(disk->queue)); in disk_discard_alignment_show()
1441 struct gendisk *disk = dev_to_disk(dev); in disk_visible() local
1443 if (a == &dev_attr_badblocks.attr && !disk->bb) in disk_visible()
1459 * disk_replace_part_tbl - replace disk->part_tbl in RCU-safe way
1460 * @disk: disk to replace part_tbl for
1463 * Replace disk->part_tbl with @new_ptbl in RCU-safe way. The
1467 * Matching bd_mutex locked or the caller is the only user of @disk.
1469 static void disk_replace_part_tbl(struct gendisk *disk, in disk_replace_part_tbl() argument
1473 rcu_dereference_protected(disk->part_tbl, 1); in disk_replace_part_tbl()
1475 rcu_assign_pointer(disk->part_tbl, new_ptbl); in disk_replace_part_tbl()
1484 * disk_expand_part_tbl - expand disk->part_tbl
1485 * @disk: disk to expand part_tbl for
1488 * Expand disk->part_tbl such that @partno can fit in. disk->part_tbl
1492 * Matching bd_mutex locked or the caller is the only user of @disk.
1498 int disk_expand_part_tbl(struct gendisk *disk, int partno) in disk_expand_part_tbl() argument
1501 rcu_dereference_protected(disk->part_tbl, 1); in disk_expand_part_tbl()
1515 if (disk_max_parts(disk) && target > disk_max_parts(disk)) in disk_expand_part_tbl()
1522 disk->node_id); in disk_expand_part_tbl()
1531 disk_replace_part_tbl(disk, new_ptbl); in disk_expand_part_tbl()
1537 * @dev: the device representing this disk
1550 * will also be freed prior to the disk.
1556 struct gendisk *disk = dev_to_disk(dev); in disk_release() local
1561 disk_release_events(disk); in disk_release()
1562 kfree(disk->random); in disk_release()
1563 disk_replace_part_tbl(disk, NULL); in disk_release()
1564 hd_free_part(&disk->part0); in disk_release()
1565 if (disk->queue) in disk_release()
1566 blk_put_queue(disk->queue); in disk_release()
1567 kfree(disk); in disk_release()
1576 struct gendisk *disk = dev_to_disk(dev); in block_devnode() local
1578 if (disk->fops->devnode) in block_devnode()
1579 return disk->fops->devnode(disk, mode); in block_devnode()
1584 .name = "disk",
1592 * aggregate disk stat collector. Uses the same stats that the sysfs
1688 struct gendisk *disk = dev_to_disk(dev); in blk_lookup_devt() local
1694 if (partno < disk->minors) { in blk_lookup_devt()
1702 part = disk_get_part(disk, partno); in blk_lookup_devt()
1716 struct gendisk *disk; in __alloc_disk_node() local
1726 disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id); in __alloc_disk_node()
1727 if (!disk) in __alloc_disk_node()
1730 disk->part0.dkstats = alloc_percpu(struct disk_stats); in __alloc_disk_node()
1731 if (!disk->part0.dkstats) in __alloc_disk_node()
1734 init_rwsem(&disk->lookup_sem); in __alloc_disk_node()
1735 disk->node_id = node_id; in __alloc_disk_node()
1736 if (disk_expand_part_tbl(disk, 0)) { in __alloc_disk_node()
1737 free_percpu(disk->part0.dkstats); in __alloc_disk_node()
1741 ptbl = rcu_dereference_protected(disk->part_tbl, 1); in __alloc_disk_node()
1742 rcu_assign_pointer(ptbl->part[0], &disk->part0); in __alloc_disk_node()
1753 hd_sects_seq_init(&disk->part0); in __alloc_disk_node()
1754 if (hd_ref_init(&disk->part0)) in __alloc_disk_node()
1757 disk->minors = minors; in __alloc_disk_node()
1758 rand_initialize_disk(disk); in __alloc_disk_node()
1759 disk_to_dev(disk)->class = &block_class; in __alloc_disk_node()
1760 disk_to_dev(disk)->type = &disk_type; in __alloc_disk_node()
1761 device_initialize(disk_to_dev(disk)); in __alloc_disk_node()
1762 return disk; in __alloc_disk_node()
1765 hd_free_part(&disk->part0); in __alloc_disk_node()
1767 kfree(disk); in __alloc_disk_node()
1774 * @disk: the struct gendisk to increment the refcount for
1781 struct kobject *get_disk_and_module(struct gendisk *disk) in get_disk_and_module() argument
1786 if (!disk->fops) in get_disk_and_module()
1788 owner = disk->fops->owner; in get_disk_and_module()
1791 kobj = kobject_get_unless_zero(&disk_to_dev(disk)->kobj); in get_disk_and_module()
1803 * @disk: the struct gendisk to decrement the refcount for
1811 void put_disk(struct gendisk *disk) in put_disk() argument
1813 if (disk) in put_disk()
1814 kobject_put(&disk_to_dev(disk)->kobj); in put_disk()
1820 * @disk: the struct gendisk to decrement the refcount for
1828 void put_disk_and_module(struct gendisk *disk) in put_disk_and_module() argument
1830 if (disk) { in put_disk_and_module()
1831 struct module *owner = disk->fops->owner; in put_disk_and_module()
1833 put_disk(disk); in put_disk_and_module()
1856 void set_disk_ro(struct gendisk *disk, int flag) in set_disk_ro() argument
1861 if (disk->part0.policy != flag) { in set_disk_ro()
1862 set_disk_ro_uevent(disk, flag); in set_disk_ro()
1863 disk->part0.policy = flag; in set_disk_ro()
1866 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY); in set_disk_ro()
1884 * Disk events - monitor disk events like media change and eject request.
1888 struct gendisk *disk; /* the associated disk */ member
1917 static unsigned long disk_events_poll_jiffies(struct gendisk *disk) in disk_events_poll_jiffies() argument
1919 struct disk_events *ev = disk->ev; in disk_events_poll_jiffies()
1928 else if (disk->event_flags & DISK_EVENT_FLAG_POLL) in disk_events_poll_jiffies()
1935 * disk_block_events - block and flush disk event checking
1936 * @disk: disk to block events for
1949 void disk_block_events(struct gendisk *disk) in disk_block_events() argument
1951 struct disk_events *ev = disk->ev; in disk_block_events()
1969 cancel_delayed_work_sync(&disk->ev->dwork); in disk_block_events()
1974 static void __disk_unblock_events(struct gendisk *disk, bool check_now) in __disk_unblock_events() argument
1976 struct disk_events *ev = disk->ev; in __disk_unblock_events()
1988 intv = disk_events_poll_jiffies(disk); in __disk_unblock_events()
2000 * disk_unblock_events - unblock disk event checking
2001 * @disk: disk to unblock events for
2009 void disk_unblock_events(struct gendisk *disk) in disk_unblock_events() argument
2011 if (disk->ev) in disk_unblock_events()
2012 __disk_unblock_events(disk, false); in disk_unblock_events()
2017 * @disk: disk to check and flush events for
2020 * Schedule immediate event checking on @disk if not blocked. Events in
2022 * doesn't clear the events from @disk->ev.
2027 void disk_flush_events(struct gendisk *disk, unsigned int mask) in disk_flush_events() argument
2029 struct disk_events *ev = disk->ev; in disk_flush_events()
2044 * @disk: disk to fetch and clear events from
2047 * Disk events are synchronously checked and pending events in @mask
2053 static unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask) in disk_clear_events() argument
2055 struct disk_events *ev = disk->ev; in disk_clear_events()
2062 disk_block_events(disk); in disk_clear_events()
2079 __disk_unblock_events(disk, ev->clearing ? true : false); in disk_clear_events()
2133 struct gendisk *disk = ev->disk; in disk_check_events() local
2141 events = disk->fops->check_events(disk, clearing); in disk_check_events()
2150 intv = disk_events_poll_jiffies(disk); in disk_check_events()
2159 * @disk->events are reported, and only if DISK_EVENT_FLAG_UEVENT in disk_check_events()
2164 if ((events & disk->events & (1 << i)) && in disk_check_events()
2165 (disk->event_flags & DISK_EVENT_FLAG_UEVENT)) in disk_check_events()
2169 kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp); in disk_check_events()
2173 * A disk events enabled device has the following sysfs nodes under
2201 struct gendisk *disk = dev_to_disk(dev); in disk_events_show() local
2203 if (!(disk->event_flags & DISK_EVENT_FLAG_UEVENT)) in disk_events_show()
2206 return __disk_events_show(disk->events, buf); in disk_events_show()
2219 struct gendisk *disk = dev_to_disk(dev); in disk_events_poll_msecs_show() local
2221 if (!disk->ev) in disk_events_poll_msecs_show()
2224 return sprintf(buf, "%ld\n", disk->ev->poll_msecs); in disk_events_poll_msecs_show()
2231 struct gendisk *disk = dev_to_disk(dev); in disk_events_poll_msecs_store() local
2240 if (!disk->ev) in disk_events_poll_msecs_store()
2243 disk_block_events(disk); in disk_events_poll_msecs_store()
2244 disk->ev->poll_msecs = intv; in disk_events_poll_msecs_store()
2245 __disk_unblock_events(disk, true); in disk_events_poll_msecs_store()
2282 disk_flush_events(ev->disk, 0); in disk_events_set_dfl_poll_msecs()
2303 static void disk_alloc_events(struct gendisk *disk) in disk_alloc_events() argument
2307 if (!disk->fops->check_events || !disk->events) in disk_alloc_events()
2312 pr_warn("%s: failed to initialize events\n", disk->disk_name); in disk_alloc_events()
2317 ev->disk = disk; in disk_alloc_events()
2324 disk->ev = ev; in disk_alloc_events()
2327 static void disk_add_events(struct gendisk *disk) in disk_add_events() argument
2330 if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0) in disk_add_events()
2332 disk->disk_name); in disk_add_events()
2334 if (!disk->ev) in disk_add_events()
2338 list_add_tail(&disk->ev->node, &disk_events); in disk_add_events()
2345 __disk_unblock_events(disk, true); in disk_add_events()
2348 static void disk_del_events(struct gendisk *disk) in disk_del_events() argument
2350 if (disk->ev) { in disk_del_events()
2351 disk_block_events(disk); in disk_del_events()
2354 list_del_init(&disk->ev->node); in disk_del_events()
2358 sysfs_remove_files(&disk_to_dev(disk)->kobj, disk_events_attrs); in disk_del_events()
2361 static void disk_release_events(struct gendisk *disk) in disk_release_events() argument
2364 WARN_ON_ONCE(disk->ev && disk->ev->block != 1); in disk_release_events()
2365 kfree(disk->ev); in disk_release_events()