From: Matthew Wilcox <matthew@wil.cx>
To: Anton Altaparmakov <aia21@cam.ac.uk>
Cc: Al Viro <viro@parcelfarce.linux.theplanet.co.uk>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: A missing i_mutex in rename? (Linux kernel 2.6.latest)
Date: Wed, 19 Apr 2006 06:18:26 -0600 [thread overview]
Message-ID: <20060419121826.GI24104@parisc-linux.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0604191102260.17373@hermes-1.csi.cam.ac.uk>
On Wed, Apr 19, 2006 at 11:50:00AM +0100, Anton Altaparmakov wrote:
> Both sys_unlink()/sys_rmdir() and sys_link() all end up taking the i_mutex
> on all parent directories and source/destination inodes before calling
> into the file system inode operations.
>
> sys_rename() OTOH, does not take i_mutex on the old inode. It only takes
> i_mutex on the two parent directories and on the target inode if it
> exists.
>
> Why is this? To me it seems that either sys_rename() must take i_mutex on
> the old inode or sys_unlink()/sys_rmdir(), sys_link(), etc do not need to
> hold the i_mutex.
>
> What am I missing?
I believe the current locking scheme to be correct. Reading
Documentation/filesystems/directory-locking and pondering for a few
minutes leads me to the following conclusions:
- sys_rmdir() must take the lock on the parent directory and on the
victim. If a different process is trying to create a file in the
victim, sys_rmdir() mustn't race with it.
- I don't immediately see a race that taking the lock on the victim of
sys_unlink() solves; however, for symmetry with sys_rmdir(), it seems
desirable.
- sys_link() needs to lock the target to be sure it isn't removed and
replaced with a directory in the meantime.
- sys_rename() does not need to lock the old inode. Since the parent
is already locked, the old inode can't be removed/renamed by a racing
process. It doesn't matter if something's created or deleted from
within the old inode (if it's a directory), unlike rmdir(). It
doesn't need to be protected from a sys_link() race.
If you need to lock the old inode inside ntfs for your own consistency
purposes, that looks like it should be fine, but the VFS doesn't need to
lock it for you.
next prev parent reply other threads:[~2006-04-19 12:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-19 10:50 A missing i_mutex in rename? (Linux kernel 2.6.latest) Anton Altaparmakov
2006-04-19 12:18 ` Matthew Wilcox [this message]
2006-04-19 12:51 ` Anton Altaparmakov
2006-04-20 10:59 ` Al Viro
2006-04-20 12:24 ` Anton Altaparmakov
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=20060419121826.GI24104@parisc-linux.org \
--to=matthew@wil.cx \
--cc=aia21@cam.ac.uk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@parcelfarce.linux.theplanet.co.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).