mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: stsp <stsp2@yandex.ru>
To: Matthew Wilcox <willy@infradead.org>
Cc: Jeff Layton <jlayton@kernel.org>,
	linux-kernel@vger.kernel.org,
	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: Wed, 21 Jun 2023 07:54:13 +0500	[thread overview]
Message-ID: <a874f022-bdd9-8f87-e571-75626f5901ee@yandex.ru> (raw)
In-Reply-To: <ZJHcT9DPGWVlTsHg@casper.infradead.org>


20.06.2023 22:05, Matthew Wilcox пишет:
>> Does this mean, by any chance, that the
>> recipient actually owns an fd before
>> recvmsg() is done?
> no, it's not in their fd table.  they don't own it.
OK, thanks for showing this pathological
case. Let me just note that this changes
nothing at all. :)

The important thing to note here is that
any lock query is race-prone: locks can
come and go at any time. So if you need
some sequence of operations, you need
to employ some global locking for that.
I use flock(LOCK_EX) on the same fd, before
doing F_OFD_GETLK, and I do flock(LOCK_UN)
only when the entire sequence of operations
is completed. And I do the same on an
F_OFD_SETLK's side to guarantee the
atomicity. You can't do it otherwise,
it would be race-prone.

So given the above, the only thing we
need for l_pid consistency is for the
"donor" process to put LOCK_EX on an
fd before doing SCM_RIGHTS, and the
recipient should do LOCK_UN. Then
the other side, which also uses LOCK_EX,
will never see the owner-less state.
And as for the kernel's POV, l_pid should
be set to -1 only when there is no owner,
like in an example you mentioned.

  reply	other threads:[~2023-06-21  2:54 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
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 [this message]
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=a874f022-bdd9-8f87-e571-75626f5901ee@yandex.ru \
    --to=stsp2@yandex.ru \
    --cc=brauner@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /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

all inboxes | Powered by JetHome®