From patchwork Wed Aug 6 13:35:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 4686231 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 DDB399F373 for ; Wed, 6 Aug 2014 13:35:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6D6C2010E for ; Wed, 6 Aug 2014 13:35:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83876200E8 for ; Wed, 6 Aug 2014 13:35:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751148AbaHFNfx (ORCPT ); Wed, 6 Aug 2014 09:35:53 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:47940 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750784AbaHFNfw (ORCPT ); Wed, 6 Aug 2014 09:35:52 -0400 Received: by mail-pa0-f49.google.com with SMTP id hz1so3417600pad.8 for ; Wed, 06 Aug 2014 06:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=kYJGEPdhQNJxkeddfKKCLqsW2VsmhBGagnU9pdBnMDU=; b=B3diGKrKZH5JOdmTVVkfhsLlT3a04jKLNudbq5zTNdH6JVpAEsSRfFYNzn6jBCPYhZ 2O/gpJQCNqxFwjqaGDuozVbZjSq3jH+EHuqzPPcLld0vhBvZll4HbNGf9YJSLjrd8O8G Yk+FC6PuhzQ6XamoyQqQfHn98H4pTVRyHpFY1+iUU4DJQLRlExpXiNckcG/DIqXDbfeW A0PzGNrAewFz6TQmf/bpFBRv/KxAyfCivOcmSI38jhWIsaBwd96dgMfGewtkv0y5XMiJ hPBMSWKM6yaAF0zTh+jKRLT031tJdTRIsrr8yh8rhIdoCHKGpmP7SNYN/xKEqAco5B4t uPZA== X-Received: by 10.70.90.237 with SMTP id bz13mr11337801pdb.110.1407332151947; Wed, 06 Aug 2014 06:35:51 -0700 (PDT) Received: from [192.168.0.100] ([110.190.119.243]) by mx.google.com with ESMTPSA id yb4sm1357543pbb.9.2014.08.06.06.35.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Aug 2014 06:35:50 -0700 (PDT) Message-ID: <53E22F2C.8070900@gmail.com> Date: Wed, 06 Aug 2014 21:35:40 +0800 From: Kinglong Mee User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.0 MIME-Version: 1.0 To: "J. Bruce Fields" CC: Linux NFS Mailing List , Trond Myklebust , jlayton@redhat.com, linux-fsdevel@vger.kernel.org, kinglongmee@gmail.com Subject: [PATCH 2/3] NFSD: Increase the reference of lockowner when coping file_lock References: <53BAAAC5.9000106@gmail.com> <53E22EA5.70708@gmail.com> In-Reply-To: <53E22EA5.70708@gmail.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=-7.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 Signed-off-by: Kinglong Mee --- fs/nfsd/nfs4state.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 24168ae..07e4b5c 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4867,6 +4867,29 @@ nfs4_transform_lock_offset(struct file_lock *lock) lock->fl_end = OFFSET_MAX; } +static inline struct nfs4_lockowner *get_lockowner(struct nfs4_lockowner *lo) +{ + atomic_inc(&lo->lo_owner.so_count); + return lo; +} + +static void nfsd4_fl_copy_lock(struct file_lock *dst, struct file_lock *src) +{ + struct nfs4_lockowner *lo = (struct nfs4_lockowner *) src->fl_owner; + get_lockowner(lo); +} + +static void nfsd4_fl_release_lock(struct file_lock *fl) +{ + struct nfs4_lockowner *lo = (struct nfs4_lockowner *) fl->fl_owner; + nfs4_put_stateowner(&lo->lo_owner); +} + +static const struct file_lock_operations nfsd4_fl_lock_ops = { + .fl_copy_lock = nfsd4_fl_copy_lock, + .fl_release_private = nfsd4_fl_release_lock, +}; + static inline void nfs4_set_lock_denied(struct file_lock *fl, struct nfsd4_lock_denied *deny) { @@ -5233,10 +5256,12 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, status = nfserr_openmode; goto out; } - file_lock->fl_owner = (fl_owner_t)lock_sop; + + file_lock->fl_owner = (fl_owner_t)get_lockowner(lock_sop); file_lock->fl_pid = current->tgid; file_lock->fl_file = filp; file_lock->fl_flags = FL_POSIX | FL_NFSD; + file_lock->fl_ops = &nfsd4_fl_lock_ops; file_lock->fl_start = lock->lk_offset; file_lock->fl_end = last_byte_offset(lock->lk_offset, lock->lk_length); nfs4_transform_lock_offset(file_lock); @@ -5399,6 +5424,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfs4_ol_stateid *stp; struct file *filp = NULL; struct file_lock *file_lock = NULL; + struct nfs4_lockowner *lock_sop = NULL; __be32 status; int err; struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); @@ -5420,6 +5446,8 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, status = nfserr_lock_range; goto put_stateid; } + + lock_sop = lockowner(stp->st_stateowner); file_lock = locks_alloc_lock(); if (!file_lock) { dprintk("NFSD: %s: unable to allocate lock!\n", __func__); @@ -5428,10 +5456,11 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, } locks_init_lock(file_lock); file_lock->fl_type = F_UNLCK; - file_lock->fl_owner = (fl_owner_t)lockowner(stp->st_stateowner); + file_lock->fl_owner = (fl_owner_t)get_lockowner(lock_sop); file_lock->fl_pid = current->tgid; file_lock->fl_file = filp; file_lock->fl_flags = FL_POSIX | FL_NFSD; + file_lock->fl_ops = &nfsd4_fl_lock_ops; file_lock->fl_start = locku->lu_offset; file_lock->fl_end = last_byte_offset(locku->lu_offset,