From patchwork Thu Jun 8 08:46:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiachen Zhang X-Patchwork-Id: 104881 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp144060vqr; Thu, 8 Jun 2023 02:10:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+VH8RulvR7MrC8Bv36xmkUHnbErphYj6zCb+DZGvy2MJznnyQEJHs6RBq0DesLtUmQGsl X-Received: by 2002:a05:6a20:c198:b0:10c:5324:dba with SMTP id bg24-20020a056a20c19800b0010c53240dbamr5750919pzb.28.1686215457686; Thu, 08 Jun 2023 02:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686215457; cv=none; d=google.com; s=arc-20160816; b=DZ8jqDe1j7N1yW+DmJFRqZj5glSyhF5M6geTyuId5qc4RS74SoFABfiVCMbVi5BSKU PR4N7hfEx/L16XTDYXj2mSh09BUskGiRTB5PF6Qs1XveJ8c01ZRMc01ww+1mY5PVwIzi FheHFGlzslySgrhMgqyAqyHL7bDy+TBCiuO1O7HbRtovHY0BvZQRFayiUJmkUNPniAJh eNtzl0bJhGth/kSW2X+IRsc7437yBuxND+Nc8HuvYFy4zirs4suaHbBkwgNYgOo7oyEN ZStLn/oahYyVxakuPlLJcVTU1ffTKV+P5+m2Ta9daV47dJarrWakP788vtowkdU48atL 5Rrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jpOSC83U6MeRWzobwwrbyrIn8PFmAweJrd0CPHgT5eo=; b=ocoqQw92W82qwEcSi/gN8V3nesrYhJdZ/mcxIKty8PKzTD0A0TiQCO8wVJBvvbAmQu l9gxFtdL4bV2uQRgsiW5+xV7Wb4GqbJBD5pFA/3h+dqXabJaak7Nfut2ljltqj25Qyct mbkKdqHCXzClslioRKq2oj7IncBK0Wfjk05ZM0zYFawVtKgtocy3uEPw4+hNhYb+st6M M/bHkEgfklUC1p9fTH1yKHrdwQR9SC2Z5d9XbFSi2Kp2HPvTcf0D0kpN0by6/VY4YLuE rt163iLQrmeHnhPXROoY7d5WLngPZGQY1QbRJwPmlW4XoBKlZrWcRH8zNs4kTaBftS5w swnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=lB9UnP+P; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 67-20020a630246000000b00517a2ca5ecbsi701107pgc.692.2023.06.08.02.10.45; Thu, 08 Jun 2023 02:10:57 -0700 (PDT) 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=@bytedance.com header.s=google header.b=lB9UnP+P; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233998AbjFHIsL (ORCPT + 99 others); Thu, 8 Jun 2023 04:48:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235564AbjFHIro (ORCPT ); Thu, 8 Jun 2023 04:47:44 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF4411984 for ; Thu, 8 Jun 2023 01:47:21 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-652d76be8c2so287913b3a.3 for ; Thu, 08 Jun 2023 01:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686214041; x=1688806041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jpOSC83U6MeRWzobwwrbyrIn8PFmAweJrd0CPHgT5eo=; b=lB9UnP+PZk/bGV8hLEcegEzVxi28mg+gtSjiuOudDXzqRQv5k1+5jBOHYdossrt9Es ERgR+FMrAuts8z9XMAxuklmArlSxafDMUAiEKOsMrqFFKQN/UsRQxIpfB87StBqVqFHK Ura+mvZg4cga1RTr15CeCTDtETNyE9Gps03oGJuXVwJ8Tb17SIPRhjWqxxgQpW7WxDdZ XMbtMfT+tMJvxCFtMhaY0FtUHJrrlbqn5MzZP+RsV63rq3EmAYjPZ4logvdQMc3zWh9I ZVrrOd1xrLz1PrQNV4pauX4xGZLJ18NSmtBMz4ze4YB6aNgvmevGv+UzAnCOi4PNh2Nh 3KdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686214041; x=1688806041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jpOSC83U6MeRWzobwwrbyrIn8PFmAweJrd0CPHgT5eo=; b=d5nx5/6n82NScLCyPIfxrepsxRuULn9FeyKFvgxyM92dcPvBuqRzj2pimIjlDM5ht2 8RdcZaQ09/hXDGjLWSi0yduq5lT1TT2P0CC/5QMbvsZxTfuzWxkWSaCv50xcojJa8J25 lujFr5DrbKuOij9wZhslRkIeRUyN9IMSzw8F6+zTyBWxxq72BDzKRDDIlk3BWiZ5sJXw +7S5tpYhdH8bdyP1Vk5naNGGAIxD1vjNpFrjt/xG7pTeeFDA24bzFOUcLTBC4/2arb8U JR2oxEDO1FZvlIbQZverZj6ffhBj8vHtBQez8FYUJMPG0IsiJthbcCljPVfKcPs/VpuA 0FzQ== X-Gm-Message-State: AC+VfDzgAc4f4mUlhvO2yZxH5pDJTip/0rvwsnHxff78okiOYWRan556 f2au1HXAtgCIles4k0RD7WD0HQ== X-Received: by 2002:a05:6a00:18aa:b0:658:26a8:9d9e with SMTP id x42-20020a056a0018aa00b0065826a89d9emr10720128pfh.29.1686214041248; Thu, 08 Jun 2023 01:47:21 -0700 (PDT) Received: from localhost.localdomain ([61.213.176.13]) by smtp.gmail.com with ESMTPSA id 23-20020aa79157000000b0063b806b111csm614160pfi.169.2023.06.08.01.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 01:47:20 -0700 (PDT) From: Jiachen Zhang To: Miklos Szeredi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , me@jcix.top, Jiachen Zhang Subject: [PATCH 1/2] fuse: support unlock remote OFD locks on file release Date: Thu, 8 Jun 2023 16:46:08 +0800 Message-Id: <20230608084609.14245-2-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230608084609.14245-1-zhangjiachen.jaycee@bytedance.com> References: <20230608084609.14245-1-zhangjiachen.jaycee@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768125059567183174?= X-GMAIL-MSGID: =?utf-8?q?1768125059567183174?= Like flock(2), the fcntl(2) OFD locks also use struct file addresses as the lock owner ID, and also should be unlocked on file release. The commit 37fb3a30b462 ("fuse: fix flock") fixed the flock unlocking issue on file release. This commit aims to fix the OFD lock by reusing the release_flag 'FUSE_RELEASE_FLOCK_UNLOCK'. The FUSE daemons should unlock both OFD locks and flocks in the FUSE_RELEASE handler. To make it more clear, rename 'ff->flock' to 'ff->unlock_on_release', as it would be used for both flock and OFD lock. It will be set true if the value of fl->fl_owner equals to the struct file address. Fixes: 37fb3a30b462 ("fuse: fix flock") Signed-off-by: Jiachen Zhang Tested-By: Jochen Friedrich --- fs/fuse/file.c | 17 ++++++++++++++--- fs/fuse/fuse_i.h | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index de37a3a06a71..7fe9d405969e 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -312,7 +312,7 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff, fuse_prepare_release(fi, ff, open_flags, opcode); - if (ff->flock) { + if (ff->unlock_on_release) { ra->inarg.release_flags |= FUSE_RELEASE_FLOCK_UNLOCK; ra->inarg.lock_owner = fuse_lock_owner_id(ff->fm->fc, id); } @@ -2650,8 +2650,19 @@ static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl) } else { if (fc->no_lock) err = posix_lock_file(file, fl, NULL); - else + else { + /* + * Like flock, the OFD lock also uses the struct + * file address as the fl_owner, and should be + * unlocked on file release. + */ + if (file == fl->fl_owner) { + struct fuse_file *ff = file->private_data; + + ff->unlock_on_release = true; + } err = fuse_setlk(file, fl, 0); + } } return err; } @@ -2668,7 +2679,7 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl) struct fuse_file *ff = file->private_data; /* emulate flock with POSIX locks */ - ff->flock = true; + ff->unlock_on_release = true; err = fuse_setlk(file, fl, 1); } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 9b7fc7d3c7f1..574f67bd5684 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -225,7 +225,7 @@ struct fuse_file { wait_queue_head_t poll_wait; /** Has flock been performed on this file? */ - bool flock:1; + bool unlock_on_release:1; }; /** One input argument of a request */ From patchwork Thu Jun 8 08:46:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiachen Zhang X-Patchwork-Id: 104878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp141878vqr; Thu, 8 Jun 2023 02:06:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ64AdgEvaxl+r80AL9tfR5yyRTVoeYLxlPqYDyNXnZ0LhL0IRz0j+k9aLrVLgrOTKISKvW5 X-Received: by 2002:a05:6a21:3295:b0:10b:cdb1:3563 with SMTP id yt21-20020a056a21329500b0010bcdb13563mr7105465pzb.46.1686215182692; Thu, 08 Jun 2023 02:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686215182; cv=none; d=google.com; s=arc-20160816; b=iJlZ/41tpR8DdKWCgQZOdo1iuvS0jUiJ3oNqWYuGtHGBDXRKK0x2lNrdKlRWa+ixVq Oyo/FLRXvd7EkSkRxsozkgGogsHdacT4pV1WKXgSihh+JK3qw+2W8b7COZK58weL57cG Ex2RX+VlFw9MOHarunHX1JjTIk1xK6yKfr2DcgZl3+gTJqzxZFfrb+zBuejtFJYcBhbf lkqG4OYOyzVydlj9iA4Ms7kyRS1uLEuYxrRb9dtMYqNgCJdcSvmokHMgnLUrIQHl+NUc CcQRbERPSFtY8kA7Bd9Mpr+KdaN+NUVGEdp/6dE+epz7R6ner4uF9VW5zEut9LUDmQG/ DgFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=M478tZ0BJPqFdShribkt4DG9LiqmYQZeG2OJxmtwTQI=; b=sxoppSnt8CsC2glQouSNBEYcsF1KU7kSAUfJf6L9QgBbHdTAP6e7W9tlKLF4JolcsK aeyMejW/QE0yOqq/JJimZT+JD5WlSZTATrcp7/14+Li2KFZ0eMr7UML++MmY+o7lccv2 15sZJe9YmQoYGMu0NaRWHMeGqQZo5HI/9wskhDzPOcu3E+SNLWxCh8lxnMsVAfF2gaBg IdBi0G6sDsvr+gwLgTHh+Xd2Nb5HrLzoAmF0sWwlwoUmE3L9W+H4SOe2fC1NPaRsJn/S iDyxeWncZUHawir+bdLtI/isGc7SKlknKXxTsB9+QO56BfQ+vYPlEK/JR56UpuTwXOPT 55vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="Yq2Nya/6"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w201-20020a627bd2000000b00625559a78a2si572201pfc.107.2023.06.08.02.06.06; Thu, 08 Jun 2023 02:06:22 -0700 (PDT) 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=@bytedance.com header.s=google header.b="Yq2Nya/6"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229827AbjFHIs2 (ORCPT + 99 others); Thu, 8 Jun 2023 04:48:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235684AbjFHIr4 (ORCPT ); Thu, 8 Jun 2023 04:47:56 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6861B270B for ; Thu, 8 Jun 2023 01:47:31 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-652dd220d67so271338b3a.3 for ; Thu, 08 Jun 2023 01:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1686214051; x=1688806051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M478tZ0BJPqFdShribkt4DG9LiqmYQZeG2OJxmtwTQI=; b=Yq2Nya/66Vu5w6nNpTUv8LEnsCGR+JlJ895K/cvR0mlClcb2DLPGqhvMmAhPRnVC6P 5lyLBb0BanEOEB5t67nNrVRDwmL/nXyneeJKirBxtqfYoX82wSUEyObyvO5lBx5WlZjd 7IFu2/h9klmSHROrvtKaxHRzYYf97RrRZ7R6kUT/MptavElCUHxFZYVt8v39v0QUxqH8 MBekCo2B/5+W5SBtVF33Auv200I2Z82VjkUUpo4jXKJb6wedh1dfBUxH68MnoVoVRJcq CehSyCf+cG+5K5kWw96LsHynVXZEpos6blrNXcKzRev92YSyY59ZKV4R2rqBlgxN/CeI vyVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686214051; x=1688806051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M478tZ0BJPqFdShribkt4DG9LiqmYQZeG2OJxmtwTQI=; b=azADb3PtNZgOQvVOgPuBDcCD5gW/1te6cilvWEC7JNh9tg+B18hZ//sv5Lwmv7tDIt iG7nbpPZWReuGBzJfBuj11jXK7rhlWfoVy3sXQbPQdkxgMePXb4PySt7sHoGZnzqO0Lq cIWGcsg958qGl2/N8DUcHwJG3vfog/hYcQRov5Nkbe/0XQv44cM9mRY/DzD4bTUvBB6r lkn0ZuZ/xSYh9DJIcjwbxtL46eIHApDh03jOYcGpiSXqFFZecxHuKyQQGan32U/54KVk RV8quET0kYnpOnuBiZYFdFCdF6/GHTscgP8b40ZyzwfliVW6/GPn/nx7awJL8TuzUiGb gpTA== X-Gm-Message-State: AC+VfDwHK3oAIi7GunOhXjZBQjskhTDtYhF8ZXtmo0dXyglKGIV7wyss DZMIxEA7YrauD4TfT0pG9urJv+o8NwCuVqdlgOE= X-Received: by 2002:a05:6a20:7d85:b0:10d:d0cd:c1c7 with SMTP id v5-20020a056a207d8500b0010dd0cdc1c7mr7184475pzj.15.1686214050909; Thu, 08 Jun 2023 01:47:30 -0700 (PDT) Received: from localhost.localdomain ([61.213.176.13]) by smtp.gmail.com with ESMTPSA id 23-20020aa79157000000b0063b806b111csm614160pfi.169.2023.06.08.01.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 01:47:30 -0700 (PDT) From: Jiachen Zhang To: Miklos Szeredi , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , me@jcix.top, Jiachen Zhang Subject: [PATCH 2/2] fuse: remove an unnecessary if statement Date: Thu, 8 Jun 2023 16:46:09 +0800 Message-Id: <20230608084609.14245-3-zhangjiachen.jaycee@bytedance.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230608084609.14245-1-zhangjiachen.jaycee@bytedance.com> References: <20230608084609.14245-1-zhangjiachen.jaycee@bytedance.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768124771465169567?= X-GMAIL-MSGID: =?utf-8?q?1768124771465169567?= FUSE remote locking code paths never add any locking state to inode->i_flctx, so the locks_remove_posix() function called on file close will return without calling fuse_setlk(). Therefore, as the if statement to be removed in this commit will always be false, remove it for clearness. Fixes: 7142125937e1 ("[PATCH] fuse: add POSIX file locking support") Signed-off-by: Jiachen Zhang --- fs/fuse/file.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 7fe9d405969e..57789215c666 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2619,10 +2619,6 @@ static int fuse_setlk(struct file *file, struct file_lock *fl, int flock) return -ENOLCK; } - /* Unlock on close is handled by the flush method */ - if ((fl->fl_flags & FL_CLOSE_POSIX) == FL_CLOSE_POSIX) - return 0; - fuse_lk_fill(&args, file, fl, opcode, pid_nr, flock, &inarg); err = fuse_simple_request(fm, &args);