]>
Commit | Line | Data |
---|---|---|
68184a5a JR |
1 | From 38c4f55850b118899c10a2811cd436b2d051303a Mon Sep 17 00:00:00 2001 |
2 | From: Neil Brown <neilb@suse.de> | |
3 | Date: Thu, 30 Aug 2012 16:13:50 +0200 | |
4 | Subject: [PATCH 07/13] overlay: overlay filesystem documentation | |
5 | Patch-mainline: not yet | |
6 | ||
7 | Document the overlay filesystem. | |
8 | ||
9 | Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> | |
10 | --- | |
11 | Documentation/filesystems/overlayfs.txt | 199 ++++++++++++++++++++++++++++++++ | |
12 | MAINTAINERS | 7 + | |
13 | 2 files changed, 206 insertions(+) | |
68184a5a | 14 | |
c06a8ce3 AM |
15 | --- /dev/null |
16 | +++ b/Documentation/filesystems/overlayfs.txt | |
68184a5a JR |
17 | @@ -0,0 +1,199 @@ |
18 | +Written by: Neil Brown <neilb@suse.de> | |
19 | + | |
20 | +Overlay Filesystem | |
21 | +================== | |
22 | + | |
23 | +This document describes a prototype for a new approach to providing | |
24 | +overlay-filesystem functionality in Linux (sometimes referred to as | |
25 | +union-filesystems). An overlay-filesystem tries to present a | |
26 | +filesystem which is the result over overlaying one filesystem on top | |
27 | +of the other. | |
28 | + | |
29 | +The result will inevitably fail to look exactly like a normal | |
30 | +filesystem for various technical reasons. The expectation is that | |
31 | +many use cases will be able to ignore these differences. | |
32 | + | |
33 | +This approach is 'hybrid' because the objects that appear in the | |
34 | +filesystem do not all appear to belong to that filesystem. In many | |
35 | +cases an object accessed in the union will be indistinguishable | |
36 | +from accessing the corresponding object from the original filesystem. | |
37 | +This is most obvious from the 'st_dev' field returned by stat(2). | |
38 | + | |
39 | +While directories will report an st_dev from the overlay-filesystem, | |
40 | +all non-directory objects will report an st_dev from the lower or | |
41 | +upper filesystem that is providing the object. Similarly st_ino will | |
42 | +only be unique when combined with st_dev, and both of these can change | |
43 | +over the lifetime of a non-directory object. Many applications and | |
44 | +tools ignore these values and will not be affected. | |
45 | + | |
46 | +Upper and Lower | |
47 | +--------------- | |
48 | + | |
49 | +An overlay filesystem combines two filesystems - an 'upper' filesystem | |
50 | +and a 'lower' filesystem. When a name exists in both filesystems, the | |
51 | +object in the 'upper' filesystem is visible while the object in the | |
52 | +'lower' filesystem is either hidden or, in the case of directories, | |
53 | +merged with the 'upper' object. | |
54 | + | |
55 | +It would be more correct to refer to an upper and lower 'directory | |
56 | +tree' rather than 'filesystem' as it is quite possible for both | |
57 | +directory trees to be in the same filesystem and there is no | |
58 | +requirement that the root of a filesystem be given for either upper or | |
59 | +lower. | |
60 | + | |
61 | +The lower filesystem can be any filesystem supported by Linux and does | |
62 | +not need to be writable. The lower filesystem can even be another | |
63 | +overlayfs. The upper filesystem will normally be writable and if it | |
64 | +is it must support the creation of trusted.* extended attributes, and | |
65 | +must provide valid d_type in readdir responses, at least for symbolic | |
66 | +links - so NFS is not suitable. | |
67 | + | |
68 | +A read-only overlay of two read-only filesystems may use any | |
69 | +filesystem type. | |
70 | + | |
71 | +Directories | |
72 | +----------- | |
73 | + | |
74 | +Overlaying mainly involves directories. If a given name appears in both | |
75 | +upper and lower filesystems and refers to a non-directory in either, | |
76 | +then the lower object is hidden - the name refers only to the upper | |
77 | +object. | |
78 | + | |
79 | +Where both upper and lower objects are directories, a merged directory | |
80 | +is formed. | |
81 | + | |
82 | +At mount time, the two directories given as mount options are combined | |
83 | +into a merged directory: | |
84 | + | |
85 | + mount -t overlayfs overlayfs -olowerdir=/lower,upperdir=/upper /overlay | |
86 | + | |
87 | +Then whenever a lookup is requested in such a merged directory, the | |
88 | +lookup is performed in each actual directory and the combined result | |
89 | +is cached in the dentry belonging to the overlay filesystem. If both | |
90 | +actual lookups find directories, both are stored and a merged | |
91 | +directory is created, otherwise only one is stored: the upper if it | |
92 | +exists, else the lower. | |
93 | + | |
94 | +Only the lists of names from directories are merged. Other content | |
95 | +such as metadata and extended attributes are reported for the upper | |
96 | +directory only. These attributes of the lower directory are hidden. | |
97 | + | |
98 | +whiteouts and opaque directories | |
99 | +-------------------------------- | |
100 | + | |
101 | +In order to support rm and rmdir without changing the lower | |
102 | +filesystem, an overlay filesystem needs to record in the upper filesystem | |
103 | +that files have been removed. This is done using whiteouts and opaque | |
104 | +directories (non-directories are always opaque). | |
105 | + | |
106 | +The overlay filesystem uses extended attributes with a | |
107 | +"trusted.overlay." prefix to record these details. | |
108 | + | |
109 | +A whiteout is created as a symbolic link with target | |
110 | +"(overlay-whiteout)" and with xattr "trusted.overlay.whiteout" set to "y". | |
111 | +When a whiteout is found in the upper level of a merged directory, any | |
112 | +matching name in the lower level is ignored, and the whiteout itself | |
113 | +is also hidden. | |
114 | + | |
115 | +A directory is made opaque by setting the xattr "trusted.overlay.opaque" | |
116 | +to "y". Where the upper filesystem contains an opaque directory, any | |
117 | +directory in the lower filesystem with the same name is ignored. | |
118 | + | |
119 | +readdir | |
120 | +------- | |
121 | + | |
122 | +When a 'readdir' request is made on a merged directory, the upper and | |
123 | +lower directories are each read and the name lists merged in the | |
124 | +obvious way (upper is read first, then lower - entries that already | |
125 | +exist are not re-added). This merged name list is cached in the | |
126 | +'struct file' and so remains as long as the file is kept open. If the | |
127 | +directory is opened and read by two processes at the same time, they | |
128 | +will each have separate caches. A seekdir to the start of the | |
129 | +directory (offset 0) followed by a readdir will cause the cache to be | |
130 | +discarded and rebuilt. | |
131 | + | |
132 | +This means that changes to the merged directory do not appear while a | |
133 | +directory is being read. This is unlikely to be noticed by many | |
134 | +programs. | |
135 | + | |
136 | +seek offsets are assigned sequentially when the directories are read. | |
137 | +Thus if | |
138 | + - read part of a directory | |
139 | + - remember an offset, and close the directory | |
140 | + - re-open the directory some time later | |
141 | + - seek to the remembered offset | |
142 | + | |
143 | +there may be little correlation between the old and new locations in | |
144 | +the list of filenames, particularly if anything has changed in the | |
145 | +directory. | |
146 | + | |
147 | +Readdir on directories that are not merged is simply handled by the | |
148 | +underlying directory (upper or lower). | |
149 | + | |
150 | + | |
151 | +Non-directories | |
152 | +--------------- | |
153 | + | |
154 | +Objects that are not directories (files, symlinks, device-special | |
155 | +files etc.) are presented either from the upper or lower filesystem as | |
156 | +appropriate. When a file in the lower filesystem is accessed in a way | |
157 | +the requires write-access, such as opening for write access, changing | |
158 | +some metadata etc., the file is first copied from the lower filesystem | |
159 | +to the upper filesystem (copy_up). Note that creating a hard-link | |
160 | +also requires copy_up, though of course creation of a symlink does | |
161 | +not. | |
162 | + | |
163 | +The copy_up may turn out to be unnecessary, for example if the file is | |
164 | +opened for read-write but the data is not modified. | |
165 | + | |
166 | +The copy_up process first makes sure that the containing directory | |
167 | +exists in the upper filesystem - creating it and any parents as | |
168 | +necessary. It then creates the object with the same metadata (owner, | |
169 | +mode, mtime, symlink-target etc.) and then if the object is a file, the | |
170 | +data is copied from the lower to the upper filesystem. Finally any | |
171 | +extended attributes are copied up. | |
172 | + | |
173 | +Once the copy_up is complete, the overlay filesystem simply | |
174 | +provides direct access to the newly created file in the upper | |
175 | +filesystem - future operations on the file are barely noticed by the | |
176 | +overlay filesystem (though an operation on the name of the file such as | |
177 | +rename or unlink will of course be noticed and handled). | |
178 | + | |
179 | + | |
180 | +Non-standard behavior | |
181 | +--------------------- | |
182 | + | |
183 | +The copy_up operation essentially creates a new, identical file and | |
184 | +moves it over to the old name. The new file may be on a different | |
185 | +filesystem, so both st_dev and st_ino of the file may change. | |
186 | + | |
187 | +Any open files referring to this inode will access the old data and | |
188 | +metadata. Similarly any file locks obtained before copy_up will not | |
189 | +apply to the copied up file. | |
190 | + | |
191 | +On a file opened with O_RDONLY fchmod(2), fchown(2), futimesat(2) and | |
192 | +fsetxattr(2) will fail with EROFS. | |
193 | + | |
194 | +If a file with multiple hard links is copied up, then this will | |
195 | +"break" the link. Changes will not be propagated to other names | |
196 | +referring to the same inode. | |
197 | + | |
198 | +Symlinks in /proc/PID/ and /proc/PID/fd which point to a non-directory | |
199 | +object in overlayfs will not contain valid absolute paths, only | |
200 | +relative paths leading up to the filesystem's root. This will be | |
201 | +fixed in the future. | |
202 | + | |
203 | +Some operations are not atomic, for example a crash during copy_up or | |
204 | +rename will leave the filesystem in an inconsistent state. This will | |
205 | +be addressed in the future. | |
206 | + | |
207 | +Changes to underlying filesystems | |
208 | +--------------------------------- | |
209 | + | |
210 | +Offline changes, when the overlay is not mounted, are allowed to either | |
211 | +the upper or the lower trees. | |
212 | + | |
213 | +Changes to the underlying filesystems while part of a mounted overlay | |
214 | +filesystem are not allowed. If the underlying filesystem is changed, | |
215 | +the behavior of the overlay is undefined, though it will not result in | |
216 | +a crash or deadlock. | |
c06a8ce3 AM |
217 | --- a/MAINTAINERS |
218 | +++ b/MAINTAINERS | |
219 | @@ -6009,6 +6009,13 @@ F: drivers/scsi/osd/ | |
68184a5a JR |
220 | F: include/scsi/osd_* |
221 | F: fs/exofs/ | |
222 | ||
223 | +OVERLAYFS FILESYSTEM | |
224 | +M: Miklos Szeredi <miklos@szeredi.hu> | |
225 | +L: linux-fsdevel@vger.kernel.org | |
226 | +S: Supported | |
227 | +F: fs/overlayfs/* | |
228 | +F: Documentation/filesystems/overlayfs.txt | |
229 | + | |
230 | P54 WIRELESS DRIVER | |
231 | M: Christian Lamparter <chunkeey@googlemail.com> | |
232 | L: linux-wireless@vger.kernel.org |