From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Teigland Subject: [PATCH v2] locks: skip posix unlock when there are no posix locks Date: Fri, 19 Aug 2011 12:56:13 -0400 Message-ID: <20110819165613.GB14345@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: swhiteho@redhat.com, bfields@redhat.com To: linux-fsdevel@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:1409 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756397Ab1HSQ4Q (ORCPT ); Fri, 19 Aug 2011 12:56:16 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7JGuFGJ020834 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 19 Aug 2011 12:56:15 -0400 Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org List-ID: When i_flock contains only flocks, the posix unlock is unnecessary, but called anyway. On gfs2, ocfs2, and possibly others with f_op->lock, the posix unlock can be costly, so only do it if posix locks exist. Signed-off-by: David Teigland --- fs/locks.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 703f545..d47f497 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1982,15 +1982,30 @@ out: void locks_remove_posix(struct file *filp, fl_owner_t owner) { struct file_lock lock; + struct file_lock **before; + struct inode *inode; /* * If there are no locks held on this file, we don't need to call * posix_lock_file(). Another process could be setting a lock on this * file at the same time, but we wouldn't remove that lock anyway. */ - if (!filp->f_path.dentry->d_inode->i_flock) + inode = filp->f_path.dentry->d_inode; + + if (!inode->i_flock) return; + lock_flocks(); + for_each_lock(inode, before) { + struct file_lock *fl = *before; + if (IS_POSIX(fl)) + goto do_unlock; + } + unlock_flocks(); + return; + +do_unlock: + unlock_flocks(); lock.fl_type = F_UNLCK; lock.fl_flags = FL_POSIX | FL_CLOSE; lock.fl_start = 0; -- 1.7.6