Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7603006rwb; Mon, 12 Dec 2022 17:36:14 -0800 (PST) X-Google-Smtp-Source: AA0mqf6g+sD3gMambgzCueVbyxnVRP3O8jXnJzr1d7MsGI9uf5Q97Mqj5d31wg26388kuLLcLSZ2 X-Received: by 2002:a17:902:f2ca:b0:189:ac49:fe9d with SMTP id h10-20020a170902f2ca00b00189ac49fe9dmr17414483plc.19.1670895374729; Mon, 12 Dec 2022 17:36:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670895374; cv=none; d=google.com; s=arc-20160816; b=fAUoQWSNCGZCbUqXegCA7CD6eegFZfc+Py8szlvWdfccHx+BQbdViSTEUEoT+2sj7d i28vnmw4FDtLmDoKvzjrtqjdxadJgc8ZCNtOOI8xKfozkFpnC+va97Tg9V9Qa/EOGJVW rHyvpsLkWB0ZEiam/QF40Tc2ga41UyfQUkyPKl0Nk9w2t9eEtFJAto68e6z6t//rxYIn jSSByLgwUxLYv/apD+6u0TvuiqhQXA9Jbkf2k9ik/KnaGYw6f7LvjV9BMO6Aa27hKJwY D0woTfz/9u5exGflL+nTi56h7UXtnYmN6AwEKL/9s4DBV4dFjaQFYpMaRjwpkgGbwybg Z2aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=PNnuGiXysu47AR56a+iVf1X9BI5R1Thaz9yuLikoxqk=; b=tBHSVs+VtFskQi8HoGRkwbLQL3IgkJGgNgSttwuOJvpQmiBH29bi0n3EKgqe1J6NGn gdlEuoP9IJQ8hyXreWYlTNYtQ6WkkTmQ+8dWmUkBBxpuT1nEWTNtOWot4aKrv//F7VMl votiyP1Ex6Wqw5aJnPDDQsiOsEaKFBLdY3rTpIpsS3MYimUqwbFB5Vgazn9omLs7AXwD ldj5Kvt/opVKebFkTK4IHxU5yHC5yhETvSmELmO4aW4mHEtsNLcDUakCTOm99m3fe4G0 pOqS/wxCYXdn3Isly1uSnnrMz33BTRhpwZ/f/qJTSOa7e53ERPUeS9OXyunq7yV4u3/6 wMMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IWmj5ahc; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q1-20020a170902dac100b00170f6f728d4si11799858plx.543.2022.12.12.17.36.05; Mon, 12 Dec 2022 17:36:14 -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=@redhat.com header.s=mimecast20190719 header.b=IWmj5ahc; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234053AbiLMB0f (ORCPT + 74 others); Mon, 12 Dec 2022 20:26:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233437AbiLMB0b (ORCPT ); Mon, 12 Dec 2022 20:26:31 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CACD626C for ; Mon, 12 Dec 2022 17:25:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670894736; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PNnuGiXysu47AR56a+iVf1X9BI5R1Thaz9yuLikoxqk=; b=IWmj5ahcHBKmyIRg7Cs5SqB3czgPfvrh1JwGZKdugWsB1NyLFnHMYCPfgPVf/573SuakK7 KPPMps0kluE2HW2Gy2X3ZCBxdQGBfrsfWWG6twLnBh/NcxqQ3FFSYuLNURpwCUhzhzvM8C D0aNVhMjBu36Y5i+QtHi0mKM9gdqdKM= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-57-a-qj0Nq-NSG8cYHbNKBanw-1; Mon, 12 Dec 2022 20:25:35 -0500 X-MC-Unique: a-qj0Nq-NSG8cYHbNKBanw-1 Received: by mail-pg1-f199.google.com with SMTP id f132-20020a636a8a000000b00473d0b600ebso8715612pgc.14 for ; Mon, 12 Dec 2022 17:25:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-language:content-transfer-encoding:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PNnuGiXysu47AR56a+iVf1X9BI5R1Thaz9yuLikoxqk=; b=ky9ewSnI3sDtmhvmDcBnPSb4saYnpA5ZCzVA4vXArxijiDXjP62Q1ZrKB1+/yTYFo4 Ro+8Su7wYmqoLNCkDME5Qhf0ZAN07dgZf/MeYYXHS/YCfbyp870aNE3xGBFY+c110MdB S939LuorzfuDKr+gB84ZdrPc3+WFMOycxOQZdwvreR1cLY3LsruRowy2CQaOdO3FLwdM CZGC3ZqSkZSZ7xzfZGuJhOy4K/4b9N3vr5Xr6b4M3PLeLlIgajwiukWKtEsWmDSrNIwN 75Pd8HI0GYwYnjLjfTWSDQKZKxmIv5kRHOwheGPgUa3rVuaM+AwOp+Pv4eSvKCWV2vxX CXvA== X-Gm-Message-State: ANoB5pmOAX21FbeTm988x4cFumxe40fJE4Jx44yEg9tzFrL4Owui+sQ+ 1unSr2FyybqmCEPBypOv86M6vAjh2LNcwUTQ2WseMA1qSxL/9QSUIzHq7FBg8HZaZ3EWjAjZOnf z7ynF9O8vpfbZoBGGQVeC0AX3 X-Received: by 2002:a62:be17:0:b0:56e:664f:a5f5 with SMTP id l23-20020a62be17000000b0056e664fa5f5mr19196059pff.8.1670894734049; Mon, 12 Dec 2022 17:25:34 -0800 (PST) X-Received: by 2002:a62:be17:0:b0:56e:664f:a5f5 with SMTP id l23-20020a62be17000000b0056e664fa5f5mr19196039pff.8.1670894733761; Mon, 12 Dec 2022 17:25:33 -0800 (PST) Received: from [10.72.12.143] ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id b27-20020aa7951b000000b00574c54423d3sm6587234pfp.145.2022.12.12.17.25.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Dec 2022 17:25:33 -0800 (PST) Subject: Re: [PATCH 2/2 v3] ceph: add ceph_lock_info support for file_lock To: Jeff Layton , Ilya Dryomov 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 References: <20221118020642.472484-1-xiubli@redhat.com> <20221118020642.472484-3-xiubli@redhat.com> From: Xiubo Li Message-ID: <932429ec-3dfe-0c27-6b00-0a9efa9893fa@redhat.com> Date: Tue, 13 Dec 2022 09:25:27 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 13/12/2022 02:02, Jeff Layton wrote: > On Mon, 2022-12-12 at 18:56 +0100, Ilya Dryomov wrote: >> On Fri, Nov 18, 2022 at 3:07 AM wrote: >>> From: Xiubo Li >>> >>> 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. >>> >>> Will switch to use ceph dedicate lock info to track the inode. >>> >>> 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. >>> >>> 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 >>> >>> 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 = file_inode(dst->fl_file); >>> atomic_inc(&ceph_inode(inode)->i_filelock_ref); >>> + dst->fl_u.ceph_fl.fl_inode = igrab(inode); >>> } >>> >>> +/* >>> + * 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 = file_inode(fl->fl_file); >>> - struct ceph_inode_info *ci = ceph_inode(inode); >>> + struct inode *inode = 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 = 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 &= ~CEPH_I_ERROR_FILELOCK; >>> spin_unlock(&ci->i_ceph_lock); >>> } >>> + fl->fl_u.ceph_fl.fl_inode = NULL; >>> + iput(inode); >>> } >>> >>> static const struct file_lock_operations ceph_fl_lock_ops = { >>> 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 *); >>> >>> /* that will die - we need it for nfs_lock_info */ >>> #include >>> +#include >>> >>> /* >>> * struct file_lock represents a generic "file lock". It's used to represent >>> @@ -1119,6 +1120,7 @@ struct file_lock { >>> int state; /* state of grant or error if -ve */ >>> unsigned int debug_id; >>> } afs; >>> + struct ceph_lock_info ceph_fl; >> Hi Xiubo and Jeff, >> >> 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. >> >> Jeff, could you please ack this with your file locking hat on? >> > ACK. I think that would be cleaner. Sure, will fix this. Thanks, - Xiubo > Thanks