From patchwork Mon Oct 2 16:10:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Hansen X-Patchwork-Id: 9980989 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 850AE60375 for ; Mon, 2 Oct 2017 16:09:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 775B128773 for ; Mon, 2 Oct 2017 16:09:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C4AC2877E; Mon, 2 Oct 2017 16:09:13 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 2900928773 for ; Mon, 2 Oct 2017 16:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751712AbdJBQJL (ORCPT ); Mon, 2 Oct 2017 12:09:11 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:34361 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751082AbdJBQJK (ORCPT ); Mon, 2 Oct 2017 12:09:10 -0400 Received: by mail-qk0-f194.google.com with SMTP id b124so1559309qke.1; Mon, 02 Oct 2017 09:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=YmQgzcOFYLnP7hmH53AqpjPeQoEILqZPEbeCt8Cs+rg=; b=TNYVQJLlsx+pY3N35bAcFjcxiYqgikEzTRZsMl8AUyf+SdPkwDgaJCqzmlfePxW+4B ADwmJVc9mpxUuAJxBvPnQCBdpF560aFYlQRTG9AipCLe8LyXA6EuuJ8QWlOFyUmA5KNc jdhdQtEtE3cGtWqZnE8tTI/qXA8H6GxIKFOWmSMpIski13DQVp5+YODnPob8wGtkQddm 85F6X3gp59PXLBIjrgpJ/Kz4PryQVWPpf+qE7ALep0XtNxpuLCJ+grLdjvv8/kH/vAMW LHdgZ20XMeLVkfYJWTwUwrVhcOfrac/t1Ed4dSzuX9OKPNKJkhNSOUDN5dhJTGTaLUy5 2m0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=YmQgzcOFYLnP7hmH53AqpjPeQoEILqZPEbeCt8Cs+rg=; b=OP+k02/B7YFbt++UJJDMwVdou9nw43YwtQYZSJcU7qKHZcV7QlMMJrScALZ2Ts12/Y Bk1gaBcsHIMpKD6nQsugiz0TehBMr+sjVkOuMKOzLpr7L8ShuWxyB6IBWjn32Ro0ye53 Cv1/Fedbva3jq0vLw0WHzc+sdQkRaPadxEgsRlWPvSuY8G5bmRf46TaNmRinr0n0Gvdp qB8G2OVZgaucQYaVFf8DreOtSkNKEX+JCEf3y9fMI5ktCLELiDjaV7enB6T0RAZ7LW0t JYZbmt3V74smFVSWGHSCSMy/9vWninC2A9qMFwyldeq+LVjt4kZ4Ez1BbIieEgbcGjTm rhOg== X-Gm-Message-State: AMCzsaWFSA3HFO/7mOyqw7YPXP7WdEw9VCAQkmQwBXa0HfELPLAQsmFy 7hRpAwzZL7CtPawO01yO4hU= X-Google-Smtp-Source: AOwi7QADPKEhiks4NPVZCdwxr96DqPfgpV/eI+8HXZ+iBUNUtpmC4yml5dI/5DtiWo8aiH4Ax2PVzQ== X-Received: by 10.55.99.144 with SMTP id x138mr15989140qkb.76.1506960549698; Mon, 02 Oct 2017 09:09:09 -0700 (PDT) Received: from debian ([68.128.154.89]) by smtp.gmail.com with ESMTPSA id m4sm510424qtc.73.2017.10.02.09.09.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Oct 2017 09:09:08 -0700 (PDT) Date: Mon, 2 Oct 2017 12:10:01 -0400 From: Tim Hansen To: fujita.tomonori@lab.ntt.co.jp Cc: axboe@kernel.dk, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, alexander.levin@one.verizon.com, devtimhansen@gmail.com Subject: [PATCH] bsg: update bsg_device_list to utilize static hash table implementation. Message-ID: <20171002161001.GA49685@debian> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Updates bsg_device_list to utilize static hashtable implementation. This is done in an effort to standarize the hashtables used across the kernel. Signed-off-by: Tim Hansen --- block/bsg.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/block/bsg.c b/block/bsg.c index ee1335c68de7..ecb93d733b56 100644 --- a/block/bsg.c +++ b/block/bsg.c @@ -66,8 +66,8 @@ enum { static DEFINE_MUTEX(bsg_mutex); static DEFINE_IDR(bsg_minor_idr); -#define BSG_LIST_ARRAY_SIZE 8 -static struct hlist_head bsg_device_list[BSG_LIST_ARRAY_SIZE]; +#define BSG_HASHTABLE_BIT_SIZE 3 +static DEFINE_HASHTABLE(bsg_device_list, BSG_HASHTABLE_BIT_SIZE); static struct class *bsg_class; static int bsg_major; @@ -130,11 +130,6 @@ static struct bsg_command *bsg_alloc_command(struct bsg_device *bd) return bc; } -static inline struct hlist_head *bsg_dev_idx_hash(int index) -{ - return &bsg_device_list[index & (BSG_LIST_ARRAY_SIZE - 1)]; -} - static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq, struct sg_io_v4 *hdr, struct bsg_device *bd, fmode_t has_write_perm) @@ -716,7 +711,7 @@ static int bsg_put_device(struct bsg_device *bd) goto out; } - hlist_del(&bd->dev_list); + hash_del(&bd->dev_list); mutex_unlock(&bsg_mutex); dprintk("%s: tearing down\n", bd->name); @@ -770,7 +765,7 @@ static struct bsg_device *bsg_add_device(struct inode *inode, atomic_set(&bd->ref_count, 1); mutex_lock(&bsg_mutex); - hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode))); + hash_add(bsg_device_list, &bd->dev_list, iminor(inode)); strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1); dprintk("bound to <%s>, max queue %d\n", @@ -786,7 +781,7 @@ static struct bsg_device *__bsg_get_device(int minor, struct request_queue *q) mutex_lock(&bsg_mutex); - hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) { + hash_for_each_possible(bsg_device_list, bd, dev_list, minor) { if (bd->queue == q) { atomic_inc(&bd->ref_count); goto found; @@ -1042,7 +1037,7 @@ static char *bsg_devnode(struct device *dev, umode_t *mode) static int __init bsg_init(void) { - int ret, i; + int ret; dev_t devid; bsg_cmd_cachep = kmem_cache_create("bsg_cmd", @@ -1052,9 +1047,6 @@ static int __init bsg_init(void) return -ENOMEM; } - for (i = 0; i < BSG_LIST_ARRAY_SIZE; i++) - INIT_HLIST_HEAD(&bsg_device_list[i]); - bsg_class = class_create(THIS_MODULE, "bsg"); if (IS_ERR(bsg_class)) { ret = PTR_ERR(bsg_class);