hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/Documentation/filesystems/directory-locking.rst
....@@ -22,12 +22,11 @@
2222 3) object removal. Locking rules: caller locks parent, finds victim,
2323 locks victim and calls the method. Locks are exclusive.
2424
25
-4) rename() that is _not_ cross-directory. Locking rules: caller locks
26
-the parent and finds source and target. In case of exchange (with
27
-RENAME_EXCHANGE in flags argument) lock both. In any case,
28
-if the target already exists, lock it. If the source is a non-directory,
29
-lock it. If we need to lock both, lock them in inode pointer order.
30
-Then call the method. All locks are exclusive.
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.
3130 NB: we might get away with locking the source (and target in exchange
3231 case) shared.
3332
....@@ -44,15 +43,17 @@
4443 rules:
4544
4645 * lock the filesystem
47
- * lock parents in "ancestors first" order.
46
+ * lock parents in "ancestors first" order. If one is not ancestor of
47
+ the other, lock them in inode pointer order.
4848 * find source and target.
4949 * if old parent is equal to or is a descendent of target
5050 fail with -ENOTEMPTY
5151 * if new parent is equal to or is a descendent of source
5252 fail with -ELOOP
53
- * If it's an exchange, lock both the source and the target.
54
- * If the target exists, lock it. If the source is a non-directory,
55
- lock it. If we need to lock both, do so in inode pointer order.
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.
5657 * call the method.
5758
5859 All ->i_rwsem are taken exclusive. Again, we might get away with locking
....@@ -66,8 +67,9 @@
6667
6768 Proof:
6869
69
- First of all, at any moment we have a partial ordering of the
70
- objects - A < B iff A is an ancestor of B.
70
+ First of all, at any moment we have a linear ordering of the
71
+ objects - A < B iff (A is an ancestor of B) or (B is not an ancestor
72
+ of A and ptr(A) < ptr(B)).
7173
7274 That ordering can change. However, the following is true:
7375