linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: stsp <stsp2@yandex.ru>, linux-kernel@vger.kernel.org
Cc: Chuck Lever <chuck.lever@oracle.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 2/3] fd/locks: allow get the lock owner by F_OFD_GETLK
Date: Tue, 20 Jun 2023 07:12:12 -0400	[thread overview]
Message-ID: <eaccc14ddc6b546e5913eb557fec55f77cb5424d.camel@kernel.org> (raw)
In-Reply-To: <a1e7f5c1-76ef-19e5-91db-a62f7615b28a@yandex.ru>

On Tue, 2023-06-20 at 15:57 +0500, stsp wrote:
> Hello,
> 
> 20.06.2023 15:51, Jeff Layton пишет:
> > 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.
> > > 
> > > Signed-off-by: Stas Sergeev <stsp2@yandex.ru>
> > > 
> > > CC: Jeff Layton <jlayton@kernel.org>
> > > CC: Chuck Lever <chuck.lever@oracle.com>
> > > CC: Alexander Viro <viro@zeniv.linux.org.uk>
> > > CC: Christian Brauner <brauner@kernel.org>
> > > CC: linux-fsdevel@vger.kernel.org
> > > CC: linux-kernel@vger.kernel.org
> > > 
> > > ---
> > >   fs/locks.c | 2 --
> > >   1 file changed, 2 deletions(-)
> > > 
> > > 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_lock *fl, struct pid_namespace *ns)
> > >   	pid_t vnr;
> > >   	struct pid *pid;
> > >   
> > > -	if (IS_OFDLCK(fl))
> > > -		return -1;
> > >   	if (IS_REMOTELCK(fl))
> > >   		return fl->fl_pid;
> > >   	/*
> > NACK on this one.
> > 
> > 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.
> 
> 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?
> 

Yes, because OFD locks are not tied to a pid in the same way that
traditional POSIX locks are.

> 
> > 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 to
> > 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.
> 
> So in case you insist on that, then should
> I send a v2 or can you just drop the patch
> yourself?

-- 
Jeff Layton <jlayton@kernel.org>

  reply	other threads:[~2023-06-20 11:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20  9:55 [PATCH 0/3] RFC: F_OFD_GETLK should provide more info Stas Sergeev
2023-06-20  9:55 ` [PATCH 1/3] fs/locks: F_UNLCK extension for F_OFD_GETLK Stas Sergeev
2023-06-20 10:46   ` Jeff Layton
2023-06-20 11:00     ` stsp
2023-06-20 11:15       ` Jeff Layton
2023-06-21 15:24         ` stsp
2023-06-20  9:55 ` [PATCH 2/3] fd/locks: allow get the lock owner by F_OFD_GETLK Stas Sergeev
2023-06-20 10:51   ` Jeff Layton
2023-06-20 10:57     ` stsp
2023-06-20 11:12       ` Jeff Layton [this message]
2023-06-20 11:45         ` stsp
2023-06-20 12:02           ` Jeff Layton
2023-06-20 12:34             ` stsp
2023-06-20 13:19               ` Jeff Layton
2023-06-20 13:39                 ` stsp
2023-06-20 13:46                   ` Matthew Wilcox
2023-06-20 13:47                     ` stsp
2023-06-20 14:36                       ` Matthew Wilcox
2023-06-20 15:45                         ` stsp
2023-06-20 17:05                           ` Matthew Wilcox
2023-06-21  2:54                             ` stsp
2023-06-23 13:10                     ` David Laight
2023-06-20 13:58                   ` Jeff Layton
2023-06-21  6:57                     ` stsp
2023-06-21 10:35                       ` Jeff Layton
2023-06-21 10:42                         ` stsp
2023-06-21 11:05                           ` Jeff Layton
2023-06-21 11:22                             ` stsp
2023-06-21 11:26                               ` stsp
2023-06-23 15:25                             ` Christian Brauner
2023-06-23 17:18                               ` stsp
2023-06-27 16:00                                 ` Jeff Layton
2023-06-27 16:20                                   ` stsp
2023-06-20  9:55 ` [PATCH 3/3] selftests: add OFD lock tests Stas Sergeev
2023-06-20 11:06   ` Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eaccc14ddc6b546e5913eb557fec55f77cb5424d.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=brauner@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stsp2@yandex.ru \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).