From patchwork Sun Aug 19 00:52:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1341891 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 7633BE0118 for ; Sun, 19 Aug 2012 00:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753516Ab2HSAxs (ORCPT ); Sat, 18 Aug 2012 20:53:48 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:41176 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752322Ab2HSAwl (ORCPT ); Sat, 18 Aug 2012 20:52:41 -0400 Received: by mail-bk0-f46.google.com with SMTP id j10so1596913bkw.19 for ; Sat, 18 Aug 2012 17:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=VX9dIYRNao+R0FxYOadQZF76fW00dRoEIwZQJ+Bdn3M=; b=euDLu64hQuRfjt56/y4U1w21E09bTEtdSQ1kKDwIJ34HtiO+vupcDUQ+sDxA+x4IV/ +z90BP6oLe9T+qgdQbI8AzrbwKxkf4YnjydRP2SNBgZxQ8+gVA7Vw7M/+LtdpxvYgx3O J3QnawH8OiteTCGFOYY16oL/WN5fItgyP/xEtsQt3gRczA1eOUax77l6wNvvpOgbEXNP t0hm4DS8FzkU7/9Ev5FbQpAzlK9uAuLPA6W+KKtvLFneVwICSBn+SzJDp4JXnVcCTQlI B0pqt9PQ2Y35tEW0U5BXOiGLjyTUPba+oTEEIj4xaFt3CiS3/NqfHhJkGXAqmSOVYeVI EmLg== Received: by 10.204.133.193 with SMTP id g1mr3220415bkt.2.1345337560853; Sat, 18 Aug 2012 17:52:40 -0700 (PDT) Received: from localhost.localdomain (95-89-78-76-dynip.superkabel.de. [95.89.78.76]) by mx.google.com with ESMTPS id c18sm4724437bkv.8.2012.08.18.17.52.38 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 18 Aug 2012 17:52:40 -0700 (PDT) From: Sasha Levin To: torvalds@linux-foundation.org Cc: tj@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, paul.gortmaker@windriver.com, davem@davemloft.net, rostedt@goodmis.org, mingo@elte.hu, ebiederm@xmission.com, aarcange@redhat.com, ericvh@gmail.com, netdev@vger.kernel.org, josh@joshtriplett.org, eric.dumazet@gmail.com, mathieu.desnoyers@efficios.com, axboe@kernel.dk, agk@redhat.com, dm-devel@redhat.com, neilb@suse.de, ccaulfie@redhat.com, teigland@redhat.com, Trond.Myklebust@netapp.com, bfields@fieldses.org, fweisbec@gmail.com, jesse@nicira.com, venkat.x.venkatsubra@oracle.com, ejt@redhat.com, snitzer@redhat.com, edumazet@google.com, linux-nfs@vger.kernel.org, dev@openvswitch.org, rds-devel@oss.oracle.com, lw@cn.fujitsu.com, Sasha Levin Subject: [PATCH v2 13/16] lockd: use new hashtable implementation Date: Sun, 19 Aug 2012 02:52:27 +0200 Message-Id: <1345337550-24304-15-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1345337550-24304-1-git-send-email-levinsasha928@gmail.com> References: <1345337550-24304-1-git-send-email-levinsasha928@gmail.com> 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. Signed-off-by: Sasha Levin --- fs/lockd/svcsubs.c | 66 ++++++++++++++++++++++++++++----------------------- 1 files changed, 36 insertions(+), 30 deletions(-) diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c index 0deb5f6..d223a1f 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); @@ -451,3 +449,11 @@ nlmsvc_unlock_all_by_ip(struct sockaddr *server_addr) return ret ? -EIO : 0; } EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_ip); + +static int __init nlm_init(void) +{ + hash_init(nlm_files); + return 0; +} + +module_init(nlm_init);