Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7127068rwb; Mon, 12 Dec 2022 10:21:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf4+Z1EC18SDuy5fAqyzVkUYW0CO1BSq+iYEM39aq7C+fwKlH1oohPdeWSalMotrjTDGaxIl X-Received: by 2002:a05:6a21:c012:b0:ac:8ab5:a96f with SMTP id bm18-20020a056a21c01200b000ac8ab5a96fmr22645739pzc.61.1670869306000; Mon, 12 Dec 2022 10:21:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670869305; cv=none; d=google.com; s=arc-20160816; b=mKbAsAmF+24m0ww8cmrRLCR+7naggVttF6pwneZAU2Scq0uGdR5THataEhjqsn7nPd 9yVIlp4IAddmlikbGH9uSPXYsW+mluMstIl97JgEdKkRSie7I5hjT/KrZMfSOOvSUSTV UKq9RWpZlgt26a8y5D9h4/aFUaajZI18VFYD33ELor6TTv9LXgJi5UfPZJ8YAnPT9Cfs T9Vi8C8glmZhWdmpJOrd4VlL5I82fxRd3utxIuo/4jBZJ5fTHmuSf13v6/bNquvQFIUz 40CjYxb9bnXwSXVZPnZqhRTFO+Sql0QhlJmbonpHosM5ViYT4ohqtbmytSAx9na9X6jj dFYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=5VxE5ecSiQbPlEx4ZASSbTV+5hOQru75mK4BygyXzSc=; b=izJWQXePWj8y8R8qsaVIBom3REsh+WSfcljANWdW5INkes7/hu45ff6tBQtDoMclJl cCtarcdQYvdW8F8gkpfxe+ebRu+eoVaBB93nJk8SDNpfZGluNfs1/qT0s0KkG6XKZvjt w63Iw1ZGyttpvnv/oLNsTqfjEFjvev0ZA663fu+zHQze38w/iYAevVRUaop9/DFrZQLK pFSWNuEdaRZjSPhusqUOIW7FurB4VvDDgDKvzcqjlI6HYXhbeGbOhoaqMLk1NcbBYOqc 3lLUCeraSL5ChgYhVoRVMy/V0E7fru0TPH0HFogF6Ky/QsKDjeGRSWPdyHksw15DdjWt /F6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i6rk80ZE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 205-20020a6301d6000000b00478ff3661c5si10332674pgb.229.2022.12.12.10.21.36; Mon, 12 Dec 2022 10:21:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i6rk80ZE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232290AbiLLSCr (ORCPT + 74 others); Mon, 12 Dec 2022 13:02:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231971AbiLLSCl (ORCPT ); Mon, 12 Dec 2022 13:02:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E5A3BC; Mon, 12 Dec 2022 10:02:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DFDD4611A1; Mon, 12 Dec 2022 18:02:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FEFAC433D2; Mon, 12 Dec 2022 18:02:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670868158; bh=3GKIRZb4uU1EeNPMEs5V6EixOSqw1dZwgmBOv4XdRgw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=i6rk80ZEyDNj+joL4OYR2+K9v7vTmuT2b63ZLfuv2XwVdKCwdiJosYWDTR7+NYS8h b7xBIKNU+Beg8JNxVNNBTWgxDqueLSBcZ7TI/U86wc8KSfqQJdmM9e4vjYsNIWff54 gDaeD1YBSvAKKVx6aMvKD73xRqYPFg/XBD4EKICCiUDyqJ97HMSWT1nlyUbXYPdFA4 6yBiFhnn99rF35C7nn4E3GvjqUaZMI2sseB72DXg//n+bQ7jaKLSATkOHV7xzwm++W RdVDDFAecxgyNQlZP0+QEQSsPKyzhB2wxDLOaGKfsk4fqRrIl0LQVfmBzk7+xMsmpT HtXjrKwg2qWzA== Message-ID: Subject: Re: [PATCH 2/2 v3] ceph: add ceph_lock_info support for file_lock From: Jeff Layton To: Ilya Dryomov , xiubli@redhat.com Cc: ceph-devel@vger.kernel.org, lhenriques@suse.de, mchangir@redhat.com, viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org Date: Mon, 12 Dec 2022 13:02:36 -0500 In-Reply-To: References: <20221118020642.472484-1-xiubli@redhat.com> <20221118020642.472484-3-xiubli@redhat.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.2 (3.46.2-1.fc37) MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2022-12-12 at 18:56 +0100, Ilya Dryomov wrote: > On Fri, Nov 18, 2022 at 3:07 AM wrote: > >=20 > > From: Xiubo Li > >=20 > > When ceph releasing the file_lock it will try to get the inode pointer > > from the fl->fl_file, which the memory could already be released by > > another thread in filp_close(). Because in VFS layer the fl->fl_file > > doesn't increase the file's reference counter. > >=20 > > Will switch to use ceph dedicate lock info to track the inode. > >=20 > > And in ceph_fl_release_lock() we should skip all the operations if > > the fl->fl_u.ceph_fl.fl_inode is not set, which should come from > > the request file_lock. And we will set fl->fl_u.ceph_fl.fl_inode when > > inserting it to the inode lock list, which is when copying the lock. > >=20 > > Cc: stable@vger.kernel.org > > Cc: Jeff Layton > > URL: https://tracker.ceph.com/issues/57986 > > Signed-off-by: Xiubo Li > > --- > > fs/ceph/locks.c | 20 ++++++++++++++++++-- > > include/linux/ceph/ceph_fs_fl.h | 17 +++++++++++++++++ > > include/linux/fs.h | 2 ++ > > 3 files changed, 37 insertions(+), 2 deletions(-) > > create mode 100644 include/linux/ceph/ceph_fs_fl.h > >=20 > > diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c > > index b191426bf880..621f38f10a88 100644 > > --- a/fs/ceph/locks.c > > +++ b/fs/ceph/locks.c > > @@ -34,18 +34,34 @@ static void ceph_fl_copy_lock(struct file_lock *dst= , struct file_lock *src) > > { > > struct inode *inode =3D file_inode(dst->fl_file); > > atomic_inc(&ceph_inode(inode)->i_filelock_ref); > > + dst->fl_u.ceph_fl.fl_inode =3D igrab(inode); > > } > >=20 > > +/* > > + * Do not use the 'fl->fl_file' in release function, which > > + * is possibly already released by another thread. > > + */ > > static void ceph_fl_release_lock(struct file_lock *fl) > > { > > - struct inode *inode =3D file_inode(fl->fl_file); > > - struct ceph_inode_info *ci =3D ceph_inode(inode); > > + struct inode *inode =3D fl->fl_u.ceph_fl.fl_inode; > > + struct ceph_inode_info *ci; > > + > > + /* > > + * If inode is NULL it should be a request file_lock, > > + * nothing we can do. > > + */ > > + if (!inode) > > + return; > > + > > + ci =3D ceph_inode(inode); > > if (atomic_dec_and_test(&ci->i_filelock_ref)) { > > /* clear error when all locks are released */ > > spin_lock(&ci->i_ceph_lock); > > ci->i_ceph_flags &=3D ~CEPH_I_ERROR_FILELOCK; > > spin_unlock(&ci->i_ceph_lock); > > } > > + fl->fl_u.ceph_fl.fl_inode =3D NULL; > > + iput(inode); > > } > >=20 > > static const struct file_lock_operations ceph_fl_lock_ops =3D { > > diff --git a/include/linux/ceph/ceph_fs_fl.h b/include/linux/ceph/ceph_= fs_fl.h > > new file mode 100644 > > index 000000000000..ad1cf96329f9 > > --- /dev/null > > +++ b/include/linux/ceph/ceph_fs_fl.h > > @@ -0,0 +1,17 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* > > + * ceph_fs_fl.h - Ceph lock info > > + * > > + * LGPL2 > > + */ > > + > > +#ifndef CEPH_FS_FL_H > > +#define CEPH_FS_FL_H > > + > > +#include > > + > > +struct ceph_lock_info { > > + struct inode *fl_inode; > > +}; > > + > > +#endif > > diff --git a/include/linux/fs.h b/include/linux/fs.h > > index d6cb42b7e91c..2b03d5e375d7 100644 > > --- a/include/linux/fs.h > > +++ b/include/linux/fs.h > > @@ -1066,6 +1066,7 @@ bool opens_in_grace(struct net *); > >=20 > > /* that will die - we need it for nfs_lock_info */ > > #include > > +#include > >=20 > > /* > > * struct file_lock represents a generic "file lock". It's used to rep= resent > > @@ -1119,6 +1120,7 @@ struct file_lock { > > int state; /* state of grant or er= ror if -ve */ > > unsigned int debug_id; > > } afs; > > + struct ceph_lock_info ceph_fl; >=20 > Hi Xiubo and Jeff, >=20 > Xiubo, instead of defining struct ceph_lock_info and including > a CephFS-specific header file in linux/fs.h, I think we should repeat > what was done for AFS -- particularly given that ceph_lock_info ends up > being a dummy type that isn't mentioned anywhere else. >=20 > Jeff, could you please ack this with your file locking hat on? >=20 ACK. I think that would be cleaner. Thanks --=20 Jeff Layton