Skip to contentSkip to conversation

__d_find_alias() problem

DISCUSSION Sage Weil 2 participants 2 messages Dec 22, 2011 1 message not in the archive

lore
Share & tools
lore

Sage Weil

author
#1 lore raw
In reply to a message not in the archive
Quoted 1 line · Alex Elder

I'll send all this to ceph-devel later, I just wanted

[added cc]

Quoted 15 lines

to document it while it's fresh and send it to *someone* and you made this change so I'm sending it to you. The change in question is:

be655596b3de5873f994ddbe205751a5ffb4de39
ceph: use i_ceph_lock instead of i_lock

First, after updating my ceph tree and rebuilding I found that every time I completed a mount in my UML environment it would immediately crash the UML.

This led to me learning how to attach a debugger to the UML (good) and this morning I was able to capture this situation in gdb.

Quoted 7 lines

The problem is in ceph_dir_set_complete(), which is blindly dereferencing the return value of __d_find_any_alias(inode), and that function is returning NULL because the inode's i_dentry list is empty.

So that's problem 1.

Yeah, looks like I broke that with 9f6f8f50663e6cf42cca64f1f5ee0ca438c33c46. Just moving the dentry->d_sb inside the if should do it! Strange that this didn't trigger on sepia... :/

Quoted 23 lines

In looking at this I find that __d_find_any_alias() is duplicated in ceph, to (almost) match the Linux implementation which is not exported. But unlike the Linux version, the ceph version does NOT grab a reference to the found alias. I consider this a bug, because a function with an identical name should perform identically to the original, otherwise it should be named something different.

That's problem 2.
Furthermore, I looked at the locking that's done for the Linux version of __d_find_any_alias, and that truly does require taking the Linux inode lock--the (new) ceph inode i_ceph_lock is not sufficient. Note that __d_find_any_alias() really only operates on the Linux inode and does nothing with the ceph inode, so it may be that simply changing the locking used *in this case* back to using the Linux inode lock is enough to fix the problem. But I'm not familiar enough at this point to know the locking context where these calls are made, so can't be sure doing this would cause problems (like lock inversions).

Quoted 8 lines

There are three places this __d_find_any_alias() is called: ceph_dir_{set,clear,test}_complete(). Those are straightforward, but the calls to *those* functions are mostly embedded in long strings of logical conditions so it's going to take a little work to unwind this.

So that's problem 3, which is the biggest one.

I think the __d_find_any_alias() needs to take the i_lock and a reference to make it fully safe. i_lock is ordered inside i_ceph_lock, now, so that should be safe in all of the call chains. Better yet, we should just export the VFS version and use that.

What do you think? A simple fix is best so we can get it into 3.2 (which is about a week away?).

Quoted 3 lines

Potential problem 4 is that this suggests the mechanical switch to using i_ceph_lock is a little suspect and might need a closer look.

Yeah. Well, this is one of the few cases where i_lock where we muddle with the dcache internal structure. The others should pretty much all be in dir.c, and maybe inode.c's splice_dentry() and friends. The dcache readdir is by far the most suspect of all of those, but also probably the lowest priority at the moment. Maybe your visit in January would be a good time to go over it in detail?

sage

#2 lore raw
Quoted 25 lines · Sage Weil
Quoted 1 line · Alex Elder

I'll send all this to ceph-devel later, I just wanted

[added cc]

Quoted 21 lines

to document it while it's fresh and send it to *someone* and you made this change so I'm sending it to you. The change in question is:

be655596b3de5873f994ddbe205751a5ffb4de39
ceph: use i_ceph_lock instead of i_lock

First, after updating my ceph tree and rebuilding I found that every time I completed a mount in my UML environment it would immediately crash the UML.

This led to me learning how to attach a debugger to the UML (good) and this morning I was able to capture this situation in gdb.

The problem is in ceph_dir_set_complete(), which is blindly dereferencing the return value of __d_find_any_alias(inode), and that function is returning NULL because the inode's i_dentry list is empty.

Quoted 6 lines
Quoted 1 line

So that's problem 1.

Yeah, looks like I broke that with 9f6f8f50663e6cf42cca64f1f5ee0ca438c33c46. Just moving the dentry->d_sb inside the if should do it! Strange that this didn't trigger on sepia... :/

I have a patch that fixes this one and I have confirmed I can now get my UML filesystem mounted with it applied.

Quoted 30 lines
Quoted 30 lines

In looking at this I find that __d_find_any_alias() is duplicated in ceph, to (almost) match the Linux implementation which is not exported. But unlike the Linux version, the ceph version does NOT grab a reference to the found alias. I consider this a bug, because a function with an identical name should perform identically to the original, otherwise it should be named something different.

That's problem 2.
Furthermore, I looked at the locking that's done for the Linux version of __d_find_any_alias, and that truly does require taking the Linux inode lock--the (new) ceph inode i_ceph_lock is not sufficient. Note that __d_find_any_alias() really only operates on the Linux inode and does nothing with the ceph inode, so it may be that simply changing the locking used *in this case* back to using the Linux inode lock is enough to fix the problem. But I'm not familiar enough at this point to know the locking context where these calls are made, so can't be sure doing this would cause problems (like lock inversions).

There are three places this __d_find_any_alias() is called: ceph_dir_{set,clear,test}_complete(). Those are straightforward, but the calls to *those* functions are mostly embedded in long strings of logical conditions so it's going to take a little work to unwind this.

Quoted 6 lines
Quoted 1 line

So that's problem 3, which is the biggest one.

I think the __d_find_any_alias() needs to take the i_lock and a reference to make it fully safe. i_lock is ordered inside i_ceph_lock, now, so that should be safe in all of the call chains. Better yet, we should just export the VFS version and use that.

I'll put together a patch that both adds the reference, and fixes callers so they release it properly.

Quoted 2 lines

What do you think? A simple fix is best so we can get it into 3.2 (which is about a week away?).

What I described is simplest. I don't want to suggest a VFS change at this point.

Quoted 10 lines
Quoted 3 lines

Potential problem 4 is that this suggests the mechanical switch to using i_ceph_lock is a little suspect and might need a closer look.

Yeah. Well, this is one of the few cases where i_lock where we muddle with the dcache internal structure. The others should pretty much all be in dir.c, and maybe inode.c's splice_dentry() and friends. The dcache readdir is by far the most suspect of all of those, but also probably the lowest priority at the moment. Maybe your visit in January would be a good time to go over it in detail?

Sure. Or I could review the committed patch. For now I'll get something togehter for the 3.2 release.

-Alex