Lines Matching +full:full +full:- +full:hd

1 // SPDX-License-Identifier: GPL-2.0
13 #include <linux/backing-dev.h>
64 kobject_uevent_env(&disk_to_dev(disk)->kobj, KOBJ_CHANGE, envp); in set_capacity_revalidate_and_notify()
77 char *disk_name(struct gendisk *hd, int partno, char *buf) in disk_name() argument
80 snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name); in disk_name()
81 else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) in disk_name()
82 snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno); in disk_name()
84 snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno); in disk_name()
91 return disk_name(bdev->bd_disk, bdev->bd_partno, buf); in bdevname()
101 struct disk_stats *ptr = per_cpu_ptr(part->dkstats, cpu); in part_stat_read_all()
105 stat->nsecs[group] += ptr->nsecs[group]; in part_stat_read_all()
106 stat->sectors[group] += ptr->sectors[group]; in part_stat_read_all()
107 stat->ios[group] += ptr->ios[group]; in part_stat_read_all()
108 stat->merges[group] += ptr->merges[group]; in part_stat_read_all()
111 stat->io_ticks += ptr->io_ticks; in part_stat_read_all()
148 struct disk_part_tbl *ptbl = rcu_dereference(disk->part_tbl); in __disk_get_part()
150 if (unlikely(partno < 0 || partno >= ptbl->len)) in __disk_get_part()
152 return rcu_dereference(ptbl->part[partno]); in __disk_get_part()
156 * disk_get_part - get partition
183 * disk_part_iter_init - initialize partition iterator
199 ptbl = rcu_dereference(disk->part_tbl); in disk_part_iter_init()
201 piter->disk = disk; in disk_part_iter_init()
202 piter->part = NULL; in disk_part_iter_init()
205 piter->idx = ptbl->len - 1; in disk_part_iter_init()
207 piter->idx = 0; in disk_part_iter_init()
209 piter->idx = 1; in disk_part_iter_init()
211 piter->flags = flags; in disk_part_iter_init()
218 * disk_part_iter_next - proceed iterator to the next partition and return it
232 disk_put_part(piter->part); in disk_part_iter_next()
233 piter->part = NULL; in disk_part_iter_next()
237 ptbl = rcu_dereference(piter->disk->part_tbl); in disk_part_iter_next()
240 if (piter->flags & DISK_PITER_REVERSE) { in disk_part_iter_next()
241 inc = -1; in disk_part_iter_next()
242 if (piter->flags & (DISK_PITER_INCL_PART0 | in disk_part_iter_next()
244 end = -1; in disk_part_iter_next()
249 end = ptbl->len; in disk_part_iter_next()
253 for (; piter->idx != end; piter->idx += inc) { in disk_part_iter_next()
256 part = rcu_dereference(ptbl->part[piter->idx]); in disk_part_iter_next()
260 !(piter->flags & DISK_PITER_INCL_EMPTY) && in disk_part_iter_next()
261 !(piter->flags & DISK_PITER_INCL_EMPTY_PART0 && in disk_part_iter_next()
262 piter->idx == 0)) in disk_part_iter_next()
266 piter->part = part; in disk_part_iter_next()
267 piter->idx += inc; in disk_part_iter_next()
273 return piter->part; in disk_part_iter_next()
278 * disk_part_iter_exit - finish up partition iteration
288 disk_put_part(piter->part); in disk_part_iter_exit()
289 piter->part = NULL; in disk_part_iter_exit()
295 return part->start_sect <= sector && in sector_in_part()
296 sector < part->start_sect + part_nr_sects_read(part); in sector_in_part()
300 * disk_map_sector_rcu - map sector to partition
323 ptbl = rcu_dereference(disk->part_tbl); in disk_map_sector_rcu()
325 part = rcu_dereference(ptbl->last_lookup); in disk_map_sector_rcu()
329 for (i = 1; i < ptbl->len; i++) { in disk_map_sector_rcu()
330 part = rcu_dereference(ptbl->part[i]); in disk_map_sector_rcu()
335 * so use-after-free on cached & deleting partition in disk_map_sector_rcu()
340 rcu_assign_pointer(ptbl->last_lookup, part); in disk_map_sector_rcu()
345 part = &disk->part0; in disk_map_sector_rcu()
361 * True if the gendisk has at least one valid non-zero size partition.
371 ptbl = rcu_dereference(disk->part_tbl); in disk_has_partitions()
374 for (i = 1; i < ptbl->len; i++) { in disk_has_partitions()
375 if (rcu_dereference(ptbl->part[i])) { in disk_has_partitions()
398 /* index in the above - for now: assume no multimajor ranges */
410 for (dp = major_names[major_to_index(offset)]; dp; dp = dp->next) in blkdev_show()
411 if (dp->major == offset) in blkdev_show()
412 seq_printf(seqf, "%3d %s\n", dp->major, dp->name); in blkdev_show()
418 * register_blkdev - register a new block device
420 * @major: the requested major device number [1..BLKDEV_MAJOR_MAX-1]. If
428 * - if a major device number was requested in range [1..BLKDEV_MAJOR_MAX-1]
430 * - if any unused major number was requested with @major = 0 parameter
432 * [1..BLKDEV_MAJOR_MAX-1] or a negative error code otherwise
434 * See Documentation/admin-guide/devices.txt for the list of allocated
446 for (index = ARRAY_SIZE(major_names)-1; index > 0; index--) { in register_blkdev()
454 ret = -EBUSY; in register_blkdev()
463 __func__, major, BLKDEV_MAJOR_MAX-1, name); in register_blkdev()
465 ret = -EINVAL; in register_blkdev()
471 ret = -ENOMEM; in register_blkdev()
475 p->major = major; in register_blkdev()
476 strlcpy(p->name, name, sizeof(p->name)); in register_blkdev()
477 p->next = NULL; in register_blkdev()
480 for (n = &major_names[index]; *n; n = &(*n)->next) { in register_blkdev()
481 if ((*n)->major == major) in register_blkdev()
487 ret = -EBUSY; in register_blkdev()
508 for (n = &major_names[index]; *n; n = &(*n)->next) in unregister_blkdev()
509 if ((*n)->major == major) in unregister_blkdev()
511 if (!*n || strcmp((*n)->name, name)) { in unregister_blkdev()
515 *n = p->next; in unregister_blkdev()
526 * blk_mangle_minor - scatter minor numbers apart
545 int high = minor & (1 << (MINORBITS - 1 - i)); in blk_mangle_minor()
546 int distance = MINORBITS - 1 - 2 * i; in blk_mangle_minor()
558 * blk_alloc_devt - allocate a dev_t for a partition
565 * 0 on success, allocated dev_t is returned in *@devt. -errno on
577 if (part->partno < disk->minors) { in blk_alloc_devt()
578 *devt = MKDEV(disk->major, disk->first_minor + part->partno); in blk_alloc_devt()
591 return idx == -ENOSPC ? -EBUSY : idx; in blk_alloc_devt()
598 * blk_free_devt - free a dev_t
635 snprintf(buf, BDEVT_SIZE, "%-9s", tbuf); in bdevt_str()
643 * Register device numbers dev..(dev+range-1)
667 return &disk_to_dev(p)->kobj; in exact_match()
675 return -1; in exact_lock()
686 set_bit(GD_NEED_PART_SCAN, &disk->state); in disk_scan_partitions()
700 ddev->parent = parent; in register_disk()
702 dev_set_name(ddev, "%s", disk->disk_name); in register_disk()
708 WARN_ON(ddev->groups); in register_disk()
709 ddev->groups = groups; in register_disk()
714 err = sysfs_create_link(block_depr, &ddev->kobj, in register_disk()
715 kobject_name(&ddev->kobj)); 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()
741 kobject_uevent(&ddev->kobj, KOBJ_ADD); in register_disk()
746 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD); in register_disk()
749 if (disk->queue->backing_dev_info->dev) { in register_disk()
750 err = sysfs_create_link(&ddev->kobj, in register_disk()
751 &disk->queue->backing_dev_info->dev->kobj, in register_disk()
758 * __device_add_disk - add disk information to kernel list
760 * @disk: per-device partitioning information
761 * @groups: Additional per-device sysfs groups
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()
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()
818 dev->devt = devt; in __device_add_disk()
822 blk_register_region(disk_devt(disk), disk->minors, NULL, in __device_add_disk()
833 WARN_ON_ONCE(!blk_get_queue(disk->queue)); in __device_add_disk()
868 remove_inode_hash(bdev->bd_inode); in invalidate_partition()
873 * del_gendisk - remove the gendisk
905 down_write(&disk->lookup_sem); in del_gendisk()
910 invalidate_partition(disk, part->partno); 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()
934 if (!(disk->flags & GENHD_FL_HIDDEN)) in del_gendisk()
935 blk_unregister_region(disk_devt(disk), disk->minors); in del_gendisk()
939 * use-after-free issues. Note that the device number stays in del_gendisk()
940 * "in-use" until we really free the gendisk. 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()
956 /* sysfs access to bad-blocks list. */
963 if (!disk->bb) in disk_badblocks_show()
966 return badblocks_show(disk->bb, page, 0); in disk_badblocks_show()
975 if (!disk->bb) in disk_badblocks_store()
976 return -ENXIO; in disk_badblocks_store()
978 return badblocks_store(disk->bb, page, len, 0); in disk_badblocks_store()
982 * get_gendisk - get partitioning information for a given device
1009 *partno = part->partno; 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()
1029 up_read(&disk->lookup_sem); in get_gendisk()
1035 * bdget_disk - do bdget() by gendisk and partition number
1062 * print a full list of all partitions - intended for places where the root
1084 (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)) in printk_all_partitions()
1089 * numbers in hex - the same format as the root= 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()
1100 part->info ? part->info->uuid : ""); in printk_all_partitions()
1102 if (dev->parent && dev->parent->driver) in printk_all_partitions()
1104 dev->parent->driver->name); in printk_all_partitions()
1125 return ERR_PTR(-ENOMEM); in disk_seqf_start()
1127 seqf->private = iter; in disk_seqf_start()
1133 } while (skip--); in disk_seqf_start()
1143 dev = class_dev_iter_next(seqf->private); in disk_seqf_next()
1152 struct class_dev_iter *iter = seqf->private; in disk_seqf_stop()
1154 /* stop is called even after start failed :-( */ in disk_seqf_stop()
1158 seqf->private = NULL; in disk_seqf_stop()
1179 /* Don't show non-partitionable removeable devices or empty devices */ in show_partition()
1181 (sgp->flags & GENHD_FL_REMOVABLE))) in show_partition()
1183 if (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO) in show_partition()
1186 /* show the full disk and all non-0 size partitions of it */ in show_partition()
1192 disk_name(sgp, part->partno, buf)); in show_partition()
1209 if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0) in base_probe()
1210 /* Make old-style 2.4 aliases work */ in base_probe()
1211 request_module("block-major-%d", MAJOR(devt)); in base_probe()
1228 /* create top-level block dir */ in genhd_device_init()
1241 return sprintf(buf, "%d\n", disk->minors); in disk_range_show()
1258 (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0)); in disk_removable_show()
1267 (disk->flags & GENHD_FL_HIDDEN ? 1 : 0)); in disk_hidden_show()
1291 struct request_queue *q = part_to_disk(p)->queue; in part_stat_show()
1335 struct request_queue *q = part_to_disk(p)->queue; in part_inflight_show()
1351 return sprintf(buf, "%x\n", disk->flags); in disk_capability_show()
1360 return sprintf(buf, "%d\n", queue_alignment_offset(disk->queue)); in disk_alignment_offset_show()
1369 return sprintf(buf, "%d\n", queue_discard_alignment(disk->queue)); in disk_discard_alignment_show()
1391 return sprintf(buf, "%d\n", p->make_it_fail); in part_fail_show()
1402 p->make_it_fail = (i == 0) ? 0 : 1; in part_fail_store()
1408 __ATTR(make-it-fail, 0644, part_fail_show, part_fail_store);
1413 __ATTR(io-timeout-fail, 0644, part_timeout_show, part_timeout_store);
1443 if (a == &dev_attr_badblocks.attr && !disk->bb) in disk_visible()
1445 return a->mode; in disk_visible()
1459 * disk_replace_part_tbl - replace disk->part_tbl in RCU-safe way
1463 * Replace disk->part_tbl with @new_ptbl in RCU-safe way. The
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()
1478 rcu_assign_pointer(old_ptbl->last_lookup, NULL); in disk_replace_part_tbl()
1484 * disk_expand_part_tbl - expand disk->part_tbl
1488 * Expand disk->part_tbl such that @partno can fit in. disk->part_tbl
1496 * 0 on success, -errno on failure.
1501 rcu_dereference_protected(disk->part_tbl, 1); in disk_expand_part_tbl()
1503 int len = old_ptbl ? old_ptbl->len : 0; in disk_expand_part_tbl()
1512 return -EINVAL; in disk_expand_part_tbl()
1516 return -EINVAL; in disk_expand_part_tbl()
1522 disk->node_id); in disk_expand_part_tbl()
1524 return -ENOMEM; in disk_expand_part_tbl()
1526 new_ptbl->len = target; in disk_expand_part_tbl()
1529 rcu_assign_pointer(new_ptbl->part[i], old_ptbl->part[i]); in disk_expand_part_tbl()
1536 * disk_release - releases all allocated resources of the gendisk
1560 blk_free_devt(dev->devt); in disk_release()
1562 kfree(disk->random); 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()
1578 if (disk->fops->devnode) in block_devnode()
1579 return disk->fops->devnode(disk, mode); in block_devnode()
1602 struct hd_struct *hd; in diskstats_show() local
1608 if (&disk_to_dev(gp)->kobj.entry == block_class.devices.next) in diskstats_show()
1616 while ((hd = disk_part_iter_next(&piter))) { in diskstats_show()
1617 part_stat_read_all(hd, &stat); in diskstats_show()
1618 if (queue_is_mq(gp->queue)) in diskstats_show()
1619 inflight = blk_mq_in_flight(gp->queue, hd); in diskstats_show()
1621 inflight = part_in_flight(hd); in diskstats_show()
1630 MAJOR(part_devt(hd)), MINOR(part_devt(hd)), in diskstats_show()
1631 disk_name(gp, hd->partno, buf), in diskstats_show()
1694 if (partno < disk->minors) { in blk_lookup_devt()
1698 devt = MKDEV(MAJOR(dev->devt), in blk_lookup_devt()
1699 MINOR(dev->devt) + partno); in blk_lookup_devt()
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()
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()
1746 * seqcounter to read/update the part0->nr_sects. Still init 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()
1759 disk_to_dev(disk)->class = &block_class; in __alloc_disk_node()
1760 disk_to_dev(disk)->type = &disk_type; in __alloc_disk_node()
1765 hd_free_part(&disk->part0); in __alloc_disk_node()
1773 * get_disk_and_module - increments the gendisk and gendisk fops module refcount
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()
1802 * put_disk - decrements the gendisk refcount
1814 kobject_put(&disk_to_dev(disk)->kobj); in put_disk()
1819 * put_disk_and_module - decrements the module and gendisk refcount
1831 struct module *owner = disk->fops->owner; in put_disk_and_module()
1846 kobject_uevent_env(&disk_to_dev(gd)->kobj, KOBJ_CHANGE, envp); in set_disk_ro_uevent()
1851 bdev->bd_part->policy = flag; in set_device_ro()
1861 if (disk->part0.policy != flag) { in set_disk_ro()
1863 disk->part0.policy = flag; in set_disk_ro()
1868 part->policy = flag; in set_disk_ro()
1878 return bdev->bd_part->policy; in bdev_read_only()
1884 * Disk events - monitor disk events like media change and eject request.
1896 long poll_msecs; /* interval, -1 for default */
1914 /* disable in-kernel polling by default */
1919 struct disk_events *ev = disk->ev; in disk_events_poll_jiffies()
1923 * If device-specific poll interval is set, always use it. If in disk_events_poll_jiffies()
1926 if (ev->poll_msecs >= 0) in disk_events_poll_jiffies()
1927 intv_msecs = ev->poll_msecs; 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
1951 struct disk_events *ev = disk->ev; in disk_block_events()
1962 mutex_lock(&ev->block_mutex); in disk_block_events()
1964 spin_lock_irqsave(&ev->lock, flags); in disk_block_events()
1965 cancel = !ev->block++; in disk_block_events()
1966 spin_unlock_irqrestore(&ev->lock, flags); in disk_block_events()
1969 cancel_delayed_work_sync(&disk->ev->dwork); in disk_block_events()
1971 mutex_unlock(&ev->block_mutex); in disk_block_events()
1976 struct disk_events *ev = disk->ev; in __disk_unblock_events()
1980 spin_lock_irqsave(&ev->lock, flags); in __disk_unblock_events()
1982 if (WARN_ON_ONCE(ev->block <= 0)) in __disk_unblock_events()
1985 if (--ev->block) in __disk_unblock_events()
1991 &ev->dwork, 0); in __disk_unblock_events()
1994 &ev->dwork, intv); in __disk_unblock_events()
1996 spin_unlock_irqrestore(&ev->lock, flags); in __disk_unblock_events()
2000 * disk_unblock_events - unblock disk event checking
2011 if (disk->ev) in disk_unblock_events()
2016 * disk_flush_events - schedule immediate event checking and flushing
2022 * doesn't clear the events from @disk->ev.
2025 * If @mask is non-zero must be called with bdev->bd_mutex held.
2029 struct disk_events *ev = disk->ev; in disk_flush_events()
2034 spin_lock_irq(&ev->lock); in disk_flush_events()
2035 ev->clearing |= mask; in disk_flush_events()
2036 if (!ev->block) in disk_flush_events()
2038 &ev->dwork, 0); in disk_flush_events()
2039 spin_unlock_irq(&ev->lock); in disk_flush_events()
2043 * disk_clear_events - synchronously check, clear and return pending events
2055 struct disk_events *ev = disk->ev; in disk_clear_events()
2065 * store the union of mask and ev->clearing on the stack so that the in disk_clear_events()
2066 * race with disk_flush_events does not cause ambiguity (ev->clearing in disk_clear_events()
2069 spin_lock_irq(&ev->lock); in disk_clear_events()
2070 clearing |= ev->clearing; in disk_clear_events()
2071 ev->clearing = 0; in disk_clear_events()
2072 spin_unlock_irq(&ev->lock); in disk_clear_events()
2076 * if ev->clearing is not 0, the disk_flush_events got called in the in disk_clear_events()
2079 __disk_unblock_events(disk, ev->clearing ? true : false); in disk_clear_events()
2082 spin_lock_irq(&ev->lock); in disk_clear_events()
2083 pending = ev->pending & mask; in disk_clear_events()
2084 ev->pending &= ~mask; in disk_clear_events()
2085 spin_unlock_irq(&ev->lock); in disk_clear_events()
2092 * bdev_check_media_change - check if a removable media has been changed
2105 events = disk_clear_events(bdev->bd_disk, DISK_EVENT_MEDIA_CHANGE | in bdev_check_media_change()
2112 bdev->bd_disk->disk_name); in bdev_check_media_change()
2113 set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state); in bdev_check_media_change()
2127 disk_check_events(ev, &ev->clearing); in disk_events_workfn()
2133 struct gendisk *disk = ev->disk; in disk_check_events()
2141 events = disk->fops->check_events(disk, clearing); in disk_check_events()
2144 spin_lock_irq(&ev->lock); in disk_check_events()
2146 events &= ~ev->pending; in disk_check_events()
2147 ev->pending |= events; in disk_check_events()
2151 if (!ev->block && intv) in disk_check_events()
2153 &ev->dwork, intv); in disk_check_events()
2155 spin_unlock_irq(&ev->lock); 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()
2179 * events_poll_msecs : polling interval, 0: disable, -1: system default
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()
2221 if (!disk->ev) in disk_events_poll_msecs_show()
2222 return sprintf(buf, "-1\n"); in disk_events_poll_msecs_show()
2224 return sprintf(buf, "%ld\n", disk->ev->poll_msecs); in disk_events_poll_msecs_show()
2235 return -EINVAL; in disk_events_poll_msecs_store()
2237 if (intv < 0 && intv != -1) in disk_events_poll_msecs_store()
2238 return -EINVAL; in disk_events_poll_msecs_store()
2240 if (!disk->ev) in disk_events_poll_msecs_store()
2241 return -ENODEV; in disk_events_poll_msecs_store()
2244 disk->ev->poll_msecs = intv; in disk_events_poll_msecs_store()
2282 disk_flush_events(ev->disk, 0); in disk_events_set_dfl_poll_msecs()
2301 * disk_{alloc|add|del|release}_events - initialize and destroy disk_events.
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()
2316 INIT_LIST_HEAD(&ev->node); in disk_alloc_events()
2317 ev->disk = disk; in disk_alloc_events()
2318 spin_lock_init(&ev->lock); in disk_alloc_events()
2319 mutex_init(&ev->block_mutex); in disk_alloc_events()
2320 ev->block = 1; in disk_alloc_events()
2321 ev->poll_msecs = -1; in disk_alloc_events()
2322 INIT_DELAYED_WORK(&ev->dwork, disk_events_workfn); in disk_alloc_events()
2324 disk->ev = ev; in disk_alloc_events()
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()
2350 if (disk->ev) { 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()
2364 WARN_ON_ONCE(disk->ev && disk->ev->block != 1); in disk_release_events()
2365 kfree(disk->ev); in disk_release_events()