From patchwork Sat Aug 23 14:41:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4769491 Return-Path: X-Original-To: patchwork-cifs-client@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 3D2E1C0338 for ; Sat, 23 Aug 2014 14:41:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4E1A92018A for ; Sat, 23 Aug 2014 14:41:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 47C1B201BB for ; Sat, 23 Aug 2014 14:41:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751572AbaHWOlf (ORCPT ); Sat, 23 Aug 2014 10:41:35 -0400 Received: from mail-qc0-f177.google.com ([209.85.216.177]:36474 "EHLO mail-qc0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751283AbaHWOlc (ORCPT ); Sat, 23 Aug 2014 10:41:32 -0400 Received: by mail-qc0-f177.google.com with SMTP id x13so12165842qcv.36 for ; Sat, 23 Aug 2014 07:41:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7IXqGpmHvbHs4vC421GPgrZI2kNTMPZlKlarOXY8FFg=; b=gO8yQYbM6V2yAmmVhOFPIJr+anC51paAvsDpYhoVH65xN/9Fbp+QdYdwPsqztjhq/W uM3PTo0WZlMILXBKq8rEEHNGwU3Rmcox4bTLGJzQq/bGp4/8S4eKUJI2L56G2UdeCwdp TVtGuI/K66OH+8e3Th+cP/VR1aEZw9Zy9lPQqD4+FA3LFQC5koiZyZfMdp+cChs5qo5U GrZ65oRs74FsME0wjGxy+6dv3NcaGLkcrtaf2zGgyjYRdnVO9MdSvkN1ld+iTEpbYTWQ unWlcqSl3XhVROhjyYGgxALF5RiwIP/wYkSb7clvD/qpxg/OgMDe/TwPQxsm8rJe6tJz VCQw== X-Gm-Message-State: ALoCoQnHYS4lntNrYTlzNpvRoYpvYtTvnXx21l3CrP0p4r3Oh5J+r3rfOPuvbMQwKikkO4cmoheH X-Received: by 10.140.92.13 with SMTP id a13mr3239458qge.88.1408804892206; Sat, 23 Aug 2014 07:41:32 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id o3sm64529771qab.21.2014.08.23.07.41.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Aug 2014 07:41:31 -0700 (PDT) From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: bfields@fieldses.org, hch@infradead.org, cluster-devel@redhat.com, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [PATCH 03/10] locks: generic_delete_lease doesn't need a file_lock at all Date: Sat, 23 Aug 2014 10:41:11 -0400 Message-Id: <1408804878-1331-4-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1408804878-1331-1-git-send-email-jlayton@primarydata.com> References: <1408804878-1331-1-git-send-email-jlayton@primarydata.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Ensure that it's OK to pass in a NULL file_lock double pointer on a F_UNLCK request and convert the vfs_setlease F_UNLCK callers to do just that. Finally, turn the BUG_ON in generic_setlease into a WARN_ON_ONCE with an error return. That's a problem we can handle without crashing the box if it occurs. Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig --- fs/locks.c | 25 ++++++++----------------- fs/nfsd/nfs4state.c | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 58ce8897f2e4..bedb817a5cc4 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1637,20 +1637,18 @@ out: return error; } -static int generic_delete_lease(struct file *filp, struct file_lock **flp) +static int generic_delete_lease(struct file *filp) { struct file_lock *fl, **before; struct dentry *dentry = filp->f_path.dentry; struct inode *inode = dentry->d_inode; - trace_generic_delete_lease(inode, *flp); - for (before = &inode->i_flock; ((fl = *before) != NULL) && IS_LEASE(fl); before = &fl->fl_next) { if (fl->fl_file != filp) continue; - return (*flp)->fl_lmops->lm_change(before, F_UNLCK); + return fl->fl_lmops->lm_change(before, F_UNLCK); } return -EAGAIN; } @@ -1682,13 +1680,15 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp) time_out_leases(inode); - BUG_ON(!(*flp)->fl_lmops->lm_break); - switch (arg) { case F_UNLCK: - return generic_delete_lease(filp, flp); + return generic_delete_lease(filp); case F_RDLCK: case F_WRLCK: + if (!(*flp)->fl_lmops->lm_break) { + WARN_ON_ONCE(1); + return -ENOLCK; + } return generic_add_lease(filp, arg, flp); default: return -EINVAL; @@ -1744,15 +1744,6 @@ int vfs_setlease(struct file *filp, long arg, struct file_lock **lease) } EXPORT_SYMBOL_GPL(vfs_setlease); -static int do_fcntl_delete_lease(struct file *filp) -{ - struct file_lock fl, *flp = &fl; - - lease_init(filp, F_UNLCK, flp); - - return vfs_setlease(filp, F_UNLCK, &flp); -} - static int do_fcntl_add_lease(unsigned int fd, struct file *filp, long arg) { struct file_lock *fl, *ret; @@ -1809,7 +1800,7 @@ out_unlock: int fcntl_setlease(unsigned int fd, struct file *filp, long arg) { if (arg == F_UNLCK) - return do_fcntl_delete_lease(filp); + return vfs_setlease(filp, F_UNLCK, NULL); return do_fcntl_add_lease(fd, filp, arg); } diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 29fac18d9102..0cd252916e1a 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -683,7 +683,7 @@ static void nfs4_put_deleg_lease(struct nfs4_file *fp) if (!fp->fi_lease) return; if (atomic_dec_and_test(&fp->fi_delegees)) { - vfs_setlease(fp->fi_deleg_file, F_UNLCK, &fp->fi_lease); + vfs_setlease(fp->fi_deleg_file, F_UNLCK, NULL); fp->fi_lease = NULL; fput(fp->fi_deleg_file); fp->fi_deleg_file = NULL;