linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: Jens Axboe <axboe@kernel.dk>, Tejun Heo <tj@kernel.org>,
	Hannes Reinecke <hare@suse.de>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: James Bottomley <jejb@linux.vnet.ibm.com>,
	Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <Bart.VanAssche@sandisk.com>,
	Martin Wilck <mwilck@suse.com>,
	linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-ide@vger.kernel.org
Subject: [PATCH RESEND v2 2/5] block: disk_events: introduce event flags
Date: Fri, 22 Mar 2019 23:43:50 +0100	[thread overview]
Message-ID: <20190322224353.11088-3-mwilck@suse.com> (raw)
In-Reply-To: <20190322224353.11088-1-mwilck@suse.com>

Currently, an empty disk->events field tells the block layer not to forward
media change events to user space. This was done in
commit 7c88a168da80 ("block: don't propagate unlisted DISK_EVENTs to userland")
in order to avoid events from "fringe" drivers to be forwarded to user
space. By doing so, the block layer lost the information which events were
supported by a particular block device, and most importantly, whether or
not a given device supports media change events at all.

Prepare for not interpreting the "events" field this way in the future any
more. This is done by adding two flag bits that can be set to have the
device treated like one that has the "events" field set to a non-zero value
before. This applies only to the sd and sr drivers, which are changed to
set the new flags.

The new flags are DISK_EVENT_FLAG_POLL to enforce polling of the device for
synchronous events, and DISK_EVENT_FLAG_UEVENT to tell the blocklayer to
generate udev events from kernel events. They can easily be fit in the int
reserved for event bits.

This patch doesn't change behavior.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 block/genhd.c         | 15 ++++++++++-----
 drivers/scsi/sd.c     |  3 ++-
 drivers/scsi/sr.c     |  3 ++-
 include/linux/genhd.h |  7 +++++++
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index ee76de0..cc6c52d1 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -1632,7 +1632,7 @@ static unsigned long disk_events_poll_jiffies(struct gendisk *disk)
 	 */
 	if (ev->poll_msecs >= 0)
 		intv_msecs = ev->poll_msecs;
-	else if (disk->events)
+	else if (disk->events & DISK_EVENT_FLAG_POLL)
 		intv_msecs = disk_events_dfl_poll_msecs;
 
 	return msecs_to_jiffies(intv_msecs);
@@ -1842,11 +1842,13 @@ static void disk_check_events(struct disk_events *ev,
 
 	/*
 	 * Tell userland about new events.  Only the events listed in
-	 * @disk->events are reported.  Unlisted events are processed the
-	 * same internally but never get reported to userland.
+	 * @disk->events are reported, and only if DISK_EVENT_FLAG_UEVENT
+	 * is set. Otherwise, events are processed internally but never
+	 * get reported to userland.
 	 */
 	for (i = 0; i < ARRAY_SIZE(disk_uevents); i++)
-		if (events & disk->events & (1 << i))
+		if (events & disk->events & (1 << i) &&
+		    disk->events & DISK_EVENT_FLAG_UEVENT)
 			envp[nr_events++] = disk_uevents[i];
 
 	if (nr_events)
@@ -1884,7 +1886,10 @@ static ssize_t disk_events_show(struct device *dev,
 {
 	struct gendisk *disk = dev_to_disk(dev);
 
-	return __disk_events_show(disk->events, buf);
+	if (!(disk->events & DISK_EVENT_FLAG_UEVENT))
+		return 0;
+
+	return __disk_events_show(disk->events & DISK_EVENT_TYPES_MASK, buf);
 }
 
 static ssize_t disk_events_async_show(struct device *dev,
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 251db30..71a8a1b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3326,7 +3326,8 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
 	gd->flags = GENHD_FL_EXT_DEVT;
 	if (sdp->removable) {
 		gd->flags |= GENHD_FL_REMOVABLE;
-		gd->events |= DISK_EVENT_MEDIA_CHANGE;
+		gd->events |= DISK_EVENT_MEDIA_CHANGE |
+			DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT;
 	}
 
 	blk_pm_runtime_init(sdp->request_queue, dev);
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 039c27c2..f7a9d34 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -715,7 +715,8 @@ static int sr_probe(struct device *dev)
 	sprintf(disk->disk_name, "sr%d", minor);
 	disk->fops = &sr_bdops;
 	disk->flags = GENHD_FL_CD | GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE;
-	disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST;
+	disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST
+		| DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT;
 
 	blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT);
 
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 5f78edb..a3d5b1c 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -148,8 +148,15 @@ struct hd_struct {
 enum {
 	DISK_EVENT_MEDIA_CHANGE			= 1 << 0, /* media changed */
 	DISK_EVENT_EJECT_REQUEST		= 1 << 1, /* eject requested */
+	/* Poll even if events_poll_msecs is unset */
+	DISK_EVENT_FLAG_POLL			= 1 << 16,
+	/* Forward events to udev */
+	DISK_EVENT_FLAG_UEVENT			= 1 << 17,
 };
 
+#define DISK_EVENT_TYPES_MASK \
+	(DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST)
+
 struct disk_part_tbl {
 	struct rcu_head rcu_head;
 	int len;
-- 
2.21.0


  parent reply	other threads:[~2019-03-22 22:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 22:43 [PATCH RESEND v2 0/5] block: skip media change event handling if unsupported Martin Wilck
2019-03-22 22:43 ` [PATCH RESEND v2 1/5] block: genhd: remove async_events field Martin Wilck
2019-03-25  7:32   ` Hannes Reinecke
2019-03-27  8:18   ` Christoph Hellwig
2019-03-22 22:43 ` Martin Wilck [this message]
2019-03-25  7:34   ` [PATCH RESEND v2 2/5] block: disk_events: introduce event flags Hannes Reinecke
2019-03-27  8:20   ` Christoph Hellwig
2019-03-22 22:43 ` [PATCH RESEND v2 3/5] Revert "ide: unexport DISK_EVENT_MEDIA_CHANGE for ide-gd and ide-cd" Martin Wilck
2019-03-25  7:37   ` Hannes Reinecke
2019-03-27  8:21   ` Christoph Hellwig
2019-03-22 22:43 ` [PATCH RESEND v2 4/5] Revert "block: unexport DISK_EVENT_MEDIA_CHANGE for legacy/fringe drivers" Martin Wilck
2019-03-25  7:38   ` Hannes Reinecke
2019-03-27  8:21   ` Christoph Hellwig
2019-03-22 22:43 ` [PATCH RESEND v2 5/5] block: check_events: don't bother with events if unsupported Martin Wilck
2019-03-25  7:39   ` Hannes Reinecke
2019-03-27  8:22   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190322224353.11088-3-mwilck@suse.com \
    --to=mwilck@suse.com \
    --cc=Bart.VanAssche@sandisk.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).