From patchwork Thu Sep 4 12:38:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4845151 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 2E6709F390 for ; Thu, 4 Sep 2014 12:41:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E13072026D for ; Thu, 4 Sep 2014 12:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2C2B920270 for ; Thu, 4 Sep 2014 12:41:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753287AbaIDMke (ORCPT ); Thu, 4 Sep 2014 08:40:34 -0400 Received: from mail-qc0-f178.google.com ([209.85.216.178]:45459 "EHLO mail-qc0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753212AbaIDMjT (ORCPT ); Thu, 4 Sep 2014 08:39:19 -0400 Received: by mail-qc0-f178.google.com with SMTP id x13so10240507qcv.37 for ; Thu, 04 Sep 2014 05:39:18 -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=tlmJ4qJ9CaD9Qb7W9/QhWs9adl+wcqMGzCrLdeLUwhI=; b=HmfGyRDCqOeo0a+YcXR95e3w8aJ1osgj5ZtcpeZXJTMMyOhjKIrgXsoghJ8O0Q5o5v Q3JCItHA4AVLAzThdtZ2o72cw5n+iwsKMt0KXMI4BrexNUL7N1VclAFr/3r9Jt1m77Or 6x4CivnblLx6JTjiG96KuOSGhSHskLPij+135HdzU+U2rMFB00TqWiG86/fgZkfZ0Gy/ aJTA9uFoi5nCaxaLbb5cT1Ocv1EWtkqxFctP3VugFqNTmE8oKq2Ylm8AifYYzlw5MD6d AemzFptt6GXCDV686y/XsvjSw5LT9p1WRrM6D351ph1VI2fiC8idMDjAgDa4/pXXXDNz 96Kg== X-Gm-Message-State: ALoCoQmQr9vOeFC5URKoJCdf3OdW4e7H0Pw55UyCEtC9hwFLZ8qoijZx9fwk5qp43+6GC/xE1J4K X-Received: by 10.140.103.75 with SMTP id x69mr6201398qge.17.1409834358424; Thu, 04 Sep 2014 05:39:18 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id t5sm19186512qat.24.2014.09.04.05.39.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 Sep 2014 05:39:17 -0700 (PDT) From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-nfs@vger.kernel.org, Christoph Hellwig , "J. Bruce Fields" , linux-kernel@vger.kernel.org Subject: [PATCH v2 14/17] locks: __break_lease cleanup in preparation of allowing direct removal of leases Date: Thu, 4 Sep 2014 08:38:40 -0400 Message-Id: <1409834323-7171-15-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1409834323-7171-1-git-send-email-jlayton@primarydata.com> References: <1409834323-7171-1-git-send-email-jlayton@primarydata.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=-8.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Eliminate an unneeded "flock" variable. We can use "fl" as a loop cursor everywhere. Add a any_leases_conflict helper function as well to consolidate a bit of code. Signed-off-by: Jeff Layton Reviewed-by: Christoph Hellwig --- fs/locks.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 011812490c92..246ba53650f7 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1351,6 +1351,20 @@ static bool leases_conflict(struct file_lock *lease, struct file_lock *breaker) return locks_conflict(breaker, lease); } +static bool +any_leases_conflict(struct inode *inode, struct file_lock *breaker) +{ + struct file_lock *fl; + + lockdep_assert_held(&inode->i_lock); + + for (fl = inode->i_flock ; fl && IS_LEASE(fl); fl = fl->fl_next) { + if (leases_conflict(fl, breaker)) + return true; + } + return false; +} + /** * __break_lease - revoke all outstanding leases on file * @inode: the inode of the file to return @@ -1367,10 +1381,9 @@ static bool leases_conflict(struct file_lock *lease, struct file_lock *breaker) int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) { int error = 0; - struct file_lock *new_fl, *flock; + struct file_lock *new_fl; struct file_lock *fl; unsigned long break_time; - bool lease_conflict = false; int want_write = (mode & O_ACCMODE) != O_RDONLY; LIST_HEAD(dispose); @@ -1383,17 +1396,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) time_out_leases(inode, &dispose); - flock = inode->i_flock; - if ((flock == NULL) || !IS_LEASE(flock)) - goto out; - - for (fl = flock; fl && IS_LEASE(fl); fl = fl->fl_next) { - if (leases_conflict(fl, new_fl)) { - lease_conflict = true; - break; - } - } - if (!lease_conflict) + if (!any_leases_conflict(inode, new_fl)) goto out; break_time = 0; @@ -1403,7 +1406,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) break_time++; /* so that 0 means no break time */ } - for (fl = flock; fl && IS_LEASE(fl); fl = fl->fl_next) { + for (fl = inode->i_flock; fl && IS_LEASE(fl); fl = fl->fl_next) { if (!leases_conflict(fl, new_fl)) continue; if (want_write) { @@ -1412,7 +1415,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) fl->fl_flags |= FL_UNLOCK_PENDING; fl->fl_break_time = break_time; } else { - if (lease_breaking(flock)) + if (lease_breaking(inode->i_flock)) continue; fl->fl_flags |= FL_DOWNGRADE_PENDING; fl->fl_downgrade_time = break_time; @@ -1427,12 +1430,12 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type) } restart: - break_time = flock->fl_break_time; + break_time = inode->i_flock->fl_break_time; if (break_time != 0) break_time -= jiffies; if (break_time == 0) break_time++; - locks_insert_block(flock, new_fl); + locks_insert_block(inode->i_flock, new_fl); trace_break_lease_block(inode, new_fl); spin_unlock(&inode->i_lock); locks_dispose_list(&dispose); @@ -1442,17 +1445,15 @@ restart: trace_break_lease_unblock(inode, new_fl); locks_delete_block(new_fl); if (error >= 0) { - if (error == 0) - time_out_leases(inode, &dispose); /* * Wait for the next conflicting lease that has not been * broken yet */ - for (flock = inode->i_flock; flock && IS_LEASE(flock); - flock = flock->fl_next) { - if (leases_conflict(new_fl, flock)) - goto restart; - } + if (error == 0) + time_out_leases(inode, &dispose); + if (any_leases_conflict(inode, new_fl)) + goto restart; + error = 0; }