From patchwork Thu Jun 30 01:59:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9206497 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 60A566075F for ; Thu, 30 Jun 2016 02:05:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FBA2285F0 for ; Thu, 30 Jun 2016 02:05:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4310A285FD; Thu, 30 Jun 2016 02:05:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D96E428533 for ; Thu, 30 Jun 2016 02:05:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751527AbcF3CAd (ORCPT ); Wed, 29 Jun 2016 22:00:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41767 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751486AbcF3CA3 (ORCPT ); Wed, 29 Jun 2016 22:00:29 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 992628553D; Thu, 30 Jun 2016 02:00:28 +0000 (UTC) Received: from ad.usersys.redhat.com (dhcp-15-133.nay.redhat.com [10.66.15.133]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5U201qO029340; Wed, 29 Jun 2016 22:00:22 -0400 From: Fam Zheng To: linux-kernel@vger.kernel.org Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Jens Axboe , "Ed L. Cashin" , Jiri Kosina , "Michael S. Tsirkin" , Minchan Kim , Nitin Gupta , Sergey Senozhatsky , Shaohua Li , Ulf Hansson , David Woodhouse , Brian Norris , Keith Busch , linuxppc-dev@lists.ozlabs.org, linux-block@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-raid@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-nvme@lists.infradead.org, Christoph Hellwig , famz@redhat.com Subject: [PATCH v2 03/12] virtio-blk: Generate uevent after attribute available Date: Thu, 30 Jun 2016 09:59:44 +0800 Message-Id: <20160630015953.6888-4-famz@redhat.com> In-Reply-To: <20160630015953.6888-1-famz@redhat.com> References: <20160630015953.6888-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 30 Jun 2016 02:00:28 +0000 (UTC) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/block/virtio_blk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index f3a59f9..cd9a036 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -733,7 +733,7 @@ static int virtblk_probe(struct virtio_device *vdev) virtio_device_ready(vdev); - add_disk(vblk->disk, true); + add_disk(vblk->disk, false); err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial); if (err) goto out_del_disk; @@ -746,6 +746,7 @@ static int virtblk_probe(struct virtio_device *vdev) &dev_attr_cache_type_ro); if (err) goto out_del_disk; + disk_gen_uevents(vblk->disk); return 0; out_del_disk: