From patchwork Tue Feb 11 08:59:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 11375087 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31DAD1580 for ; Tue, 11 Feb 2020 08:59:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 116B12070A for ; Tue, 11 Feb 2020 08:59:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XJOwbV3S" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727769AbgBKI7K (ORCPT ); Tue, 11 Feb 2020 03:59:10 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:54080 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727608AbgBKI7K (ORCPT ); Tue, 11 Feb 2020 03:59:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581411549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=OpYLi/SKvpTFGnb6x+Unzb5oJB6614lgbLk6nYwF4jI=; b=XJOwbV3SdovLsdQC5zTu8oJH9UCYAaqaDpeziM6XRjW7Q2qft1CJnWuXbx5GcwH67QI4Ii zYn433HtoNSm5f1bGNi4g1rk/Wd+nkmsvL8YWfVCo+HFpsIaCuE4cf7Th2gHtvqg7FM3yP nGOM1lC672YoXoI7UIjzQwWJjZnw4fk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-100-rVaUnRCPNyGTXIRerrQR4Q-1; Tue, 11 Feb 2020 03:59:05 -0500 X-MC-Unique: rVaUnRCPNyGTXIRerrQR4Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E6D4A1922961; Tue, 11 Feb 2020 08:59:04 +0000 (UTC) Received: from zhyan-laptop.redhat.com (ovpn-13-118.pek2.redhat.com [10.72.13.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 117185D9CA; Tue, 11 Feb 2020 08:59:02 +0000 (UTC) From: "Yan, Zheng" To: jlayton@kernel.org, ceph-devel@vger.kernel.org Cc: "Yan, Zheng" Subject: [PATCH] ceph: check if file lock exists before sending unlock request Date: Tue, 11 Feb 2020 16:59:01 +0800 Message-Id: <20200211085901.16256-1-zyan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org When a process exits, kernel closes its files. locks_remove_file() is called to remove file locks on these files. locks_remove_file() tries unlocking files locks even there is no file locks. Signed-off-by: "Yan, Zheng" --- fs/ceph/locks.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c index 544e9e85b120..78be861259eb 100644 --- a/fs/ceph/locks.c +++ b/fs/ceph/locks.c @@ -255,9 +255,21 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) else lock_cmd = CEPH_LOCK_UNLOCK; + if (op == CEPH_MDS_OP_SETFILELOCK && F_UNLCK == fl->fl_type) { + unsigned int orig_flags = fl->fl_flags; + fl->fl_flags |= FL_EXISTS; + err = posix_lock_file(file, fl, NULL); + fl->fl_flags = orig_flags; + if (err == -ENOENT) { + if (!(orig_flags & FL_EXISTS)) + err = 0; + return err; + } + } + err = ceph_lock_message(CEPH_LOCK_FCNTL, op, inode, lock_cmd, wait, fl); if (!err) { - if (op == CEPH_MDS_OP_SETFILELOCK) { + if (op == CEPH_MDS_OP_SETFILELOCK && F_UNLCK != fl->fl_type) { dout("mds locked, locking locally\n"); err = posix_lock_file(file, fl, NULL); if (err) { @@ -311,9 +323,21 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl) else lock_cmd = CEPH_LOCK_UNLOCK; + if (F_UNLCK == fl->fl_type) { + unsigned int orig_flags = fl->fl_flags; + fl->fl_flags |= FL_EXISTS; + err = locks_lock_file_wait(file, fl); + fl->fl_flags = orig_flags; + if (err == -ENOENT) { + if (!(orig_flags & FL_EXISTS)) + err = 0; + return err; + } + } + err = ceph_lock_message(CEPH_LOCK_FLOCK, CEPH_MDS_OP_SETFILELOCK, inode, lock_cmd, wait, fl); - if (!err) { + if (!err && F_UNLCK != fl->fl_type) { err = locks_lock_file_wait(file, fl); if (err) { ceph_lock_message(CEPH_LOCK_FLOCK,