Commit 90118e03 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Li Nan
Browse files

block: add the events* attributes to disk_attrs

mainline inclusion
from mainline-v5.14-rc1
commit 2bc8cda5
category: bugfix
bugzilla: 188733

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=2bc8cda5ea4b42ff78be1b11011092d57b424d37



----------------------------------------

Add the events attributes to the disk_attrs array, which ensures they are
added by the driver core when the device is created rather than adding
them after the device has been added, which is racy versus uevents and
requires more boilerplate code.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Link: https://lore.kernel.org/r/20210624073843.251178-3-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
conflict:
  block/genhd.c
Signed-off-by: default avatarZhong Jinghua <zhongjinghua@huawei.com>
Signed-off-by: default avatarLi Nan <linan122@huawei.com>
parent da0bafb2
Loading
Loading
Loading
Loading
+10 −19
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ static int disk_alloc_events(struct gendisk *disk);
static void disk_add_events(struct gendisk *disk);
static void disk_del_events(struct gendisk *disk);
static void disk_release_events(struct gendisk *disk);
static struct device_attribute dev_attr_events;
static struct device_attribute dev_attr_events_async;
static struct device_attribute dev_attr_events_poll_msecs;

/*
 * Set disk capacity and notify if the size is not currently
@@ -1513,6 +1516,9 @@ static struct attribute *disk_attrs[] = {
	&dev_attr_stat.attr,
	&dev_attr_inflight.attr,
	&dev_attr_badblocks.attr,
	&dev_attr_events.attr,
	&dev_attr_events_async.attr,
	&dev_attr_events_poll_msecs.attr,
#ifdef CONFIG_FAIL_MAKE_REQUEST
	&dev_attr_fail.attr,
#endif
@@ -2343,19 +2349,11 @@ static ssize_t disk_events_poll_msecs_store(struct device *dev,
	return count;
}

static const DEVICE_ATTR(events, 0444, disk_events_show, NULL);
static const DEVICE_ATTR(events_async, 0444, disk_events_async_show, NULL);
static const DEVICE_ATTR(events_poll_msecs, 0644,
			 disk_events_poll_msecs_show,
static DEVICE_ATTR(events, 0444, disk_events_show, NULL);
static DEVICE_ATTR(events_async, 0444, disk_events_async_show, NULL);
static DEVICE_ATTR(events_poll_msecs, 0644, disk_events_poll_msecs_show,
		   disk_events_poll_msecs_store);

static const struct attribute *disk_events_attrs[] = {
	&dev_attr_events.attr,
	&dev_attr_events_async.attr,
	&dev_attr_events_poll_msecs.attr,
	NULL,
};

/*
 * The default polling interval can be specified by the kernel
 * parameter block.events_dfl_poll_msecs which defaults to 0
@@ -2423,11 +2421,6 @@ static int disk_alloc_events(struct gendisk *disk)

static void disk_add_events(struct gendisk *disk)
{
	/* FIXME: error handling */
	if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0)
		pr_warn("%s: failed to create sysfs files for events\n",
			disk->disk_name);

	if (!disk->ev)
		return;

@@ -2451,8 +2444,6 @@ static void disk_del_events(struct gendisk *disk)
		list_del_init(&disk->ev->node);
		mutex_unlock(&disk_events_mutex);
	}

	sysfs_remove_files(&disk_to_dev(disk)->kobj, disk_events_attrs);
}

static void disk_release_events(struct gendisk *disk)