From patchwork Thu Sep 26 18:40:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benny Halevy X-Patchwork-Id: 2950171 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9EF229F288 for ; Thu, 26 Sep 2013 18:40:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 11DCF202E5 for ; Thu, 26 Sep 2013 18:40:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C0D5202D1 for ; Thu, 26 Sep 2013 18:40:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753426Ab3IZSkf (ORCPT ); Thu, 26 Sep 2013 14:40:35 -0400 Received: from mail-qe0-f44.google.com ([209.85.128.44]:35256 "EHLO mail-qe0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753047Ab3IZSke (ORCPT ); Thu, 26 Sep 2013 14:40:34 -0400 Received: by mail-qe0-f44.google.com with SMTP id 3so1108012qeb.31 for ; Thu, 26 Sep 2013 11:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=5jkB1JCKpgbmiOHAU88O3FgghsrtSdsDLK1gOOxZVAc=; b=I7vudY8wDHfbAHSrdeDuHv7xNOv/jjRtcC8LHXvHi/woogf8LjFglK6gri8DDHEQvQ EH75GO/agyba4kyFYrcgEhcyuCM4nVOlDsojFccV5Y+aXHl2UXphSje4Q0kNyA5eY2CA WUhfShLj4oc9ZfjCOhKWh1Mx09bLaGBQwjMwMlyiq8xZUsCXCoH4V5WVggPXGW5GWpqy 6nuSXz28TOY7ARPE7Sq4ioQ1Nn6+8x1Wdjo6cn3viK48ddr9G3iUQp9qXY+dV+OVVd1y 6m0vtyav7y9FT0wxxjsed1tjiO17qKWGbb8otO2LtYAPyx1oiei7h+X0WwvmaWFXK0k8 8Bow== X-Received: by 10.224.36.71 with SMTP id s7mr8539738qad.33.1380220833702; Thu, 26 Sep 2013 11:40:33 -0700 (PDT) Received: from bhalevy-lt.il.tonian.com.com (nat-pool-bos-u.redhat.com. [66.187.233.207]) by mx.google.com with ESMTPSA id 5sm10279298qao.3.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 26 Sep 2013 11:40:33 -0700 (PDT) From: Benny Halevy To: " J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH RFC v0 10/49] pnfsd: use sbid hash table to map super_blocks to devid major identifiers Date: Thu, 26 Sep 2013 14:40:31 -0400 Message-Id: <1380220831-13136-1-git-send-email-bhalevy@primarydata.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <52447EA0.7070004@primarydata.com> References: <52447EA0.7070004@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Benny Halevy Signed-off-by: Benny Halevy [pnfsd: alloc_sid should kmalloc a object not a pointer] Signed-off-by: Bian Naimeng Signed-off-by: Benny Halevy Signed-off-by: Benny Halevy --- fs/nfsd/nfs4pnfsd.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nfsd/pnfsd.h | 2 + 2 files changed, 122 insertions(+) diff --git a/fs/nfsd/nfs4pnfsd.c b/fs/nfsd/nfs4pnfsd.c index cb28207..9a7cbc9 100644 --- a/fs/nfsd/nfs4pnfsd.c +++ b/fs/nfsd/nfs4pnfsd.c @@ -25,3 +25,123 @@ #define NFSDDBG_FACILITY NFSDDBG_PNFS +static DEFINE_SPINLOCK(layout_lock); + +/* hash table for nfsd4_pnfs_deviceid.sbid */ +#define SBID_HASH_BITS 8 +#define SBID_HASH_SIZE (1 << SBID_HASH_BITS) +#define SBID_HASH_MASK (SBID_HASH_SIZE - 1) + +struct sbid_tracker { + u64 id; + struct super_block *sb; + struct list_head hash; +}; + +static u64 current_sbid; +static struct list_head sbid_hashtbl[SBID_HASH_SIZE]; + +static unsigned long +sbid_hashval(struct super_block *sb) +{ + return hash_ptr(sb, SBID_HASH_BITS); +} + +static struct sbid_tracker * +alloc_sbid(void) +{ + return kmalloc(sizeof(struct sbid_tracker), GFP_KERNEL); +} + +static void +destroy_sbid(struct sbid_tracker *sbid) +{ + spin_lock(&layout_lock); + list_del(&sbid->hash); + spin_unlock(&layout_lock); + kfree(sbid); +} + +void +nfsd4_free_pnfs_slabs(void) +{ + int i; + struct sbid_tracker *sbid; + + for (i = 0; i < SBID_HASH_SIZE; i++) { + while (!list_empty(&sbid_hashtbl[i])) { + sbid = list_first_entry(&sbid_hashtbl[i], + struct sbid_tracker, + hash); + destroy_sbid(sbid); + } + } +} + +int +nfsd4_init_pnfs_slabs(void) +{ + int i; + + for (i = 0; i < SBID_HASH_SIZE; i++) + INIT_LIST_HEAD(&sbid_hashtbl[i]); + + return 0; +} + +static u64 +alloc_init_sbid(struct super_block *sb) +{ + struct sbid_tracker *sbid; + struct sbid_tracker *new = alloc_sbid(); + unsigned long hash_idx = sbid_hashval(sb); + u64 id = 0; + + if (likely(new)) { + spin_lock(&layout_lock); + id = ++current_sbid; + new->id = (id << SBID_HASH_BITS) | (hash_idx & SBID_HASH_MASK); + id = new->id; + BUG_ON(id == 0); + new->sb = sb; + + list_for_each_entry (sbid, &sbid_hashtbl[hash_idx], hash) + if (sbid->sb == sb) { + kfree(new); + id = sbid->id; + spin_unlock(&layout_lock); + return id; + } + list_add(&new->hash, &sbid_hashtbl[hash_idx]); + spin_unlock(&layout_lock); + } + return id; +} + +static u64 +find_create_sbid(struct super_block *sb) +{ + struct sbid_tracker *sbid; + unsigned long hash_idx = sbid_hashval(sb); + int pos = 0; + u64 id = 0; + + spin_lock(&layout_lock); + list_for_each_entry (sbid, &sbid_hashtbl[hash_idx], hash) { + pos++; + if (sbid->sb != sb) + continue; + if (pos > 1) { + list_del(&sbid->hash); + list_add(&sbid->hash, &sbid_hashtbl[hash_idx]); + } + id = sbid->id; + break; + } + spin_unlock(&layout_lock); + + if (!id) + id = alloc_init_sbid(sb); + + return id; +} diff --git a/fs/nfsd/pnfsd.h b/fs/nfsd/pnfsd.h index 7c46791..29ea2e7 100644 --- a/fs/nfsd/pnfsd.h +++ b/fs/nfsd/pnfsd.h @@ -36,4 +36,6 @@ #include +#include "xdr4.h" + #endif /* LINUX_NFSD_PNFSD_H */