From patchwork Wed Jan 31 23:02:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 195091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:106:209c:c626 with SMTP id mn5csp107062dyc; Wed, 31 Jan 2024 16:09:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtKKjJe7NqddxWQsLeC6iQCBYFaSUMf8mVoiXgsdQARePfDyFxvYtCtdu4q/hAnd8TofPp X-Received: by 2002:a5e:8a04:0:b0:7bc:202a:bf9 with SMTP id d4-20020a5e8a04000000b007bc202a0bf9mr3681615iok.15.1706746157848; Wed, 31 Jan 2024 16:09:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706746157; cv=pass; d=google.com; s=arc-20160816; b=f9s4+TGX+m6HLfH0y7KgEug7YWBUwbpxf3nnUx8+84Z6uowaN4TcOSex8XRqlm4cmu 3lZQBMXyTavjJTXnW+dr4S1SkzhtnYhKRIklSyl3xiIh5KlFoWkulGKH85G4VzRsMRLz IpXIHxbnoH18YTSE44fdudDqj6azCJLS3nIe+QZngez5qmCqIGm/ViOLDLcogTcgmkCm jd4c7hG9mDHPB3UhWWjrDq1YuU47ZxJJy7DK7kZypu2qu9uzAT7+PW0zbOlPBvAzW/ns sj1N+HrBxWM7x4d202Kh+PAUMVTOJzhYZcW8rjHbdKguVSQTin3pkyjThboolbut8iUV CM6Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=JKUWTSVGbMk/bimJqzBgF/lMLJ78PSQhPA5cK3IwVgg=; fh=RrE/8i+8hBLeUu5m6/R4nFh/EBmT9zKPpQTjxkZfQ6w=; b=AmXSO4IQnpa4GvSAJAZ8eutuY+RrixSiBhlenPQQyACAgAP4zNkZZyM48vkdOCu7td HoL7l6lLVpZolC3L3BaiKWf8zv4TNW1NfZzPhFQlILZPExiBsFmBBwKWbNJDLXeYSwyg Wd2ydOcHOSce2/PIxu/ifZ7CHUsDMzHxzDsnDMINxvK7GTXuumiJZG6+JOAJgDbUn4iM OcwM+l8vcd6a/0t6wRpLcXJy3i25jytiP6jiU+4yA+6KwmXTqcbpzPkDpGk2+/wQf6Eg 7MQ8AYlondzdnOqLzbCeU1Q6URzzfAxKp/GNtLyad+DP5VOP7VMw744mPAwELXjQHcUF AlrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="bM/ekbRV"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47310-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47310-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCVenVTgd6GV7EYibPI9aPpcKqSQpnGdRVeqejDNBLpSApLkoS1ZES8puuPli+32FBEp9k3icOk0uawQi/L7bCsB8c+63g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q11-20020a65684b000000b005ce19c68684si10813412pgt.495.2024.01.31.16.09.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 16:09:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47310-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="bM/ekbRV"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-47310-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47310-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C181BB2613C for ; Wed, 31 Jan 2024 23:13:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ABA1813F008; Wed, 31 Jan 2024 23:03:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bM/ekbRV" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3402D13E211; Wed, 31 Jan 2024 23:03:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706742232; cv=none; b=M/2b6qFJRe1tTKvYUH72v5iHBtej4OU0ncV+wQkbVu3kijO0McGDWKjDOQJE1ZuJKUpW9gZb4XGOaGjKkmuEPeU2iOVjbuX6+QGC2lGTwW5WjzFpDDsTdVF+Pyw51goRL2gZq+/j/Ns6Pe87f0R3DyaMN2MinYNrY9QrOylXQ0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706742232; c=relaxed/simple; bh=+fh0Pyz60IyaAdOx+0EoERtKYPFhqrIpllRCidYLo4Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z6imatu71v+il6C8JJZeDQPgw6kwcAh3rThZcKpgANo71IybuCi9IbvD9/qTSDfb8pZe8/4+kRB9XlMDDL70nStboNO/1TiaIpyzJgKOJTNCkJ/w28c5Zu1SwIkUDRLNTc+z84C1V9C36u6Q64LitJ1AK01vEpVRccSASZX42ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bM/ekbRV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED23DC43390; Wed, 31 Jan 2024 23:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706742231; bh=+fh0Pyz60IyaAdOx+0EoERtKYPFhqrIpllRCidYLo4Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bM/ekbRViAsY+5DUTUT/5NUOUze2DbyGhWio8gErtKqeAff1puRV3oVoFidhFxcrC 74+Y/EbuBOUKRsoOP6iH6jpYg4ZkxJd5FgCYz5i1YfheC8gB6jotkv28djCoZ5CHCl 0tIDSchku+P+ziP0FisUyux1IOGT+3oXNBf1b3YXYu6D6HiEmZbD7V4GJMjHBt4oTn kttrW4HaMwmDKHFes5s4df23+V/rh0S4SJ5NsllOLU60xiFTtQeipmlGfqJrlyVRxB vGWMHcS1ODdJ54p6UcLKQHM6XQSDn8hjyN8Yzr97Ij6tDJQFpQpTbgHroWJq7SRDeZ 1wYiPZ0v8v1Uw== From: Jeff Layton Date: Wed, 31 Jan 2024 18:02:05 -0500 Subject: [PATCH v3 24/47] filelock: make __locks_delete_block and __locks_wake_up_blocks take file_lock_core Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240131-flsplit-v3-24-c6129007ee8d@kernel.org> References: <20240131-flsplit-v3-0-c6129007ee8d@kernel.org> In-Reply-To: <20240131-flsplit-v3-0-c6129007ee8d@kernel.org> To: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Chuck Lever , Alexander Viro , Christian Brauner , Jan Kara , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Christian Schoenebeck , David Howells , Marc Dionne , Xiubo Li , Ilya Dryomov , Alexander Aring , David Teigland , Andreas Gruenbacher , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Mark Fasheh , Joel Becker , Joseph Qi , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Namjae Jeon , Sergey Senozhatsky , Miklos Szeredi Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, v9fs@lists.linux.dev, linux-afs@lists.infradead.org, ceph-devel@vger.kernel.org, gfs2@lists.linux.dev, linux-nfs@vger.kernel.org, ocfs2-devel@lists.linux.dev, linux-cifs@vger.kernel.org, Jeff Layton X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4001; i=jlayton@kernel.org; h=from:subject:message-id; bh=+fh0Pyz60IyaAdOx+0EoERtKYPFhqrIpllRCidYLo4Y=; b=owEBbQKS/ZANAwAIAQAOaEEZVoIVAcsmYgBlutFxs5terizvq50AGfajQ5gB4SSv/QE7zun6s 7LfTA+Vb+yJAjMEAAEIAB0WIQRLwNeyRHGyoYTq9dMADmhBGVaCFQUCZbrRcQAKCRAADmhBGVaC FTzmD/9jWU1AHowJsmJW2yQFaIH0ea4koaFqzMTBSqcK+HWHLMXGEkBSwD7pZaPUvN5mzp1/E8W 1b0C34g48/w3VQ2AnR65/mmhehnLZdjb19USwIEcyHVt+fvGuT/K8af5sMCd16GKP35di1euDE5 Knu35ZM8cbwywmNp7HZapaH89KYCHVZcFx3G++GoKh2KBauAXv8B9ha1zb3hB0RMFj3MDikNVV0 u0b6xmUGUVDZeHDV90U7MAe/nFj0cst36l+1Ea1s30Wpcr1K42eL6MqZ70HRWE93WXH5NTqG6nT h44ogNN9gqZUPZq/vO/RVPcVJd6ofWcKMLJLizOr+Uhbf1lEbKaXlORiNebQDXWr84ViPdFlDtE sDOlX1kP6HbWA2wa7Lv/w+6dAk8rou/cD7/SOr2g+Uu/3ftDPMNYoUYTWxO1AiRMkGMXGA408pw 0xlpWo+JikKkcktjPyZdjg04MVlPjGl2SjL+PfeGuPAXmDGl+u4jo52iBSQW79g3Gnaf4ovsF0d p4B2Dm0f+sKXtcR4ZUNZpigsOxk4G6s3nLfyA2lTZ2QB+jaMEH+2lWPL2A09jY1Z7j76sGIlRAK OGXZdEt7Q0xgUFTGdAOc2iyFZq2i5qGKHJiAoLARcU0E6eoE/LDAgR5ZFLTv/mHmm+6bKZkHh4i lKZhCpia9wEtUPQ== X-Developer-Key: i=jlayton@kernel.org; a=openpgp; fpr=4BC0D7B24471B2A184EAF5D3000E684119568215 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789653059417937756 X-GMAIL-MSGID: 1789653059417937756 Convert __locks_delete_block and __locks_wake_up_blocks to take a struct file_lock_core pointer. While we could do this in another way, we're going to need to add a file_lock() helper function later anyway, so introduce and use it now. Signed-off-by: Jeff Layton --- fs/locks.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/fs/locks.c b/fs/locks.c index ef67a5a7bae8..1e8b943bd7f9 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -69,6 +69,11 @@ #include +static struct file_lock *file_lock(struct file_lock_core *flc) +{ + return container_of(flc, struct file_lock, c); +} + static bool lease_breaking(struct file_lock *fl) { return fl->c.flc_flags & (FL_UNLOCK_PENDING | FL_DOWNGRADE_PENDING); @@ -654,31 +659,35 @@ static void locks_delete_global_blocked(struct file_lock_core *waiter) * * Must be called with blocked_lock_lock held. */ -static void __locks_delete_block(struct file_lock *waiter) +static void __locks_delete_block(struct file_lock_core *waiter) { - locks_delete_global_blocked(&waiter->c); - list_del_init(&waiter->c.flc_blocked_member); + locks_delete_global_blocked(waiter); + list_del_init(&waiter->flc_blocked_member); } -static void __locks_wake_up_blocks(struct file_lock *blocker) +static void __locks_wake_up_blocks(struct file_lock_core *blocker) { - while (!list_empty(&blocker->c.flc_blocked_requests)) { - struct file_lock *waiter; + while (!list_empty(&blocker->flc_blocked_requests)) { + struct file_lock_core *waiter; + struct file_lock *fl; + + waiter = list_first_entry(&blocker->flc_blocked_requests, + struct file_lock_core, flc_blocked_member); - waiter = list_first_entry(&blocker->c.flc_blocked_requests, - struct file_lock, c.flc_blocked_member); + fl = file_lock(waiter); __locks_delete_block(waiter); - if (waiter->fl_lmops && waiter->fl_lmops->lm_notify) - waiter->fl_lmops->lm_notify(waiter); + if ((waiter->flc_flags & (FL_POSIX | FL_FLOCK)) && + fl->fl_lmops && fl->fl_lmops->lm_notify) + fl->fl_lmops->lm_notify(fl); else - locks_wake_up(waiter); + locks_wake_up(fl); /* - * The setting of fl_blocker to NULL marks the "done" + * The setting of flc_blocker to NULL marks the "done" * point in deleting a block. Paired with acquire at the top * of locks_delete_block(). */ - smp_store_release(&waiter->c.flc_blocker, NULL); + smp_store_release(&waiter->flc_blocker, NULL); } } @@ -720,8 +729,8 @@ int locks_delete_block(struct file_lock *waiter) spin_lock(&blocked_lock_lock); if (waiter->c.flc_blocker) status = 0; - __locks_wake_up_blocks(waiter); - __locks_delete_block(waiter); + __locks_wake_up_blocks(&waiter->c); + __locks_delete_block(&waiter->c); /* * The setting of fl_blocker to NULL marks the "done" point in deleting @@ -773,7 +782,7 @@ static void __locks_insert_block(struct file_lock *blocker, * waiter, but might not conflict with blocker, or the requests * and lock which block it. So they all need to be woken. */ - __locks_wake_up_blocks(waiter); + __locks_wake_up_blocks(&waiter->c); } /* Must be called with flc_lock held. */ @@ -805,7 +814,7 @@ static void locks_wake_up_blocks(struct file_lock *blocker) return; spin_lock(&blocked_lock_lock); - __locks_wake_up_blocks(blocker); + __locks_wake_up_blocks(&blocker->c); spin_unlock(&blocked_lock_lock); } @@ -1159,7 +1168,7 @@ static int posix_lock_inode(struct inode *inode, struct file_lock *request, * Ensure that we don't find any locks blocked on this * request during deadlock detection. */ - __locks_wake_up_blocks(request); + __locks_wake_up_blocks(&request->c); if (likely(!posix_locks_deadlock(request, fl))) { error = FILE_LOCK_DEFERRED; __locks_insert_block(fl, request,