From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84B7FEB64D7 for ; Tue, 20 Jun 2023 11:12:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232641AbjFTLMV (ORCPT ); Tue, 20 Jun 2023 07:12:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232430AbjFTLMR (ORCPT ); Tue, 20 Jun 2023 07:12:17 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A7FA10FE; Tue, 20 Jun 2023 04:12:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 80C26611E2; Tue, 20 Jun 2023 11:12:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D894C433C0; Tue, 20 Jun 2023 11:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687259533; bh=48Q1ZvZWks9PL/vJ+2ghQX3YFsGy4B0LOKhH2s8OAiY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=lAQamsTgFEzaPXSFzQljTEmdNDn4UuRICLZgEEuVC3CBhxynrKaamZgCDbzFRpUg1 l7uUSdesVHquPyMRFYlV4RrZPDg0HLcXcGB/KyRtN44+N/JnFLZe5fz3BUJTPVVaz/ 9RY+X7oe9yci2dZNFdQVmFh5tOwd8Yn/gJU+7NjBYUCY6hboCYQZixQoJNNLtwAoLp +SPB8AmPCh+e2KBcQHmxg6EqsrNaN9hFMSlyws67yrSQO54bb97TFhP3KX4DmEZB7i r3/W0HIGggtrHAyEH7Uphw3glax5kLduey7UaXSYp4y20jZqU0ko9mql/5TZPTo71G oqhsbtPmlFdQA== Message-ID: Subject: Re: [PATCH 2/3] fd/locks: allow get the lock owner by F_OFD_GETLK From: Jeff Layton To: stsp , linux-kernel@vger.kernel.org Cc: Chuck Lever , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org Date: Tue, 20 Jun 2023 07:12:12 -0400 In-Reply-To: References: <20230620095507.2677463-1-stsp2@yandex.ru> <20230620095507.2677463-3-stsp2@yandex.ru> <5728ebda22a723b0eb209ae078e8f132d7b4ac7b.camel@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.3 (3.48.3-1.fc38) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2023-06-20 at 15:57 +0500, stsp wrote: > Hello, >=20 > 20.06.2023 15:51, Jeff Layton =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > > On Tue, 2023-06-20 at 14:55 +0500, Stas Sergeev wrote: > > > Currently F_OFD_GETLK sets the pid of the lock owner to -1. > > > Remove such behavior to allow getting the proper owner's pid. > > > This may be helpful when you want to send some message (like SIGKILL) > > > to the offending locker. > > >=20 > > > Signed-off-by: Stas Sergeev > > >=20 > > > CC: Jeff Layton > > > CC: Chuck Lever > > > CC: Alexander Viro > > > CC: Christian Brauner > > > CC: linux-fsdevel@vger.kernel.org > > > CC: linux-kernel@vger.kernel.org > > >=20 > > > --- > > > fs/locks.c | 2 -- > > > 1 file changed, 2 deletions(-) > > >=20 > > > diff --git a/fs/locks.c b/fs/locks.c > > > index 210766007e63..ee265e166542 100644 > > > --- a/fs/locks.c > > > +++ b/fs/locks.c > > > @@ -2158,8 +2158,6 @@ static pid_t locks_translate_pid(struct file_lo= ck *fl, struct pid_namespace *ns) > > > pid_t vnr; > > > struct pid *pid; > > > =20 > > > - if (IS_OFDLCK(fl)) > > > - return -1; > > > if (IS_REMOTELCK(fl)) > > > return fl->fl_pid; > > > /* > > NACK on this one. > >=20 > > OFD locks are not owned by processes. They are owned by the file > > description (hence the name). Because of this, returning a pid here is > > wrong. >=20 > But fd is owned by a process. No, it isn't. fd's can be handed off between processes via unix descriptors. Multithreaded processes are also a bit of a gray area here: Suppose I open a file and set an OFD lock on it in one task, and then let that task exit while the file is still open. What should l_pid say in that case? > PID has a meaning, you can send SIGKILL > to the returned PID, and the lock is clear. > Was there any reason to hide the PID at > a first place? >=20 Yes, because OFD locks are not tied to a pid in the same way that traditional POSIX locks are. >=20 > > This precedent comes from BSD, where flock() and POSIX locks can > > conflict. BSD returns -1 for the pid if you call F_GETLK on a file > > locked with flock(). Since OFD locks have similar ownership semantics t= o > > flock() locks, we use the same convention here. > OK if you insist I can drop this one and > search the PID by some other means. > Just a bit unsure what makes it so important > to overwrite the potentially useful info > with -1. >=20 > So in case you insist on that, then should > I send a v2 or can you just drop the patch > yourself? --=20 Jeff Layton