From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-co1nam03on0118.outbound.protection.outlook.com ([104.47.40.118]:6048 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032198AbeCAP3A (ORCPT ); Thu, 1 Mar 2018 10:29:00 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Jeff Layton , Sasha Levin Subject: [added to the 4.1 stable tree] locks: don't check for race with close when setting OFD lock Date: Thu, 1 Mar 2018 15:23:56 +0000 Message-ID: <20180301152116.1486-141-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Jeff Layton This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 0752ba807b04ccd69cb4bc8bbf829a80ee208a3c ] We don't clean out OFD locks on close(), so there's no need to check for a race with them here. They'll get cleaned out at the same time that flock locks are. Signed-off-by: Jeff Layton Acked-by: "J. Bruce Fields" Signed-off-by: Sasha Levin --- fs/locks.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index 3c234b9fbdd9..af6fcf6e0dd0 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -2192,10 +2192,12 @@ int fcntl_setlk(unsigned int fd, struct file *filp,= unsigned int cmd, error =3D do_lock_file_wait(filp, cmd, file_lock); =20 /* - * Attempt to detect a close/fcntl race and recover by - * releasing the lock that was just acquired. + * Attempt to detect a close/fcntl race and recover by releasing the + * lock that was just acquired. There is no need to do that when we're + * unlocking though, or for OFD locks. */ - if (!error && file_lock->fl_type !=3D F_UNLCK) { + if (!error && file_lock->fl_type !=3D F_UNLCK && + !(file_lock->fl_flags & FL_OFDLCK)) { /* * We need that spin_lock here - it prevents reordering between * update of i_flctx->flc_posix and check for it done in @@ -2334,10 +2336,12 @@ int fcntl_setlk64(unsigned int fd, struct file *fil= p, unsigned int cmd, error =3D do_lock_file_wait(filp, cmd, file_lock); =20 /* - * Attempt to detect a close/fcntl race and recover by - * releasing the lock that was just acquired. + * Attempt to detect a close/fcntl race and recover by releasing the + * lock that was just acquired. There is no need to do that when we're + * unlocking though, or for OFD locks. */ - if (!error && file_lock->fl_type !=3D F_UNLCK) { + if (!error && file_lock->fl_type !=3D F_UNLCK && + !(file_lock->fl_flags & FL_OFDLCK)) { /* * We need that spin_lock here - it prevents reordering between * update of i_flctx->flc_posix and check for it done in --=20 2.14.1