From patchwork Mon Aug 13 17:25:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10564543 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 E4D161815 for ; Mon, 13 Aug 2018 17:25:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8D1A296BC for ; Mon, 13 Aug 2018 17:25:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD29A296CB; Mon, 13 Aug 2018 17:25:34 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 16E30296BC for ; Mon, 13 Aug 2018 17:25:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730133AbeHMUIl (ORCPT ); Mon, 13 Aug 2018 16:08:41 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:12170 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729478AbeHMUIl (ORCPT ); Mon, 13 Aug 2018 16:08:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1534181132; x=1565717132; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=e96HnAaI1edoUasqvcb35RW2kCmLTdB2/jLnJXM5Xuk=; b=YTpyj8/9YY0+1KAwxcscWYM68sNG3bRTZ5HesmKm5kC5MfVq+pqaLMfe tk1n+XC5gQ+g5WYtGM8MuZufxdcPOWczofOBo2X7M2sx67OnSV6/QBd1h zMEhVGFI6Pbhcwx3pAfWDFhLeZf1qSjshWjqpctbd7szLEO3YkU3PqgYn MWAXpoP1XwYJ7qWXREs3/jjkj9UJKECk5ETlZlXUPIf0iV+AP3uGUCXeO DPAh9Euju7aDso0MaR7PaSC/vWEhyL404fbaLiXotIMzdmMeh7kTUSapB FklaYpo6s/PUBKGBtakZ62vvi+O+YoztaWLQt+c41tPD1mf2HfGRej0cz w==; X-IronPort-AV: E=Sophos;i="5.53,234,1531756800"; d="scan'208";a="191415865" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Aug 2018 01:25:32 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP; 13 Aug 2018 10:13:34 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com ([10.111.67.248]) by uls-op-cesaip01.wdc.com with ESMTP; 13 Aug 2018 10:25:32 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Greg Kroah-Hartman , Bart Van Assche , Keith Busch , Sagi Grimberg , Matias Bjorling , stable@vger.kernel.org Subject: [PATCH v2 1/2] block: Introduce alloc_disk_node_attr() Date: Mon, 13 Aug 2018 10:25:30 -0700 Message-Id: <20180813172531.7451-2-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180813172531.7451-1-bart.vanassche@wdc.com> References: <20180813172531.7451-1-bart.vanassche@wdc.com> 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 This patch does not change the behavior of any existing code but introduces a function that will be used by the next patch. Signed-off-by: Bart Van Assche Cc: Keith Busch Cc: Christoph Hellwig Cc: Greg Kroah-Hartman Cc: Sagi Grimberg Cc: Matias Bjorling Cc: --- block/genhd.c | 26 ++++++++++++++++++++++++-- include/linux/genhd.h | 13 +++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 8cc719a37b32..3b643152907d 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1413,10 +1413,20 @@ dev_t blk_lookup_devt(const char *name, int partno) } EXPORT_SYMBOL(blk_lookup_devt); -struct gendisk *__alloc_disk_node(int minors, int node_id) +/** + * __alloc_disk_node - allocate a gendisk structure and initialize it + * @minors: number of partitions to allocate memory for + * @node_id: NUMA node to allocate memory from + * @ag: NULL or pointer to a NULL-terminated array with attribute groups that + * must be attached to the disk_to_dev() of the allocated disk structure + */ +struct gendisk *__alloc_disk_node(int minors, int node_id, + const struct attribute_group **ag) { struct gendisk *disk; struct disk_part_tbl *ptbl; + const struct attribute_group **agp; + int num_groups = 0; if (minors > DISK_MAX_PARTS) { printk(KERN_ERR @@ -1425,7 +1435,15 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) minors = DISK_MAX_PARTS; } - disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id); + if (ag) { + for (agp = ag; *agp; agp++) + num_groups++; + /* Only count the terminating NULL if the array is not empty. */ + if (num_groups) + num_groups++; + } + disk = kzalloc_node(struct_size(disk, ag, num_groups), GFP_KERNEL, + node_id); if (disk) { if (!init_part_stats(&disk->part0)) { kfree(disk); @@ -1461,6 +1479,10 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) rand_initialize_disk(disk); disk_to_dev(disk)->class = &block_class; disk_to_dev(disk)->type = &disk_type; + if (num_groups) { + memcpy(disk->ag, ag, num_groups * sizeof(ag)); + disk_to_dev(disk)->groups = disk->ag; + } device_initialize(disk_to_dev(disk)); } return disk; diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 57864422a2c8..50ab6cf77fdf 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -211,6 +211,11 @@ struct gendisk { int node_id; struct badblocks *bb; struct lockdep_map lockdep_map; + /* + * Storage space for NULL-terminated attribute group array for + * disk_to_dev() of this gendisk structure. + */ + const struct attribute_group *ag[0]; }; static inline struct gendisk *part_to_disk(struct hd_struct *part) @@ -608,7 +613,8 @@ extern void __delete_partition(struct percpu_ref *); extern void delete_partition(struct gendisk *, int); extern void printk_all_partitions(void); -extern struct gendisk *__alloc_disk_node(int minors, int node_id); +extern struct gendisk *__alloc_disk_node(int minors, int node_id, + const struct attribute_group **ag); extern struct kobject *get_disk_and_module(struct gendisk *disk); extern void put_disk(struct gendisk *disk); extern void put_disk_and_module(struct gendisk *disk); @@ -634,6 +640,9 @@ extern ssize_t part_fail_store(struct device *dev, #endif /* CONFIG_FAIL_MAKE_REQUEST */ #define alloc_disk_node(minors, node_id) \ + alloc_disk_node_attr(minors, node_id, NULL) + +#define alloc_disk_node_attr(minors, node_id, ag) \ ({ \ static struct lock_class_key __key; \ const char *__name; \ @@ -641,7 +650,7 @@ extern ssize_t part_fail_store(struct device *dev, \ __name = "(gendisk_completion)"#minors"("#node_id")"; \ \ - __disk = __alloc_disk_node(minors, node_id); \ + __disk = __alloc_disk_node(minors, node_id, ag); \ \ if (__disk) \ lockdep_init_map(&__disk->lockdep_map, __name, &__key, 0); \