* [PATCH] fs:lock_rename()/unlock_rename() can lead to deadlock in distributed fs.
@ 2005-06-27 9:24 Zuzana Petrova
2005-06-27 9:39 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Zuzana Petrova @ 2005-06-27 9:24 UTC (permalink / raw)
To: linux-kernel; +Cc: Michael Gaughen
The problem with lock_rename() is that it compares parent directory dentries
when trying to decide how many inode i_sem semaphores to acquire. That works
fine on a single node system, but not in a distributed environment, on a
distributed filesystem.
The problem with rename(2) in a cluster, is that there is no guarantee that
path_lookup()s will return a coherent path structure while at the same time
renames, on another node, are executing on that same path hierarchy. In our
case, in do_rename(), the parent directory path_lookup()s find/create unique
dentries for the old_dir and new_dir, however, because a rename(2) on another
node was executing, both dentries end up pointing to the same inode.
When lock_rename(new_dir, old_dir) is called, the dentries don't match, so we
end up in a code path that tries to acquire the inode i_sem of both the
old_dir and new_dir, but since they point to the same inode, the second
attempt to acquire the same i_sem results in a deadlock.
A fix would be to compare the dentries ->d_inode field instead. Patch for
kernel 2.6.12.1 attached.
Author of the patch is Michael Gaughen <mgaughen@polyserve.com>
--
Zuzana Petrova
===================================================================
#
# This patch changes lock_rename()/unlock_rename() to compare the inodes
# referenced by the dentries. The problem with distributed filesystems is
# that there is no guarantee the path_lookup() will return valid path dentry
# components at the same time rename(2)s of that same path hierarchy are
# executing on another node. So there are cases where the dentries, passed
# to lock_rename()/unlock_rename(), are different, but refer to the same
# inode. In that case, the check for equivalent dentries will fail, and an
# attempt to acquire each of the dentries inode will be made, resulting in
# a deadlock since the inodes are the same.
#
--- linux-2.6.11.12.old/fs/namei.c 2005-03-11 13:56:30.877725438 +0100
+++ linux-2.6.11.12/fs/namei.c 2005-03-11 14:01:49.196080914 +0100
@@ -1197,7 +1197,7 @@ lock_rename(
{
struct dentry *p;
- if (p1 == p2) {
+ if (p1->d_inode == p2->d_inode) {
down(&p1->d_inode->i_sem);
return NULL;
}
@@ -1228,7 +1228,7 @@
void unlock_rename(struct dentry *p1, struct dentry *p2)
{
up(&p1->d_inode->i_sem);
- if (p1 != p2) {
+ if (p1->d_inode != p2->d_inode) {
up(&p2->d_inode->i_sem);
up(&p1->d_inode->i_sb->s_vfs_rename_sem);
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] fs:lock_rename()/unlock_rename() can lead to deadlock in distributed fs.
2005-06-27 9:24 [PATCH] fs:lock_rename()/unlock_rename() can lead to deadlock in distributed fs Zuzana Petrova
@ 2005-06-27 9:39 ` Christoph Hellwig
0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2005-06-27 9:39 UTC (permalink / raw)
To: Zuzana Petrova; +Cc: linux-kernel
On Mon, Jun 27, 2005 at 11:24:49AM +0200, Zuzana Petrova wrote:
> When lock_rename(new_dir, old_dir) is called, the dentries don't match, so we
> end up in a code path that tries to acquire the inode i_sem of both the
> old_dir and new_dir, but since they point to the same inode, the second
> attempt to acquire the same i_sem results in a deadlock.
>
> A fix would be to compare the dentries ->d_inode field instead. Patch for
> kernel 2.6.12.1 attached.
No, that's bogus. Make sure the filesystem never has multiple dentries
for the same directory inode.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fs:lock_rename()/unlock_rename() can lead to deadlock in distributed fs.
@ 2005-06-27 16:15 Nikita Danilov
0 siblings, 0 replies; 3+ messages in thread
From: Nikita Danilov @ 2005-06-27 16:15 UTC (permalink / raw)
To: Linux Kernel Mailing List
Zuzana Petrova writes:
> The problem with lock_rename() is that it compares parent directory dentries
> when trying to decide how many inode i_sem semaphores to acquire. That works
> fine on a single node system, but not in a distributed environment, on a
> distributed filesystem.
>
> The problem with rename(2) in a cluster, is that there is no guarantee that
> path_lookup()s will return a coherent path structure while at the same time
> renames, on another node, are executing on that same path hierarchy. In our
> case, in do_rename(), the parent directory path_lookup()s find/create unique
> dentries for the old_dir and new_dir, however, because a rename(2) on another
> node was executing, both dentries end up pointing to the same inode.
>
> When lock_rename(new_dir, old_dir) is called, the dentries don't match, so we
> end up in a code path that tries to acquire the inode i_sem of both the
> old_dir and new_dir, but since they point to the same inode, the second
> attempt to acquire the same i_sem results in a deadlock.
>
> A fix would be to compare the dentries ->d_inode field instead. Patch for
> kernel 2.6.12.1 attached.
reiser4 had identical patch before pseudo files were disabled. It even
went into -mm:
ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.9-rc1/2.6.9-rc1-mm1/broken-out/reiser4-aliased-dir.patch
Nikita.
>
> Author of the patch is Michael Gaughen <mgaughen@polyserve.com>
>
> --
> Zuzana Petrova
Nikita.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-06-27 16:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-27 9:24 [PATCH] fs:lock_rename()/unlock_rename() can lead to deadlock in distributed fs Zuzana Petrova
2005-06-27 9:39 ` Christoph Hellwig
2005-06-27 16:15 Nikita Danilov
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®