Skip to content

Commit ec23eb5

Browse files
mchehabJonathan Corbet
authored andcommitted
docs: fs: convert docs without extension to ReST
There are 3 remaining files without an extension inside the fs docs dir. Manually convert them to ReST. In the case of the nfs/exporting.rst file, as the nfs docs aren't ported yet, I opted to convert and add a :orphan: there, with should be removed when it gets added into a nfs-specific part of the fs documentation. Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent 5a5e045 commit ec23eb5

11 files changed

Lines changed: 226 additions & 120 deletions

File tree

Documentation/filesystems/directory-locking renamed to Documentation/filesystems/directory-locking.rst

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
Locking scheme used for directory operations is based on two
1+
=================
2+
Directory Locking
3+
=================
4+
5+
6+
Locking scheme used for directory operations is based on two
27
kinds of locks - per-inode (->i_rwsem) and per-filesystem
38
(->s_vfs_rename_mutex).
49

5-
When taking the i_rwsem on multiple non-directory objects, we
10+
When taking the i_rwsem on multiple non-directory objects, we
611
always acquire the locks in order by increasing address. We'll call
712
that "inode pointer" order in the following.
813

9-
For our purposes all operations fall in 5 classes:
14+
For our purposes all operations fall in 5 classes:
1015

1116
1) read access. Locking rules: caller locks directory we are accessing.
1217
The lock is taken shared.
@@ -27,25 +32,29 @@ NB: we might get away with locking the the source (and target in exchange
2732
case) shared.
2833

2934
5) link creation. Locking rules:
35+
3036
* lock parent
3137
* check that source is not a directory
3238
* lock source
3339
* call the method.
40+
3441
All locks are exclusive.
3542

3643
6) cross-directory rename. The trickiest in the whole bunch. Locking
3744
rules:
45+
3846
* lock the filesystem
3947
* lock parents in "ancestors first" order.
4048
* find source and target.
4149
* if old parent is equal to or is a descendent of target
42-
fail with -ENOTEMPTY
50+
fail with -ENOTEMPTY
4351
* if new parent is equal to or is a descendent of source
44-
fail with -ELOOP
52+
fail with -ELOOP
4553
* If it's an exchange, lock both the source and the target.
4654
* If the target exists, lock it. If the source is a non-directory,
4755
lock it. If we need to lock both, do so in inode pointer order.
4856
* call the method.
57+
4958
All ->i_rwsem are taken exclusive. Again, we might get away with locking
5059
the the source (and target in exchange case) shared.
5160

@@ -54,10 +63,11 @@ read, modified or removed by method will be locked by caller.
5463

5564

5665
If no directory is its own ancestor, the scheme above is deadlock-free.
66+
5767
Proof:
5868

5969
First of all, at any moment we have a partial ordering of the
60-
objects - A < B iff A is an ancestor of B.
70+
objects - A < B iff A is an ancestor of B.
6171

6272
That ordering can change. However, the following is true:
6373

@@ -77,32 +87,32 @@ objects - A < B iff A is an ancestor of B.
7787
non-directory object, except renames, which take locks on source and
7888
target in inode pointer order in the case they are not directories.)
7989

80-
Now consider the minimal deadlock. Each process is blocked on
90+
Now consider the minimal deadlock. Each process is blocked on
8191
attempt to acquire some lock and already holds at least one lock. Let's
8292
consider the set of contended locks. First of all, filesystem lock is
8393
not contended, since any process blocked on it is not holding any locks.
8494
Thus all processes are blocked on ->i_rwsem.
8595

86-
By (3), any process holding a non-directory lock can only be
96+
By (3), any process holding a non-directory lock can only be
8797
waiting on another non-directory lock with a larger address. Therefore
8898
the process holding the "largest" such lock can always make progress, and
8999
non-directory objects are not included in the set of contended locks.
90100

91-
Thus link creation can't be a part of deadlock - it can't be
101+
Thus link creation can't be a part of deadlock - it can't be
92102
blocked on source and it means that it doesn't hold any locks.
93103

94-
Any contended object is either held by cross-directory rename or
104+
Any contended object is either held by cross-directory rename or
95105
has a child that is also contended. Indeed, suppose that it is held by
96106
operation other than cross-directory rename. Then the lock this operation
97107
is blocked on belongs to child of that object due to (1).
98108

99-
It means that one of the operations is cross-directory rename.
109+
It means that one of the operations is cross-directory rename.
100110
Otherwise the set of contended objects would be infinite - each of them
101111
would have a contended child and we had assumed that no object is its
102112
own descendent. Moreover, there is exactly one cross-directory rename
103113
(see above).
104114

105-
Consider the object blocking the cross-directory rename. One
115+
Consider the object blocking the cross-directory rename. One
106116
of its descendents is locked by cross-directory rename (otherwise we
107117
would again have an infinite set of contended objects). But that
108118
means that cross-directory rename is taking locks out of order. Due
@@ -112,7 +122,7 @@ try to acquire lock on descendent before the lock on ancestor.
112122
Contradiction. I.e. deadlock is impossible. Q.E.D.
113123

114124

115-
These operations are guaranteed to avoid loop creation. Indeed,
125+
These operations are guaranteed to avoid loop creation. Indeed,
116126
the only operation that could introduce loops is cross-directory rename.
117127
Since the only new (parent, child) pair added by rename() is (new parent,
118128
source), such loop would have to contain these objects and the rest of it
@@ -123,13 +133,13 @@ new parent had been equal to or a descendent of source since the moment when
123133
we had acquired filesystem lock and rename() would fail with -ELOOP in that
124134
case.
125135

126-
While this locking scheme works for arbitrary DAGs, it relies on
136+
While this locking scheme works for arbitrary DAGs, it relies on
127137
ability to check that directory is a descendent of another object. Current
128138
implementation assumes that directory graph is a tree. This assumption is
129139
also preserved by all operations (cross-directory rename on a tree that would
130140
not introduce a cycle will leave it a tree and link() fails for directories).
131141

132-
Notice that "directory" in the above == "anything that might have
142+
Notice that "directory" in the above == "anything that might have
133143
children", so if we are going to introduce hybrid objects we will need
134144
either to make sure that link(2) doesn't work for them or to make changes
135145
in is_subdir() that would make it work even in presence of such beasts.

‎Documentation/filesystems/index.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ algorithms work.
2020
path-lookup
2121
api-summary
2222
splice
23+
locking
24+
directory-locking
2325

2426
Filesystem support layers
2527
=========================

0 commit comments

Comments
 (0)