From patchwork Wed Jul 25 06:28:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 10543483 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 614EFA635 for ; Wed, 25 Jul 2018 06:28:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5282229651 for ; Wed, 25 Jul 2018 06:28:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 463582965E; Wed, 25 Jul 2018 06:28:47 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 1189329646 for ; Wed, 25 Jul 2018 06:28:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728337AbeGYHiy (ORCPT ); Wed, 25 Jul 2018 03:38:54 -0400 Received: from mx2.suse.de ([195.135.220.15]:47154 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728210AbeGYHiy (ORCPT ); Wed, 25 Jul 2018 03:38:54 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C14AAAE84; Wed, 25 Jul 2018 06:28:41 +0000 (UTC) From: Hannes Reinecke To: Jens Axboe Cc: Christoph Hellwig , Keith Busch , Sagi Grimberg , linux-block@vger.kernel.org, linux-nvme@lists.infradead.org, Martin Wilck , Hannes Reinecke , Hannes Reinecke Subject: [PATCH 2/5] block: genhd: add device_add_disk_with_groups Date: Wed, 25 Jul 2018 08:28:37 +0200 Message-Id: <20180725062840.94114-3-hare@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180725062840.94114-1-hare@suse.de> References: <20180725062840.94114-1-hare@suse.de> 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 Update __device_add_disk() to take an 'groups' argument so that individual drivers can register a device with additional sysfs attributes. This avoids race condition the driver would otherwise have if these groups need to be created with sysfs_add_groups(). Signed-off-by: Martin Wilck Signed-off-by: Hannes Reinecke --- block/genhd.c | 28 +++++++++++++++++++++++----- include/linux/genhd.h | 3 +++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index cfa7f4f78435..fbe27cb2c9d7 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -567,7 +567,8 @@ static int exact_lock(dev_t devt, void *data) return 0; } -static void register_disk(struct device *parent, struct gendisk *disk) +static void register_disk(struct device *parent, struct gendisk *disk, + const struct attribute_group **groups) { struct device *ddev = disk_to_dev(disk); struct block_device *bdev; @@ -582,6 +583,10 @@ static void register_disk(struct device *parent, struct gendisk *disk) /* delay uevents, until we scanned partition table */ dev_set_uevent_suppress(ddev, 1); + if (groups) { + WARN_ON(ddev->groups); + ddev->groups = groups; + } if (device_add(ddev)) return; if (!sysfs_deprecated) { @@ -647,13 +652,15 @@ static void register_disk(struct device *parent, struct gendisk *disk) * __device_add_disk - add disk information to kernel list * @parent: parent device for the disk * @disk: per-device partitioning information + * @groups: Additional per-device sysfs groups * * This function registers the partitioning information in @disk * with the kernel. * * FIXME: error handling */ -static void __device_add_disk(struct device *parent, struct gendisk *disk) +static void __device_add_disk(struct device *parent, struct gendisk *disk, + const struct attribute_group **groups) { dev_t devt; int retval; @@ -696,7 +703,7 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk) blk_register_region(disk_devt(disk), disk->minors, NULL, exact_match, exact_lock, disk); } - register_disk(parent, disk); + register_disk(parent, disk, groups); } void __device_get_disk(struct gendisk *disk) @@ -711,9 +718,20 @@ void __device_get_disk(struct gendisk *disk) blk_integrity_add(disk); } +void device_add_disk_with_groups(struct device *parent, struct gendisk *disk, + const struct attribute_group **groups) +{ + __device_add_disk(parent, disk, groups); + + blk_register_queue(disk); + + __device_get_disk(disk); +} +EXPORT_SYMBOL(device_add_disk_with_groups); + void device_add_disk(struct device *parent, struct gendisk *disk) { - __device_add_disk(parent, disk); + __device_add_disk(parent, disk, NULL); blk_register_queue(disk); @@ -723,7 +741,7 @@ EXPORT_SYMBOL(device_add_disk); void device_add_disk_no_queue_reg(struct device *parent, struct gendisk *disk) { - __device_add_disk(parent, disk); + __device_add_disk(parent, disk, NULL); __device_get_disk(disk); } EXPORT_SYMBOL(device_add_disk_no_queue_reg); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 6cb8a5789668..f41152979296 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -394,6 +394,9 @@ extern void part_round_stats(struct request_queue *q, int cpu, struct hd_struct /* block/genhd.c */ extern void device_add_disk(struct device *parent, struct gendisk *disk); +extern void device_add_disk_with_groups(struct device *parent, + struct gendisk *disk, + const struct attribute_group **groups); static inline void add_disk(struct gendisk *disk) { device_add_disk(NULL, disk);