From patchwork Tue Aug 19 15:26:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 4744241 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6743BC0338 for ; Tue, 19 Aug 2014 15:27:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 329A020136 for ; Tue, 19 Aug 2014 15:27:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 220302010B for ; Tue, 19 Aug 2014 15:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753105AbaHSP1J (ORCPT ); Tue, 19 Aug 2014 11:27:09 -0400 Received: from mail-pa0-f52.google.com ([209.85.220.52]:55410 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751810AbaHSP1H (ORCPT ); Tue, 19 Aug 2014 11:27:07 -0400 Received: by mail-pa0-f52.google.com with SMTP id bj1so10206596pad.25 for ; Tue, 19 Aug 2014 08:27:06 -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=woNXQohvV3ewSX1TYA8GzUNbTzV7mE/uaFdUZ0dmjCU=; b=CLokMyrEf8flaMqgAkYpFWmBASO2SeghRt6CwZUNBCN2sJeztlwkLAn75yPYd7wl3w 0jnyocrTo3dwWbZYpe6iuVcYx0t1GmXxhnWhXPauq4eGX3q5C1C8I83XcH78T0h3fJRu jI+OoGC1RcvyPqkA4Dfv8tiKgGVxPaTIIgRp5IaJlsGGqm7f4LvkyYLanSLuag3/bl+a Z3TcNwpvrnTLNpKcJiMAtjn4QFEUpWT80LmKf2cbHy2cigVPNPqMPk7Hv4uaIwJsUQOh FjiJ05uCBxTfdDdYm/CsZJdbhBHbCtjnsSkd0d4p7SYG5xm8UvVGfmkYQZ1VasknHFCO Qn0A== X-Received: by 10.68.245.135 with SMTP id xo7mr19191746pbc.161.1408462026629; Tue, 19 Aug 2014 08:27:06 -0700 (PDT) Received: from [192.168.0.100] ([118.117.110.46]) by mx.google.com with ESMTPSA id ee5sm19571031pbc.47.2014.08.19.08.27.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Aug 2014 08:27:05 -0700 (PDT) Message-ID: <53F36CB5.2030707@gmail.com> Date: Tue, 19 Aug 2014 23:26:45 +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: Jeff Layton CC: "J. Bruce Fields" , Linux NFS Mailing List , Trond Myklebust , linux-fsdevel@vger.kernel.org, kinglongmee@gmail.com Subject: [PATCH 6/6 v4] NFSD: Increase the reference of lockowner when coping file_lock References: <53BAAAC5.9000106@gmail.com> <53E22EA5.70708@gmail.com> <20140809065112.700e0ecc@tlielax.poochiereds.net> <53E791F1.40802@gmail.com> <53ED5093.6000308@gmail.com> In-Reply-To: <53ED5093.6000308@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 v4: same as v3, no change v3: Update based on Jeff's comments v2: Fix bad using of struct file_lock_operations for handle the owner. Signed-off-by: Kinglong Mee Acked-by: Jeff Layton --- fs/nfsd/nfs4state.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index e087a71..7161111 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4869,9 +4869,31 @@ nfs4_transform_lock_offset(struct file_lock *lock) lock->fl_end = OFFSET_MAX; } -/* Hack!: For now, we're defining this just so we can use a pointer to it - * as a unique cookie to identify our (NFSv4's) posix locks. */ +static inline struct nfs4_lockowner * +nfs4_get_lockowner(struct nfs4_lockowner *lo) +{ + return lockowner(nfs4_get_stateowner(&lo->lo_owner)); +} + +static void nfsd4_fl_get_owner(struct file_lock *dst, struct file_lock *src) +{ + struct nfs4_lockowner *lo = (struct nfs4_lockowner *) src->fl_owner; + dst->fl_owner = (fl_owner_t) nfs4_get_lockowner(lo); +} + +static void nfsd4_fl_put_owner(struct file_lock *fl) +{ + struct nfs4_lockowner *lo = (struct nfs4_lockowner *) fl->fl_owner; + + if (lo) { + nfs4_put_stateowner(&lo->lo_owner); + fl->fl_owner = NULL; + } +} + static const struct lock_manager_operations nfsd_posix_mng_ops = { + .lm_get_owner = nfsd4_fl_get_owner, + .lm_put_owner = nfsd4_fl_put_owner, }; static inline void @@ -5236,7 +5258,8 @@ 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) nfs4_get_lockowner(lock_sop); file_lock->fl_pid = current->tgid; file_lock->fl_file = filp; file_lock->fl_flags = FL_POSIX; @@ -5403,6 +5426,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); @@ -5424,6 +5448,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__); @@ -5432,7 +5458,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, } file_lock->fl_type = F_UNLCK; - file_lock->fl_owner = (fl_owner_t)lockowner(stp->st_stateowner); + file_lock->fl_owner = (fl_owner_t) nfs4_get_lockowner(lock_sop); file_lock->fl_pid = current->tgid; file_lock->fl_file = filp; file_lock->fl_flags = FL_POSIX;