From patchwork Thu May 14 11:14:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Henriques X-Patchwork-Id: 11548519 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 04BF6139A for ; Thu, 14 May 2020 11:15:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E7BB8206DA for ; Thu, 14 May 2020 11:15:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726146AbgENLO5 (ORCPT ); Thu, 14 May 2020 07:14:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:60090 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgENLO5 (ORCPT ); Thu, 14 May 2020 07:14:57 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 60498B03E; Thu, 14 May 2020 11:14:58 +0000 (UTC) Received: from localhost (webern.olymp [local]) by webern.olymp (OpenSMTPD) with ESMTPA id 5cfcdbe1; Thu, 14 May 2020 12:14:53 +0100 (WEST) Date: Thu, 14 May 2020 12:14:53 +0100 From: Luis Henriques To: Jeff Layton , Ilya Dryomov Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] ceph: don't return -ESTALE if there's still an open file Message-ID: <20200514111453.GA99187@suse.com> MIME-Version: 1.0 Content-Disposition: inline Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org Similarly to commit 03f219041fdb ("ceph: check i_nlink while converting a file handle to dentry"), this fixes another corner case with name_to_handle_at/open_by_handle_at. The issue has been detected by xfstest generic/467, when doing: - name_to_handle_at("/cephfs/myfile") - open("/cephfs/myfile") - unlink("/cephfs/myfile") - open_by_handle_at() The call to open_by_handle_at should not fail because the file still exists and we do have a valid handle to it. Signed-off-by: Luis Henriques --- fs/ceph/export.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/ceph/export.c b/fs/ceph/export.c index 79dc06881e78..8556df9d94d0 100644 --- a/fs/ceph/export.c +++ b/fs/ceph/export.c @@ -171,12 +171,21 @@ struct inode *ceph_lookup_inode(struct super_block *sb, u64 ino) static struct dentry *__fh_to_dentry(struct super_block *sb, u64 ino) { + struct ceph_inode_info *ci; struct inode *inode = __lookup_inode(sb, ino); + if (IS_ERR(inode)) return ERR_CAST(inode); if (inode->i_nlink == 0) { - iput(inode); - return ERR_PTR(-ESTALE); + bool is_open; + ci = ceph_inode(inode); + spin_lock(&ci->i_ceph_lock); + is_open = __ceph_is_file_opened(ci); + spin_unlock(&ci->i_ceph_lock); + if (!is_open) { + iput(inode); + return ERR_PTR(-ESTALE); + } } return d_obtain_alias(inode); }