From patchwork Thu Jan 8 18:34:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 5595221 Return-Path: X-Original-To: patchwork-ceph-devel@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 CB4499F443 for ; Thu, 8 Jan 2015 18:39:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0564920444 for ; Thu, 8 Jan 2015 18:39:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E8C9C20445 for ; Thu, 8 Jan 2015 18:39:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756051AbbAHSiy (ORCPT ); Thu, 8 Jan 2015 13:38:54 -0500 Received: from mail-qg0-f48.google.com ([209.85.192.48]:44203 "EHLO mail-qg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757266AbbAHSeq (ORCPT ); Thu, 8 Jan 2015 13:34:46 -0500 Received: by mail-qg0-f48.google.com with SMTP id j5so3855101qga.7 for ; Thu, 08 Jan 2015 10:34:45 -0800 (PST) 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=d5B6muy1R8kexmsGOZxuF9LAc4F+6Je1Tab5w24BgBU=; b=f9ra6Ll32elXJf6wIRG7dV9mPxesgJR8avMaR+XOG8YYemOLWMF1EkrWcDrc4zEdWr SjOCtEjrTOKLdoCO212iZ+Wtna43XzudzamN7ZroQ/yBtJ6fwAK//jRLCvVdTSK/fdRJ Vj+Kc+0SlJedqtcme5XvATjFTHjlvlZr+Msu4WyLBSnvpZI0P+H8p+Q/85LJ/qjcAjig /bn7ZBvQNfesNcujMFgaS9DvLaCA0FyhXkeIN+Ii/WNnY+oeIp456apZFhNQ697pl1eg tLfDYzLbN2gWRtQ+xcgqi1MEqzwJbEhZ2016pdtTAtBiulb/C7rg94SmbgBqwJpnwAqI Kj0Q== X-Gm-Message-State: ALoCoQnd+Q86sfL+FyEp0VdBZiqbhJEb2eSefZG/bZhQDcZIDJMn3M78cXfdKe///IpLrKAH8BPq X-Received: by 10.224.69.200 with SMTP id a8mr18364671qaj.40.1420742085256; Thu, 08 Jan 2015 10:34:45 -0800 (PST) Received: from synchrony.poochiereds.net ([50.242.95.105]) by mx.google.com with ESMTPSA id 7sm4708739qak.20.2015.01.08.10.34.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jan 2015 10:34:44 -0800 (PST) From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, hch@infradead.org Subject: [PATCH v2 02/10] locks: have locks_release_file use flock_lock_file to release generic flock locks Date: Thu, 8 Jan 2015 10:34:17 -0800 Message-Id: <1420742065-28423-3-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1420742065-28423-1-git-send-email-jlayton@primarydata.com> References: <1420742065-28423-1-git-send-email-jlayton@primarydata.com> Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 ...instead of open-coding it and removing flock locks directly. This simplifies some coming interim changes in the following patches when we have different file_lock types protected by different spinlocks. Signed-off-by: Jeff Layton --- fs/locks.c | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index fba8bc7af6d3..cec00425bfb6 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -2360,6 +2360,30 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner) EXPORT_SYMBOL(locks_remove_posix); +static void +locks_remove_flock(struct file *filp) +{ + struct file_lock fl = { + .fl_owner = filp, + .fl_pid = current->tgid, + .fl_file = filp, + .fl_flags = FL_FLOCK, + .fl_type = F_UNLCK, + .fl_end = OFFSET_MAX, + }; + + if (!file_inode(filp)->i_flock) + return; + + if (filp->f_op->flock) + filp->f_op->flock(filp, F_SETLKW, &fl); + else + flock_lock_file(filp, &fl); + + if (fl.fl_ops && fl.fl_ops->fl_release_private) + fl.fl_ops->fl_release_private(&fl); +} + /* * This function is called on the last close of an open file. */ @@ -2370,24 +2394,14 @@ void locks_remove_file(struct file *filp) struct file_lock **before; LIST_HEAD(dispose); - if (!inode->i_flock) - return; - + /* remove any OFD locks */ locks_remove_posix(filp, filp); - if (filp->f_op->flock) { - struct file_lock fl = { - .fl_owner = filp, - .fl_pid = current->tgid, - .fl_file = filp, - .fl_flags = FL_FLOCK, - .fl_type = F_UNLCK, - .fl_end = OFFSET_MAX, - }; - filp->f_op->flock(filp, F_SETLKW, &fl); - if (fl.fl_ops && fl.fl_ops->fl_release_private) - fl.fl_ops->fl_release_private(&fl); - } + /* remove flock locks */ + locks_remove_flock(filp); + + if (!inode->i_flock) + return; spin_lock(&inode->i_lock); before = &inode->i_flock; @@ -2407,8 +2421,7 @@ void locks_remove_file(struct file *filp) * some info about it and then just remove it from * the list. */ - WARN(!IS_FLOCK(fl), - "leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n", + WARN(1, "leftover lock: dev=%u:%u ino=%lu type=%hhd flags=0x%x start=%lld end=%lld\n", MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev), inode->i_ino, fl->fl_type, fl->fl_flags,