linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio-blk: Generate uevent after attribute available
@ 2016-06-28  2:39 Fam Zheng
  2016-06-28 11:45 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Fam Zheng @ 2016-06-28  2:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: Michael S. Tsirkin, virtualization, famz

Userspace listens to the KOBJ_ADD uevent generated in add_disk. At that
point we haven't created the serial attribute file, therefore depending
on how fast udev reacts, the /dev/disk/by-id/ entry doesn't always get
created.

This race condition can be easily reproduced by hot plugging a number of
virtio-blk disks.

Also in systemd, there used to be a related workaround in udev rules
called 'WAIT_FOR="serial"', but it is removed in later versions.

Now let's generate a KOBJ_CHANGE event after the attributes are ready.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 drivers/block/virtio_blk.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 42758b5..5056007 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -567,6 +567,7 @@ static int virtblk_probe(struct virtio_device *vdev)
 {
 	struct virtio_blk *vblk;
 	struct request_queue *q;
+	struct device *ddev;
 	int err, index;
 
 	u64 cap;
@@ -746,6 +747,8 @@ static int virtblk_probe(struct virtio_device *vdev)
 					 &dev_attr_cache_type_ro);
 	if (err)
 		goto out_del_disk;
+	ddev = disk_to_dev(vblk->disk);
+	kobject_uevent(&ddev->kobj, KOBJ_CHANGE);
 	return 0;
 
 out_del_disk:
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] virtio-blk: Generate uevent after attribute available
  2016-06-28  2:39 [PATCH] virtio-blk: Generate uevent after attribute available Fam Zheng
@ 2016-06-28 11:45 ` Christoph Hellwig
  2016-06-29  1:24   ` Fam Zheng
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2016-06-28 11:45 UTC (permalink / raw)
  To: Fam Zheng; +Cc: linux-kernel, Michael S. Tsirkin, virtualization

On Tue, Jun 28, 2016 at 10:39:15AM +0800, Fam Zheng wrote:
> Userspace listens to the KOBJ_ADD uevent generated in add_disk. At that
> point we haven't created the serial attribute file, therefore depending
> on how fast udev reacts, the /dev/disk/by-id/ entry doesn't always get
> created.
> 
> This race condition can be easily reproduced by hot plugging a number of
> virtio-blk disks.
> 
> Also in systemd, there used to be a related workaround in udev rules
> called 'WAIT_FOR="serial"', but it is removed in later versions.
> 
> Now let's generate a KOBJ_CHANGE event after the attributes are ready.

The same race is present in other drivers as well, e.g. nvme.  Please
find a way to make this work properly without needing to hack every
driver to send events manually.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] virtio-blk: Generate uevent after attribute available
  2016-06-28 11:45 ` Christoph Hellwig
@ 2016-06-29  1:24   ` Fam Zheng
  2016-09-02 22:56     ` Michael S. Tsirkin
  0 siblings, 1 reply; 5+ messages in thread
From: Fam Zheng @ 2016-06-29  1:24 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-kernel, Michael S. Tsirkin, virtualization

On Tue, 06/28 04:45, Christoph Hellwig wrote:
> On Tue, Jun 28, 2016 at 10:39:15AM +0800, Fam Zheng wrote:
> > Userspace listens to the KOBJ_ADD uevent generated in add_disk. At that
> > point we haven't created the serial attribute file, therefore depending
> > on how fast udev reacts, the /dev/disk/by-id/ entry doesn't always get
> > created.
> > 
> > This race condition can be easily reproduced by hot plugging a number of
> > virtio-blk disks.
> > 
> > Also in systemd, there used to be a related workaround in udev rules
> > called 'WAIT_FOR="serial"', but it is removed in later versions.
> > 
> > Now let's generate a KOBJ_CHANGE event after the attributes are ready.
> 
> The same race is present in other drivers as well, e.g. nvme.  Please
> find a way to make this work properly without needing to hack every
> driver to send events manually.

OK, I'll take a look today!

Fam

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] virtio-blk: Generate uevent after attribute available
  2016-06-29  1:24   ` Fam Zheng
@ 2016-09-02 22:56     ` Michael S. Tsirkin
  2016-09-03  7:08       ` Fam Zheng
  0 siblings, 1 reply; 5+ messages in thread
From: Michael S. Tsirkin @ 2016-09-02 22:56 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Christoph Hellwig, linux-kernel, virtualization

On Wed, Jun 29, 2016 at 09:24:15AM +0800, Fam Zheng wrote:
> On Tue, 06/28 04:45, Christoph Hellwig wrote:
> > On Tue, Jun 28, 2016 at 10:39:15AM +0800, Fam Zheng wrote:
> > > Userspace listens to the KOBJ_ADD uevent generated in add_disk. At that
> > > point we haven't created the serial attribute file, therefore depending
> > > on how fast udev reacts, the /dev/disk/by-id/ entry doesn't always get
> > > created.
> > > 
> > > This race condition can be easily reproduced by hot plugging a number of
> > > virtio-blk disks.
> > > 
> > > Also in systemd, there used to be a related workaround in udev rules
> > > called 'WAIT_FOR="serial"', but it is removed in later versions.
> > > 
> > > Now let's generate a KOBJ_CHANGE event after the attributes are ready.
> > 
> > The same race is present in other drivers as well, e.g. nvme.  Please
> > find a way to make this work properly without needing to hack every
> > driver to send events manually.
> 
> OK, I'll take a look today!
> 
> Fam

Was this fixed in the generic code?

-- 
MST

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] virtio-blk: Generate uevent after attribute available
  2016-09-02 22:56     ` Michael S. Tsirkin
@ 2016-09-03  7:08       ` Fam Zheng
  0 siblings, 0 replies; 5+ messages in thread
From: Fam Zheng @ 2016-09-03  7:08 UTC (permalink / raw)
  To: Michael S. Tsirkin; +Cc: Christoph Hellwig, linux-kernel, virtualization

On Sat, 09/03 01:56, Michael S. Tsirkin wrote:
> On Wed, Jun 29, 2016 at 09:24:15AM +0800, Fam Zheng wrote:
> > On Tue, 06/28 04:45, Christoph Hellwig wrote:
> > > On Tue, Jun 28, 2016 at 10:39:15AM +0800, Fam Zheng wrote:
> > > > Userspace listens to the KOBJ_ADD uevent generated in add_disk. At that
> > > > point we haven't created the serial attribute file, therefore depending
> > > > on how fast udev reacts, the /dev/disk/by-id/ entry doesn't always get
> > > > created.
> > > > 
> > > > This race condition can be easily reproduced by hot plugging a number of
> > > > virtio-blk disks.
> > > > 
> > > > Also in systemd, there used to be a related workaround in udev rules
> > > > called 'WAIT_FOR="serial"', but it is removed in later versions.
> > > > 
> > > > Now let's generate a KOBJ_CHANGE event after the attributes are ready.
> > > 
> > > The same race is present in other drivers as well, e.g. nvme.  Please
> > > find a way to make this work properly without needing to hack every
> > > driver to send events manually.
> > 
> > OK, I'll take a look today!
> > 
> > Fam
> 
> Was this fixed in the generic code?

A proposed fix is:

https://lkml.org/lkml/2016/8/17/81

Fam

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-03  7:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-28  2:39 [PATCH] virtio-blk: Generate uevent after attribute available Fam Zheng
2016-06-28 11:45 ` Christoph Hellwig
2016-06-29  1:24   ` Fam Zheng
2016-09-02 22:56     ` Michael S. Tsirkin
2016-09-03  7:08       ` Fam Zheng

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).