From patchwork Mon Aug 31 09:09:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 7099121 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D42E99F1B9 for ; Mon, 31 Aug 2015 09:09:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D780B20570 for ; Mon, 31 Aug 2015 09:09:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C568D2056E for ; Mon, 31 Aug 2015 09:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752720AbbHaJJX (ORCPT ); Mon, 31 Aug 2015 05:09:23 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:36152 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752714AbbHaJJU (ORCPT ); Mon, 31 Aug 2015 05:09:20 -0400 Received: by pabpg12 with SMTP id pg12so375559pab.3 for ; Mon, 31 Aug 2015 02:09:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=p73M08WE1owqafBBmDkOAFwNYVJ1eiTI1Mxky/Ulpsg=; b=wDCUsFK+Qh27/EmfxiLA3RDFQKCnqkShy8fchbDwze8NenVnKpPgB8akSABeLoUB7F on60upW1e7kx4aUO/DOO8BbVSn9gJ08s6drzLZISH5Ezu6eWWaS8Un+2yyLNPEKRFe2i aKXewUFZkxBqxE+8b1eMbQWOmX/pnbZXJA5M5/pHsPO71E4GY5iv2Z9D4kfZzhv9TtVJ wyYoH5mPSqUwo2eeHL8ytiV/Rs46b7dTgFKpU3gWurHABGUAwkRNWDQ1IcRSbESEOyOd cFdSzCgceOYu1K4xzYsDkFn6I3F2XVup3ajSs1rAIdbmN46SDzEZq+gids5lcD57cy0l 5hoQ== X-Received: by 10.68.139.226 with SMTP id rb2mr35768027pbb.49.1441012160283; Mon, 31 Aug 2015 02:09:20 -0700 (PDT) Received: from [192.168.99.14] ([104.143.41.79]) by smtp.googlemail.com with ESMTPSA id pi9sm13744522pbb.96.2015.08.31.02.09.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Aug 2015 02:09:19 -0700 (PDT) To: Trond Myklebust Cc: "linux-nfs@vger.kernel.org" , kinglongmee@gmail.com From: Kinglong Mee Subject: [PATCH] nfs: Get lock context by fl_owner/fl_pid when unlocking file Message-ID: <55E419B9.50905@gmail.com> Date: Mon, 31 Aug 2015 17:09:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 Whan a file unlocking is cuased by 'Ctrl + C', the current->files is NULL, so that, nfs_get_lock_context always create a new lock context in do_unlk(). A new helper nfs_get_lock_context_by_owner requests the owner and pid for searching and creating lock context. Ps: I'm not sure it's needed in ->flush logical. Signed-off-by: Kinglong Mee --- fs/nfs/file.c | 3 ++- fs/nfs/inode.c | 37 ++++++++++++++++++++++++++----------- include/linux/nfs_fs.h | 2 ++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index cc4fa1e..85e01c7 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -774,7 +774,8 @@ do_unlk(struct file *filp, int cmd, struct file_lock *fl, int is_local) */ vfs_fsync(filp, 0); - l_ctx = nfs_get_lock_context(nfs_file_open_context(filp)); + l_ctx = nfs_get_lock_context_by_owner(nfs_file_open_context(filp), + fl->fl_owner, fl->fl_pid); if (!IS_ERR(l_ctx)) { status = nfs_iocounter_wait(&l_ctx->io_count); nfs_put_lock_context(l_ctx); diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 0adc7d2..cbc1256 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c @@ -688,24 +688,26 @@ out: } EXPORT_SYMBOL_GPL(nfs_getattr); -static void nfs_init_lock_context(struct nfs_lock_context *l_ctx) +static void nfs_init_lock_context(struct nfs_lock_context *l_ctx, + fl_owner_t owner, pid_t pid) { atomic_set(&l_ctx->count, 1); - l_ctx->lockowner.l_owner = current->files; - l_ctx->lockowner.l_pid = current->tgid; + l_ctx->lockowner.l_owner = owner; + l_ctx->lockowner.l_pid = pid; INIT_LIST_HEAD(&l_ctx->list); nfs_iocounter_init(&l_ctx->io_count); } -static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context *ctx) +static struct nfs_lock_context * +__nfs_find_lock_context(struct nfs_open_context *ctx, fl_owner_t owner, pid_t pid) { struct nfs_lock_context *head = &ctx->lock_context; struct nfs_lock_context *pos = head; do { - if (pos->lockowner.l_owner != current->files) + if (pos->lockowner.l_owner != owner) continue; - if (pos->lockowner.l_pid != current->tgid) + if (pos->lockowner.l_pid != pid) continue; atomic_inc(&pos->count); return pos; @@ -713,21 +715,22 @@ static struct nfs_lock_context *__nfs_find_lock_context(struct nfs_open_context return NULL; } -struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx) +static struct nfs_lock_context * +__nfs_get_lock_context(struct nfs_open_context *ctx, fl_owner_t owner, pid_t pid) { struct nfs_lock_context *res, *new = NULL; struct inode *inode = d_inode(ctx->dentry); spin_lock(&inode->i_lock); - res = __nfs_find_lock_context(ctx); + res = __nfs_find_lock_context(ctx, owner, pid); if (res == NULL) { spin_unlock(&inode->i_lock); new = kmalloc(sizeof(*new), GFP_KERNEL); if (new == NULL) return ERR_PTR(-ENOMEM); - nfs_init_lock_context(new); + nfs_init_lock_context(new, owner, pid); spin_lock(&inode->i_lock); - res = __nfs_find_lock_context(ctx); + res = __nfs_find_lock_context(ctx, owner, pid); if (res == NULL) { list_add_tail(&new->list, &ctx->lock_context.list); new->open_context = ctx; @@ -739,8 +742,20 @@ struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx) kfree(new); return res; } + +struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx) +{ + return __nfs_get_lock_context(ctx, current->files, current->tgid); +} EXPORT_SYMBOL_GPL(nfs_get_lock_context); +struct nfs_lock_context * +nfs_get_lock_context_by_owner(struct nfs_open_context *ctx, fl_owner_t owner, pid_t pid) +{ + return __nfs_get_lock_context(ctx, owner, pid); +} +EXPORT_SYMBOL_GPL(nfs_get_lock_context_by_owner); + void nfs_put_lock_context(struct nfs_lock_context *l_ctx) { struct nfs_open_context *ctx = l_ctx->open_context; @@ -800,7 +815,7 @@ struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fmode_t f ctx->mode = f_mode; ctx->flags = 0; ctx->error = 0; - nfs_init_lock_context(&ctx->lock_context); + nfs_init_lock_context(&ctx->lock_context, current->files, current->tgid); ctx->lock_context.open_context = ctx; INIT_LIST_HEAD(&ctx->list); ctx->mdsthreshold = NULL; diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h index 874b772..a13c16e5 100644 --- a/include/linux/nfs_fs.h +++ b/include/linux/nfs_fs.h @@ -372,6 +372,8 @@ extern struct nfs_open_context *alloc_nfs_open_context(struct dentry *dentry, fm 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 struct nfs_lock_context *nfs_get_lock_context(struct nfs_open_context *ctx); +extern struct nfs_lock_context *nfs_get_lock_context_by_owner( + struct nfs_open_context *ctx, fl_owner_t owner, pid_t pid); extern void nfs_put_lock_context(struct nfs_lock_context *l_ctx); extern u64 nfs_compat_user_ino64(u64 fileid); extern void nfs_fattr_init(struct nfs_fattr *fattr);