From patchwork Wed Oct 5 06:15:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9362501 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B2F1C607D6 for ; Wed, 5 Oct 2016 06:16:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A339D287C5 for ; Wed, 5 Oct 2016 06:16:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98078287C9; Wed, 5 Oct 2016 06:16:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7B26287C5 for ; Wed, 5 Oct 2016 06:16:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752569AbcJEGQ0 (ORCPT ); Wed, 5 Oct 2016 02:16:26 -0400 Received: from mx2.suse.de ([195.135.220.15]:58582 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752371AbcJEGQ0 (ORCPT ); Wed, 5 Oct 2016 02:16:26 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 77CF2ABE4; Wed, 5 Oct 2016 06:16:24 +0000 (UTC) From: NeilBrown To: Trond Myklebust , Anna Schumaker , Jeff Layton Date: Wed, 05 Oct 2016 17:15:31 +1100 Subject: [PATCH 1/3] NFSv4: add flock_context to open context Cc: Benjamin Coddington , Linux NFS Mailing List Message-ID: <147564813165.1201.1763939224234530957.stgit@noble> In-Reply-To: <147564712849.1201.16474326551460993904.stgit@noble> References: <147564712849.1201.16474326551460993904.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP An open file description (struct file) can have two possible lock contexts. It can have a Posix lock context which will be different in each process that has a fd on the file. It can have a Flock context which will be the same in all processes. When searching for a lock stateid to use, we need to consider both of these contexts. So add a new "flock_contex" to the "nfs_open_context" (of which there is one for each open file description). This flock_context does not need to be reference-counted (as we will use the refcount for the primary lock_context), and will never be part of a list of contexts. So initilization is minimal. When creating an open_context for a non-openning create call, we don't have a 'struct file' to passing, so the lock context gets initialized with a NULL owner, but this will never be used. The flock_context is not used at all in this patch, that will come later. Signed-off-by: NeilBrown --- fs/nfs/dir.c | 6 +++--- fs/nfs/inode.c | 16 ++++++++++++++-- fs/nfs/nfs4file.c | 2 +- fs/nfs/nfs4proc.c | 2 +- include/linux/nfs_fs.h | 3 ++- 5 files changed, 21 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index 177fefb26c18..797dbaf1ebe4 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1453,9 +1453,9 @@ static fmode_t flags_to_mode(int flags) return res; } -static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags) +static struct nfs_open_context *create_nfs_open_context(struct dentry *dentry, int open_flags, struct file *filp) { - return alloc_nfs_open_context(dentry, flags_to_mode(open_flags)); + return alloc_nfs_open_context(dentry, flags_to_mode(open_flags), filp); } static int do_open(struct inode *inode, struct file *filp) @@ -1540,7 +1540,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry, return finish_no_open(file, dentry); } - ctx = create_nfs_open_context(dentry, open_flags); + ctx = create_nfs_open_context(dentry, open_flags, file); err = PTR_ERR(ctx); if (IS_ERR(ctx)) goto out; diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index bf4ec5ecc97e..40e7b88f680d 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -708,6 +708,14 @@ static void nfs_init_lock_context(struct nfs_lock_context *l_ctx) atomic_set(&l_ctx->io_count, 0); } +static void nfs_init_flock_context(struct nfs_lock_context *l_ctx, struct file *filp) +{ + atomic_set(&l_ctx->count, 0); + l_ctx->lockowner.l_owner = filp; + l_ctx->lockowner.l_pid = 0; + atomic_set(&l_ctx->io_count, 0); +} + static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx) { struct nfs_lock_context *head = &ctx->lock_context; @@ -799,7 +807,9 @@ void nfs_close_context(struct nfs_open_context *ctx, int is_sync) } EXPORT_SYMBOL_GPL(nfs_close_context); -struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode) +struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, + fmode_t f_mode, + struct file *filp) { struct nfs_open_context *ctx; struct rpc_cred *cred = rpc_lookup_cred(); @@ -819,7 +829,9 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f ctx->flags = 0; ctx->error = 0; nfs_init_lock_context(&ctx->lock_context); + nfs_init_flock_context(&ctx->flock_context, filp); ctx->lock_context.open_context = ctx; + ctx->flock_context.open_context = ctx; INIT_LIST_HEAD(&ctx->list); ctx->mdsthreshold = NULL; return ctx; @@ -942,7 +954,7 @@ int nfs_open(struct inode *inode, struct file *filp) { struct nfs_open_context *ctx; - ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode); + ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp); if (IS_ERR(ctx)) return PTR_ERR(ctx); nfs_file_set_open_context(filp, ctx); diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c index d085ad794884..13b899b9347e 100644 --- a/fs/nfs/nfs4file.c +++ b/fs/nfs/nfs4file.c @@ -57,7 +57,7 @@ nfs4_file_open(struct inode *inode, struct file *filp) parent = dget_parent(dentry); dir = d_inode(parent); - ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode); + ctx = alloc_nfs_open_context(file_dentry(filp), filp->f_mode, filp); err = PTR_ERR(ctx); if (IS_ERR(ctx)) goto out; diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index a9dec32ba9ba..a8f8b4720c90 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -3793,7 +3793,7 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr, struct nfs4_state *state; int status = 0; - ctx = alloc_nfs_open_context(dentry, FMODE_READ); + ctx = alloc_nfs_open_context(dentry, FMODE_READ, NULL); if (IS_ERR(ctx)) return PTR_ERR(ctx); diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 810124b33327..a9fb754fff34 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -71,6 +71,7 @@ struct nfs_lock_context { struct nfs4_state; struct nfs_open_context { struct nfs_lock_context lock_context; + struct nfs_lock_context flock_context; struct dentry *dentry; struct rpc_cred *cred; struct nfs4_state *state; @@ -358,7 +359,7 @@ extern void nfs_setsecurity(struct inode *inode, struct nfs_fattr *fattr, extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx); extern void put_nfs_open_context(struct nfs_open_context *ctx); extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode); -extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode); +extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f_mode, struct file *filp); extern void nfs_inode_attach_open_context(struct nfs_open_context *ctx); extern void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx); extern void nfs_file_clear_open_context(struct file *flip);