From patchwork Mon Dec 17 15:01:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1887631 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 11699DF266 for ; Mon, 17 Dec 2012 15:05:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753450Ab2LQPFC (ORCPT ); Mon, 17 Dec 2012 10:05:02 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:33507 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753347Ab2LQPCs (ORCPT ); Mon, 17 Dec 2012 10:02:48 -0500 Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by userp1040.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id qBHF2fOm003038 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 17 Dec 2012 15:02:42 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by ucsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id qBHF2etw003355 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 17 Dec 2012 15:02:41 GMT Received: from abhmt107.oracle.com (abhmt107.oracle.com [141.146.116.59]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id qBHF2eVV012073; Mon, 17 Dec 2012 09:02:40 -0600 Received: from lappy.us.oracle.com (/10.159.170.135) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 17 Dec 2012 07:02:40 -0800 From: Sasha Levin To: Trond Myklebust , "J. Bruce Fields" , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sasha Levin Subject: [PATCH 12/15] lockd: use new hashtable implementation Date: Mon, 17 Dec 2012 10:01:32 -0500 Message-Id: <1355756497-15834-12-git-send-email-sasha.levin@oracle.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1355756497-15834-1-git-send-email-sasha.levin@oracle.com> References: <1355756497-15834-1-git-send-email-sasha.levin@oracle.com> X-Source-IP: ucsinet22.oracle.com [156.151.31.94] Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Switch lockd to use the new hashtable implementation. This reduces the amount of generic unrelated code in lockd. This patch depends on d9b482c ("hashtable: introduce a small and naive hashtable") which was merged in v3.6. Tested-by: J. Bruce Fields Signed-off-by: Sasha Levin --- fs/lockd/svcsubs.c | 58 ++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c index 0deb5f6..26c90c8 100644 --- a/fs/lockd/svcsubs.c +++ b/fs/lockd/svcsubs.c @@ -20,6 +20,7 @@ #include #include #include +#include #define NLMDBG_FACILITY NLMDBG_SVCSUBS @@ -28,8 +29,7 @@ * Global file hash table */ #define FILE_HASH_BITS 7 -#define FILE_NRHASH (1<data[i]; - return tmp & (FILE_NRHASH - 1); + return tmp; } /* @@ -86,17 +86,17 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result, { struct hlist_node *pos; struct nlm_file *file; - unsigned int hash; + unsigned int key; __be32 nfserr; nlm_debug_print_fh("nlm_lookup_file", f); - hash = file_hash(f); + key = file_hash(f); /* Lock file table */ mutex_lock(&nlm_file_mutex); - hlist_for_each_entry(file, pos, &nlm_files[hash], f_list) + hash_for_each_possible(nlm_files, file, pos, f_list, file_hash(f)) if (!nfs_compare_fh(&file->f_handle, f)) goto found; @@ -123,7 +123,7 @@ nlm_lookup_file(struct svc_rqst *rqstp, struct nlm_file **result, goto out_free; } - hlist_add_head(&file->f_list, &nlm_files[hash]); + hash_add(nlm_files, &file->f_list, key); found: dprintk("lockd: found file %p (count %d)\n", file, file->f_count); @@ -147,8 +147,8 @@ static inline void nlm_delete_file(struct nlm_file *file) { nlm_debug_print_file("closing file", file); - if (!hlist_unhashed(&file->f_list)) { - hlist_del(&file->f_list); + if (hash_hashed(&file->f_list)) { + hash_del(&file->f_list); nlmsvc_ops->fclose(file->f_file); kfree(file); } else { @@ -253,27 +253,25 @@ nlm_traverse_files(void *data, nlm_host_match_fn_t match, int i, ret = 0; mutex_lock(&nlm_file_mutex); - for (i = 0; i < FILE_NRHASH; i++) { - hlist_for_each_entry_safe(file, pos, next, &nlm_files[i], f_list) { - if (is_failover_file && !is_failover_file(data, file)) - continue; - file->f_count++; - mutex_unlock(&nlm_file_mutex); - - /* Traverse locks, blocks and shares of this file - * and update file->f_locks count */ - if (nlm_inspect_file(data, file, match)) - ret = 1; - - mutex_lock(&nlm_file_mutex); - file->f_count--; - /* No more references to this file. Let go of it. */ - if (list_empty(&file->f_blocks) && !file->f_locks - && !file->f_shares && !file->f_count) { - hlist_del(&file->f_list); - nlmsvc_ops->fclose(file->f_file); - kfree(file); - } + hash_for_each_safe(nlm_files, i, pos, next, file, f_list) { + if (is_failover_file && !is_failover_file(data, file)) + continue; + file->f_count++; + mutex_unlock(&nlm_file_mutex); + + /* Traverse locks, blocks and shares of this file + * and update file->f_locks count */ + if (nlm_inspect_file(data, file, match)) + ret = 1; + + mutex_lock(&nlm_file_mutex); + file->f_count--; + /* No more references to this file. Let go of it. */ + if (list_empty(&file->f_blocks) && !file->f_locks + && !file->f_shares && !file->f_count) { + hash_del(&file->f_list); + nlmsvc_ops->fclose(file->f_file); + kfree(file); } } mutex_unlock(&nlm_file_mutex);