@@ -22,13 +22,16 @@ exclusive.
22223) object removal. Locking rules: caller locks parent, finds victim,
2323locks victim and calls the method. Locks are exclusive.
2424
25- 4) rename() that is _not_ cross-directory. Locking rules: caller locks the
26- parent and finds source and target. We lock both (provided they exist). If we
27- need to lock two inodes of different type (dir vs non-dir), we lock directory
28- first. If we need to lock two inodes of the same type, lock them in inode
29- pointer order. Then call the method. All locks are exclusive.
30- NB: we might get away with locking the source (and target in exchange
31- case) shared.
25+ 4) rename() that is _not_ cross-directory. Locking rules: caller locks
26+ the parent and finds source and target. Then we decide which of the
27+ source and target need to be locked. Source needs to be locked if it's a
28+ non-directory; target - if it's a non-directory or about to be removed.
29+ Take the locks that need to be taken, in inode pointer order if need
30+ to take both (that can happen only when both source and target are
31+ non-directories - the source because it wouldn't be locked otherwise
32+ and the target because mixing directory and non-directory is allowed
33+ only with RENAME_EXCHANGE, and that won't be removing the target).
34+ After the locks had been taken, call the method. All locks are exclusive.
3235
33365) link creation. Locking rules:
3437
@@ -44,20 +47,17 @@ rules:
4447
4548 * lock the filesystem
4649 * lock parents in "ancestors first" order. If one is not ancestor of
47- the other, lock them in inode pointer order .
50+ the other, lock the parent of source first .
4851 * find source and target.
4952 * if old parent is equal to or is a descendent of target
5053 fail with -ENOTEMPTY
5154 * if new parent is equal to or is a descendent of source
5255 fail with -ELOOP
53- * Lock both the source and the target provided they exist. If we
54- need to lock two inodes of different type (dir vs non-dir), we lock
55- the directory first. If we need to lock two inodes of the same type,
56- lock them in inode pointer order.
56+ * Lock subdirectories involved (source before target).
57+ * Lock non-directories involved, in inode pointer order.
5758 * call the method.
5859
59- All ->i_rwsem are taken exclusive. Again, we might get away with locking
60- the source (and target in exchange case) shared.
60+ All ->i_rwsem are taken exclusive.
6161
6262The rules above obviously guarantee that all directories that are going to be
6363read, modified or removed by method will be locked by caller.
@@ -67,6 +67,7 @@ If no directory is its own ancestor, the scheme above is deadlock-free.
6767
6868Proof:
6969
70+ [XXX: will be updated once we are done massaging the lock_rename()]
7071 First of all, at any moment we have a linear ordering of the
7172 objects - A < B iff (A is an ancestor of B) or (B is not an ancestor
7273 of A and ptr(A) < ptr(B)).
0 commit comments