Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1323756ybk; Thu, 14 May 2020 06:17:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSX3tq2Vd0dWIbVGVKmgJnPhCN4WAgkgizquf8+29Kl5rFLwaffPtzdM/Z5XEmqOMgWjUw X-Received: by 2002:a17:906:6891:: with SMTP id n17mr3793213ejr.338.1589462268345; Thu, 14 May 2020 06:17:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589462268; cv=none; d=google.com; s=arc-20160816; b=nK++VJDf0AX47NLNue+HWFF4sMv35rn5E5ChrcGZnEoShqhHq4ctRTmv5QjnuxmWRa SV3iuwuOq3S2SheGGZYEZJeE3BP8Z1ksG4woaAqskx54cxDC5Gp6TP4BBZ3ng+X4O6r/ eJgS91inwQidTT2bNaaOBuPGHoclldM7mjyaehX5ZsdxRtX69Rm0qkFBgG7GNk2W+Chl R4sapWQRddMjLkBLNr54aF2hFmZ0AISEpUi9a85ZyGnVgJZ06nP1oVkd7DwYrMNGKUtW k6T5WHsADKG2DGgGk8Z9+lZofYjar0VdvMypQiSJil8h5A9Kc3RR/+ZFPtznLok2r1TX 6a5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=dUwLgmR4F9tJ8u+XQfptVC+BLanSfkWX8mKqWXi4czw=; b=xhhzgGKg6hvzayPkpcFuanQdYj6AI/tz26Ptrfezah2fpAXmbBIHtyCWkBAONvq6NM OHMzZrKVGaOOl7g1Puv2odzd4R62sbIXEHk1rAdqvPtRweJTEy+NsfDN/jwT7wlIqjtc 8wzpQE2do0qbE5RD0x7+DVgpDBZL0+W8jeEVophgbC4v4w9cEnbacWh5xDe8MmnXaHyg IHd0T023g9M0X0qu1TGsFgUPO37Ri1SP0MZVuVKJu3SbWuOkFqCRmYqKKLVw5v13z3SQ 9gJBaWuGEg2e8KVML4blKjNhjqEeUBDsoAhwr7twRksgdLAtDuj68w2Q1BgoxXvXb0d9 5nAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XB6Ugjlx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o20si1580089edr.279.2020.05.14.06.17.24; Thu, 14 May 2020 06:17:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XB6Ugjlx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726232AbgENNP5 (ORCPT + 99 others); Thu, 14 May 2020 09:15:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:59894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgENNP4 (ORCPT ); Thu, 14 May 2020 09:15:56 -0400 Received: from tleilax.poochiereds.net (68-20-15-154.lightspeed.rlghnc.sbcglobal.net [68.20.15.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7B327206DA; Thu, 14 May 2020 13:15:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589462156; bh=v6MXwV/gG1H4E+LPHWAerasj/q/Dsnckh5u8rtbYcbI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XB6Ugjlx1W02LH3VZWK0fqRmtjYZSNl3xW6tdtxis9HDm4ZOUr75Aq2XAHcOg2XDj EYLZkgbIWPq0x/CprqqaTBIrrj/qGQii0SrkXoVlo6d8P3nz7JPKXPOXRJmQOqTH1i M9Z22+FO6a0yNNOu7fSdROa1ZtoLKX87+Qg9RbSM= Message-ID: <4e5bf0e3bf055e53a342b19d168f6cf441781973.camel@kernel.org> Subject: Re: [PATCH] ceph: don't return -ESTALE if there's still an open file From: Jeff Layton To: Luis Henriques Cc: Ilya Dryomov , ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Amir Goldstein Date: Thu, 14 May 2020 09:15:54 -0400 In-Reply-To: <20200514124845.GA12559@suse.com> References: <20200514111453.GA99187@suse.com> <8497fe9a11ac1837813ee5f14b6ebae8fa6bf707.camel@kernel.org> <20200514124845.GA12559@suse.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.2 (3.36.2-1.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2020-05-14 at 13:48 +0100, Luis Henriques wrote: > On Thu, May 14, 2020 at 08:10:09AM -0400, Jeff Layton wrote: > > On Thu, 2020-05-14 at 12:14 +0100, Luis Henriques wrote: > > > 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); > > > } > > > > Thanks Luis. Out of curiousity, is there any reason we shouldn't ignore > > the i_nlink value here? Does anything obviously break if we do? > > Yes, the scenario described in commit 03f219041fdb is still valid, which > is basically the same but without the extra open(2): > > - name_to_handle_at("/cephfs/myfile") > - unlink("/cephfs/myfile") > - open_by_handle_at() > Ok, I guess we end up doing some delayed cleanup, and that allows the inode to be found in that situation. > The open_by_handle_at man page isn't really clear about these 2 scenarios, > but generic/426 will fail if -ESTALE isn't returned. Want me to add a > comment to the code, describing these 2 scenarios? > (cc'ing Amir since he added this test) I don't think there is any hard requirement that open_by_handle_at should fail in that situation. It generally does for most filesystems due to the way they handle cleaning up unlinked inodes, but I don't think it's technically illegal to allow the inode to still be found. If the caller cares about whether it has been unlinked it can always test i_nlink itself. Amir, is this required for some reason that I'm not aware of? Thanks, -- Jeff Layton