1 diff -urNp -x '*.orig' linux-4.4/Documentation/ABI/testing/debugfs-aufs linux-4.4/Documentation/ABI/testing/debugfs-aufs
2 --- linux-4.4/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-4.4/Documentation/ABI/testing/debugfs-aufs 2021-02-24 17:28:14.395474512 +0100
5 +What: /debug/aufs/si_<id>/
7 +Contact: J. R. Okajima <hooanon05g@gmail.com>
9 + Under /debug/aufs, a directory named si_<id> is created
10 + per aufs mount, where <id> is a unique id generated
13 +What: /debug/aufs/si_<id>/plink
15 +Contact: J. R. Okajima <hooanon05g@gmail.com>
17 + It has three lines and shows the information about the
18 + pseudo-link. The first line is a single number
19 + representing a number of buckets. The second line is a
20 + number of pseudo-links per buckets (separated by a
21 + blank). The last line is a single number representing a
22 + total number of psedo-links.
23 + When the aufs mount option 'noplink' is specified, it
24 + will show "1\n0\n0\n".
26 +What: /debug/aufs/si_<id>/xib
28 +Contact: J. R. Okajima <hooanon05g@gmail.com>
30 + It shows the consumed blocks by xib (External Inode Number
31 + Bitmap), its block size and file size.
32 + When the aufs mount option 'noxino' is specified, it
33 + will be empty. About XINO files, see the aufs manual.
35 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
37 +Contact: J. R. Okajima <hooanon05g@gmail.com>
39 + It shows the consumed blocks by xino (External Inode Number
40 + Translation Table), its link count, block size and file
42 + When the aufs mount option 'noxino' is specified, it
43 + will be empty. About XINO files, see the aufs manual.
45 +What: /debug/aufs/si_<id>/xigen
47 +Contact: J. R. Okajima <hooanon05g@gmail.com>
49 + It shows the consumed blocks by xigen (External Inode
50 + Generation Table), its block size and file size.
51 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
53 + When the aufs mount option 'noxino' is specified, it
54 + will be empty. About XINO files, see the aufs manual.
55 diff -urNp -x '*.orig' linux-4.4/Documentation/ABI/testing/sysfs-aufs linux-4.4/Documentation/ABI/testing/sysfs-aufs
56 --- linux-4.4/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
57 +++ linux-4.4/Documentation/ABI/testing/sysfs-aufs 2021-02-24 17:28:14.395474512 +0100
59 +What: /sys/fs/aufs/si_<id>/
61 +Contact: J. R. Okajima <hooanon05g@gmail.com>
63 + Under /sys/fs/aufs, a directory named si_<id> is created
64 + per aufs mount, where <id> is a unique id generated
67 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
69 +Contact: J. R. Okajima <hooanon05g@gmail.com>
71 + It shows the abolute path of a member directory (which
72 + is called branch) in aufs, and its permission.
74 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
76 +Contact: J. R. Okajima <hooanon05g@gmail.com>
78 + It shows the id of a member directory (which is called
81 +What: /sys/fs/aufs/si_<id>/xi_path
83 +Contact: J. R. Okajima <hooanon05g@gmail.com>
85 + It shows the abolute path of XINO (External Inode Number
86 + Bitmap, Translation Table and Generation Table) file
87 + even if it is the default path.
88 + When the aufs mount option 'noxino' is specified, it
89 + will be empty. About XINO files, see the aufs manual.
90 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/README linux-4.4/Documentation/filesystems/aufs/README
91 --- linux-4.4/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
92 +++ linux-4.4/Documentation/filesystems/aufs/README 2021-02-24 17:28:14.398807954 +0100
95 +Aufs4 -- advanced multi layered unification filesystem version 4.x
101 +----------------------------------------
102 +In the early days, aufs was entirely re-designed and re-implemented
103 +Unionfs Version 1.x series. Adding many original ideas, approaches,
104 +improvements and implementations, it becomes totally different from
105 +Unionfs while keeping the basic features.
106 +Recently, Unionfs Version 2.x series begin taking some of the same
107 +approaches to aufs1's.
108 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
109 +University and his team.
111 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
112 +If you want older kernel version support, try aufs2-2.6.git or
113 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
115 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
116 + According to Christoph Hellwig, linux rejects all union-type
117 + filesystems but UnionMount.
118 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
120 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
121 + UnionMount, and he pointed out an issue around a directory mutex
122 + lock and aufs addressed it. But it is still unsure whether aufs will
123 + be merged (or any other union solution).
124 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
128 +----------------------------------------
129 +- unite several directories into a single virtual filesystem. The member
130 + directory is called as a branch.
131 +- you can specify the permission flags to the branch, which are 'readonly',
132 + 'readwrite' and 'whiteout-able.'
133 +- by upper writable branch, internal copyup and whiteout, files/dirs on
134 + readonly branch are modifiable logically.
135 +- dynamic branch manipulation, add, del.
138 +Also there are many enhancements in aufs, such as:
139 +- test only the highest one for the directory permission (dirperm1)
140 +- copyup on open (coo=)
141 +- 'move' policy for copy-up between two writable branches, after
142 + checking free space.
144 +- readdir(3) in userspace.
145 +- keep inode number by external inode number table
146 +- keep the timestamps of file/dir in internal copyup operation
147 +- seekable directory, supporting NFS readdir.
148 +- whiteout is hardlinked in order to reduce the consumption of inodes
150 +- do not copyup, nor create a whiteout when it is unnecessary
151 +- revert a single systemcall when an error occurs in aufs
152 +- remount interface instead of ioctl
153 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
154 +- loopback mounted filesystem as a branch
155 +- kernel thread for removing the dir who has a plenty of whiteouts
156 +- support copyup sparse file (a file which has a 'hole' in it)
157 +- default permission flags for branches
158 +- selectable permission flags for ro branch, whether whiteout can
161 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
162 +- support multiple writable branches, some policies to select one
163 + among multiple writable branches.
164 +- a new semantics for link(2) and rename(2) to support multiple
166 +- no glibc changes are required.
167 +- pseudo hardlink (hardlink over branches)
168 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
169 + including NFS or remote filesystem branch.
170 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
173 +Currently these features are dropped temporary from aufs4.
174 +See design/08plan.txt in detail.
175 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
177 +- statistics of aufs thread (/sys/fs/aufs/stat)
179 +Features or just an idea in the future (see also design/*.txt),
180 +- reorder the branch index without del/re-add.
181 +- permanent xino files for NFSD
182 +- an option for refreshing the opened files after add/del branches
183 +- light version, without branch manipulation. (unnecessary?)
184 +- copyup in userspace
185 +- inotify in userspace
190 +----------------------------------------
191 +There are three GIT trees for aufs4, aufs4-linux.git,
192 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
194 +While the aufs-util is always necessary, you need either of aufs4-linux
195 +or aufs4-standalone.
197 +The aufs4-linux tree includes the whole linux mainline GIT tree,
198 +git://git.kernel.org/.../torvalds/linux.git.
199 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
200 +build aufs4 as an external kernel module.
201 +Several extra patches are not included in this tree. Only
202 +aufs4-standalone tree contains them. They are described in the later
203 +section "Configuration and Compilation."
205 +On the other hand, the aufs4-standalone tree has only aufs source files
206 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
207 +But you need to apply all aufs patches manually.
209 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
210 +represents the linux kernel version, "linux-4.x". For instance,
211 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
212 +"aufs4.x-rcN" branch.
215 +$ git clone --reference /your/linux/git/tree \
216 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
217 +- if you don't have linux GIT tree, then remove "--reference ..."
218 +$ cd aufs4-linux.git
219 +$ git checkout origin/aufs4.0
221 +Or You may want to directly git-pull aufs into your linux GIT tree, and
222 +leave the patch-work to GIT.
223 +$ cd /your/linux/git/tree
224 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
226 +$ git checkout -b my4.0 v4.0
227 +$ (add your local change...)
228 +$ git pull aufs4 aufs4.0
229 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
230 +- you may need to solve some conflicts between your_changes and
231 + aufs4.0. in this case, git-rerere is recommended so that you can
232 + solve the similar conflicts automatically when you upgrade to 4.1 or
233 + later in the future.
235 +o aufs4-standalone tree
236 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
237 +$ cd aufs4-standalone.git
238 +$ git checkout origin/aufs4.0
241 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
242 +- note that the public aufs-util.git is on SourceForge instead of
245 +$ git checkout origin/aufs4.0
247 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
248 +The minor version number, 'x' in '4.x', of aufs may not always
249 +follow the minor version number of the kernel.
250 +Because changes in the kernel that cause the use of a new
251 +minor version number do not always require changes to aufs-util.
253 +Since aufs-util has its own minor version number, you may not be
254 +able to find a GIT branch in aufs-util for your kernel's
255 +exact minor version number.
256 +In this case, you should git-checkout the branch for the
257 +nearest lower number.
259 +For (an unreleased) example:
260 +If you are using "linux-4.10" and the "aufs4.10" branch
261 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
262 +or something numerically smaller is the branch for your kernel.
264 +Also you can view all branches by
268 +3. Configuration and Compilation
269 +----------------------------------------
270 +Make sure you have git-checkout'ed the correct branch.
272 +For aufs4-linux tree,
273 +- enable CONFIG_AUFS_FS.
274 +- set other aufs configurations if necessary.
276 +For aufs4-standalone tree,
277 +There are several ways to build.
280 +- apply ./aufs4-kbuild.patch to your kernel source files.
281 +- apply ./aufs4-base.patch too.
282 +- apply ./aufs4-mmap.patch too.
283 +- apply ./aufs4-standalone.patch too, if you have a plan to set
284 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
285 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
286 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
287 +- enable CONFIG_AUFS_FS, you can select either
289 +- and build your kernel as usual.
290 +- install the built kernel.
291 + Note: Since linux-3.9, every filesystem module requires an alias
292 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
293 + modules.aliases file if you set CONFIG_AUFS_FS=m.
294 +- install the header files too by "make headers_install" to the
295 + directory where you specify. By default, it is $PWD/usr.
296 + "make help" shows a brief note for headers_install.
297 +- and reboot your system.
300 +- module only (CONFIG_AUFS_FS=m).
301 +- apply ./aufs4-base.patch to your kernel source files.
302 +- apply ./aufs4-mmap.patch too.
303 +- apply ./aufs4-standalone.patch too.
304 +- build your kernel, don't forget "make headers_install", and reboot.
305 +- edit ./config.mk and set other aufs configurations if necessary.
306 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
307 + every aufs configurations.
308 +- build the module by simple "make".
309 + Note: Since linux-3.9, every filesystem module requires an alias
310 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
311 + modules.aliases file.
312 +- you can specify ${KDIR} make variable which points to your kernel
315 + + run "make install" to install the aufs module, or copy the built
316 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
317 + + run "make install_headers" (instead of headers_install) to install
318 + the modified aufs header file (you can specify DESTDIR which is
319 + available in aufs standalone version's Makefile only), or copy
320 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
321 + you like manually. By default, the target directory is $PWD/usr.
322 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
323 + kernel source tree.
325 +Note: The header file aufs_type.h is necessary to build aufs-util
326 + as well as "make headers_install" in the kernel source tree.
327 + headers_install is subject to be forgotten, but it is essentially
328 + necessary, not only for building aufs-util.
329 + You may not meet problems without headers_install in some older
333 +- read README in aufs-util, build and install it
334 +- note that your distribution may contain an obsoleted version of
335 + aufs_type.h in /usr/include/linux or something. When you build aufs
336 + utilities, make sure that your compiler refers the correct aufs header
337 + file which is built by "make headers_install."
338 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
339 + then run "make install_ulib" too. And refer to the aufs manual in
342 +There several other patches in aufs4-standalone.git. They are all
343 +optional. When you meet some problems, they will help you.
344 +- aufs4-loopback.patch
345 + Supports a nested loopback mount in a branch-fs. This patch is
346 + unnecessary until aufs produces a message like "you may want to try
347 + another patch for loopback file".
349 + Modifies a system global kernel internal function get_next_ino() in
350 + order to stop assigning 0 for an inode-number. Not directly related to
351 + aufs, but recommended generally.
353 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
354 + the size of aufs XINO files for tmpfs branch. Also it prevents the
355 + duplication of inode number, which is important for backup tools and
356 + other utilities. When you find aufs XINO files for tmpfs branch
357 + growing too much, try this patch.
358 +- lockdep-debug.patch
359 + Because aufs is not only an ordinary filesystem (callee of VFS), but
360 + also a caller of VFS functions for branch filesystems, subclassing of
361 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
362 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
363 + need to apply this debug patch to expand several constant values.
364 + If don't know what LOCKDEP, then you don't have apply this patch.
368 +----------------------------------------
369 +At first, make sure aufs-util are installed, and please read the aufs
370 +manual, aufs.5 in aufs-util.git tree.
374 +$ mkdir /tmp/rw /tmp/aufs
375 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
377 +Here is another example. The result is equivalent.
378 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
380 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
381 +# mount -o remount,append:${HOME} /tmp/aufs
383 +Then, you can see whole tree of your home dir through /tmp/aufs. If
384 +you modify a file under /tmp/aufs, the one on your home directory is
385 +not affected, instead the same named file will be newly created under
386 +/tmp/rw. And all of your modification to a file will be applied to
387 +the one under /tmp/rw. This is called the file based Copy on Write
389 +Aufs mount options are described in aufs.5.
390 +If you run chroot or something and make your aufs as a root directory,
391 +then you need to customize the shutdown script. See the aufs manual in
394 +Additionally, there are some sample usages of aufs which are a
395 +diskless system with network booting, and LiveCD over NFS.
396 +See sample dir in CVS tree on SourceForge.
400 +----------------------------------------
401 +When you have any problems or strange behaviour in aufs, please let me
403 +- /proc/mounts (instead of the output of mount(8))
404 +- /sys/module/aufs/*
405 +- /sys/fs/aufs/* (if you have them)
406 +- /debug/aufs/* (if you have them)
407 +- linux kernel version
408 + if your kernel is not plain, for example modified by distributor,
409 + the url where i can download its source is necessary too.
410 +- aufs version which was printed at loading the module or booting the
411 + system, instead of the date you downloaded.
412 +- configuration (define/undefine CONFIG_AUFS_xxx)
413 +- kernel configuration or /proc/config.gz (if you have it)
414 +- behaviour which you think to be incorrect
415 +- actual operation, reproducible one is better
416 +- mailto: aufs-users at lists.sourceforge.net
418 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
419 +and Feature Requests) on SourceForge. Please join and write to
424 +----------------------------------------
425 +Thanks to everyone who have tried and are using aufs, whoever
426 +have reported a bug or any feedback.
428 +Especially donators:
429 +Tomas Matejicek(slax.org) made a donation (much more than once).
430 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
431 + scripts) is making "doubling" donations.
432 + Unfortunately I cannot list all of the donators, but I really
434 + It ends Aug 2010, but the ordinary donation URL is still available.
435 + <http://sourceforge.net/donate/index.php?group_id=167503>
436 +Dai Itasaka made a donation (2007/8).
437 +Chuck Smith made a donation (2008/4, 10 and 12).
438 +Henk Schoneveld made a donation (2008/9).
439 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
440 +Francois Dupoux made a donation (2008/11).
441 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
442 + aufs2 GIT tree (2009/2).
443 +William Grant made a donation (2009/3).
444 +Patrick Lane made a donation (2009/4).
445 +The Mail Archive (mail-archive.com) made donations (2009/5).
446 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
447 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
448 +Pavel Pronskiy made a donation (2011/2).
449 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
450 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
451 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
453 +Sam Liddicott made a donation (2011/9).
454 +Era Scarecrow made a donation (2013/4).
455 +Bor Ratajc made a donation (2013/4).
456 +Alessandro Gorreta made a donation (2013/4).
457 +POIRETTE Marc made a donation (2013/4).
458 +Alessandro Gorreta made a donation (2013/4).
459 +lauri kasvandik made a donation (2013/5).
460 +"pemasu from Finland" made a donation (2013/7).
461 +The Parted Magic Project made a donation (2013/9 and 11).
462 +Pavel Barta made a donation (2013/10).
463 +Nikolay Pertsev made a donation (2014/5).
464 +James B made a donation (2014/7 and 2015/7).
465 +Stefano Di Biase made a donation (2014/8).
466 +Daniel Epellei made a donation (2015/1).
467 +OmegaPhil made a donation (2016/1).
469 +Thank you very much.
470 +Donations are always, including future donations, very important and
471 +helpful for me to keep on developing aufs.
475 +----------------------------------------
476 +If you are an experienced user, no explanation is needed. Aufs is
477 +just a linux filesystem.
482 +# Local variables: ;
485 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/01intro.txt linux-4.4/Documentation/filesystems/aufs/design/01intro.txt
486 --- linux-4.4/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
487 +++ linux-4.4/Documentation/filesystems/aufs/design/01intro.txt 2021-02-24 17:28:14.395474512 +0100
490 +# Copyright (C) 2005-2016 Junjiro R. Okajima
492 +# This program is free software; you can redistribute it and/or modify
493 +# it under the terms of the GNU General Public License as published by
494 +# the Free Software Foundation; either version 2 of the License, or
495 +# (at your option) any later version.
497 +# This program is distributed in the hope that it will be useful,
498 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
499 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
500 +# GNU General Public License for more details.
502 +# You should have received a copy of the GNU General Public License
503 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
506 +----------------------------------------
508 +aufs [ei ju: ef es] | [a u f s]
509 +1. abbrev. for "advanced multi-layered unification filesystem".
510 +2. abbrev. for "another unionfs".
511 +3. abbrev. for "auf das" in German which means "on the" in English.
512 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
513 + But "Filesystem aufs Filesystem" is hard to understand.
515 +AUFS is a filesystem with features:
516 +- multi layered stackable unification filesystem, the member directory
517 + is called as a branch.
518 +- branch permission and attribute, 'readonly', 'real-readonly',
519 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
521 +- internal "file copy-on-write".
522 +- logical deletion, whiteout.
523 +- dynamic branch manipulation, adding, deleting and changing permission.
524 +- allow bypassing aufs, user's direct branch access.
525 +- external inode number translation table and bitmap which maintains the
526 + persistent aufs inode number.
527 +- seekable directory, including NFS readdir.
528 +- file mapping, mmap and sharing pages.
529 +- pseudo-link, hardlink over branches.
530 +- loopback mounted filesystem as a branch.
531 +- several policies to select one among multiple writable branches.
532 +- revert a single systemcall when an error occurs in aufs.
536 +Multi Layered Stackable Unification Filesystem
537 +----------------------------------------------------------------------
538 +Most people already knows what it is.
539 +It is a filesystem which unifies several directories and provides a
540 +merged single directory. When users access a file, the access will be
541 +passed/re-directed/converted (sorry, I am not sure which English word is
542 +correct) to the real file on the member filesystem. The member
543 +filesystem is called 'lower filesystem' or 'branch' and has a mode
544 +'readonly' and 'readwrite.' And the deletion for a file on the lower
545 +readonly branch is handled by creating 'whiteout' on the upper writable
548 +On LKML, there have been discussions about UnionMount (Jan Blunck,
549 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
550 +different approaches to implement the merged-view.
551 +The former tries putting it into VFS, and the latter implements as a
552 +separate filesystem.
553 +(If I misunderstand about these implementations, please let me know and
554 +I shall correct it. Because it is a long time ago when I read their
555 +source files last time).
557 +UnionMount's approach will be able to small, but may be hard to share
558 +branches between several UnionMount since the whiteout in it is
559 +implemented in the inode on branch filesystem and always
560 +shared. According to Bharata's post, readdir does not seems to be
562 +There are several missing features known in this implementations such as
563 +- for users, the inode number may change silently. eg. copy-up.
564 +- link(2) may break by copy-up.
565 +- read(2) may get an obsoleted filedata (fstat(2) too).
566 +- fcntl(F_SETLK) may be broken by copy-up.
567 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
570 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
571 +merged into mainline. This is another implementation of UnionMount as a
572 +separated filesystem. All the limitations and known problems which
573 +UnionMount are equally inherited to "overlay" filesystem.
575 +Unionfs has a longer history. When I started implementing a stackable
576 +filesystem (Aug 2005), it already existed. It has virtual super_block,
577 +inode, dentry and file objects and they have an array pointing lower
578 +same kind objects. After contributing many patches for Unionfs, I
579 +re-started my project AUFS (Jun 2006).
581 +In AUFS, the structure of filesystem resembles to Unionfs, but I
582 +implemented my own ideas, approaches and enhancements and it became
583 +totally different one.
585 +Comparing DM snapshot and fs based implementation
586 +- the number of bytes to be copied between devices is much smaller.
587 +- the type of filesystem must be one and only.
588 +- the fs must be writable, no readonly fs, even for the lower original
589 + device. so the compression fs will not be usable. but if we use
590 + loopback mount, we may address this issue.
592 + mount /cdrom/squashfs.img /sq
593 + losetup /sq/ext2.img
594 + losetup /somewhere/cow
595 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
596 +- it will be difficult (or needs more operations) to extract the
597 + difference between the original device and COW.
598 +- DM snapshot-merge may help a lot when users try merging. in the
599 + fs-layer union, users will use rsync(1).
601 +You may want to read my old paper "Filesystems in LiveCD"
602 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
605 +Several characters/aspects/persona of aufs
606 +----------------------------------------------------------------------
608 +Aufs has several characters, aspects or persona.
609 +1. a filesystem, callee of VFS helper
610 +2. sub-VFS, caller of VFS helper for branches
611 +3. a virtual filesystem which maintains persistent inode number
612 +4. reader/writer of files on branches such like an application
614 +1. Callee of VFS Helper
615 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
616 +unlink(2) from an application reaches sys_unlink() kernel function and
617 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
618 +calls filesystem specific unlink operation. Actually aufs implements the
619 +unlink operation but it behaves like a redirector.
621 +2. Caller of VFS Helper for Branches
622 +aufs_unlink() passes the unlink request to the branch filesystem as if
623 +it were called from VFS. So the called unlink operation of the branch
624 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
625 +every necessary pre/post operation for the branch filesystem.
626 +- acquire the lock for the parent dir on a branch
627 +- lookup in a branch
628 +- revalidate dentry on a branch
629 +- mnt_want_write() for a branch
630 +- vfs_unlink() for a branch
631 +- mnt_drop_write() for a branch
632 +- release the lock on a branch
634 +3. Persistent Inode Number
635 +One of the most important issue for a filesystem is to maintain inode
636 +numbers. This is particularly important to support exporting a
637 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
638 +backend block device for its own. But some storage is necessary to
639 +keep and maintain the inode numbers. It may be a large space and may not
640 +suit to keep in memory. Aufs rents some space from its first writable
641 +branch filesystem (by default) and creates file(s) on it. These files
642 +are created by aufs internally and removed soon (currently) keeping
644 +Note: Because these files are removed, they are totally gone after
645 + unmounting aufs. It means the inode numbers are not persistent
646 + across unmount or reboot. I have a plan to make them really
647 + persistent which will be important for aufs on NFS server.
649 +4. Read/Write Files Internally (copy-on-write)
650 +Because a branch can be readonly, when you write a file on it, aufs will
651 +"copy-up" it to the upper writable branch internally. And then write the
652 +originally requested thing to the file. Generally kernel doesn't
653 +open/read/write file actively. In aufs, even a single write may cause a
654 +internal "file copy". This behaviour is very similar to cp(1) command.
656 +Some people may think it is better to pass such work to user space
657 +helper, instead of doing in kernel space. Actually I am still thinking
658 +about it. But currently I have implemented it in kernel space.
659 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/02struct.txt linux-4.4/Documentation/filesystems/aufs/design/02struct.txt
660 --- linux-4.4/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
661 +++ linux-4.4/Documentation/filesystems/aufs/design/02struct.txt 2021-02-24 17:28:14.395474512 +0100
664 +# Copyright (C) 2005-2016 Junjiro R. Okajima
666 +# This program is free software; you can redistribute it and/or modify
667 +# it under the terms of the GNU General Public License as published by
668 +# the Free Software Foundation; either version 2 of the License, or
669 +# (at your option) any later version.
671 +# This program is distributed in the hope that it will be useful,
672 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
673 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
674 +# GNU General Public License for more details.
676 +# You should have received a copy of the GNU General Public License
677 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
679 +Basic Aufs Internal Structure
681 +Superblock/Inode/Dentry/File Objects
682 +----------------------------------------------------------------------
683 +As like an ordinary filesystem, aufs has its own
684 +superblock/inode/dentry/file objects. All these objects have a
685 +dynamically allocated array and store the same kind of pointers to the
686 +lower filesystem, branch.
687 +For example, when you build a union with one readwrite branch and one
688 +readonly, mounted /au, /rw and /ro respectively.
690 +- /ro/fileA exists but /rw/fileA
692 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
693 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
694 +- [0] = NULL (because /rw/fileA doesn't exist)
697 +This style of an array is essentially same to the aufs
698 +superblock/inode/dentry/file objects.
700 +Because aufs supports manipulating branches, ie. add/delete/change
701 +branches dynamically, these objects has its own generation. When
702 +branches are changed, the generation in aufs superblock is
703 +incremented. And a generation in other object are compared when it is
704 +accessed. When a generation in other objects are obsoleted, aufs
705 +refreshes the internal array.
709 +----------------------------------------------------------------------
710 +Additionally aufs superblock has some data for policies to select one
711 +among multiple writable branches, XIB files, pseudo-links and kobject.
712 +See below in detail.
713 +About the policies which supports copy-down a directory, see
717 +Branch and XINO(External Inode Number Translation Table)
718 +----------------------------------------------------------------------
719 +Every branch has its own xino (external inode number translation table)
720 +file. The xino file is created and unlinked by aufs internally. When two
721 +members of a union exist on the same filesystem, they share the single
723 +The struct of a xino file is simple, just a sequence of aufs inode
724 +numbers which is indexed by the lower inode number.
725 +In the above sample, assume the inode number of /ro/fileA is i111 and
726 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
727 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
729 +When the inode numbers are not contiguous, the xino file will be sparse
730 +which has a hole in it and doesn't consume as much disk space as it
731 +might appear. If your branch filesystem consumes disk space for such
732 +holes, then you should specify 'xino=' option at mounting aufs.
734 +Aufs has a mount option to free the disk blocks for such holes in XINO
735 +files on tmpfs or ramdisk. But it is not so effective actually. If you
736 +meet a problem of disk shortage due to XINO files, then you should try
737 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
738 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
739 +the holes in XINO files.
741 +Also a writable branch has three kinds of "whiteout bases". All these
742 +are existed when the branch is joined to aufs, and their names are
743 +whiteout-ed doubly, so that users will never see their names in aufs
745 +1. a regular file which will be hardlinked to all whiteouts.
746 +2. a directory to store a pseudo-link.
747 +3. a directory to store an "orphan"-ed file temporary.
750 + When you remove a file on a readonly branch, aufs handles it as a
751 + logical deletion and creates a whiteout on the upper writable branch
752 + as a hardlink of this file in order not to consume inode on the
755 + See below, Pseudo-link.
757 + When "fileC" exists on the lower readonly branch only and it is
758 + opened and removed with its parent dir, and then user writes
759 + something into it, then aufs copies-up fileC to this
760 + directory. Because there is no other dir to store fileC. After
761 + creating a file under this dir, the file is unlinked.
763 +Because aufs supports manipulating branches, ie. add/delete/change
764 +dynamically, a branch has its own id. When the branch order changes,
765 +aufs finds the new index by searching the branch id.
769 +----------------------------------------------------------------------
770 +Assume "fileA" exists on the lower readonly branch only and it is
771 +hardlinked to "fileB" on the branch. When you write something to fileA,
772 +aufs copies-up it to the upper writable branch. Additionally aufs
773 +creates a hardlink under the Pseudo-link Directory of the writable
774 +branch. The inode of a pseudo-link is kept in aufs super_block as a
775 +simple list. If fileB is read after unlinking fileA, aufs returns
776 +filedata from the pseudo-link instead of the lower readonly
777 +branch. Because the pseudo-link is based upon the inode, to keep the
778 +inode number by xino (see above) is essentially necessary.
780 +All the hardlinks under the Pseudo-link Directory of the writable branch
781 +should be restored in a proper location later. Aufs provides a utility
782 +to do this. The userspace helpers executed at remounting and unmounting
784 +During this utility is running, it puts aufs into the pseudo-link
785 +maintenance mode. In this mode, only the process which began the
786 +maintenance mode (and its child processes) is allowed to operate in
787 +aufs. Some other processes which are not related to the pseudo-link will
788 +be allowed to run too, but the rest have to return an error or wait
789 +until the maintenance mode ends. If a process already acquires an inode
790 +mutex (in VFS), it has to return an error.
793 +XIB(external inode number bitmap)
794 +----------------------------------------------------------------------
795 +Addition to the xino file per a branch, aufs has an external inode number
796 +bitmap in a superblock object. It is also an internal file such like a
798 +It is a simple bitmap to mark whether the aufs inode number is in-use or
800 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
802 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
803 +reduce the number of consumed disk blocks for these files.
806 +Virtual or Vertical Dir, and Readdir in Userspace
807 +----------------------------------------------------------------------
808 +In order to support multiple layers (branches), aufs readdir operation
809 +constructs a virtual dir block on memory. For readdir, aufs calls
810 +vfs_readdir() internally for each dir on branches, merges their entries
811 +with eliminating the whiteout-ed ones, and sets it to file (dir)
812 +object. So the file object has its entry list until it is closed. The
813 +entry list will be updated when the file position is zero and becomes
814 +obsoleted. This decision is made in aufs automatically.
816 +The dynamically allocated memory block for the name of entries has a
817 +unit of 512 bytes (by default) and stores the names contiguously (no
818 +padding). Another block for each entry is handled by kmem_cache too.
819 +During building dir blocks, aufs creates hash list and judging whether
820 +the entry is whiteouted by its upper branch or already listed.
821 +The merged result is cached in the corresponding inode object and
822 +maintained by a customizable life-time option.
824 +Some people may call it can be a security hole or invite DoS attack
825 +since the opened and once readdir-ed dir (file object) holds its entry
826 +list and becomes a pressure for system memory. But I'd say it is similar
827 +to files under /proc or /sys. The virtual files in them also holds a
828 +memory page (generally) while they are opened. When an idea to reduce
829 +memory for them is introduced, it will be applied to aufs too.
830 +For those who really hate this situation, I've developed readdir(3)
831 +library which operates this merging in userspace. You just need to set
832 +LD_PRELOAD environment variable, and aufs will not consume no memory in
833 +kernel space for readdir(3).
837 +----------------------------------------------------------------------
838 +Aufs sometimes requires privilege access to a branch. For instance,
839 +in copy-up/down operation. When a user process is going to make changes
840 +to a file which exists in the lower readonly branch only, and the mode
841 +of one of ancestor directories may not be writable by a user
842 +process. Here aufs copy-up the file with its ancestors and they may
843 +require privilege to set its owner/group/mode/etc.
844 +This is a typical case of a application character of aufs (see
847 +Aufs uses workqueue synchronously for this case. It creates its own
848 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
849 +passes the request to call mkdir or write (for example), and wait for
850 +its completion. This approach solves a problem of a signal handler
852 +If aufs didn't adopt the workqueue and changed the privilege of the
853 +process, then the process may receive the unexpected SIGXFSZ or other
856 +Also aufs uses the system global workqueue ("events" kernel thread) too
857 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
858 +whiteout base and etc. This is unrelated to a privilege.
859 +Most of aufs operation tries acquiring a rw_semaphore for aufs
860 +superblock at the beginning, at the same time waits for the completion
861 +of all queued asynchronous tasks.
865 +----------------------------------------------------------------------
866 +The whiteout in aufs is very similar to Unionfs's. That is represented
867 +by its filename. UnionMount takes an approach of a file mode, but I am
868 +afraid several utilities (find(1) or something) will have to support it.
870 +Basically the whiteout represents "logical deletion" which stops aufs to
871 +lookup further, but also it represents "dir is opaque" which also stop
874 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
875 +In order to make several functions in a single systemcall to be
876 +revertible, aufs adopts an approach to rename a directory to a temporary
877 +unique whiteouted name.
878 +For example, in rename(2) dir where the target dir already existed, aufs
879 +renames the target dir to a temporary unique whiteouted name before the
880 +actual rename on a branch, and then handles other actions (make it opaque,
881 +update the attributes, etc). If an error happens in these actions, aufs
882 +simply renames the whiteouted name back and returns an error. If all are
883 +succeeded, aufs registers a function to remove the whiteouted unique
884 +temporary name completely and asynchronously to the system global
889 +----------------------------------------------------------------------
890 +It is a well-known feature or concept.
891 +When user modifies a file on a readonly branch, aufs operate "copy-up"
892 +internally and makes change to the new file on the upper writable branch.
893 +When the trigger systemcall does not update the timestamps of the parent
894 +dir, aufs reverts it after copy-up.
897 +Move-down (aufs3.9 and later)
898 +----------------------------------------------------------------------
899 +"Copy-up" is one of the essential feature in aufs. It copies a file from
900 +the lower readonly branch to the upper writable branch when a user
901 +changes something about the file.
902 +"Move-down" is an opposite action of copy-up. Basically this action is
903 +ran manually instead of automatically and internally.
904 +For desgin and implementation, aufs has to consider these issues.
905 +- whiteout for the file may exist on the lower branch.
906 +- ancestor directories may not exist on the lower branch.
907 +- diropq for the ancestor directories may exist on the upper branch.
908 +- free space on the lower branch will reduce.
909 +- another access to the file may happen during moving-down, including
910 + UDBA (see "Revalidate Dentry and UDBA").
911 +- the file should not be hard-linked nor pseudo-linked. they should be
912 + handled by auplink utility later.
914 +Sometimes users want to move-down a file from the upper writable branch
915 +to the lower readonly or writable branch. For instance,
916 +- the free space of the upper writable branch is going to run out.
917 +- create a new intermediate branch between the upper and lower branch.
920 +For this purpose, use "aumvdown" command in aufs-util.git.
921 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/03atomic_open.txt linux-4.4/Documentation/filesystems/aufs/design/03atomic_open.txt
922 --- linux-4.4/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
923 +++ linux-4.4/Documentation/filesystems/aufs/design/03atomic_open.txt 2021-02-24 17:28:14.395474512 +0100
926 +# Copyright (C) 2015-2016 Junjiro R. Okajima
928 +# This program is free software; you can redistribute it and/or modify
929 +# it under the terms of the GNU General Public License as published by
930 +# the Free Software Foundation; either version 2 of the License, or
931 +# (at your option) any later version.
933 +# This program is distributed in the hope that it will be useful,
934 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
935 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
936 +# GNU General Public License for more details.
938 +# You should have received a copy of the GNU General Public License
939 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
941 +Support for a branch who has its ->atomic_open()
942 +----------------------------------------------------------------------
943 +The filesystems who implement its ->atomic_open() are not majority. For
944 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
945 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
946 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
947 +sure whether all filesystems who have ->atomic_open() behave like this,
948 +but NFSv4 surely returns the error.
950 +In order to support ->atomic_open() for aufs, there are a few
953 +A. Introduce aufs_atomic_open()
954 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
956 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
957 + an aufs user Pip Cet's approach
958 + - calls aufs_create(), VFS finish_open() and notify_change().
959 + - pass fake-mode to finish_open(), and then correct the mode by
961 +C. Extend aufs_open() to call branch fs's ->atomic_open()
962 + - no aufs_atomic_open().
963 + - aufs_lookup() registers the TID to an aufs internal object.
964 + - aufs_create() does nothing when the matching TID is registered, but
965 + registers the mode.
966 + - aufs_open() calls branch fs's ->atomic_open() when the matching
968 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
970 + - no aufs_atomic_open().
971 + - aufs_create() registers the TID to an internal object. this info
972 + represents "this process created this file just now."
973 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
974 + registered TID and re-try open() with superuser's credential.
976 +Pros and cons for each approach.
979 + - straightforward but highly depends upon VFS internal.
980 + - the atomic behavaiour is kept.
981 + - some of parameters such as nameidata are hard to reproduce for
985 + - easy to implement.
986 + - the atomic behavaiour is lost.
988 + - the atomic behavaiour is kept.
989 + - dirty and tricky.
990 + - VFS checks whether the file is created correctly after calling
991 + ->create(), which means this approach doesn't work.
993 + - easy to implement.
994 + - the atomic behavaiour is lost.
995 + - to open a file with superuser's credential and give it to a user
996 + process is a bad idea, since the file object keeps the credential
997 + in it. It may affect LSM or something. This approach doesn't work
1000 +The approach A is ideal, but it hard to implement. So here is a
1001 +variation of A, which is to be implemented.
1003 +A-1. Introduce aufs_atomic_open()
1004 + - calls branch fs ->atomic_open() if exists. otherwise calls
1005 + vfs_create() and finish_open().
1006 + - the demerit is that the several checks after branch fs
1007 + ->atomic_open() are lost. in the ordinary case, the checks are
1008 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1009 + be implemented in aufs, but not all I am afraid.
1010 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/03lookup.txt linux-4.4/Documentation/filesystems/aufs/design/03lookup.txt
1011 --- linux-4.4/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1012 +++ linux-4.4/Documentation/filesystems/aufs/design/03lookup.txt 2021-02-24 17:28:14.395474512 +0100
1015 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1017 +# This program is free software; you can redistribute it and/or modify
1018 +# it under the terms of the GNU General Public License as published by
1019 +# the Free Software Foundation; either version 2 of the License, or
1020 +# (at your option) any later version.
1022 +# This program is distributed in the hope that it will be useful,
1023 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1024 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1025 +# GNU General Public License for more details.
1027 +# You should have received a copy of the GNU General Public License
1028 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1031 +----------------------------------------------------------------------
1032 +Since aufs has a character of sub-VFS (see Introduction), it operates
1033 +lookup for branches as VFS does. It may be a heavy work. But almost all
1034 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1035 +directly connected to its parent. Digging down the directory hierarchy
1036 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1039 +When a branch is a remote filesystem, aufs basically relies upon its
1040 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1042 +For d_revalidate, aufs implements three levels of revalidate tests. See
1043 +"Revalidate Dentry and UDBA" in detail.
1046 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1047 +----------------------------------------------------------------------
1048 +Let's try case study.
1049 +- aufs has two branches, upper readwrite and lower readonly.
1051 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1052 +- user invoked "chmod a+rx /au/dirA"
1053 +- the internal copy-up is activated and "/rw/dirA" is created and its
1054 + permission bits are set to world readable.
1055 +- then "/au/dirA" becomes world readable?
1057 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1058 +or it may be a natively readonly filesystem. If aufs respects the lower
1059 +branch, it should not respond readdir request from other users. But user
1060 +allowed it by chmod. Should really aufs rejects showing the entries
1063 +To be honest, I don't have a good solution for this case. So aufs
1064 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1066 +When dirperm1 is specified, aufs checks only the highest one for the
1067 +directory permission, and shows the entries. Otherwise, as usual, checks
1068 +every dir existing on all branches and rejects the request.
1070 +As a side effect, dirperm1 option improves the performance of aufs
1071 +because the number of permission check is reduced when the number of
1075 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1076 +----------------------------------------------------------------------
1077 +Generally VFS helpers re-validate a dentry as a part of lookup.
1078 +0. digging down the directory hierarchy.
1079 +1. lock the parent dir by its i_mutex.
1080 +2. lookup the final (child) entry.
1082 +4. call the actual operation (create, unlink, etc.)
1083 +5. unlock the parent dir
1085 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1086 +called. Actually aufs implements it and checks the dentry on a branch is
1088 +But it is not enough. Because aufs has to release the lock for the
1089 +parent dir on a branch at the end of ->lookup() (step 2) and
1090 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1092 +If the file on a branch is changed directly, eg. bypassing aufs, after
1093 +aufs released the lock, then the subsequent operation may cause
1094 +something unpleasant result.
1096 +This situation is a result of VFS architecture, ->lookup() and
1097 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1098 +design from VFS's point of view. It is just not suitable for sub-VFS
1101 +Aufs supports such case by three level of revalidation which is
1102 +selectable by user.
1103 +1. Simple Revalidate
1104 + Addition to the native flow in VFS's, confirm the child-parent
1105 + relationship on the branch just after locking the parent dir on the
1106 + branch in the "actual operation" (step 4). When this validation
1107 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1108 + checks the validation of the dentry on branches.
1109 +2. Monitor Changes Internally by Inotify/Fsnotify
1110 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1111 + the dentry on the branch, and returns EBUSY if it finds different
1113 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1114 + during it is in cache. When the event is notified, aufs registers a
1115 + function to kernel 'events' thread by schedule_work(). And the
1116 + function sets some special status to the cached aufs dentry and inode
1117 + private data. If they are not cached, then aufs has nothing to
1118 + do. When the same file is accessed through aufs (step 0-3) later,
1119 + aufs will detect the status and refresh all necessary data.
1120 + In this mode, aufs has to ignore the event which is fired by aufs
1122 +3. No Extra Validation
1123 + This is the simplest test and doesn't add any additional revalidation
1124 + test, and skip the revalidation in step 4. It is useful and improves
1125 + aufs performance when system surely hide the aufs branches from user,
1126 + by over-mounting something (or another method).
1127 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/04branch.txt linux-4.4/Documentation/filesystems/aufs/design/04branch.txt
1128 --- linux-4.4/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1129 +++ linux-4.4/Documentation/filesystems/aufs/design/04branch.txt 2021-02-24 17:28:14.395474512 +0100
1132 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1134 +# This program is free software; you can redistribute it and/or modify
1135 +# it under the terms of the GNU General Public License as published by
1136 +# the Free Software Foundation; either version 2 of the License, or
1137 +# (at your option) any later version.
1139 +# This program is distributed in the hope that it will be useful,
1140 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1141 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1142 +# GNU General Public License for more details.
1144 +# You should have received a copy of the GNU General Public License
1145 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1147 +Branch Manipulation
1149 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1150 +and changing its permission/attribute, there are a lot of works to do.
1154 +----------------------------------------------------------------------
1155 +o Confirm the adding dir exists outside of aufs, including loopback
1156 + mount, and its various attributes.
1157 +o Initialize the xino file and whiteout bases if necessary.
1160 +o Check the owner/group/mode of the directory
1161 + When the owner/group/mode of the adding directory differs from the
1162 + existing branch, aufs issues a warning because it may impose a
1164 + For example, when a upper writable branch has a world writable empty
1165 + top directory, a malicious user can create any files on the writable
1166 + branch directly, like copy-up and modify manually. If something like
1167 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1168 + writable branch, and the writable branch is world-writable, then a
1169 + malicious guy may create /etc/passwd on the writable branch directly
1170 + and the infected file will be valid in aufs.
1171 + I am afraid it can be a security issue, but aufs can do nothing except
1172 + producing a warning.
1176 +----------------------------------------------------------------------
1177 +o Confirm the deleting branch is not busy
1178 + To be general, there is one merit to adopt "remount" interface to
1179 + manipulate branches. It is to discard caches. At deleting a branch,
1180 + aufs checks the still cached (and connected) dentries and inodes. If
1181 + there are any, then they are all in-use. An inode without its
1182 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1184 + For the cached one, aufs checks whether the same named entry exists on
1186 + If the cached one is a directory, because aufs provides a merged view
1187 + to users, as long as one dir is left on any branch aufs can show the
1188 + dir to users. In this case, the branch can be removed from aufs.
1189 + Otherwise aufs rejects deleting the branch.
1191 + If any file on the deleting branch is opened by aufs, then aufs
1195 +Modify the Permission of a Branch
1196 +----------------------------------------------------------------------
1197 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1200 +o rw --> ro: Confirm the modifying branch is not busy
1201 + Aufs rejects the request if any of these conditions are true.
1202 + - a file on the branch is mmap-ed.
1203 + - a regular file on the branch is opened for write and there is no
1204 + same named entry on the upper branch.
1205 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/05wbr_policy.txt linux-4.4/Documentation/filesystems/aufs/design/05wbr_policy.txt
1206 --- linux-4.4/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1207 +++ linux-4.4/Documentation/filesystems/aufs/design/05wbr_policy.txt 2021-02-24 17:28:14.395474512 +0100
1210 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1212 +# This program is free software; you can redistribute it and/or modify
1213 +# it under the terms of the GNU General Public License as published by
1214 +# the Free Software Foundation; either version 2 of the License, or
1215 +# (at your option) any later version.
1217 +# This program is distributed in the hope that it will be useful,
1218 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1219 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1220 +# GNU General Public License for more details.
1222 +# You should have received a copy of the GNU General Public License
1223 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1225 +Policies to Select One among Multiple Writable Branches
1226 +----------------------------------------------------------------------
1227 +When the number of writable branch is more than one, aufs has to decide
1228 +the target branch for file creation or copy-up. By default, the highest
1229 +writable branch which has the parent (or ancestor) dir of the target
1230 +file is chosen (top-down-parent policy).
1231 +By user's request, aufs implements some other policies to select the
1232 +writable branch, for file creation several policies, round-robin,
1233 +most-free-space, and other policies. For copy-up, top-down-parent,
1234 +bottom-up-parent, bottom-up and others.
1236 +As expected, the round-robin policy selects the branch in circular. When
1237 +you have two writable branches and creates 10 new files, 5 files will be
1238 +created for each branch. mkdir(2) systemcall is an exception. When you
1239 +create 10 new directories, all will be created on the same branch.
1240 +And the most-free-space policy selects the one which has most free
1241 +space among the writable branches. The amount of free space will be
1242 +checked by aufs internally, and users can specify its time interval.
1244 +The policies for copy-up is more simple,
1245 +top-down-parent is equivalent to the same named on in create policy,
1246 +bottom-up-parent selects the writable branch where the parent dir
1247 +exists and the nearest upper one from the copyup-source,
1248 +bottom-up selects the nearest upper writable branch from the
1249 +copyup-source, regardless the existence of the parent dir.
1251 +There are some rules or exceptions to apply these policies.
1252 +- If there is a readonly branch above the policy-selected branch and
1253 + the parent dir is marked as opaque (a variation of whiteout), or the
1254 + target (creating) file is whiteout-ed on the upper readonly branch,
1255 + then the result of the policy is ignored and the target file will be
1256 + created on the nearest upper writable branch than the readonly branch.
1257 +- If there is a writable branch above the policy-selected branch and
1258 + the parent dir is marked as opaque or the target file is whiteouted
1259 + on the branch, then the result of the policy is ignored and the target
1260 + file will be created on the highest one among the upper writable
1261 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1263 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1264 + They try selecting the branch where the source exists as possible
1265 + since copyup a large file will take long time. If it can't be,
1266 + ie. the branch where the source exists is readonly, then they will
1267 + follow the copyup policy.
1268 +- There is an exception for rename(2) when the target exists.
1269 + If the rename target exists, aufs compares the index of the branches
1270 + where the source and the target exists and selects the higher
1271 + one. If the selected branch is readonly, then aufs follows the
1273 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/06fhsm.txt linux-4.4/Documentation/filesystems/aufs/design/06fhsm.txt
1274 --- linux-4.4/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1275 +++ linux-4.4/Documentation/filesystems/aufs/design/06fhsm.txt 2021-02-24 17:28:14.395474512 +0100
1278 +# Copyright (C) 2011-2016 Junjiro R. Okajima
1280 +# This program is free software; you can redistribute it and/or modify
1281 +# it under the terms of the GNU General Public License as published by
1282 +# the Free Software Foundation; either version 2 of the License, or
1283 +# (at your option) any later version.
1285 +# This program is distributed in the hope that it will be useful,
1286 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1287 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1288 +# GNU General Public License for more details.
1290 +# You should have received a copy of the GNU General Public License
1291 +# along with this program; if not, write to the Free Software
1292 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1295 +File-based Hierarchical Storage Management (FHSM)
1296 +----------------------------------------------------------------------
1297 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1298 +storage world. Aufs provides this feature as file-based with multiple
1299 +writable branches, based upon the principle of "Colder, the Lower".
1300 +Here the word "colder" means that the less used files, and "lower" means
1301 +that the position in the order of the stacked branches vertically.
1302 +These multiple writable branches are prioritized, ie. the topmost one
1303 +should be the fastest drive and be used heavily.
1305 +o Characters in aufs FHSM story
1306 +- aufs itself and a new branch attribute.
1307 +- a new ioctl interface to move-down and to establish a connection with
1308 + the daemon ("move-down" is a converse of "copy-up").
1309 +- userspace tool and daemon.
1311 +The userspace daemon establishes a connection with aufs and waits for
1312 +the notification. The notified information is very similar to struct
1313 +statfs containing the number of consumed blocks and inodes.
1314 +When the consumed blocks/inodes of a branch exceeds the user-specified
1315 +upper watermark, the daemon activates its move-down process until the
1316 +consumed blocks/inodes reaches the user-specified lower watermark.
1318 +The actual move-down is done by aufs based upon the request from
1319 +user-space since we need to maintain the inode number and the internal
1320 +pointer arrays in aufs.
1322 +Currently aufs FHSM handles the regular files only. Additionally they
1323 +must not be hard-linked nor pseudo-linked.
1326 +o Cowork of aufs and the user-space daemon
1327 + During the userspace daemon established the connection, aufs sends a
1328 + small notification to it whenever aufs writes something into the
1329 + writable branch. But it may cost high since aufs issues statfs(2)
1330 + internally. So user can specify a new option to cache the
1331 + info. Actually the notification is controlled by these factors.
1332 + + the specified cache time.
1333 + + classified as "force" by aufs internally.
1334 + Until the specified time expires, aufs doesn't send the info
1335 + except the forced cases. When aufs decide forcing, the info is always
1336 + notified to userspace.
1337 + For example, the number of free inodes is generally large enough and
1338 + the shortage of it happens rarely. So aufs doesn't force the
1339 + notification when creating a new file, directory and others. This is
1340 + the typical case which aufs doesn't force.
1341 + When aufs writes the actual filedata and the files consumes any of new
1342 + blocks, the aufs forces notifying.
1345 +o Interfaces in aufs
1346 +- New branch attribute.
1348 + Specifies that the branch is managed by FHSM feature. In other word,
1349 + participant in the FHSM.
1350 + When nofhsm is set to the branch, it will not be the source/target
1351 + branch of the move-down operation. This attribute is set
1352 + independently from coo and moo attributes, and if you want full
1353 + FHSM, you should specify them as well.
1354 +- New mount option.
1356 + Specifies a second to suppress many less important info to be
1359 + + AUFS_CTL_FHSM_FD
1360 + create a new file descriptor which userspace can read the notification
1361 + (a subset of struct statfs) from aufs.
1362 +- Module parameter 'brs'
1363 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1365 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1366 + When there are two or more branches with fhsm attributes,
1367 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1368 + terminates it. As a result of remounting and branch-manipulation, the
1369 + number of branches with fhsm attribute can be one. In this case,
1370 + /sbin/mount.aufs will terminate the user-space daemon.
1373 +Finally the operation is done as these steps in kernel-space.
1375 + + no one else is using the file.
1376 + + the file is not hard-linked.
1377 + + the file is not pseudo-linked.
1378 + + the file is a regular file.
1379 + + the parent dir is not opaqued.
1380 +- find the target writable branch.
1381 +- make sure the file is not whiteout-ed by the upper (than the target)
1383 +- make the parent dir on the target branch.
1384 +- mutex lock the inode on the branch.
1385 +- unlink the whiteout on the target branch (if exists).
1386 +- lookup and create the whiteout-ed temporary name on the target branch.
1387 +- copy the file as the whiteout-ed temporary name on the target branch.
1388 +- rename the whiteout-ed temporary name to the original name.
1389 +- unlink the file on the source branch.
1390 +- maintain the internal pointer array and the external inode number
1392 +- maintain the timestamps and other attributes of the parent dir and the
1395 +And of course, in every step, an error may happen. So the operation
1396 +should restore the original file state after an error happens.
1397 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/06mmap.txt linux-4.4/Documentation/filesystems/aufs/design/06mmap.txt
1398 --- linux-4.4/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1399 +++ linux-4.4/Documentation/filesystems/aufs/design/06mmap.txt 2021-02-24 17:28:14.395474512 +0100
1402 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1404 +# This program is free software; you can redistribute it and/or modify
1405 +# it under the terms of the GNU General Public License as published by
1406 +# the Free Software Foundation; either version 2 of the License, or
1407 +# (at your option) any later version.
1409 +# This program is distributed in the hope that it will be useful,
1410 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1411 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1412 +# GNU General Public License for more details.
1414 +# You should have received a copy of the GNU General Public License
1415 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1417 +mmap(2) -- File Memory Mapping
1418 +----------------------------------------------------------------------
1419 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1420 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1422 +This approach is simple and good, but there is one problem.
1423 +Under /proc, several entries show the mmapped files by its path (with
1424 +device and inode number), and the printed path will be the path on the
1425 +branch fs's instead of virtual aufs's.
1426 +This is not a problem in most cases, but some utilities lsof(1) (and its
1427 +user) may expect the path on aufs.
1429 +To address this issue, aufs adds a new member called vm_prfile in struct
1430 +vm_area_struct (and struct vm_region). The original vm_file points to
1431 +the file on the branch fs in order to handle everything correctly as
1432 +usual. The new vm_prfile points to a virtual file in aufs, and the
1433 +show-functions in procfs refers to vm_prfile if it is set.
1434 +Also we need to maintain several other places where touching vm_file
1436 +- fork()/clone() copies vma and the reference count of vm_file is
1438 +- merging vma maintains the ref count too.
1440 +This is not a good approach. It just fakes the printed path. But it
1441 +leaves all behaviour around f_mapping unchanged. This is surely an
1443 +Actually aufs had adopted another complicated approach which calls
1444 +generic_file_mmap() and handles struct vm_operations_struct. In this
1445 +approach, aufs met a hard problem and I could not solve it without
1446 +switching the approach.
1448 +There may be one more another approach which is
1449 +- bind-mount the branch-root onto the aufs-root internally
1450 +- grab the new vfsmount (ie. struct mount)
1451 +- lazy-umount the branch-root internally
1452 +- in open(2) the aufs-file, open the branch-file with the hidden
1453 + vfsmount (instead of the original branch's vfsmount)
1454 +- ideally this "bind-mount and lazy-umount" should be done atomically,
1455 + but it may be possible from userspace by the mount helper.
1457 +Adding the internal hidden vfsmount and using it in opening a file, the
1458 +file path under /proc will be printed correctly. This approach looks
1459 +smarter, but is not possible I am afraid.
1460 +- aufs-root may be bind-mount later. when it happens, another hidden
1461 + vfsmount will be required.
1462 +- it is hard to get the chance to bind-mount and lazy-umount
1463 + + in kernel-space, FS can have vfsmount in open(2) via
1464 + file->f_path, and aufs can know its vfsmount. But several locks are
1465 + already acquired, and if aufs tries to bind-mount and lazy-umount
1466 + here, then it may cause a deadlock.
1467 + + in user-space, bind-mount doesn't invoke the mount helper.
1468 +- since /proc shows dev and ino, aufs has to give vma these info. it
1469 + means a new member vm_prinode will be necessary. this is essentially
1470 + equivalent to vm_prfile described above.
1472 +I have to give up this "looks-smater" approach.
1473 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/06xattr.txt linux-4.4/Documentation/filesystems/aufs/design/06xattr.txt
1474 --- linux-4.4/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
1475 +++ linux-4.4/Documentation/filesystems/aufs/design/06xattr.txt 2021-02-24 17:28:14.395474512 +0100
1478 +# Copyright (C) 2014-2016 Junjiro R. Okajima
1480 +# This program is free software; you can redistribute it and/or modify
1481 +# it under the terms of the GNU General Public License as published by
1482 +# the Free Software Foundation; either version 2 of the License, or
1483 +# (at your option) any later version.
1485 +# This program is distributed in the hope that it will be useful,
1486 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1487 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1488 +# GNU General Public License for more details.
1490 +# You should have received a copy of the GNU General Public License
1491 +# along with this program; if not, write to the Free Software
1492 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1495 +Listing XATTR/EA and getting the value
1496 +----------------------------------------------------------------------
1497 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
1498 +shows the values from the topmost existing file. This behaviour is good
1499 +for the non-dir entries since the bahaviour exactly matches the shown
1500 +information. But for the directories, aufs considers all the same named
1501 +entries on the lower branches. Which means, if one of the lower entry
1502 +rejects readdir call, then aufs returns an error even if the topmost
1503 +entry allows it. This behaviour is necessary to respect the branch fs's
1504 +security, but can make users confused since the user-visible standard
1505 +attributes don't match the behaviour.
1506 +To address this issue, aufs has a mount option called dirperm1 which
1507 +checks the permission for the topmost entry only, and ignores the lower
1508 +entry's permission.
1510 +A similar issue can happen around XATTR.
1511 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
1512 +always set. Otherwise these very unpleasant situation would happen.
1513 +- listxattr(2) may return the duplicated entries.
1514 +- users may not be able to remove or reset the XATTR forever,
1517 +XATTR/EA support in the internal (copy,move)-(up,down)
1518 +----------------------------------------------------------------------
1519 +Generally the extended attributes of inode are categorized as these.
1520 +- "security" for LSM and capability.
1521 +- "system" for posix ACL, 'acl' mount option is required for the branch
1523 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
1524 +- "user" for userspace, 'user_xattr' mount option is required for the
1525 + branch fs generally.
1527 +Moreover there are some other categories. Aufs handles these rather
1528 +unpopular categories as the ordinary ones, ie. there is no special
1529 +condition nor exception.
1531 +In copy-up, the support for XATTR on the dst branch may differ from the
1532 +src branch. In this case, the copy-up operation will get an error and
1533 +the original user operation which triggered the copy-up will fail. It
1534 +can happen that even all copy-up will fail.
1535 +When both of src and dst branches support XATTR and if an error occurs
1536 +during copying XATTR, then the copy-up should fail obviously. That is a
1537 +good reason and aufs should return an error to userspace. But when only
1538 +the src branch support that XATTR, aufs should not return an error.
1539 +For example, the src branch supports ACL but the dst branch doesn't
1540 +because the dst branch may natively un-support it or temporary
1541 +un-support it due to "noacl" mount option. Of course, the dst branch fs
1542 +may NOT return an error even if the XATTR is not supported. It is
1543 +totally up to the branch fs.
1545 +Anyway when the aufs internal copy-up gets an error from the dst branch
1546 +fs, then aufs tries removing the just copied entry and returns the error
1547 +to the userspace. The worst case of this situation will be all copy-up
1550 +For the copy-up operation, there two basic approaches.
1551 +- copy the specified XATTR only (by category above), and return the
1552 + error unconditionally if it happens.
1553 +- copy all XATTR, and ignore the error on the specified category only.
1555 +In order to support XATTR and to implement the correct behaviour, aufs
1556 +chooses the latter approach and introduces some new branch attributes,
1557 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
1558 +They correspond to the XATTR namespaces (see above). Additionally, to be
1559 +convenient, "icex" is also provided which means all "icex*" attributes
1560 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
1562 +The meaning of these attributes is to ignore the error from setting
1563 +XATTR on that branch.
1564 +Note that aufs tries copying all XATTR unconditionally, and ignores the
1565 +error from the dst branch according to the specified attributes.
1567 +Some XATTR may have its default value. The default value may come from
1568 +the parent dir or the environment. If the default value is set at the
1569 +file creating-time, it will be overwritten by copy-up.
1570 +Some contradiction may happen I am afraid.
1571 +Do we need another attribute to stop copying XATTR? I am unsure. For
1572 +now, aufs implements the branch attributes to ignore the error.
1573 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/07export.txt linux-4.4/Documentation/filesystems/aufs/design/07export.txt
1574 --- linux-4.4/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1575 +++ linux-4.4/Documentation/filesystems/aufs/design/07export.txt 2021-02-24 17:28:14.398807954 +0100
1578 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1580 +# This program is free software; you can redistribute it and/or modify
1581 +# it under the terms of the GNU General Public License as published by
1582 +# the Free Software Foundation; either version 2 of the License, or
1583 +# (at your option) any later version.
1585 +# This program is distributed in the hope that it will be useful,
1586 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1587 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1588 +# GNU General Public License for more details.
1590 +# You should have received a copy of the GNU General Public License
1591 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1593 +Export Aufs via NFS
1594 +----------------------------------------------------------------------
1595 +Here is an approach.
1596 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1598 +- iget_locked(): initialize aufs inode generation for a new inode, and
1599 + store it in xigen file.
1600 +- destroy_inode(): increment aufs inode generation and store it in xigen
1601 + file. it is necessary even if it is not unlinked, because any data of
1602 + inode may be changed by UDBA.
1603 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1604 + build file handle by
1605 + + branch id (4 bytes)
1606 + + superblock generation (4 bytes)
1607 + + inode number (4 or 8 bytes)
1608 + + parent dir inode number (4 or 8 bytes)
1609 + + inode generation (4 bytes))
1610 + + return value of exportfs_encode_fh() for the parent on a branch (4
1612 + + file handle for a branch (by exportfs_encode_fh())
1614 + + find the index of a branch from its id in handle, and check it is
1615 + still exist in aufs.
1616 + + 1st level: get the inode number from handle and search it in cache.
1617 + + 2nd level: if not found in cache, get the parent inode number from
1618 + the handle and search it in cache. and then open the found parent
1619 + dir, find the matching inode number by vfs_readdir() and get its
1620 + name, and call lookup_one_len() for the target dentry.
1621 + + 3rd level: if the parent dir is not cached, call
1622 + exportfs_decode_fh() for a branch and get the parent on a branch,
1623 + build a pathname of it, convert it a pathname in aufs, call
1624 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1626 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1627 + for every branch, but not itself. to get this, (currently) aufs
1628 + searches in current->nsproxy->mnt_ns list. it may not be a good
1629 + idea, but I didn't get other approach.
1630 + + test the generation of the gotten inode.
1631 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1632 + convert it into ESTALE for NFSD.
1633 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1634 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1635 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/08shwh.txt linux-4.4/Documentation/filesystems/aufs/design/08shwh.txt
1636 --- linux-4.4/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1637 +++ linux-4.4/Documentation/filesystems/aufs/design/08shwh.txt 2021-02-24 17:28:14.398807954 +0100
1640 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1642 +# This program is free software; you can redistribute it and/or modify
1643 +# it under the terms of the GNU General Public License as published by
1644 +# the Free Software Foundation; either version 2 of the License, or
1645 +# (at your option) any later version.
1647 +# This program is distributed in the hope that it will be useful,
1648 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1649 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1650 +# GNU General Public License for more details.
1652 +# You should have received a copy of the GNU General Public License
1653 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1655 +Show Whiteout Mode (shwh)
1656 +----------------------------------------------------------------------
1657 +Generally aufs hides the name of whiteouts. But in some cases, to show
1658 +them is very useful for users. For instance, creating a new middle layer
1659 +(branch) by merging existing layers.
1661 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1662 +When you have three branches,
1663 +- Bottom: 'system', squashfs (underlying base system), read-only
1664 +- Middle: 'mods', squashfs, read-only
1665 +- Top: 'overlay', ram (tmpfs), read-write
1667 +The top layer is loaded at boot time and saved at shutdown, to preserve
1668 +the changes made to the system during the session.
1669 +When larger changes have been made, or smaller changes have accumulated,
1670 +the size of the saved top layer data grows. At this point, it would be
1671 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1672 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1673 +restoring save and load speed.
1675 +This merging is simplified by the use of another aufs mount, of just the
1676 +two overlay branches using the 'shwh' option.
1677 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1678 + aufs /livesys/merge_union
1680 +A merged view of these two branches is then available at
1681 +/livesys/merge_union, and the new feature is that the whiteouts are
1683 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1684 +writing to all branches. Also the default mode for all branches is 'ro'.
1685 +It is now possible to save the combined contents of the two overlay
1686 +branches to a new squashfs, e.g.:
1687 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1689 +This new squashfs archive can be stored on the boot device and the
1690 +initramfs will use it to replace the old one at the next boot.
1691 diff -urNp -x '*.orig' linux-4.4/Documentation/filesystems/aufs/design/10dynop.txt linux-4.4/Documentation/filesystems/aufs/design/10dynop.txt
1692 --- linux-4.4/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1693 +++ linux-4.4/Documentation/filesystems/aufs/design/10dynop.txt 2021-02-24 17:28:14.398807954 +0100
1696 +# Copyright (C) 2010-2016 Junjiro R. Okajima
1698 +# This program is free software; you can redistribute it and/or modify
1699 +# it under the terms of the GNU General Public License as published by
1700 +# the Free Software Foundation; either version 2 of the License, or
1701 +# (at your option) any later version.
1703 +# This program is distributed in the hope that it will be useful,
1704 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1705 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1706 +# GNU General Public License for more details.
1708 +# You should have received a copy of the GNU General Public License
1709 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1711 +Dynamically customizable FS operations
1712 +----------------------------------------------------------------------
1713 +Generally FS operations (struct inode_operations, struct
1714 +address_space_operations, struct file_operations, etc.) are defined as
1715 +"static const", but it never means that FS have only one set of
1716 +operation. Some FS have multiple sets of them. For instance, ext2 has
1717 +three sets, one for XIP, for NOBH, and for normal.
1718 +Since aufs overrides and redirects these operations, sometimes aufs has
1719 +to change its behaviour according to the branch FS type. More importantly
1720 +VFS acts differently if a function (member in the struct) is set or
1721 +not. It means aufs should have several sets of operations and select one
1722 +among them according to the branch FS definition.
1724 +In order to solve this problem and not to affect the behaviour of VFS,
1725 +aufs defines these operations dynamically. For instance, aufs defines
1726 +dummy direct_IO function for struct address_space_operations, but it may
1727 +not be set to the address_space_operations actually. When the branch FS
1728 +doesn't have it, aufs doesn't set it to its address_space_operations
1729 +while the function definition itself is still alive. So the behaviour
1730 +itself will not change, and it will return an error when direct_IO is
1733 +The lifetime of these dynamically generated operation object is
1734 +maintained by aufs branch object. When the branch is removed from aufs,
1735 +the reference counter of the object is decremented. When it reaches
1736 +zero, the dynamically generated operation object will be freed.
1738 +This approach is designed to support AIO (io_submit), Direct I/O and
1740 +Currently this approach is applied to address_space_operations for
1741 +regular files only.
1742 diff -urNp -x '*.orig' linux-4.4/MAINTAINERS linux-4.4/MAINTAINERS
1743 --- linux-4.4/MAINTAINERS 2021-02-24 17:28:00.965039120 +0100
1744 +++ linux-4.4/MAINTAINERS 2021-02-24 17:28:14.382140747 +0100
1745 @@ -2029,6 +2029,19 @@ F: include/linux/audit.h
1746 F: include/uapi/linux/audit.h
1749 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
1750 +M: "J. R. Okajima" <hooanon05g@gmail.com>
1751 +L: linux-unionfs@vger.kernel.org
1752 +L: aufs-users@lists.sourceforge.net (members only)
1753 +W: http://aufs.sourceforge.net
1754 +T: git://github.com/sfjro/aufs4-linux.git
1756 +F: Documentation/filesystems/aufs/
1757 +F: Documentation/ABI/testing/debugfs-aufs
1758 +F: Documentation/ABI/testing/sysfs-aufs
1760 +F: include/uapi/linux/aufs_type.h
1762 AUXILIARY DISPLAY DRIVERS
1763 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
1764 W: http://miguelojeda.es/auxdisplay.htm
1765 diff -urNp -x '*.orig' linux-4.4/drivers/block/loop.c linux-4.4/drivers/block/loop.c
1766 --- linux-4.4/drivers/block/loop.c 2021-02-24 17:28:03.251779927 +0100
1767 +++ linux-4.4/drivers/block/loop.c 2021-02-24 17:28:14.418808602 +0100
1768 @@ -563,7 +563,7 @@ static int do_req_filebacked(struct loop
1771 struct switch_request {
1772 - struct file *file;
1773 + struct file *file, *virt_file;
1774 struct completion wait;
1777 @@ -589,6 +589,7 @@ static void do_loop_switch(struct loop_d
1778 mapping = file->f_mapping;
1779 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
1780 lo->lo_backing_file = file;
1781 + lo->lo_backing_virt_file = p->virt_file;
1782 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
1783 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
1784 lo->old_gfp_mask = mapping_gfp_mask(mapping);
1785 @@ -601,11 +602,13 @@ static void do_loop_switch(struct loop_d
1786 * First it needs to flush existing IO, it does this by sending a magic
1787 * BIO down the pipe. The completion of this BIO does the actual switch.
1789 -static int loop_switch(struct loop_device *lo, struct file *file)
1790 +static int loop_switch(struct loop_device *lo, struct file *file,
1791 + struct file *virt_file)
1793 struct switch_request w;
1796 + w.virt_file = virt_file;
1798 /* freeze queue and wait for completion of scheduled requests */
1799 blk_mq_freeze_queue(lo->lo_queue);
1800 @@ -627,7 +630,16 @@ static int loop_flush(struct loop_device
1801 /* loop not yet configured, no running thread, nothing to flush */
1802 if (lo->lo_state != Lo_bound)
1804 - return loop_switch(lo, NULL);
1805 + return loop_switch(lo, NULL, NULL);
1808 +static struct file *loop_real_file(struct file *file)
1810 + struct file *f = NULL;
1812 + if (file->f_path.dentry->d_sb->s_op->real_loop)
1813 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
1817 static void loop_reread_partitions(struct loop_device *lo,
1818 @@ -694,6 +706,7 @@ static int loop_change_fd(struct loop_de
1821 struct file *file, *old_file;
1822 + struct file *f, *virt_file = NULL, *old_virt_file;
1823 struct inode *inode;
1826 @@ -710,6 +723,12 @@ static int loop_change_fd(struct loop_de
1830 + f = loop_real_file(file);
1837 error = loop_validate_file(file, bdev);
1839 @@ -717,6 +736,7 @@ static int loop_change_fd(struct loop_de
1841 inode = file->f_mapping->host;
1842 old_file = lo->lo_backing_file;
1843 + old_virt_file = lo->lo_backing_virt_file;
1847 @@ -725,21 +745,43 @@ static int loop_change_fd(struct loop_de
1850 /* and ... switch */
1851 - error = loop_switch(lo, file);
1852 + error = loop_switch(lo, file, virt_file);
1857 + if (old_virt_file)
1858 + fput(old_virt_file);
1859 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
1860 loop_reread_partitions(lo, bdev);
1873 + * no get/put for file.
1875 +struct file *loop_backing_file(struct super_block *sb)
1878 + struct loop_device *l;
1881 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
1882 + l = sb->s_bdev->bd_disk->private_data;
1883 + ret = l->lo_backing_file;
1887 +EXPORT_SYMBOL(loop_backing_file);
1889 /* loop sysfs attributes */
1891 static ssize_t loop_attr_show(struct device *dev, char *page,
1892 @@ -898,7 +940,7 @@ static int loop_prepare_queue(struct loo
1893 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
1894 struct block_device *bdev, unsigned int arg)
1896 - struct file *file;
1897 + struct file *file, *f, *virt_file = NULL;
1898 struct inode *inode;
1899 struct address_space *mapping;
1900 unsigned lo_blocksize;
1901 @@ -913,6 +955,12 @@ static int loop_set_fd(struct loop_devic
1905 + f = loop_real_file(file);
1913 if (lo->lo_state != Lo_unbound)
1914 @@ -950,6 +998,7 @@ static int loop_set_fd(struct loop_devic
1915 lo->lo_flags = lo_flags;
1916 lo->lo_xid = vx_current_xid();
1917 lo->lo_backing_file = file;
1918 + lo->lo_backing_virt_file = virt_file;
1919 lo->transfer = NULL;
1921 lo->lo_sizelimit = 0;
1922 @@ -982,6 +1031,8 @@ static int loop_set_fd(struct loop_devic
1929 /* This is safe: open() is still holding a reference. */
1930 module_put(THIS_MODULE);
1931 @@ -1028,6 +1079,7 @@ loop_init_xfer(struct loop_device *lo, s
1932 static int loop_clr_fd(struct loop_device *lo)
1934 struct file *filp = lo->lo_backing_file;
1935 + struct file *virt_filp = lo->lo_backing_virt_file;
1936 gfp_t gfp = lo->old_gfp_mask;
1937 struct block_device *bdev = lo->lo_device;
1939 @@ -1059,6 +1111,7 @@ static int loop_clr_fd(struct loop_devic
1940 spin_lock_irq(&lo->lo_lock);
1941 lo->lo_state = Lo_rundown;
1942 lo->lo_backing_file = NULL;
1943 + lo->lo_backing_virt_file = NULL;
1944 spin_unlock_irq(&lo->lo_lock);
1946 loop_release_xfer(lo);
1947 @@ -1104,6 +1157,8 @@ static int loop_clr_fd(struct loop_devic
1948 * bd_mutex which is usually taken before lo_ctl_mutex.
1956 diff -urNp -x '*.orig' linux-4.4/drivers/block/loop.h linux-4.4/drivers/block/loop.h
1957 --- linux-4.4/drivers/block/loop.h 2021-02-24 17:28:03.251779927 +0100
1958 +++ linux-4.4/drivers/block/loop.h 2021-02-24 17:28:14.418808602 +0100
1959 @@ -47,7 +47,7 @@ struct loop_device {
1960 int (*ioctl)(struct loop_device *, int cmd,
1963 - struct file * lo_backing_file;
1964 + struct file * lo_backing_file, *lo_backing_virt_file;
1965 struct block_device *lo_device;
1966 unsigned lo_blocksize;
1968 diff -urNp -x '*.orig' linux-4.4/fs/Kconfig linux-4.4/fs/Kconfig
1969 --- linux-4.4/fs/Kconfig 2016-01-11 00:01:32.000000000 +0100
1970 +++ linux-4.4/fs/Kconfig 2021-02-24 17:28:14.378807305 +0100
1971 @@ -221,6 +221,7 @@ source "fs/pstore/Kconfig"
1972 source "fs/sysv/Kconfig"
1973 source "fs/ufs/Kconfig"
1974 source "fs/exofs/Kconfig"
1975 +source "fs/aufs/Kconfig"
1977 endif # MISC_FILESYSTEMS
1979 diff -urNp -x '*.orig' linux-4.4/fs/Makefile linux-4.4/fs/Makefile
1980 --- linux-4.4/fs/Makefile 2016-01-11 00:01:32.000000000 +0100
1981 +++ linux-4.4/fs/Makefile 2021-02-24 17:28:14.378807305 +0100
1982 @@ -126,3 +126,4 @@ obj-y += exofs/ # Multiple modules
1983 obj-$(CONFIG_CEPH_FS) += ceph/
1984 obj-$(CONFIG_PSTORE) += pstore/
1985 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
1986 +obj-$(CONFIG_AUFS_FS) += aufs/
1987 diff -urNp -x '*.orig' linux-4.4/fs/aufs/Kconfig linux-4.4/fs/aufs/Kconfig
1988 --- linux-4.4/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
1989 +++ linux-4.4/fs/aufs/Kconfig 2021-02-24 17:28:14.408808278 +0100
1992 + tristate "Aufs (Advanced multi layered unification filesystem) support"
1994 + Aufs is a stackable unification filesystem such as Unionfs,
1995 + which unifies several directories and provides a merged single
1997 + In the early days, aufs was entirely re-designed and
1998 + re-implemented Unionfs Version 1.x series. Introducing many
1999 + original ideas, approaches and improvements, it becomes totally
2000 + different from Unionfs while keeping the basic features.
2004 + prompt "Maximum number of branches"
2005 + default AUFS_BRANCH_MAX_127
2007 + Specifies the maximum number of branches (or member directories)
2008 + in a single aufs. The larger value consumes more system
2009 + resources and has a minor impact to performance.
2010 +config AUFS_BRANCH_MAX_127
2013 + Specifies the maximum number of branches (or member directories)
2014 + in a single aufs. The larger value consumes more system
2015 + resources and has a minor impact to performance.
2016 +config AUFS_BRANCH_MAX_511
2019 + Specifies the maximum number of branches (or member directories)
2020 + in a single aufs. The larger value consumes more system
2021 + resources and has a minor impact to performance.
2022 +config AUFS_BRANCH_MAX_1023
2025 + Specifies the maximum number of branches (or member directories)
2026 + in a single aufs. The larger value consumes more system
2027 + resources and has a minor impact to performance.
2028 +config AUFS_BRANCH_MAX_32767
2031 + Specifies the maximum number of branches (or member directories)
2032 + in a single aufs. The larger value consumes more system
2033 + resources and has a minor impact to performance.
2036 +config AUFS_SBILIST
2038 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
2041 + Automatic configuration for internal use.
2042 + When aufs supports Magic SysRq or /proc, enabled automatically.
2044 +config AUFS_HNOTIFY
2045 + bool "Detect direct branch access (bypassing aufs)"
2047 + If you want to modify files on branches directly, eg. bypassing aufs,
2048 + and want aufs to detect the changes of them fully, then enable this
2049 + option and use 'udba=notify' mount option.
2050 + Currently there is only one available configuration, "fsnotify".
2051 + It will have a negative impact to the performance.
2052 + See detail in aufs.5.
2055 + prompt "method" if AUFS_HNOTIFY
2056 + default AUFS_HFSNOTIFY
2057 +config AUFS_HFSNOTIFY
2063 + bool "NFS-exportable aufs"
2064 + depends on EXPORTFS
2066 + If you want to export your mounted aufs via NFS, then enable this
2067 + option. There are several requirements for this configuration.
2068 + See detail in aufs.5.
2070 +config AUFS_INO_T_64
2072 + depends on AUFS_EXPORT
2073 + depends on 64BIT && !(ALPHA || S390)
2076 + Automatic configuration for internal use.
2077 + /* typedef unsigned long/int __kernel_ino_t */
2078 + /* alpha and s390x are int */
2081 + bool "support for XATTR/EA (including Security Labels)"
2083 + If your branch fs supports XATTR/EA and you want to make them
2084 + available in aufs too, then enable this opsion and specify the
2085 + branch attributes for EA.
2086 + See detail in aufs.5.
2089 + bool "File-based Hierarchical Storage Management"
2091 + Hierarchical Storage Management (or HSM) is a well-known feature
2092 + in the storage world. Aufs provides this feature as file-based.
2093 + with multiple branches.
2094 + These multiple branches are prioritized, ie. the topmost one
2095 + should be the fastest drive and be used heavily.
2098 + bool "Readdir in userspace"
2100 + Aufs has two methods to provide a merged view for a directory,
2101 + by a user-space library and by kernel-space natively. The latter
2102 + is always enabled but sometimes large and slow.
2103 + If you enable this option, install the library in aufs2-util
2104 + package, and set some environment variables for your readdir(3),
2105 + then the work will be handled in user-space which generally
2106 + shows better performance in most cases.
2107 + See detail in aufs.5.
2110 + bool "Show whiteouts"
2112 + If you want to make the whiteouts in aufs visible, then enable
2113 + this option and specify 'shwh' mount option. Although it may
2114 + sounds like philosophy or something, but in technically it
2115 + simply shows the name of whiteout with keeping its behaviour.
2117 +config AUFS_BR_RAMFS
2118 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
2120 + If you want to use ramfs as an aufs branch fs, then enable this
2121 + option. Generally tmpfs is recommended.
2122 + Aufs prohibited them to be a branch fs by default, because
2123 + initramfs becomes unusable after switch_root or something
2124 + generally. If you sets initramfs as an aufs branch and boot your
2125 + system by switch_root, you will meet a problem easily since the
2126 + files in initramfs may be inaccessible.
2127 + Unless you are going to use ramfs as an aufs branch fs without
2128 + switch_root or something, leave it N.
2130 +config AUFS_BR_FUSE
2131 + bool "Fuse fs as an aufs branch"
2132 + depends on FUSE_FS
2135 + If you want to use fuse-based userspace filesystem as an aufs
2136 + branch fs, then enable this option.
2137 + It implements the internal poll(2) operation which is
2138 + implemented by fuse only (curretnly).
2143 + Automatic configuration for internal use.
2145 +config AUFS_BR_HFSPLUS
2146 + bool "Hfsplus as an aufs branch"
2147 + depends on HFSPLUS_FS
2150 + If you want to use hfsplus fs as an aufs branch fs, then enable
2151 + this option. This option introduces a small overhead at
2152 + copying-up a file on hfsplus.
2154 +config AUFS_BDEV_LOOP
2156 + depends on BLK_DEV_LOOP
2159 + Automatic configuration for internal use.
2160 + Convert =[ym] into =y.
2165 + Enable this to compile aufs internal debug code.
2166 + It will have a negative impact to the performance.
2168 +config AUFS_MAGIC_SYSRQ
2170 + depends on AUFS_DEBUG && MAGIC_SYSRQ
2173 + Automatic configuration for internal use.
2174 + When aufs supports Magic SysRq, enabled automatically.
2176 diff -urNp -x '*.orig' linux-4.4/fs/aufs/Makefile linux-4.4/fs/aufs/Makefile
2177 --- linux-4.4/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
2178 +++ linux-4.4/fs/aufs/Makefile 2021-02-24 17:28:14.408808278 +0100
2181 +include ${src}/magic.mk
2182 +ifeq (${CONFIG_AUFS_FS},m)
2183 +include ${src}/conf.mk
2185 +-include ${src}/priv_def.mk
2187 +# cf. include/linux/kernel.h
2189 +ccflags-y += -DDEBUG
2190 +# sparse requires the full pathname
2192 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
2194 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
2197 +obj-$(CONFIG_AUFS_FS) += aufs.o
2198 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
2199 + wkq.o vfsub.o dcsub.o \
2200 + cpup.o whout.o wbr_policy.o \
2201 + dinfo.o dentry.o \
2203 + finfo.o file.o f_op.o \
2205 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
2209 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
2210 +aufs-$(CONFIG_SYSFS) += sysfs.o
2211 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
2212 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
2213 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
2214 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
2215 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
2216 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
2217 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
2218 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
2219 +aufs-$(CONFIG_AUFS_POLL) += poll.o
2220 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
2221 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
2222 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
2223 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
2224 diff -urNp -x '*.orig' linux-4.4/fs/aufs/aufs.h linux-4.4/fs/aufs/aufs.h
2225 --- linux-4.4/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2226 +++ linux-4.4/fs/aufs/aufs.h 2021-02-24 17:28:14.398807954 +0100
2229 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2231 + * This program, aufs is free software; you can redistribute it and/or modify
2232 + * it under the terms of the GNU General Public License as published by
2233 + * the Free Software Foundation; either version 2 of the License, or
2234 + * (at your option) any later version.
2236 + * This program is distributed in the hope that it will be useful,
2237 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2238 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2239 + * GNU General Public License for more details.
2241 + * You should have received a copy of the GNU General Public License
2242 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2246 + * all header files
2254 +#define AuStub(type, name, body, ...) \
2255 + static inline type name(__VA_ARGS__) { body; }
2257 +#define AuStubVoid(name, ...) \
2258 + AuStub(void, name, , __VA_ARGS__)
2259 +#define AuStubInt0(name, ...) \
2260 + AuStub(int, name, return 0, __VA_ARGS__)
2264 +#include "branch.h"
2267 +#include "dbgaufs.h"
2268 +#include "dentry.h"
2272 +#include "fstype.h"
2275 +#include "module.h"
2280 +#include "sysaufs.h"
2285 +#endif /* __KERNEL__ */
2286 +#endif /* __AUFS_H__ */
2287 diff -urNp -x '*.orig' linux-4.4/fs/aufs/branch.c linux-4.4/fs/aufs/branch.c
2288 --- linux-4.4/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2289 +++ linux-4.4/fs/aufs/branch.c 2021-02-24 17:28:14.398807954 +0100
2292 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2294 + * This program, aufs is free software; you can redistribute it and/or modify
2295 + * it under the terms of the GNU General Public License as published by
2296 + * the Free Software Foundation; either version 2 of the License, or
2297 + * (at your option) any later version.
2299 + * This program is distributed in the hope that it will be useful,
2300 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2301 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2302 + * GNU General Public License for more details.
2304 + * You should have received a copy of the GNU General Public License
2305 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2309 + * branch management
2312 +#include <linux/compat.h>
2313 +#include <linux/statfs.h>
2317 + * free a single branch
2319 +static void au_br_do_free(struct au_branch *br)
2322 + struct au_wbr *wbr;
2323 + struct au_dykey **key;
2325 + au_hnotify_fin_br(br);
2327 + if (br->br_xino.xi_file)
2328 + fput(br->br_xino.xi_file);
2329 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2331 + AuDebugOn(atomic_read(&br->br_count));
2335 + for (i = 0; i < AuBrWh_Last; i++)
2336 + dput(wbr->wbr_wh[i]);
2337 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2338 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2341 + if (br->br_fhsm) {
2342 + au_br_fhsm_fin(br->br_fhsm);
2343 + kfree(br->br_fhsm);
2346 + key = br->br_dykey;
2347 + for (i = 0; i < AuBrDynOp; i++, key++)
2353 + /* recursive lock, s_umount of branch's */
2355 + path_put(&br->br_path);
2362 + * frees all branches
2364 +void au_br_free(struct au_sbinfo *sbinfo)
2366 + aufs_bindex_t bmax;
2367 + struct au_branch **br;
2369 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2371 + bmax = sbinfo->si_bend + 1;
2372 + br = sbinfo->si_branch;
2374 + au_br_do_free(*br++);
2378 + * find the index of a branch which is specified by @br_id.
2380 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2382 + aufs_bindex_t bindex, bend;
2384 + bend = au_sbend(sb);
2385 + for (bindex = 0; bindex <= bend; bindex++)
2386 + if (au_sbr_id(sb, bindex) == br_id)
2391 +/* ---------------------------------------------------------------------- */
2397 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2398 + struct dentry *h_root)
2400 + if (unlikely(h_adding == h_root
2401 + || au_test_loopback_overlap(sb, h_adding)))
2403 + if (h_adding->d_sb != h_root->d_sb)
2405 + return au_test_subdir(h_adding, h_root)
2406 + || au_test_subdir(h_root, h_adding);
2410 + * returns a newly allocated branch. @new_nbranch is a number of branches
2411 + * after adding a branch.
2413 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2416 + struct au_branch *add_branch;
2417 + struct dentry *root;
2418 + struct inode *inode;
2422 + root = sb->s_root;
2423 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
2424 + if (unlikely(!add_branch))
2427 + err = au_hnotify_init_br(add_branch, perm);
2428 + if (unlikely(err))
2431 + if (au_br_writable(perm)) {
2432 + /* may be freed separately at changing the branch permission */
2433 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
2435 + if (unlikely(!add_branch->br_wbr))
2439 + if (au_br_fhsm(perm)) {
2440 + err = au_fhsm_br_alloc(add_branch);
2441 + if (unlikely(err))
2445 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2447 + err = au_di_realloc(au_di(root), new_nbranch);
2449 + inode = d_inode(root);
2450 + err = au_ii_realloc(au_ii(inode), new_nbranch);
2453 + return add_branch; /* success */
2456 + kfree(add_branch->br_wbr);
2458 + au_hnotify_fin_br(add_branch);
2460 + kfree(add_branch);
2462 + return ERR_PTR(err);
2466 + * test if the branch permission is legal or not.
2468 +static int test_br(struct inode *inode, int brperm, char *path)
2472 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2477 + pr_err("write permission for readonly mount or inode, %s\n", path);
2485 + * 0: success, the caller will add it
2486 + * plus: success, it is already unified, the caller should ignore it
2489 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2492 + aufs_bindex_t bend, bindex;
2493 + struct dentry *root, *h_dentry;
2494 + struct inode *inode, *h_inode;
2496 + root = sb->s_root;
2497 + bend = au_sbend(sb);
2498 + if (unlikely(bend >= 0
2499 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2503 + pr_err("%s duplicated\n", add->pathname);
2508 + err = -ENOSPC; /* -E2BIG; */
2509 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2510 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2511 + pr_err("number of branches exceeded %s\n", add->pathname);
2516 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2517 + pr_err("bad index %d\n", add->bindex);
2521 + inode = d_inode(add->path.dentry);
2523 + if (unlikely(!inode->i_nlink)) {
2524 + pr_err("no existence %s\n", add->pathname);
2529 + if (unlikely(inode->i_sb == sb)) {
2530 + pr_err("%s must be outside\n", add->pathname);
2534 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2535 + pr_err("unsupported filesystem, %s (%s)\n",
2536 + add->pathname, au_sbtype(inode->i_sb));
2540 + if (unlikely(inode->i_sb->s_stack_depth)) {
2541 + pr_err("already stacked, %s (%s)\n",
2542 + add->pathname, au_sbtype(inode->i_sb));
2546 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
2547 + if (unlikely(err))
2551 + return 0; /* success */
2554 + for (bindex = 0; bindex <= bend; bindex++)
2555 + if (unlikely(test_overlap(sb, add->path.dentry,
2556 + au_h_dptr(root, bindex)))) {
2557 + pr_err("%s is overlapped\n", add->pathname);
2562 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2563 + h_dentry = au_h_dptr(root, 0);
2564 + h_inode = d_inode(h_dentry);
2565 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2566 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2567 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2568 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2570 + i_uid_read(inode), i_gid_read(inode),
2571 + (inode->i_mode & S_IALLUGO),
2572 + i_uid_read(h_inode), i_gid_read(h_inode),
2573 + (h_inode->i_mode & S_IALLUGO));
2581 + * initialize or clean the whiteouts for an adding branch
2583 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2586 + int err, old_perm;
2587 + aufs_bindex_t bindex;
2588 + struct mutex *h_mtx;
2589 + struct au_wbr *wbr;
2590 + struct au_hinode *hdir;
2591 + struct dentry *h_dentry;
2593 + err = vfsub_mnt_want_write(au_br_mnt(br));
2594 + if (unlikely(err))
2598 + old_perm = br->br_perm;
2599 + br->br_perm = new_perm;
2602 + bindex = au_br_index(sb, br->br_id);
2603 + if (0 <= bindex) {
2604 + hdir = au_hi(d_inode(sb->s_root), bindex);
2605 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2607 + h_dentry = au_br_dentry(br);
2608 + h_mtx = &d_inode(h_dentry)->i_mutex;
2609 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2612 + err = au_wh_init(br, sb);
2614 + wbr_wh_write_lock(wbr);
2615 + err = au_wh_init(br, sb);
2616 + wbr_wh_write_unlock(wbr);
2619 + au_hn_imtx_unlock(hdir);
2621 + mutex_unlock(h_mtx);
2622 + vfsub_mnt_drop_write(au_br_mnt(br));
2623 + br->br_perm = old_perm;
2625 + if (!err && wbr && !au_br_writable(new_perm)) {
2627 + br->br_wbr = NULL;
2634 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2638 + struct kstatfs kst;
2639 + struct au_wbr *wbr;
2642 + au_rw_init(&wbr->wbr_wh_rwsem);
2643 + atomic_set(&wbr->wbr_wh_running, 0);
2646 + * a limit for rmdir/rename a dir
2647 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
2649 + err = vfs_statfs(&br->br_path, &kst);
2650 + if (unlikely(err))
2653 + if (kst.f_namelen >= NAME_MAX)
2654 + err = au_br_init_wh(sb, br, perm);
2656 + pr_err("%pd(%s), unsupported namelen %ld\n",
2658 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2664 +/* initialize a new branch */
2665 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2666 + struct au_opt_add *add)
2669 + struct inode *h_inode;
2672 + mutex_init(&br->br_xino.xi_nondir_mtx);
2673 + br->br_perm = add->perm;
2674 + br->br_path = add->path; /* set first, path_get() later */
2675 + spin_lock_init(&br->br_dykey_lock);
2676 + atomic_set(&br->br_count, 0);
2677 + atomic_set(&br->br_xino_running, 0);
2678 + br->br_id = au_new_br_id(sb);
2679 + AuDebugOn(br->br_id < 0);
2681 + if (au_br_writable(add->perm)) {
2682 + err = au_wbr_init(br, sb, add->perm);
2683 + if (unlikely(err))
2687 + if (au_opt_test(au_mntflags(sb), XINO)) {
2688 + h_inode = d_inode(add->path.dentry);
2689 + err = au_xino_br(sb, br, h_inode->i_ino,
2690 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2691 + if (unlikely(err)) {
2692 + AuDebugOn(br->br_xino.xi_file);
2697 + sysaufs_br_init(br);
2698 + path_get(&br->br_path);
2699 + goto out; /* success */
2702 + memset(&br->br_path, 0, sizeof(br->br_path));
2707 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2708 + struct au_branch *br, aufs_bindex_t bend,
2709 + aufs_bindex_t amount)
2711 + struct au_branch **brp;
2713 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2715 + brp = sbinfo->si_branch + bindex;
2716 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2718 + sbinfo->si_bend++;
2719 + if (unlikely(bend < 0))
2720 + sbinfo->si_bend = 0;
2723 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2724 + aufs_bindex_t bend, aufs_bindex_t amount)
2726 + struct au_hdentry *hdp;
2728 + AuRwMustWriteLock(&dinfo->di_rwsem);
2730 + hdp = dinfo->di_hdentry + bindex;
2731 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2732 + au_h_dentry_init(hdp);
2734 + if (unlikely(bend < 0))
2735 + dinfo->di_bstart = 0;
2738 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2739 + aufs_bindex_t bend, aufs_bindex_t amount)
2741 + struct au_hinode *hip;
2743 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2745 + hip = iinfo->ii_hinode + bindex;
2746 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2747 + hip->hi_inode = NULL;
2750 + if (unlikely(bend < 0))
2751 + iinfo->ii_bstart = 0;
2754 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
2755 + aufs_bindex_t bindex)
2757 + struct dentry *root, *h_dentry;
2758 + struct inode *root_inode, *h_inode;
2759 + aufs_bindex_t bend, amount;
2761 + root = sb->s_root;
2762 + root_inode = d_inode(root);
2763 + bend = au_sbend(sb);
2764 + amount = bend + 1 - bindex;
2765 + h_dentry = au_br_dentry(br);
2766 + au_sbilist_lock();
2767 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2768 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2769 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2770 + au_set_h_dptr(root, bindex, dget(h_dentry));
2771 + h_inode = d_inode(h_dentry);
2772 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
2773 + au_sbilist_unlock();
2776 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
2779 + aufs_bindex_t bend, add_bindex;
2780 + struct dentry *root, *h_dentry;
2781 + struct inode *root_inode;
2782 + struct au_branch *add_branch;
2784 + root = sb->s_root;
2785 + root_inode = d_inode(root);
2786 + IMustLock(root_inode);
2787 + err = test_add(sb, add, remount);
2788 + if (unlikely(err < 0))
2792 + goto out; /* success */
2795 + bend = au_sbend(sb);
2796 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
2797 + err = PTR_ERR(add_branch);
2798 + if (IS_ERR(add_branch))
2801 + err = au_br_init(add_branch, sb, add);
2802 + if (unlikely(err)) {
2803 + au_br_do_free(add_branch);
2807 + add_bindex = add->bindex;
2809 + au_br_do_add(sb, add_branch, add_bindex);
2811 + sysaufs_brs_del(sb, add_bindex);
2812 + au_br_do_add(sb, add_branch, add_bindex);
2813 + sysaufs_brs_add(sb, add_bindex);
2816 + h_dentry = add->path.dentry;
2817 + if (!add_bindex) {
2818 + au_cpup_attr_all(root_inode, /*force*/1);
2819 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
2821 + au_add_nlink(root_inode, d_inode(h_dentry));
2824 + * this test/set prevents aufs from handling unnecesary notify events
2825 + * of xino files, in case of re-adding a writable branch which was
2826 + * once detached from aufs.
2828 + if (au_xino_brid(sb) < 0
2829 + && au_br_writable(add_branch->br_perm)
2830 + && !au_test_fs_bad_xino(h_dentry->d_sb)
2831 + && add_branch->br_xino.xi_file
2832 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
2833 + au_xino_brid_set(sb, add_branch->br_id);
2839 +/* ---------------------------------------------------------------------- */
2841 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
2842 + unsigned long long max __maybe_unused,
2845 + unsigned long long n;
2846 + struct file **p, *f;
2847 + struct au_sphlhead *files;
2848 + struct au_finfo *finfo;
2852 + files = &au_sbi(sb)->si_files;
2853 + spin_lock(&files->spin);
2854 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
2855 + f = finfo->fi_file;
2857 + && !special_file(file_inode(f)->i_mode)) {
2861 + AuDebugOn(n > max);
2864 + spin_unlock(&files->spin);
2869 +static struct file **au_farray_alloc(struct super_block *sb,
2870 + unsigned long long *max)
2872 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
2873 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
2876 +static void au_farray_free(struct file **a, unsigned long long max)
2878 + unsigned long long ull;
2880 + for (ull = 0; ull < max; ull++)
2886 +/* ---------------------------------------------------------------------- */
2892 +/* to show the line number, do not make it inlined function */
2893 +#define AuVerbose(do_info, fmt, ...) do { \
2895 + pr_info(fmt, ##__VA_ARGS__); \
2898 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
2899 + aufs_bindex_t bend)
2901 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
2904 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
2905 + aufs_bindex_t bend)
2907 + return au_test_ibusy(d_inode(dentry), bstart, bend);
2911 + * test if the branch is deletable or not.
2913 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
2914 + unsigned int sigen, const unsigned int verbose)
2916 + int err, i, j, ndentry;
2917 + aufs_bindex_t bstart, bend;
2918 + struct au_dcsub_pages dpages;
2919 + struct au_dpage *dpage;
2922 + err = au_dpages_init(&dpages, GFP_NOFS);
2923 + if (unlikely(err))
2925 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
2926 + if (unlikely(err))
2929 + for (i = 0; !err && i < dpages.ndpage; i++) {
2930 + dpage = dpages.dpages + i;
2931 + ndentry = dpage->ndentry;
2932 + for (j = 0; !err && j < ndentry; j++) {
2933 + d = dpage->dentries[j];
2934 + AuDebugOn(au_dcount(d) <= 0);
2935 + if (!au_digen_test(d, sigen)) {
2936 + di_read_lock_child(d, AuLock_IR);
2937 + if (unlikely(au_dbrange_test(d))) {
2938 + di_read_unlock(d, AuLock_IR);
2942 + di_write_lock_child(d);
2943 + if (unlikely(au_dbrange_test(d))) {
2944 + di_write_unlock(d);
2947 + err = au_reval_dpath(d, sigen);
2949 + di_downgrade_lock(d, AuLock_IR);
2951 + di_write_unlock(d);
2956 + /* AuDbgDentry(d); */
2957 + bstart = au_dbstart(d);
2958 + bend = au_dbend(d);
2959 + if (bstart <= bindex
2961 + && au_h_dptr(d, bindex)
2962 + && au_test_dbusy(d, bstart, bend)) {
2964 + AuVerbose(verbose, "busy %pd\n", d);
2967 + di_read_unlock(d, AuLock_IR);
2972 + au_dpages_free(&dpages);
2977 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
2978 + unsigned int sigen, const unsigned int verbose)
2981 + unsigned long long max, ull;
2982 + struct inode *i, **array;
2983 + aufs_bindex_t bstart, bend;
2985 + array = au_iarray_alloc(sb, &max);
2986 + err = PTR_ERR(array);
2987 + if (IS_ERR(array))
2991 + AuDbg("b%d\n", bindex);
2992 + for (ull = 0; !err && ull < max; ull++) {
2996 + if (i->i_ino == AUFS_ROOT_INO)
2999 + /* AuDbgInode(i); */
3000 + if (au_iigen(i, NULL) == sigen)
3001 + ii_read_lock_child(i);
3003 + ii_write_lock_child(i);
3004 + err = au_refresh_hinode_self(i);
3007 + ii_downgrade_lock(i);
3009 + ii_write_unlock(i);
3014 + bstart = au_ibstart(i);
3015 + bend = au_ibend(i);
3016 + if (bstart <= bindex
3018 + && au_h_iptr(i, bindex)
3019 + && au_test_ibusy(i, bstart, bend)) {
3021 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3024 + ii_read_unlock(i);
3026 + au_iarray_free(array, max);
3032 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3033 + const unsigned int verbose)
3036 + unsigned int sigen;
3038 + sigen = au_sigen(root->d_sb);
3039 + DiMustNoWaiters(root);
3040 + IiMustNoWaiters(d_inode(root));
3041 + di_write_unlock(root);
3042 + err = test_dentry_busy(root, bindex, sigen, verbose);
3044 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3045 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3050 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3051 + struct file **to_free, int *idx)
3054 + unsigned char matched, root;
3055 + aufs_bindex_t bindex, bend;
3056 + struct au_fidir *fidir;
3057 + struct au_hfile *hfile;
3060 + root = IS_ROOT(file->f_path.dentry);
3063 + to_free[*idx] = file;
3069 + fidir = au_fi(file)->fi_hdir;
3070 + AuDebugOn(!fidir);
3071 + bend = au_fbend_dir(file);
3072 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3073 + hfile = fidir->fd_hfile + bindex;
3074 + if (!hfile->hf_file)
3077 + if (hfile->hf_br->br_id == br_id) {
3089 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3090 + struct file **to_free, int opened)
3093 + unsigned long long ull, max;
3094 + aufs_bindex_t bstart;
3095 + struct file *file, **array;
3096 + struct dentry *root;
3097 + struct au_hfile *hfile;
3099 + array = au_farray_alloc(sb, &max);
3100 + err = PTR_ERR(array);
3101 + if (IS_ERR(array))
3106 + root = sb->s_root;
3107 + di_write_unlock(root);
3108 + for (ull = 0; ull < max; ull++) {
3109 + file = array[ull];
3110 + if (unlikely(!file))
3113 + /* AuDbg("%pD\n", file); */
3114 + fi_read_lock(file);
3115 + bstart = au_fbstart(file);
3116 + if (!d_is_dir(file->f_path.dentry)) {
3117 + hfile = &au_fi(file)->fi_htop;
3118 + if (hfile->hf_br->br_id == br_id)
3121 + err = test_dir_busy(file, br_id, to_free, &idx);
3122 + fi_read_unlock(file);
3123 + if (unlikely(err))
3126 + di_write_lock_child(root);
3127 + au_farray_free(array, max);
3128 + AuDebugOn(idx > opened);
3134 +static void br_del_file(struct file **to_free, unsigned long long opened,
3135 + aufs_bindex_t br_id)
3137 + unsigned long long ull;
3138 + aufs_bindex_t bindex, bstart, bend, bfound;
3139 + struct file *file;
3140 + struct au_fidir *fidir;
3141 + struct au_hfile *hfile;
3143 + for (ull = 0; ull < opened; ull++) {
3144 + file = to_free[ull];
3145 + if (unlikely(!file))
3148 + /* AuDbg("%pD\n", file); */
3149 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3151 + fidir = au_fi(file)->fi_hdir;
3152 + AuDebugOn(!fidir);
3153 + fi_write_lock(file);
3154 + bstart = au_fbstart(file);
3155 + bend = au_fbend_dir(file);
3156 + for (bindex = bstart; bindex <= bend; bindex++) {
3157 + hfile = fidir->fd_hfile + bindex;
3158 + if (!hfile->hf_file)
3161 + if (hfile->hf_br->br_id == br_id) {
3166 + AuDebugOn(bfound < 0);
3167 + au_set_h_fptr(file, bfound, NULL);
3168 + if (bfound == bstart) {
3169 + for (bstart++; bstart <= bend; bstart++)
3170 + if (au_hf_dir(file, bstart)) {
3171 + au_set_fbstart(file, bstart);
3175 + fi_write_unlock(file);
3179 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3180 + const aufs_bindex_t bindex,
3181 + const aufs_bindex_t bend)
3183 + struct au_branch **brp, **p;
3185 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3187 + brp = sbinfo->si_branch + bindex;
3188 + if (bindex < bend)
3189 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3190 + sbinfo->si_branch[0 + bend] = NULL;
3191 + sbinfo->si_bend--;
3193 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3195 + sbinfo->si_branch = p;
3196 + /* harmless error */
3199 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3200 + const aufs_bindex_t bend)
3202 + struct au_hdentry *hdp, *p;
3204 + AuRwMustWriteLock(&dinfo->di_rwsem);
3206 + hdp = dinfo->di_hdentry;
3207 + if (bindex < bend)
3208 + memmove(hdp + bindex, hdp + bindex + 1,
3209 + sizeof(*hdp) * (bend - bindex));
3210 + hdp[0 + bend].hd_dentry = NULL;
3213 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3215 + dinfo->di_hdentry = p;
3216 + /* harmless error */
3219 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3220 + const aufs_bindex_t bend)
3222 + struct au_hinode *hip, *p;
3224 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3226 + hip = iinfo->ii_hinode + bindex;
3227 + if (bindex < bend)
3228 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3229 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3230 + au_hn_init(iinfo->ii_hinode + bend);
3233 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3235 + iinfo->ii_hinode = p;
3236 + /* harmless error */
3239 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3240 + struct au_branch *br)
3242 + aufs_bindex_t bend;
3243 + struct au_sbinfo *sbinfo;
3244 + struct dentry *root, *h_root;
3245 + struct inode *inode, *h_inode;
3246 + struct au_hinode *hinode;
3248 + SiMustWriteLock(sb);
3250 + root = sb->s_root;
3251 + inode = d_inode(root);
3252 + sbinfo = au_sbi(sb);
3253 + bend = sbinfo->si_bend;
3255 + h_root = au_h_dptr(root, bindex);
3256 + hinode = au_hi(inode, bindex);
3257 + h_inode = au_igrab(hinode->hi_inode);
3260 + au_sbilist_lock();
3261 + au_br_do_del_brp(sbinfo, bindex, bend);
3262 + au_br_do_del_hdp(au_di(root), bindex, bend);
3263 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3264 + au_sbilist_unlock();
3268 + au_br_do_free(br);
3271 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3272 + unsigned long long max, void *arg)
3277 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3280 + unsigned long long opened;
3281 + unsigned int mnt_flags;
3282 + aufs_bindex_t bindex, bend, br_id;
3283 + unsigned char do_wh, verbose;
3284 + struct au_branch *br;
3285 + struct au_wbr *wbr;
3286 + struct dentry *root;
3287 + struct file **to_free;
3292 + root = sb->s_root;
3293 + bindex = au_find_dbindex(root, del->h_path.dentry);
3296 + goto out; /* success */
3298 + pr_err("%s no such branch\n", del->pathname);
3301 + AuDbg("bindex b%d\n", bindex);
3304 + mnt_flags = au_mntflags(sb);
3305 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3306 + bend = au_sbend(sb);
3307 + if (unlikely(!bend)) {
3308 + AuVerbose(verbose, "no more branches left\n");
3311 + br = au_sbr(sb, bindex);
3312 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3314 + br_id = br->br_id;
3315 + opened = atomic_read(&br->br_count);
3316 + if (unlikely(opened)) {
3317 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3318 + err = PTR_ERR(to_free);
3319 + if (IS_ERR(to_free))
3322 + err = test_file_busy(sb, br_id, to_free, opened);
3323 + if (unlikely(err)) {
3324 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3330 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3332 + /* instead of WbrWhMustWriteLock(wbr) */
3333 + SiMustWriteLock(sb);
3334 + for (i = 0; i < AuBrWh_Last; i++) {
3335 + dput(wbr->wbr_wh[i]);
3336 + wbr->wbr_wh[i] = NULL;
3340 + err = test_children_busy(root, bindex, verbose);
3341 + if (unlikely(err)) {
3350 + * now we confirmed the branch is deletable.
3351 + * let's free the remaining opened dirs on the branch.
3353 + di_write_unlock(root);
3354 + br_del_file(to_free, opened, br_id);
3355 + di_write_lock_child(root);
3359 + au_br_do_del(sb, bindex, br);
3361 + sysaufs_brs_del(sb, bindex);
3362 + au_br_do_del(sb, bindex, br);
3363 + sysaufs_brs_add(sb, bindex);
3367 + au_cpup_attr_all(d_inode(root), /*force*/1);
3368 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3370 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3371 + if (au_opt_test(mnt_flags, PLINK))
3372 + au_plink_half_refresh(sb, br_id);
3374 + if (au_xino_brid(sb) == br_id)
3375 + au_xino_brid_set(sb, -1);
3376 + goto out; /* success */
3380 + rerr = au_br_init_wh(sb, br, br->br_perm);
3382 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3383 + del->pathname, rerr);
3386 + au_farray_free(to_free, opened);
3390 +/* ---------------------------------------------------------------------- */
3392 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3395 + aufs_bindex_t bstart, bend;
3396 + struct aufs_ibusy ibusy;
3397 + struct inode *inode, *h_inode;
3400 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3403 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3405 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3406 + if (unlikely(err)) {
3413 + si_read_lock(sb, AuLock_FLUSH);
3414 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3418 + ibusy.h_ino = 0; /* invalid */
3419 + inode = ilookup(sb, ibusy.ino);
3421 + || inode->i_ino == AUFS_ROOT_INO
3422 + || is_bad_inode(inode))
3425 + ii_read_lock_child(inode);
3426 + bstart = au_ibstart(inode);
3427 + bend = au_ibend(inode);
3428 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3429 + h_inode = au_h_iptr(inode, ibusy.bindex);
3430 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3431 + ibusy.h_ino = h_inode->i_ino;
3433 + ii_read_unlock(inode);
3437 + si_read_unlock(sb);
3439 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3440 + if (unlikely(err)) {
3449 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3451 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
3454 +#ifdef CONFIG_COMPAT
3455 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3457 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
3461 +/* ---------------------------------------------------------------------- */
3464 + * change a branch permission
3467 +static void au_warn_ima(void)
3470 + /* since it doesn't support mark_files_ro() */
3471 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3475 +static int do_need_sigen_inc(int a, int b)
3477 + return au_br_whable(a) && !au_br_whable(b);
3480 +static int need_sigen_inc(int old, int new)
3482 + return do_need_sigen_inc(old, new)
3483 + || do_need_sigen_inc(new, old);
3486 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3489 + unsigned int mnt_flags;
3490 + unsigned long long ull, max;
3491 + aufs_bindex_t br_id;
3492 + unsigned char verbose, writer;
3493 + struct file *file, *hf, **array;
3494 + struct au_hfile *hfile;
3496 + mnt_flags = au_mntflags(sb);
3497 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3499 + array = au_farray_alloc(sb, &max);
3500 + err = PTR_ERR(array);
3501 + if (IS_ERR(array))
3505 + br_id = au_sbr_id(sb, bindex);
3506 + for (ull = 0; ull < max; ull++) {
3507 + file = array[ull];
3508 + if (unlikely(!file))
3511 + /* AuDbg("%pD\n", file); */
3512 + fi_read_lock(file);
3513 + if (unlikely(au_test_mmapped(file))) {
3515 + AuVerbose(verbose, "mmapped %pD\n", file);
3517 + FiMustNoWaiters(file);
3518 + fi_read_unlock(file);
3522 + hfile = &au_fi(file)->fi_htop;
3523 + hf = hfile->hf_file;
3524 + if (!d_is_reg(file->f_path.dentry)
3525 + || !(file->f_mode & FMODE_WRITE)
3526 + || hfile->hf_br->br_id != br_id
3527 + || !(hf->f_mode & FMODE_WRITE))
3528 + array[ull] = NULL;
3534 + FiMustNoWaiters(file);
3535 + fi_read_unlock(file);
3543 + for (ull = 0; ull < max; ull++) {
3544 + file = array[ull];
3548 + /* todo: already flushed? */
3550 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
3551 + * approach which resets f_mode and calls mnt_drop_write() and
3552 + * file_release_write() for each file, because the branch
3553 + * attribute in aufs world is totally different from the native
3556 + /* fi_read_lock(file); */
3557 + hfile = &au_fi(file)->fi_htop;
3558 + hf = hfile->hf_file;
3559 + /* fi_read_unlock(file); */
3560 + spin_lock(&hf->f_lock);
3561 + writer = !!(hf->f_mode & FMODE_WRITER);
3562 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
3563 + spin_unlock(&hf->f_lock);
3565 + put_write_access(file_inode(hf));
3566 + __mnt_drop_write(hf->f_path.mnt);
3571 + au_farray_free(array, max);
3577 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3581 + aufs_bindex_t bindex;
3582 + struct dentry *root;
3583 + struct au_branch *br;
3584 + struct au_br_fhsm *bf;
3586 + root = sb->s_root;
3587 + bindex = au_find_dbindex(root, mod->h_root);
3590 + return 0; /* success */
3592 + pr_err("%s no such branch\n", mod->path);
3595 + AuDbg("bindex b%d\n", bindex);
3597 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
3598 + if (unlikely(err))
3601 + br = au_sbr(sb, bindex);
3602 + AuDebugOn(mod->h_root != au_br_dentry(br));
3603 + if (br->br_perm == mod->perm)
3604 + return 0; /* success */
3606 + /* pre-allocate for non-fhsm --> fhsm */
3608 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
3609 + err = au_fhsm_br_alloc(br);
3610 + if (unlikely(err))
3613 + br->br_fhsm = NULL;
3616 + if (au_br_writable(br->br_perm)) {
3617 + /* remove whiteout base */
3618 + err = au_br_init_wh(sb, br, mod->perm);
3619 + if (unlikely(err))
3622 + if (!au_br_writable(mod->perm)) {
3623 + /* rw --> ro, file might be mmapped */
3624 + DiMustNoWaiters(root);
3625 + IiMustNoWaiters(d_inode(root));
3626 + di_write_unlock(root);
3627 + err = au_br_mod_files_ro(sb, bindex);
3628 + /* aufs_write_lock() calls ..._child() */
3629 + di_write_lock_child(root);
3631 + if (unlikely(err)) {
3633 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
3636 + rerr = au_wbr_init(br, sb, br->br_perm);
3637 + if (unlikely(rerr)) {
3638 + AuIOErr("nested error %d (%d)\n",
3640 + br->br_perm = mod->perm;
3644 + } else if (au_br_writable(mod->perm)) {
3647 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
3649 + err = au_wbr_init(br, sb, mod->perm);
3650 + if (unlikely(err)) {
3651 + kfree(br->br_wbr);
3652 + br->br_wbr = NULL;
3656 + if (unlikely(err))
3659 + if (au_br_fhsm(br->br_perm)) {
3660 + if (!au_br_fhsm(mod->perm)) {
3661 + /* fhsm --> non-fhsm */
3662 + au_br_fhsm_fin(br->br_fhsm);
3663 + kfree(br->br_fhsm);
3664 + br->br_fhsm = NULL;
3666 + } else if (au_br_fhsm(mod->perm))
3667 + /* non-fhsm --> fhsm */
3670 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3671 + br->br_perm = mod->perm;
3672 + goto out; /* success */
3681 +/* ---------------------------------------------------------------------- */
3683 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
3686 + struct kstatfs kstfs;
3688 + err = vfs_statfs(&br->br_path, &kstfs);
3690 + stfs->f_blocks = kstfs.f_blocks;
3691 + stfs->f_bavail = kstfs.f_bavail;
3692 + stfs->f_files = kstfs.f_files;
3693 + stfs->f_ffree = kstfs.f_ffree;
3698 diff -urNp -x '*.orig' linux-4.4/fs/aufs/branch.h linux-4.4/fs/aufs/branch.h
3699 --- linux-4.4/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3700 +++ linux-4.4/fs/aufs/branch.h 2021-02-24 17:28:14.398807954 +0100
3703 + * Copyright (C) 2005-2016 Junjiro R. Okajima
3705 + * This program, aufs is free software; you can redistribute it and/or modify
3706 + * it under the terms of the GNU General Public License as published by
3707 + * the Free Software Foundation; either version 2 of the License, or
3708 + * (at your option) any later version.
3710 + * This program is distributed in the hope that it will be useful,
3711 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3713 + * GNU General Public License for more details.
3715 + * You should have received a copy of the GNU General Public License
3716 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3720 + * branch filesystems and xino for them
3723 +#ifndef __AUFS_BRANCH_H__
3724 +#define __AUFS_BRANCH_H__
3728 +#include <linux/mount.h>
3733 +/* ---------------------------------------------------------------------- */
3736 +struct au_xino_file {
3737 + struct file *xi_file;
3738 + struct mutex xi_nondir_mtx;
3740 + /* todo: make xino files an array to support huge inode number */
3742 +#ifdef CONFIG_DEBUG_FS
3743 + struct dentry *xi_dbgaufs;
3747 +/* File-based Hierarchical Storage Management */
3748 +struct au_br_fhsm {
3749 +#ifdef CONFIG_AUFS_FHSM
3750 + struct mutex bf_lock;
3751 + unsigned long bf_jiffy;
3752 + struct aufs_stfs bf_stfs;
3757 +/* members for writable branch only */
3758 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
3760 + struct au_rwsem wbr_wh_rwsem;
3761 + struct dentry *wbr_wh[AuBrWh_Last];
3762 + atomic_t wbr_wh_running;
3763 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
3764 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
3765 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
3768 + unsigned long long wbr_bytes;
3771 +/* ext2 has 3 types of operations at least, ext3 has 4 */
3772 +#define AuBrDynOp (AuDyLast * 4)
3774 +#ifdef CONFIG_AUFS_HFSNOTIFY
3775 +/* support for asynchronous destruction */
3776 +struct au_br_hfsnotify {
3777 + struct fsnotify_group *hfsn_group;
3781 +/* sysfs entries */
3782 +struct au_brsysfs {
3784 + struct attribute attr;
3793 +/* protected by superblock rwsem */
3795 + struct au_xino_file br_xino;
3797 + aufs_bindex_t br_id;
3800 + struct path br_path;
3801 + spinlock_t br_dykey_lock;
3802 + struct au_dykey *br_dykey[AuBrDynOp];
3803 + atomic_t br_count;
3805 + struct au_wbr *br_wbr;
3806 + struct au_br_fhsm *br_fhsm;
3808 + /* xino truncation */
3809 + atomic_t br_xino_running;
3811 +#ifdef CONFIG_AUFS_HFSNOTIFY
3812 + struct au_br_hfsnotify *br_hfsn;
3815 +#ifdef CONFIG_SYSFS
3816 + /* entries under sysfs per mount-point */
3817 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
3821 +/* ---------------------------------------------------------------------- */
3823 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
3825 + return br->br_path.mnt;
3828 +static inline struct dentry *au_br_dentry(struct au_branch *br)
3830 + return br->br_path.dentry;
3833 +static inline struct super_block *au_br_sb(struct au_branch *br)
3835 + return au_br_mnt(br)->mnt_sb;
3838 +static inline int au_br_rdonly(struct au_branch *br)
3840 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
3841 + || !au_br_writable(br->br_perm))
3845 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
3847 +#ifdef CONFIG_AUFS_HNOTIFY
3848 + return !(brperm & AuBrPerm_RR);
3854 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
3856 + int err, exec_flag;
3859 + exec_flag = oflag & __FMODE_EXEC;
3860 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
3866 +/* ---------------------------------------------------------------------- */
3870 +void au_br_free(struct au_sbinfo *sinfo);
3871 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
3873 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
3875 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
3876 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
3877 +#ifdef CONFIG_COMPAT
3878 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
3881 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3884 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
3887 +static const loff_t au_loff_max = LLONG_MAX;
3889 +int au_xib_trunc(struct super_block *sb);
3890 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
3892 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
3893 + size_t size, loff_t *pos);
3894 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
3895 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
3896 +ino_t au_xino_new_ino(struct super_block *sb);
3897 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
3898 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3900 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
3902 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
3903 + struct file *base_file, int do_test);
3904 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
3906 +struct au_opt_xino;
3907 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
3908 +void au_xino_clr(struct super_block *sb);
3909 +struct file *au_xino_def(struct super_block *sb);
3910 +int au_xino_path(struct seq_file *seq, struct file *file);
3912 +/* ---------------------------------------------------------------------- */
3914 +/* Superblock to branch */
3916 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
3918 + return au_sbr(sb, bindex)->br_id;
3922 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
3924 + return au_br_mnt(au_sbr(sb, bindex));
3928 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
3930 + return au_br_sb(au_sbr(sb, bindex));
3933 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
3935 + atomic_dec(&au_sbr(sb, bindex)->br_count);
3938 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
3940 + return au_sbr(sb, bindex)->br_perm;
3943 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
3945 + return au_br_whable(au_sbr_perm(sb, bindex));
3948 +/* ---------------------------------------------------------------------- */
3951 + * wbr_wh_read_lock, wbr_wh_write_lock
3952 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
3954 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
3956 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
3957 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
3958 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
3960 +/* ---------------------------------------------------------------------- */
3962 +#ifdef CONFIG_AUFS_FHSM
3963 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
3965 + mutex_init(&brfhsm->bf_lock);
3966 + brfhsm->bf_jiffy = 0;
3967 + brfhsm->bf_readable = 0;
3970 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
3972 + mutex_destroy(&brfhsm->bf_lock);
3975 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
3976 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
3979 +#endif /* __KERNEL__ */
3980 +#endif /* __AUFS_BRANCH_H__ */
3981 diff -urNp -x '*.orig' linux-4.4/fs/aufs/conf.mk linux-4.4/fs/aufs/conf.mk
3982 --- linux-4.4/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
3983 +++ linux-4.4/fs/aufs/conf.mk 2021-02-24 17:28:14.398807954 +0100
3986 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
3990 +AuConfStr += ${1}=${${1}}
3994 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
3996 + HNOTIFY HFSNOTIFY \
4007 +$(foreach i, ${AuConfAll}, \
4008 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4010 +AuConfName = ${obj}/conf.str
4011 +${AuConfName}.tmp: FORCE
4012 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4013 +${AuConfName}: ${AuConfName}.tmp
4014 + @diff -q $< $@ > /dev/null 2>&1 || { \
4015 + echo ' GEN ' $@; \
4019 +clean-files += ${AuConfName} ${AuConfName}.tmp
4020 +${obj}/sysfs.o: ${AuConfName}
4022 +-include ${srctree}/${src}/conf_priv.mk
4023 diff -urNp -x '*.orig' linux-4.4/fs/aufs/cpup.c linux-4.4/fs/aufs/cpup.c
4024 --- linux-4.4/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4025 +++ linux-4.4/fs/aufs/cpup.c 2021-02-24 17:28:14.398807954 +0100
4028 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4030 + * This program, aufs is free software; you can redistribute it and/or modify
4031 + * it under the terms of the GNU General Public License as published by
4032 + * the Free Software Foundation; either version 2 of the License, or
4033 + * (at your option) any later version.
4035 + * This program is distributed in the hope that it will be useful,
4036 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4037 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4038 + * GNU General Public License for more details.
4040 + * You should have received a copy of the GNU General Public License
4041 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4045 + * copy-up functions, see wbr_policy.c for copy-down
4048 +#include <linux/fs_stack.h>
4049 +#include <linux/mm.h>
4050 +#include <linux/task_work.h>
4053 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4055 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4056 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4058 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4060 + dst->i_flags |= iflags & ~mask;
4061 + if (au_test_fs_notime(dst->i_sb))
4062 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4065 +void au_cpup_attr_timesizes(struct inode *inode)
4067 + struct inode *h_inode;
4069 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4070 + fsstack_copy_attr_times(inode, h_inode);
4071 + fsstack_copy_inode_size(inode, h_inode);
4074 +void au_cpup_attr_nlink(struct inode *inode, int force)
4076 + struct inode *h_inode;
4077 + struct super_block *sb;
4078 + aufs_bindex_t bindex, bend;
4081 + bindex = au_ibstart(inode);
4082 + h_inode = au_h_iptr(inode, bindex);
4084 + && !S_ISDIR(h_inode->i_mode)
4085 + && au_opt_test(au_mntflags(sb), PLINK)
4086 + && au_plink_test(inode))
4090 + * 0 can happen in revalidating.
4091 + * h_inode->i_mutex may not be held here, but it is harmless since once
4092 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4094 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4095 + * the incorrect link count.
4097 + set_nlink(inode, h_inode->i_nlink);
4100 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4101 + * it may includes whplink directory.
4103 + if (S_ISDIR(h_inode->i_mode)) {
4104 + bend = au_ibend(inode);
4105 + for (bindex++; bindex <= bend; bindex++) {
4106 + h_inode = au_h_iptr(inode, bindex);
4108 + au_add_nlink(inode, h_inode);
4113 +void au_cpup_attr_changeable(struct inode *inode)
4115 + struct inode *h_inode;
4117 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4118 + inode->i_mode = h_inode->i_mode;
4119 + inode->i_uid = h_inode->i_uid;
4120 + inode->i_gid = h_inode->i_gid;
4121 + au_cpup_attr_timesizes(inode);
4122 + au_cpup_attr_flags(inode, h_inode->i_flags);
4125 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4127 + struct au_iinfo *iinfo = au_ii(inode);
4129 + IiMustWriteLock(inode);
4131 + iinfo->ii_higen = h_inode->i_generation;
4132 + iinfo->ii_hsb1 = h_inode->i_sb;
4135 +void au_cpup_attr_all(struct inode *inode, int force)
4137 + struct inode *h_inode;
4139 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4140 + au_cpup_attr_changeable(inode);
4141 + if (inode->i_nlink > 0)
4142 + au_cpup_attr_nlink(inode, force);
4143 + inode->i_rdev = h_inode->i_rdev;
4144 + inode->i_blkbits = h_inode->i_blkbits;
4145 + au_cpup_igen(inode, h_inode);
4148 +/* ---------------------------------------------------------------------- */
4150 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4152 +/* keep the timestamps of the parent dir when cpup */
4153 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4154 + struct path *h_path)
4156 + struct inode *h_inode;
4158 + dt->dt_dentry = dentry;
4159 + dt->dt_h_path = *h_path;
4160 + h_inode = d_inode(h_path->dentry);
4161 + dt->dt_atime = h_inode->i_atime;
4162 + dt->dt_mtime = h_inode->i_mtime;
4166 +void au_dtime_revert(struct au_dtime *dt)
4168 + struct iattr attr;
4171 + attr.ia_atime = dt->dt_atime;
4172 + attr.ia_mtime = dt->dt_mtime;
4173 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4174 + | ATTR_ATIME | ATTR_ATIME_SET;
4176 + /* no delegation since this is a directory */
4177 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4178 + if (unlikely(err))
4179 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4182 +/* ---------------------------------------------------------------------- */
4184 +/* internal use only */
4185 +struct au_cpup_reg_attr {
4188 + unsigned int iflags; /* inode->i_flags */
4191 +static noinline_for_stack
4192 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4193 + struct au_cpup_reg_attr *h_src_attr)
4195 + int err, sbits, icex;
4196 + unsigned int mnt_flags;
4197 + unsigned char verbose;
4199 + struct path h_path;
4200 + struct inode *h_isrc, *h_idst;
4201 + struct kstat *h_st;
4202 + struct au_branch *br;
4204 + h_path.dentry = au_h_dptr(dst, bindex);
4205 + h_idst = d_inode(h_path.dentry);
4206 + br = au_sbr(dst->d_sb, bindex);
4207 + h_path.mnt = au_br_mnt(br);
4208 + h_isrc = d_inode(h_src);
4209 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4210 + | ATTR_ATIME | ATTR_MTIME
4211 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4212 + if (h_src_attr && h_src_attr->valid) {
4213 + h_st = &h_src_attr->st;
4214 + ia.ia_uid = h_st->uid;
4215 + ia.ia_gid = h_st->gid;
4216 + ia.ia_atime = h_st->atime;
4217 + ia.ia_mtime = h_st->mtime;
4218 + if (h_idst->i_mode != h_st->mode
4219 + && !S_ISLNK(h_idst->i_mode)) {
4220 + ia.ia_valid |= ATTR_MODE;
4221 + ia.ia_mode = h_st->mode;
4223 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4224 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4226 + ia.ia_uid = h_isrc->i_uid;
4227 + ia.ia_gid = h_isrc->i_gid;
4228 + ia.ia_atime = h_isrc->i_atime;
4229 + ia.ia_mtime = h_isrc->i_mtime;
4230 + if (h_idst->i_mode != h_isrc->i_mode
4231 + && !S_ISLNK(h_idst->i_mode)) {
4232 + ia.ia_valid |= ATTR_MODE;
4233 + ia.ia_mode = h_isrc->i_mode;
4235 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4236 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4238 + /* no delegation since it is just created */
4239 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4241 + /* is this nfs only? */
4242 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4243 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4244 + ia.ia_mode = h_isrc->i_mode;
4245 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4248 + icex = br->br_perm & AuBrAttr_ICEX;
4250 + mnt_flags = au_mntflags(dst->d_sb);
4251 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4252 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4258 +/* ---------------------------------------------------------------------- */
4260 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4261 + char *buf, unsigned long blksize)
4264 + size_t sz, rbytes, wbytes;
4265 + unsigned char all_zero;
4267 + struct mutex *h_mtx;
4268 + /* reduce stack usage */
4271 + zp = page_address(ZERO_PAGE(0));
4272 + if (unlikely(!zp))
4273 + return -ENOMEM; /* possible? */
4278 + AuDbg("len %lld\n", len);
4280 + if (len < blksize)
4284 + /* todo: signal_pending? */
4285 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4286 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4289 + if (unlikely(err < 0))
4293 + if (len >= rbytes && rbytes == blksize)
4294 + all_zero = !memcmp(buf, zp, rbytes);
4301 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4303 + /* todo: signal_pending? */
4304 + if (unlikely(err == -EAGAIN || err == -EINTR))
4306 + if (unlikely(err < 0))
4311 + if (unlikely(err < 0))
4317 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4319 + if (unlikely(res < 0))
4326 + /* the last block may be a hole */
4327 + if (!err && all_zero) {
4328 + AuLabel(last hole);
4331 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4332 + /* nfs requires this step to make last hole */
4333 + /* is this only nfs? */
4335 + /* todo: signal_pending? */
4336 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4337 + } while (err == -EAGAIN || err == -EINTR);
4344 + ia->ia_size = dst->f_pos;
4345 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4346 + ia->ia_file = dst;
4347 + h_mtx = &file_inode(dst)->i_mutex;
4348 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4349 + /* no delegation since it is just created */
4350 + err = vfsub_notify_change(&dst->f_path, ia,
4351 + /*delegated*/NULL);
4352 + mutex_unlock(h_mtx);
4359 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4362 + unsigned long blksize;
4363 + unsigned char do_kfree;
4367 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4368 + if (!blksize || PAGE_SIZE < blksize)
4369 + blksize = PAGE_SIZE;
4370 + AuDbg("blksize %lu\n", blksize);
4371 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4373 + buf = kmalloc(blksize, GFP_NOFS);
4375 + buf = (void *)__get_free_page(GFP_NOFS);
4376 + if (unlikely(!buf))
4379 + if (len > (1 << 22))
4380 + AuDbg("copying a large file %lld\n", (long long)len);
4384 + err = au_do_copy_file(dst, src, len, buf, blksize);
4388 + free_page((unsigned long)buf);
4395 + * to support a sparse file which is opened with O_APPEND,
4396 + * we need to close the file.
4398 +static int au_cp_regular(struct au_cp_generic *cpg)
4401 + enum { SRC, DST };
4403 + aufs_bindex_t bindex;
4404 + unsigned int flags;
4405 + struct dentry *dentry;
4407 + struct file *file;
4411 + .bindex = cpg->bsrc,
4412 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4416 + .bindex = cpg->bdst,
4417 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4418 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4419 + .label = &&out_src
4422 + struct super_block *sb;
4423 + struct task_struct *tsk = current;
4425 + /* bsrc branch can be ro/rw. */
4426 + sb = cpg->dentry->d_sb;
4428 + for (i = 0; i < 2; i++, f++) {
4429 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4430 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4431 + /*file*/NULL, f->force_wr);
4432 + err = PTR_ERR(f->file);
4433 + if (IS_ERR(f->file))
4437 + /* try stopping to update while we copyup */
4438 + IMustLock(d_inode(file[SRC].dentry));
4439 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4441 + /* i wonder if we had O_NO_DELAY_FPUT flag */
4442 + if (tsk->flags & PF_KTHREAD)
4443 + __fput_sync(file[DST].file);
4445 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
4447 + fput(file[DST].file);
4450 + * we have to call both since we don't know which place the file
4454 + flush_delayed_fput();
4456 + au_sbr_put(sb, file[DST].bindex);
4459 + fput(file[SRC].file);
4460 + au_sbr_put(sb, file[SRC].bindex);
4465 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4466 + struct au_cpup_reg_attr *h_src_attr)
4470 + struct path h_path;
4471 + struct inode *h_src_inode, *h_dst_inode;
4474 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
4475 + l = i_size_read(h_src_inode);
4476 + if (cpg->len == -1 || l < cpg->len)
4479 + /* try stopping to update while we are referencing */
4480 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4481 + au_pin_hdir_unlock(cpg->pin);
4483 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4484 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4485 + h_src_attr->iflags = h_src_inode->i_flags;
4486 + if (!au_test_nfs(h_src_inode->i_sb))
4487 + err = vfs_getattr(&h_path, &h_src_attr->st);
4489 + mutex_unlock(&h_src_inode->i_mutex);
4490 + err = vfs_getattr(&h_path, &h_src_attr->st);
4491 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4493 + if (unlikely(err)) {
4494 + mutex_unlock(&h_src_inode->i_mutex);
4497 + h_src_attr->valid = 1;
4498 + err = au_cp_regular(cpg);
4499 + mutex_unlock(&h_src_inode->i_mutex);
4500 + rerr = au_pin_hdir_relock(cpg->pin);
4504 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4505 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4506 + h_dst_inode = d_inode(h_path.dentry);
4507 + spin_lock(&h_dst_inode->i_lock);
4508 + h_dst_inode->i_state |= I_LINKABLE;
4509 + spin_unlock(&h_dst_inode->i_lock);
4516 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4517 + struct inode *h_dir)
4520 + mm_segment_t old_fs;
4525 + struct inode *h_inode = d_inode(h_src);
4526 + const struct inode_operations *h_iop = h_inode->i_op;
4529 + if (unlikely(!h_iop->readlink))
4533 + sym.k = (void *)__get_free_page(GFP_NOFS);
4534 + if (unlikely(!sym.k))
4537 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4538 + old_fs = get_fs();
4539 + set_fs(KERNEL_DS);
4540 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
4545 + sym.k[symlen] = 0;
4546 + err = vfsub_symlink(h_dir, h_path, sym.k);
4548 + free_page((unsigned long)sym.k);
4555 + * regardless 'acl' option, reset all ACL.
4556 + * All ACL will be copied up later from the original entry on the lower branch.
4558 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
4561 + struct dentry *h_dentry;
4562 + struct inode *h_inode;
4564 + h_dentry = h_path->dentry;
4565 + h_inode = d_inode(h_dentry);
4566 + /* forget_all_cached_acls(h_inode)); */
4567 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
4569 + if (err == -EOPNOTSUPP)
4572 + err = vfsub_acl_chmod(h_inode, mode);
4578 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
4579 + struct inode *h_dir, struct path *h_path)
4582 + struct inode *dir, *inode;
4584 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
4586 + if (err == -EOPNOTSUPP)
4588 + if (unlikely(err))
4592 + * strange behaviour from the users view,
4593 + * particularry setattr case
4595 + dir = d_inode(dst_parent);
4596 + if (au_ibstart(dir) == cpg->bdst)
4597 + au_cpup_attr_nlink(dir, /*force*/1);
4598 + inode = d_inode(cpg->dentry);
4599 + au_cpup_attr_nlink(inode, /*force*/1);
4605 +static noinline_for_stack
4606 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
4607 + struct au_cpup_reg_attr *h_src_attr)
4611 + unsigned int mnt_flags;
4612 + unsigned char isdir, isreg, force;
4613 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
4614 + struct au_dtime dt;
4615 + struct path h_path;
4616 + struct dentry *h_src, *h_dst, *h_parent;
4617 + struct inode *h_inode, *h_dir;
4618 + struct super_block *sb;
4620 + /* bsrc branch can be ro/rw. */
4621 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4622 + h_inode = d_inode(h_src);
4623 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
4625 + /* try stopping to be referenced while we are creating */
4626 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4627 + if (au_ftest_cpup(cpg->flags, RENAME))
4628 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
4629 + AUFS_WH_PFX_LEN));
4630 + h_parent = h_dst->d_parent; /* dir inode is locked */
4631 + h_dir = d_inode(h_parent);
4633 + AuDebugOn(h_parent != h_dst->d_parent);
4635 + sb = cpg->dentry->d_sb;
4636 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4638 + h_path.dentry = h_parent;
4639 + au_dtime_store(&dt, dst_parent, &h_path);
4641 + h_path.dentry = h_dst;
4645 + mode = h_inode->i_mode;
4646 + switch (mode & S_IFMT) {
4649 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
4650 + /*want_excl*/true);
4652 + err = au_do_cpup_regular(cpg, h_src_attr);
4656 + err = vfsub_mkdir(h_dir, &h_path, mode);
4658 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
4661 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4665 + AuDebugOn(!capable(CAP_MKNOD));
4669 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4672 + AuIOErr("Unknown inode type 0%o\n", mode);
4676 + err = au_reset_acl(h_dir, &h_path, mode);
4678 + mnt_flags = au_mntflags(sb);
4679 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4681 + && au_opt_test(mnt_flags, XINO)
4682 + && (h_inode->i_nlink == 1
4683 + || (h_inode->i_state & I_LINKABLE))
4684 + /* todo: unnecessary? */
4685 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
4686 + && cpg->bdst < cpg->bsrc
4687 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4688 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4689 + /* ignore this error */
4694 + force = !!cpg->len;
4695 + if (cpg->len == -1)
4696 + force = !!i_size_read(h_inode);
4698 + au_fhsm_wrote(sb, cpg->bdst, force);
4702 + au_dtime_revert(&dt);
4706 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4709 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4710 + struct inode *h_dir;
4711 + aufs_bindex_t bdst;
4713 + dentry = cpg->dentry;
4715 + h_dentry = au_h_dptr(dentry, bdst);
4716 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
4718 + au_set_h_dptr(dentry, bdst, NULL);
4719 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4721 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4722 + au_set_h_dptr(dentry, bdst, h_dentry);
4725 + parent = dget_parent(dentry);
4726 + h_parent = au_h_dptr(parent, bdst);
4728 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
4729 + if (IS_ERR(h_path->dentry))
4730 + err = PTR_ERR(h_path->dentry);
4732 + if (unlikely(err))
4735 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4736 + h_dir = d_inode(h_parent);
4738 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
4739 + /* no delegation since it is just created */
4740 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
4741 + dput(h_path->dentry);
4748 + * copyup the @dentry from @bsrc to @bdst.
4749 + * the caller must set the both of lower dentries.
4750 + * @len is for truncating when it is -1 copyup the entire file.
4751 + * in link/rename cases, @dst_parent may be different from the real one.
4752 + * basic->bsrc can be larger than basic->bdst.
4754 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4757 + aufs_bindex_t old_ibstart;
4758 + unsigned char isdir, plink;
4759 + struct dentry *h_src, *h_dst, *h_parent;
4760 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
4761 + struct super_block *sb;
4762 + struct au_branch *br;
4763 + /* to reuduce stack size */
4765 + struct au_dtime dt;
4766 + struct path h_path;
4767 + struct au_cpup_reg_attr h_src_attr;
4771 + a = kmalloc(sizeof(*a), GFP_NOFS);
4774 + a->h_src_attr.valid = 0;
4776 + sb = cpg->dentry->d_sb;
4777 + br = au_sbr(sb, cpg->bdst);
4778 + a->h_path.mnt = au_br_mnt(br);
4779 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4780 + h_parent = h_dst->d_parent; /* dir inode is locked */
4781 + h_dir = d_inode(h_parent);
4784 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4785 + inode = d_inode(cpg->dentry);
4788 + dst_parent = dget_parent(cpg->dentry);
4792 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4793 + dst_inode = au_h_iptr(inode, cpg->bdst);
4795 + if (unlikely(!plink)) {
4797 + AuIOErr("hi%lu(i%lu) exists on b%d "
4798 + "but plink is disabled\n",
4799 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4803 + if (dst_inode->i_nlink) {
4804 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4806 + h_src = au_plink_lkup(inode, cpg->bdst);
4807 + err = PTR_ERR(h_src);
4808 + if (IS_ERR(h_src))
4810 + if (unlikely(d_is_negative(h_src))) {
4812 + AuIOErr("i%lu exists on b%d "
4813 + "but not pseudo-linked\n",
4814 + inode->i_ino, cpg->bdst);
4820 + a->h_path.dentry = h_parent;
4821 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4824 + a->h_path.dentry = h_dst;
4826 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
4827 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4828 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4830 + au_dtime_revert(&a->dt);
4831 + if (unlikely(err == -EWOULDBLOCK)) {
4832 + pr_warn("cannot retry for NFSv4 delegation"
4833 + " for an internal link\n");
4839 + /* todo: cpup_wh_file? */
4841 + au_update_ibrange(inode, /*do_put_zero*/1);
4844 + isdir = S_ISDIR(inode->i_mode);
4845 + old_ibstart = au_ibstart(inode);
4846 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4847 + if (unlikely(err))
4849 + dst_inode = d_inode(h_dst);
4850 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
4851 + /* todo: necessary? */
4852 + /* au_pin_hdir_unlock(cpg->pin); */
4854 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
4855 + if (unlikely(err)) {
4856 + /* todo: necessary? */
4857 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
4858 + mutex_unlock(&dst_inode->i_mutex);
4862 + if (cpg->bdst < old_ibstart) {
4863 + if (S_ISREG(inode->i_mode)) {
4864 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
4865 + if (unlikely(err)) {
4866 + /* ignore an error */
4867 + /* au_pin_hdir_relock(cpg->pin); */
4868 + mutex_unlock(&dst_inode->i_mutex);
4872 + au_set_ibstart(inode, cpg->bdst);
4874 + au_set_ibend(inode, cpg->bdst);
4875 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
4876 + au_hi_flags(inode, isdir));
4878 + /* todo: necessary? */
4879 + /* err = au_pin_hdir_relock(cpg->pin); */
4880 + mutex_unlock(&dst_inode->i_mutex);
4881 + if (unlikely(err))
4884 + src_inode = d_inode(h_src);
4886 + && (src_inode->i_nlink > 1
4887 + || src_inode->i_state & I_LINKABLE)
4889 + au_plink_append(inode, cpg->bdst, h_dst);
4891 + if (au_ftest_cpup(cpg->flags, RENAME)) {
4892 + a->h_path.dentry = h_dst;
4893 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4896 + goto out_parent; /* success */
4900 + a->h_path.dentry = h_parent;
4901 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4902 + a->h_path.dentry = h_dst;
4904 + if (d_is_positive(h_dst)) {
4906 + /* no delegation since it is just created */
4907 + rerr = vfsub_unlink(h_dir, &a->h_path,
4908 + /*delegated*/NULL, /*force*/0);
4910 + rerr = vfsub_rmdir(h_dir, &a->h_path);
4912 + au_dtime_revert(&a->dt);
4914 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
4924 +#if 0 /* reserved */
4925 +struct au_cpup_single_args {
4927 + struct au_cp_generic *cpg;
4928 + struct dentry *dst_parent;
4931 +static void au_call_cpup_single(void *args)
4933 + struct au_cpup_single_args *a = args;
4935 + au_pin_hdir_acquire_nest(a->cpg->pin);
4936 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
4937 + au_pin_hdir_release(a->cpg->pin);
4942 + * prevent SIGXFSZ in copy-up.
4943 + * testing CAP_MKNOD is for generic fs,
4944 + * but CAP_FSETID is for xfs only, currently.
4946 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
4949 + struct super_block *sb;
4950 + struct inode *h_dir;
4953 + sb = au_pinned_parent(pin)->d_sb;
4954 + if (!au_wkq_test()
4955 + && (!au_sbi(sb)->si_plink_maint_pid
4956 + || au_plink_maint(sb, AuLock_NOPLM))) {
4957 + switch (mode & S_IFMT) {
4959 + /* no condition about RLIMIT_FSIZE and the file size */
4964 + do_sio = !capable(CAP_MKNOD);
4968 + do_sio = ((mode & (S_ISUID | S_ISGID))
4969 + && !capable(CAP_FSETID));
4970 + /* this workaround may be removed in the future */
4972 + h_dir = au_pinned_h_dir(pin);
4973 + do_sio = h_dir->i_mode & S_ISVTX;
4980 +#if 0 /* reserved */
4981 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4984 + struct dentry *h_dentry;
4986 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4987 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
4988 + err = au_cpup_single(cpg, dst_parent);
4990 + struct au_cpup_single_args args = {
4993 + .dst_parent = dst_parent
4995 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
4996 + if (unlikely(wkq_err))
5005 + * copyup the @dentry from the first active lower branch to @bdst,
5006 + * using au_cpup_single().
5008 +static int au_cpup_simple(struct au_cp_generic *cpg)
5011 + unsigned int flags_orig;
5012 + struct dentry *dentry;
5014 + AuDebugOn(cpg->bsrc < 0);
5016 + dentry = cpg->dentry;
5017 + DiMustWriteLock(dentry);
5019 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5021 + flags_orig = cpg->flags;
5022 + au_fset_cpup(cpg->flags, RENAME);
5023 + err = au_cpup_single(cpg, NULL);
5024 + cpg->flags = flags_orig;
5026 + return 0; /* success */
5029 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5030 + au_set_dbstart(dentry, cpg->bsrc);
5036 +struct au_cpup_simple_args {
5038 + struct au_cp_generic *cpg;
5041 +static void au_call_cpup_simple(void *args)
5043 + struct au_cpup_simple_args *a = args;
5045 + au_pin_hdir_acquire_nest(a->cpg->pin);
5046 + *a->errp = au_cpup_simple(a->cpg);
5047 + au_pin_hdir_release(a->cpg->pin);
5050 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5053 + struct dentry *dentry, *parent;
5054 + struct file *h_file;
5055 + struct inode *h_dir;
5057 + dentry = cpg->dentry;
5059 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5060 + AuDebugOn(cpg->bsrc < 0);
5061 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5062 + err = PTR_ERR(h_file);
5063 + if (IS_ERR(h_file))
5067 + parent = dget_parent(dentry);
5068 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5069 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5070 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5071 + err = au_cpup_simple(cpg);
5073 + struct au_cpup_simple_args args = {
5077 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5078 + if (unlikely(wkq_err))
5084 + au_h_open_post(dentry, cpg->bsrc, h_file);
5090 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5092 + aufs_bindex_t bsrc, bend;
5093 + struct dentry *dentry, *h_dentry;
5095 + if (cpg->bsrc < 0) {
5096 + dentry = cpg->dentry;
5097 + bend = au_dbend(dentry);
5098 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5099 + h_dentry = au_h_dptr(dentry, bsrc);
5101 + AuDebugOn(d_is_negative(h_dentry));
5105 + AuDebugOn(bsrc > bend);
5108 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5109 + return au_do_sio_cpup_simple(cpg);
5112 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5114 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5115 + return au_do_sio_cpup_simple(cpg);
5118 +/* ---------------------------------------------------------------------- */
5121 + * copyup the deleted file for writing.
5123 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5124 + struct file *file)
5127 + unsigned int flags_orig;
5128 + aufs_bindex_t bsrc_orig;
5129 + struct dentry *h_d_dst, *h_d_start;
5130 + struct au_dinfo *dinfo;
5131 + struct au_hdentry *hdp;
5133 + dinfo = au_di(cpg->dentry);
5134 + AuRwMustWriteLock(&dinfo->di_rwsem);
5136 + bsrc_orig = cpg->bsrc;
5137 + cpg->bsrc = dinfo->di_bstart;
5138 + hdp = dinfo->di_hdentry;
5139 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5140 + dinfo->di_bstart = cpg->bdst;
5141 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5144 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5145 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry;
5147 + flags_orig = cpg->flags;
5148 + cpg->flags = !AuCpup_DTIME;
5149 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5150 + cpg->flags = flags_orig;
5153 + err = au_reopen_nondir(file);
5154 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5156 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5157 + dinfo->di_bstart = cpg->bsrc;
5158 + cpg->bsrc = bsrc_orig;
5163 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5166 + aufs_bindex_t bdst;
5167 + struct au_dtime dt;
5168 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5169 + struct au_branch *br;
5170 + struct path h_path;
5172 + dentry = cpg->dentry;
5174 + br = au_sbr(dentry->d_sb, bdst);
5175 + parent = dget_parent(dentry);
5176 + h_parent = au_h_dptr(parent, bdst);
5177 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5178 + err = PTR_ERR(wh_dentry);
5179 + if (IS_ERR(wh_dentry))
5182 + h_path.dentry = h_parent;
5183 + h_path.mnt = au_br_mnt(br);
5184 + au_dtime_store(&dt, parent, &h_path);
5185 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5186 + if (unlikely(err))
5190 + h_path.dentry = wh_dentry;
5191 + if (!d_is_dir(wh_dentry)) {
5192 + /* no delegation since it is just created */
5193 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5194 + /*delegated*/NULL, /*force*/0);
5196 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5197 + if (unlikely(err)) {
5198 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5202 + au_dtime_revert(&dt);
5203 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5212 +struct au_cpup_wh_args {
5214 + struct au_cp_generic *cpg;
5215 + struct file *file;
5218 +static void au_call_cpup_wh(void *args)
5220 + struct au_cpup_wh_args *a = args;
5222 + au_pin_hdir_acquire_nest(a->cpg->pin);
5223 + *a->errp = au_cpup_wh(a->cpg, a->file);
5224 + au_pin_hdir_release(a->cpg->pin);
5227 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5230 + aufs_bindex_t bdst;
5231 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5232 + struct inode *dir, *h_dir, *h_tmpdir;
5233 + struct au_wbr *wbr;
5234 + struct au_pin wh_pin, *pin_orig;
5236 + dentry = cpg->dentry;
5238 + parent = dget_parent(dentry);
5239 + dir = d_inode(parent);
5242 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5245 + if (!h_dir->i_nlink) {
5246 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5247 + h_orph = wbr->wbr_orph;
5249 + h_parent = dget(au_h_dptr(parent, bdst));
5250 + au_set_h_dptr(parent, bdst, dget(h_orph));
5251 + h_tmpdir = d_inode(h_orph);
5252 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5254 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5255 + /* todo: au_h_open_pre()? */
5257 + pin_orig = cpg->pin;
5258 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5259 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5260 + cpg->pin = &wh_pin;
5263 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5264 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5265 + err = au_cpup_wh(cpg, file);
5267 + struct au_cpup_wh_args args = {
5272 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5273 + if (unlikely(wkq_err))
5278 + mutex_unlock(&h_tmpdir->i_mutex);
5279 + /* todo: au_h_open_post()? */
5280 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5281 + au_set_h_dptr(parent, bdst, h_parent);
5282 + AuDebugOn(!pin_orig);
5283 + cpg->pin = pin_orig;
5291 +/* ---------------------------------------------------------------------- */
5294 + * generic routine for both of copy-up and copy-down.
5296 +/* cf. revalidate function in file.c */
5297 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5298 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5299 + struct au_pin *pin,
5300 + struct dentry *h_parent, void *arg),
5304 + struct au_pin pin;
5305 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5308 + parent = dget_parent(dentry);
5309 + if (IS_ROOT(parent))
5312 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5313 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5315 + /* do not use au_dpage */
5316 + real_parent = parent;
5319 + parent = dget_parent(dentry);
5320 + h_parent = au_h_dptr(parent, bdst);
5322 + goto out; /* success */
5324 + /* find top dir which is necessary to cpup */
5328 + parent = dget_parent(d);
5329 + di_read_lock_parent3(parent, !AuLock_IR);
5330 + h_parent = au_h_dptr(parent, bdst);
5331 + di_read_unlock(parent, !AuLock_IR);
5332 + } while (!h_parent);
5334 + if (d != real_parent)
5335 + di_write_lock_child3(d);
5337 + /* somebody else might create while we were sleeping */
5338 + h_dentry = au_h_dptr(d, bdst);
5339 + if (!h_dentry || d_is_negative(h_dentry)) {
5341 + au_update_dbstart(d);
5343 + au_pin_set_dentry(&pin, d);
5344 + err = au_do_pin(&pin);
5346 + err = cp(d, bdst, &pin, h_parent, arg);
5351 + if (d != real_parent)
5352 + di_write_unlock(d);
5353 + if (unlikely(err))
5362 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5363 + struct au_pin *pin,
5364 + struct dentry *h_parent __maybe_unused,
5365 + void *arg __maybe_unused)
5367 + struct au_cp_generic cpg = {
5373 + .flags = AuCpup_DTIME
5375 + return au_sio_cpup_simple(&cpg);
5378 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5380 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5383 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5386 + struct dentry *parent;
5387 + struct inode *dir;
5389 + parent = dget_parent(dentry);
5390 + dir = d_inode(parent);
5392 + if (au_h_iptr(dir, bdst))
5395 + di_read_unlock(parent, AuLock_IR);
5396 + di_write_lock_parent(parent);
5397 + /* someone else might change our inode while we were sleeping */
5398 + if (!au_h_iptr(dir, bdst))
5399 + err = au_cpup_dirs(dentry, bdst);
5400 + di_downgrade_lock(parent, AuLock_IR);
5406 diff -urNp -x '*.orig' linux-4.4/fs/aufs/cpup.h linux-4.4/fs/aufs/cpup.h
5407 --- linux-4.4/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5408 +++ linux-4.4/fs/aufs/cpup.h 2021-02-24 17:28:14.398807954 +0100
5411 + * Copyright (C) 2005-2016 Junjiro R. Okajima
5413 + * This program, aufs is free software; you can redistribute it and/or modify
5414 + * it under the terms of the GNU General Public License as published by
5415 + * the Free Software Foundation; either version 2 of the License, or
5416 + * (at your option) any later version.
5418 + * This program is distributed in the hope that it will be useful,
5419 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5420 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5421 + * GNU General Public License for more details.
5423 + * You should have received a copy of the GNU General Public License
5424 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5428 + * copy-up/down functions
5431 +#ifndef __AUFS_CPUP_H__
5432 +#define __AUFS_CPUP_H__
5436 +#include <linux/path.h>
5442 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5443 +void au_cpup_attr_timesizes(struct inode *inode);
5444 +void au_cpup_attr_nlink(struct inode *inode, int force);
5445 +void au_cpup_attr_changeable(struct inode *inode);
5446 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5447 +void au_cpup_attr_all(struct inode *inode, int force);
5449 +/* ---------------------------------------------------------------------- */
5451 +struct au_cp_generic {
5452 + struct dentry *dentry;
5453 + aufs_bindex_t bdst, bsrc;
5455 + struct au_pin *pin;
5456 + unsigned int flags;
5460 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5461 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5463 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5464 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5466 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5468 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5469 + the branch is marked as RO */
5471 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5472 +#define au_fset_cpup(flags, name) \
5473 + do { (flags) |= AuCpup_##name; } while (0)
5474 +#define au_fclr_cpup(flags, name) \
5475 + do { (flags) &= ~AuCpup_##name; } while (0)
5477 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5478 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5479 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5480 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5482 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5483 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5484 + struct au_pin *pin,
5485 + struct dentry *h_parent, void *arg),
5487 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5488 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5490 +/* ---------------------------------------------------------------------- */
5492 +/* keep timestamps when copyup */
5494 + struct dentry *dt_dentry;
5495 + struct path dt_h_path;
5496 + struct timespec dt_atime, dt_mtime;
5498 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5499 + struct path *h_path);
5500 +void au_dtime_revert(struct au_dtime *dt);
5502 +#endif /* __KERNEL__ */
5503 +#endif /* __AUFS_CPUP_H__ */
5504 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dbgaufs.c linux-4.4/fs/aufs/dbgaufs.c
5505 --- linux-4.4/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5506 +++ linux-4.4/fs/aufs/dbgaufs.c 2021-02-24 17:28:14.398807954 +0100
5509 + * Copyright (C) 2005-2016 Junjiro R. Okajima
5511 + * This program, aufs is free software; you can redistribute it and/or modify
5512 + * it under the terms of the GNU General Public License as published by
5513 + * the Free Software Foundation; either version 2 of the License, or
5514 + * (at your option) any later version.
5516 + * This program is distributed in the hope that it will be useful,
5517 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5518 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5519 + * GNU General Public License for more details.
5521 + * You should have received a copy of the GNU General Public License
5522 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5526 + * debugfs interface
5529 +#include <linux/debugfs.h>
5532 +#ifndef CONFIG_SYSFS
5533 +#error DEBUG_FS depends upon SYSFS
5536 +static struct dentry *dbgaufs;
5537 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5539 +/* 20 is max digits length of ulong 64 */
5540 +struct dbgaufs_arg {
5546 + * common function for all XINO files
5548 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5549 + struct file *file)
5551 + kfree(file->private_data);
5555 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5559 + struct dbgaufs_arg *p;
5562 + p = kmalloc(sizeof(*p), GFP_NOFS);
5568 + file->private_data = p;
5572 + err = vfs_getattr(&xf->f_path, &st);
5576 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5577 + (long)file_count(xf), st.blocks, st.blksize,
5578 + (long long)st.size);
5580 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5581 + st.blocks, st.blksize,
5582 + (long long)st.size);
5583 + AuDebugOn(p->n >= sizeof(p->a));
5585 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5594 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5595 + size_t count, loff_t *ppos)
5597 + struct dbgaufs_arg *p;
5599 + p = file->private_data;
5600 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5603 +/* ---------------------------------------------------------------------- */
5605 +struct dbgaufs_plink_arg {
5610 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
5611 + struct file *file)
5613 + free_page((unsigned long)file->private_data);
5617 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
5619 + int err, i, limit;
5620 + unsigned long n, sum;
5621 + struct dbgaufs_plink_arg *p;
5622 + struct au_sbinfo *sbinfo;
5623 + struct super_block *sb;
5624 + struct au_sphlhead *sphl;
5627 + p = (void *)get_zeroed_page(GFP_NOFS);
5632 + sbinfo = inode->i_private;
5633 + sb = sbinfo->si_sb;
5634 + si_noflush_read_lock(sb);
5635 + if (au_opt_test(au_mntflags(sb), PLINK)) {
5636 + limit = PAGE_SIZE - sizeof(p->n);
5638 + /* the number of buckets */
5639 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
5644 + for (i = 0, sphl = sbinfo->si_plink;
5645 + i < AuPlink_NHASH;
5647 + n = au_sphl_count(sphl);
5650 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5653 + if (unlikely(limit <= 0))
5656 + p->a[p->n - 1] = '\n';
5658 + /* the sum of plinks */
5659 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5662 + if (unlikely(limit <= 0))
5665 +#define str "1\n0\n0\n"
5666 + p->n = sizeof(str) - 1;
5667 + strcpy(p->a, str);
5670 + si_read_unlock(sb);
5673 + file->private_data = p;
5674 + goto out; /* success */
5677 + free_page((unsigned long)p);
5682 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5683 + size_t count, loff_t *ppos)
5685 + struct dbgaufs_plink_arg *p;
5687 + p = file->private_data;
5688 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5691 +static const struct file_operations dbgaufs_plink_fop = {
5692 + .owner = THIS_MODULE,
5693 + .open = dbgaufs_plink_open,
5694 + .release = dbgaufs_plink_release,
5695 + .read = dbgaufs_plink_read
5698 +/* ---------------------------------------------------------------------- */
5700 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5703 + struct au_sbinfo *sbinfo;
5704 + struct super_block *sb;
5706 + sbinfo = inode->i_private;
5707 + sb = sbinfo->si_sb;
5708 + si_noflush_read_lock(sb);
5709 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5710 + si_read_unlock(sb);
5714 +static const struct file_operations dbgaufs_xib_fop = {
5715 + .owner = THIS_MODULE,
5716 + .open = dbgaufs_xib_open,
5717 + .release = dbgaufs_xi_release,
5718 + .read = dbgaufs_xi_read
5721 +/* ---------------------------------------------------------------------- */
5723 +#define DbgaufsXi_PREFIX "xi"
5725 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5729 + struct au_sbinfo *sbinfo;
5730 + struct super_block *sb;
5732 + struct qstr *name;
5736 + name = &file->f_path.dentry->d_name;
5737 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5738 + || memcmp(name->name, DbgaufsXi_PREFIX,
5739 + sizeof(DbgaufsXi_PREFIX) - 1)))
5741 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5742 + if (unlikely(err))
5745 + sbinfo = inode->i_private;
5746 + sb = sbinfo->si_sb;
5747 + si_noflush_read_lock(sb);
5748 + if (l <= au_sbend(sb)) {
5749 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5750 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5753 + si_read_unlock(sb);
5759 +static const struct file_operations dbgaufs_xino_fop = {
5760 + .owner = THIS_MODULE,
5761 + .open = dbgaufs_xino_open,
5762 + .release = dbgaufs_xi_release,
5763 + .read = dbgaufs_xi_read
5766 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5768 + aufs_bindex_t bend;
5769 + struct au_branch *br;
5770 + struct au_xino_file *xi;
5772 + if (!au_sbi(sb)->si_dbgaufs)
5775 + bend = au_sbend(sb);
5776 + for (; bindex <= bend; bindex++) {
5777 + br = au_sbr(sb, bindex);
5778 + xi = &br->br_xino;
5779 + debugfs_remove(xi->xi_dbgaufs);
5780 + xi->xi_dbgaufs = NULL;
5784 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5786 + struct au_sbinfo *sbinfo;
5787 + struct dentry *parent;
5788 + struct au_branch *br;
5789 + struct au_xino_file *xi;
5790 + aufs_bindex_t bend;
5791 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5793 + sbinfo = au_sbi(sb);
5794 + parent = sbinfo->si_dbgaufs;
5798 + bend = au_sbend(sb);
5799 + for (; bindex <= bend; bindex++) {
5800 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5801 + br = au_sbr(sb, bindex);
5802 + xi = &br->br_xino;
5803 + AuDebugOn(xi->xi_dbgaufs);
5804 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5805 + sbinfo, &dbgaufs_xino_fop);
5806 + /* ignore an error */
5807 + if (unlikely(!xi->xi_dbgaufs))
5808 + AuWarn1("failed %s under debugfs\n", name);
5812 +/* ---------------------------------------------------------------------- */
5814 +#ifdef CONFIG_AUFS_EXPORT
5815 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5818 + struct au_sbinfo *sbinfo;
5819 + struct super_block *sb;
5821 + sbinfo = inode->i_private;
5822 + sb = sbinfo->si_sb;
5823 + si_noflush_read_lock(sb);
5824 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5825 + si_read_unlock(sb);
5829 +static const struct file_operations dbgaufs_xigen_fop = {
5830 + .owner = THIS_MODULE,
5831 + .open = dbgaufs_xigen_open,
5832 + .release = dbgaufs_xi_release,
5833 + .read = dbgaufs_xi_read
5836 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5841 + * This function is a dynamic '__init' function actually,
5842 + * so the tiny check for si_rwsem is unnecessary.
5844 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5847 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
5848 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5849 + &dbgaufs_xigen_fop);
5850 + if (sbinfo->si_dbgaufs_xigen)
5856 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5860 +#endif /* CONFIG_AUFS_EXPORT */
5862 +/* ---------------------------------------------------------------------- */
5864 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
5867 + * This function is a dynamic '__fin' function actually,
5868 + * so the tiny check for si_rwsem is unnecessary.
5870 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5872 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
5873 + sbinfo->si_dbgaufs = NULL;
5874 + kobject_put(&sbinfo->si_kobj);
5877 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
5880 + char name[SysaufsSiNameLen];
5883 + * This function is a dynamic '__init' function actually,
5884 + * so the tiny check for si_rwsem is unnecessary.
5886 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5890 + AuErr1("/debug/aufs is uninitialized\n");
5895 + sysaufs_name(sbinfo, name);
5896 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
5897 + if (unlikely(!sbinfo->si_dbgaufs))
5899 + kobject_get(&sbinfo->si_kobj);
5901 + sbinfo->si_dbgaufs_xib = debugfs_create_file
5902 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5903 + &dbgaufs_xib_fop);
5904 + if (unlikely(!sbinfo->si_dbgaufs_xib))
5907 + sbinfo->si_dbgaufs_plink = debugfs_create_file
5908 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
5909 + &dbgaufs_plink_fop);
5910 + if (unlikely(!sbinfo->si_dbgaufs_plink))
5913 + err = dbgaufs_xigen_init(sbinfo);
5915 + goto out; /* success */
5918 + dbgaufs_si_fin(sbinfo);
5923 +/* ---------------------------------------------------------------------- */
5925 +void dbgaufs_fin(void)
5927 + debugfs_remove(dbgaufs);
5930 +int __init dbgaufs_init(void)
5935 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
5940 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dbgaufs.h linux-4.4/fs/aufs/dbgaufs.h
5941 --- linux-4.4/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
5942 +++ linux-4.4/fs/aufs/dbgaufs.h 2021-02-24 17:28:14.398807954 +0100
5945 + * Copyright (C) 2005-2016 Junjiro R. Okajima
5947 + * This program, aufs is free software; you can redistribute it and/or modify
5948 + * it under the terms of the GNU General Public License as published by
5949 + * the Free Software Foundation; either version 2 of the License, or
5950 + * (at your option) any later version.
5952 + * This program is distributed in the hope that it will be useful,
5953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5955 + * GNU General Public License for more details.
5957 + * You should have received a copy of the GNU General Public License
5958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5962 + * debugfs interface
5965 +#ifndef __DBGAUFS_H__
5966 +#define __DBGAUFS_H__
5970 +struct super_block;
5973 +#ifdef CONFIG_DEBUG_FS
5975 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
5976 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
5977 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
5978 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
5979 +void dbgaufs_fin(void);
5980 +int __init dbgaufs_init(void);
5982 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
5983 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
5984 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
5985 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
5986 +AuStubVoid(dbgaufs_fin, void)
5987 +AuStubInt0(__init dbgaufs_init, void)
5988 +#endif /* CONFIG_DEBUG_FS */
5990 +#endif /* __KERNEL__ */
5991 +#endif /* __DBGAUFS_H__ */
5992 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dcsub.c linux-4.4/fs/aufs/dcsub.c
5993 --- linux-4.4/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
5994 +++ linux-4.4/fs/aufs/dcsub.c 2021-02-24 17:28:14.398807954 +0100
5997 + * Copyright (C) 2005-2016 Junjiro R. Okajima
5999 + * This program, aufs is free software; you can redistribute it and/or modify
6000 + * it under the terms of the GNU General Public License as published by
6001 + * the Free Software Foundation; either version 2 of the License, or
6002 + * (at your option) any later version.
6004 + * This program is distributed in the hope that it will be useful,
6005 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6006 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6007 + * GNU General Public License for more details.
6009 + * You should have received a copy of the GNU General Public License
6010 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6014 + * sub-routines for dentry cache
6019 +static void au_dpage_free(struct au_dpage *dpage)
6022 + struct dentry **p;
6024 + p = dpage->dentries;
6025 + for (i = 0; i < dpage->ndentry; i++)
6027 + free_page((unsigned long)dpage->dentries);
6030 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6036 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6037 + if (unlikely(!dpages->dpages))
6040 + p = (void *)__get_free_page(gfp);
6044 + dpages->dpages[0].ndentry = 0;
6045 + dpages->dpages[0].dentries = p;
6046 + dpages->ndpage = 1;
6047 + return 0; /* success */
6050 + kfree(dpages->dpages);
6055 +void au_dpages_free(struct au_dcsub_pages *dpages)
6058 + struct au_dpage *p;
6060 + p = dpages->dpages;
6061 + for (i = 0; i < dpages->ndpage; i++)
6062 + au_dpage_free(p++);
6063 + kfree(dpages->dpages);
6066 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6067 + struct dentry *dentry, gfp_t gfp)
6070 + struct au_dpage *dpage;
6073 + dpage = dpages->dpages + dpages->ndpage - 1;
6074 + sz = PAGE_SIZE / sizeof(dentry);
6075 + if (unlikely(dpage->ndentry >= sz)) {
6076 + AuLabel(new dpage);
6078 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6079 + p = au_kzrealloc(dpages->dpages, sz,
6080 + sz + sizeof(*dpages->dpages), gfp);
6084 + dpages->dpages = p;
6085 + dpage = dpages->dpages + dpages->ndpage;
6086 + p = (void *)__get_free_page(gfp);
6090 + dpage->ndentry = 0;
6091 + dpage->dentries = p;
6095 + AuDebugOn(au_dcount(dentry) <= 0);
6096 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6097 + return 0; /* success */
6103 +/* todo: BAD approach */
6104 +/* copied from linux/fs/dcache.c */
6112 +extern void d_walk(struct dentry *parent, void *data,
6113 + enum d_walk_ret (*enter)(void *, struct dentry *),
6114 + void (*finish)(void *));
6116 +struct ac_dpages_arg {
6118 + struct au_dcsub_pages *dpages;
6119 + struct super_block *sb;
6120 + au_dpages_test test;
6124 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6126 + enum d_walk_ret ret;
6127 + struct ac_dpages_arg *arg = _arg;
6129 + ret = D_WALK_CONTINUE;
6130 + if (dentry->d_sb == arg->sb
6131 + && !IS_ROOT(dentry)
6132 + && au_dcount(dentry) > 0
6134 + && (!arg->test || arg->test(dentry, arg->arg))) {
6135 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6136 + if (unlikely(arg->err))
6137 + ret = D_WALK_QUIT;
6143 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6144 + au_dpages_test test, void *arg)
6146 + struct ac_dpages_arg args = {
6154 + d_walk(root, &args, au_call_dpages_append, NULL);
6159 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6160 + int do_include, au_dpages_test test, void *arg)
6165 + write_seqlock(&rename_lock);
6166 + spin_lock(&dentry->d_lock);
6168 + && au_dcount(dentry) > 0
6169 + && (!test || test(dentry, arg)))
6170 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6171 + spin_unlock(&dentry->d_lock);
6172 + if (unlikely(err))
6176 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6179 + while (!IS_ROOT(dentry)) {
6180 + dentry = dentry->d_parent; /* rename_lock is locked */
6181 + spin_lock(&dentry->d_lock);
6182 + if (au_dcount(dentry) > 0
6183 + && (!test || test(dentry, arg)))
6184 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6185 + spin_unlock(&dentry->d_lock);
6186 + if (unlikely(err))
6191 + write_sequnlock(&rename_lock);
6195 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6197 + return au_di(dentry) && dentry->d_sb == arg;
6200 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6201 + struct dentry *dentry, int do_include)
6203 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6204 + au_dcsub_dpages_aufs, dentry->d_sb);
6207 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6209 + struct path path[2] = {
6218 + return path_is_under(path + 0, path + 1);
6220 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dcsub.h linux-4.4/fs/aufs/dcsub.h
6221 --- linux-4.4/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6222 +++ linux-4.4/fs/aufs/dcsub.h 2021-02-24 17:28:14.402141395 +0100
6225 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6227 + * This program, aufs is free software; you can redistribute it and/or modify
6228 + * it under the terms of the GNU General Public License as published by
6229 + * the Free Software Foundation; either version 2 of the License, or
6230 + * (at your option) any later version.
6232 + * This program is distributed in the hope that it will be useful,
6233 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6234 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6235 + * GNU General Public License for more details.
6237 + * You should have received a copy of the GNU General Public License
6238 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6242 + * sub-routines for dentry cache
6245 +#ifndef __AUFS_DCSUB_H__
6246 +#define __AUFS_DCSUB_H__
6250 +#include <linux/dcache.h>
6251 +#include <linux/fs.h>
6255 + struct dentry **dentries;
6258 +struct au_dcsub_pages {
6260 + struct au_dpage *dpages;
6263 +/* ---------------------------------------------------------------------- */
6266 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6267 +void au_dpages_free(struct au_dcsub_pages *dpages);
6268 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6269 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6270 + au_dpages_test test, void *arg);
6271 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6272 + int do_include, au_dpages_test test, void *arg);
6273 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6274 + struct dentry *dentry, int do_include);
6275 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6277 +/* ---------------------------------------------------------------------- */
6280 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6281 + * include/linux/dcache.h. Try them (in the future).
6284 +static inline int au_d_hashed_positive(struct dentry *d)
6287 + struct inode *inode = d_inode(d);
6290 + if (unlikely(d_unhashed(d)
6291 + || d_is_negative(d)
6292 + || !inode->i_nlink))
6297 +static inline int au_d_linkable(struct dentry *d)
6300 + struct inode *inode = d_inode(d);
6302 + err = au_d_hashed_positive(d);
6304 + && d_is_positive(d)
6305 + && (inode->i_state & I_LINKABLE))
6310 +static inline int au_d_alive(struct dentry *d)
6313 + struct inode *inode;
6317 + err = au_d_hashed_positive(d);
6319 + inode = d_inode(d);
6320 + if (unlikely(d_unlinked(d)
6321 + || d_is_negative(d)
6322 + || !inode->i_nlink))
6328 +static inline int au_alive_dir(struct dentry *d)
6332 + err = au_d_alive(d);
6333 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6338 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6340 + return a->len == b->len
6341 + && !memcmp(a->name, b->name, a->len);
6346 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6348 + * the type of d_lockref.count became int, but the inlined function d_count()
6349 + * still returns unsigned int.
6350 + * I don't know why. Maybe it is for every d_count() users?
6351 + * Anyway au_dcount() lives on.
6353 +static inline int au_dcount(struct dentry *d)
6355 + return (int)d_count(d);
6358 +#endif /* __KERNEL__ */
6359 +#endif /* __AUFS_DCSUB_H__ */
6360 diff -urNp -x '*.orig' linux-4.4/fs/aufs/debug.c linux-4.4/fs/aufs/debug.c
6361 --- linux-4.4/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6362 +++ linux-4.4/fs/aufs/debug.c 2021-02-24 17:28:14.402141395 +0100
6365 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6367 + * This program, aufs is free software; you can redistribute it and/or modify
6368 + * it under the terms of the GNU General Public License as published by
6369 + * the Free Software Foundation; either version 2 of the License, or
6370 + * (at your option) any later version.
6372 + * This program is distributed in the hope that it will be useful,
6373 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6374 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6375 + * GNU General Public License for more details.
6377 + * You should have received a copy of the GNU General Public License
6378 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6382 + * debug print functions
6387 +/* Returns 0, or -errno. arg is in kp->arg. */
6388 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6392 + err = kstrtoint(val, 0, &n);
6402 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6403 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6408 + return sprintf(buffer, "%d", atomic_read(a));
6411 +static struct kernel_param_ops param_ops_atomic_t = {
6412 + .set = param_atomic_t_set,
6413 + .get = param_atomic_t_get
6414 + /* void (*free)(void *arg) */
6417 +atomic_t aufs_debug = ATOMIC_INIT(0);
6418 +MODULE_PARM_DESC(debug, "debug print");
6419 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6421 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6422 +char *au_plevel = KERN_DEBUG;
6423 +#define dpri(fmt, ...) do { \
6425 + && strcmp(au_plevel, KERN_DEBUG)) \
6426 + || au_debug_test()) \
6427 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6430 +/* ---------------------------------------------------------------------- */
6432 +void au_dpri_whlist(struct au_nhash *whlist)
6434 + unsigned long ul, n;
6435 + struct hlist_head *head;
6436 + struct au_vdir_wh *pos;
6438 + n = whlist->nh_num;
6439 + head = whlist->nh_head;
6440 + for (ul = 0; ul < n; ul++) {
6441 + hlist_for_each_entry(pos, head, wh_hash)
6442 + dpri("b%d, %.*s, %d\n",
6444 + pos->wh_str.len, pos->wh_str.name,
6450 +void au_dpri_vdir(struct au_vdir *vdir)
6453 + union au_vdir_deblk_p p;
6456 + if (!vdir || IS_ERR(vdir)) {
6457 + dpri("err %ld\n", PTR_ERR(vdir));
6461 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6462 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6463 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6464 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6465 + p.deblk = vdir->vd_deblk[ul];
6467 + dpri("[%lu]: %p\n", ul, o);
6471 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6472 + struct dentry *wh)
6477 + if (!inode || IS_ERR(inode)) {
6478 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6482 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6483 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6484 + && sizeof(inode->i_blocks) != sizeof(u64));
6486 + n = (void *)wh->d_name.name;
6487 + l = wh->d_name.len;
6490 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6491 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6493 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6494 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6495 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6496 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6497 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6498 + inode->i_state, inode->i_flags, inode->i_version,
6499 + inode->i_generation,
6500 + l ? ", wh " : "", l, n);
6504 +void au_dpri_inode(struct inode *inode)
6506 + struct au_iinfo *iinfo;
6507 + aufs_bindex_t bindex;
6510 + err = do_pri_inode(-1, inode, -1, NULL);
6511 + if (err || !au_test_aufs(inode->i_sb))
6514 + iinfo = au_ii(inode);
6517 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6518 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6519 + if (iinfo->ii_bstart < 0)
6522 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6523 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6524 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6525 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6529 +void au_dpri_dalias(struct inode *inode)
6533 + spin_lock(&inode->i_lock);
6534 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
6535 + au_dpri_dentry(d);
6536 + spin_unlock(&inode->i_lock);
6539 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6541 + struct dentry *wh = NULL;
6543 + struct au_iinfo *iinfo;
6545 + if (!dentry || IS_ERR(dentry)) {
6546 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6549 + /* do not call dget_parent() here */
6550 + /* note: access d_xxx without d_lock */
6551 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6552 + bindex, dentry, dentry,
6553 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6554 + au_dcount(dentry), dentry->d_flags,
6555 + d_unhashed(dentry) ? "un" : "");
6558 + && d_is_positive(dentry)
6559 + && au_test_aufs(dentry->d_sb)) {
6560 + iinfo = au_ii(d_inode(dentry));
6562 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6563 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6566 + do_pri_inode(bindex, d_inode(dentry), hn, wh);
6570 +void au_dpri_dentry(struct dentry *dentry)
6572 + struct au_dinfo *dinfo;
6573 + aufs_bindex_t bindex;
6575 + struct au_hdentry *hdp;
6577 + err = do_pri_dentry(-1, dentry);
6578 + if (err || !au_test_aufs(dentry->d_sb))
6581 + dinfo = au_di(dentry);
6584 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
6585 + dinfo->di_bstart, dinfo->di_bend,
6586 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
6587 + dinfo->di_tmpfile);
6588 + if (dinfo->di_bstart < 0)
6590 + hdp = dinfo->di_hdentry;
6591 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6592 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6595 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
6599 + if (!file || IS_ERR(file)) {
6600 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
6605 + && !IS_ERR_OR_NULL(file->f_path.dentry)
6606 + && au_test_aufs(file->f_path.dentry->d_sb)
6608 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
6609 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
6610 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
6611 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
6612 + file->f_version, file->f_pos, a);
6613 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
6614 + do_pri_dentry(bindex, file->f_path.dentry);
6618 +void au_dpri_file(struct file *file)
6620 + struct au_finfo *finfo;
6621 + struct au_fidir *fidir;
6622 + struct au_hfile *hfile;
6623 + aufs_bindex_t bindex;
6626 + err = do_pri_file(-1, file);
6628 + || IS_ERR_OR_NULL(file->f_path.dentry)
6629 + || !au_test_aufs(file->f_path.dentry->d_sb))
6632 + finfo = au_fi(file);
6635 + if (finfo->fi_btop < 0)
6637 + fidir = finfo->fi_hdir;
6639 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
6641 + for (bindex = finfo->fi_btop;
6642 + bindex >= 0 && bindex <= fidir->fd_bbot;
6644 + hfile = fidir->fd_hfile + bindex;
6645 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
6649 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
6651 + struct vfsmount *mnt;
6652 + struct super_block *sb;
6654 + if (!br || IS_ERR(br))
6656 + mnt = au_br_mnt(br);
6657 + if (!mnt || IS_ERR(mnt))
6660 + if (!sb || IS_ERR(sb))
6663 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
6664 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
6666 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
6667 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
6668 + sb->s_flags, sb->s_count,
6669 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
6673 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6677 +void au_dpri_sb(struct super_block *sb)
6679 + struct au_sbinfo *sbinfo;
6680 + aufs_bindex_t bindex;
6682 + /* to reuduce stack size */
6684 + struct vfsmount mnt;
6685 + struct au_branch fake;
6688 + /* this function can be called from magic sysrq */
6689 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6690 + if (unlikely(!a)) {
6691 + dpri("no memory\n");
6695 + a->mnt.mnt_sb = sb;
6696 + a->fake.br_path.mnt = &a->mnt;
6697 + atomic_set(&a->fake.br_count, 0);
6698 + smp_mb(); /* atomic_set */
6699 + err = do_pri_br(-1, &a->fake);
6701 + dpri("dev 0x%x\n", sb->s_dev);
6702 + if (err || !au_test_aufs(sb))
6705 + sbinfo = au_sbi(sb);
6708 + dpri("nw %d, gen %u, kobj %d\n",
6709 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6710 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6711 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6712 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6715 +/* ---------------------------------------------------------------------- */
6717 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
6719 + struct inode *h_inode, *inode = d_inode(dentry);
6720 + struct dentry *h_dentry;
6721 + aufs_bindex_t bindex, bend, bi;
6723 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
6726 + bend = au_dbend(dentry);
6727 + bi = au_ibend(inode);
6730 + bindex = au_dbstart(dentry);
6731 + bi = au_ibstart(inode);
6735 + for (; bindex <= bend; bindex++) {
6736 + h_dentry = au_h_dptr(dentry, bindex);
6739 + h_inode = au_h_iptr(inode, bindex);
6740 + if (unlikely(h_inode != d_inode(h_dentry))) {
6742 + AuDbg("b%d, %s:%d\n", bindex, func, line);
6743 + AuDbgDentry(dentry);
6744 + AuDbgInode(inode);
6751 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6754 + struct au_dcsub_pages dpages;
6755 + struct au_dpage *dpage;
6756 + struct dentry **dentries;
6758 + err = au_dpages_init(&dpages, GFP_NOFS);
6760 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6762 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6763 + dpage = dpages.dpages + i;
6764 + dentries = dpage->dentries;
6765 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6766 + AuDebugOn(au_digen_test(dentries[j], sigen));
6768 + au_dpages_free(&dpages);
6771 +void au_dbg_verify_kthread(void)
6773 + if (au_wkq_test()) {
6776 + * It may be recursive, but udba=notify between two aufs mounts,
6777 + * where a single ro branch is shared, is not a problem.
6783 +/* ---------------------------------------------------------------------- */
6785 +int __init au_debug_init(void)
6787 + aufs_bindex_t bindex;
6788 + struct au_vdir_destr destr;
6791 + AuDebugOn(bindex >= 0);
6794 + AuDebugOn(destr.len < NAME_MAX);
6796 +#ifdef CONFIG_4KSTACKS
6797 + pr_warn("CONFIG_4KSTACKS is defined.\n");
6802 diff -urNp -x '*.orig' linux-4.4/fs/aufs/debug.h linux-4.4/fs/aufs/debug.h
6803 --- linux-4.4/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
6804 +++ linux-4.4/fs/aufs/debug.h 2021-02-24 17:28:14.402141395 +0100
6807 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6809 + * This program, aufs is free software; you can redistribute it and/or modify
6810 + * it under the terms of the GNU General Public License as published by
6811 + * the Free Software Foundation; either version 2 of the License, or
6812 + * (at your option) any later version.
6814 + * This program is distributed in the hope that it will be useful,
6815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6817 + * GNU General Public License for more details.
6819 + * You should have received a copy of the GNU General Public License
6820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6824 + * debug print functions
6827 +#ifndef __AUFS_DEBUG_H__
6828 +#define __AUFS_DEBUG_H__
6832 +#include <linux/atomic.h>
6833 +#include <linux/module.h>
6834 +#include <linux/kallsyms.h>
6835 +#include <linux/sysrq.h>
6837 +#ifdef CONFIG_AUFS_DEBUG
6838 +#define AuDebugOn(a) BUG_ON(a)
6840 +/* module parameter */
6841 +extern atomic_t aufs_debug;
6842 +static inline void au_debug_on(void)
6844 + atomic_inc(&aufs_debug);
6846 +static inline void au_debug_off(void)
6848 + atomic_dec_if_positive(&aufs_debug);
6851 +static inline int au_debug_test(void)
6853 + return atomic_read(&aufs_debug) > 0;
6856 +#define AuDebugOn(a) do {} while (0)
6857 +AuStubVoid(au_debug_on, void)
6858 +AuStubVoid(au_debug_off, void)
6859 +AuStubInt0(au_debug_test, void)
6860 +#endif /* CONFIG_AUFS_DEBUG */
6862 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
6864 +/* ---------------------------------------------------------------------- */
6868 +#define AuDbg(fmt, ...) do { \
6869 + if (au_debug_test()) \
6870 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
6872 +#define AuLabel(l) AuDbg(#l "\n")
6873 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
6874 +#define AuWarn1(fmt, ...) do { \
6875 + static unsigned char _c; \
6877 + pr_warn(fmt, ##__VA_ARGS__); \
6880 +#define AuErr1(fmt, ...) do { \
6881 + static unsigned char _c; \
6883 + pr_err(fmt, ##__VA_ARGS__); \
6886 +#define AuIOErr1(fmt, ...) do { \
6887 + static unsigned char _c; \
6889 + AuIOErr(fmt, ##__VA_ARGS__); \
6892 +#define AuUnsupportMsg "This operation is not supported." \
6893 + " Please report this application to aufs-users ML."
6894 +#define AuUnsupport(fmt, ...) do { \
6895 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
6899 +#define AuTraceErr(e) do { \
6900 + if (unlikely((e) < 0)) \
6901 + AuDbg("err %d\n", (int)(e)); \
6904 +#define AuTraceErrPtr(p) do { \
6906 + AuDbg("err %ld\n", PTR_ERR(p)); \
6909 +/* dirty macros for debug print, use with "%.*s" and caution */
6910 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
6912 +/* ---------------------------------------------------------------------- */
6915 +#ifdef CONFIG_AUFS_DEBUG
6916 +extern struct mutex au_dbg_mtx;
6917 +extern char *au_plevel;
6919 +void au_dpri_whlist(struct au_nhash *whlist);
6921 +void au_dpri_vdir(struct au_vdir *vdir);
6923 +void au_dpri_inode(struct inode *inode);
6924 +void au_dpri_dalias(struct inode *inode);
6925 +void au_dpri_dentry(struct dentry *dentry);
6927 +void au_dpri_file(struct file *filp);
6928 +struct super_block;
6929 +void au_dpri_sb(struct super_block *sb);
6931 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
6932 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
6933 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
6934 +void au_dbg_verify_kthread(void);
6936 +int __init au_debug_init(void);
6938 +#define AuDbgWhlist(w) do { \
6939 + mutex_lock(&au_dbg_mtx); \
6941 + au_dpri_whlist(w); \
6942 + mutex_unlock(&au_dbg_mtx); \
6945 +#define AuDbgVdir(v) do { \
6946 + mutex_lock(&au_dbg_mtx); \
6948 + au_dpri_vdir(v); \
6949 + mutex_unlock(&au_dbg_mtx); \
6952 +#define AuDbgInode(i) do { \
6953 + mutex_lock(&au_dbg_mtx); \
6955 + au_dpri_inode(i); \
6956 + mutex_unlock(&au_dbg_mtx); \
6959 +#define AuDbgDAlias(i) do { \
6960 + mutex_lock(&au_dbg_mtx); \
6962 + au_dpri_dalias(i); \
6963 + mutex_unlock(&au_dbg_mtx); \
6966 +#define AuDbgDentry(d) do { \
6967 + mutex_lock(&au_dbg_mtx); \
6969 + au_dpri_dentry(d); \
6970 + mutex_unlock(&au_dbg_mtx); \
6973 +#define AuDbgFile(f) do { \
6974 + mutex_lock(&au_dbg_mtx); \
6976 + au_dpri_file(f); \
6977 + mutex_unlock(&au_dbg_mtx); \
6980 +#define AuDbgSb(sb) do { \
6981 + mutex_lock(&au_dbg_mtx); \
6982 + AuDbg(#sb "\n"); \
6984 + mutex_unlock(&au_dbg_mtx); \
6987 +#define AuDbgSym(addr) do { \
6988 + char sym[KSYM_SYMBOL_LEN]; \
6989 + sprint_symbol(sym, (unsigned long)addr); \
6990 + AuDbg("%s\n", sym); \
6993 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
6994 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
6995 +AuStubVoid(au_dbg_verify_kthread, void)
6996 +AuStubInt0(__init au_debug_init, void)
6998 +#define AuDbgWhlist(w) do {} while (0)
6999 +#define AuDbgVdir(v) do {} while (0)
7000 +#define AuDbgInode(i) do {} while (0)
7001 +#define AuDbgDAlias(i) do {} while (0)
7002 +#define AuDbgDentry(d) do {} while (0)
7003 +#define AuDbgFile(f) do {} while (0)
7004 +#define AuDbgSb(sb) do {} while (0)
7005 +#define AuDbgSym(addr) do {} while (0)
7006 +#endif /* CONFIG_AUFS_DEBUG */
7008 +/* ---------------------------------------------------------------------- */
7010 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7011 +int __init au_sysrq_init(void);
7012 +void au_sysrq_fin(void);
7014 +#ifdef CONFIG_HW_CONSOLE
7015 +#define au_dbg_blocked() do { \
7017 + handle_sysrq('w'); \
7020 +AuStubVoid(au_dbg_blocked, void)
7024 +AuStubInt0(__init au_sysrq_init, void)
7025 +AuStubVoid(au_sysrq_fin, void)
7026 +AuStubVoid(au_dbg_blocked, void)
7027 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7029 +#endif /* __KERNEL__ */
7030 +#endif /* __AUFS_DEBUG_H__ */
7031 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dentry.c linux-4.4/fs/aufs/dentry.c
7032 --- linux-4.4/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7033 +++ linux-4.4/fs/aufs/dentry.c 2021-02-24 17:28:14.402141395 +0100
7036 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7038 + * This program, aufs is free software; you can redistribute it and/or modify
7039 + * it under the terms of the GNU General Public License as published by
7040 + * the Free Software Foundation; either version 2 of the License, or
7041 + * (at your option) any later version.
7043 + * This program is distributed in the hope that it will be useful,
7044 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7045 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7046 + * GNU General Public License for more details.
7048 + * You should have received a copy of the GNU General Public License
7049 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7053 + * lookup and dentry operations
7056 +#include <linux/namei.h>
7059 +#define AuLkup_ALLOW_NEG 1
7060 +#define AuLkup_IGNORE_PERM (1 << 1)
7061 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7062 +#define au_fset_lkup(flags, name) \
7063 + do { (flags) |= AuLkup_##name; } while (0)
7064 +#define au_fclr_lkup(flags, name) \
7065 + do { (flags) &= ~AuLkup_##name; } while (0)
7067 +struct au_do_lookup_args {
7068 + unsigned int flags;
7073 + * returns positive/negative dentry, NULL or an error.
7074 + * NULL means whiteout-ed or not-found.
7076 +static struct dentry*
7077 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7078 + aufs_bindex_t bindex, struct qstr *wh_name,
7079 + struct au_do_lookup_args *args)
7081 + struct dentry *h_dentry;
7082 + struct inode *h_inode;
7083 + struct au_branch *br;
7084 + int wh_found, opq;
7085 + unsigned char wh_able;
7086 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7087 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7091 + br = au_sbr(dentry->d_sb, bindex);
7092 + wh_able = !!au_br_whable(br->br_perm);
7094 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7095 + h_dentry = ERR_PTR(wh_found);
7098 + if (unlikely(wh_found < 0))
7101 + /* We found a whiteout */
7102 + /* au_set_dbend(dentry, bindex); */
7103 + au_set_dbwh(dentry, bindex);
7105 + return NULL; /* success */
7109 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7111 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7112 + if (IS_ERR(h_dentry)) {
7113 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7119 + h_inode = d_inode(h_dentry);
7120 + if (d_is_negative(h_dentry)) {
7123 + } else if (wh_found
7124 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7127 + if (au_dbend(dentry) <= bindex)
7128 + au_set_dbend(dentry, bindex);
7129 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7130 + au_set_dbstart(dentry, bindex);
7131 + au_set_h_dptr(dentry, bindex, h_dentry);
7133 + if (!d_is_dir(h_dentry)
7135 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7136 + goto out; /* success */
7138 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7139 + opq = au_diropq_test(h_dentry);
7140 + mutex_unlock(&h_inode->i_mutex);
7142 + au_set_dbdiropq(dentry, bindex);
7143 + else if (unlikely(opq < 0)) {
7144 + au_set_h_dptr(dentry, bindex, NULL);
7145 + h_dentry = ERR_PTR(opq);
7156 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7158 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7159 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7165 + * returns the number of lower positive dentries,
7166 + * otherwise an error.
7167 + * can be called at unlinking with @type is zero.
7169 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7171 + int npositive, err;
7172 + aufs_bindex_t bindex, btail, bdiropq;
7173 + unsigned char isdir, dirperm1;
7174 + struct qstr whname;
7175 + struct au_do_lookup_args args = {
7179 + const struct qstr *name = &dentry->d_name;
7180 + struct dentry *parent;
7181 + struct super_block *sb;
7183 + sb = dentry->d_sb;
7184 + err = au_test_shwh(sb, name);
7185 + if (unlikely(err))
7188 + err = au_wh_name_alloc(&whname, name);
7189 + if (unlikely(err))
7192 + isdir = !!d_is_dir(dentry);
7194 + au_fset_lkup(args.flags, ALLOW_NEG);
7195 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7198 + parent = dget_parent(dentry);
7199 + btail = au_dbtaildir(parent);
7200 + for (bindex = bstart; bindex <= btail; bindex++) {
7201 + struct dentry *h_parent, *h_dentry;
7202 + struct inode *h_inode, *h_dir;
7204 + h_dentry = au_h_dptr(dentry, bindex);
7206 + if (d_is_positive(h_dentry))
7208 + if (type != S_IFDIR)
7212 + h_parent = au_h_dptr(parent, bindex);
7213 + if (!h_parent || !d_is_dir(h_parent))
7216 + h_dir = d_inode(h_parent);
7217 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7218 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7220 + mutex_unlock(&h_dir->i_mutex);
7221 + err = PTR_ERR(h_dentry);
7222 + if (IS_ERR(h_dentry))
7225 + au_fclr_lkup(args.flags, ALLOW_NEG);
7227 + au_fset_lkup(args.flags, IGNORE_PERM);
7229 + if (au_dbwh(dentry) == bindex)
7233 + if (d_is_negative(h_dentry))
7235 + h_inode = d_inode(h_dentry);
7238 + args.type = h_inode->i_mode & S_IFMT;
7239 + if (args.type != S_IFDIR)
7242 + /* the type of lower may be different */
7243 + bdiropq = au_dbdiropq(dentry);
7244 + if (bdiropq >= 0 && bdiropq <= bindex)
7250 + AuLabel(positive);
7251 + au_update_dbstart(dentry);
7254 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7255 + && au_dbstart(dentry) < 0)) {
7257 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7263 + kfree(whname.name);
7268 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7270 + struct dentry *dentry;
7273 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7274 + dentry = vfsub_lkup_one(name, parent);
7276 + struct vfsub_lkup_one_args args = {
7282 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7283 + if (unlikely(wkq_err))
7284 + dentry = ERR_PTR(wkq_err);
7291 + * lookup @dentry on @bindex which should be negative.
7293 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7296 + struct dentry *parent, *h_parent, *h_dentry;
7297 + struct au_branch *br;
7299 + parent = dget_parent(dentry);
7300 + h_parent = au_h_dptr(parent, bindex);
7301 + br = au_sbr(dentry->d_sb, bindex);
7303 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7305 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7306 + err = PTR_ERR(h_dentry);
7307 + if (IS_ERR(h_dentry))
7309 + if (unlikely(d_is_positive(h_dentry))) {
7311 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7317 + if (bindex < au_dbstart(dentry))
7318 + au_set_dbstart(dentry, bindex);
7319 + if (au_dbend(dentry) < bindex)
7320 + au_set_dbend(dentry, bindex);
7321 + au_set_h_dptr(dentry, bindex, h_dentry);
7328 +/* ---------------------------------------------------------------------- */
7330 +/* subset of struct inode */
7332 + unsigned long i_ino;
7333 + /* unsigned int i_nlink; */
7339 + blkcnt_t i_blocks;
7344 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7346 + ia->i_ino = h_inode->i_ino;
7347 + /* ia->i_nlink = h_inode->i_nlink; */
7348 + ia->i_uid = h_inode->i_uid;
7349 + ia->i_gid = h_inode->i_gid;
7350 + ia->i_version = h_inode->i_version;
7352 + ia->i_size = h_inode->i_size;
7353 + ia->i_blocks = h_inode->i_blocks;
7355 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7358 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7360 + return ia->i_ino != h_inode->i_ino
7361 + /* || ia->i_nlink != h_inode->i_nlink */
7362 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7363 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7364 + || ia->i_version != h_inode->i_version
7366 + || ia->i_size != h_inode->i_size
7367 + || ia->i_blocks != h_inode->i_blocks
7369 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7372 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7373 + struct au_branch *br)
7376 + struct au_iattr ia;
7377 + struct inode *h_inode;
7378 + struct dentry *h_d;
7379 + struct super_block *h_sb;
7382 + memset(&ia, -1, sizeof(ia));
7383 + h_sb = h_dentry->d_sb;
7385 + if (d_is_positive(h_dentry)) {
7386 + h_inode = d_inode(h_dentry);
7387 + au_iattr_save(&ia, h_inode);
7388 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7389 + /* nfs d_revalidate may return 0 for negative dentry */
7390 + /* fuse d_revalidate always return 0 for negative dentry */
7393 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7394 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7395 + err = PTR_ERR(h_d);
7400 + if (unlikely(h_d != h_dentry
7401 + || d_inode(h_d) != h_inode
7402 + || (h_inode && au_iattr_test(&ia, h_inode))))
7403 + err = au_busy_or_stale();
7411 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7412 + struct dentry *h_parent, struct au_branch *br)
7417 + if (udba == AuOpt_UDBA_REVAL
7418 + && !au_test_fs_remote(h_dentry->d_sb)) {
7420 + err = (d_inode(h_dentry->d_parent) != h_dir);
7421 + } else if (udba != AuOpt_UDBA_NONE)
7422 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7427 +/* ---------------------------------------------------------------------- */
7429 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7432 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7433 + struct au_hdentry tmp, *p, *q;
7434 + struct au_dinfo *dinfo;
7435 + struct super_block *sb;
7437 + DiMustWriteLock(dentry);
7439 + sb = dentry->d_sb;
7440 + dinfo = au_di(dentry);
7441 + bend = dinfo->di_bend;
7442 + bwh = dinfo->di_bwh;
7443 + bdiropq = dinfo->di_bdiropq;
7444 + p = dinfo->di_hdentry + dinfo->di_bstart;
7445 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7446 + if (!p->hd_dentry)
7449 + new_bindex = au_br_index(sb, p->hd_id);
7450 + if (new_bindex == bindex)
7453 + if (dinfo->di_bwh == bindex)
7455 + if (dinfo->di_bdiropq == bindex)
7456 + bdiropq = new_bindex;
7457 + if (new_bindex < 0) {
7459 + p->hd_dentry = NULL;
7463 + /* swap two lower dentries, and loop again */
7464 + q = dinfo->di_hdentry + new_bindex;
7468 + if (tmp.hd_dentry) {
7474 + dinfo->di_bwh = -1;
7475 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7476 + dinfo->di_bwh = bwh;
7478 + dinfo->di_bdiropq = -1;
7480 + && bdiropq <= au_sbend(sb)
7481 + && au_sbr_whable(sb, bdiropq))
7482 + dinfo->di_bdiropq = bdiropq;
7485 + dinfo->di_bstart = -1;
7486 + dinfo->di_bend = -1;
7487 + bend = au_dbend(parent);
7488 + p = dinfo->di_hdentry;
7489 + for (bindex = 0; bindex <= bend; bindex++, p++)
7490 + if (p->hd_dentry) {
7491 + dinfo->di_bstart = bindex;
7495 + if (dinfo->di_bstart >= 0) {
7496 + p = dinfo->di_hdentry + bend;
7497 + for (bindex = bend; bindex >= 0; bindex--, p--)
7498 + if (p->hd_dentry) {
7499 + dinfo->di_bend = bindex;
7508 +static void au_do_hide(struct dentry *dentry)
7510 + struct inode *inode;
7512 + if (d_really_is_positive(dentry)) {
7513 + inode = d_inode(dentry);
7514 + if (!d_is_dir(dentry)) {
7515 + if (inode->i_nlink && !d_unhashed(dentry))
7516 + drop_nlink(inode);
7518 + clear_nlink(inode);
7519 + /* stop next lookup */
7520 + inode->i_flags |= S_DEAD;
7522 + smp_mb(); /* necessary? */
7527 +static int au_hide_children(struct dentry *parent)
7529 + int err, i, j, ndentry;
7530 + struct au_dcsub_pages dpages;
7531 + struct au_dpage *dpage;
7532 + struct dentry *dentry;
7534 + err = au_dpages_init(&dpages, GFP_NOFS);
7535 + if (unlikely(err))
7537 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7538 + if (unlikely(err))
7541 + /* in reverse order */
7542 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7543 + dpage = dpages.dpages + i;
7544 + ndentry = dpage->ndentry;
7545 + for (j = ndentry - 1; j >= 0; j--) {
7546 + dentry = dpage->dentries[j];
7547 + if (dentry != parent)
7548 + au_do_hide(dentry);
7553 + au_dpages_free(&dpages);
7558 +static void au_hide(struct dentry *dentry)
7562 + AuDbgDentry(dentry);
7563 + if (d_is_dir(dentry)) {
7564 + /* shrink_dcache_parent(dentry); */
7565 + err = au_hide_children(dentry);
7566 + if (unlikely(err))
7567 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7570 + au_do_hide(dentry);
7574 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7576 + * a dirty branch is added
7577 + * - on the top of layers
7578 + * - in the middle of layers
7579 + * - to the bottom of layers
7581 + * on the added branch there exists
7584 + * - a same named entry
7586 + * * negative --> positive
7587 + * * positive --> positive
7588 + * - type is unchanged
7589 + * - type is changed
7591 + * * negative --> negative
7592 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7595 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7596 + struct au_dinfo *tmp)
7599 + aufs_bindex_t bindex, bend;
7601 + struct dentry *dentry;
7602 + struct inode *inode;
7604 + } orig_h, tmp_h = {
7607 + struct au_hdentry *hd;
7608 + struct inode *inode, *h_inode;
7609 + struct dentry *h_dentry;
7612 + AuDebugOn(dinfo->di_bstart < 0);
7614 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
7615 + orig_h.inode = NULL;
7616 + if (d_is_positive(orig_h.dentry)) {
7617 + orig_h.inode = d_inode(orig_h.dentry);
7618 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
7620 + if (tmp->di_bstart >= 0) {
7621 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
7622 + if (d_is_positive(tmp_h.dentry)) {
7623 + tmp_h.inode = d_inode(tmp_h.dentry);
7624 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
7629 + if (d_really_is_positive(dentry))
7630 + inode = d_inode(dentry);
7631 + if (!orig_h.inode) {
7632 + AuDbg("nagative originally\n");
7638 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7639 + AuDebugOn(dinfo->di_bdiropq != -1);
7641 + if (!tmp_h.inode) {
7642 + AuDbg("negative --> negative\n");
7643 + /* should have only one negative lower */
7644 + if (tmp->di_bstart >= 0
7645 + && tmp->di_bstart < dinfo->di_bstart) {
7646 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
7647 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7648 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
7649 + au_di_cp(dinfo, tmp);
7650 + hd = tmp->di_hdentry + tmp->di_bstart;
7651 + au_set_h_dptr(dentry, tmp->di_bstart,
7652 + dget(hd->hd_dentry));
7654 + au_dbg_verify_dinode(dentry);
7656 + AuDbg("negative --> positive\n");
7658 + * similar to the behaviour of creating with bypassing
7660 + * unhash it in order to force an error in the
7661 + * succeeding create operation.
7662 + * we should not set S_DEAD here.
7665 + /* au_di_swap(tmp, dinfo); */
7666 + au_dbg_verify_dinode(dentry);
7669 + AuDbg("positive originally\n");
7670 + /* inode may be NULL */
7671 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
7672 + if (!tmp_h.inode) {
7673 + AuDbg("positive --> negative\n");
7674 + /* or bypassing aufs */
7676 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
7677 + dinfo->di_bwh = tmp->di_bwh;
7679 + err = au_refresh_hinode_self(inode);
7680 + au_dbg_verify_dinode(dentry);
7681 + } else if (orig_h.mode == tmp_h.mode) {
7682 + AuDbg("positive --> positive, same type\n");
7683 + if (!S_ISDIR(orig_h.mode)
7684 + && dinfo->di_bstart > tmp->di_bstart) {
7686 + * similar to the behaviour of removing and
7691 + err = au_refresh_hinode_self(inode);
7692 + au_dbg_verify_dinode(dentry);
7694 + /* fill empty slots */
7695 + if (dinfo->di_bstart > tmp->di_bstart)
7696 + dinfo->di_bstart = tmp->di_bstart;
7697 + if (dinfo->di_bend < tmp->di_bend)
7698 + dinfo->di_bend = tmp->di_bend;
7699 + dinfo->di_bwh = tmp->di_bwh;
7700 + dinfo->di_bdiropq = tmp->di_bdiropq;
7701 + hd = tmp->di_hdentry;
7702 + bend = dinfo->di_bend;
7703 + for (bindex = tmp->di_bstart; bindex <= bend;
7705 + if (au_h_dptr(dentry, bindex))
7707 + h_dentry = hd[bindex].hd_dentry;
7710 + AuDebugOn(d_is_negative(h_dentry));
7711 + h_inode = d_inode(h_dentry);
7712 + AuDebugOn(orig_h.mode
7713 + != (h_inode->i_mode
7715 + au_set_h_dptr(dentry, bindex,
7718 + err = au_refresh_hinode(inode, dentry);
7719 + au_dbg_verify_dinode(dentry);
7722 + AuDbg("positive --> positive, different type\n");
7723 + /* similar to the behaviour of removing and creating */
7726 + err = au_refresh_hinode_self(inode);
7727 + au_dbg_verify_dinode(dentry);
7735 +void au_refresh_dop(struct dentry *dentry, int force_reval)
7737 + const struct dentry_operations *dop
7738 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
7739 + static const unsigned int mask
7740 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
7742 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
7744 + if (dentry->d_op == dop)
7747 + AuDbg("%pd\n", dentry);
7748 + spin_lock(&dentry->d_lock);
7749 + if (dop == &aufs_dop)
7750 + dentry->d_flags |= mask;
7752 + dentry->d_flags &= ~mask;
7753 + dentry->d_op = dop;
7754 + spin_unlock(&dentry->d_lock);
7757 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7760 + unsigned int sigen;
7761 + struct au_dinfo *dinfo, *tmp;
7762 + struct super_block *sb;
7763 + struct inode *inode;
7765 + DiMustWriteLock(dentry);
7766 + AuDebugOn(IS_ROOT(dentry));
7767 + AuDebugOn(d_really_is_negative(parent));
7769 + sb = dentry->d_sb;
7770 + sigen = au_sigen(sb);
7771 + err = au_digen_test(parent, sigen);
7772 + if (unlikely(err))
7775 + dinfo = au_di(dentry);
7776 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
7777 + if (unlikely(err))
7779 + ebrange = au_dbrange_test(dentry);
7781 + ebrange = au_do_refresh_hdentry(dentry, parent);
7783 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
7784 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
7785 + if (d_really_is_positive(dentry)) {
7786 + inode = d_inode(dentry);
7787 + err = au_refresh_hinode_self(inode);
7789 + au_dbg_verify_dinode(dentry);
7791 + goto out_dgen; /* success */
7795 + /* temporary dinfo */
7796 + AuDbgDentry(dentry);
7798 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
7799 + if (unlikely(!tmp))
7801 + au_di_swap(tmp, dinfo);
7802 + /* returns the number of positive dentries */
7804 + * if current working dir is removed, it returns an error.
7805 + * but the dentry is legal.
7807 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
7808 + AuDbgDentry(dentry);
7809 + au_di_swap(tmp, dinfo);
7810 + if (err == -ENOENT)
7813 + /* compare/refresh by dinfo */
7814 + AuDbgDentry(dentry);
7815 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
7816 + au_dbg_verify_dinode(dentry);
7819 + au_rw_write_unlock(&tmp->di_rwsem);
7821 + if (unlikely(err))
7825 + au_update_digen(dentry);
7827 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
7828 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
7829 + AuDbgDentry(dentry);
7835 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
7836 + struct dentry *dentry, aufs_bindex_t bindex)
7841 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
7844 + AuDbg("b%d\n", bindex);
7846 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
7847 + * due to whiteout and branch permission.
7849 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
7850 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
7851 + /* it may return tri-state */
7852 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
7854 + if (unlikely(valid < 0))
7864 +/* todo: remove this */
7865 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
7866 + unsigned int flags, int do_udba)
7869 + umode_t mode, h_mode;
7870 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
7871 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
7872 + struct inode *h_inode, *h_cached_inode;
7873 + struct dentry *h_dentry;
7874 + struct qstr *name, *h_name;
7881 + unhashed = !!d_unhashed(dentry);
7882 + is_root = !!IS_ROOT(dentry);
7883 + name = &dentry->d_name;
7884 + tmpfile = au_di(dentry)->di_tmpfile;
7887 + * Theoretically, REVAL test should be unnecessary in case of
7889 + * But {fs,i}notify doesn't fire some necessary events,
7890 + * IN_ATTRIB for atime/nlink/pageio
7891 + * Let's do REVAL test too.
7893 + if (do_udba && inode) {
7894 + mode = (inode->i_mode & S_IFMT);
7895 + plus = (inode->i_nlink > 0);
7896 + ibs = au_ibstart(inode);
7897 + ibe = au_ibend(inode);
7900 + bstart = au_dbstart(dentry);
7902 + if (inode && S_ISDIR(inode->i_mode))
7903 + btail = au_dbtaildir(dentry);
7904 + for (bindex = bstart; bindex <= btail; bindex++) {
7905 + h_dentry = au_h_dptr(dentry, bindex);
7909 + AuDbg("b%d, %pd\n", bindex, h_dentry);
7910 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
7911 + spin_lock(&h_dentry->d_lock);
7912 + h_name = &h_dentry->d_name;
7913 + if (unlikely(do_udba
7916 + && (unhashed != !!d_unhashed(h_dentry)
7918 + && !au_qstreq(name, h_name))
7921 + && !(flags & LOOKUP_OPEN)
7922 + && (h_dentry->d_flags
7923 + & DCACHE_NFSFS_RENAMED)))
7927 + h_unhashed = d_unhashed(h_dentry);
7928 + spin_unlock(&h_dentry->d_lock);
7929 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
7930 + unhashed, h_unhashed, dentry, h_dentry);
7933 + spin_unlock(&h_dentry->d_lock);
7935 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
7936 + if (unlikely(err))
7937 + /* do not goto err, to keep the errno */
7940 + /* todo: plink too? */
7945 + if (unlikely(!!inode != d_is_positive(h_dentry)))
7949 + if (d_is_positive(h_dentry))
7950 + h_inode = d_inode(h_dentry);
7953 + h_cached_inode = h_inode;
7955 + h_mode = (h_inode->i_mode & S_IFMT);
7956 + h_plus = (h_inode->i_nlink > 0);
7958 + if (inode && ibs <= bindex && bindex <= ibe)
7959 + h_cached_inode = au_h_iptr(inode, bindex);
7962 + if (unlikely(plus != h_plus && !tmpfile))
7965 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
7967 + && !IS_ROOT(h_dentry)
7968 + && unhashed != d_unhashed(h_dentry)))
7971 + if (unlikely(mode != h_mode
7972 + || h_cached_inode != h_inode))
7985 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
7986 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
7989 + struct dentry *parent;
7991 + if (!au_digen_test(dentry, sigen))
7994 + parent = dget_parent(dentry);
7995 + di_read_lock_parent(parent, AuLock_IR);
7996 + AuDebugOn(au_digen_test(parent, sigen));
7997 + au_dbg_verify_gen(parent, sigen);
7998 + err = au_refresh_dentry(dentry, parent);
7999 + di_read_unlock(parent, AuLock_IR);
8005 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8008 + struct dentry *d, *parent;
8010 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8011 + return simple_reval_dpath(dentry, sigen);
8013 + /* slow loop, keep it simple and stupid */
8014 + /* cf: au_cpup_dirs() */
8017 + while (au_digen_test(dentry, sigen)) {
8021 + parent = dget_parent(d);
8022 + if (!au_digen_test(parent, sigen))
8028 + di_write_lock_child2(d);
8030 + /* someone might update our dentry while we were sleeping */
8031 + if (au_digen_test(d, sigen)) {
8033 + * todo: consolidate with simple_reval_dpath(),
8034 + * do_refresh() and au_reval_for_attr().
8036 + di_read_lock_parent(parent, AuLock_IR);
8037 + err = au_refresh_dentry(d, parent);
8038 + di_read_unlock(parent, AuLock_IR);
8042 + di_write_unlock(d);
8044 + if (unlikely(err))
8052 + * if valid returns 1, otherwise 0.
8054 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8057 + unsigned int sigen;
8058 + unsigned char do_udba;
8059 + struct super_block *sb;
8060 + struct inode *inode;
8062 + /* todo: support rcu-walk? */
8063 + if (flags & LOOKUP_RCU)
8067 + if (unlikely(!au_di(dentry)))
8071 + sb = dentry->d_sb;
8074 + * i_mutex of parent dir may be held,
8075 + * but we should not return 'invalid' due to busy.
8077 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8078 + if (unlikely(err)) {
8084 + if (d_really_is_positive(dentry))
8085 + inode = d_inode(dentry);
8086 + if (unlikely(inode && is_bad_inode(inode))) {
8091 + if (unlikely(au_dbrange_test(dentry))) {
8097 + sigen = au_sigen(sb);
8098 + if (au_digen_test(dentry, sigen)) {
8099 + AuDebugOn(IS_ROOT(dentry));
8100 + err = au_reval_dpath(dentry, sigen);
8101 + if (unlikely(err)) {
8106 + di_downgrade_lock(dentry, AuLock_IR);
8109 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8111 + && !(inode->i_state && I_LINKABLE)
8112 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8117 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8118 + if (do_udba && inode) {
8119 + aufs_bindex_t bstart = au_ibstart(inode);
8120 + struct inode *h_inode;
8122 + if (bstart >= 0) {
8123 + h_inode = au_h_iptr(inode, bstart);
8124 + if (h_inode && au_test_higen(inode, h_inode)) {
8131 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8132 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8134 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8140 + di_downgrade_lock(dentry, AuLock_IR);
8142 + aufs_read_unlock(dentry, AuLock_IR);
8147 + AuDbg("%pd invalid, %d\n", dentry, valid);
8153 +static void aufs_d_release(struct dentry *dentry)
8155 + if (au_di(dentry)) {
8156 + au_di_fin(dentry);
8157 + au_hn_di_reinit(dentry);
8161 +const struct dentry_operations aufs_dop = {
8162 + .d_revalidate = aufs_d_revalidate,
8163 + .d_weak_revalidate = aufs_d_revalidate,
8164 + .d_release = aufs_d_release
8167 +/* aufs_dop without d_revalidate */
8168 +const struct dentry_operations aufs_dop_noreval = {
8169 + .d_release = aufs_d_release
8171 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dentry.h linux-4.4/fs/aufs/dentry.h
8172 --- linux-4.4/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8173 +++ linux-4.4/fs/aufs/dentry.h 2021-02-24 17:28:14.402141395 +0100
8176 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8178 + * This program, aufs is free software; you can redistribute it and/or modify
8179 + * it under the terms of the GNU General Public License as published by
8180 + * the Free Software Foundation; either version 2 of the License, or
8181 + * (at your option) any later version.
8183 + * This program is distributed in the hope that it will be useful,
8184 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8185 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8186 + * GNU General Public License for more details.
8188 + * You should have received a copy of the GNU General Public License
8189 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8193 + * lookup and dentry operations
8196 +#ifndef __AUFS_DENTRY_H__
8197 +#define __AUFS_DENTRY_H__
8201 +#include <linux/dcache.h>
8204 +struct au_hdentry {
8205 + struct dentry *hd_dentry;
8206 + aufs_bindex_t hd_id;
8210 + atomic_t di_generation;
8212 + struct au_rwsem di_rwsem;
8213 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8214 + unsigned char di_tmpfile; /* to allow the different name */
8215 + struct au_hdentry *di_hdentry;
8216 +} ____cacheline_aligned_in_smp;
8218 +/* ---------------------------------------------------------------------- */
8221 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8223 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8224 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8225 + struct dentry *h_parent, struct au_branch *br);
8227 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8228 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8229 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8230 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8231 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8234 +void au_di_init_once(void *_di);
8235 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8236 +void au_di_free(struct au_dinfo *dinfo);
8237 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8238 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8239 +int au_di_init(struct dentry *dentry);
8240 +void au_di_fin(struct dentry *dentry);
8241 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8243 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8244 +void di_read_unlock(struct dentry *d, int flags);
8245 +void di_downgrade_lock(struct dentry *d, int flags);
8246 +void di_write_lock(struct dentry *d, unsigned int lsc);
8247 +void di_write_unlock(struct dentry *d);
8248 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8249 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8250 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8252 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8253 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8254 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8255 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8257 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8258 + struct dentry *h_dentry);
8259 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8260 +int au_dbrange_test(struct dentry *dentry);
8261 +void au_update_digen(struct dentry *dentry);
8262 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8263 +void au_update_dbstart(struct dentry *dentry);
8264 +void au_update_dbend(struct dentry *dentry);
8265 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8267 +/* ---------------------------------------------------------------------- */
8269 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8271 + return dentry->d_fsdata;
8274 +/* ---------------------------------------------------------------------- */
8276 +/* lock subclass for dinfo */
8278 + AuLsc_DI_CHILD, /* child first */
8279 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8280 + AuLsc_DI_CHILD3, /* copyup dirs */
8284 + AuLsc_DI_TMP /* temp for replacing dinfo */
8288 + * di_read_lock_child, di_write_lock_child,
8289 + * di_read_lock_child2, di_write_lock_child2,
8290 + * di_read_lock_child3, di_write_lock_child3,
8291 + * di_read_lock_parent, di_write_lock_parent,
8292 + * di_read_lock_parent2, di_write_lock_parent2,
8293 + * di_read_lock_parent3, di_write_lock_parent3,
8295 +#define AuReadLockFunc(name, lsc) \
8296 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8297 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8299 +#define AuWriteLockFunc(name, lsc) \
8300 +static inline void di_write_lock_##name(struct dentry *d) \
8301 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8303 +#define AuRWLockFuncs(name, lsc) \
8304 + AuReadLockFunc(name, lsc) \
8305 + AuWriteLockFunc(name, lsc)
8307 +AuRWLockFuncs(child, CHILD);
8308 +AuRWLockFuncs(child2, CHILD2);
8309 +AuRWLockFuncs(child3, CHILD3);
8310 +AuRWLockFuncs(parent, PARENT);
8311 +AuRWLockFuncs(parent2, PARENT2);
8312 +AuRWLockFuncs(parent3, PARENT3);
8314 +#undef AuReadLockFunc
8315 +#undef AuWriteLockFunc
8316 +#undef AuRWLockFuncs
8318 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8319 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8320 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8322 +/* ---------------------------------------------------------------------- */
8324 +/* todo: memory barrier? */
8325 +static inline unsigned int au_digen(struct dentry *d)
8327 + return atomic_read(&au_di(d)->di_generation);
8330 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8332 + hdentry->hd_dentry = NULL;
8335 +static inline void au_hdput(struct au_hdentry *hd)
8338 + dput(hd->hd_dentry);
8341 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8343 + DiMustAnyLock(dentry);
8344 + return au_di(dentry)->di_bstart;
8347 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8349 + DiMustAnyLock(dentry);
8350 + return au_di(dentry)->di_bend;
8353 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8355 + DiMustAnyLock(dentry);
8356 + return au_di(dentry)->di_bwh;
8359 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8361 + DiMustAnyLock(dentry);
8362 + return au_di(dentry)->di_bdiropq;
8365 +/* todo: hard/soft set? */
8366 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8368 + DiMustWriteLock(dentry);
8369 + au_di(dentry)->di_bstart = bindex;
8372 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8374 + DiMustWriteLock(dentry);
8375 + au_di(dentry)->di_bend = bindex;
8378 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8380 + DiMustWriteLock(dentry);
8381 + /* dbwh can be outside of bstart - bend range */
8382 + au_di(dentry)->di_bwh = bindex;
8385 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8387 + DiMustWriteLock(dentry);
8388 + au_di(dentry)->di_bdiropq = bindex;
8391 +/* ---------------------------------------------------------------------- */
8393 +#ifdef CONFIG_AUFS_HNOTIFY
8394 +static inline void au_digen_dec(struct dentry *d)
8396 + atomic_dec(&au_di(d)->di_generation);
8399 +static inline void au_hn_di_reinit(struct dentry *dentry)
8401 + dentry->d_fsdata = NULL;
8404 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8405 +#endif /* CONFIG_AUFS_HNOTIFY */
8407 +#endif /* __KERNEL__ */
8408 +#endif /* __AUFS_DENTRY_H__ */
8409 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dinfo.c linux-4.4/fs/aufs/dinfo.c
8410 --- linux-4.4/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8411 +++ linux-4.4/fs/aufs/dinfo.c 2021-02-24 17:28:14.402141395 +0100
8414 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8416 + * This program, aufs is free software; you can redistribute it and/or modify
8417 + * it under the terms of the GNU General Public License as published by
8418 + * the Free Software Foundation; either version 2 of the License, or
8419 + * (at your option) any later version.
8421 + * This program is distributed in the hope that it will be useful,
8422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8424 + * GNU General Public License for more details.
8426 + * You should have received a copy of the GNU General Public License
8427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8431 + * dentry private data
8436 +void au_di_init_once(void *_dinfo)
8438 + struct au_dinfo *dinfo = _dinfo;
8439 + static struct lock_class_key aufs_di;
8441 + au_rw_init(&dinfo->di_rwsem);
8442 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8445 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8447 + struct au_dinfo *dinfo;
8450 + dinfo = au_cache_alloc_dinfo();
8451 + if (unlikely(!dinfo))
8454 + nbr = au_sbend(sb) + 1;
8457 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8458 + if (dinfo->di_hdentry) {
8459 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8460 + dinfo->di_bstart = -1;
8461 + dinfo->di_bend = -1;
8462 + dinfo->di_bwh = -1;
8463 + dinfo->di_bdiropq = -1;
8464 + dinfo->di_tmpfile = 0;
8465 + for (i = 0; i < nbr; i++)
8466 + dinfo->di_hdentry[i].hd_id = -1;
8470 + au_cache_free_dinfo(dinfo);
8477 +void au_di_free(struct au_dinfo *dinfo)
8479 + struct au_hdentry *p;
8480 + aufs_bindex_t bend, bindex;
8482 + /* dentry may not be revalidated */
8483 + bindex = dinfo->di_bstart;
8484 + if (bindex >= 0) {
8485 + bend = dinfo->di_bend;
8486 + p = dinfo->di_hdentry + bindex;
8487 + while (bindex++ <= bend)
8490 + kfree(dinfo->di_hdentry);
8491 + au_cache_free_dinfo(dinfo);
8494 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8496 + struct au_hdentry *p;
8499 + AuRwMustWriteLock(&a->di_rwsem);
8500 + AuRwMustWriteLock(&b->di_rwsem);
8502 +#define DiSwap(v, name) \
8504 + v = a->di_##name; \
8505 + a->di_##name = b->di_##name; \
8506 + b->di_##name = v; \
8509 + DiSwap(p, hdentry);
8510 + DiSwap(bi, bstart);
8513 + DiSwap(bi, bdiropq);
8519 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8521 + AuRwMustWriteLock(&dst->di_rwsem);
8522 + AuRwMustWriteLock(&src->di_rwsem);
8524 + dst->di_bstart = src->di_bstart;
8525 + dst->di_bend = src->di_bend;
8526 + dst->di_bwh = src->di_bwh;
8527 + dst->di_bdiropq = src->di_bdiropq;
8531 +int au_di_init(struct dentry *dentry)
8534 + struct super_block *sb;
8535 + struct au_dinfo *dinfo;
8538 + sb = dentry->d_sb;
8539 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8541 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8542 + /* smp_mb(); */ /* atomic_set */
8543 + dentry->d_fsdata = dinfo;
8550 +void au_di_fin(struct dentry *dentry)
8552 + struct au_dinfo *dinfo;
8554 + dinfo = au_di(dentry);
8555 + AuRwDestroy(&dinfo->di_rwsem);
8556 + au_di_free(dinfo);
8559 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8562 + struct au_hdentry *hdp;
8564 + AuRwMustWriteLock(&dinfo->di_rwsem);
8567 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8569 + sz = sizeof(*hdp);
8570 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8572 + dinfo->di_hdentry = hdp;
8579 +/* ---------------------------------------------------------------------- */
8581 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8584 + case AuLsc_DI_CHILD:
8585 + ii_write_lock_child(inode);
8587 + case AuLsc_DI_CHILD2:
8588 + ii_write_lock_child2(inode);
8590 + case AuLsc_DI_CHILD3:
8591 + ii_write_lock_child3(inode);
8593 + case AuLsc_DI_PARENT:
8594 + ii_write_lock_parent(inode);
8596 + case AuLsc_DI_PARENT2:
8597 + ii_write_lock_parent2(inode);
8599 + case AuLsc_DI_PARENT3:
8600 + ii_write_lock_parent3(inode);
8607 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8610 + case AuLsc_DI_CHILD:
8611 + ii_read_lock_child(inode);
8613 + case AuLsc_DI_CHILD2:
8614 + ii_read_lock_child2(inode);
8616 + case AuLsc_DI_CHILD3:
8617 + ii_read_lock_child3(inode);
8619 + case AuLsc_DI_PARENT:
8620 + ii_read_lock_parent(inode);
8622 + case AuLsc_DI_PARENT2:
8623 + ii_read_lock_parent2(inode);
8625 + case AuLsc_DI_PARENT3:
8626 + ii_read_lock_parent3(inode);
8633 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
8635 + struct inode *inode;
8637 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8638 + if (d_really_is_positive(d)) {
8639 + inode = d_inode(d);
8640 + if (au_ftest_lock(flags, IW))
8641 + do_ii_write_lock(inode, lsc);
8642 + else if (au_ftest_lock(flags, IR))
8643 + do_ii_read_lock(inode, lsc);
8647 +void di_read_unlock(struct dentry *d, int flags)
8649 + struct inode *inode;
8651 + if (d_really_is_positive(d)) {
8652 + inode = d_inode(d);
8653 + if (au_ftest_lock(flags, IW)) {
8654 + au_dbg_verify_dinode(d);
8655 + ii_write_unlock(inode);
8656 + } else if (au_ftest_lock(flags, IR)) {
8657 + au_dbg_verify_dinode(d);
8658 + ii_read_unlock(inode);
8661 + au_rw_read_unlock(&au_di(d)->di_rwsem);
8664 +void di_downgrade_lock(struct dentry *d, int flags)
8666 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
8667 + ii_downgrade_lock(d_inode(d));
8668 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
8671 +void di_write_lock(struct dentry *d, unsigned int lsc)
8673 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
8674 + if (d_really_is_positive(d))
8675 + do_ii_write_lock(d_inode(d), lsc);
8678 +void di_write_unlock(struct dentry *d)
8680 + au_dbg_verify_dinode(d);
8681 + if (d_really_is_positive(d))
8682 + ii_write_unlock(d_inode(d));
8683 + au_rw_write_unlock(&au_di(d)->di_rwsem);
8686 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
8688 + AuDebugOn(d1 == d2
8689 + || d_inode(d1) == d_inode(d2)
8690 + || d1->d_sb != d2->d_sb);
8692 + if (isdir && au_test_subdir(d1, d2)) {
8693 + di_write_lock_child(d1);
8694 + di_write_lock_child2(d2);
8696 + /* there should be no races */
8697 + di_write_lock_child(d2);
8698 + di_write_lock_child2(d1);
8702 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
8704 + AuDebugOn(d1 == d2
8705 + || d_inode(d1) == d_inode(d2)
8706 + || d1->d_sb != d2->d_sb);
8708 + if (isdir && au_test_subdir(d1, d2)) {
8709 + di_write_lock_parent(d1);
8710 + di_write_lock_parent2(d2);
8712 + /* there should be no races */
8713 + di_write_lock_parent(d2);
8714 + di_write_lock_parent2(d1);
8718 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
8720 + di_write_unlock(d1);
8721 + if (d_inode(d1) == d_inode(d2))
8722 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
8724 + di_write_unlock(d2);
8727 +/* ---------------------------------------------------------------------- */
8729 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
8733 + DiMustAnyLock(dentry);
8735 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
8737 + AuDebugOn(bindex < 0);
8738 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
8739 + AuDebugOn(d && au_dcount(d) <= 0);
8744 + * extended version of au_h_dptr().
8745 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
8748 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
8750 + struct dentry *h_dentry;
8751 + struct inode *inode, *h_inode;
8753 + AuDebugOn(d_really_is_negative(dentry));
8756 + if (au_dbstart(dentry) <= bindex
8757 + && bindex <= au_dbend(dentry))
8758 + h_dentry = au_h_dptr(dentry, bindex);
8759 + if (h_dentry && !au_d_linkable(h_dentry)) {
8761 + goto out; /* success */
8764 + inode = d_inode(dentry);
8765 + AuDebugOn(bindex < au_ibstart(inode));
8766 + AuDebugOn(au_ibend(inode) < bindex);
8767 + h_inode = au_h_iptr(inode, bindex);
8768 + h_dentry = d_find_alias(h_inode);
8770 + if (!IS_ERR(h_dentry)) {
8771 + if (!au_d_linkable(h_dentry))
8772 + goto out; /* success */
8778 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8779 + h_dentry = au_plink_lkup(inode, bindex);
8780 + AuDebugOn(!h_dentry);
8781 + if (!IS_ERR(h_dentry)) {
8782 + if (!au_d_hashed_positive(h_dentry))
8783 + goto out; /* success */
8790 + AuDbgDentry(h_dentry);
8794 +aufs_bindex_t au_dbtail(struct dentry *dentry)
8796 + aufs_bindex_t bend, bwh;
8798 + bend = au_dbend(dentry);
8800 + bwh = au_dbwh(dentry);
8803 + if (0 < bwh && bwh < bend)
8809 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
8811 + aufs_bindex_t bend, bopq;
8813 + bend = au_dbtail(dentry);
8815 + bopq = au_dbdiropq(dentry);
8816 + if (0 <= bopq && bopq < bend)
8822 +/* ---------------------------------------------------------------------- */
8824 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8825 + struct dentry *h_dentry)
8827 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
8828 + struct au_branch *br;
8830 + DiMustWriteLock(dentry);
8833 + hd->hd_dentry = h_dentry;
8835 + br = au_sbr(dentry->d_sb, bindex);
8836 + hd->hd_id = br->br_id;
8840 +int au_dbrange_test(struct dentry *dentry)
8843 + aufs_bindex_t bstart, bend;
8846 + bstart = au_dbstart(dentry);
8847 + bend = au_dbend(dentry);
8849 + AuDebugOn(bend < 0 && bstart > bend);
8852 + AuDebugOn(bend >= 0);
8858 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
8863 + if (unlikely(au_digen(dentry) != sigen
8864 + || au_iigen_test(d_inode(dentry), sigen)))
8870 +void au_update_digen(struct dentry *dentry)
8872 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
8873 + /* smp_mb(); */ /* atomic_set */
8876 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
8878 + struct au_dinfo *dinfo;
8879 + struct dentry *h_d;
8880 + struct au_hdentry *hdp;
8882 + DiMustWriteLock(dentry);
8884 + dinfo = au_di(dentry);
8885 + if (!dinfo || dinfo->di_bstart < 0)
8888 + hdp = dinfo->di_hdentry;
8889 + if (do_put_zero) {
8890 + aufs_bindex_t bindex, bend;
8892 + bend = dinfo->di_bend;
8893 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
8894 + h_d = hdp[0 + bindex].hd_dentry;
8895 + if (h_d && d_is_negative(h_d))
8896 + au_set_h_dptr(dentry, bindex, NULL);
8900 + dinfo->di_bstart = -1;
8901 + while (++dinfo->di_bstart <= dinfo->di_bend)
8902 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
8904 + if (dinfo->di_bstart > dinfo->di_bend) {
8905 + dinfo->di_bstart = -1;
8906 + dinfo->di_bend = -1;
8911 + while (0 <= --dinfo->di_bend)
8912 + if (hdp[0 + dinfo->di_bend].hd_dentry)
8914 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
8917 +void au_update_dbstart(struct dentry *dentry)
8919 + aufs_bindex_t bindex, bend;
8920 + struct dentry *h_dentry;
8922 + bend = au_dbend(dentry);
8923 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
8924 + h_dentry = au_h_dptr(dentry, bindex);
8927 + if (d_is_positive(h_dentry)) {
8928 + au_set_dbstart(dentry, bindex);
8931 + au_set_h_dptr(dentry, bindex, NULL);
8935 +void au_update_dbend(struct dentry *dentry)
8937 + aufs_bindex_t bindex, bstart;
8938 + struct dentry *h_dentry;
8940 + bstart = au_dbstart(dentry);
8941 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
8942 + h_dentry = au_h_dptr(dentry, bindex);
8945 + if (d_is_positive(h_dentry)) {
8946 + au_set_dbend(dentry, bindex);
8949 + au_set_h_dptr(dentry, bindex, NULL);
8953 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
8955 + aufs_bindex_t bindex, bend;
8957 + bend = au_dbend(dentry);
8958 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
8959 + if (au_h_dptr(dentry, bindex) == h_dentry)
8963 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dir.c linux-4.4/fs/aufs/dir.c
8964 --- linux-4.4/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
8965 +++ linux-4.4/fs/aufs/dir.c 2021-02-24 17:28:14.402141395 +0100
8968 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8970 + * This program, aufs is free software; you can redistribute it and/or modify
8971 + * it under the terms of the GNU General Public License as published by
8972 + * the Free Software Foundation; either version 2 of the License, or
8973 + * (at your option) any later version.
8975 + * This program is distributed in the hope that it will be useful,
8976 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8977 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8978 + * GNU General Public License for more details.
8980 + * You should have received a copy of the GNU General Public License
8981 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8985 + * directory operations
8988 +#include <linux/fs_stack.h>
8991 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
8993 + unsigned int nlink;
8995 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
8997 + nlink = dir->i_nlink;
8998 + nlink += h_dir->i_nlink - 2;
8999 + if (h_dir->i_nlink < 2)
9001 + smp_mb(); /* for i_nlink */
9002 + /* 0 can happen in revaliding */
9003 + set_nlink(dir, nlink);
9006 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9008 + unsigned int nlink;
9010 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9012 + nlink = dir->i_nlink;
9013 + nlink -= h_dir->i_nlink - 2;
9014 + if (h_dir->i_nlink < 2)
9016 + smp_mb(); /* for i_nlink */
9017 + /* nlink == 0 means the branch-fs is broken */
9018 + set_nlink(dir, nlink);
9021 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9024 + aufs_bindex_t bindex, bend;
9025 + struct file *h_file;
9026 + struct dentry *h_dentry;
9030 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9032 + bend = au_fbend_dir(file);
9033 + for (bindex = au_fbstart(file);
9034 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9036 + h_file = au_hf_dir(file, bindex);
9037 + if (h_file && file_inode(h_file))
9038 + sz += vfsub_f_size_read(h_file);
9041 + AuDebugOn(!dentry);
9042 + AuDebugOn(!d_is_dir(dentry));
9044 + bend = au_dbtaildir(dentry);
9045 + for (bindex = au_dbstart(dentry);
9046 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9048 + h_dentry = au_h_dptr(dentry, bindex);
9049 + if (h_dentry && d_is_positive(h_dentry))
9050 + sz += i_size_read(d_inode(h_dentry));
9053 + if (sz < KMALLOC_MAX_SIZE)
9054 + sz = roundup_pow_of_two(sz);
9055 + if (sz > KMALLOC_MAX_SIZE)
9056 + sz = KMALLOC_MAX_SIZE;
9057 + else if (sz < NAME_MAX) {
9058 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9059 + sz = AUFS_RDBLK_DEF;
9064 +struct au_dir_ts_arg {
9065 + struct dentry *dentry;
9066 + aufs_bindex_t brid;
9069 +static void au_do_dir_ts(void *arg)
9071 + struct au_dir_ts_arg *a = arg;
9072 + struct au_dtime dt;
9073 + struct path h_path;
9074 + struct inode *dir, *h_dir;
9075 + struct super_block *sb;
9076 + struct au_branch *br;
9077 + struct au_hinode *hdir;
9079 + aufs_bindex_t bstart, bindex;
9081 + sb = a->dentry->d_sb;
9082 + if (d_really_is_negative(a->dentry))
9084 + /* no dir->i_mutex lock */
9085 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9087 + dir = d_inode(a->dentry);
9088 + bstart = au_ibstart(dir);
9089 + bindex = au_br_index(sb, a->brid);
9090 + if (bindex < bstart)
9093 + br = au_sbr(sb, bindex);
9094 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9095 + if (!h_path.dentry)
9097 + h_path.mnt = au_br_mnt(br);
9098 + au_dtime_store(&dt, a->dentry, &h_path);
9100 + br = au_sbr(sb, bstart);
9101 + if (!au_br_writable(br->br_perm))
9103 + h_path.dentry = au_h_dptr(a->dentry, bstart);
9104 + h_path.mnt = au_br_mnt(br);
9105 + err = vfsub_mnt_want_write(h_path.mnt);
9108 + hdir = au_hi(dir, bstart);
9109 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
9110 + h_dir = au_h_iptr(dir, bstart);
9111 + if (h_dir->i_nlink
9112 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9113 + dt.dt_h_path = h_path;
9114 + au_dtime_revert(&dt);
9116 + au_hn_imtx_unlock(hdir);
9117 + vfsub_mnt_drop_write(h_path.mnt);
9118 + au_cpup_attr_timesizes(dir);
9121 + aufs_read_unlock(a->dentry, AuLock_DW);
9124 + au_nwt_done(&au_sbi(sb)->si_nowait);
9128 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9130 + int perm, wkq_err;
9131 + aufs_bindex_t bstart;
9132 + struct au_dir_ts_arg *arg;
9133 + struct dentry *dentry;
9134 + struct super_block *sb;
9138 + dentry = d_find_any_alias(dir);
9139 + AuDebugOn(!dentry);
9140 + sb = dentry->d_sb;
9141 + bstart = au_ibstart(dir);
9142 + if (bstart == bindex) {
9143 + au_cpup_attr_timesizes(dir);
9147 + perm = au_sbr_perm(sb, bstart);
9148 + if (!au_br_writable(perm))
9151 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9155 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9156 + arg->brid = au_sbr_id(sb, bindex);
9157 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9158 + if (unlikely(wkq_err)) {
9159 + pr_err("wkq %d\n", wkq_err);
9168 +/* ---------------------------------------------------------------------- */
9170 +static int reopen_dir(struct file *file)
9173 + unsigned int flags;
9174 + aufs_bindex_t bindex, btail, bstart;
9175 + struct dentry *dentry, *h_dentry;
9176 + struct file *h_file;
9178 + /* open all lower dirs */
9179 + dentry = file->f_path.dentry;
9180 + bstart = au_dbstart(dentry);
9181 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9182 + au_set_h_fptr(file, bindex, NULL);
9183 + au_set_fbstart(file, bstart);
9185 + btail = au_dbtaildir(dentry);
9186 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9187 + au_set_h_fptr(file, bindex, NULL);
9188 + au_set_fbend_dir(file, btail);
9190 + flags = vfsub_file_flags(file);
9191 + for (bindex = bstart; bindex <= btail; bindex++) {
9192 + h_dentry = au_h_dptr(dentry, bindex);
9195 + h_file = au_hf_dir(file, bindex);
9199 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9200 + err = PTR_ERR(h_file);
9201 + if (IS_ERR(h_file))
9202 + goto out; /* close all? */
9203 + au_set_h_fptr(file, bindex, h_file);
9205 + au_update_figen(file);
9206 + /* todo: necessary? */
9207 + /* file->f_ra = h_file->f_ra; */
9214 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9217 + aufs_bindex_t bindex, btail;
9218 + struct dentry *dentry, *h_dentry;
9219 + struct vfsmount *mnt;
9221 + FiMustWriteLock(file);
9222 + AuDebugOn(h_file);
9225 + mnt = file->f_path.mnt;
9226 + dentry = file->f_path.dentry;
9227 + file->f_version = d_inode(dentry)->i_version;
9228 + bindex = au_dbstart(dentry);
9229 + au_set_fbstart(file, bindex);
9230 + btail = au_dbtaildir(dentry);
9231 + au_set_fbend_dir(file, btail);
9232 + for (; !err && bindex <= btail; bindex++) {
9233 + h_dentry = au_h_dptr(dentry, bindex);
9237 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9238 + if (unlikely(err))
9240 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9241 + if (IS_ERR(h_file)) {
9242 + err = PTR_ERR(h_file);
9245 + au_set_h_fptr(file, bindex, h_file);
9247 + au_update_figen(file);
9248 + /* todo: necessary? */
9249 + /* file->f_ra = h_file->f_ra; */
9251 + return 0; /* success */
9254 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9255 + au_set_h_fptr(file, bindex, NULL);
9256 + au_set_fbstart(file, -1);
9257 + au_set_fbend_dir(file, -1);
9262 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9263 + struct file *file)
9266 + struct super_block *sb;
9267 + struct au_fidir *fidir;
9270 + sb = file->f_path.dentry->d_sb;
9271 + si_read_lock(sb, AuLock_FLUSH);
9272 + fidir = au_fidir_alloc(sb);
9274 + struct au_do_open_args args = {
9275 + .open = do_open_dir,
9278 + err = au_do_open(file, &args);
9279 + if (unlikely(err))
9282 + si_read_unlock(sb);
9286 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9287 + struct file *file)
9289 + struct au_vdir *vdir_cache;
9290 + struct au_finfo *finfo;
9291 + struct au_fidir *fidir;
9292 + aufs_bindex_t bindex, bend;
9294 + finfo = au_fi(file);
9295 + fidir = finfo->fi_hdir;
9297 + au_sphl_del(&finfo->fi_hlist,
9298 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9299 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9301 + au_vdir_free(vdir_cache);
9303 + bindex = finfo->fi_btop;
9304 + if (bindex >= 0) {
9306 + * calls fput() instead of filp_close(),
9307 + * since no dnotify or lock for the lower file.
9309 + bend = fidir->fd_bbot;
9310 + for (; bindex <= bend; bindex++)
9311 + au_set_h_fptr(file, bindex, NULL);
9314 + finfo->fi_hdir = NULL;
9316 + au_finfo_fin(file);
9320 +/* ---------------------------------------------------------------------- */
9322 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9325 + aufs_bindex_t bindex, bend;
9326 + struct file *h_file;
9329 + bend = au_fbend_dir(file);
9330 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9331 + h_file = au_hf_dir(file, bindex);
9333 + err = vfsub_flush(h_file, id);
9338 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9340 + return au_do_flush(file, id, au_do_flush_dir);
9343 +/* ---------------------------------------------------------------------- */
9345 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9348 + aufs_bindex_t bend, bindex;
9349 + struct inode *inode;
9350 + struct super_block *sb;
9353 + sb = dentry->d_sb;
9354 + inode = d_inode(dentry);
9356 + bend = au_dbend(dentry);
9357 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9358 + struct path h_path;
9360 + if (au_test_ro(sb, bindex, inode))
9362 + h_path.dentry = au_h_dptr(dentry, bindex);
9363 + if (!h_path.dentry)
9366 + h_path.mnt = au_sbr_mnt(sb, bindex);
9367 + err = vfsub_fsync(NULL, &h_path, datasync);
9373 +static int au_do_fsync_dir(struct file *file, int datasync)
9376 + aufs_bindex_t bend, bindex;
9377 + struct file *h_file;
9378 + struct super_block *sb;
9379 + struct inode *inode;
9381 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9382 + if (unlikely(err))
9385 + inode = file_inode(file);
9387 + bend = au_fbend_dir(file);
9388 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9389 + h_file = au_hf_dir(file, bindex);
9390 + if (!h_file || au_test_ro(sb, bindex, inode))
9393 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9401 + * @file may be NULL
9403 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9407 + struct dentry *dentry;
9408 + struct inode *inode;
9409 + struct super_block *sb;
9410 + struct mutex *mtx;
9413 + dentry = file->f_path.dentry;
9414 + inode = d_inode(dentry);
9415 + mtx = &inode->i_mutex;
9417 + sb = dentry->d_sb;
9418 + si_noflush_read_lock(sb);
9420 + err = au_do_fsync_dir(file, datasync);
9422 + di_write_lock_child(dentry);
9423 + err = au_do_fsync_dir_no_file(dentry, datasync);
9425 + au_cpup_attr_timesizes(inode);
9426 + di_write_unlock(dentry);
9428 + fi_write_unlock(file);
9430 + si_read_unlock(sb);
9431 + mutex_unlock(mtx);
9435 +/* ---------------------------------------------------------------------- */
9437 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9440 + struct dentry *dentry;
9441 + struct inode *inode, *h_inode;
9442 + struct super_block *sb;
9444 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9446 + dentry = file->f_path.dentry;
9447 + inode = d_inode(dentry);
9450 + sb = dentry->d_sb;
9451 + si_read_lock(sb, AuLock_FLUSH);
9452 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9453 + if (unlikely(err))
9455 + err = au_alive_dir(dentry);
9457 + err = au_vdir_init(file);
9458 + di_downgrade_lock(dentry, AuLock_IR);
9459 + if (unlikely(err))
9462 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9463 + if (!au_test_nfsd()) {
9464 + err = au_vdir_fill_de(file, ctx);
9465 + fsstack_copy_attr_atime(inode, h_inode);
9468 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9469 + * encode_fh() and others.
9471 + atomic_inc(&h_inode->i_count);
9472 + di_read_unlock(dentry, AuLock_IR);
9473 + si_read_unlock(sb);
9474 + err = au_vdir_fill_de(file, ctx);
9475 + fsstack_copy_attr_atime(inode, h_inode);
9476 + fi_write_unlock(file);
9484 + di_read_unlock(dentry, AuLock_IR);
9485 + fi_write_unlock(file);
9487 + si_read_unlock(sb);
9491 +/* ---------------------------------------------------------------------- */
9493 +#define AuTestEmpty_WHONLY 1
9494 +#define AuTestEmpty_CALLED (1 << 1)
9495 +#define AuTestEmpty_SHWH (1 << 2)
9496 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9497 +#define au_fset_testempty(flags, name) \
9498 + do { (flags) |= AuTestEmpty_##name; } while (0)
9499 +#define au_fclr_testempty(flags, name) \
9500 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9502 +#ifndef CONFIG_AUFS_SHWH
9503 +#undef AuTestEmpty_SHWH
9504 +#define AuTestEmpty_SHWH 0
9507 +struct test_empty_arg {
9508 + struct dir_context ctx;
9509 + struct au_nhash *whlist;
9510 + unsigned int flags;
9512 + aufs_bindex_t bindex;
9515 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9516 + int namelen, loff_t offset __maybe_unused, u64 ino,
9517 + unsigned int d_type)
9519 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9521 + char *name = (void *)__name;
9524 + au_fset_testempty(arg->flags, CALLED);
9526 + if (name[0] == '.'
9527 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9528 + goto out; /* success */
9530 + if (namelen <= AUFS_WH_PFX_LEN
9531 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9532 + if (au_ftest_testempty(arg->flags, WHONLY)
9533 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9534 + arg->err = -ENOTEMPTY;
9538 + name += AUFS_WH_PFX_LEN;
9539 + namelen -= AUFS_WH_PFX_LEN;
9540 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9541 + arg->err = au_nhash_append_wh
9542 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9543 + au_ftest_testempty(arg->flags, SHWH));
9547 + AuTraceErr(arg->err);
9551 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9554 + struct file *h_file;
9556 + h_file = au_h_open(dentry, arg->bindex,
9557 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9558 + /*file*/NULL, /*force_wr*/0);
9559 + err = PTR_ERR(h_file);
9560 + if (IS_ERR(h_file))
9564 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9565 + && !file_inode(h_file)->i_nlink)
9570 + au_fclr_testempty(arg->flags, CALLED);
9572 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9575 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9579 + au_sbr_put(dentry->d_sb, arg->bindex);
9584 +struct do_test_empty_args {
9586 + struct dentry *dentry;
9587 + struct test_empty_arg *arg;
9590 +static void call_do_test_empty(void *args)
9592 + struct do_test_empty_args *a = args;
9593 + *a->errp = do_test_empty(a->dentry, a->arg);
9596 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9599 + struct dentry *h_dentry;
9600 + struct inode *h_inode;
9602 + h_dentry = au_h_dptr(dentry, arg->bindex);
9603 + h_inode = d_inode(h_dentry);
9604 + /* todo: i_mode changes anytime? */
9605 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9606 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9607 + mutex_unlock(&h_inode->i_mutex);
9609 + err = do_test_empty(dentry, arg);
9611 + struct do_test_empty_args args = {
9616 + unsigned int flags = arg->flags;
9618 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9619 + if (unlikely(wkq_err))
9621 + arg->flags = flags;
9627 +int au_test_empty_lower(struct dentry *dentry)
9630 + unsigned int rdhash;
9631 + aufs_bindex_t bindex, bstart, btail;
9632 + struct au_nhash whlist;
9633 + struct test_empty_arg arg = {
9635 + .actor = test_empty_cb
9638 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
9640 + SiMustAnyLock(dentry->d_sb);
9642 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
9644 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
9645 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
9646 + if (unlikely(err))
9650 + arg.whlist = &whlist;
9651 + bstart = au_dbstart(dentry);
9652 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9653 + au_fset_testempty(arg.flags, SHWH);
9654 + test_empty = do_test_empty;
9655 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
9656 + test_empty = sio_test_empty;
9657 + arg.bindex = bstart;
9658 + err = test_empty(dentry, &arg);
9659 + if (unlikely(err))
9662 + au_fset_testempty(arg.flags, WHONLY);
9663 + btail = au_dbtaildir(dentry);
9664 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
9665 + struct dentry *h_dentry;
9667 + h_dentry = au_h_dptr(dentry, bindex);
9668 + if (h_dentry && d_is_positive(h_dentry)) {
9669 + arg.bindex = bindex;
9670 + err = test_empty(dentry, &arg);
9675 + au_nhash_wh_free(&whlist);
9680 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
9683 + struct test_empty_arg arg = {
9685 + .actor = test_empty_cb
9688 + aufs_bindex_t bindex, btail;
9691 + arg.whlist = whlist;
9692 + arg.flags = AuTestEmpty_WHONLY;
9693 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9694 + au_fset_testempty(arg.flags, SHWH);
9695 + btail = au_dbtaildir(dentry);
9696 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
9697 + struct dentry *h_dentry;
9699 + h_dentry = au_h_dptr(dentry, bindex);
9700 + if (h_dentry && d_is_positive(h_dentry)) {
9701 + arg.bindex = bindex;
9702 + err = sio_test_empty(dentry, &arg);
9709 +/* ---------------------------------------------------------------------- */
9711 +const struct file_operations aufs_dir_fop = {
9712 + .owner = THIS_MODULE,
9713 + .llseek = default_llseek,
9714 + .read = generic_read_dir,
9715 + .iterate = aufs_iterate,
9716 + .unlocked_ioctl = aufs_ioctl_dir,
9717 +#ifdef CONFIG_COMPAT
9718 + .compat_ioctl = aufs_compat_ioctl_dir,
9720 + .open = aufs_open_dir,
9721 + .release = aufs_release_dir,
9722 + .flush = aufs_flush_dir,
9723 + .fsync = aufs_fsync_dir
9725 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dir.h linux-4.4/fs/aufs/dir.h
9726 --- linux-4.4/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
9727 +++ linux-4.4/fs/aufs/dir.h 2021-02-24 17:28:14.402141395 +0100
9730 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9732 + * This program, aufs is free software; you can redistribute it and/or modify
9733 + * it under the terms of the GNU General Public License as published by
9734 + * the Free Software Foundation; either version 2 of the License, or
9735 + * (at your option) any later version.
9737 + * This program is distributed in the hope that it will be useful,
9738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9740 + * GNU General Public License for more details.
9742 + * You should have received a copy of the GNU General Public License
9743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9747 + * directory operations
9750 +#ifndef __AUFS_DIR_H__
9751 +#define __AUFS_DIR_H__
9755 +#include <linux/fs.h>
9757 +/* ---------------------------------------------------------------------- */
9759 +/* need to be faster and smaller */
9762 + unsigned int nh_num;
9763 + struct hlist_head *nh_head;
9766 +struct au_vdir_destr {
9767 + unsigned char len;
9768 + unsigned char name[0];
9771 +struct au_vdir_dehstr {
9772 + struct hlist_node hash;
9773 + struct au_vdir_destr *str;
9774 +} ____cacheline_aligned_in_smp;
9776 +struct au_vdir_de {
9778 + unsigned char de_type;
9779 + /* caution: packed */
9780 + struct au_vdir_destr de_str;
9783 +struct au_vdir_wh {
9784 + struct hlist_node wh_hash;
9785 +#ifdef CONFIG_AUFS_SHWH
9787 + aufs_bindex_t wh_bindex;
9788 + unsigned char wh_type;
9790 + aufs_bindex_t wh_bindex;
9792 + /* caution: packed */
9793 + struct au_vdir_destr wh_str;
9796 +union au_vdir_deblk_p {
9797 + unsigned char *deblk;
9798 + struct au_vdir_de *de;
9802 + unsigned char **vd_deblk;
9803 + unsigned long vd_nblk;
9806 + union au_vdir_deblk_p p;
9809 + unsigned long vd_version;
9810 + unsigned int vd_deblk_sz;
9811 + unsigned long vd_jiffy;
9812 +} ____cacheline_aligned_in_smp;
9814 +/* ---------------------------------------------------------------------- */
9817 +extern const struct file_operations aufs_dir_fop;
9818 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
9819 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
9820 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
9821 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
9822 +int au_test_empty_lower(struct dentry *dentry);
9823 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
9826 +unsigned int au_rdhash_est(loff_t sz);
9827 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
9828 +void au_nhash_wh_free(struct au_nhash *whlist);
9829 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
9831 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
9832 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
9833 + unsigned int d_type, aufs_bindex_t bindex,
9834 + unsigned char shwh);
9835 +void au_vdir_free(struct au_vdir *vdir);
9836 +int au_vdir_init(struct file *file);
9837 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
9840 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
9842 +#ifdef CONFIG_AUFS_RDU
9844 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
9845 +#ifdef CONFIG_COMPAT
9846 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9847 + unsigned long arg);
9850 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
9851 + unsigned int cmd, unsigned long arg)
9852 +#ifdef CONFIG_COMPAT
9853 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
9854 + unsigned int cmd, unsigned long arg)
9858 +#endif /* __KERNEL__ */
9859 +#endif /* __AUFS_DIR_H__ */
9860 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dynop.c linux-4.4/fs/aufs/dynop.c
9861 --- linux-4.4/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
9862 +++ linux-4.4/fs/aufs/dynop.c 2021-02-24 17:28:14.402141395 +0100
9865 + * Copyright (C) 2010-2016 Junjiro R. Okajima
9867 + * This program, aufs is free software; you can redistribute it and/or modify
9868 + * it under the terms of the GNU General Public License as published by
9869 + * the Free Software Foundation; either version 2 of the License, or
9870 + * (at your option) any later version.
9872 + * This program is distributed in the hope that it will be useful,
9873 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9874 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9875 + * GNU General Public License for more details.
9877 + * You should have received a copy of the GNU General Public License
9878 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9882 + * dynamically customizable operations for regular files
9887 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9890 + * How large will these lists be?
9891 + * Usually just a few elements, 20-30 at most for each, I guess.
9893 +static struct au_splhead dynop[AuDyLast];
9895 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9897 + struct au_dykey *key, *tmp;
9898 + struct list_head *head;
9901 + head = &spl->head;
9903 + list_for_each_entry_rcu(tmp, head, dk_list)
9904 + if (tmp->dk_op.dy_hop == h_op) {
9906 + kref_get(&key->dk_kref);
9909 + rcu_read_unlock();
9914 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
9916 + struct au_dykey **k, *found;
9917 + const void *h_op = key->dk_op.dy_hop;
9922 + for (i = 0; i < AuBrDynOp; i++)
9924 + if (k[i]->dk_op.dy_hop == h_op) {
9931 + spin_lock(&br->br_dykey_lock);
9932 + for (; i < AuBrDynOp; i++)
9934 + if (k[i]->dk_op.dy_hop == h_op) {
9942 + spin_unlock(&br->br_dykey_lock);
9943 + BUG_ON(i == AuBrDynOp); /* expand the array */
9949 +/* kref_get() if @key is already added */
9950 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
9952 + struct au_dykey *tmp, *found;
9953 + struct list_head *head;
9954 + const void *h_op = key->dk_op.dy_hop;
9957 + head = &spl->head;
9958 + spin_lock(&spl->spin);
9959 + list_for_each_entry(tmp, head, dk_list)
9960 + if (tmp->dk_op.dy_hop == h_op) {
9961 + kref_get(&tmp->dk_kref);
9966 + list_add_rcu(&key->dk_list, head);
9967 + spin_unlock(&spl->spin);
9974 +static void dy_free_rcu(struct rcu_head *rcu)
9976 + struct au_dykey *key;
9978 + key = container_of(rcu, struct au_dykey, dk_rcu);
9983 +static void dy_free(struct kref *kref)
9985 + struct au_dykey *key;
9986 + struct au_splhead *spl;
9988 + key = container_of(kref, struct au_dykey, dk_kref);
9989 + spl = dynop + key->dk_op.dy_type;
9990 + au_spl_del_rcu(&key->dk_list, spl);
9991 + call_rcu(&key->dk_rcu, dy_free_rcu);
9994 +void au_dy_put(struct au_dykey *key)
9996 + kref_put(&key->dk_kref, dy_free);
9999 +/* ---------------------------------------------------------------------- */
10001 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10003 +#ifdef CONFIG_AUFS_DEBUG
10004 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10005 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10007 +#define DyDbgDeclare(cnt) do {} while (0)
10008 +#define DyDbgInc(cnt) do {} while (0)
10011 +#define DySet(func, dst, src, h_op, h_sb) do { \
10013 + if (h_op->func) { \
10015 + dst.func = src.func; \
10017 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10021 +#define DySetForce(func, dst, src) do { \
10022 + AuDebugOn(!src.func); \
10024 + dst.func = src.func; \
10027 +#define DySetAop(func) \
10028 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10029 +#define DySetAopForce(func) \
10030 + DySetForce(func, dyaop->da_op, aufs_aop)
10032 +static void dy_aop(struct au_dykey *key, const void *h_op,
10033 + struct super_block *h_sb __maybe_unused)
10035 + struct au_dyaop *dyaop = (void *)key;
10036 + const struct address_space_operations *h_aop = h_op;
10037 + DyDbgDeclare(cnt);
10039 + AuDbg("%s\n", au_sbtype(h_sb));
10041 + DySetAop(writepage);
10042 + DySetAopForce(readpage); /* force */
10043 + DySetAop(writepages);
10044 + DySetAop(set_page_dirty);
10045 + DySetAop(readpages);
10046 + DySetAop(write_begin);
10047 + DySetAop(write_end);
10049 + DySetAop(invalidatepage);
10050 + DySetAop(releasepage);
10051 + DySetAop(freepage);
10052 + /* this one will be changed according to an aufs mount option */
10053 + DySetAop(direct_IO);
10054 + DySetAop(migratepage);
10055 + DySetAop(launder_page);
10056 + DySetAop(is_partially_uptodate);
10057 + DySetAop(is_dirty_writeback);
10058 + DySetAop(error_remove_page);
10059 + DySetAop(swap_activate);
10060 + DySetAop(swap_deactivate);
10062 + DyDbgSize(cnt, *h_aop);
10065 +/* ---------------------------------------------------------------------- */
10067 +static void dy_bug(struct kref *kref)
10072 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10074 + struct au_dykey *key, *old;
10075 + struct au_splhead *spl;
10078 + void (*set)(struct au_dykey *key, const void *h_op,
10079 + struct super_block *h_sb __maybe_unused);
10081 + static const struct op a[] = {
10083 + .sz = sizeof(struct au_dyaop),
10087 + const struct op *p;
10089 + spl = dynop + op->dy_type;
10090 + key = dy_gfind_get(spl, op->dy_hop);
10092 + goto out_add; /* success */
10094 + p = a + op->dy_type;
10095 + key = kzalloc(p->sz, GFP_NOFS);
10096 + if (unlikely(!key)) {
10097 + key = ERR_PTR(-ENOMEM);
10101 + key->dk_op.dy_hop = op->dy_hop;
10102 + kref_init(&key->dk_kref);
10103 + p->set(key, op->dy_hop, au_br_sb(br));
10104 + old = dy_gadd(spl, key);
10111 + old = dy_bradd(br, key);
10113 + /* its ref-count should never be zero here */
10114 + kref_put(&key->dk_kref, dy_bug);
10119 +/* ---------------------------------------------------------------------- */
10121 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10122 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10123 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10124 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10125 + * See the aufs manual in detail.
10127 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10130 + dyaop->da_op.direct_IO = NULL;
10132 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10135 +static struct au_dyaop *dy_aget(struct au_branch *br,
10136 + const struct address_space_operations *h_aop,
10139 + struct au_dyaop *dyaop;
10140 + struct au_dynop op;
10142 + op.dy_type = AuDy_AOP;
10143 + op.dy_haop = h_aop;
10144 + dyaop = (void *)dy_get(&op, br);
10145 + if (IS_ERR(dyaop))
10147 + dy_adx(dyaop, do_dx);
10153 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10154 + struct inode *h_inode)
10157 + struct super_block *sb;
10158 + struct au_branch *br;
10159 + struct au_dyaop *dyaop;
10161 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10162 + IiMustWriteLock(inode);
10164 + sb = inode->i_sb;
10165 + br = au_sbr(sb, bindex);
10166 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10167 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10168 + err = PTR_ERR(dyaop);
10169 + if (IS_ERR(dyaop))
10170 + /* unnecessary to call dy_fput() */
10174 + inode->i_mapping->a_ops = &dyaop->da_op;
10181 + * Is it safe to replace a_ops during the inode/file is in operation?
10182 + * Yes, I hope so.
10184 +int au_dy_irefresh(struct inode *inode)
10187 + aufs_bindex_t bstart;
10188 + struct inode *h_inode;
10191 + if (S_ISREG(inode->i_mode)) {
10192 + bstart = au_ibstart(inode);
10193 + h_inode = au_h_iptr(inode, bstart);
10194 + err = au_dy_iaop(inode, bstart, h_inode);
10199 +void au_dy_arefresh(int do_dx)
10201 + struct au_splhead *spl;
10202 + struct list_head *head;
10203 + struct au_dykey *key;
10205 + spl = dynop + AuDy_AOP;
10206 + head = &spl->head;
10207 + spin_lock(&spl->spin);
10208 + list_for_each_entry(key, head, dk_list)
10209 + dy_adx((void *)key, do_dx);
10210 + spin_unlock(&spl->spin);
10213 +/* ---------------------------------------------------------------------- */
10215 +void __init au_dy_init(void)
10219 + /* make sure that 'struct au_dykey *' can be any type */
10220 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10222 + for (i = 0; i < AuDyLast; i++)
10223 + au_spl_init(dynop + i);
10226 +void au_dy_fin(void)
10230 + for (i = 0; i < AuDyLast; i++)
10231 + WARN_ON(!list_empty(&dynop[i].head));
10233 diff -urNp -x '*.orig' linux-4.4/fs/aufs/dynop.h linux-4.4/fs/aufs/dynop.h
10234 --- linux-4.4/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10235 +++ linux-4.4/fs/aufs/dynop.h 2021-02-24 17:28:14.402141395 +0100
10238 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10240 + * This program, aufs is free software; you can redistribute it and/or modify
10241 + * it under the terms of the GNU General Public License as published by
10242 + * the Free Software Foundation; either version 2 of the License, or
10243 + * (at your option) any later version.
10245 + * This program is distributed in the hope that it will be useful,
10246 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10247 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10248 + * GNU General Public License for more details.
10250 + * You should have received a copy of the GNU General Public License
10251 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10255 + * dynamically customizable operations (for regular files only)
10258 +#ifndef __AUFS_DYNOP_H__
10259 +#define __AUFS_DYNOP_H__
10263 +#include <linux/fs.h>
10264 +#include <linux/kref.h>
10266 +enum {AuDy_AOP, AuDyLast};
10271 + const void *dy_hop;
10272 + const struct address_space_operations *dy_haop;
10278 + struct list_head dk_list;
10279 + struct rcu_head dk_rcu;
10281 + struct au_dynop dk_op;
10284 + * during I am in the branch local array, kref is gotten. when the
10285 + * branch is removed, kref is put.
10287 + struct kref dk_kref;
10290 +/* stop unioning since their sizes are very different from each other */
10292 + struct au_dykey da_key;
10293 + struct address_space_operations da_op; /* not const */
10296 +/* ---------------------------------------------------------------------- */
10300 +void au_dy_put(struct au_dykey *key);
10301 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10302 + struct inode *h_inode);
10303 +int au_dy_irefresh(struct inode *inode);
10304 +void au_dy_arefresh(int do_dio);
10306 +void __init au_dy_init(void);
10307 +void au_dy_fin(void);
10309 +#endif /* __KERNEL__ */
10310 +#endif /* __AUFS_DYNOP_H__ */
10311 diff -urNp -x '*.orig' linux-4.4/fs/aufs/export.c linux-4.4/fs/aufs/export.c
10312 --- linux-4.4/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10313 +++ linux-4.4/fs/aufs/export.c 2021-02-24 17:28:14.402141395 +0100
10316 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10318 + * This program, aufs is free software; you can redistribute it and/or modify
10319 + * it under the terms of the GNU General Public License as published by
10320 + * the Free Software Foundation; either version 2 of the License, or
10321 + * (at your option) any later version.
10323 + * This program is distributed in the hope that it will be useful,
10324 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10325 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10326 + * GNU General Public License for more details.
10328 + * You should have received a copy of the GNU General Public License
10329 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10336 +#include <linux/exportfs.h>
10337 +#include <linux/fs_struct.h>
10338 +#include <linux/namei.h>
10339 +#include <linux/nsproxy.h>
10340 +#include <linux/random.h>
10341 +#include <linux/writeback.h>
10342 +#include "../fs/mount.h"
10346 +#ifdef CONFIG_AUFS_INO_T_64
10354 +static ino_t decode_ino(__u32 *a)
10358 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10360 +#ifdef CONFIG_AUFS_INO_T_64
10366 +static void encode_ino(__u32 *a, ino_t ino)
10372 +#ifdef CONFIG_AUFS_INO_T_64
10377 +/* NFS file handle */
10381 +#ifdef CONFIG_AUFS_INO_T_64
10382 + /* support 64bit inode number */
10395 + Fh_ino = Fh_ino1,
10396 + Fh_dir_ino = Fh_dir_ino1
10399 +static int au_test_anon(struct dentry *dentry)
10401 + /* note: read d_flags without d_lock */
10402 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10405 +int au_test_nfsd(void)
10408 + struct task_struct *tsk = current;
10409 + char comm[sizeof(tsk->comm)];
10412 + if (tsk->flags & PF_KTHREAD) {
10413 + get_task_comm(comm, tsk);
10414 + ret = !strcmp(comm, "nfsd");
10420 +/* ---------------------------------------------------------------------- */
10421 +/* inode generation external table */
10423 +void au_xigen_inc(struct inode *inode)
10428 + struct super_block *sb;
10429 + struct au_sbinfo *sbinfo;
10431 + sb = inode->i_sb;
10432 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10434 + sbinfo = au_sbi(sb);
10435 + pos = inode->i_ino;
10436 + pos *= sizeof(igen);
10437 + igen = inode->i_generation + 1;
10438 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10439 + sizeof(igen), &pos);
10440 + if (sz == sizeof(igen))
10441 + return; /* success */
10443 + if (unlikely(sz >= 0))
10444 + AuIOErr("xigen error (%zd)\n", sz);
10447 +int au_xigen_new(struct inode *inode)
10452 + struct super_block *sb;
10453 + struct au_sbinfo *sbinfo;
10454 + struct file *file;
10457 + /* todo: dirty, at mount time */
10458 + if (inode->i_ino == AUFS_ROOT_INO)
10460 + sb = inode->i_sb;
10461 + SiMustAnyLock(sb);
10462 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10466 + pos = inode->i_ino;
10467 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10468 + AuIOErr1("too large i%lld\n", pos);
10471 + pos *= sizeof(inode->i_generation);
10474 + sbinfo = au_sbi(sb);
10475 + file = sbinfo->si_xigen;
10478 + if (vfsub_f_size_read(file)
10479 + < pos + sizeof(inode->i_generation)) {
10480 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10481 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10482 + sizeof(inode->i_generation), &pos);
10484 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10485 + sizeof(inode->i_generation), &pos);
10486 + if (sz == sizeof(inode->i_generation))
10487 + goto out; /* success */
10490 + if (unlikely(sz >= 0)) {
10492 + AuIOErr("xigen error (%zd)\n", sz);
10499 +int au_xigen_set(struct super_block *sb, struct file *base)
10502 + struct au_sbinfo *sbinfo;
10503 + struct file *file;
10505 + SiMustWriteLock(sb);
10507 + sbinfo = au_sbi(sb);
10508 + file = au_xino_create2(base, sbinfo->si_xigen);
10509 + err = PTR_ERR(file);
10510 + if (IS_ERR(file))
10513 + if (sbinfo->si_xigen)
10514 + fput(sbinfo->si_xigen);
10515 + sbinfo->si_xigen = file;
10521 +void au_xigen_clr(struct super_block *sb)
10523 + struct au_sbinfo *sbinfo;
10525 + SiMustWriteLock(sb);
10527 + sbinfo = au_sbi(sb);
10528 + if (sbinfo->si_xigen) {
10529 + fput(sbinfo->si_xigen);
10530 + sbinfo->si_xigen = NULL;
10534 +/* ---------------------------------------------------------------------- */
10536 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10539 + struct dentry *dentry, *d;
10540 + struct inode *inode;
10541 + unsigned int sigen;
10544 + inode = ilookup(sb, ino);
10548 + dentry = ERR_PTR(-ESTALE);
10549 + sigen = au_sigen(sb);
10550 + if (unlikely(is_bad_inode(inode)
10551 + || IS_DEADDIR(inode)
10552 + || sigen != au_iigen(inode, NULL)))
10556 + if (!dir_ino || S_ISDIR(inode->i_mode))
10557 + dentry = d_find_alias(inode);
10559 + spin_lock(&inode->i_lock);
10560 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
10561 + spin_lock(&d->d_lock);
10562 + if (!au_test_anon(d)
10563 + && d_inode(d->d_parent)->i_ino == dir_ino) {
10564 + dentry = dget_dlock(d);
10565 + spin_unlock(&d->d_lock);
10568 + spin_unlock(&d->d_lock);
10570 + spin_unlock(&inode->i_lock);
10572 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10573 + /* need to refresh */
10581 + AuTraceErrPtr(dentry);
10585 +/* ---------------------------------------------------------------------- */
10587 +/* todo: dirty? */
10588 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10590 +struct au_compare_mnt_args {
10592 + struct super_block *sb;
10595 + struct vfsmount *mnt;
10598 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10600 + struct au_compare_mnt_args *a = arg;
10602 + if (mnt->mnt_sb != a->sb)
10604 + a->mnt = mntget(mnt);
10608 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10611 + struct path root;
10612 + struct au_compare_mnt_args args = {
10616 + get_fs_root(current->fs, &root);
10618 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10619 + rcu_read_unlock();
10622 + AuDebugOn(!args.mnt);
10626 +struct au_nfsd_si_lock {
10627 + unsigned int sigen;
10628 + aufs_bindex_t bindex, br_id;
10629 + unsigned char force_lock;
10632 +static int si_nfsd_read_lock(struct super_block *sb,
10633 + struct au_nfsd_si_lock *nsi_lock)
10636 + aufs_bindex_t bindex;
10638 + si_read_lock(sb, AuLock_FLUSH);
10640 + /* branch id may be wrapped around */
10642 + bindex = au_br_index(sb, nsi_lock->br_id);
10643 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
10644 + goto out; /* success */
10648 + if (!nsi_lock->force_lock)
10649 + si_read_unlock(sb);
10652 + nsi_lock->bindex = bindex;
10656 +struct find_name_by_ino {
10657 + struct dir_context ctx;
10658 + int called, found;
10665 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
10666 + loff_t offset, u64 ino, unsigned int d_type)
10668 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
10672 + if (a->ino != ino)
10675 + memcpy(a->name, name, namelen);
10676 + a->namelen = namelen;
10681 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
10682 + struct au_nfsd_si_lock *nsi_lock)
10684 + struct dentry *dentry, *parent;
10685 + struct file *file;
10686 + struct inode *dir;
10687 + struct find_name_by_ino arg = {
10689 + .actor = find_name_by_ino
10694 + parent = path->dentry;
10696 + si_read_unlock(parent->d_sb);
10697 + file = vfsub_dentry_open(path, au_dir_roflags);
10698 + dentry = (void *)file;
10699 + if (IS_ERR(file))
10702 + dentry = ERR_PTR(-ENOMEM);
10703 + arg.name = (void *)__get_free_page(GFP_NOFS);
10704 + if (unlikely(!arg.name))
10711 + err = vfsub_iterate_dir(file, &arg.ctx);
10712 + } while (!err && !arg.found && arg.called);
10713 + dentry = ERR_PTR(err);
10714 + if (unlikely(err))
10716 + /* instead of ENOENT */
10717 + dentry = ERR_PTR(-ESTALE);
10721 + /* do not call vfsub_lkup_one() */
10722 + dir = d_inode(parent);
10723 + mutex_lock(&dir->i_mutex);
10724 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
10725 + mutex_unlock(&dir->i_mutex);
10726 + AuTraceErrPtr(dentry);
10727 + if (IS_ERR(dentry))
10729 + AuDebugOn(au_test_anon(dentry));
10730 + if (unlikely(d_really_is_negative(dentry))) {
10732 + dentry = ERR_PTR(-ENOENT);
10736 + free_page((unsigned long)arg.name);
10740 + if (unlikely(nsi_lock
10741 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10742 + if (!IS_ERR(dentry)) {
10744 + dentry = ERR_PTR(-ESTALE);
10746 + AuTraceErrPtr(dentry);
10750 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
10752 + struct au_nfsd_si_lock *nsi_lock)
10754 + struct dentry *dentry;
10755 + struct path path;
10757 + if (dir_ino != AUFS_ROOT_INO) {
10758 + path.dentry = decode_by_ino(sb, dir_ino, 0);
10759 + dentry = path.dentry;
10760 + if (!path.dentry || IS_ERR(path.dentry))
10762 + AuDebugOn(au_test_anon(path.dentry));
10764 + path.dentry = dget(sb->s_root);
10766 + path.mnt = au_mnt_get(sb);
10767 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
10771 + AuTraceErrPtr(dentry);
10775 +/* ---------------------------------------------------------------------- */
10777 +static int h_acceptable(void *expv, struct dentry *dentry)
10782 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
10783 + char *buf, int len, struct super_block *sb)
10787 + struct path path;
10789 + p = d_path(h_rootpath, buf, len);
10794 + path.mnt = h_rootpath->mnt;
10795 + path.dentry = h_parent;
10796 + p = d_path(&path, buf, len);
10802 + path.mnt = au_mnt_get(sb);
10803 + path.dentry = sb->s_root;
10804 + p = d_path(&path, buf, len - strlen(p));
10805 + mntput(path.mnt);
10809 + p[strlen(p)] = '/';
10812 + AuTraceErrPtr(p);
10817 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
10818 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
10820 + struct dentry *dentry, *h_parent, *root;
10821 + struct super_block *h_sb;
10822 + char *pathname, *p;
10823 + struct vfsmount *h_mnt;
10824 + struct au_branch *br;
10826 + struct path path;
10828 + br = au_sbr(sb, nsi_lock->bindex);
10829 + h_mnt = au_br_mnt(br);
10830 + h_sb = h_mnt->mnt_sb;
10831 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
10832 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
10833 + fh_len - Fh_tail, fh[Fh_h_type],
10834 + h_acceptable, /*context*/NULL);
10835 + dentry = h_parent;
10836 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
10837 + AuWarn1("%s decode_fh failed, %ld\n",
10838 + au_sbtype(h_sb), PTR_ERR(h_parent));
10842 + if (unlikely(au_test_anon(h_parent))) {
10843 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
10844 + au_sbtype(h_sb));
10845 + goto out_h_parent;
10848 + dentry = ERR_PTR(-ENOMEM);
10849 + pathname = (void *)__get_free_page(GFP_NOFS);
10850 + if (unlikely(!pathname))
10851 + goto out_h_parent;
10853 + root = sb->s_root;
10854 + path.mnt = h_mnt;
10855 + di_read_lock_parent(root, !AuLock_IR);
10856 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
10857 + di_read_unlock(root, !AuLock_IR);
10858 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
10859 + dentry = (void *)p;
10861 + goto out_pathname;
10863 + si_read_unlock(sb);
10864 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
10865 + dentry = ERR_PTR(err);
10866 + if (unlikely(err))
10869 + dentry = ERR_PTR(-ENOENT);
10870 + AuDebugOn(au_test_anon(path.dentry));
10871 + if (unlikely(d_really_is_negative(path.dentry)))
10874 + if (ino != d_inode(path.dentry)->i_ino)
10875 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10877 + dentry = dget(path.dentry);
10882 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10883 + if (!IS_ERR(dentry)) {
10885 + dentry = ERR_PTR(-ESTALE);
10888 + free_page((unsigned long)pathname);
10892 + AuTraceErrPtr(dentry);
10896 +/* ---------------------------------------------------------------------- */
10898 +static struct dentry *
10899 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
10902 + struct dentry *dentry;
10903 + __u32 *fh = fid->raw;
10904 + struct au_branch *br;
10905 + ino_t ino, dir_ino;
10906 + struct au_nfsd_si_lock nsi_lock = {
10910 + dentry = ERR_PTR(-ESTALE);
10911 + /* it should never happen, but the file handle is unreliable */
10912 + if (unlikely(fh_len < Fh_tail))
10914 + nsi_lock.sigen = fh[Fh_sigen];
10915 + nsi_lock.br_id = fh[Fh_br_id];
10917 + /* branch id may be wrapped around */
10919 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
10921 + nsi_lock.force_lock = 1;
10923 + /* is this inode still cached? */
10924 + ino = decode_ino(fh + Fh_ino);
10925 + /* it should never happen */
10926 + if (unlikely(ino == AUFS_ROOT_INO))
10929 + dir_ino = decode_ino(fh + Fh_dir_ino);
10930 + dentry = decode_by_ino(sb, ino, dir_ino);
10931 + if (IS_ERR(dentry))
10936 + /* is the parent dir cached? */
10937 + br = au_sbr(sb, nsi_lock.bindex);
10938 + atomic_inc(&br->br_count);
10939 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
10940 + if (IS_ERR(dentry))
10945 + /* lookup path */
10946 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
10947 + if (IS_ERR(dentry))
10949 + if (unlikely(!dentry))
10950 + /* todo?: make it ESTALE */
10954 + if (!au_digen_test(dentry, au_sigen(sb))
10955 + && d_inode(dentry)->i_generation == fh[Fh_igen])
10956 + goto out_unlock; /* success */
10959 + dentry = ERR_PTR(-ESTALE);
10962 + atomic_dec(&br->br_count);
10963 + si_read_unlock(sb);
10965 + AuTraceErrPtr(dentry);
10969 +#if 0 /* reserved for future use */
10970 +/* support subtreecheck option */
10971 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
10972 + int fh_len, int fh_type)
10974 + struct dentry *parent;
10975 + __u32 *fh = fid->raw;
10978 + dir_ino = decode_ino(fh + Fh_dir_ino);
10979 + parent = decode_by_ino(sb, dir_ino, 0);
10980 + if (IS_ERR(parent))
10983 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
10984 + dir_ino, fh, fh_len);
10987 + AuTraceErrPtr(parent);
10992 +/* ---------------------------------------------------------------------- */
10994 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
10995 + struct inode *dir)
10998 + aufs_bindex_t bindex;
10999 + struct super_block *sb, *h_sb;
11000 + struct dentry *dentry, *parent, *h_parent;
11001 + struct inode *h_dir;
11002 + struct au_branch *br;
11005 + if (unlikely(*max_len <= Fh_tail)) {
11006 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11010 + err = FILEID_ROOT;
11011 + if (inode->i_ino == AUFS_ROOT_INO) {
11012 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11017 + sb = inode->i_sb;
11018 + err = si_read_lock(sb, AuLock_FLUSH);
11019 + if (unlikely(err))
11022 +#ifdef CONFIG_AUFS_DEBUG
11023 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11024 + AuWarn1("NFS-exporting requires xino\n");
11028 + ii_read_lock_child(inode);
11029 + bindex = au_ibstart(inode);
11031 + dentry = d_find_any_alias(inode);
11032 + if (unlikely(!dentry))
11034 + AuDebugOn(au_test_anon(dentry));
11035 + parent = dget_parent(dentry);
11037 + if (unlikely(!parent))
11039 + if (d_really_is_positive(parent))
11040 + dir = d_inode(parent);
11043 + ii_read_lock_parent(dir);
11044 + h_dir = au_h_iptr(dir, bindex);
11045 + ii_read_unlock(dir);
11046 + if (unlikely(!h_dir))
11048 + h_parent = d_find_any_alias(h_dir);
11049 + if (unlikely(!h_parent))
11050 + goto out_hparent;
11053 + br = au_sbr(sb, bindex);
11054 + h_sb = au_br_sb(br);
11055 + if (unlikely(!h_sb->s_export_op)) {
11056 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11057 + goto out_hparent;
11060 + fh[Fh_br_id] = br->br_id;
11061 + fh[Fh_sigen] = au_sigen(sb);
11062 + encode_ino(fh + Fh_ino, inode->i_ino);
11063 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11064 + fh[Fh_igen] = inode->i_generation;
11066 + *max_len -= Fh_tail;
11067 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11069 + /*connectable or subtreecheck*/0);
11070 + err = fh[Fh_h_type];
11071 + *max_len += Fh_tail;
11072 + /* todo: macros? */
11073 + if (err != FILEID_INVALID)
11076 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11083 + ii_read_unlock(inode);
11084 + si_read_unlock(sb);
11086 + if (unlikely(err < 0))
11087 + err = FILEID_INVALID;
11091 +/* ---------------------------------------------------------------------- */
11093 +static int aufs_commit_metadata(struct inode *inode)
11096 + aufs_bindex_t bindex;
11097 + struct super_block *sb;
11098 + struct inode *h_inode;
11099 + int (*f)(struct inode *inode);
11101 + sb = inode->i_sb;
11102 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11103 + ii_write_lock_child(inode);
11104 + bindex = au_ibstart(inode);
11105 + AuDebugOn(bindex < 0);
11106 + h_inode = au_h_iptr(inode, bindex);
11108 + f = h_inode->i_sb->s_export_op->commit_metadata;
11110 + err = f(h_inode);
11112 + struct writeback_control wbc = {
11113 + .sync_mode = WB_SYNC_ALL,
11114 + .nr_to_write = 0 /* metadata only */
11117 + err = sync_inode(h_inode, &wbc);
11120 + au_cpup_attr_timesizes(inode);
11121 + ii_write_unlock(inode);
11122 + si_read_unlock(sb);
11126 +/* ---------------------------------------------------------------------- */
11128 +static struct export_operations aufs_export_op = {
11129 + .fh_to_dentry = aufs_fh_to_dentry,
11130 + /* .fh_to_parent = aufs_fh_to_parent, */
11131 + .encode_fh = aufs_encode_fh,
11132 + .commit_metadata = aufs_commit_metadata
11135 +void au_export_init(struct super_block *sb)
11137 + struct au_sbinfo *sbinfo;
11140 + sb->s_export_op = &aufs_export_op;
11141 + sbinfo = au_sbi(sb);
11142 + sbinfo->si_xigen = NULL;
11143 + get_random_bytes(&u, sizeof(u));
11144 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11145 + atomic_set(&sbinfo->si_xigen_next, u);
11147 diff -urNp -x '*.orig' linux-4.4/fs/aufs/f_op.c linux-4.4/fs/aufs/f_op.c
11148 --- linux-4.4/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
11149 +++ linux-4.4/fs/aufs/f_op.c 2021-02-24 17:28:14.418808602 +0100
11152 + * Copyright (C) 2005-2016 Junjiro R. Okajima
11154 + * This program, aufs is free software; you can redistribute it and/or modify
11155 + * it under the terms of the GNU General Public License as published by
11156 + * the Free Software Foundation; either version 2 of the License, or
11157 + * (at your option) any later version.
11159 + * This program is distributed in the hope that it will be useful,
11160 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11161 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11162 + * GNU General Public License for more details.
11164 + * You should have received a copy of the GNU General Public License
11165 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11169 + * file and vm operations
11172 +#include <linux/aio.h>
11173 +#include <linux/fs_stack.h>
11174 +#include <linux/mman.h>
11175 +#include <linux/security.h>
11178 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
11181 + aufs_bindex_t bindex;
11182 + struct dentry *dentry, *h_dentry;
11183 + struct au_finfo *finfo;
11184 + struct inode *h_inode;
11186 + FiMustWriteLock(file);
11189 + dentry = file->f_path.dentry;
11190 + AuDebugOn(IS_ERR_OR_NULL(dentry));
11191 + finfo = au_fi(file);
11192 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
11193 + atomic_set(&finfo->fi_mmapped, 0);
11194 + bindex = au_dbstart(dentry);
11196 + h_dentry = au_h_dptr(dentry, bindex);
11197 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
11198 + if (unlikely(err))
11200 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
11202 + h_dentry = h_file->f_path.dentry;
11203 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
11204 + if (unlikely(err))
11206 + get_file(h_file);
11208 + if (IS_ERR(h_file))
11209 + err = PTR_ERR(h_file);
11211 + if ((flags & __O_TMPFILE)
11212 + && !(flags & O_EXCL)) {
11213 + h_inode = file_inode(h_file);
11214 + spin_lock(&h_inode->i_lock);
11215 + h_inode->i_state |= I_LINKABLE;
11216 + spin_unlock(&h_inode->i_lock);
11218 + au_set_fbstart(file, bindex);
11219 + au_set_h_fptr(file, bindex, h_file);
11220 + au_update_figen(file);
11221 + /* todo: necessary? */
11222 + /* file->f_ra = h_file->f_ra; */
11229 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
11230 + struct file *file)
11233 + struct super_block *sb;
11234 + struct au_do_open_args args = {
11235 + .open = au_do_open_nondir
11238 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
11239 + file, vfsub_file_flags(file), file->f_mode);
11241 + sb = file->f_path.dentry->d_sb;
11242 + si_read_lock(sb, AuLock_FLUSH);
11243 + err = au_do_open(file, &args);
11244 + si_read_unlock(sb);
11248 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
11250 + struct au_finfo *finfo;
11251 + aufs_bindex_t bindex;
11253 + finfo = au_fi(file);
11254 + au_sphl_del(&finfo->fi_hlist,
11255 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
11256 + bindex = finfo->fi_btop;
11258 + au_set_h_fptr(file, bindex, NULL);
11260 + au_finfo_fin(file);
11264 +/* ---------------------------------------------------------------------- */
11266 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
11269 + struct file *h_file;
11272 + h_file = au_hf_top(file);
11274 + err = vfsub_flush(h_file, id);
11278 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
11280 + return au_do_flush(file, id, au_do_flush_nondir);
11283 +/* ---------------------------------------------------------------------- */
11285 + * read and write functions acquire [fdi]_rwsem once, but release before
11286 + * mmap_sem. This is because to stop a race condition between mmap(2).
11287 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
11288 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
11289 + * read functions after [fdi]_rwsem are released, but it should be harmless.
11292 +/* Callers should call au_read_post() or fput() in the end */
11293 +struct file *au_read_pre(struct file *file, int keep_fi)
11295 + struct file *h_file;
11298 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
11300 + di_read_unlock(file->f_path.dentry, AuLock_IR);
11301 + h_file = au_hf_top(file);
11302 + get_file(h_file);
11304 + fi_read_unlock(file);
11306 + h_file = ERR_PTR(err);
11311 +static void au_read_post(struct inode *inode, struct file *h_file)
11313 + /* update without lock, I don't think it a problem */
11314 + fsstack_copy_attr_atime(inode, file_inode(h_file));
11318 +struct au_write_pre {
11320 + aufs_bindex_t bstart;
11324 + * return with iinfo is write-locked
11325 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
11328 +static struct file *au_write_pre(struct file *file, int do_ready,
11329 + struct au_write_pre *wpre)
11331 + struct file *h_file;
11332 + struct dentry *dentry;
11334 + struct au_pin pin;
11336 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
11337 + h_file = ERR_PTR(err);
11338 + if (unlikely(err))
11341 + dentry = file->f_path.dentry;
11343 + err = au_ready_to_write(file, -1, &pin);
11344 + if (unlikely(err)) {
11345 + h_file = ERR_PTR(err);
11346 + di_write_unlock(dentry);
11351 + di_downgrade_lock(dentry, /*flags*/0);
11353 + wpre->bstart = au_fbstart(file);
11354 + h_file = au_hf_top(file);
11355 + get_file(h_file);
11357 + wpre->blks = file_inode(h_file)->i_blocks;
11360 + di_read_unlock(dentry, /*flags*/0);
11363 + fi_write_unlock(file);
11368 +static void au_write_post(struct inode *inode, struct file *h_file,
11369 + struct au_write_pre *wpre, ssize_t written)
11371 + struct inode *h_inode;
11373 + au_cpup_attr_timesizes(inode);
11374 + AuDebugOn(au_ibstart(inode) != wpre->bstart);
11375 + h_inode = file_inode(h_file);
11376 + inode->i_mode = h_inode->i_mode;
11377 + ii_write_unlock(inode);
11380 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
11382 + au_fhsm_wrote(inode->i_sb, wpre->bstart,
11383 + /*force*/h_inode->i_blocks > wpre->blks);
11386 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
11390 + struct inode *inode;
11391 + struct file *h_file;
11392 + struct super_block *sb;
11394 + inode = file_inode(file);
11395 + sb = inode->i_sb;
11396 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11398 + h_file = au_read_pre(file, /*keep_fi*/0);
11399 + err = PTR_ERR(h_file);
11400 + if (IS_ERR(h_file))
11403 + /* filedata may be obsoleted by concurrent copyup, but no problem */
11404 + err = vfsub_read_u(h_file, buf, count, ppos);
11405 + /* todo: necessary? */
11406 + /* file->f_ra = h_file->f_ra; */
11407 + au_read_post(inode, h_file);
11410 + si_read_unlock(sb);
11415 + * todo: very ugly
11416 + * it locks both of i_mutex and si_rwsem for read in safe.
11417 + * if the plink maintenance mode continues forever (that is the problem),
11418 + * may loop forever.
11420 +static void au_mtx_and_read_lock(struct inode *inode)
11423 + struct super_block *sb = inode->i_sb;
11426 + mutex_lock(&inode->i_mutex);
11427 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
11430 + mutex_unlock(&inode->i_mutex);
11431 + si_read_lock(sb, AuLock_NOPLMW);
11432 + si_read_unlock(sb);
11436 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
11437 + size_t count, loff_t *ppos)
11440 + struct au_write_pre wpre;
11441 + struct inode *inode;
11442 + struct file *h_file;
11443 + char __user *buf = (char __user *)ubuf;
11445 + inode = file_inode(file);
11446 + au_mtx_and_read_lock(inode);
11448 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
11449 + err = PTR_ERR(h_file);
11450 + if (IS_ERR(h_file))
11453 + err = vfsub_write_u(h_file, buf, count, ppos);
11454 + au_write_post(inode, h_file, &wpre, err);
11457 + si_read_unlock(inode->i_sb);
11458 + mutex_unlock(&inode->i_mutex);
11462 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
11463 + struct iov_iter *iov_iter)
11466 + struct file *file;
11467 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
11469 + err = security_file_permission(h_file, rw);
11470 + if (unlikely(err))
11475 + if (rw == MAY_READ)
11476 + iter = h_file->f_op->read_iter;
11477 + else if (rw == MAY_WRITE)
11478 + iter = h_file->f_op->write_iter;
11480 + file = kio->ki_filp;
11481 + kio->ki_filp = h_file;
11484 + err = iter(kio, iov_iter);
11487 + /* currently there is no such fs */
11489 + kio->ki_filp = file;
11495 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
11498 + struct file *file, *h_file;
11499 + struct inode *inode;
11500 + struct super_block *sb;
11502 + file = kio->ki_filp;
11503 + inode = file_inode(file);
11504 + sb = inode->i_sb;
11505 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11507 + h_file = au_read_pre(file, /*keep_fi*/0);
11508 + err = PTR_ERR(h_file);
11509 + if (IS_ERR(h_file))
11512 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
11513 + /* todo: necessary? */
11514 + /* file->f_ra = h_file->f_ra; */
11515 + au_read_post(inode, h_file);
11518 + si_read_unlock(sb);
11522 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
11525 + struct au_write_pre wpre;
11526 + struct inode *inode;
11527 + struct file *file, *h_file;
11529 + file = kio->ki_filp;
11530 + inode = file_inode(file);
11531 + au_mtx_and_read_lock(inode);
11533 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
11534 + err = PTR_ERR(h_file);
11535 + if (IS_ERR(h_file))
11538 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
11539 + au_write_post(inode, h_file, &wpre, err);
11542 + si_read_unlock(inode->i_sb);
11543 + mutex_unlock(&inode->i_mutex);
11547 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
11548 + struct pipe_inode_info *pipe, size_t len,
11549 + unsigned int flags)
11552 + struct file *h_file;
11553 + struct inode *inode;
11554 + struct super_block *sb;
11556 + inode = file_inode(file);
11557 + sb = inode->i_sb;
11558 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11560 + h_file = au_read_pre(file, /*keep_fi*/1);
11561 + err = PTR_ERR(h_file);
11562 + if (IS_ERR(h_file))
11565 + if (0 && au_test_loopback_kthread()) {
11566 + au_warn_loopback(h_file->f_path.dentry->d_sb);
11567 + if (file->f_mapping != h_file->f_mapping) {
11568 + file->f_mapping = h_file->f_mapping;
11569 + smp_mb(); /* unnecessary? */
11572 + fi_read_unlock(file);
11574 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
11575 + /* todo: necessasry? */
11576 + /* file->f_ra = h_file->f_ra; */
11577 + au_read_post(inode, h_file);
11580 + si_read_unlock(sb);
11585 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
11586 + size_t len, unsigned int flags)
11589 + struct au_write_pre wpre;
11590 + struct inode *inode;
11591 + struct file *h_file;
11593 + inode = file_inode(file);
11594 + au_mtx_and_read_lock(inode);
11596 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
11597 + err = PTR_ERR(h_file);
11598 + if (IS_ERR(h_file))
11601 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
11602 + au_write_post(inode, h_file, &wpre, err);
11605 + si_read_unlock(inode->i_sb);
11606 + mutex_unlock(&inode->i_mutex);
11610 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
11614 + struct au_write_pre wpre;
11615 + struct inode *inode;
11616 + struct file *h_file;
11618 + inode = file_inode(file);
11619 + au_mtx_and_read_lock(inode);
11621 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
11622 + err = PTR_ERR(h_file);
11623 + if (IS_ERR(h_file))
11627 + err = vfs_fallocate(h_file, mode, offset, len);
11629 + au_write_post(inode, h_file, &wpre, /*written*/1);
11632 + si_read_unlock(inode->i_sb);
11633 + mutex_unlock(&inode->i_mutex);
11637 +/* ---------------------------------------------------------------------- */
11640 + * The locking order around current->mmap_sem.
11641 + * - in most and regular cases
11642 + * file I/O syscall -- aufs_read() or something
11643 + * -- si_rwsem for read -- mmap_sem
11644 + * (Note that [fdi]i_rwsem are released before mmap_sem).
11646 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
11647 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
11648 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
11649 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
11650 + * It means that when aufs acquires si_rwsem for write, the process should never
11651 + * acquire mmap_sem.
11653 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
11654 + * problem either since any directory is not able to be mmap-ed.
11655 + * The similar scenario is applied to aufs_readlink() too.
11658 +#if 0 /* stop calling security_file_mmap() */
11659 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
11660 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
11662 +static unsigned long au_arch_prot_conv(unsigned long flags)
11664 + /* currently ppc64 only */
11665 +#ifdef CONFIG_PPC64
11666 + /* cf. linux/arch/powerpc/include/asm/mman.h */
11667 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
11668 + return AuConv_VM_PROT(flags, SAO);
11670 + AuDebugOn(arch_calc_vm_prot_bits(-1));
11675 +static unsigned long au_prot_conv(unsigned long flags)
11677 + return AuConv_VM_PROT(flags, READ)
11678 + | AuConv_VM_PROT(flags, WRITE)
11679 + | AuConv_VM_PROT(flags, EXEC)
11680 + | au_arch_prot_conv(flags);
11683 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
11684 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
11686 +static unsigned long au_flag_conv(unsigned long flags)
11688 + return AuConv_VM_MAP(flags, GROWSDOWN)
11689 + | AuConv_VM_MAP(flags, DENYWRITE)
11690 + | AuConv_VM_MAP(flags, LOCKED);
11694 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
11697 + const unsigned char wlock
11698 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
11699 + struct super_block *sb;
11700 + struct file *h_file;
11701 + struct inode *inode;
11703 + AuDbgVmRegion(file, vma);
11705 + inode = file_inode(file);
11706 + sb = inode->i_sb;
11708 + si_read_lock(sb, AuLock_NOPLMW);
11710 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
11712 + err = PTR_ERR(h_file);
11713 + if (IS_ERR(h_file))
11717 + au_set_mmapped(file);
11718 + au_vm_file_reset(vma, h_file);
11720 + * we cannot call security_mmap_file() here since it may acquire
11721 + * mmap_sem or i_mutex.
11723 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
11724 + * au_flag_conv(vma->vm_flags));
11727 + err = h_file->f_op->mmap(h_file, vma);
11729 + au_vm_prfile_set(vma, file);
11730 + fsstack_copy_attr_atime(inode, file_inode(h_file));
11731 + goto out_fput; /* success */
11733 + au_unset_mmapped(file);
11734 + au_vm_file_reset(vma, file);
11738 + ii_write_unlock(inode);
11743 + si_read_unlock(sb);
11749 +/* ---------------------------------------------------------------------- */
11751 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
11755 + struct au_write_pre wpre;
11756 + struct inode *inode;
11757 + struct file *h_file;
11759 + err = 0; /* -EBADF; */ /* posix? */
11760 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
11763 + inode = file_inode(file);
11764 + au_mtx_and_read_lock(inode);
11766 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
11767 + err = PTR_ERR(h_file);
11768 + if (IS_ERR(h_file))
11771 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
11772 + au_write_post(inode, h_file, &wpre, /*written*/0);
11775 + si_read_unlock(inode->i_sb);
11776 + mutex_unlock(&inode->i_mutex);
11781 +/* no one supports this operation, currently */
11783 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
11786 + struct au_write_pre wpre;
11787 + struct inode *inode;
11788 + struct file *file, *h_file;
11790 + err = 0; /* -EBADF; */ /* posix? */
11791 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
11794 + file = kio->ki_filp;
11795 + inode = file_inode(file);
11796 + au_mtx_and_read_lock(inode);
11798 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
11799 + err = PTR_ERR(h_file);
11800 + if (IS_ERR(h_file))
11804 + h_file = au_hf_top(file);
11805 + if (h_file->f_op->aio_fsync) {
11806 + struct mutex *h_mtx;
11808 + h_mtx = &file_inode(h_file)->i_mutex;
11809 + if (!is_sync_kiocb(kio)) {
11810 + get_file(h_file);
11813 + kio->ki_filp = h_file;
11814 + err = h_file->f_op->aio_fsync(kio, datasync);
11815 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
11817 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
11819 + mutex_unlock(h_mtx);
11821 + au_write_post(inode, h_file, &wpre, /*written*/0);
11824 + si_read_unlock(inode->sb);
11825 + mutex_unlock(&inode->i_mutex);
11831 +static int aufs_fasync(int fd, struct file *file, int flag)
11834 + struct file *h_file;
11835 + struct super_block *sb;
11837 + sb = file->f_path.dentry->d_sb;
11838 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11840 + h_file = au_read_pre(file, /*keep_fi*/0);
11841 + err = PTR_ERR(h_file);
11842 + if (IS_ERR(h_file))
11845 + if (h_file->f_op->fasync)
11846 + err = h_file->f_op->fasync(fd, h_file, flag);
11847 + fput(h_file); /* instead of au_read_post() */
11850 + si_read_unlock(sb);
11854 +/* ---------------------------------------------------------------------- */
11856 +/* no one supports this operation, currently */
11858 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
11859 + size_t len, loff_t *pos, int more)
11864 +/* ---------------------------------------------------------------------- */
11866 +const struct file_operations aufs_file_fop = {
11867 + .owner = THIS_MODULE,
11869 + .llseek = default_llseek,
11871 + .read = aufs_read,
11872 + .write = aufs_write,
11873 + .read_iter = aufs_read_iter,
11874 + .write_iter = aufs_write_iter,
11876 +#ifdef CONFIG_AUFS_POLL
11877 + .poll = aufs_poll,
11879 + .unlocked_ioctl = aufs_ioctl_nondir,
11880 +#ifdef CONFIG_COMPAT
11881 + .compat_ioctl = aufs_compat_ioctl_nondir,
11883 + .mmap = aufs_mmap,
11884 + .open = aufs_open_nondir,
11885 + .flush = aufs_flush_nondir,
11886 + .release = aufs_release_nondir,
11887 + .fsync = aufs_fsync_nondir,
11888 + /* .aio_fsync = aufs_aio_fsync_nondir, */
11889 + .fasync = aufs_fasync,
11890 + /* .sendpage = aufs_sendpage, */
11891 + .splice_write = aufs_splice_write,
11892 + .splice_read = aufs_splice_read,
11894 + .aio_splice_write = aufs_aio_splice_write,
11895 + .aio_splice_read = aufs_aio_splice_read,
11897 + .fallocate = aufs_fallocate
11899 diff -urNp -x '*.orig' linux-4.4/fs/aufs/fhsm.c linux-4.4/fs/aufs/fhsm.c
11900 --- linux-4.4/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11901 +++ linux-4.4/fs/aufs/fhsm.c 2021-02-24 17:28:14.402141395 +0100
11904 + * Copyright (C) 2011-2016 Junjiro R. Okajima
11906 + * This program, aufs is free software; you can redistribute it and/or modify
11907 + * it under the terms of the GNU General Public License as published by
11908 + * the Free Software Foundation; either version 2 of the License, or
11909 + * (at your option) any later version.
11911 + * This program is distributed in the hope that it will be useful,
11912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11914 + * GNU General Public License for more details.
11916 + * You should have received a copy of the GNU General Public License
11917 + * along with this program; if not, write to the Free Software
11918 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11922 + * File-based Hierarchy Storage Management
11925 +#include <linux/anon_inodes.h>
11926 +#include <linux/poll.h>
11927 +#include <linux/seq_file.h>
11928 +#include <linux/statfs.h>
11931 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11933 + struct au_sbinfo *sbinfo;
11934 + struct au_fhsm *fhsm;
11936 + SiMustAnyLock(sb);
11938 + sbinfo = au_sbi(sb);
11939 + fhsm = &sbinfo->si_fhsm;
11940 + AuDebugOn(!fhsm);
11941 + return fhsm->fhsm_bottom;
11944 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11946 + struct au_sbinfo *sbinfo;
11947 + struct au_fhsm *fhsm;
11949 + SiMustWriteLock(sb);
11951 + sbinfo = au_sbi(sb);
11952 + fhsm = &sbinfo->si_fhsm;
11953 + AuDebugOn(!fhsm);
11954 + fhsm->fhsm_bottom = bindex;
11957 +/* ---------------------------------------------------------------------- */
11959 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11961 + struct au_br_fhsm *bf;
11963 + bf = br->br_fhsm;
11964 + MtxMustLock(&bf->bf_lock);
11966 + return !bf->bf_readable
11967 + || time_after(jiffies,
11968 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11971 +/* ---------------------------------------------------------------------- */
11973 +static void au_fhsm_notify(struct super_block *sb, int val)
11975 + struct au_sbinfo *sbinfo;
11976 + struct au_fhsm *fhsm;
11978 + SiMustAnyLock(sb);
11980 + sbinfo = au_sbi(sb);
11981 + fhsm = &sbinfo->si_fhsm;
11982 + if (au_fhsm_pid(fhsm)
11983 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11984 + atomic_set(&fhsm->fhsm_readable, val);
11986 + wake_up(&fhsm->fhsm_wqh);
11990 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11991 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11994 + struct au_branch *br;
11995 + struct au_br_fhsm *bf;
11997 + br = au_sbr(sb, bindex);
11998 + AuDebugOn(au_br_rdonly(br));
11999 + bf = br->br_fhsm;
12003 + mutex_lock(&bf->bf_lock);
12005 + MtxMustLock(&bf->bf_lock);
12007 + /* sb->s_root for NFS is unreliable */
12008 + err = au_br_stfs(br, &bf->bf_stfs);
12009 + if (unlikely(err)) {
12010 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
12014 + bf->bf_jiffy = jiffies;
12015 + bf->bf_readable = 1;
12017 + au_fhsm_notify(sb, /*val*/1);
12019 + *rstfs = bf->bf_stfs;
12023 + mutex_unlock(&bf->bf_lock);
12024 + au_fhsm_notify(sb, /*val*/1);
12029 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
12032 + struct au_sbinfo *sbinfo;
12033 + struct au_fhsm *fhsm;
12034 + struct au_branch *br;
12035 + struct au_br_fhsm *bf;
12037 + AuDbg("b%d, force %d\n", bindex, force);
12038 + SiMustAnyLock(sb);
12040 + sbinfo = au_sbi(sb);
12041 + fhsm = &sbinfo->si_fhsm;
12042 + if (!au_ftest_si(sbinfo, FHSM)
12043 + || fhsm->fhsm_bottom == bindex)
12046 + br = au_sbr(sb, bindex);
12047 + bf = br->br_fhsm;
12049 + mutex_lock(&bf->bf_lock);
12051 + || au_fhsm_pid(fhsm)
12052 + || au_fhsm_test_jiffy(sbinfo, br))
12053 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
12055 + mutex_unlock(&bf->bf_lock);
12058 +void au_fhsm_wrote_all(struct super_block *sb, int force)
12060 + aufs_bindex_t bindex, bend;
12061 + struct au_branch *br;
12063 + /* exclude the bottom */
12064 + bend = au_fhsm_bottom(sb);
12065 + for (bindex = 0; bindex < bend; bindex++) {
12066 + br = au_sbr(sb, bindex);
12067 + if (au_br_fhsm(br->br_perm))
12068 + au_fhsm_wrote(sb, bindex, force);
12072 +/* ---------------------------------------------------------------------- */
12074 +static unsigned int au_fhsm_poll(struct file *file,
12075 + struct poll_table_struct *wait)
12077 + unsigned int mask;
12078 + struct au_sbinfo *sbinfo;
12079 + struct au_fhsm *fhsm;
12082 + sbinfo = file->private_data;
12083 + fhsm = &sbinfo->si_fhsm;
12084 + poll_wait(file, &fhsm->fhsm_wqh, wait);
12085 + if (atomic_read(&fhsm->fhsm_readable))
12086 + mask = POLLIN /* | POLLRDNORM */;
12088 + AuTraceErr((int)mask);
12092 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
12093 + struct aufs_stfs *stfs, __s16 brid)
12097 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
12099 + err = __put_user(brid, &stbr->brid);
12100 + if (unlikely(err))
12106 +static ssize_t au_fhsm_do_read(struct super_block *sb,
12107 + struct aufs_stbr __user *stbr, size_t count)
12111 + aufs_bindex_t bindex, bend;
12112 + struct au_branch *br;
12113 + struct au_br_fhsm *bf;
12115 + /* except the bottom branch */
12118 + bend = au_fhsm_bottom(sb);
12119 + for (bindex = 0; !err && bindex < bend; bindex++) {
12120 + br = au_sbr(sb, bindex);
12121 + if (!au_br_fhsm(br->br_perm))
12124 + bf = br->br_fhsm;
12125 + mutex_lock(&bf->bf_lock);
12126 + if (bf->bf_readable) {
12128 + if (count >= sizeof(*stbr))
12129 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
12132 + bf->bf_readable = 0;
12133 + count -= sizeof(*stbr);
12137 + mutex_unlock(&bf->bf_lock);
12140 + err = sizeof(*stbr) * nstbr;
12145 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
12150 + aufs_bindex_t nfhsm, bindex, bend;
12151 + struct au_sbinfo *sbinfo;
12152 + struct au_fhsm *fhsm;
12153 + struct au_branch *br;
12154 + struct super_block *sb;
12157 + sbinfo = file->private_data;
12158 + fhsm = &sbinfo->si_fhsm;
12160 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
12161 + if (!atomic_read(&fhsm->fhsm_readable)) {
12162 + if (vfsub_file_flags(file) & O_NONBLOCK)
12165 + err = wait_event_interruptible_locked_irq
12167 + atomic_read(&fhsm->fhsm_readable));
12169 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
12170 + if (unlikely(err))
12173 + /* sb may already be dead */
12174 + au_rw_read_lock(&sbinfo->si_rwsem);
12175 + readable = atomic_read(&fhsm->fhsm_readable);
12176 + if (readable > 0) {
12177 + sb = sbinfo->si_sb;
12179 + /* exclude the bottom branch */
12181 + bend = au_fhsm_bottom(sb);
12182 + for (bindex = 0; bindex < bend; bindex++) {
12183 + br = au_sbr(sb, bindex);
12184 + if (au_br_fhsm(br->br_perm))
12188 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
12189 + atomic_set(&fhsm->fhsm_readable, 0);
12190 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
12194 + au_rw_read_unlock(&sbinfo->si_rwsem);
12202 +static int au_fhsm_release(struct inode *inode, struct file *file)
12204 + struct au_sbinfo *sbinfo;
12205 + struct au_fhsm *fhsm;
12207 + /* sb may already be dead */
12208 + sbinfo = file->private_data;
12209 + fhsm = &sbinfo->si_fhsm;
12210 + spin_lock(&fhsm->fhsm_spin);
12211 + fhsm->fhsm_pid = 0;
12212 + spin_unlock(&fhsm->fhsm_spin);
12213 + kobject_put(&sbinfo->si_kobj);
12218 +static const struct file_operations au_fhsm_fops = {
12219 + .owner = THIS_MODULE,
12220 + .llseek = noop_llseek,
12221 + .read = au_fhsm_read,
12222 + .poll = au_fhsm_poll,
12223 + .release = au_fhsm_release
12226 +int au_fhsm_fd(struct super_block *sb, int oflags)
12229 + struct au_sbinfo *sbinfo;
12230 + struct au_fhsm *fhsm;
12233 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12237 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12241 + sbinfo = au_sbi(sb);
12242 + fhsm = &sbinfo->si_fhsm;
12243 + spin_lock(&fhsm->fhsm_spin);
12244 + if (!fhsm->fhsm_pid)
12245 + fhsm->fhsm_pid = current->pid;
12248 + spin_unlock(&fhsm->fhsm_spin);
12249 + if (unlikely(err))
12252 + oflags |= O_RDONLY;
12253 + /* oflags |= FMODE_NONOTIFY; */
12254 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12256 + if (unlikely(fd < 0))
12259 + /* succeed reglardless 'fhsm' status */
12260 + kobject_get(&sbinfo->si_kobj);
12261 + si_noflush_read_lock(sb);
12262 + if (au_ftest_si(sbinfo, FHSM))
12263 + au_fhsm_wrote_all(sb, /*force*/0);
12264 + si_read_unlock(sb);
12265 + goto out; /* success */
12268 + spin_lock(&fhsm->fhsm_spin);
12269 + fhsm->fhsm_pid = 0;
12270 + spin_unlock(&fhsm->fhsm_spin);
12276 +/* ---------------------------------------------------------------------- */
12278 +int au_fhsm_br_alloc(struct au_branch *br)
12283 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12285 + au_br_fhsm_init(br->br_fhsm);
12292 +/* ---------------------------------------------------------------------- */
12294 +void au_fhsm_fin(struct super_block *sb)
12296 + au_fhsm_notify(sb, /*val*/-1);
12299 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12301 + struct au_fhsm *fhsm;
12303 + fhsm = &sbinfo->si_fhsm;
12304 + spin_lock_init(&fhsm->fhsm_spin);
12305 + init_waitqueue_head(&fhsm->fhsm_wqh);
12306 + atomic_set(&fhsm->fhsm_readable, 0);
12307 + fhsm->fhsm_expire
12308 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12309 + fhsm->fhsm_bottom = -1;
12312 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12314 + sbinfo->si_fhsm.fhsm_expire
12315 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12318 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12322 + if (!au_ftest_si(sbinfo, FHSM))
12325 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12326 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12327 + seq_printf(seq, ",fhsm_sec=%u", u);
12329 diff -urNp -x '*.orig' linux-4.4/fs/aufs/file.c linux-4.4/fs/aufs/file.c
12330 --- linux-4.4/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12331 +++ linux-4.4/fs/aufs/file.c 2021-02-24 17:28:14.405474836 +0100
12334 + * Copyright (C) 2005-2016 Junjiro R. Okajima
12336 + * This program, aufs is free software; you can redistribute it and/or modify
12337 + * it under the terms of the GNU General Public License as published by
12338 + * the Free Software Foundation; either version 2 of the License, or
12339 + * (at your option) any later version.
12341 + * This program is distributed in the hope that it will be useful,
12342 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12343 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12344 + * GNU General Public License for more details.
12346 + * You should have received a copy of the GNU General Public License
12347 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12351 + * handling file/dir, and address_space operation
12354 +#ifdef CONFIG_AUFS_DEBUG
12355 +#include <linux/migrate.h>
12357 +#include <linux/pagemap.h>
12360 +/* drop flags for writing */
12361 +unsigned int au_file_roflags(unsigned int flags)
12363 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12364 + flags |= O_RDONLY | O_NOATIME;
12368 +/* common functions to regular file and dir */
12369 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12370 + struct file *file, int force_wr)
12372 + struct file *h_file;
12373 + struct dentry *h_dentry;
12374 + struct inode *h_inode;
12375 + struct super_block *sb;
12376 + struct au_branch *br;
12377 + struct path h_path;
12380 + /* a race condition can happen between open and unlink/rmdir */
12381 + h_file = ERR_PTR(-ENOENT);
12382 + h_dentry = au_h_dptr(dentry, bindex);
12383 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12385 + h_inode = d_inode(h_dentry);
12386 + spin_lock(&h_dentry->d_lock);
12387 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12388 + /* || !d_inode(dentry)->i_nlink */
12390 + spin_unlock(&h_dentry->d_lock);
12391 + if (unlikely(err))
12394 + sb = dentry->d_sb;
12395 + br = au_sbr(sb, bindex);
12396 + err = au_br_test_oflag(flags, br);
12397 + h_file = ERR_PTR(err);
12398 + if (unlikely(err))
12401 + /* drop flags for writing */
12402 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12403 + if (force_wr && !(flags & O_WRONLY))
12405 + flags = au_file_roflags(flags);
12407 + h_file = ERR_PTR(-EROFS);
12408 + flags = au_file_roflags(flags);
12409 + if (unlikely(vfsub_native_ro(h_inode)
12410 + || IS_APPEND(h_inode)))
12412 + flags &= ~O_ACCMODE;
12413 + flags |= O_WRONLY;
12416 + flags &= ~O_CREAT;
12417 + atomic_inc(&br->br_count);
12418 + h_path.dentry = h_dentry;
12419 + h_path.mnt = au_br_mnt(br);
12420 + h_file = vfsub_dentry_open(&h_path, flags);
12421 + if (IS_ERR(h_file))
12424 + if (flags & __FMODE_EXEC) {
12425 + err = deny_write_access(h_file);
12426 + if (unlikely(err)) {
12428 + h_file = ERR_PTR(err);
12432 + fsnotify_open(h_file);
12433 + goto out; /* success */
12436 + atomic_dec(&br->br_count);
12441 +static int au_cmoo(struct dentry *dentry)
12444 + unsigned int udba;
12445 + struct path h_path;
12446 + struct au_pin pin;
12447 + struct au_cp_generic cpg = {
12448 + .dentry = dentry,
12453 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12455 + struct inode *delegated;
12456 + struct super_block *sb;
12457 + struct au_sbinfo *sbinfo;
12458 + struct au_fhsm *fhsm;
12460 + struct au_branch *br;
12461 + struct dentry *parent;
12462 + struct au_hinode *hdir;
12464 + DiMustWriteLock(dentry);
12465 + IiMustWriteLock(d_inode(dentry));
12468 + if (IS_ROOT(dentry))
12470 + cpg.bsrc = au_dbstart(dentry);
12474 + sb = dentry->d_sb;
12475 + sbinfo = au_sbi(sb);
12476 + fhsm = &sbinfo->si_fhsm;
12477 + pid = au_fhsm_pid(fhsm);
12479 + && (current->pid == pid
12480 + || current->real_parent->pid == pid))
12483 + br = au_sbr(sb, cpg.bsrc);
12484 + cmoo = au_br_cmoo(br->br_perm);
12487 + if (!d_is_reg(dentry))
12488 + cmoo &= AuBrAttr_COO_ALL;
12492 + parent = dget_parent(dentry);
12493 + di_write_lock_parent(parent);
12494 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12496 + if (unlikely(err < 0)) {
12497 + err = 0; /* there is no upper writable branch */
12500 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12502 + /* do not respect the coo attrib for the target branch */
12503 + err = au_cpup_dirs(dentry, cpg.bdst);
12504 + if (unlikely(err))
12507 + di_downgrade_lock(parent, AuLock_IR);
12508 + udba = au_opt_udba(sb);
12509 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12510 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12511 + if (unlikely(err))
12514 + err = au_sio_cpup_simple(&cpg);
12516 + if (unlikely(err))
12518 + if (!(cmoo & AuBrWAttr_MOO))
12519 + goto out_parent; /* success */
12521 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12522 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12523 + if (unlikely(err))
12526 + h_path.mnt = au_br_mnt(br);
12527 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12528 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12529 + delegated = NULL;
12530 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12532 + /* todo: keep h_dentry or not? */
12533 + if (unlikely(err == -EWOULDBLOCK)) {
12534 + pr_warn("cannot retry for NFSv4 delegation"
12535 + " for an internal unlink\n");
12538 + if (unlikely(err)) {
12539 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12543 + goto out_parent; /* success */
12546 + di_downgrade_lock(parent, AuLock_IR);
12548 + di_read_unlock(parent, AuLock_IR);
12555 +int au_do_open(struct file *file, struct au_do_open_args *args)
12557 + int err, no_lock = args->no_lock;
12558 + struct dentry *dentry;
12559 + struct au_finfo *finfo;
12562 + err = au_finfo_init(file, args->fidir);
12565 + err = au_finfo_init(file, args->fidir);
12568 + if (unlikely(err))
12571 + dentry = file->f_path.dentry;
12572 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12574 + di_write_lock_child(dentry);
12575 + err = au_cmoo(dentry);
12576 + di_downgrade_lock(dentry, AuLock_IR);
12578 + err = args->open(file, vfsub_file_flags(file), NULL);
12579 + di_read_unlock(dentry, AuLock_IR);
12581 + err = au_cmoo(dentry);
12583 + err = args->open(file, vfsub_file_flags(file),
12585 + if (!err && au_fbstart(file) != au_dbstart(dentry))
12587 + * cmoo happens after h_file was opened.
12588 + * need to refresh file later.
12590 + atomic_dec(&au_fi(file)->fi_generation);
12593 + finfo = au_fi(file);
12595 + finfo->fi_file = file;
12596 + au_sphl_add(&finfo->fi_hlist,
12597 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12600 + fi_write_unlock(file);
12603 + fi_write_unlock(file);
12606 + if (unlikely(err)) {
12607 + finfo->fi_hdir = NULL;
12608 + au_finfo_fin(file);
12615 +int au_reopen_nondir(struct file *file)
12618 + aufs_bindex_t bstart;
12619 + struct dentry *dentry;
12620 + struct file *h_file, *h_file_tmp;
12622 + dentry = file->f_path.dentry;
12623 + bstart = au_dbstart(dentry);
12624 + h_file_tmp = NULL;
12625 + if (au_fbstart(file) == bstart) {
12626 + h_file = au_hf_top(file);
12627 + if (file->f_mode == h_file->f_mode)
12628 + return 0; /* success */
12629 + h_file_tmp = h_file;
12630 + get_file(h_file_tmp);
12631 + au_set_h_fptr(file, bstart, NULL);
12633 + AuDebugOn(au_fi(file)->fi_hdir);
12636 + * file exists on both of rw and ro
12637 + * open --> dbstart and fbstart are both 0
12638 + * prepend a branch as rw, "rw" become ro
12640 + * delete the top branch, "rw" becomes rw again
12641 + * --> dbstart is 1, fbstart is still 0
12642 + * write --> fbstart is 0 but dbstart is 1
12644 + /* AuDebugOn(au_fbstart(file) < bstart); */
12646 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
12647 + file, /*force_wr*/0);
12648 + err = PTR_ERR(h_file);
12649 + if (IS_ERR(h_file)) {
12650 + if (h_file_tmp) {
12651 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
12652 + au_set_h_fptr(file, bstart, h_file_tmp);
12653 + h_file_tmp = NULL;
12655 + goto out; /* todo: close all? */
12659 + au_set_fbstart(file, bstart);
12660 + au_set_h_fptr(file, bstart, h_file);
12661 + au_update_figen(file);
12662 + /* todo: necessary? */
12663 + /* file->f_ra = h_file->f_ra; */
12667 + fput(h_file_tmp);
12671 +/* ---------------------------------------------------------------------- */
12673 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12674 + struct dentry *hi_wh)
12677 + aufs_bindex_t bstart;
12678 + struct au_dinfo *dinfo;
12679 + struct dentry *h_dentry;
12680 + struct au_hdentry *hdp;
12682 + dinfo = au_di(file->f_path.dentry);
12683 + AuRwMustWriteLock(&dinfo->di_rwsem);
12685 + bstart = dinfo->di_bstart;
12686 + dinfo->di_bstart = btgt;
12687 + hdp = dinfo->di_hdentry;
12688 + h_dentry = hdp[0 + btgt].hd_dentry;
12689 + hdp[0 + btgt].hd_dentry = hi_wh;
12690 + err = au_reopen_nondir(file);
12691 + hdp[0 + btgt].hd_dentry = h_dentry;
12692 + dinfo->di_bstart = bstart;
12697 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12698 + aufs_bindex_t bcpup, struct au_pin *pin)
12701 + struct inode *inode, *h_inode;
12702 + struct dentry *h_dentry, *hi_wh;
12703 + struct au_cp_generic cpg = {
12704 + .dentry = file->f_path.dentry,
12711 + au_update_dbstart(cpg.dentry);
12712 + inode = d_inode(cpg.dentry);
12714 + if (au_dbstart(cpg.dentry) <= bcpup
12715 + && au_dbend(cpg.dentry) >= bcpup) {
12716 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12717 + if (h_dentry && d_is_positive(h_dentry))
12718 + h_inode = d_inode(h_dentry);
12720 + hi_wh = au_hi_wh(inode, bcpup);
12721 + if (!hi_wh && !h_inode)
12722 + err = au_sio_cpup_wh(&cpg, file);
12724 + /* already copied-up after unlink */
12725 + err = au_reopen_wh(file, bcpup, hi_wh);
12728 + && (inode->i_nlink > 1
12729 + || (inode->i_state & I_LINKABLE))
12730 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12731 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12737 + * prepare the @file for writing.
12739 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12742 + aufs_bindex_t dbstart;
12743 + struct dentry *parent;
12744 + struct inode *inode;
12745 + struct super_block *sb;
12746 + struct file *h_file;
12747 + struct au_cp_generic cpg = {
12748 + .dentry = file->f_path.dentry,
12753 + .flags = AuCpup_DTIME
12756 + sb = cpg.dentry->d_sb;
12757 + inode = d_inode(cpg.dentry);
12758 + cpg.bsrc = au_fbstart(file);
12759 + err = au_test_ro(sb, cpg.bsrc, inode);
12760 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12761 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12766 + /* need to cpup or reopen */
12767 + parent = dget_parent(cpg.dentry);
12768 + di_write_lock_parent(parent);
12769 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12771 + if (unlikely(err < 0))
12775 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12776 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12777 + if (unlikely(err))
12781 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12782 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12783 + if (unlikely(err))
12786 + dbstart = au_dbstart(cpg.dentry);
12787 + if (dbstart <= cpg.bdst)
12788 + cpg.bsrc = cpg.bdst;
12790 + if (dbstart <= cpg.bdst /* just reopen */
12791 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12793 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12794 + if (IS_ERR(h_file))
12795 + err = PTR_ERR(h_file);
12797 + di_downgrade_lock(parent, AuLock_IR);
12798 + if (dbstart > cpg.bdst)
12799 + err = au_sio_cpup_simple(&cpg);
12801 + err = au_reopen_nondir(file);
12802 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12804 + } else { /* copyup as wh and reopen */
12806 + * since writable hfsplus branch is not supported,
12807 + * h_open_pre/post() are unnecessary.
12809 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12810 + di_downgrade_lock(parent, AuLock_IR);
12814 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12815 + goto out_dput; /* success */
12821 + di_downgrade_lock(parent, AuLock_IR);
12823 + di_read_unlock(parent, AuLock_IR);
12830 +/* ---------------------------------------------------------------------- */
12832 +int au_do_flush(struct file *file, fl_owner_t id,
12833 + int (*flush)(struct file *file, fl_owner_t id))
12836 + struct super_block *sb;
12837 + struct inode *inode;
12839 + inode = file_inode(file);
12840 + sb = inode->i_sb;
12841 + si_noflush_read_lock(sb);
12842 + fi_read_lock(file);
12843 + ii_read_lock_child(inode);
12845 + err = flush(file, id);
12846 + au_cpup_attr_timesizes(inode);
12848 + ii_read_unlock(inode);
12849 + fi_read_unlock(file);
12850 + si_read_unlock(sb);
12854 +/* ---------------------------------------------------------------------- */
12856 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12859 + struct au_pin pin;
12860 + struct au_finfo *finfo;
12861 + struct dentry *parent, *hi_wh;
12862 + struct inode *inode;
12863 + struct super_block *sb;
12864 + struct au_cp_generic cpg = {
12865 + .dentry = file->f_path.dentry,
12870 + .flags = AuCpup_DTIME
12873 + FiMustWriteLock(file);
12876 + finfo = au_fi(file);
12877 + sb = cpg.dentry->d_sb;
12878 + inode = d_inode(cpg.dentry);
12879 + cpg.bdst = au_ibstart(inode);
12880 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12883 + parent = dget_parent(cpg.dentry);
12884 + if (au_test_ro(sb, cpg.bdst, inode)) {
12885 + di_read_lock_parent(parent, !AuLock_IR);
12886 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12888 + di_read_unlock(parent, !AuLock_IR);
12889 + if (unlikely(err < 0))
12894 + di_read_lock_parent(parent, AuLock_IR);
12895 + hi_wh = au_hi_wh(inode, cpg.bdst);
12896 + if (!S_ISDIR(inode->i_mode)
12897 + && au_opt_test(au_mntflags(sb), PLINK)
12898 + && au_plink_test(inode)
12899 + && !d_unhashed(cpg.dentry)
12900 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12901 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12902 + if (unlikely(err))
12905 + /* always superio. */
12906 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12907 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12909 + err = au_sio_cpup_simple(&cpg);
12912 + } else if (hi_wh) {
12913 + /* already copied-up after unlink */
12914 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12915 + *need_reopen = 0;
12919 + di_read_unlock(parent, AuLock_IR);
12926 +static void au_do_refresh_dir(struct file *file)
12928 + aufs_bindex_t bindex, bend, new_bindex, brid;
12929 + struct au_hfile *p, tmp, *q;
12930 + struct au_finfo *finfo;
12931 + struct super_block *sb;
12932 + struct au_fidir *fidir;
12934 + FiMustWriteLock(file);
12936 + sb = file->f_path.dentry->d_sb;
12937 + finfo = au_fi(file);
12938 + fidir = finfo->fi_hdir;
12939 + AuDebugOn(!fidir);
12940 + p = fidir->fd_hfile + finfo->fi_btop;
12941 + brid = p->hf_br->br_id;
12942 + bend = fidir->fd_bbot;
12943 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12947 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12948 + if (new_bindex == bindex)
12950 + if (new_bindex < 0) {
12951 + au_set_h_fptr(file, bindex, NULL);
12955 + /* swap two lower inode, and loop again */
12956 + q = fidir->fd_hfile + new_bindex;
12960 + if (tmp.hf_file) {
12966 + p = fidir->fd_hfile;
12967 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12968 + bend = au_sbend(sb);
12969 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12970 + finfo->fi_btop++, p++)
12971 + if (p->hf_file) {
12972 + if (file_inode(p->hf_file))
12974 + au_hfput(p, file);
12977 + bend = au_br_index(sb, brid);
12978 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12979 + finfo->fi_btop++, p++)
12981 + au_hfput(p, file);
12982 + bend = au_sbend(sb);
12985 + p = fidir->fd_hfile + bend;
12986 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12987 + fidir->fd_bbot--, p--)
12988 + if (p->hf_file) {
12989 + if (file_inode(p->hf_file))
12991 + au_hfput(p, file);
12993 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12997 + * after branch manipulating, refresh the file.
12999 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
13001 + int err, need_reopen;
13002 + aufs_bindex_t bend, bindex;
13003 + struct dentry *dentry;
13004 + struct au_finfo *finfo;
13005 + struct au_hfile *hfile;
13007 + dentry = file->f_path.dentry;
13008 + finfo = au_fi(file);
13009 + if (!finfo->fi_hdir) {
13010 + hfile = &finfo->fi_htop;
13011 + AuDebugOn(!hfile->hf_file);
13012 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
13013 + AuDebugOn(bindex < 0);
13014 + if (bindex != finfo->fi_btop)
13015 + au_set_fbstart(file, bindex);
13017 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
13018 + if (unlikely(err))
13020 + au_do_refresh_dir(file);
13025 + if (!au_test_mmapped(file))
13026 + err = au_file_refresh_by_inode(file, &need_reopen);
13027 + if (!err && need_reopen && !d_unlinked(dentry))
13028 + err = reopen(file);
13030 + au_update_figen(file);
13031 + goto out; /* success */
13034 + /* error, close all lower files */
13035 + if (finfo->fi_hdir) {
13036 + bend = au_fbend_dir(file);
13037 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
13038 + au_set_h_fptr(file, bindex, NULL);
13045 +/* common function to regular file and dir */
13046 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13050 + unsigned int sigen, figen;
13051 + aufs_bindex_t bstart;
13052 + unsigned char pseudo_link;
13053 + struct dentry *dentry;
13054 + struct inode *inode;
13057 + dentry = file->f_path.dentry;
13058 + inode = d_inode(dentry);
13059 + sigen = au_sigen(dentry->d_sb);
13060 + fi_write_lock(file);
13061 + figen = au_figen(file);
13062 + di_write_lock_child(dentry);
13063 + bstart = au_dbstart(dentry);
13064 + pseudo_link = (bstart != au_ibstart(inode));
13065 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
13067 + di_downgrade_lock(dentry, AuLock_IR);
13068 + fi_downgrade_lock(file);
13070 + goto out; /* success */
13073 + AuDbg("sigen %d, figen %d\n", sigen, figen);
13074 + if (au_digen_test(dentry, sigen)) {
13075 + err = au_reval_dpath(dentry, sigen);
13076 + AuDebugOn(!err && au_digen_test(dentry, sigen));
13080 + err = refresh_file(file, reopen);
13083 + di_downgrade_lock(dentry, AuLock_IR);
13084 + fi_downgrade_lock(file);
13087 + di_write_unlock(dentry);
13088 + fi_write_unlock(file);
13095 +/* ---------------------------------------------------------------------- */
13097 +/* cf. aufs_nopage() */
13098 +/* for madvise(2) */
13099 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
13101 + unlock_page(page);
13105 +/* it will never be called, but necessary to support O_DIRECT */
13106 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
13108 +{ BUG(); return 0; }
13110 +/* they will never be called. */
13111 +#ifdef CONFIG_AUFS_DEBUG
13112 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
13113 + loff_t pos, unsigned len, unsigned flags,
13114 + struct page **pagep, void **fsdata)
13115 +{ AuUnsupport(); return 0; }
13116 +static int aufs_write_end(struct file *file, struct address_space *mapping,
13117 + loff_t pos, unsigned len, unsigned copied,
13118 + struct page *page, void *fsdata)
13119 +{ AuUnsupport(); return 0; }
13120 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
13121 +{ AuUnsupport(); return 0; }
13123 +static int aufs_set_page_dirty(struct page *page)
13124 +{ AuUnsupport(); return 0; }
13125 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
13126 + unsigned int length)
13127 +{ AuUnsupport(); }
13128 +static int aufs_releasepage(struct page *page, gfp_t gfp)
13129 +{ AuUnsupport(); return 0; }
13130 +#if 0 /* called by memory compaction regardless file */
13131 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
13132 + struct page *page, enum migrate_mode mode)
13133 +{ AuUnsupport(); return 0; }
13135 +static int aufs_launder_page(struct page *page)
13136 +{ AuUnsupport(); return 0; }
13137 +static int aufs_is_partially_uptodate(struct page *page,
13138 + unsigned long from,
13139 + unsigned long count)
13140 +{ AuUnsupport(); return 0; }
13141 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
13143 +{ AuUnsupport(); }
13144 +static int aufs_error_remove_page(struct address_space *mapping,
13145 + struct page *page)
13146 +{ AuUnsupport(); return 0; }
13147 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
13149 +{ AuUnsupport(); return 0; }
13150 +static void aufs_swap_deactivate(struct file *file)
13151 +{ AuUnsupport(); }
13152 +#endif /* CONFIG_AUFS_DEBUG */
13154 +const struct address_space_operations aufs_aop = {
13155 + .readpage = aufs_readpage,
13156 + .direct_IO = aufs_direct_IO,
13157 +#ifdef CONFIG_AUFS_DEBUG
13158 + .writepage = aufs_writepage,
13159 + /* no writepages, because of writepage */
13160 + .set_page_dirty = aufs_set_page_dirty,
13161 + /* no readpages, because of readpage */
13162 + .write_begin = aufs_write_begin,
13163 + .write_end = aufs_write_end,
13164 + /* no bmap, no block device */
13165 + .invalidatepage = aufs_invalidatepage,
13166 + .releasepage = aufs_releasepage,
13167 + /* is fallback_migrate_page ok? */
13168 + /* .migratepage = aufs_migratepage, */
13169 + .launder_page = aufs_launder_page,
13170 + .is_partially_uptodate = aufs_is_partially_uptodate,
13171 + .is_dirty_writeback = aufs_is_dirty_writeback,
13172 + .error_remove_page = aufs_error_remove_page,
13173 + .swap_activate = aufs_swap_activate,
13174 + .swap_deactivate = aufs_swap_deactivate
13175 +#endif /* CONFIG_AUFS_DEBUG */
13177 diff -urNp -x '*.orig' linux-4.4/fs/aufs/file.h linux-4.4/fs/aufs/file.h
13178 --- linux-4.4/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
13179 +++ linux-4.4/fs/aufs/file.h 2021-02-24 17:28:14.405474836 +0100
13182 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13184 + * This program, aufs is free software; you can redistribute it and/or modify
13185 + * it under the terms of the GNU General Public License as published by
13186 + * the Free Software Foundation; either version 2 of the License, or
13187 + * (at your option) any later version.
13189 + * This program is distributed in the hope that it will be useful,
13190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13192 + * GNU General Public License for more details.
13194 + * You should have received a copy of the GNU General Public License
13195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13199 + * file operations
13202 +#ifndef __AUFS_FILE_H__
13203 +#define __AUFS_FILE_H__
13207 +#include <linux/file.h>
13208 +#include <linux/fs.h>
13209 +#include <linux/poll.h>
13210 +#include "rwsem.h"
13214 + struct file *hf_file;
13215 + struct au_branch *hf_br;
13220 + aufs_bindex_t fd_bbot;
13221 + aufs_bindex_t fd_nent;
13222 + struct au_vdir *fd_vdir_cache;
13223 + struct au_hfile fd_hfile[];
13226 +static inline int au_fidir_sz(int nent)
13228 + AuDebugOn(nent < 0);
13229 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13233 + atomic_t fi_generation;
13235 + struct au_rwsem fi_rwsem;
13236 + aufs_bindex_t fi_btop;
13238 + /* do not union them */
13239 + struct { /* for non-dir */
13240 + struct au_hfile fi_htop;
13241 + atomic_t fi_mmapped;
13243 + struct au_fidir *fi_hdir; /* for dir only */
13245 + struct hlist_node fi_hlist;
13246 + struct file *fi_file; /* very ugly */
13247 +} ____cacheline_aligned_in_smp;
13249 +/* ---------------------------------------------------------------------- */
13252 +extern const struct address_space_operations aufs_aop;
13253 +unsigned int au_file_roflags(unsigned int flags);
13254 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13255 + struct file *file, int force_wr);
13256 +struct au_do_open_args {
13258 + int (*open)(struct file *file, int flags,
13259 + struct file *h_file);
13260 + struct au_fidir *fidir;
13261 + struct file *h_file;
13263 +int au_do_open(struct file *file, struct au_do_open_args *args);
13264 +int au_reopen_nondir(struct file *file);
13266 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13267 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13269 +int au_do_flush(struct file *file, fl_owner_t id,
13270 + int (*flush)(struct file *file, fl_owner_t id));
13273 +#ifdef CONFIG_AUFS_POLL
13274 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13277 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13279 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13281 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13282 + struct file *h_file);
13284 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13285 + aufs_bindex_t bindex, int force_wr)
13286 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13287 + struct file *h_file);
13291 +extern const struct file_operations aufs_file_fop;
13292 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13293 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13294 +struct file *au_read_pre(struct file *file, int keep_fi);
13297 +void au_hfput(struct au_hfile *hf, struct file *file);
13298 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13299 + struct file *h_file);
13301 +void au_update_figen(struct file *file);
13302 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13303 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
13305 +void au_fi_init_once(void *_fi);
13306 +void au_finfo_fin(struct file *file);
13307 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13310 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13311 +#ifdef CONFIG_COMPAT
13312 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13313 + unsigned long arg);
13314 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13315 + unsigned long arg);
13318 +/* ---------------------------------------------------------------------- */
13320 +static inline struct au_finfo *au_fi(struct file *file)
13322 + return file->private_data;
13325 +/* ---------------------------------------------------------------------- */
13328 + * fi_read_lock, fi_write_lock,
13329 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13331 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13333 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13334 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13335 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13337 +/* ---------------------------------------------------------------------- */
13339 +/* todo: hard/soft set? */
13340 +static inline aufs_bindex_t au_fbstart(struct file *file)
13342 + FiMustAnyLock(file);
13343 + return au_fi(file)->fi_btop;
13346 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
13348 + FiMustAnyLock(file);
13349 + AuDebugOn(!au_fi(file)->fi_hdir);
13350 + return au_fi(file)->fi_hdir->fd_bbot;
13353 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13355 + FiMustAnyLock(file);
13356 + AuDebugOn(!au_fi(file)->fi_hdir);
13357 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13360 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
13362 + FiMustWriteLock(file);
13363 + au_fi(file)->fi_btop = bindex;
13366 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
13368 + FiMustWriteLock(file);
13369 + AuDebugOn(!au_fi(file)->fi_hdir);
13370 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13373 +static inline void au_set_fvdir_cache(struct file *file,
13374 + struct au_vdir *vdir_cache)
13376 + FiMustWriteLock(file);
13377 + AuDebugOn(!au_fi(file)->fi_hdir);
13378 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13381 +static inline struct file *au_hf_top(struct file *file)
13383 + FiMustAnyLock(file);
13384 + AuDebugOn(au_fi(file)->fi_hdir);
13385 + return au_fi(file)->fi_htop.hf_file;
13388 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13390 + FiMustAnyLock(file);
13391 + AuDebugOn(!au_fi(file)->fi_hdir);
13392 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13395 +/* todo: memory barrier? */
13396 +static inline unsigned int au_figen(struct file *f)
13398 + return atomic_read(&au_fi(f)->fi_generation);
13401 +static inline void au_set_mmapped(struct file *f)
13403 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13405 + pr_warn("fi_mmapped wrapped around\n");
13406 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13410 +static inline void au_unset_mmapped(struct file *f)
13412 + atomic_dec(&au_fi(f)->fi_mmapped);
13415 +static inline int au_test_mmapped(struct file *f)
13417 + return atomic_read(&au_fi(f)->fi_mmapped);
13420 +/* customize vma->vm_file */
13422 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13423 + struct file *file)
13427 + f = vma->vm_file;
13429 + vma->vm_file = file;
13434 +#define AuDbgVmRegion(file, vma) do {} while (0)
13436 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13437 + struct file *file)
13439 + au_do_vm_file_reset(vma, file);
13442 +#define AuDbgVmRegion(file, vma) \
13443 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13445 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13446 + struct file *file)
13450 + au_do_vm_file_reset(vma, file);
13451 + f = vma->vm_region->vm_file;
13453 + vma->vm_region->vm_file = file;
13456 +#endif /* CONFIG_MMU */
13458 +/* handle vma->vm_prfile */
13459 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13460 + struct file *file)
13463 + vma->vm_prfile = file;
13464 +#ifndef CONFIG_MMU
13466 + vma->vm_region->vm_prfile = file;
13470 +#endif /* __KERNEL__ */
13471 +#endif /* __AUFS_FILE_H__ */
13472 diff -urNp -x '*.orig' linux-4.4/fs/aufs/finfo.c linux-4.4/fs/aufs/finfo.c
13473 --- linux-4.4/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13474 +++ linux-4.4/fs/aufs/finfo.c 2021-02-24 17:28:14.405474836 +0100
13477 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13479 + * This program, aufs is free software; you can redistribute it and/or modify
13480 + * it under the terms of the GNU General Public License as published by
13481 + * the Free Software Foundation; either version 2 of the License, or
13482 + * (at your option) any later version.
13484 + * This program is distributed in the hope that it will be useful,
13485 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13486 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13487 + * GNU General Public License for more details.
13489 + * You should have received a copy of the GNU General Public License
13490 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13494 + * file private data
13499 +void au_hfput(struct au_hfile *hf, struct file *file)
13501 + /* todo: direct access f_flags */
13502 + if (vfsub_file_flags(file) & __FMODE_EXEC)
13503 + allow_write_access(hf->hf_file);
13504 + fput(hf->hf_file);
13505 + hf->hf_file = NULL;
13506 + atomic_dec(&hf->hf_br->br_count);
13507 + hf->hf_br = NULL;
13510 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13512 + struct au_finfo *finfo = au_fi(file);
13513 + struct au_hfile *hf;
13514 + struct au_fidir *fidir;
13516 + fidir = finfo->fi_hdir;
13518 + AuDebugOn(finfo->fi_btop != bindex);
13519 + hf = &finfo->fi_htop;
13521 + hf = fidir->fd_hfile + bindex;
13523 + if (hf && hf->hf_file)
13524 + au_hfput(hf, file);
13526 + FiMustWriteLock(file);
13527 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13528 + hf->hf_file = val;
13529 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13533 +void au_update_figen(struct file *file)
13535 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13536 + /* smp_mb(); */ /* atomic_set */
13539 +/* ---------------------------------------------------------------------- */
13541 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13543 + struct au_fidir *fidir;
13546 + nbr = au_sbend(sb) + 1;
13548 + nbr = 2; /* initial allocate for 2 branches */
13549 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13551 + fidir->fd_bbot = -1;
13552 + fidir->fd_nent = nbr;
13558 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13561 + struct au_fidir *fidir, *p;
13563 + AuRwMustWriteLock(&finfo->fi_rwsem);
13564 + fidir = finfo->fi_hdir;
13565 + AuDebugOn(!fidir);
13568 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13571 + p->fd_nent = nbr;
13572 + finfo->fi_hdir = p;
13579 +/* ---------------------------------------------------------------------- */
13581 +void au_finfo_fin(struct file *file)
13583 + struct au_finfo *finfo;
13585 + au_nfiles_dec(file->f_path.dentry->d_sb);
13587 + finfo = au_fi(file);
13588 + AuDebugOn(finfo->fi_hdir);
13589 + AuRwDestroy(&finfo->fi_rwsem);
13590 + au_cache_free_finfo(finfo);
13593 +void au_fi_init_once(void *_finfo)
13595 + struct au_finfo *finfo = _finfo;
13596 + static struct lock_class_key aufs_fi;
13598 + au_rw_init(&finfo->fi_rwsem);
13599 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
13602 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13605 + struct au_finfo *finfo;
13606 + struct dentry *dentry;
13609 + dentry = file->f_path.dentry;
13610 + finfo = au_cache_alloc_finfo();
13611 + if (unlikely(!finfo))
13615 + au_nfiles_inc(dentry->d_sb);
13616 + /* verbose coding for lock class name */
13618 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
13620 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
13621 + au_rw_write_lock(&finfo->fi_rwsem);
13622 + finfo->fi_btop = -1;
13623 + finfo->fi_hdir = fidir;
13624 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13625 + /* smp_mb(); */ /* atomic_set */
13627 + file->private_data = finfo;
13632 diff -urNp -x '*.orig' linux-4.4/fs/aufs/fstype.h linux-4.4/fs/aufs/fstype.h
13633 --- linux-4.4/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13634 +++ linux-4.4/fs/aufs/fstype.h 2021-02-24 17:28:14.405474836 +0100
13637 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13639 + * This program, aufs is free software; you can redistribute it and/or modify
13640 + * it under the terms of the GNU General Public License as published by
13641 + * the Free Software Foundation; either version 2 of the License, or
13642 + * (at your option) any later version.
13644 + * This program is distributed in the hope that it will be useful,
13645 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13646 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13647 + * GNU General Public License for more details.
13649 + * You should have received a copy of the GNU General Public License
13650 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13654 + * judging filesystem type
13657 +#ifndef __AUFS_FSTYPE_H__
13658 +#define __AUFS_FSTYPE_H__
13662 +#include <linux/fs.h>
13663 +#include <linux/magic.h>
13664 +#include <linux/nfs_fs.h>
13665 +#include <linux/romfs_fs.h>
13667 +static inline int au_test_aufs(struct super_block *sb)
13669 + return sb->s_magic == AUFS_SUPER_MAGIC;
13672 +static inline const char *au_sbtype(struct super_block *sb)
13674 + return sb->s_type->name;
13677 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
13679 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
13680 + return sb->s_magic == ISOFS_SUPER_MAGIC;
13686 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
13688 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
13689 + return sb->s_magic == ROMFS_MAGIC;
13695 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
13697 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
13698 + return sb->s_magic == CRAMFS_MAGIC;
13703 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
13705 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
13706 + return sb->s_magic == NFS_SUPER_MAGIC;
13712 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
13714 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
13715 + return sb->s_magic == FUSE_SUPER_MAGIC;
13721 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
13723 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
13724 + return sb->s_magic == XFS_SB_MAGIC;
13730 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
13732 +#ifdef CONFIG_TMPFS
13733 + return sb->s_magic == TMPFS_MAGIC;
13739 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
13741 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
13742 + return !strcmp(au_sbtype(sb), "ecryptfs");
13748 +static inline int au_test_ramfs(struct super_block *sb)
13750 + return sb->s_magic == RAMFS_MAGIC;
13753 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
13755 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
13756 + return sb->s_magic == UBIFS_SUPER_MAGIC;
13762 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
13764 +#ifdef CONFIG_PROC_FS
13765 + return sb->s_magic == PROC_SUPER_MAGIC;
13771 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
13773 +#ifdef CONFIG_SYSFS
13774 + return sb->s_magic == SYSFS_MAGIC;
13780 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
13782 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
13783 + return sb->s_magic == CONFIGFS_MAGIC;
13789 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
13791 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
13792 + return sb->s_magic == MINIX3_SUPER_MAGIC
13793 + || sb->s_magic == MINIX2_SUPER_MAGIC
13794 + || sb->s_magic == MINIX2_SUPER_MAGIC2
13795 + || sb->s_magic == MINIX_SUPER_MAGIC
13796 + || sb->s_magic == MINIX_SUPER_MAGIC2;
13802 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
13804 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
13805 + return sb->s_magic == MSDOS_SUPER_MAGIC;
13811 +static inline int au_test_msdos(struct super_block *sb)
13813 + return au_test_fat(sb);
13816 +static inline int au_test_vfat(struct super_block *sb)
13818 + return au_test_fat(sb);
13821 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
13823 +#ifdef CONFIG_SECURITYFS
13824 + return sb->s_magic == SECURITYFS_MAGIC;
13830 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
13832 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
13833 + return sb->s_magic == SQUASHFS_MAGIC;
13839 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
13841 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
13842 + return sb->s_magic == BTRFS_SUPER_MAGIC;
13848 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
13850 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
13851 + return sb->s_magic == XENFS_SUPER_MAGIC;
13857 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
13859 +#ifdef CONFIG_DEBUG_FS
13860 + return sb->s_magic == DEBUGFS_MAGIC;
13866 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
13868 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
13869 + return sb->s_magic == NILFS_SUPER_MAGIC;
13875 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
13877 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
13878 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
13884 +/* ---------------------------------------------------------------------- */
13886 + * they can't be an aufs branch.
13888 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
13891 +#ifndef CONFIG_AUFS_BR_RAMFS
13892 + au_test_ramfs(sb) ||
13894 + au_test_procfs(sb)
13895 + || au_test_sysfs(sb)
13896 + || au_test_configfs(sb)
13897 + || au_test_debugfs(sb)
13898 + || au_test_securityfs(sb)
13899 + || au_test_xenfs(sb)
13900 + || au_test_ecryptfs(sb)
13901 + /* || !strcmp(au_sbtype(sb), "unionfs") */
13902 + || au_test_aufs(sb); /* will be supported in next version */
13905 +static inline int au_test_fs_remote(struct super_block *sb)
13907 + return !au_test_tmpfs(sb)
13908 +#ifdef CONFIG_AUFS_BR_RAMFS
13909 + && !au_test_ramfs(sb)
13911 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
13914 +/* ---------------------------------------------------------------------- */
13917 + * Note: these functions (below) are created after reading ->getattr() in all
13918 + * filesystems under linux/fs. it means we have to do so in every update...
13922 + * some filesystems require getattr to refresh the inode attributes before
13924 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
13925 + * and leave the work for d_revalidate()
13927 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
13929 + return au_test_nfs(sb)
13930 + || au_test_fuse(sb)
13931 + /* || au_test_btrfs(sb) */ /* untested */
13936 + * filesystems which don't maintain i_size or i_blocks.
13938 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
13940 + return au_test_xfs(sb)
13941 + || au_test_btrfs(sb)
13942 + || au_test_ubifs(sb)
13943 + || au_test_hfsplus(sb) /* maintained, but incorrect */
13944 + /* || au_test_minix(sb) */ /* untested */
13949 + * filesystems which don't store the correct value in some of their inode
13952 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
13954 + return au_test_fs_bad_iattr_size(sb)
13955 + || au_test_fat(sb)
13956 + || au_test_msdos(sb)
13957 + || au_test_vfat(sb);
13960 +/* they don't check i_nlink in link(2) */
13961 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
13963 + return au_test_tmpfs(sb)
13964 +#ifdef CONFIG_AUFS_BR_RAMFS
13965 + || au_test_ramfs(sb)
13967 + || au_test_ubifs(sb)
13968 + || au_test_hfsplus(sb);
13972 + * filesystems which sets S_NOATIME and S_NOCMTIME.
13974 +static inline int au_test_fs_notime(struct super_block *sb)
13976 + return au_test_nfs(sb)
13977 + || au_test_fuse(sb)
13978 + || au_test_ubifs(sb)
13982 +/* temporary support for i#1 in cramfs */
13983 +static inline int au_test_fs_unique_ino(struct inode *inode)
13985 + if (au_test_cramfs(inode->i_sb))
13986 + return inode->i_ino != 1;
13990 +/* ---------------------------------------------------------------------- */
13993 + * the filesystem where the xino files placed must support i/o after unlink and
13994 + * maintain i_size and i_blocks.
13996 +static inline int au_test_fs_bad_xino(struct super_block *sb)
13998 + return au_test_fs_remote(sb)
13999 + || au_test_fs_bad_iattr_size(sb)
14000 + /* don't want unnecessary work for xino */
14001 + || au_test_aufs(sb)
14002 + || au_test_ecryptfs(sb)
14003 + || au_test_nilfs(sb);
14006 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14008 + return au_test_tmpfs(sb)
14009 + || au_test_ramfs(sb);
14013 + * test if the @sb is real-readonly.
14015 +static inline int au_test_fs_rr(struct super_block *sb)
14017 + return au_test_squashfs(sb)
14018 + || au_test_iso9660(sb)
14019 + || au_test_cramfs(sb)
14020 + || au_test_romfs(sb);
14024 + * test if the @inode is nfs with 'noacl' option
14025 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14027 +static inline int au_test_nfs_noacl(struct inode *inode)
14029 + return au_test_nfs(inode->i_sb)
14030 + /* && IS_POSIXACL(inode) */
14031 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14034 +#endif /* __KERNEL__ */
14035 +#endif /* __AUFS_FSTYPE_H__ */
14036 diff -urNp -x '*.orig' linux-4.4/fs/aufs/hfsnotify.c linux-4.4/fs/aufs/hfsnotify.c
14037 --- linux-4.4/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14038 +++ linux-4.4/fs/aufs/hfsnotify.c 2021-02-24 17:28:14.405474836 +0100
14041 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14043 + * This program, aufs is free software; you can redistribute it and/or modify
14044 + * it under the terms of the GNU General Public License as published by
14045 + * the Free Software Foundation; either version 2 of the License, or
14046 + * (at your option) any later version.
14048 + * This program is distributed in the hope that it will be useful,
14049 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14050 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14051 + * GNU General Public License for more details.
14053 + * You should have received a copy of the GNU General Public License
14054 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14058 + * fsnotify for the lower directories
14063 +/* FS_IN_IGNORED is unnecessary */
14064 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14065 + | FS_CREATE | FS_EVENT_ON_CHILD);
14066 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14067 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14069 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14071 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14074 + au_cache_free_hnotify(hn);
14075 + smp_mb__before_atomic();
14076 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14077 + wake_up(&au_hfsn_wq);
14080 +static int au_hfsn_alloc(struct au_hinode *hinode)
14083 + struct au_hnotify *hn;
14084 + struct super_block *sb;
14085 + struct au_branch *br;
14086 + struct fsnotify_mark *mark;
14087 + aufs_bindex_t bindex;
14089 + hn = hinode->hi_notify;
14090 + sb = hn->hn_aufs_inode->i_sb;
14091 + bindex = au_br_index(sb, hinode->hi_id);
14092 + br = au_sbr(sb, bindex);
14093 + AuDebugOn(!br->br_hfsn);
14095 + mark = &hn->hn_mark;
14096 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14097 + mark->mask = AuHfsnMask;
14099 + * by udba rename or rmdir, aufs assign a new inode to the known
14100 + * h_inode, so specify 1 to allow dups.
14103 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14104 + /*mnt*/NULL, /*allow_dups*/1);
14105 + /* even if err */
14106 + fsnotify_put_mark(mark);
14112 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14114 + struct fsnotify_mark *mark;
14115 + unsigned long long ull;
14116 + struct fsnotify_group *group;
14118 + ull = atomic64_inc_return(&au_hfsn_ifree);
14121 + mark = &hn->hn_mark;
14122 + spin_lock(&mark->lock);
14123 + group = mark->group;
14124 + fsnotify_get_group(group);
14125 + spin_unlock(&mark->lock);
14127 + fsnotify_destroy_mark(mark, group);
14128 + fsnotify_put_group(group);
14131 + /* free hn by myself */
14135 +/* ---------------------------------------------------------------------- */
14137 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14139 + struct fsnotify_mark *mark;
14141 + mark = &hinode->hi_notify->hn_mark;
14142 + spin_lock(&mark->lock);
14144 + AuDebugOn(mark->mask & AuHfsnMask);
14145 + mark->mask |= AuHfsnMask;
14147 + AuDebugOn(!(mark->mask & AuHfsnMask));
14148 + mark->mask &= ~AuHfsnMask;
14150 + spin_unlock(&mark->lock);
14151 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14154 +/* ---------------------------------------------------------------------- */
14156 +/* #define AuDbgHnotify */
14157 +#ifdef AuDbgHnotify
14158 +static char *au_hfsn_name(u32 mask)
14160 +#ifdef CONFIG_AUFS_DEBUG
14161 +#define test_ret(flag) \
14163 + if (mask & flag) \
14166 + test_ret(FS_ACCESS);
14167 + test_ret(FS_MODIFY);
14168 + test_ret(FS_ATTRIB);
14169 + test_ret(FS_CLOSE_WRITE);
14170 + test_ret(FS_CLOSE_NOWRITE);
14171 + test_ret(FS_OPEN);
14172 + test_ret(FS_MOVED_FROM);
14173 + test_ret(FS_MOVED_TO);
14174 + test_ret(FS_CREATE);
14175 + test_ret(FS_DELETE);
14176 + test_ret(FS_DELETE_SELF);
14177 + test_ret(FS_MOVE_SELF);
14178 + test_ret(FS_UNMOUNT);
14179 + test_ret(FS_Q_OVERFLOW);
14180 + test_ret(FS_IN_IGNORED);
14181 + test_ret(FS_ISDIR);
14182 + test_ret(FS_IN_ONESHOT);
14183 + test_ret(FS_EVENT_ON_CHILD);
14192 +/* ---------------------------------------------------------------------- */
14194 +static void au_hfsn_free_group(struct fsnotify_group *group)
14196 + struct au_br_hfsnotify *hfsn = group->private;
14202 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14203 + struct inode *inode,
14204 + struct fsnotify_mark *inode_mark,
14205 + struct fsnotify_mark *vfsmount_mark,
14206 + u32 mask, void *data, int data_type,
14207 + const unsigned char *file_name, u32 cookie)
14210 + struct au_hnotify *hnotify;
14211 + struct inode *h_dir, *h_inode;
14212 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14214 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14217 + /* if FS_UNMOUNT happens, there must be another bug */
14218 + AuDebugOn(mask & FS_UNMOUNT);
14219 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14224 +#ifdef AuDbgHnotify
14226 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14227 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14228 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14229 + h_dir->i_ino, mask, au_hfsn_name(mask),
14230 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14231 + /* WARN_ON(1); */
14236 + AuDebugOn(!inode_mark);
14237 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14238 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14244 +static struct fsnotify_ops au_hfsn_ops = {
14245 + .handle_event = au_hfsn_handle_event,
14246 + .free_group_priv = au_hfsn_free_group
14249 +/* ---------------------------------------------------------------------- */
14251 +static void au_hfsn_fin_br(struct au_branch *br)
14253 + struct au_br_hfsnotify *hfsn;
14255 + hfsn = br->br_hfsn;
14258 + fsnotify_put_group(hfsn->hfsn_group);
14263 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14266 + struct fsnotify_group *group;
14267 + struct au_br_hfsnotify *hfsn;
14270 + br->br_hfsn = NULL;
14271 + if (!au_br_hnotifyable(perm))
14275 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14276 + if (unlikely(!hfsn))
14280 + group = fsnotify_alloc_group(&au_hfsn_ops);
14281 + if (IS_ERR(group)) {
14282 + err = PTR_ERR(group);
14283 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14287 + group->private = hfsn;
14288 + hfsn->hfsn_group = group;
14289 + br->br_hfsn = hfsn;
14290 + goto out; /* success */
14298 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14303 + if (!br->br_hfsn)
14304 + err = au_hfsn_init_br(br, perm);
14309 +/* ---------------------------------------------------------------------- */
14311 +static void au_hfsn_fin(void)
14313 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14314 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14317 +const struct au_hnotify_op au_hnotify_op = {
14318 + .ctl = au_hfsn_ctl,
14319 + .alloc = au_hfsn_alloc,
14320 + .free = au_hfsn_free,
14322 + .fin = au_hfsn_fin,
14324 + .reset_br = au_hfsn_reset_br,
14325 + .fin_br = au_hfsn_fin_br,
14326 + .init_br = au_hfsn_init_br
14328 diff -urNp -x '*.orig' linux-4.4/fs/aufs/hfsplus.c linux-4.4/fs/aufs/hfsplus.c
14329 --- linux-4.4/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14330 +++ linux-4.4/fs/aufs/hfsplus.c 2021-02-24 17:28:14.405474836 +0100
14333 + * Copyright (C) 2010-2016 Junjiro R. Okajima
14335 + * This program, aufs is free software; you can redistribute it and/or modify
14336 + * it under the terms of the GNU General Public License as published by
14337 + * the Free Software Foundation; either version 2 of the License, or
14338 + * (at your option) any later version.
14340 + * This program is distributed in the hope that it will be useful,
14341 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14342 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14343 + * GNU General Public License for more details.
14345 + * You should have received a copy of the GNU General Public License
14346 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14350 + * special support for filesystems which aqucires an inode mutex
14351 + * at final closing a file, eg, hfsplus.
14353 + * This trick is very simple and stupid, just to open the file before really
14354 + * neceeary open to tell hfsplus that this is not the final closing.
14355 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14356 + * and au_h_open_post() after releasing it.
14361 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14364 + struct file *h_file;
14365 + struct dentry *h_dentry;
14367 + h_dentry = au_h_dptr(dentry, bindex);
14368 + AuDebugOn(!h_dentry);
14369 + AuDebugOn(d_is_negative(h_dentry));
14372 + if (au_test_hfsplus(h_dentry->d_sb)
14373 + && d_is_reg(h_dentry))
14374 + h_file = au_h_open(dentry, bindex,
14375 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14376 + /*file*/NULL, force_wr);
14380 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14381 + struct file *h_file)
14385 + au_sbr_put(dentry->d_sb, bindex);
14388 diff -urNp -x '*.orig' linux-4.4/fs/aufs/hnotify.c linux-4.4/fs/aufs/hnotify.c
14389 --- linux-4.4/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14390 +++ linux-4.4/fs/aufs/hnotify.c 2021-02-24 17:28:14.405474836 +0100
14393 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14395 + * This program, aufs is free software; you can redistribute it and/or modify
14396 + * it under the terms of the GNU General Public License as published by
14397 + * the Free Software Foundation; either version 2 of the License, or
14398 + * (at your option) any later version.
14400 + * This program is distributed in the hope that it will be useful,
14401 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14402 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14403 + * GNU General Public License for more details.
14405 + * You should have received a copy of the GNU General Public License
14406 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14410 + * abstraction to notify the direct changes on lower directories
14415 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14418 + struct au_hnotify *hn;
14421 + hn = au_cache_alloc_hnotify();
14423 + hn->hn_aufs_inode = inode;
14424 + hinode->hi_notify = hn;
14425 + err = au_hnotify_op.alloc(hinode);
14427 + if (unlikely(err)) {
14428 + hinode->hi_notify = NULL;
14429 + au_cache_free_hnotify(hn);
14431 + * The upper dir was removed by udba, but the same named
14432 + * dir left. In this case, aufs assignes a new inode
14433 + * number and set the monitor again.
14434 + * For the lower dir, the old monitnor is still left.
14436 + if (err == -EEXIST)
14445 +void au_hn_free(struct au_hinode *hinode)
14447 + struct au_hnotify *hn;
14449 + hn = hinode->hi_notify;
14451 + hinode->hi_notify = NULL;
14452 + if (au_hnotify_op.free(hinode, hn))
14453 + au_cache_free_hnotify(hn);
14457 +/* ---------------------------------------------------------------------- */
14459 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14461 + if (hinode->hi_notify)
14462 + au_hnotify_op.ctl(hinode, do_set);
14465 +void au_hn_reset(struct inode *inode, unsigned int flags)
14467 + aufs_bindex_t bindex, bend;
14468 + struct inode *hi;
14469 + struct dentry *iwhdentry;
14471 + bend = au_ibend(inode);
14472 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14473 + hi = au_h_iptr(inode, bindex);
14477 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14478 + iwhdentry = au_hi_wh(inode, bindex);
14482 + au_set_h_iptr(inode, bindex, NULL, 0);
14483 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14484 + flags & ~AuHi_XINO);
14487 + /* mutex_unlock(&hi->i_mutex); */
14491 +/* ---------------------------------------------------------------------- */
14493 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14496 + aufs_bindex_t bindex, bend, bfound, bstart;
14497 + struct inode *h_i;
14500 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14501 + pr_warn("branch root dir was changed\n");
14506 + bend = au_ibend(inode);
14507 + bstart = au_ibstart(inode);
14508 +#if 0 /* reserved for future use */
14509 + if (bindex == bend) {
14510 + /* keep this ino in rename case */
14514 + for (bindex = bstart; bindex <= bend; bindex++)
14515 + if (au_h_iptr(inode, bindex) == h_inode) {
14522 + for (bindex = bstart; bindex <= bend; bindex++) {
14523 + h_i = au_h_iptr(inode, bindex);
14527 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14528 + /* ignore this error */
14529 + /* bad action? */
14532 + /* children inode number will be broken */
14539 +static int hn_gen_tree(struct dentry *dentry)
14541 + int err, i, j, ndentry;
14542 + struct au_dcsub_pages dpages;
14543 + struct au_dpage *dpage;
14544 + struct dentry **dentries;
14546 + err = au_dpages_init(&dpages, GFP_NOFS);
14547 + if (unlikely(err))
14549 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14550 + if (unlikely(err))
14553 + for (i = 0; i < dpages.ndpage; i++) {
14554 + dpage = dpages.dpages + i;
14555 + dentries = dpage->dentries;
14556 + ndentry = dpage->ndentry;
14557 + for (j = 0; j < ndentry; j++) {
14558 + struct dentry *d;
14565 + if (d_really_is_positive(d))
14566 + /* todo: reset children xino?
14567 + cached children only? */
14568 + au_iigen_dec(d_inode(d));
14573 + au_dpages_free(&dpages);
14576 + /* discard children */
14577 + dentry_unhash(dentry);
14585 + * return 0 if processed.
14587 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14588 + const unsigned int isdir)
14591 + struct dentry *d;
14592 + struct qstr *dname;
14595 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14596 + pr_warn("branch root dir was changed\n");
14602 + AuDebugOn(!name);
14603 + au_iigen_dec(inode);
14604 + spin_lock(&inode->i_lock);
14605 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
14606 + spin_lock(&d->d_lock);
14607 + dname = &d->d_name;
14608 + if (dname->len != nlen
14609 + && memcmp(dname->name, name, nlen)) {
14610 + spin_unlock(&d->d_lock);
14615 + spin_unlock(&d->d_lock);
14618 + spin_unlock(&inode->i_lock);
14620 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14621 + d = d_find_any_alias(inode);
14623 + au_iigen_dec(inode);
14627 + spin_lock(&d->d_lock);
14628 + dname = &d->d_name;
14629 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14630 + spin_unlock(&d->d_lock);
14631 + err = hn_gen_tree(d);
14632 + spin_lock(&d->d_lock);
14634 + spin_unlock(&d->d_lock);
14643 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
14647 + if (IS_ROOT(dentry)) {
14648 + pr_warn("branch root dir was changed\n");
14654 + au_digen_dec(dentry);
14655 + if (d_really_is_positive(dentry))
14656 + au_iigen_dec(d_inode(dentry));
14658 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
14659 + if (d_really_is_positive(dentry))
14660 + err = hn_gen_tree(dentry);
14667 +/* ---------------------------------------------------------------------- */
14669 +/* hnotify job flags */
14670 +#define AuHnJob_XINO0 1
14671 +#define AuHnJob_GEN (1 << 1)
14672 +#define AuHnJob_DIRENT (1 << 2)
14673 +#define AuHnJob_ISDIR (1 << 3)
14674 +#define AuHnJob_TRYXINO0 (1 << 4)
14675 +#define AuHnJob_MNTPNT (1 << 5)
14676 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
14677 +#define au_fset_hnjob(flags, name) \
14678 + do { (flags) |= AuHnJob_##name; } while (0)
14679 +#define au_fclr_hnjob(flags, name) \
14680 + do { (flags) &= ~AuHnJob_##name; } while (0)
14688 +struct au_hnotify_args {
14689 + struct inode *h_dir, *dir, *h_child_inode;
14691 + unsigned int flags[AuHnLast];
14692 + unsigned int h_child_nlen;
14693 + char h_child_name[];
14696 +struct hn_job_args {
14697 + unsigned int flags;
14698 + struct inode *inode, *h_inode, *dir, *h_dir;
14699 + struct dentry *dentry;
14704 +static int hn_job(struct hn_job_args *a)
14706 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
14710 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
14711 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14713 + if (au_ftest_hnjob(a->flags, TRYXINO0)
14716 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
14717 + if (!a->h_inode->i_nlink
14718 + && !(a->h_inode->i_state & I_LINKABLE))
14719 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14720 + mutex_unlock(&a->h_inode->i_mutex);
14723 + /* make the generation obsolete */
14724 + if (au_ftest_hnjob(a->flags, GEN)) {
14727 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
14729 + if (e && a->dentry)
14730 + hn_gen_by_name(a->dentry, isdir);
14731 + /* ignore this error */
14734 + /* make dir entries obsolete */
14735 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
14736 + struct au_vdir *vdir;
14738 + vdir = au_ivdir(a->inode);
14740 + vdir->vd_jiffy = 0;
14741 + /* IMustLock(a->inode); */
14742 + /* a->inode->i_version++; */
14745 + /* can do nothing but warn */
14746 + if (au_ftest_hnjob(a->flags, MNTPNT)
14748 + && d_mountpoint(a->dentry))
14749 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
14754 +/* ---------------------------------------------------------------------- */
14756 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
14757 + struct inode *dir)
14759 + struct dentry *dentry, *d, *parent;
14760 + struct qstr *dname;
14762 + parent = d_find_any_alias(dir);
14767 + spin_lock(&parent->d_lock);
14768 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
14769 + /* AuDbg("%pd\n", d); */
14770 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
14771 + dname = &d->d_name;
14772 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
14773 + goto cont_unlock;
14777 + goto cont_unlock;
14778 + if (au_dcount(d) > 0) {
14779 + dentry = dget_dlock(d);
14780 + spin_unlock(&d->d_lock);
14785 + spin_unlock(&d->d_lock);
14787 + spin_unlock(&parent->d_lock);
14791 + di_write_lock_child(dentry);
14796 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
14797 + aufs_bindex_t bindex, ino_t h_ino)
14799 + struct inode *inode;
14804 + err = au_xino_read(sb, bindex, h_ino, &ino);
14806 + inode = ilookup(sb, ino);
14810 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14811 + pr_warn("wrong root branch\n");
14817 + ii_write_lock_child(inode);
14823 +static void au_hn_bh(void *_args)
14825 + struct au_hnotify_args *a = _args;
14826 + struct super_block *sb;
14827 + aufs_bindex_t bindex, bend, bfound;
14828 + unsigned char xino, try_iput;
14830 + struct inode *inode;
14832 + struct hn_job_args args;
14833 + struct dentry *dentry;
14834 + struct au_sbinfo *sbinfo;
14836 + AuDebugOn(!_args);
14837 + AuDebugOn(!a->h_dir);
14838 + AuDebugOn(!a->dir);
14839 + AuDebugOn(!a->mask);
14840 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
14841 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
14842 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
14847 + * do not lock a->dir->i_mutex here
14848 + * because of d_revalidate() may cause a deadlock.
14850 + sb = a->dir->i_sb;
14852 + sbinfo = au_sbi(sb);
14853 + AuDebugOn(!sbinfo);
14854 + si_write_lock(sb, AuLock_NOPLMW);
14856 + ii_read_lock_parent(a->dir);
14858 + bend = au_ibend(a->dir);
14859 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
14860 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
14864 + ii_read_unlock(a->dir);
14865 + if (unlikely(bfound < 0))
14868 + xino = !!au_opt_test(au_mntflags(sb), XINO);
14870 + if (a->h_child_inode)
14871 + h_ino = a->h_child_inode->i_ino;
14873 + if (a->h_child_nlen
14874 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
14875 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
14876 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
14879 + if (dentry && d_really_is_positive(dentry))
14880 + inode = d_inode(dentry);
14881 + if (xino && !inode && h_ino
14882 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
14883 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
14884 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
14885 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
14889 + args.flags = a->flags[AuHn_CHILD];
14890 + args.dentry = dentry;
14891 + args.inode = inode;
14892 + args.h_inode = a->h_child_inode;
14893 + args.dir = a->dir;
14894 + args.h_dir = a->h_dir;
14895 + args.h_name = a->h_child_name;
14896 + args.h_nlen = a->h_child_nlen;
14897 + err = hn_job(&args);
14899 + if (au_di(dentry))
14900 + di_write_unlock(dentry);
14903 + if (inode && try_iput) {
14904 + ii_write_unlock(inode);
14908 + ii_write_lock_parent(a->dir);
14909 + args.flags = a->flags[AuHn_PARENT];
14910 + args.dentry = NULL;
14911 + args.inode = a->dir;
14912 + args.h_inode = a->h_dir;
14914 + args.h_dir = NULL;
14915 + args.h_name = NULL;
14917 + err = hn_job(&args);
14918 + ii_write_unlock(a->dir);
14921 + iput(a->h_child_inode);
14924 + si_write_unlock(sb);
14925 + au_nwt_done(&sbinfo->si_nowait);
14929 +/* ---------------------------------------------------------------------- */
14931 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
14932 + struct qstr *h_child_qstr, struct inode *h_child_inode)
14935 + unsigned int flags[AuHnLast], f;
14936 + unsigned char isdir, isroot, wh;
14937 + struct inode *dir;
14938 + struct au_hnotify_args *args;
14939 + char *p, *h_child_name;
14942 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
14943 + dir = igrab(hnotify->hn_aufs_inode);
14947 + isroot = (dir->i_ino == AUFS_ROOT_INO);
14949 + h_child_name = (void *)h_child_qstr->name;
14950 + len = h_child_qstr->len;
14951 + if (h_child_name) {
14952 + if (len > AUFS_WH_PFX_LEN
14953 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
14954 + h_child_name += AUFS_WH_PFX_LEN;
14955 + len -= AUFS_WH_PFX_LEN;
14961 + if (h_child_inode)
14962 + isdir = !!S_ISDIR(h_child_inode->i_mode);
14963 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
14964 + flags[AuHn_CHILD] = 0;
14966 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
14967 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
14968 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
14969 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
14970 + case FS_MOVED_FROM:
14971 + case FS_MOVED_TO:
14972 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
14973 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14976 + AuDebugOn(!h_child_name);
14981 + * aufs never be able to get this child inode.
14982 + * revalidation should be in d_revalidate()
14983 + * by checking i_nlink, i_generation or d_unhashed().
14985 + AuDebugOn(!h_child_name);
14986 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
14987 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
14995 + h_child_inode = NULL;
14998 + /* iput() and kfree() will be called in au_hnotify() */
14999 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15000 + if (unlikely(!args)) {
15001 + AuErr1("no memory\n");
15005 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15006 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15007 + args->mask = mask;
15009 + args->h_dir = igrab(h_dir);
15010 + if (h_child_inode)
15011 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15012 + args->h_child_inode = h_child_inode;
15013 + args->h_child_nlen = len;
15015 + p = (void *)args;
15016 + p += sizeof(*args);
15017 + memcpy(p, h_child_name, len);
15021 + /* NFS fires the event for silly-renamed one from kworker */
15023 + if (!dir->i_nlink
15024 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15026 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15027 + if (unlikely(err)) {
15028 + pr_err("wkq %d\n", err);
15029 + iput(args->h_child_inode);
15030 + iput(args->h_dir);
15039 +/* ---------------------------------------------------------------------- */
15041 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15045 + AuDebugOn(!(udba & AuOptMask_UDBA));
15048 + if (au_hnotify_op.reset_br)
15049 + err = au_hnotify_op.reset_br(udba, br, perm);
15054 +int au_hnotify_init_br(struct au_branch *br, int perm)
15059 + if (au_hnotify_op.init_br)
15060 + err = au_hnotify_op.init_br(br, perm);
15065 +void au_hnotify_fin_br(struct au_branch *br)
15067 + if (au_hnotify_op.fin_br)
15068 + au_hnotify_op.fin_br(br);
15071 +static void au_hn_destroy_cache(void)
15073 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15074 + au_cachep[AuCache_HNOTIFY] = NULL;
15077 +int __init au_hnotify_init(void)
15082 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15083 + if (au_cachep[AuCache_HNOTIFY]) {
15085 + if (au_hnotify_op.init)
15086 + err = au_hnotify_op.init();
15087 + if (unlikely(err))
15088 + au_hn_destroy_cache();
15094 +void au_hnotify_fin(void)
15096 + if (au_hnotify_op.fin)
15097 + au_hnotify_op.fin();
15098 + /* cf. au_cache_fin() */
15099 + if (au_cachep[AuCache_HNOTIFY])
15100 + au_hn_destroy_cache();
15102 diff -urNp -x '*.orig' linux-4.4/fs/aufs/i_op.c linux-4.4/fs/aufs/i_op.c
15103 --- linux-4.4/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
15104 +++ linux-4.4/fs/aufs/i_op.c 2021-02-24 17:28:14.408808278 +0100
15107 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15109 + * This program, aufs is free software; you can redistribute it and/or modify
15110 + * it under the terms of the GNU General Public License as published by
15111 + * the Free Software Foundation; either version 2 of the License, or
15112 + * (at your option) any later version.
15114 + * This program is distributed in the hope that it will be useful,
15115 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15117 + * GNU General Public License for more details.
15119 + * You should have received a copy of the GNU General Public License
15120 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15124 + * inode operations (except add/del/rename)
15127 +#include <linux/device_cgroup.h>
15128 +#include <linux/fs_stack.h>
15129 +#include <linux/namei.h>
15130 +#include <linux/security.h>
15133 +static int h_permission(struct inode *h_inode, int mask,
15134 + struct path *h_path, int brperm)
15137 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
15140 + if ((write_mask && IS_IMMUTABLE(h_inode))
15141 + || ((mask & MAY_EXEC)
15142 + && S_ISREG(h_inode->i_mode)
15143 + && (path_noexec(h_path)
15144 + || !(h_inode->i_mode & S_IXUGO))))
15148 + * - skip the lower fs test in the case of write to ro branch.
15149 + * - nfs dir permission write check is optimized, but a policy for
15150 + * link/rename requires a real check.
15151 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
15152 + * in this case, generic_permission() returns -EOPNOTSUPP.
15154 + if ((write_mask && !au_br_writable(brperm))
15155 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
15156 + && write_mask && !(mask & MAY_READ))
15157 + || !h_inode->i_op->permission) {
15158 + /* AuLabel(generic_permission); */
15159 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
15160 + err = generic_permission(h_inode, mask);
15161 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
15162 + err = h_inode->i_op->permission(h_inode, mask);
15165 + /* AuLabel(h_inode->permission); */
15166 + err = h_inode->i_op->permission(h_inode, mask);
15171 + err = devcgroup_inode_permission(h_inode, mask);
15173 + err = security_inode_permission(h_inode, mask);
15177 + /* todo: do we need to call ima_path_check()? */
15178 + struct path h_path = {
15182 + err = ima_path_check(&h_path,
15183 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
15184 + IMA_COUNT_LEAVE);
15192 +static int aufs_permission(struct inode *inode, int mask)
15195 + aufs_bindex_t bindex, bend;
15196 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
15197 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
15198 + struct inode *h_inode;
15199 + struct super_block *sb;
15200 + struct au_branch *br;
15202 + /* todo: support rcu-walk? */
15203 + if (mask & MAY_NOT_BLOCK)
15206 + sb = inode->i_sb;
15207 + si_read_lock(sb, AuLock_FLUSH);
15208 + ii_read_lock_child(inode);
15210 + err = au_iigen_test(inode, au_sigen(sb));
15211 + if (unlikely(err))
15217 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
15218 + err = au_busy_or_stale();
15219 + h_inode = au_h_iptr(inode, au_ibstart(inode));
15220 + if (unlikely(!h_inode
15221 + || (h_inode->i_mode & S_IFMT)
15222 + != (inode->i_mode & S_IFMT)))
15226 + bindex = au_ibstart(inode);
15227 + br = au_sbr(sb, bindex);
15228 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
15231 + && !special_file(h_inode->i_mode)) {
15232 + /* test whether the upper writable branch exists */
15234 + for (; bindex >= 0; bindex--)
15235 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
15243 + /* non-write to dir */
15245 + bend = au_ibend(inode);
15246 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
15247 + h_inode = au_h_iptr(inode, bindex);
15249 + err = au_busy_or_stale();
15250 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
15253 + br = au_sbr(sb, bindex);
15254 + err = h_permission(h_inode, mask, &br->br_path,
15260 + ii_read_unlock(inode);
15261 + si_read_unlock(sb);
15265 +/* ---------------------------------------------------------------------- */
15267 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
15268 + unsigned int flags)
15270 + struct dentry *ret, *parent;
15271 + struct inode *inode;
15272 + struct super_block *sb;
15273 + int err, npositive;
15277 + /* todo: support rcu-walk? */
15278 + ret = ERR_PTR(-ECHILD);
15279 + if (flags & LOOKUP_RCU)
15282 + ret = ERR_PTR(-ENAMETOOLONG);
15283 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
15287 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
15288 + ret = ERR_PTR(err);
15289 + if (unlikely(err))
15292 + err = au_di_init(dentry);
15293 + ret = ERR_PTR(err);
15294 + if (unlikely(err))
15298 + npositive = 0; /* suppress a warning */
15299 + parent = dentry->d_parent; /* dir inode is locked */
15300 + di_read_lock_parent(parent, AuLock_IR);
15301 + err = au_alive_dir(parent);
15303 + err = au_digen_test(parent, au_sigen(sb));
15305 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
15309 + di_read_unlock(parent, AuLock_IR);
15310 + ret = ERR_PTR(err);
15311 + if (unlikely(err < 0))
15315 + inode = au_new_inode(dentry, /*must_new*/0);
15316 + if (IS_ERR(inode)) {
15317 + ret = (void *)inode;
15324 + atomic_inc(&inode->i_count);
15325 + ret = d_splice_alias(inode, dentry);
15327 + if (unlikely(d_need_lookup(dentry))) {
15328 + spin_lock(&dentry->d_lock);
15329 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
15330 + spin_unlock(&dentry->d_lock);
15334 + if (!IS_ERR(ret)) {
15336 + if (ret && ret != dentry)
15337 + ii_write_unlock(inode);
15339 + ii_write_unlock(inode);
15346 + di_write_unlock(dentry);
15348 + /* verbose coding for lock class name */
15349 + if (unlikely(S_ISLNK(inode->i_mode)))
15350 + au_rw_class(&au_di(dentry)->di_rwsem,
15351 + au_lc_key + AuLcSymlink_DIINFO);
15352 + else if (unlikely(S_ISDIR(inode->i_mode)))
15353 + au_rw_class(&au_di(dentry)->di_rwsem,
15354 + au_lc_key + AuLcDir_DIINFO);
15355 + else /* likely */
15356 + au_rw_class(&au_di(dentry)->di_rwsem,
15357 + au_lc_key + AuLcNonDir_DIINFO);
15360 + si_read_unlock(sb);
15365 +/* ---------------------------------------------------------------------- */
15367 +struct aopen_node {
15368 + struct hlist_node hlist;
15369 + struct file *file, *h_file;
15372 +static int au_do_aopen(struct inode *inode, struct file *file)
15374 + struct au_sphlhead *aopen;
15375 + struct aopen_node *node;
15376 + struct au_do_open_args args = {
15378 + .open = au_do_open_nondir
15381 + aopen = &au_sbi(inode->i_sb)->si_aopen;
15382 + spin_lock(&aopen->spin);
15383 + hlist_for_each_entry(node, &aopen->head, hlist)
15384 + if (node->file == file) {
15385 + args.h_file = node->h_file;
15388 + spin_unlock(&aopen->spin);
15389 + /* AuDebugOn(!args.h_file); */
15391 + return au_do_open(file, &args);
15394 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
15395 + struct file *file, unsigned int open_flag,
15396 + umode_t create_mode, int *opened)
15398 + int err, h_opened = *opened;
15399 + struct dentry *parent;
15400 + struct dentry *d;
15401 + struct au_sphlhead *aopen;
15402 + struct vfsub_aopen_args args = {
15403 + .open_flag = open_flag,
15404 + .create_mode = create_mode,
15405 + .opened = &h_opened
15407 + struct aopen_node aopen_node = {
15412 + AuDbg("open_flag 0x%x\n", open_flag);
15413 + AuDbgDentry(dentry);
15416 + if (!au_di(dentry)) {
15417 + d = aufs_lookup(dir, dentry, /*flags*/0);
15419 + err = PTR_ERR(d);
15423 + * obsoleted dentry found.
15424 + * another error will be returned later.
15430 + AuDbgDentry(dentry);
15433 + if (d_is_positive(dentry)
15434 + || d_unhashed(dentry)
15435 + || d_unlinked(dentry)
15436 + || !(open_flag & O_CREAT))
15437 + goto out_no_open;
15439 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
15440 + if (unlikely(err))
15443 + parent = dentry->d_parent; /* dir is locked */
15444 + di_write_lock_parent(parent);
15445 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
15446 + if (unlikely(err))
15449 + AuDbgDentry(dentry);
15450 + if (d_is_positive(dentry))
15453 + args.file = get_empty_filp();
15454 + err = PTR_ERR(args.file);
15455 + if (IS_ERR(args.file))
15458 + args.file->f_flags = file->f_flags;
15459 + err = au_aopen_or_create(dir, dentry, &args);
15461 + AuDbgFile(args.file);
15462 + if (unlikely(err < 0)) {
15463 + if (h_opened & FILE_OPENED)
15466 + put_filp(args.file);
15470 + /* some filesystems don't set FILE_CREATED while succeeded? */
15471 + *opened |= FILE_CREATED;
15472 + if (h_opened & FILE_OPENED)
15473 + aopen_node.h_file = args.file;
15475 + put_filp(args.file);
15476 + args.file = NULL;
15478 + aopen = &au_sbi(dir->i_sb)->si_aopen;
15479 + au_sphl_add(&aopen_node.hlist, aopen);
15480 + err = finish_open(file, dentry, au_do_aopen, opened);
15481 + au_sphl_del(&aopen_node.hlist, aopen);
15484 + if (aopen_node.h_file)
15485 + fput(aopen_node.h_file);
15488 + di_write_unlock(parent);
15489 + aufs_read_unlock(dentry, AuLock_DW);
15490 + AuDbgDentry(dentry);
15491 + if (unlikely(err))
15494 + if (!err && !(*opened & FILE_CREATED)) {
15495 + AuLabel(out_no_open);
15497 + err = finish_no_open(file, dentry);
15500 + AuDbg("%pd%s%s\n", dentry,
15501 + (*opened & FILE_CREATED) ? " created" : "",
15502 + (*opened & FILE_OPENED) ? " opened" : "");
15508 +/* ---------------------------------------------------------------------- */
15510 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
15511 + const unsigned char add_entry, aufs_bindex_t bcpup,
15512 + aufs_bindex_t bstart)
15515 + struct dentry *h_parent;
15516 + struct inode *h_dir;
15519 + IMustLock(d_inode(parent));
15521 + di_write_lock_parent(parent);
15524 + if (!au_h_dptr(parent, bcpup)) {
15525 + if (bstart > bcpup)
15526 + err = au_cpup_dirs(dentry, bcpup);
15527 + else if (bstart < bcpup)
15528 + err = au_cpdown_dirs(dentry, bcpup);
15532 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
15533 + h_parent = au_h_dptr(parent, bcpup);
15534 + h_dir = d_inode(h_parent);
15535 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
15536 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
15537 + /* todo: no unlock here */
15538 + mutex_unlock(&h_dir->i_mutex);
15540 + AuDbg("bcpup %d\n", bcpup);
15542 + if (d_really_is_negative(dentry))
15543 + au_set_h_dptr(dentry, bstart, NULL);
15544 + au_update_dbrange(dentry, /*do_put_zero*/0);
15549 + di_write_unlock(parent);
15551 + err = bcpup; /* success */
15558 + * decide the branch and the parent dir where we will create a new entry.
15559 + * returns new bindex or an error.
15560 + * copyup the parent dir if needed.
15562 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
15563 + struct au_wr_dir_args *args)
15566 + unsigned int flags;
15567 + aufs_bindex_t bcpup, bstart, src_bstart;
15568 + const unsigned char add_entry
15569 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
15570 + | au_ftest_wrdir(args->flags, TMPFILE);
15571 + struct super_block *sb;
15572 + struct dentry *parent;
15573 + struct au_sbinfo *sbinfo;
15575 + sb = dentry->d_sb;
15576 + sbinfo = au_sbi(sb);
15577 + parent = dget_parent(dentry);
15578 + bstart = au_dbstart(dentry);
15580 + if (args->force_btgt < 0) {
15581 + if (src_dentry) {
15582 + src_bstart = au_dbstart(src_dentry);
15583 + if (src_bstart < bstart)
15584 + bcpup = src_bstart;
15585 + } else if (add_entry) {
15587 + if (au_ftest_wrdir(args->flags, ISDIR))
15588 + au_fset_wbr(flags, DIR);
15589 + err = AuWbrCreate(sbinfo, dentry, flags);
15593 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
15595 + err = AuWbrCopyup(sbinfo, dentry);
15597 + if (!IS_ROOT(dentry)) {
15598 + di_read_lock_parent(parent, !AuLock_IR);
15599 + err = AuWbrCopyup(sbinfo, dentry);
15600 + di_read_unlock(parent, !AuLock_IR);
15602 + err = AuWbrCopyup(sbinfo, dentry);
15605 + if (unlikely(err < 0))
15609 + bcpup = args->force_btgt;
15610 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
15613 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
15615 + if (bcpup == bstart)
15616 + goto out; /* success */
15618 + /* copyup the new parent into the branch we process */
15619 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
15621 + if (d_really_is_negative(dentry)) {
15622 + au_set_h_dptr(dentry, bstart, NULL);
15623 + au_set_dbstart(dentry, bcpup);
15624 + au_set_dbend(dentry, bcpup);
15626 + AuDebugOn(add_entry
15627 + && !au_ftest_wrdir(args->flags, TMPFILE)
15628 + && !au_h_dptr(dentry, bcpup));
15636 +/* ---------------------------------------------------------------------- */
15638 +void au_pin_hdir_unlock(struct au_pin *p)
15641 + au_hn_imtx_unlock(p->hdir);
15644 +int au_pin_hdir_lock(struct au_pin *p)
15652 + /* even if an error happens later, keep this lock */
15653 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
15656 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
15661 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
15662 + p->h_parent, p->br);
15668 +int au_pin_hdir_relock(struct au_pin *p)
15671 + struct inode *h_i;
15672 + struct dentry *h_d[] = {
15677 + err = au_pin_hdir_lock(p);
15678 + if (unlikely(err))
15681 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
15684 + if (d_is_positive(h_d[i])) {
15685 + h_i = d_inode(h_d[i]);
15686 + err = !h_i->i_nlink;
15694 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
15696 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
15697 + p->hdir->hi_inode->i_mutex.owner = task;
15701 +void au_pin_hdir_acquire_nest(struct au_pin *p)
15704 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
15705 + p->lsc_hi, 0, NULL, _RET_IP_);
15706 + au_pin_hdir_set_owner(p, current);
15710 +void au_pin_hdir_release(struct au_pin *p)
15713 + au_pin_hdir_set_owner(p, p->task);
15714 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
15718 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
15720 + if (pin && pin->parent)
15721 + return au_h_dptr(pin->parent, pin->bindex);
15725 +void au_unpin(struct au_pin *p)
15728 + au_pin_hdir_unlock(p);
15729 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
15730 + vfsub_mnt_drop_write(p->h_mnt);
15734 + if (!au_ftest_pin(p->flags, DI_LOCKED))
15735 + di_read_unlock(p->parent, AuLock_IR);
15736 + iput(p->hdir->hi_inode);
15738 + p->parent = NULL;
15741 + /* do not clear p->task */
15744 +int au_do_pin(struct au_pin *p)
15747 + struct super_block *sb;
15748 + struct inode *h_dir;
15751 + sb = p->dentry->d_sb;
15752 + p->br = au_sbr(sb, p->bindex);
15753 + if (IS_ROOT(p->dentry)) {
15754 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
15755 + p->h_mnt = au_br_mnt(p->br);
15756 + err = vfsub_mnt_want_write(p->h_mnt);
15757 + if (unlikely(err)) {
15758 + au_fclr_pin(p->flags, MNT_WRITE);
15765 + p->h_dentry = NULL;
15766 + if (p->bindex <= au_dbend(p->dentry))
15767 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
15769 + p->parent = dget_parent(p->dentry);
15770 + if (!au_ftest_pin(p->flags, DI_LOCKED))
15771 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
15774 + p->h_parent = au_h_dptr(p->parent, p->bindex);
15775 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
15777 + h_dir = p->hdir->hi_inode;
15781 + * if DI_LOCKED is not set, then p->parent may be different
15782 + * and h_parent can be NULL.
15784 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
15786 + if (!au_ftest_pin(p->flags, DI_LOCKED))
15787 + di_read_unlock(p->parent, AuLock_IR);
15789 + p->parent = NULL;
15793 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
15794 + p->h_mnt = au_br_mnt(p->br);
15795 + err = vfsub_mnt_want_write(p->h_mnt);
15796 + if (unlikely(err)) {
15797 + au_fclr_pin(p->flags, MNT_WRITE);
15798 + if (!au_ftest_pin(p->flags, DI_LOCKED))
15799 + di_read_unlock(p->parent, AuLock_IR);
15801 + p->parent = NULL;
15807 + err = au_pin_hdir_lock(p);
15809 + goto out; /* success */
15814 + pr_err("err %d\n", err);
15815 + err = au_busy_or_stale();
15820 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
15821 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
15822 + unsigned int udba, unsigned char flags)
15824 + p->dentry = dentry;
15826 + p->lsc_di = lsc_di;
15827 + p->lsc_hi = lsc_hi;
15828 + p->flags = flags;
15829 + p->bindex = bindex;
15831 + p->parent = NULL;
15835 + p->h_dentry = NULL;
15836 + p->h_parent = NULL;
15838 + p->task = current;
15841 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
15842 + unsigned int udba, unsigned char flags)
15844 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
15846 + return au_do_pin(pin);
15849 +/* ---------------------------------------------------------------------- */
15852 + * ->setattr() and ->getattr() are called in various cases.
15853 + * chmod, stat: dentry is revalidated.
15854 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
15856 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
15858 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
15859 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
15862 + struct dentry *parent;
15865 + if (au_digen_test(dentry, sigen)) {
15866 + parent = dget_parent(dentry);
15867 + di_read_lock_parent(parent, AuLock_IR);
15868 + err = au_refresh_dentry(dentry, parent);
15869 + di_read_unlock(parent, AuLock_IR);
15877 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
15878 + struct au_icpup_args *a)
15882 + aufs_bindex_t bstart, ibstart;
15883 + struct dentry *hi_wh, *parent;
15884 + struct inode *inode;
15885 + struct au_wr_dir_args wr_dir_args = {
15886 + .force_btgt = -1,
15890 + if (d_is_dir(dentry))
15891 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
15892 + /* plink or hi_wh() case */
15893 + bstart = au_dbstart(dentry);
15894 + inode = d_inode(dentry);
15895 + ibstart = au_ibstart(inode);
15896 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
15897 + wr_dir_args.force_btgt = ibstart;
15898 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
15899 + if (unlikely(err < 0))
15902 + if (err != bstart)
15903 + au_fset_icpup(a->flags, DID_CPUP);
15906 + a->pin_flags = AuPin_MNT_WRITE;
15908 + if (!IS_ROOT(dentry)) {
15909 + au_fset_pin(a->pin_flags, DI_LOCKED);
15910 + parent = dget_parent(dentry);
15911 + di_write_lock_parent(parent);
15914 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
15915 + if (unlikely(err))
15918 + a->h_path.dentry = au_h_dptr(dentry, bstart);
15920 + a->h_inode = d_inode(a->h_path.dentry);
15921 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
15922 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
15923 + if (ia->ia_size < i_size_read(a->h_inode))
15924 + sz = ia->ia_size;
15925 + mutex_unlock(&a->h_inode->i_mutex);
15929 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
15930 + hi_wh = au_hi_wh(inode, a->btgt);
15932 + struct au_cp_generic cpg = {
15933 + .dentry = dentry,
15939 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
15940 + if (unlikely(err))
15942 + hi_wh = au_hi_wh(inode, a->btgt);
15943 + /* todo: revalidate hi_wh? */
15948 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
15949 + di_downgrade_lock(parent, AuLock_IR);
15953 + if (!au_ftest_icpup(a->flags, DID_CPUP))
15954 + goto out; /* success */
15956 + if (!d_unhashed(dentry)) {
15957 + struct au_cp_generic cpg = {
15958 + .dentry = dentry,
15963 + .flags = AuCpup_DTIME | AuCpup_HOPEN
15965 + err = au_sio_cpup_simple(&cpg);
15967 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
15968 + } else if (!hi_wh)
15969 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
15971 + a->h_path.dentry = hi_wh; /* do not dget here */
15974 + a->h_inode = d_inode(a->h_path.dentry);
15976 + goto out; /* success */
15977 + au_unpin(&a->pin);
15980 + di_write_unlock(parent);
15985 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
15989 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
15992 + struct inode *inode, *delegated;
15993 + struct super_block *sb;
15994 + struct file *file;
15995 + struct au_icpup_args *a;
15997 + inode = d_inode(dentry);
15998 + IMustLock(inode);
16001 + a = kzalloc(sizeof(*a), GFP_NOFS);
16002 + if (unlikely(!a))
16005 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
16006 + ia->ia_valid &= ~ATTR_MODE;
16009 + sb = dentry->d_sb;
16010 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16011 + if (unlikely(err))
16014 + if (ia->ia_valid & ATTR_FILE) {
16015 + /* currently ftruncate(2) only */
16016 + AuDebugOn(!d_is_reg(dentry));
16017 + file = ia->ia_file;
16018 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
16019 + if (unlikely(err))
16021 + ia->ia_file = au_hf_top(file);
16022 + a->udba = AuOpt_UDBA_NONE;
16024 + /* fchmod() doesn't pass ia_file */
16025 + a->udba = au_opt_udba(sb);
16026 + di_write_lock_child(dentry);
16027 + /* no d_unlinked(), to set UDBA_NONE for root */
16028 + if (d_unhashed(dentry))
16029 + a->udba = AuOpt_UDBA_NONE;
16030 + if (a->udba != AuOpt_UDBA_NONE) {
16031 + AuDebugOn(IS_ROOT(dentry));
16032 + err = au_reval_for_attr(dentry, au_sigen(sb));
16033 + if (unlikely(err))
16038 + err = au_pin_and_icpup(dentry, ia, a);
16039 + if (unlikely(err < 0))
16041 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
16042 + ia->ia_file = NULL;
16043 + ia->ia_valid &= ~ATTR_FILE;
16046 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
16047 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
16048 + == (ATTR_MODE | ATTR_CTIME)) {
16049 + err = security_path_chmod(&a->h_path, ia->ia_mode);
16050 + if (unlikely(err))
16052 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
16053 + && (ia->ia_valid & ATTR_CTIME)) {
16054 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
16055 + if (unlikely(err))
16059 + if (ia->ia_valid & ATTR_SIZE) {
16062 + if (ia->ia_size < i_size_read(inode))
16064 + truncate_setsize(inode, ia->ia_size);
16067 + if (ia->ia_valid & ATTR_FILE)
16069 + mutex_unlock(&a->h_inode->i_mutex);
16070 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
16071 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
16073 + delegated = NULL;
16075 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
16077 + err = break_deleg_wait(&delegated);
16085 + * regardless aufs 'acl' option setting.
16086 + * why don't all acl-aware fs call this func from their ->setattr()?
16088 + if (!err && (ia->ia_valid & ATTR_MODE))
16089 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
16091 + au_cpup_attr_changeable(inode);
16094 + mutex_unlock(&a->h_inode->i_mutex);
16095 + au_unpin(&a->pin);
16096 + if (unlikely(err))
16097 + au_update_dbstart(dentry);
16099 + di_write_unlock(dentry);
16101 + fi_write_unlock(file);
16102 + ia->ia_file = file;
16103 + ia->ia_valid |= ATTR_FILE;
16106 + si_read_unlock(sb);
16114 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16115 +static int au_h_path_to_set_attr(struct dentry *dentry,
16116 + struct au_icpup_args *a, struct path *h_path)
16119 + struct super_block *sb;
16121 + sb = dentry->d_sb;
16122 + a->udba = au_opt_udba(sb);
16123 + /* no d_unlinked(), to set UDBA_NONE for root */
16124 + if (d_unhashed(dentry))
16125 + a->udba = AuOpt_UDBA_NONE;
16126 + if (a->udba != AuOpt_UDBA_NONE) {
16127 + AuDebugOn(IS_ROOT(dentry));
16128 + err = au_reval_for_attr(dentry, au_sigen(sb));
16129 + if (unlikely(err))
16132 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
16133 + if (unlikely(err < 0))
16136 + h_path->dentry = a->h_path.dentry;
16137 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
16143 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
16146 + struct path h_path;
16147 + struct super_block *sb;
16148 + struct au_icpup_args *a;
16149 + struct inode *inode, *h_inode;
16151 + inode = d_inode(dentry);
16152 + IMustLock(inode);
16155 + a = kzalloc(sizeof(*a), GFP_NOFS);
16156 + if (unlikely(!a))
16159 + sb = dentry->d_sb;
16160 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16161 + if (unlikely(err))
16164 + h_path.dentry = NULL; /* silence gcc */
16165 + di_write_lock_child(dentry);
16166 + err = au_h_path_to_set_attr(dentry, a, &h_path);
16167 + if (unlikely(err))
16170 + mutex_unlock(&a->h_inode->i_mutex);
16171 + switch (arg->type) {
16172 + case AU_XATTR_SET:
16173 + err = vfsub_setxattr(h_path.dentry,
16174 + arg->u.set.name, arg->u.set.value,
16175 + arg->u.set.size, arg->u.set.flags);
16177 + case AU_XATTR_REMOVE:
16178 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
16181 + err = -EOPNOTSUPP;
16182 + h_inode = d_inode(h_path.dentry);
16183 + if (h_inode->i_op->set_acl)
16184 + err = h_inode->i_op->set_acl(h_inode,
16185 + arg->u.acl_set.acl,
16186 + arg->u.acl_set.type);
16190 + au_cpup_attr_timesizes(inode);
16192 + au_unpin(&a->pin);
16193 + if (unlikely(err))
16194 + au_update_dbstart(dentry);
16197 + di_write_unlock(dentry);
16198 + si_read_unlock(sb);
16207 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
16208 + unsigned int nlink)
16212 + inode->i_mode = st->mode;
16213 + /* don't i_[ug]id_write() here */
16214 + inode->i_uid = st->uid;
16215 + inode->i_gid = st->gid;
16216 + inode->i_atime = st->atime;
16217 + inode->i_mtime = st->mtime;
16218 + inode->i_ctime = st->ctime;
16220 + au_cpup_attr_nlink(inode, /*force*/0);
16221 + if (S_ISDIR(inode->i_mode)) {
16222 + n = inode->i_nlink;
16225 + smp_mb(); /* for i_nlink */
16226 + /* 0 can happen */
16227 + set_nlink(inode, n);
16230 + spin_lock(&inode->i_lock);
16231 + inode->i_blocks = st->blocks;
16232 + i_size_write(inode, st->size);
16233 + spin_unlock(&inode->i_lock);
16237 + * common routine for aufs_getattr() and aufs_getxattr().
16238 + * returns zero or negative (an error).
16239 + * @dentry will be read-locked in success.
16241 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
16244 + unsigned int mnt_flags, sigen;
16245 + unsigned char udba_none;
16246 + aufs_bindex_t bindex;
16247 + struct super_block *sb, *h_sb;
16248 + struct inode *inode;
16250 + h_path->mnt = NULL;
16251 + h_path->dentry = NULL;
16254 + sb = dentry->d_sb;
16255 + mnt_flags = au_mntflags(sb);
16256 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
16258 + /* support fstat(2) */
16259 + if (!d_unlinked(dentry) && !udba_none) {
16260 + sigen = au_sigen(sb);
16261 + err = au_digen_test(dentry, sigen);
16263 + di_read_lock_child(dentry, AuLock_IR);
16264 + err = au_dbrange_test(dentry);
16265 + if (unlikely(err)) {
16266 + di_read_unlock(dentry, AuLock_IR);
16270 + AuDebugOn(IS_ROOT(dentry));
16271 + di_write_lock_child(dentry);
16272 + err = au_dbrange_test(dentry);
16274 + err = au_reval_for_attr(dentry, sigen);
16276 + di_downgrade_lock(dentry, AuLock_IR);
16278 + di_write_unlock(dentry);
16283 + di_read_lock_child(dentry, AuLock_IR);
16285 + inode = d_inode(dentry);
16286 + bindex = au_ibstart(inode);
16287 + h_path->mnt = au_sbr_mnt(sb, bindex);
16288 + h_sb = h_path->mnt->mnt_sb;
16290 + && !au_test_fs_bad_iattr(h_sb)
16292 + goto out; /* success */
16294 + if (au_dbstart(dentry) == bindex)
16295 + h_path->dentry = au_h_dptr(dentry, bindex);
16296 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
16297 + h_path->dentry = au_plink_lkup(inode, bindex);
16298 + if (IS_ERR(h_path->dentry))
16299 + /* pretending success */
16300 + h_path->dentry = NULL;
16302 + dput(h_path->dentry);
16309 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
16310 + struct dentry *dentry, struct kstat *st)
16313 + unsigned char positive;
16314 + struct path h_path;
16315 + struct inode *inode;
16316 + struct super_block *sb;
16318 + inode = d_inode(dentry);
16319 + sb = dentry->d_sb;
16320 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
16321 + if (unlikely(err))
16323 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
16324 + if (unlikely(err))
16326 + if (unlikely(!h_path.dentry))
16327 + /* illegally overlapped or something */
16328 + goto out_fill; /* pretending success */
16330 + positive = d_is_positive(h_path.dentry);
16332 + err = vfs_getattr(&h_path, st);
16335 + au_refresh_iattr(inode, st,
16336 + d_inode(h_path.dentry)->i_nlink);
16337 + goto out_fill; /* success */
16343 + generic_fillattr(inode, st);
16345 + di_read_unlock(dentry, AuLock_IR);
16347 + si_read_unlock(sb);
16353 +/* ---------------------------------------------------------------------- */
16357 + * - the number of symlinks is not so many.
16360 + * - sbinfo (instead of iinfo) contains an hlist of struct au_symlink.
16361 + * If iinfo contained the hlist, then it would be rather large waste of memory
16363 + * - struct au_symlink contains the necessary info for h_inode follow_link() and
16367 +struct au_symlink {
16369 + struct hlist_node hlist;
16370 + struct rcu_head rcu;
16373 + struct inode *h_inode;
16377 +static void au_symlink_add(struct super_block *sb, struct au_symlink *slink,
16378 + struct inode *h_inode, void *cookie)
16380 + struct au_sbinfo *sbinfo;
16383 + slink->h_inode = h_inode;
16384 + slink->h_cookie = cookie;
16385 + sbinfo = au_sbi(sb);
16386 + au_sphl_add(&slink->hlist, &sbinfo->si_symlink);
16389 +static void au_symlink_del(struct super_block *sb, struct au_symlink *slink)
16391 + struct au_sbinfo *sbinfo;
16393 + /* do not iput() within rcu */
16394 + iput(slink->h_inode);
16395 + slink->h_inode = NULL;
16396 + sbinfo = au_sbi(sb);
16397 + au_sphl_del_rcu(&slink->hlist, &sbinfo->si_symlink);
16398 + kfree_rcu(slink, rcu);
16401 +static const char *aufs_follow_link(struct dentry *dentry, void **cookie)
16404 + struct inode *inode, *h_inode;
16405 + struct dentry *h_dentry;
16406 + struct au_symlink *slink;
16408 + aufs_bindex_t bindex;
16410 + ret = NULL; /* suppress a warning */
16411 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
16412 + if (unlikely(err))
16415 + err = au_d_hashed_positive(dentry);
16416 + if (unlikely(err))
16420 + inode = d_inode(dentry);
16421 + bindex = au_ibstart(inode);
16422 + h_inode = au_h_iptr(inode, bindex);
16423 + if (unlikely(!h_inode->i_op->follow_link))
16427 + slink = kmalloc(sizeof(*slink), GFP_NOFS);
16428 + if (unlikely(!slink))
16433 + if (au_dbstart(dentry) <= bindex) {
16434 + h_dentry = au_h_dptr(dentry, bindex);
16439 + h_dentry = d_find_any_alias(h_inode);
16440 + if (IS_ERR(h_dentry)) {
16441 + err = PTR_ERR(h_dentry);
16445 + if (unlikely(!h_dentry))
16449 + AuDbg("%pf\n", h_inode->i_op->follow_link);
16450 + AuDbgDentry(h_dentry);
16451 + ret = h_inode->i_op->follow_link(h_dentry, cookie);
16454 + if (!IS_ERR_OR_NULL(ret)) {
16455 + au_symlink_add(inode->i_sb, slink, h_inode, *cookie);
16457 + AuDbg("slink %p\n", slink);
16458 + goto out_unlock; /* success */
16462 + slink->h_inode = NULL;
16463 + kfree_rcu(slink, rcu);
16465 + aufs_read_unlock(dentry, AuLock_IR);
16467 + if (unlikely(err))
16468 + ret = ERR_PTR(err);
16469 + AuTraceErrPtr(ret);
16473 +static void aufs_put_link(struct inode *inode, void *cookie)
16475 + struct au_symlink *slink;
16476 + struct inode *h_inode;
16479 + AuDbg("slink %p\n", slink);
16480 + h_inode = slink->h_inode;
16481 + AuDbg("%pf\n", h_inode->i_op->put_link);
16482 + AuDbgInode(h_inode);
16483 + if (h_inode->i_op->put_link)
16484 + h_inode->i_op->put_link(h_inode, slink->h_cookie);
16485 + au_symlink_del(inode->i_sb, slink);
16488 +/* ---------------------------------------------------------------------- */
16490 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
16493 + struct super_block *sb;
16494 + struct inode *h_inode;
16496 + sb = inode->i_sb;
16497 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
16499 + si_read_lock(sb, AuLock_FLUSH);
16500 + ii_write_lock_child(inode);
16502 + h_inode = au_h_iptr(inode, au_ibstart(inode));
16503 + err = vfsub_update_time(h_inode, ts, flags);
16506 + au_cpup_attr_timesizes(inode);
16507 + ii_write_unlock(inode);
16508 + si_read_unlock(sb);
16511 + if (!err && (flags & S_VERSION))
16512 + inode_inc_iversion(inode);
16517 +/* ---------------------------------------------------------------------- */
16519 +/* no getattr version will be set by module.c:aufs_init() */
16520 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
16522 + [AuIop_SYMLINK] = {
16523 + .permission = aufs_permission,
16524 +#ifdef CONFIG_FS_POSIX_ACL
16525 + .get_acl = aufs_get_acl,
16526 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
16529 + .setattr = aufs_setattr,
16530 + .getattr = aufs_getattr,
16532 +#ifdef CONFIG_AUFS_XATTR
16533 + .setxattr = aufs_setxattr,
16534 + .getxattr = aufs_getxattr,
16535 + .listxattr = aufs_listxattr,
16536 + .removexattr = aufs_removexattr,
16539 + .readlink = generic_readlink,
16540 + .follow_link = aufs_follow_link,
16541 + .put_link = aufs_put_link,
16543 + /* .update_time = aufs_update_time */
16546 + .create = aufs_create,
16547 + .lookup = aufs_lookup,
16548 + .link = aufs_link,
16549 + .unlink = aufs_unlink,
16550 + .symlink = aufs_symlink,
16551 + .mkdir = aufs_mkdir,
16552 + .rmdir = aufs_rmdir,
16553 + .mknod = aufs_mknod,
16554 + .rename = aufs_rename,
16556 + .permission = aufs_permission,
16557 +#ifdef CONFIG_FS_POSIX_ACL
16558 + .get_acl = aufs_get_acl,
16559 + .set_acl = aufs_set_acl,
16562 + .setattr = aufs_setattr,
16563 + .getattr = aufs_getattr,
16565 +#ifdef CONFIG_AUFS_XATTR
16566 + .setxattr = aufs_setxattr,
16567 + .getxattr = aufs_getxattr,
16568 + .listxattr = aufs_listxattr,
16569 + .removexattr = aufs_removexattr,
16572 + .update_time = aufs_update_time,
16573 + .atomic_open = aufs_atomic_open,
16574 + .tmpfile = aufs_tmpfile
16576 + [AuIop_OTHER] = {
16577 + .permission = aufs_permission,
16578 +#ifdef CONFIG_FS_POSIX_ACL
16579 + .get_acl = aufs_get_acl,
16580 + .set_acl = aufs_set_acl,
16583 + .setattr = aufs_setattr,
16584 + .getattr = aufs_getattr,
16586 +#ifdef CONFIG_AUFS_XATTR
16587 + .setxattr = aufs_setxattr,
16588 + .getxattr = aufs_getxattr,
16589 + .listxattr = aufs_listxattr,
16590 + .removexattr = aufs_removexattr,
16593 + .update_time = aufs_update_time
16596 diff -urNp -x '*.orig' linux-4.4/fs/aufs/i_op_add.c linux-4.4/fs/aufs/i_op_add.c
16597 --- linux-4.4/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
16598 +++ linux-4.4/fs/aufs/i_op_add.c 2021-02-24 17:28:14.405474836 +0100
16601 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16603 + * This program, aufs is free software; you can redistribute it and/or modify
16604 + * it under the terms of the GNU General Public License as published by
16605 + * the Free Software Foundation; either version 2 of the License, or
16606 + * (at your option) any later version.
16608 + * This program is distributed in the hope that it will be useful,
16609 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16610 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16611 + * GNU General Public License for more details.
16613 + * You should have received a copy of the GNU General Public License
16614 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16618 + * inode operations (add entry)
16624 + * final procedure of adding a new entry, except link(2).
16625 + * remove whiteout, instantiate, copyup the parent dir's times and size
16626 + * and update version.
16627 + * if it failed, re-create the removed whiteout.
16629 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
16630 + struct dentry *wh_dentry, struct dentry *dentry)
16633 + aufs_bindex_t bwh;
16634 + struct path h_path;
16635 + struct super_block *sb;
16636 + struct inode *inode, *h_dir;
16637 + struct dentry *wh;
16642 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
16643 + IMustLock(h_dir);
16644 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
16645 + bwh = au_dbwh(dentry);
16646 + h_path.dentry = wh_dentry;
16647 + h_path.mnt = au_sbr_mnt(sb, bindex);
16648 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
16650 + if (unlikely(err))
16654 + inode = au_new_inode(dentry, /*must_new*/1);
16655 + if (!IS_ERR(inode)) {
16656 + d_instantiate(dentry, inode);
16657 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
16659 + au_dir_ts(dir, bindex);
16660 + dir->i_version++;
16661 + au_fhsm_wrote(sb, bindex, /*force*/0);
16662 + return 0; /* success */
16665 + err = PTR_ERR(inode);
16670 + /* dir inode is locked */
16671 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
16672 + rerr = PTR_ERR(wh);
16673 + if (IS_ERR(wh)) {
16674 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
16675 + dentry, err, rerr);
16684 +static int au_d_may_add(struct dentry *dentry)
16689 + if (unlikely(d_unhashed(dentry)))
16691 + if (unlikely(d_really_is_positive(dentry)))
16697 + * simple tests for the adding inode operations.
16698 + * following the checks in vfs, plus the parent-child relationship.
16700 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16701 + struct dentry *h_parent, int isdir)
16705 + struct dentry *h_dentry;
16706 + struct inode *h_inode;
16708 + err = -ENAMETOOLONG;
16709 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16712 + h_dentry = au_h_dptr(dentry, bindex);
16713 + if (d_really_is_negative(dentry)) {
16715 + if (unlikely(d_is_positive(h_dentry)))
16718 + /* rename(2) case */
16720 + if (unlikely(d_is_negative(h_dentry)))
16722 + h_inode = d_inode(h_dentry);
16723 + if (unlikely(!h_inode->i_nlink))
16726 + h_mode = h_inode->i_mode;
16729 + if (unlikely(S_ISDIR(h_mode)))
16731 + } else if (unlikely(!S_ISDIR(h_mode))) {
16738 + /* expected parent dir is locked */
16739 + if (unlikely(h_parent != h_dentry->d_parent))
16748 + * initial procedure of adding a new entry.
16749 + * prepare writable branch and the parent dir, lock it,
16750 + * and lookup whiteout for the new entry.
16752 +static struct dentry*
16753 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
16754 + struct dentry *src_dentry, struct au_pin *pin,
16755 + struct au_wr_dir_args *wr_dir_args)
16757 + struct dentry *wh_dentry, *h_parent;
16758 + struct super_block *sb;
16759 + struct au_branch *br;
16761 + unsigned int udba;
16762 + aufs_bindex_t bcpup;
16764 + AuDbg("%pd\n", dentry);
16766 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
16768 + wh_dentry = ERR_PTR(err);
16769 + if (unlikely(err < 0))
16772 + sb = dentry->d_sb;
16773 + udba = au_opt_udba(sb);
16774 + err = au_pin(pin, dentry, bcpup, udba,
16775 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
16776 + wh_dentry = ERR_PTR(err);
16777 + if (unlikely(err))
16780 + h_parent = au_pinned_h_parent(pin);
16781 + if (udba != AuOpt_UDBA_NONE
16782 + && au_dbstart(dentry) == bcpup)
16783 + err = au_may_add(dentry, bcpup, h_parent,
16784 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
16785 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
16786 + err = -ENAMETOOLONG;
16787 + wh_dentry = ERR_PTR(err);
16788 + if (unlikely(err))
16791 + br = au_sbr(sb, bcpup);
16793 + struct path tmp = {
16794 + .dentry = h_parent,
16795 + .mnt = au_br_mnt(br)
16797 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
16800 + wh_dentry = NULL;
16801 + if (bcpup != au_dbwh(dentry))
16802 + goto out; /* success */
16805 + * ENAMETOOLONG here means that if we allowed create such name, then it
16806 + * would not be able to removed in the future. So we don't allow such
16807 + * name here and we don't handle ENAMETOOLONG differently here.
16809 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
16812 + if (IS_ERR(wh_dentry))
16815 + return wh_dentry;
16818 +/* ---------------------------------------------------------------------- */
16820 +enum { Mknod, Symlink, Creat };
16821 +struct simple_arg {
16828 + struct vfsub_aopen_args *aopen;
16831 + const char *symname;
16840 +static int add_simple(struct inode *dir, struct dentry *dentry,
16841 + struct simple_arg *arg)
16844 + aufs_bindex_t bstart;
16845 + unsigned char created;
16846 + const unsigned char try_aopen
16847 + = (arg->type == Creat && arg->u.c.try_aopen);
16848 + struct dentry *wh_dentry, *parent;
16849 + struct inode *h_dir;
16850 + struct super_block *sb;
16851 + struct au_branch *br;
16852 + /* to reuduce stack size */
16854 + struct au_dtime dt;
16855 + struct au_pin pin;
16856 + struct path h_path;
16857 + struct au_wr_dir_args wr_dir_args;
16860 + AuDbg("%pd\n", dentry);
16864 + a = kmalloc(sizeof(*a), GFP_NOFS);
16865 + if (unlikely(!a))
16867 + a->wr_dir_args.force_btgt = -1;
16868 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
16870 + parent = dentry->d_parent; /* dir inode is locked */
16871 + if (!try_aopen) {
16872 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
16873 + if (unlikely(err))
16876 + err = au_d_may_add(dentry);
16877 + if (unlikely(err))
16880 + di_write_lock_parent(parent);
16881 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
16882 + &a->pin, &a->wr_dir_args);
16883 + err = PTR_ERR(wh_dentry);
16884 + if (IS_ERR(wh_dentry))
16887 + bstart = au_dbstart(dentry);
16888 + sb = dentry->d_sb;
16889 + br = au_sbr(sb, bstart);
16890 + a->h_path.dentry = au_h_dptr(dentry, bstart);
16891 + a->h_path.mnt = au_br_mnt(br);
16892 + h_dir = au_pinned_h_dir(&a->pin);
16893 + switch (arg->type) {
16896 + if (!try_aopen || !h_dir->i_op->atomic_open)
16897 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
16898 + arg->u.c.want_excl);
16900 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
16901 + arg->u.c.aopen, br);
16904 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
16907 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
16915 + err = epilog(dir, bstart, wh_dentry, dentry);
16918 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
16919 + /* no delegation since it is just created */
16920 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
16923 + AuIOErr("%pd revert failure(%d, %d)\n",
16924 + dentry, err, rerr);
16927 + au_dtime_revert(&a->dt);
16930 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
16931 + *arg->u.c.aopen->opened |= FILE_CREATED;
16933 + au_unpin(&a->pin);
16938 + di_write_unlock(parent);
16940 + if (unlikely(err)) {
16941 + au_update_dbstart(dentry);
16945 + aufs_read_unlock(dentry, AuLock_DW);
16952 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16955 + struct simple_arg arg = {
16962 + return add_simple(dir, dentry, &arg);
16965 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
16967 + struct simple_arg arg = {
16969 + .u.s.symname = symname
16971 + return add_simple(dir, dentry, &arg);
16974 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16977 + struct simple_arg arg = {
16981 + .want_excl = want_excl
16984 + return add_simple(dir, dentry, &arg);
16987 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16988 + struct vfsub_aopen_args *aopen_args)
16990 + struct simple_arg arg = {
16993 + .mode = aopen_args->create_mode,
16994 + .want_excl = aopen_args->open_flag & O_EXCL,
16995 + .try_aopen = true,
16996 + .aopen = aopen_args
16999 + return add_simple(dir, dentry, &arg);
17002 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17005 + aufs_bindex_t bindex;
17006 + struct super_block *sb;
17007 + struct dentry *parent, *h_parent, *h_dentry;
17008 + struct inode *h_dir, *inode;
17009 + struct vfsmount *h_mnt;
17010 + struct au_wr_dir_args wr_dir_args = {
17011 + .force_btgt = -1,
17012 + .flags = AuWrDir_TMPFILE
17015 + /* copy-up may happen */
17016 + mutex_lock(&dir->i_mutex);
17019 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17020 + if (unlikely(err))
17023 + err = au_di_init(dentry);
17024 + if (unlikely(err))
17028 + parent = d_find_any_alias(dir);
17029 + AuDebugOn(!parent);
17030 + di_write_lock_parent(parent);
17031 + if (unlikely(d_inode(parent) != dir))
17034 + err = au_digen_test(parent, au_sigen(sb));
17035 + if (unlikely(err))
17038 + bindex = au_dbstart(parent);
17039 + au_set_dbstart(dentry, bindex);
17040 + au_set_dbend(dentry, bindex);
17041 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17043 + if (unlikely(err < 0))
17046 + err = -EOPNOTSUPP;
17047 + h_dir = au_h_iptr(dir, bindex);
17048 + if (unlikely(!h_dir->i_op->tmpfile))
17051 + h_mnt = au_sbr_mnt(sb, bindex);
17052 + err = vfsub_mnt_want_write(h_mnt);
17053 + if (unlikely(err))
17056 + h_parent = au_h_dptr(parent, bindex);
17057 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
17058 + if (unlikely(err))
17062 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17063 + if (unlikely(!h_dentry))
17066 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17067 + if (unlikely(err))
17070 + au_set_dbstart(dentry, bindex);
17071 + au_set_dbend(dentry, bindex);
17072 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17073 + inode = au_new_inode(dentry, /*must_new*/1);
17074 + if (IS_ERR(inode)) {
17075 + err = PTR_ERR(inode);
17076 + au_set_h_dptr(dentry, bindex, NULL);
17077 + au_set_dbstart(dentry, -1);
17078 + au_set_dbend(dentry, -1);
17080 + if (!inode->i_nlink)
17081 + set_nlink(inode, 1);
17082 + d_tmpfile(dentry, inode);
17083 + au_di(dentry)->di_tmpfile = 1;
17085 + /* update without i_mutex */
17086 + if (au_ibstart(dir) == au_dbstart(dentry))
17087 + au_cpup_attr_timesizes(dir);
17093 + vfsub_mnt_drop_write(h_mnt);
17095 + di_write_unlock(parent);
17097 + di_write_unlock(dentry);
17100 + /* verbose coding for lock class name */
17101 + au_rw_class(&au_di(dentry)->di_rwsem,
17102 + au_lc_key + AuLcNonDir_DIINFO);
17107 + au_di_fin(dentry);
17108 + dentry->d_fsdata = NULL;
17111 + si_read_unlock(sb);
17113 + mutex_unlock(&dir->i_mutex);
17117 +/* ---------------------------------------------------------------------- */
17119 +struct au_link_args {
17120 + aufs_bindex_t bdst, bsrc;
17121 + struct au_pin pin;
17122 + struct path h_path;
17123 + struct dentry *src_parent, *parent;
17126 +static int au_cpup_before_link(struct dentry *src_dentry,
17127 + struct au_link_args *a)
17130 + struct dentry *h_src_dentry;
17131 + struct au_cp_generic cpg = {
17132 + .dentry = src_dentry,
17137 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17140 + di_read_lock_parent(a->src_parent, AuLock_IR);
17141 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17142 + if (unlikely(err))
17145 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17146 + err = au_pin(&a->pin, src_dentry, a->bdst,
17147 + au_opt_udba(src_dentry->d_sb),
17148 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17149 + if (unlikely(err))
17152 + err = au_sio_cpup_simple(&cpg);
17153 + au_unpin(&a->pin);
17156 + di_read_unlock(a->src_parent, AuLock_IR);
17160 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17161 + struct au_link_args *a)
17164 + unsigned char plink;
17165 + aufs_bindex_t bend;
17166 + struct dentry *h_src_dentry;
17167 + struct inode *h_inode, *inode, *delegated;
17168 + struct super_block *sb;
17169 + struct file *h_file;
17173 + sb = src_dentry->d_sb;
17174 + inode = d_inode(src_dentry);
17175 + if (au_ibstart(inode) <= a->bdst)
17176 + h_inode = au_h_iptr(inode, a->bdst);
17177 + if (!h_inode || !h_inode->i_nlink) {
17178 + /* copyup src_dentry as the name of dentry. */
17179 + bend = au_dbend(dentry);
17180 + if (bend < a->bsrc)
17181 + au_set_dbend(dentry, a->bsrc);
17182 + au_set_h_dptr(dentry, a->bsrc,
17183 + dget(au_h_dptr(src_dentry, a->bsrc)));
17184 + dget(a->h_path.dentry);
17185 + au_set_h_dptr(dentry, a->bdst, NULL);
17186 + AuDbg("temporary d_inode...\n");
17187 + spin_lock(&dentry->d_lock);
17188 + dentry->d_inode = d_inode(src_dentry); /* tmp */
17189 + spin_unlock(&dentry->d_lock);
17190 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17191 + if (IS_ERR(h_file))
17192 + err = PTR_ERR(h_file);
17194 + struct au_cp_generic cpg = {
17195 + .dentry = dentry,
17200 + .flags = AuCpup_KEEPLINO
17202 + err = au_sio_cpup_simple(&cpg);
17203 + au_h_open_post(dentry, a->bsrc, h_file);
17205 + dput(a->h_path.dentry);
17206 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17208 + au_set_h_dptr(dentry, a->bdst,
17209 + a->h_path.dentry);
17211 + spin_lock(&dentry->d_lock);
17212 + dentry->d_inode = NULL; /* restore */
17213 + spin_unlock(&dentry->d_lock);
17214 + AuDbg("temporary d_inode...done\n");
17215 + au_set_h_dptr(dentry, a->bsrc, NULL);
17216 + au_set_dbend(dentry, bend);
17218 + /* the inode of src_dentry already exists on a.bdst branch */
17219 + h_src_dentry = d_find_alias(h_inode);
17220 + if (!h_src_dentry && au_plink_test(inode)) {
17222 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17223 + err = PTR_ERR(h_src_dentry);
17224 + if (IS_ERR(h_src_dentry))
17227 + if (unlikely(d_is_negative(h_src_dentry))) {
17228 + dput(h_src_dentry);
17229 + h_src_dentry = NULL;
17233 + if (h_src_dentry) {
17234 + delegated = NULL;
17235 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17236 + &a->h_path, &delegated);
17237 + if (unlikely(err == -EWOULDBLOCK)) {
17238 + pr_warn("cannot retry for NFSv4 delegation"
17239 + " for an internal link\n");
17242 + dput(h_src_dentry);
17244 + AuIOErr("no dentry found for hi%lu on b%d\n",
17245 + h_inode->i_ino, a->bdst);
17250 + if (!err && !plink)
17251 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17258 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17259 + struct dentry *dentry)
17262 + struct au_dtime dt;
17263 + struct au_link_args *a;
17264 + struct dentry *wh_dentry, *h_src_dentry;
17265 + struct inode *inode, *delegated;
17266 + struct super_block *sb;
17267 + struct au_wr_dir_args wr_dir_args = {
17268 + /* .force_btgt = -1, */
17269 + .flags = AuWrDir_ADD_ENTRY
17273 + inode = d_inode(src_dentry);
17274 + IMustLock(inode);
17277 + a = kzalloc(sizeof(*a), GFP_NOFS);
17278 + if (unlikely(!a))
17281 + a->parent = dentry->d_parent; /* dir inode is locked */
17282 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17283 + AuLock_NOPLM | AuLock_GEN);
17284 + if (unlikely(err))
17286 + err = au_d_linkable(src_dentry);
17287 + if (unlikely(err))
17289 + err = au_d_may_add(dentry);
17290 + if (unlikely(err))
17293 + a->src_parent = dget_parent(src_dentry);
17294 + wr_dir_args.force_btgt = au_ibstart(inode);
17296 + di_write_lock_parent(a->parent);
17297 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
17298 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
17300 + err = PTR_ERR(wh_dentry);
17301 + if (IS_ERR(wh_dentry))
17305 + sb = dentry->d_sb;
17306 + a->bdst = au_dbstart(dentry);
17307 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17308 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17309 + a->bsrc = au_ibstart(inode);
17310 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17311 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
17312 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
17313 + if (!h_src_dentry) {
17314 + a->bsrc = au_dbstart(src_dentry);
17315 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17316 + AuDebugOn(!h_src_dentry);
17317 + } else if (IS_ERR(h_src_dentry)) {
17318 + err = PTR_ERR(h_src_dentry);
17322 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17323 + if (a->bdst < a->bsrc
17324 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17325 + err = au_cpup_or_link(src_dentry, dentry, a);
17327 + delegated = NULL;
17328 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17329 + &a->h_path, &delegated);
17330 + if (unlikely(err == -EWOULDBLOCK)) {
17331 + pr_warn("cannot retry for NFSv4 delegation"
17332 + " for an internal link\n");
17336 + dput(h_src_dentry);
17339 + * copyup src_dentry to the branch we process,
17340 + * and then link(2) to it.
17342 + dput(h_src_dentry);
17343 + if (a->bdst < a->bsrc
17344 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17345 + au_unpin(&a->pin);
17346 + di_write_unlock(a->parent);
17347 + err = au_cpup_before_link(src_dentry, a);
17348 + di_write_lock_parent(a->parent);
17350 + err = au_pin(&a->pin, dentry, a->bdst,
17352 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17353 + if (unlikely(err))
17357 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17359 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
17360 + delegated = NULL;
17361 + err = vfsub_link(h_src_dentry,
17362 + au_pinned_h_dir(&a->pin),
17363 + &a->h_path, &delegated);
17364 + if (unlikely(err == -EWOULDBLOCK)) {
17365 + pr_warn("cannot retry"
17366 + " for NFSv4 delegation"
17367 + " for an internal link\n");
17373 + if (unlikely(err))
17377 + a->h_path.dentry = wh_dentry;
17378 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17380 + if (unlikely(err))
17384 + au_dir_ts(dir, a->bdst);
17385 + dir->i_version++;
17386 + inc_nlink(inode);
17387 + inode->i_ctime = dir->i_ctime;
17388 + d_instantiate(dentry, au_igrab(inode));
17389 + if (d_unhashed(a->h_path.dentry))
17390 + /* some filesystem calls d_drop() */
17392 + /* some filesystems consume an inode even hardlink */
17393 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
17394 + goto out_unpin; /* success */
17397 + /* no delegation since it is just created */
17398 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17399 + /*delegated*/NULL, /*force*/0);
17400 + if (unlikely(rerr)) {
17401 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17404 + au_dtime_revert(&dt);
17406 + au_unpin(&a->pin);
17410 + di_write_unlock(a->parent);
17411 + dput(a->src_parent);
17413 + if (unlikely(err)) {
17414 + au_update_dbstart(dentry);
17417 + aufs_read_and_write_unlock2(dentry, src_dentry);
17425 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
17428 + aufs_bindex_t bindex;
17429 + unsigned char diropq;
17430 + struct path h_path;
17431 + struct dentry *wh_dentry, *parent, *opq_dentry;
17432 + struct mutex *h_mtx;
17433 + struct super_block *sb;
17435 + struct au_pin pin;
17436 + struct au_dtime dt;
17437 + } *a; /* reduce the stack usage */
17438 + struct au_wr_dir_args wr_dir_args = {
17439 + .force_btgt = -1,
17440 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
17446 + a = kmalloc(sizeof(*a), GFP_NOFS);
17447 + if (unlikely(!a))
17450 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17451 + if (unlikely(err))
17453 + err = au_d_may_add(dentry);
17454 + if (unlikely(err))
17457 + parent = dentry->d_parent; /* dir inode is locked */
17458 + di_write_lock_parent(parent);
17459 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17460 + &a->pin, &wr_dir_args);
17461 + err = PTR_ERR(wh_dentry);
17462 + if (IS_ERR(wh_dentry))
17465 + sb = dentry->d_sb;
17466 + bindex = au_dbstart(dentry);
17467 + h_path.dentry = au_h_dptr(dentry, bindex);
17468 + h_path.mnt = au_sbr_mnt(sb, bindex);
17469 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
17470 + if (unlikely(err))
17473 + /* make the dir opaque */
17475 + h_mtx = &d_inode(h_path.dentry)->i_mutex;
17477 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
17478 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17479 + opq_dentry = au_diropq_create(dentry, bindex);
17480 + mutex_unlock(h_mtx);
17481 + err = PTR_ERR(opq_dentry);
17482 + if (IS_ERR(opq_dentry))
17484 + dput(opq_dentry);
17488 + err = epilog(dir, bindex, wh_dentry, dentry);
17491 + goto out_unpin; /* success */
17496 + AuLabel(revert opq);
17497 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17498 + rerr = au_diropq_remove(dentry, bindex);
17499 + mutex_unlock(h_mtx);
17501 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
17502 + dentry, err, rerr);
17508 + AuLabel(revert dir);
17509 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
17511 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
17512 + dentry, err, rerr);
17515 + au_dtime_revert(&a->dt);
17517 + au_unpin(&a->pin);
17520 + di_write_unlock(parent);
17522 + if (unlikely(err)) {
17523 + au_update_dbstart(dentry);
17526 + aufs_read_unlock(dentry, AuLock_DW);
17532 diff -urNp -x '*.orig' linux-4.4/fs/aufs/i_op_del.c linux-4.4/fs/aufs/i_op_del.c
17533 --- linux-4.4/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
17534 +++ linux-4.4/fs/aufs/i_op_del.c 2021-02-24 17:28:14.408808278 +0100
17537 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17539 + * This program, aufs is free software; you can redistribute it and/or modify
17540 + * it under the terms of the GNU General Public License as published by
17541 + * the Free Software Foundation; either version 2 of the License, or
17542 + * (at your option) any later version.
17544 + * This program is distributed in the hope that it will be useful,
17545 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17546 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17547 + * GNU General Public License for more details.
17549 + * You should have received a copy of the GNU General Public License
17550 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17554 + * inode operations (del entry)
17560 + * decide if a new whiteout for @dentry is necessary or not.
17561 + * when it is necessary, prepare the parent dir for the upper branch whose
17562 + * branch index is @bcpup for creation. the actual creation of the whiteout will
17563 + * be done by caller.
17565 + * 0: wh is unnecessary
17566 + * plus: wh is necessary
17569 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
17571 + int need_wh, err;
17572 + aufs_bindex_t bstart;
17573 + struct super_block *sb;
17575 + sb = dentry->d_sb;
17576 + bstart = au_dbstart(dentry);
17577 + if (*bcpup < 0) {
17579 + if (au_test_ro(sb, bstart, d_inode(dentry))) {
17580 + err = AuWbrCopyup(au_sbi(sb), dentry);
17582 + if (unlikely(err < 0))
17586 + AuDebugOn(bstart < *bcpup
17587 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
17588 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
17590 + if (*bcpup != bstart) {
17591 + err = au_cpup_dirs(dentry, *bcpup);
17592 + if (unlikely(err))
17596 + struct au_dinfo *dinfo, *tmp;
17598 + need_wh = -ENOMEM;
17599 + dinfo = au_di(dentry);
17600 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
17602 + au_di_cp(tmp, dinfo);
17603 + au_di_swap(tmp, dinfo);
17604 + /* returns the number of positive dentries */
17605 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
17606 + au_di_swap(tmp, dinfo);
17607 + au_rw_write_unlock(&tmp->di_rwsem);
17611 + AuDbg("need_wh %d\n", need_wh);
17619 + * simple tests for the del-entry operations.
17620 + * following the checks in vfs, plus the parent-child relationship.
17622 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
17623 + struct dentry *h_parent, int isdir)
17627 + struct dentry *h_dentry, *h_latest;
17628 + struct inode *h_inode;
17630 + h_dentry = au_h_dptr(dentry, bindex);
17631 + if (d_really_is_positive(dentry)) {
17633 + if (unlikely(d_is_negative(h_dentry)))
17635 + h_inode = d_inode(h_dentry);
17636 + if (unlikely(!h_inode->i_nlink))
17639 + h_mode = h_inode->i_mode;
17642 + if (unlikely(S_ISDIR(h_mode)))
17644 + } else if (unlikely(!S_ISDIR(h_mode))) {
17649 + /* rename(2) case */
17651 + if (unlikely(d_is_positive(h_dentry)))
17656 + /* expected parent dir is locked */
17657 + if (unlikely(h_parent != h_dentry->d_parent))
17662 + * rmdir a dir may break the consistency on some filesystem.
17663 + * let's try heavy test.
17666 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
17667 + && au_test_h_perm(d_inode(h_parent),
17668 + MAY_EXEC | MAY_WRITE)))
17671 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
17673 + if (IS_ERR(h_latest))
17675 + if (h_latest == h_dentry)
17684 + * decide the branch where we operate for @dentry. the branch index will be set
17685 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
17686 + * dir for reverting.
17687 + * when a new whiteout is necessary, create it.
17689 +static struct dentry*
17690 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
17691 + struct au_dtime *dt, struct au_pin *pin)
17693 + struct dentry *wh_dentry;
17694 + struct super_block *sb;
17695 + struct path h_path;
17696 + int err, need_wh;
17697 + unsigned int udba;
17698 + aufs_bindex_t bcpup;
17700 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
17701 + wh_dentry = ERR_PTR(need_wh);
17702 + if (unlikely(need_wh < 0))
17705 + sb = dentry->d_sb;
17706 + udba = au_opt_udba(sb);
17708 + err = au_pin(pin, dentry, bcpup, udba,
17709 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17710 + wh_dentry = ERR_PTR(err);
17711 + if (unlikely(err))
17714 + h_path.dentry = au_pinned_h_parent(pin);
17715 + if (udba != AuOpt_UDBA_NONE
17716 + && au_dbstart(dentry) == bcpup) {
17717 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
17718 + wh_dentry = ERR_PTR(err);
17719 + if (unlikely(err))
17723 + h_path.mnt = au_sbr_mnt(sb, bcpup);
17724 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
17725 + wh_dentry = NULL;
17727 + goto out; /* success, no need to create whiteout */
17729 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
17730 + if (IS_ERR(wh_dentry))
17733 + /* returns with the parent is locked and wh_dentry is dget-ed */
17734 + goto out; /* success */
17739 + return wh_dentry;
17743 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
17744 + * in order to be revertible and save time for removing many child whiteouts
17746 + * returns 1 when there are too many child whiteout and caller should remove
17747 + * them asynchronously. returns 0 when the number of children is enough small to
17748 + * remove now or the branch fs is a remote fs.
17749 + * otherwise return an error.
17751 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
17752 + struct au_nhash *whlist, struct inode *dir)
17754 + int rmdir_later, err, dirwh;
17755 + struct dentry *h_dentry;
17756 + struct super_block *sb;
17757 + struct inode *inode;
17759 + sb = dentry->d_sb;
17760 + SiMustAnyLock(sb);
17761 + h_dentry = au_h_dptr(dentry, bindex);
17762 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
17763 + if (unlikely(err))
17766 + /* stop monitoring */
17767 + inode = d_inode(dentry);
17768 + au_hn_free(au_hi(inode, bindex));
17770 + if (!au_test_fs_remote(h_dentry->d_sb)) {
17771 + dirwh = au_sbi(sb)->si_dirwh;
17772 + rmdir_later = (dirwh <= 1);
17773 + if (!rmdir_later)
17774 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
17777 + return rmdir_later;
17780 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
17781 + if (unlikely(err)) {
17782 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
17783 + h_dentry, bindex, err);
17793 + * final procedure for deleting a entry.
17794 + * maintain dentry and iattr.
17796 +static void epilog(struct inode *dir, struct dentry *dentry,
17797 + aufs_bindex_t bindex)
17799 + struct inode *inode;
17801 + inode = d_inode(dentry);
17803 + inode->i_ctime = dir->i_ctime;
17805 + au_dir_ts(dir, bindex);
17806 + dir->i_version++;
17810 + * when an error happened, remove the created whiteout and revert everything.
17812 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
17813 + aufs_bindex_t bwh, struct dentry *wh_dentry,
17814 + struct dentry *dentry, struct au_dtime *dt)
17817 + struct path h_path = {
17818 + .dentry = wh_dentry,
17819 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
17822 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
17824 + au_set_dbwh(dentry, bwh);
17825 + au_dtime_revert(dt);
17829 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
17833 +/* ---------------------------------------------------------------------- */
17835 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
17838 + aufs_bindex_t bwh, bindex, bstart;
17839 + struct inode *inode, *h_dir, *delegated;
17840 + struct dentry *parent, *wh_dentry;
17841 + /* to reuduce stack size */
17843 + struct au_dtime dt;
17844 + struct au_pin pin;
17845 + struct path h_path;
17851 + a = kmalloc(sizeof(*a), GFP_NOFS);
17852 + if (unlikely(!a))
17855 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17856 + if (unlikely(err))
17858 + err = au_d_hashed_positive(dentry);
17859 + if (unlikely(err))
17861 + inode = d_inode(dentry);
17862 + IMustLock(inode);
17864 + if (unlikely(d_is_dir(dentry)))
17865 + goto out_unlock; /* possible? */
17867 + bstart = au_dbstart(dentry);
17868 + bwh = au_dbwh(dentry);
17870 + parent = dentry->d_parent; /* dir inode is locked */
17871 + di_write_lock_parent(parent);
17872 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
17874 + err = PTR_ERR(wh_dentry);
17875 + if (IS_ERR(wh_dentry))
17878 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17879 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17880 + dget(a->h_path.dentry);
17881 + if (bindex == bstart) {
17882 + h_dir = au_pinned_h_dir(&a->pin);
17883 + delegated = NULL;
17884 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
17885 + if (unlikely(err == -EWOULDBLOCK)) {
17886 + pr_warn("cannot retry for NFSv4 delegation"
17887 + " for an internal unlink\n");
17891 + /* dir inode is locked */
17892 + h_dir = d_inode(wh_dentry->d_parent);
17893 + IMustLock(h_dir);
17898 + vfsub_drop_nlink(inode);
17899 + epilog(dir, dentry, bindex);
17901 + /* update target timestamps */
17902 + if (bindex == bstart) {
17903 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
17905 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
17907 + /* todo: this timestamp may be reverted later */
17908 + inode->i_ctime = h_dir->i_ctime;
17909 + goto out_unpin; /* success */
17916 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
17923 + au_unpin(&a->pin);
17925 + dput(a->h_path.dentry);
17927 + di_write_unlock(parent);
17929 + aufs_read_unlock(dentry, AuLock_DW);
17936 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
17938 + int err, rmdir_later;
17939 + aufs_bindex_t bwh, bindex, bstart;
17940 + struct inode *inode;
17941 + struct dentry *parent, *wh_dentry, *h_dentry;
17942 + struct au_whtmp_rmdir *args;
17943 + /* to reuduce stack size */
17945 + struct au_dtime dt;
17946 + struct au_pin pin;
17952 + a = kmalloc(sizeof(*a), GFP_NOFS);
17953 + if (unlikely(!a))
17956 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
17957 + if (unlikely(err))
17959 + err = au_alive_dir(dentry);
17960 + if (unlikely(err))
17962 + inode = d_inode(dentry);
17963 + IMustLock(inode);
17965 + if (unlikely(!d_is_dir(dentry)))
17966 + goto out_unlock; /* possible? */
17969 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
17970 + if (unlikely(!args))
17973 + parent = dentry->d_parent; /* dir inode is locked */
17974 + di_write_lock_parent(parent);
17975 + err = au_test_empty(dentry, &args->whlist);
17976 + if (unlikely(err))
17979 + bstart = au_dbstart(dentry);
17980 + bwh = au_dbwh(dentry);
17982 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
17984 + err = PTR_ERR(wh_dentry);
17985 + if (IS_ERR(wh_dentry))
17988 + h_dentry = au_h_dptr(dentry, bstart);
17991 + if (bindex == bstart) {
17992 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
17994 + rmdir_later = err;
17998 + /* stop monitoring */
17999 + au_hn_free(au_hi(inode, bstart));
18001 + /* dir inode is locked */
18002 + IMustLock(d_inode(wh_dentry->d_parent));
18007 + vfsub_dead_dir(inode);
18008 + au_set_dbdiropq(dentry, -1);
18009 + epilog(dir, dentry, bindex);
18011 + if (rmdir_later) {
18012 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
18016 + goto out_unpin; /* success */
18024 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
18031 + au_unpin(&a->pin);
18035 + di_write_unlock(parent);
18037 + au_whtmp_rmdir_free(args);
18039 + aufs_read_unlock(dentry, AuLock_DW);
18046 diff -urNp -x '*.orig' linux-4.4/fs/aufs/i_op_ren.c linux-4.4/fs/aufs/i_op_ren.c
18047 --- linux-4.4/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
18048 +++ linux-4.4/fs/aufs/i_op_ren.c 2021-02-24 17:28:14.408808278 +0100
18051 + * Copyright (C) 2005-2016 Junjiro R. Okajima
18053 + * This program, aufs is free software; you can redistribute it and/or modify
18054 + * it under the terms of the GNU General Public License as published by
18055 + * the Free Software Foundation; either version 2 of the License, or
18056 + * (at your option) any later version.
18058 + * This program is distributed in the hope that it will be useful,
18059 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18060 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18061 + * GNU General Public License for more details.
18063 + * You should have received a copy of the GNU General Public License
18064 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18068 + * inode operation (rename entry)
18069 + * todo: this is crazy monster
18074 +enum { AuSRC, AuDST, AuSrcDst };
18075 +enum { AuPARENT, AuCHILD, AuParentChild };
18077 +#define AuRen_ISDIR 1
18078 +#define AuRen_ISSAMEDIR (1 << 1)
18079 +#define AuRen_WHSRC (1 << 2)
18080 +#define AuRen_WHDST (1 << 3)
18081 +#define AuRen_MNT_WRITE (1 << 4)
18082 +#define AuRen_DT_DSTDIR (1 << 5)
18083 +#define AuRen_DIROPQ (1 << 6)
18084 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
18085 +#define au_fset_ren(flags, name) \
18086 + do { (flags) |= AuRen_##name; } while (0)
18087 +#define au_fclr_ren(flags, name) \
18088 + do { (flags) &= ~AuRen_##name; } while (0)
18090 +struct au_ren_args {
18092 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
18094 + struct inode *dir, *inode;
18095 + struct au_hinode *hdir;
18096 + struct au_dtime dt[AuParentChild];
18097 + aufs_bindex_t bstart;
18100 +#define src_dentry sd[AuSRC].dentry
18101 +#define src_dir sd[AuSRC].dir
18102 +#define src_inode sd[AuSRC].inode
18103 +#define src_h_dentry sd[AuSRC].h_dentry
18104 +#define src_parent sd[AuSRC].parent
18105 +#define src_h_parent sd[AuSRC].h_parent
18106 +#define src_wh_dentry sd[AuSRC].wh_dentry
18107 +#define src_hdir sd[AuSRC].hdir
18108 +#define src_h_dir sd[AuSRC].hdir->hi_inode
18109 +#define src_dt sd[AuSRC].dt
18110 +#define src_bstart sd[AuSRC].bstart
18112 +#define dst_dentry sd[AuDST].dentry
18113 +#define dst_dir sd[AuDST].dir
18114 +#define dst_inode sd[AuDST].inode
18115 +#define dst_h_dentry sd[AuDST].h_dentry
18116 +#define dst_parent sd[AuDST].parent
18117 +#define dst_h_parent sd[AuDST].h_parent
18118 +#define dst_wh_dentry sd[AuDST].wh_dentry
18119 +#define dst_hdir sd[AuDST].hdir
18120 +#define dst_h_dir sd[AuDST].hdir->hi_inode
18121 +#define dst_dt sd[AuDST].dt
18122 +#define dst_bstart sd[AuDST].bstart
18124 + struct dentry *h_trap;
18125 + struct au_branch *br;
18126 + struct au_hinode *src_hinode;
18127 + struct path h_path;
18128 + struct au_nhash whlist;
18129 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
18131 + unsigned int flags;
18133 + struct au_whtmp_rmdir *thargs;
18134 + struct dentry *h_dst;
18137 +/* ---------------------------------------------------------------------- */
18140 + * functions for reverting.
18141 + * when an error happened in a single rename systemcall, we should revert
18142 + * everything as if nothing happened.
18143 + * we don't need to revert the copied-up/down the parent dir since they are
18147 +#define RevertFailure(fmt, ...) do { \
18148 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
18149 + ##__VA_ARGS__, err, rerr); \
18153 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
18157 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18158 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
18159 + au_hn_imtx_unlock(a->src_hinode);
18160 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
18162 + RevertFailure("remove diropq %pd", a->src_dentry);
18165 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
18168 + struct inode *delegated;
18170 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
18171 + a->src_h_parent);
18172 + rerr = PTR_ERR(a->h_path.dentry);
18173 + if (IS_ERR(a->h_path.dentry)) {
18174 + RevertFailure("lkup one %pd", a->src_dentry);
18178 + delegated = NULL;
18179 + rerr = vfsub_rename(a->dst_h_dir,
18180 + au_h_dptr(a->src_dentry, a->btgt),
18181 + a->src_h_dir, &a->h_path, &delegated);
18182 + if (unlikely(rerr == -EWOULDBLOCK)) {
18183 + pr_warn("cannot retry for NFSv4 delegation"
18184 + " for an internal rename\n");
18187 + d_drop(a->h_path.dentry);
18188 + dput(a->h_path.dentry);
18189 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
18191 + RevertFailure("rename %pd", a->src_dentry);
18194 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
18197 + struct inode *delegated;
18199 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
18200 + a->dst_h_parent);
18201 + rerr = PTR_ERR(a->h_path.dentry);
18202 + if (IS_ERR(a->h_path.dentry)) {
18203 + RevertFailure("lkup one %pd", a->dst_dentry);
18206 + if (d_is_positive(a->h_path.dentry)) {
18207 + d_drop(a->h_path.dentry);
18208 + dput(a->h_path.dentry);
18212 + delegated = NULL;
18213 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
18215 + if (unlikely(rerr == -EWOULDBLOCK)) {
18216 + pr_warn("cannot retry for NFSv4 delegation"
18217 + " for an internal rename\n");
18220 + d_drop(a->h_path.dentry);
18221 + dput(a->h_path.dentry);
18223 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
18225 + RevertFailure("rename %pd", a->h_dst);
18228 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
18232 + a->h_path.dentry = a->src_wh_dentry;
18233 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
18234 + au_set_dbwh(a->src_dentry, a->src_bwh);
18236 + RevertFailure("unlink %pd", a->src_wh_dentry);
18238 +#undef RevertFailure
18240 +/* ---------------------------------------------------------------------- */
18243 + * when we have to copyup the renaming entry, do it with the rename-target name
18244 + * in order to minimize the cost (the later actual rename is unnecessary).
18245 + * otherwise rename it on the target branch.
18247 +static int au_ren_or_cpup(struct au_ren_args *a)
18250 + struct dentry *d;
18251 + struct inode *delegated;
18253 + d = a->src_dentry;
18254 + if (au_dbstart(d) == a->btgt) {
18255 + a->h_path.dentry = a->dst_h_dentry;
18256 + if (au_ftest_ren(a->flags, DIROPQ)
18257 + && au_dbdiropq(d) == a->btgt)
18258 + au_fclr_ren(a->flags, DIROPQ);
18259 + AuDebugOn(au_dbstart(d) != a->btgt);
18260 + delegated = NULL;
18261 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
18262 + a->dst_h_dir, &a->h_path, &delegated);
18263 + if (unlikely(err == -EWOULDBLOCK)) {
18264 + pr_warn("cannot retry for NFSv4 delegation"
18265 + " for an internal rename\n");
18271 + if (!err && a->h_dst)
18272 + /* it will be set to dinfo later */
18278 +/* cf. aufs_rmdir() */
18279 +static int au_ren_del_whtmp(struct au_ren_args *a)
18282 + struct inode *dir;
18284 + dir = a->dst_dir;
18285 + SiMustAnyLock(dir->i_sb);
18286 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
18287 + au_sbi(dir->i_sb)->si_dirwh)
18288 + || au_test_fs_remote(a->h_dst->d_sb)) {
18289 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
18290 + if (unlikely(err))
18291 + pr_warn("failed removing whtmp dir %pd (%d), "
18292 + "ignored.\n", a->h_dst, err);
18294 + au_nhash_wh_free(&a->thargs->whlist);
18295 + a->thargs->whlist = a->whlist;
18296 + a->whlist.nh_num = 0;
18297 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
18299 + a->thargs = NULL;
18305 +/* make it 'opaque' dir. */
18306 +static int au_ren_diropq(struct au_ren_args *a)
18309 + struct dentry *diropq;
18312 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
18313 + a->src_hinode = au_hi(a->src_inode, a->btgt);
18314 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
18315 + diropq = au_diropq_create(a->src_dentry, a->btgt);
18316 + au_hn_imtx_unlock(a->src_hinode);
18317 + if (IS_ERR(diropq))
18318 + err = PTR_ERR(diropq);
18325 +static int do_rename(struct au_ren_args *a)
18328 + struct dentry *d, *h_d;
18330 + /* prepare workqueue args for asynchronous rmdir */
18331 + h_d = a->dst_h_dentry;
18332 + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) {
18334 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
18335 + if (unlikely(!a->thargs))
18337 + a->h_dst = dget(h_d);
18340 + /* create whiteout for src_dentry */
18341 + if (au_ftest_ren(a->flags, WHSRC)) {
18342 + a->src_bwh = au_dbwh(a->src_dentry);
18343 + AuDebugOn(a->src_bwh >= 0);
18345 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
18346 + err = PTR_ERR(a->src_wh_dentry);
18347 + if (IS_ERR(a->src_wh_dentry))
18351 + /* lookup whiteout for dentry */
18352 + if (au_ftest_ren(a->flags, WHDST)) {
18353 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
18355 + err = PTR_ERR(h_d);
18358 + if (d_is_negative(h_d))
18361 + a->dst_wh_dentry = h_d;
18364 + /* rename dentry to tmpwh */
18366 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
18367 + if (unlikely(err))
18370 + d = a->dst_dentry;
18371 + au_set_h_dptr(d, a->btgt, NULL);
18372 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
18373 + if (unlikely(err))
18375 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
18378 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_bstart != a->btgt);
18380 + /* rename by vfs_rename or cpup */
18381 + d = a->dst_dentry;
18382 + if (au_ftest_ren(a->flags, ISDIR)
18383 + && (a->dst_wh_dentry
18384 + || au_dbdiropq(d) == a->btgt
18385 + /* hide the lower to keep xino */
18386 + || a->btgt < au_dbend(d)
18387 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
18388 + au_fset_ren(a->flags, DIROPQ);
18389 + err = au_ren_or_cpup(a);
18390 + if (unlikely(err))
18391 + /* leave the copied-up one */
18394 + /* make dir opaque */
18395 + if (au_ftest_ren(a->flags, DIROPQ)) {
18396 + err = au_ren_diropq(a);
18397 + if (unlikely(err))
18401 + /* update target timestamps */
18402 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
18403 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
18404 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
18405 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
18407 + /* remove whiteout for dentry */
18408 + if (a->dst_wh_dentry) {
18409 + a->h_path.dentry = a->dst_wh_dentry;
18410 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
18412 + if (unlikely(err))
18416 + /* remove whtmp */
18418 + au_ren_del_whtmp(a); /* ignore this error */
18420 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
18422 + goto out_success;
18425 + if (au_ftest_ren(a->flags, DIROPQ))
18426 + au_ren_rev_diropq(err, a);
18428 + au_ren_rev_rename(err, a);
18432 + au_ren_rev_whtmp(err, a);
18434 + dput(a->dst_wh_dentry);
18435 + a->dst_wh_dentry = NULL;
18437 + if (a->src_wh_dentry)
18438 + au_ren_rev_whsrc(err, a);
18440 + dput(a->src_wh_dentry);
18441 + dput(a->dst_wh_dentry);
18445 + au_whtmp_rmdir_free(a->thargs);
18446 + a->thargs = NULL;
18452 +/* ---------------------------------------------------------------------- */
18455 + * test if @dentry dir can be rename destination or not.
18456 + * success means, it is a logically empty dir.
18458 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
18460 + return au_test_empty(dentry, whlist);
18464 + * test if @dentry dir can be rename source or not.
18465 + * if it can, return 0 and @children is filled.
18467 + * - it is a logically empty dir.
18468 + * - or, it exists on writable branch and has no children including whiteouts
18469 + * on the lower branch.
18471 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
18474 + unsigned int rdhash;
18475 + aufs_bindex_t bstart;
18477 + bstart = au_dbstart(dentry);
18478 + if (bstart != btgt) {
18479 + struct au_nhash whlist;
18481 + SiMustAnyLock(dentry->d_sb);
18482 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
18484 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
18486 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
18487 + if (unlikely(err))
18489 + err = au_test_empty(dentry, &whlist);
18490 + au_nhash_wh_free(&whlist);
18494 + if (bstart == au_dbtaildir(dentry))
18495 + return 0; /* success */
18497 + err = au_test_empty_lower(dentry);
18500 + if (err == -ENOTEMPTY) {
18501 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
18502 + " is not supported\n");
18508 +/* side effect: sets whlist and h_dentry */
18509 +static int au_ren_may_dir(struct au_ren_args *a)
18512 + unsigned int rdhash;
18513 + struct dentry *d;
18515 + d = a->dst_dentry;
18516 + SiMustAnyLock(d->d_sb);
18519 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
18520 + rdhash = au_sbi(d->d_sb)->si_rdhash;
18522 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
18523 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
18524 + if (unlikely(err))
18527 + au_set_dbstart(d, a->dst_bstart);
18528 + err = may_rename_dstdir(d, &a->whlist);
18529 + au_set_dbstart(d, a->btgt);
18531 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
18532 + if (unlikely(err))
18535 + d = a->src_dentry;
18536 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
18537 + if (au_ftest_ren(a->flags, ISDIR)) {
18538 + err = may_rename_srcdir(d, a->btgt);
18539 + if (unlikely(err)) {
18540 + au_nhash_wh_free(&a->whlist);
18541 + a->whlist.nh_num = 0;
18548 +/* ---------------------------------------------------------------------- */
18551 + * simple tests for rename.
18552 + * following the checks in vfs, plus the parent-child relationship.
18554 +static int au_may_ren(struct au_ren_args *a)
18557 + struct inode *h_inode;
18559 + if (a->src_bstart == a->btgt) {
18560 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
18561 + au_ftest_ren(a->flags, ISDIR));
18562 + if (unlikely(err))
18565 + if (unlikely(a->src_h_dentry == a->h_trap))
18570 + if (a->dst_bstart != a->btgt)
18573 + err = -ENOTEMPTY;
18574 + if (unlikely(a->dst_h_dentry == a->h_trap))
18578 + isdir = !!au_ftest_ren(a->flags, ISDIR);
18579 + if (d_really_is_negative(a->dst_dentry)) {
18580 + if (d_is_negative(a->dst_h_dentry))
18581 + err = au_may_add(a->dst_dentry, a->btgt,
18582 + a->dst_h_parent, isdir);
18584 + if (unlikely(d_is_negative(a->dst_h_dentry)))
18586 + h_inode = d_inode(a->dst_h_dentry);
18587 + if (h_inode->i_nlink)
18588 + err = au_may_del(a->dst_dentry, a->btgt,
18589 + a->dst_h_parent, isdir);
18593 + if (unlikely(err == -ENOENT || err == -EEXIST))
18599 +/* ---------------------------------------------------------------------- */
18604 + * - src_dir and dir by lock_rename()
18605 + * - inode if exitsts
18608 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
18610 + * + di_write_lock2_child()
18611 + * + di_write_lock_child()
18612 + * + ii_write_lock_child()
18613 + * + di_write_lock_child2()
18614 + * + ii_write_lock_child2()
18615 + * + src_parent and parent
18616 + * + di_write_lock_parent()
18617 + * + ii_write_lock_parent()
18618 + * + di_write_lock_parent2()
18619 + * + ii_write_lock_parent2()
18620 + * + lower src_dir and dir by vfsub_lock_rename()
18621 + * + verify the every relationships between child and parent. if any
18622 + * of them failed, unlock all and return -EBUSY.
18624 +static void au_ren_unlock(struct au_ren_args *a)
18626 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
18627 + a->dst_h_parent, a->dst_hdir);
18628 + if (au_ftest_ren(a->flags, MNT_WRITE))
18629 + vfsub_mnt_drop_write(au_br_mnt(a->br));
18632 +static int au_ren_lock(struct au_ren_args *a)
18635 + unsigned int udba;
18638 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
18639 + a->src_hdir = au_hi(a->src_dir, a->btgt);
18640 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
18641 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
18643 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
18644 + if (unlikely(err))
18646 + au_fset_ren(a->flags, MNT_WRITE);
18647 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
18648 + a->dst_h_parent, a->dst_hdir);
18649 + udba = au_opt_udba(a->src_dentry->d_sb);
18650 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
18651 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
18652 + err = au_busy_or_stale();
18653 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
18654 + err = au_h_verify(a->src_h_dentry, udba,
18655 + d_inode(a->src_h_parent), a->src_h_parent,
18657 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
18658 + err = au_h_verify(a->dst_h_dentry, udba,
18659 + d_inode(a->dst_h_parent), a->dst_h_parent,
18662 + goto out; /* success */
18664 + err = au_busy_or_stale();
18665 + au_ren_unlock(a);
18671 +/* ---------------------------------------------------------------------- */
18673 +static void au_ren_refresh_dir(struct au_ren_args *a)
18675 + struct inode *dir;
18677 + dir = a->dst_dir;
18678 + dir->i_version++;
18679 + if (au_ftest_ren(a->flags, ISDIR)) {
18680 + /* is this updating defined in POSIX? */
18681 + au_cpup_attr_timesizes(a->src_inode);
18682 + au_cpup_attr_nlink(dir, /*force*/1);
18685 + au_dir_ts(dir, a->btgt);
18687 + if (au_ftest_ren(a->flags, ISSAMEDIR))
18690 + dir = a->src_dir;
18691 + dir->i_version++;
18692 + if (au_ftest_ren(a->flags, ISDIR))
18693 + au_cpup_attr_nlink(dir, /*force*/1);
18694 + au_dir_ts(dir, a->btgt);
18697 +static void au_ren_refresh(struct au_ren_args *a)
18699 + aufs_bindex_t bend, bindex;
18700 + struct dentry *d, *h_d;
18701 + struct inode *i, *h_i;
18702 + struct super_block *sb;
18704 + d = a->dst_dentry;
18707 + /* already dget-ed by au_ren_or_cpup() */
18708 + au_set_h_dptr(d, a->btgt, a->h_dst);
18710 + i = a->dst_inode;
18712 + if (!au_ftest_ren(a->flags, ISDIR))
18713 + vfsub_drop_nlink(i);
18715 + vfsub_dead_dir(i);
18716 + au_cpup_attr_timesizes(i);
18718 + au_update_dbrange(d, /*do_put_zero*/1);
18721 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
18722 + au_set_h_dptr(d, bindex, NULL);
18723 + bend = au_dbend(d);
18724 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
18725 + au_set_h_dptr(d, bindex, NULL);
18726 + au_update_dbrange(d, /*do_put_zero*/0);
18729 + d = a->src_dentry;
18730 + au_set_dbwh(d, -1);
18731 + bend = au_dbend(d);
18732 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18733 + h_d = au_h_dptr(d, bindex);
18735 + au_set_h_dptr(d, bindex, NULL);
18737 + au_set_dbend(d, a->btgt);
18740 + i = a->src_inode;
18741 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
18742 + return; /* success */
18744 + bend = au_ibend(i);
18745 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
18746 + h_i = au_h_iptr(i, bindex);
18748 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
18749 + /* ignore this error */
18750 + au_set_h_iptr(i, bindex, NULL, 0);
18753 + au_set_ibend(i, a->btgt);
18756 +/* ---------------------------------------------------------------------- */
18758 +/* mainly for link(2) and rename(2) */
18759 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
18761 + aufs_bindex_t bdiropq, bwh;
18762 + struct dentry *parent;
18763 + struct au_branch *br;
18765 + parent = dentry->d_parent;
18766 + IMustLock(d_inode(parent)); /* dir is locked */
18768 + bdiropq = au_dbdiropq(parent);
18769 + bwh = au_dbwh(dentry);
18770 + br = au_sbr(dentry->d_sb, btgt);
18771 + if (au_br_rdonly(br)
18772 + || (0 <= bdiropq && bdiropq < btgt)
18773 + || (0 <= bwh && bwh < btgt))
18776 + AuDbg("btgt %d\n", btgt);
18780 +/* sets src_bstart, dst_bstart and btgt */
18781 +static int au_ren_wbr(struct au_ren_args *a)
18784 + struct au_wr_dir_args wr_dir_args = {
18785 + /* .force_btgt = -1, */
18786 + .flags = AuWrDir_ADD_ENTRY
18789 + a->src_bstart = au_dbstart(a->src_dentry);
18790 + a->dst_bstart = au_dbstart(a->dst_dentry);
18791 + if (au_ftest_ren(a->flags, ISDIR))
18792 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18793 + wr_dir_args.force_btgt = a->src_bstart;
18794 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
18795 + wr_dir_args.force_btgt = a->dst_bstart;
18796 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
18797 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
18803 +static void au_ren_dt(struct au_ren_args *a)
18805 + a->h_path.dentry = a->src_h_parent;
18806 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
18807 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
18808 + a->h_path.dentry = a->dst_h_parent;
18809 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
18812 + au_fclr_ren(a->flags, DT_DSTDIR);
18813 + if (!au_ftest_ren(a->flags, ISDIR))
18816 + a->h_path.dentry = a->src_h_dentry;
18817 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
18818 + if (d_is_positive(a->dst_h_dentry)) {
18819 + au_fset_ren(a->flags, DT_DSTDIR);
18820 + a->h_path.dentry = a->dst_h_dentry;
18821 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
18825 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
18827 + struct dentry *h_d;
18828 + struct mutex *h_mtx;
18830 + au_dtime_revert(a->src_dt + AuPARENT);
18831 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
18832 + au_dtime_revert(a->dst_dt + AuPARENT);
18834 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
18835 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
18836 + h_mtx = &d_inode(h_d)->i_mutex;
18837 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18838 + au_dtime_revert(a->src_dt + AuCHILD);
18839 + mutex_unlock(h_mtx);
18841 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
18842 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
18843 + h_mtx = &d_inode(h_d)->i_mutex;
18844 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18845 + au_dtime_revert(a->dst_dt + AuCHILD);
18846 + mutex_unlock(h_mtx);
18851 +/* ---------------------------------------------------------------------- */
18853 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
18854 + struct inode *_dst_dir, struct dentry *_dst_dentry)
18857 + /* reduce stack space */
18858 + struct au_ren_args *a;
18860 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
18861 + IMustLock(_src_dir);
18862 + IMustLock(_dst_dir);
18865 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
18866 + a = kzalloc(sizeof(*a), GFP_NOFS);
18867 + if (unlikely(!a))
18870 + a->src_dir = _src_dir;
18871 + a->src_dentry = _src_dentry;
18872 + a->src_inode = NULL;
18873 + if (d_really_is_positive(a->src_dentry))
18874 + a->src_inode = d_inode(a->src_dentry);
18875 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
18876 + a->dst_dir = _dst_dir;
18877 + a->dst_dentry = _dst_dentry;
18878 + a->dst_inode = NULL;
18879 + if (d_really_is_positive(a->dst_dentry))
18880 + a->dst_inode = d_inode(a->dst_dentry);
18881 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
18882 + if (a->dst_inode) {
18883 + IMustLock(a->dst_inode);
18884 + au_igrab(a->dst_inode);
18888 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
18889 + if (d_is_dir(a->src_dentry)) {
18890 + au_fset_ren(a->flags, ISDIR);
18891 + if (unlikely(d_really_is_positive(a->dst_dentry)
18892 + && !d_is_dir(a->dst_dentry)))
18894 + flags |= AuLock_DIRS;
18896 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, flags);
18897 + if (unlikely(err))
18900 + err = au_d_hashed_positive(a->src_dentry);
18901 + if (unlikely(err))
18904 + if (a->dst_inode) {
18906 + * If it is a dir, VFS unhash dst_dentry before this
18907 + * function. It means we cannot rely upon d_unhashed().
18909 + if (unlikely(!a->dst_inode->i_nlink))
18911 + if (!S_ISDIR(a->dst_inode->i_mode)) {
18912 + err = au_d_hashed_positive(a->dst_dentry);
18913 + if (unlikely(err))
18915 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
18917 + } else if (unlikely(d_unhashed(a->dst_dentry)))
18921 + * is it possible?
18922 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
18923 + * there may exist a problem somewhere else.
18926 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
18929 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
18930 + di_write_lock_parent(a->dst_parent);
18932 + /* which branch we process */
18933 + err = au_ren_wbr(a);
18934 + if (unlikely(err < 0))
18936 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
18937 + a->h_path.mnt = au_br_mnt(a->br);
18939 + /* are they available to be renamed */
18940 + err = au_ren_may_dir(a);
18941 + if (unlikely(err))
18942 + goto out_children;
18944 + /* prepare the writable parent dir on the same branch */
18945 + if (a->dst_bstart == a->btgt) {
18946 + au_fset_ren(a->flags, WHDST);
18948 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
18949 + if (unlikely(err))
18950 + goto out_children;
18953 + if (a->src_dir != a->dst_dir) {
18955 + * this temporary unlock is safe,
18956 + * because both dir->i_mutex are locked.
18958 + di_write_unlock(a->dst_parent);
18959 + di_write_lock_parent(a->src_parent);
18960 + err = au_wr_dir_need_wh(a->src_dentry,
18961 + au_ftest_ren(a->flags, ISDIR),
18963 + di_write_unlock(a->src_parent);
18964 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
18965 + au_fclr_ren(a->flags, ISSAMEDIR);
18967 + err = au_wr_dir_need_wh(a->src_dentry,
18968 + au_ftest_ren(a->flags, ISDIR),
18970 + if (unlikely(err < 0))
18971 + goto out_children;
18973 + au_fset_ren(a->flags, WHSRC);
18976 + if (a->src_bstart != a->btgt) {
18977 + struct au_pin pin;
18979 + err = au_pin(&pin, a->src_dentry, a->btgt,
18980 + au_opt_udba(a->src_dentry->d_sb),
18981 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18983 + struct au_cp_generic cpg = {
18984 + .dentry = a->src_dentry,
18986 + .bsrc = a->src_bstart,
18989 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18991 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
18992 + err = au_sio_cpup_simple(&cpg);
18995 + if (unlikely(err))
18996 + goto out_children;
18997 + a->src_bstart = a->btgt;
18998 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
18999 + au_fset_ren(a->flags, WHSRC);
19002 + /* lock them all */
19003 + err = au_ren_lock(a);
19004 + if (unlikely(err))
19005 + /* leave the copied-up one */
19006 + goto out_children;
19008 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
19009 + err = au_may_ren(a);
19010 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
19011 + err = -ENAMETOOLONG;
19012 + if (unlikely(err))
19015 + /* store timestamps to be revertible */
19019 + err = do_rename(a);
19020 + if (unlikely(err))
19023 + /* update dir attributes */
19024 + au_ren_refresh_dir(a);
19026 + /* dput/iput all lower dentries */
19027 + au_ren_refresh(a);
19029 + goto out_hdir; /* success */
19032 + au_ren_rev_dt(err, a);
19034 + au_ren_unlock(a);
19036 + au_nhash_wh_free(&a->whlist);
19037 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
19038 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
19039 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
19040 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
19044 + d_move(a->src_dentry, a->dst_dentry);
19046 + au_update_dbstart(a->dst_dentry);
19047 + if (!a->dst_inode)
19048 + d_drop(a->dst_dentry);
19050 + if (au_ftest_ren(a->flags, ISSAMEDIR))
19051 + di_write_unlock(a->dst_parent);
19053 + di_write_unlock2(a->src_parent, a->dst_parent);
19055 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
19057 + iput(a->dst_inode);
19059 + au_whtmp_rmdir_free(a->thargs);
19065 diff -urNp -x '*.orig' linux-4.4/fs/aufs/iinfo.c linux-4.4/fs/aufs/iinfo.c
19066 --- linux-4.4/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
19067 +++ linux-4.4/fs/aufs/iinfo.c 2021-02-24 17:28:14.405474836 +0100
19070 + * Copyright (C) 2005-2016 Junjiro R. Okajima
19072 + * This program, aufs is free software; you can redistribute it and/or modify
19073 + * it under the terms of the GNU General Public License as published by
19074 + * the Free Software Foundation; either version 2 of the License, or
19075 + * (at your option) any later version.
19077 + * This program is distributed in the hope that it will be useful,
19078 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19079 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19080 + * GNU General Public License for more details.
19082 + * You should have received a copy of the GNU General Public License
19083 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19087 + * inode private data
19092 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
19094 + struct inode *h_inode;
19096 + IiMustAnyLock(inode);
19098 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
19099 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19103 +/* todo: hard/soft set? */
19104 +void au_hiput(struct au_hinode *hinode)
19106 + au_hn_free(hinode);
19107 + dput(hinode->hi_whdentry);
19108 + iput(hinode->hi_inode);
19111 +unsigned int au_hi_flags(struct inode *inode, int isdir)
19113 + unsigned int flags;
19114 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
19117 + if (au_opt_test(mnt_flags, XINO))
19118 + au_fset_hi(flags, XINO);
19119 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
19120 + au_fset_hi(flags, HNOTIFY);
19124 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
19125 + struct inode *h_inode, unsigned int flags)
19127 + struct au_hinode *hinode;
19128 + struct inode *hi;
19129 + struct au_iinfo *iinfo = au_ii(inode);
19131 + IiMustWriteLock(inode);
19133 + hinode = iinfo->ii_hinode + bindex;
19134 + hi = hinode->hi_inode;
19135 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
19138 + au_hiput(hinode);
19139 + hinode->hi_inode = h_inode;
19142 + struct super_block *sb = inode->i_sb;
19143 + struct au_branch *br;
19145 + AuDebugOn(inode->i_mode
19146 + && (h_inode->i_mode & S_IFMT)
19147 + != (inode->i_mode & S_IFMT));
19148 + if (bindex == iinfo->ii_bstart)
19149 + au_cpup_igen(inode, h_inode);
19150 + br = au_sbr(sb, bindex);
19151 + hinode->hi_id = br->br_id;
19152 + if (au_ftest_hi(flags, XINO)) {
19153 + err = au_xino_write(sb, bindex, h_inode->i_ino,
19155 + if (unlikely(err))
19156 + AuIOErr1("failed au_xino_write() %d\n", err);
19159 + if (au_ftest_hi(flags, HNOTIFY)
19160 + && au_br_hnotifyable(br->br_perm)) {
19161 + err = au_hn_alloc(hinode, inode);
19162 + if (unlikely(err))
19163 + AuIOErr1("au_hn_alloc() %d\n", err);
19168 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
19169 + struct dentry *h_wh)
19171 + struct au_hinode *hinode;
19173 + IiMustWriteLock(inode);
19175 + hinode = au_ii(inode)->ii_hinode + bindex;
19176 + AuDebugOn(hinode->hi_whdentry);
19177 + hinode->hi_whdentry = h_wh;
19180 +void au_update_iigen(struct inode *inode, int half)
19182 + struct au_iinfo *iinfo;
19183 + struct au_iigen *iigen;
19184 + unsigned int sigen;
19186 + sigen = au_sigen(inode->i_sb);
19187 + iinfo = au_ii(inode);
19188 + iigen = &iinfo->ii_generation;
19189 + spin_lock(&iigen->ig_spin);
19190 + iigen->ig_generation = sigen;
19192 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
19194 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
19195 + spin_unlock(&iigen->ig_spin);
19198 +/* it may be called at remount time, too */
19199 +void au_update_ibrange(struct inode *inode, int do_put_zero)
19201 + struct au_iinfo *iinfo;
19202 + aufs_bindex_t bindex, bend;
19204 + iinfo = au_ii(inode);
19208 + IiMustWriteLock(inode);
19210 + if (do_put_zero && iinfo->ii_bstart >= 0) {
19211 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
19213 + struct inode *h_i;
19215 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
19218 + && !(h_i->i_state & I_LINKABLE))
19219 + au_set_h_iptr(inode, bindex, NULL, 0);
19223 + iinfo->ii_bstart = -1;
19224 + iinfo->ii_bend = -1;
19225 + bend = au_sbend(inode->i_sb);
19226 + for (bindex = 0; bindex <= bend; bindex++)
19227 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
19228 + iinfo->ii_bstart = bindex;
19231 + if (iinfo->ii_bstart >= 0)
19232 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
19233 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
19234 + iinfo->ii_bend = bindex;
19237 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
19240 +/* ---------------------------------------------------------------------- */
19242 +void au_icntnr_init_once(void *_c)
19244 + struct au_icntnr *c = _c;
19245 + struct au_iinfo *iinfo = &c->iinfo;
19246 + static struct lock_class_key aufs_ii;
19248 + spin_lock_init(&iinfo->ii_generation.ig_spin);
19249 + au_rw_init(&iinfo->ii_rwsem);
19250 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
19251 + inode_init_once(&c->vfs_inode);
19254 +int au_iinfo_init(struct inode *inode)
19256 + struct au_iinfo *iinfo;
19257 + struct super_block *sb;
19260 + sb = inode->i_sb;
19261 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
19262 + nbr = au_sbend(sb) + 1;
19263 + if (unlikely(nbr <= 0))
19265 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
19266 + if (iinfo->ii_hinode) {
19267 + au_ninodes_inc(sb);
19268 + for (i = 0; i < nbr; i++)
19269 + iinfo->ii_hinode[i].hi_id = -1;
19271 + iinfo->ii_generation.ig_generation = au_sigen(sb);
19272 + iinfo->ii_bstart = -1;
19273 + iinfo->ii_bend = -1;
19274 + iinfo->ii_vdir = NULL;
19280 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
19283 + struct au_hinode *hip;
19285 + AuRwMustWriteLock(&iinfo->ii_rwsem);
19288 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
19290 + sz = sizeof(*hip);
19291 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
19293 + iinfo->ii_hinode = hip;
19300 +void au_iinfo_fin(struct inode *inode)
19302 + struct au_iinfo *iinfo;
19303 + struct au_hinode *hi;
19304 + struct super_block *sb;
19305 + aufs_bindex_t bindex, bend;
19306 + const unsigned char unlinked = !inode->i_nlink;
19308 + iinfo = au_ii(inode);
19309 + /* bad_inode case */
19313 + sb = inode->i_sb;
19314 + au_ninodes_dec(sb);
19315 + if (si_pid_test(sb))
19316 + au_xino_delete_inode(inode, unlinked);
19319 + * it is safe to hide the dependency between sbinfo and
19323 + si_noflush_read_lock(sb);
19324 + au_xino_delete_inode(inode, unlinked);
19325 + si_read_unlock(sb);
19329 + if (iinfo->ii_vdir)
19330 + au_vdir_free(iinfo->ii_vdir);
19332 + bindex = iinfo->ii_bstart;
19333 + if (bindex >= 0) {
19334 + hi = iinfo->ii_hinode + bindex;
19335 + bend = iinfo->ii_bend;
19336 + while (bindex++ <= bend) {
19337 + if (hi->hi_inode)
19342 + kfree(iinfo->ii_hinode);
19343 + iinfo->ii_hinode = NULL;
19344 + AuRwDestroy(&iinfo->ii_rwsem);
19346 diff -urNp -x '*.orig' linux-4.4/fs/aufs/inode.c linux-4.4/fs/aufs/inode.c
19347 --- linux-4.4/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
19348 +++ linux-4.4/fs/aufs/inode.c 2021-02-24 17:28:14.405474836 +0100
19351 + * Copyright (C) 2005-2016 Junjiro R. Okajima
19353 + * This program, aufs is free software; you can redistribute it and/or modify
19354 + * it under the terms of the GNU General Public License as published by
19355 + * the Free Software Foundation; either version 2 of the License, or
19356 + * (at your option) any later version.
19358 + * This program is distributed in the hope that it will be useful,
19359 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19360 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19361 + * GNU General Public License for more details.
19363 + * You should have received a copy of the GNU General Public License
19364 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19368 + * inode functions
19373 +struct inode *au_igrab(struct inode *inode)
19376 + AuDebugOn(!atomic_read(&inode->i_count));
19382 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
19384 + au_cpup_attr_all(inode, /*force*/0);
19385 + au_update_iigen(inode, /*half*/1);
19387 + inode->i_version++;
19390 +static int au_ii_refresh(struct inode *inode, int *update)
19394 + aufs_bindex_t bindex, new_bindex;
19395 + struct super_block *sb;
19396 + struct au_iinfo *iinfo;
19397 + struct au_hinode *p, *q, tmp;
19399 + IiMustWriteLock(inode);
19402 + sb = inode->i_sb;
19403 + type = inode->i_mode & S_IFMT;
19404 + iinfo = au_ii(inode);
19405 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
19406 + if (unlikely(err))
19409 + AuDebugOn(iinfo->ii_bstart < 0);
19410 + p = iinfo->ii_hinode + iinfo->ii_bstart;
19411 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
19413 + if (!p->hi_inode)
19416 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
19417 + new_bindex = au_br_index(sb, p->hi_id);
19418 + if (new_bindex == bindex)
19421 + if (new_bindex < 0) {
19424 + p->hi_inode = NULL;
19428 + if (new_bindex < iinfo->ii_bstart)
19429 + iinfo->ii_bstart = new_bindex;
19430 + if (iinfo->ii_bend < new_bindex)
19431 + iinfo->ii_bend = new_bindex;
19432 + /* swap two lower inode, and loop again */
19433 + q = iinfo->ii_hinode + new_bindex;
19437 + if (tmp.hi_inode) {
19442 + au_update_ibrange(inode, /*do_put_zero*/0);
19443 + e = au_dy_irefresh(inode);
19444 + if (unlikely(e && !err))
19452 +void au_refresh_iop(struct inode *inode, int force_getattr)
19455 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
19456 + const struct inode_operations *iop
19457 + = force_getattr ? aufs_iop : sbi->si_iop_array;
19459 + if (inode->i_op == iop)
19462 + switch (inode->i_mode & S_IFMT) {
19464 + type = AuIop_DIR;
19467 + type = AuIop_SYMLINK;
19470 + type = AuIop_OTHER;
19474 + inode->i_op = iop + type;
19475 + /* unnecessary smp_wmb() */
19478 +int au_refresh_hinode_self(struct inode *inode)
19482 + err = au_ii_refresh(inode, &update);
19484 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
19490 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
19492 + int err, e, update;
19493 + unsigned int flags;
19495 + aufs_bindex_t bindex, bend;
19496 + unsigned char isdir;
19497 + struct au_hinode *p;
19498 + struct au_iinfo *iinfo;
19500 + err = au_ii_refresh(inode, &update);
19501 + if (unlikely(err))
19505 + iinfo = au_ii(inode);
19506 + p = iinfo->ii_hinode + iinfo->ii_bstart;
19507 + mode = (inode->i_mode & S_IFMT);
19508 + isdir = S_ISDIR(mode);
19509 + flags = au_hi_flags(inode, isdir);
19510 + bend = au_dbend(dentry);
19511 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
19512 + struct inode *h_i, *h_inode;
19513 + struct dentry *h_d;
19515 + h_d = au_h_dptr(dentry, bindex);
19516 + if (!h_d || d_is_negative(h_d))
19519 + h_inode = d_inode(h_d);
19520 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
19521 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
19522 + h_i = au_h_iptr(inode, bindex);
19524 + if (h_i == h_inode)
19530 + if (bindex < iinfo->ii_bstart)
19531 + iinfo->ii_bstart = bindex;
19532 + if (iinfo->ii_bend < bindex)
19533 + iinfo->ii_bend = bindex;
19534 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
19537 + au_update_ibrange(inode, /*do_put_zero*/0);
19538 + e = au_dy_irefresh(inode);
19539 + if (unlikely(e && !err))
19542 + au_refresh_hinode_attr(inode, update && isdir);
19549 +static int set_inode(struct inode *inode, struct dentry *dentry)
19552 + unsigned int flags;
19554 + aufs_bindex_t bindex, bstart, btail;
19555 + unsigned char isdir;
19556 + struct dentry *h_dentry;
19557 + struct inode *h_inode;
19558 + struct au_iinfo *iinfo;
19559 + struct inode_operations *iop;
19561 + IiMustWriteLock(inode);
19565 + iop = au_sbi(inode->i_sb)->si_iop_array;
19566 + bstart = au_dbstart(dentry);
19567 + h_dentry = au_h_dptr(dentry, bstart);
19568 + h_inode = d_inode(h_dentry);
19569 + mode = h_inode->i_mode;
19570 + switch (mode & S_IFMT) {
19572 + btail = au_dbtail(dentry);
19573 + inode->i_op = iop + AuIop_OTHER;
19574 + inode->i_fop = &aufs_file_fop;
19575 + err = au_dy_iaop(inode, bstart, h_inode);
19576 + if (unlikely(err))
19581 + btail = au_dbtaildir(dentry);
19582 + inode->i_op = iop + AuIop_DIR;
19583 + inode->i_fop = &aufs_dir_fop;
19586 + btail = au_dbtail(dentry);
19587 + inode->i_op = iop + AuIop_SYMLINK;
19593 + btail = au_dbtail(dentry);
19594 + inode->i_op = iop + AuIop_OTHER;
19595 + init_special_inode(inode, mode, h_inode->i_rdev);
19598 + AuIOErr("Unknown file type 0%o\n", mode);
19603 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
19604 + flags = au_hi_flags(inode, isdir);
19605 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
19606 + && au_ftest_hi(flags, HNOTIFY)
19607 + && dentry->d_name.len > AUFS_WH_PFX_LEN
19608 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
19609 + au_fclr_hi(flags, HNOTIFY);
19610 + iinfo = au_ii(inode);
19611 + iinfo->ii_bstart = bstart;
19612 + iinfo->ii_bend = btail;
19613 + for (bindex = bstart; bindex <= btail; bindex++) {
19614 + h_dentry = au_h_dptr(dentry, bindex);
19616 + au_set_h_iptr(inode, bindex,
19617 + au_igrab(d_inode(h_dentry)), flags);
19619 + au_cpup_attr_all(inode, /*force*/1);
19621 + * to force calling aufs_get_acl() every time,
19622 + * do not call cache_no_acl() for aufs inode.
19630 + * successful returns with iinfo write_locked
19632 + * zero: success, matched
19633 + * plus: no error, but unmatched
19635 +static int reval_inode(struct inode *inode, struct dentry *dentry)
19638 + unsigned int gen, igflags;
19639 + aufs_bindex_t bindex, bend;
19640 + struct inode *h_inode, *h_dinode;
19641 + struct dentry *h_dentry;
19644 + * before this function, if aufs got any iinfo lock, it must be only
19645 + * one, the parent dir.
19646 + * it can happen by UDBA and the obsoleted inode number.
19649 + if (unlikely(inode->i_ino == parent_ino(dentry)))
19653 + ii_write_lock_new_child(inode);
19654 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
19655 + h_dinode = d_inode(h_dentry);
19656 + bend = au_ibend(inode);
19657 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
19658 + h_inode = au_h_iptr(inode, bindex);
19659 + if (!h_inode || h_inode != h_dinode)
19663 + gen = au_iigen(inode, &igflags);
19664 + if (gen == au_digen(dentry)
19665 + && !au_ig_ftest(igflags, HALF_REFRESHED))
19668 + /* fully refresh inode using dentry */
19669 + err = au_refresh_hinode(inode, dentry);
19671 + au_update_iigen(inode, /*half*/0);
19675 + if (unlikely(err))
19676 + ii_write_unlock(inode);
19681 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
19682 + unsigned int d_type, ino_t *ino)
19685 + struct mutex *mtx;
19687 + /* prevent hardlinked inode number from race condition */
19689 + if (d_type != DT_DIR) {
19690 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
19693 + err = au_xino_read(sb, bindex, h_ino, ino);
19694 + if (unlikely(err))
19699 + *ino = au_xino_new_ino(sb);
19700 + if (unlikely(!*ino))
19702 + err = au_xino_write(sb, bindex, h_ino, *ino);
19703 + if (unlikely(err))
19709 + mutex_unlock(mtx);
19713 +/* successful returns with iinfo write_locked */
19714 +/* todo: return with unlocked? */
19715 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
19717 + struct inode *inode, *h_inode;
19718 + struct dentry *h_dentry;
19719 + struct super_block *sb;
19720 + struct mutex *mtx;
19721 + ino_t h_ino, ino;
19723 + aufs_bindex_t bstart;
19725 + sb = dentry->d_sb;
19726 + bstart = au_dbstart(dentry);
19727 + h_dentry = au_h_dptr(dentry, bstart);
19728 + h_inode = d_inode(h_dentry);
19729 + h_ino = h_inode->i_ino;
19732 + * stop 'race'-ing between hardlinks under different
19736 + if (!d_is_dir(h_dentry))
19737 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
19742 + err = au_xino_read(sb, bstart, h_ino, &ino);
19743 + inode = ERR_PTR(err);
19744 + if (unlikely(err))
19748 + ino = au_xino_new_ino(sb);
19749 + if (unlikely(!ino)) {
19750 + inode = ERR_PTR(-EIO);
19755 + AuDbg("i%lu\n", (unsigned long)ino);
19756 + inode = au_iget_locked(sb, ino);
19757 + err = PTR_ERR(inode);
19758 + if (IS_ERR(inode))
19761 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
19762 + if (inode->i_state & I_NEW) {
19763 + /* verbose coding for lock class name */
19764 + if (unlikely(d_is_symlink(h_dentry)))
19765 + au_rw_class(&au_ii(inode)->ii_rwsem,
19766 + au_lc_key + AuLcSymlink_IIINFO);
19767 + else if (unlikely(d_is_dir(h_dentry)))
19768 + au_rw_class(&au_ii(inode)->ii_rwsem,
19769 + au_lc_key + AuLcDir_IIINFO);
19770 + else /* likely */
19771 + au_rw_class(&au_ii(inode)->ii_rwsem,
19772 + au_lc_key + AuLcNonDir_IIINFO);
19774 + ii_write_lock_new_child(inode);
19775 + err = set_inode(inode, dentry);
19777 + unlock_new_inode(inode);
19778 + goto out; /* success */
19782 + * iget_failed() calls iput(), but we need to call
19783 + * ii_write_unlock() after iget_failed(). so dirty hack for
19786 + atomic_inc(&inode->i_count);
19787 + iget_failed(inode);
19788 + ii_write_unlock(inode);
19789 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
19790 + /* ignore this error */
19792 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
19794 + * horrible race condition between lookup, readdir and copyup
19795 + * (or something).
19798 + mutex_unlock(mtx);
19799 + err = reval_inode(inode, dentry);
19800 + if (unlikely(err < 0)) {
19807 + goto out; /* success */
19812 + if (unlikely(au_test_fs_unique_ino(h_inode)))
19813 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
19814 + " b%d, %s, %pd, hi%lu, i%lu.\n",
19815 + bstart, au_sbtype(h_dentry->d_sb), dentry,
19816 + (unsigned long)h_ino, (unsigned long)ino);
19818 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
19822 + mutex_unlock(mtx);
19828 + inode = ERR_PTR(err);
19831 + mutex_unlock(mtx);
19835 +/* ---------------------------------------------------------------------- */
19837 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
19838 + struct inode *inode)
19841 + struct inode *hi;
19843 + err = au_br_rdonly(au_sbr(sb, bindex));
19845 + /* pseudo-link after flushed may happen out of bounds */
19848 + && au_ibstart(inode) <= bindex
19849 + && bindex <= au_ibend(inode)) {
19851 + * permission check is unnecessary since vfsub routine
19852 + * will be called later
19854 + hi = au_h_iptr(inode, bindex);
19856 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
19862 +int au_test_h_perm(struct inode *h_inode, int mask)
19864 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
19866 + return inode_permission(h_inode, mask);
19869 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
19871 + if (au_test_nfs(h_inode->i_sb)
19872 + && (mask & MAY_WRITE)
19873 + && S_ISDIR(h_inode->i_mode))
19874 + mask |= MAY_READ; /* force permission check */
19875 + return au_test_h_perm(h_inode, mask);
19877 diff -urNp -x '*.orig' linux-4.4/fs/aufs/inode.h linux-4.4/fs/aufs/inode.h
19878 --- linux-4.4/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
19879 +++ linux-4.4/fs/aufs/inode.h 2021-02-24 17:28:14.405474836 +0100
19882 + * Copyright (C) 2005-2016 Junjiro R. Okajima
19884 + * This program, aufs is free software; you can redistribute it and/or modify
19885 + * it under the terms of the GNU General Public License as published by
19886 + * the Free Software Foundation; either version 2 of the License, or
19887 + * (at your option) any later version.
19889 + * This program is distributed in the hope that it will be useful,
19890 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19891 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19892 + * GNU General Public License for more details.
19894 + * You should have received a copy of the GNU General Public License
19895 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19899 + * inode operations
19902 +#ifndef __AUFS_INODE_H__
19903 +#define __AUFS_INODE_H__
19907 +#include <linux/fsnotify.h>
19908 +#include "rwsem.h"
19912 +struct au_hnotify {
19913 +#ifdef CONFIG_AUFS_HNOTIFY
19914 +#ifdef CONFIG_AUFS_HFSNOTIFY
19915 + /* never use fsnotify_add_vfsmount_mark() */
19916 + struct fsnotify_mark hn_mark;
19918 + struct inode *hn_aufs_inode; /* no get/put */
19920 +} ____cacheline_aligned_in_smp;
19922 +struct au_hinode {
19923 + struct inode *hi_inode;
19924 + aufs_bindex_t hi_id;
19925 +#ifdef CONFIG_AUFS_HNOTIFY
19926 + struct au_hnotify *hi_notify;
19929 + /* reference to the copied-up whiteout with get/put */
19930 + struct dentry *hi_whdentry;
19934 +#define AuIG_HALF_REFRESHED 1
19935 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
19936 +#define au_ig_fset(flags, name) \
19937 + do { (flags) |= AuIG_##name; } while (0)
19938 +#define au_ig_fclr(flags, name) \
19939 + do { (flags) &= ~AuIG_##name; } while (0)
19942 + spinlock_t ig_spin;
19943 + __u32 ig_generation, ig_flags;
19948 + struct au_iigen ii_generation;
19949 + struct super_block *ii_hsb1; /* no get/put */
19951 + struct au_rwsem ii_rwsem;
19952 + aufs_bindex_t ii_bstart, ii_bend;
19954 + struct au_hinode *ii_hinode;
19955 + struct au_vdir *ii_vdir;
19958 +struct au_icntnr {
19959 + struct au_iinfo iinfo;
19960 + struct inode vfs_inode;
19961 +} ____cacheline_aligned_in_smp;
19963 +/* au_pin flags */
19964 +#define AuPin_DI_LOCKED 1
19965 +#define AuPin_MNT_WRITE (1 << 1)
19966 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
19967 +#define au_fset_pin(flags, name) \
19968 + do { (flags) |= AuPin_##name; } while (0)
19969 +#define au_fclr_pin(flags, name) \
19970 + do { (flags) &= ~AuPin_##name; } while (0)
19974 + struct dentry *dentry;
19975 + unsigned int udba;
19976 + unsigned char lsc_di, lsc_hi, flags;
19977 + aufs_bindex_t bindex;
19980 + struct dentry *parent;
19981 + struct au_hinode *hdir;
19982 + struct vfsmount *h_mnt;
19984 + /* temporary unlock/relock for copyup */
19985 + struct dentry *h_dentry, *h_parent;
19986 + struct au_branch *br;
19987 + struct task_struct *task;
19990 +void au_pin_hdir_unlock(struct au_pin *p);
19991 +int au_pin_hdir_lock(struct au_pin *p);
19992 +int au_pin_hdir_relock(struct au_pin *p);
19993 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
19994 +void au_pin_hdir_acquire_nest(struct au_pin *p);
19995 +void au_pin_hdir_release(struct au_pin *p);
19997 +/* ---------------------------------------------------------------------- */
19999 +static inline struct au_iinfo *au_ii(struct inode *inode)
20001 + struct au_iinfo *iinfo;
20003 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
20004 + if (iinfo->ii_hinode)
20006 + return NULL; /* debugging bad_inode case */
20009 +/* ---------------------------------------------------------------------- */
20012 +struct inode *au_igrab(struct inode *inode);
20013 +void au_refresh_iop(struct inode *inode, int force_getattr);
20014 +int au_refresh_hinode_self(struct inode *inode);
20015 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
20016 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
20017 + unsigned int d_type, ino_t *ino);
20018 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
20019 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
20020 + struct inode *inode);
20021 +int au_test_h_perm(struct inode *h_inode, int mask);
20022 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
20024 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
20025 + ino_t h_ino, unsigned int d_type, ino_t *ino)
20027 +#ifdef CONFIG_AUFS_SHWH
20028 + return au_ino(sb, bindex, h_ino, d_type, ino);
20041 +extern struct inode_operations aufs_iop[AuIop_Last],
20042 + aufs_iop_nogetattr[AuIop_Last];
20044 +/* au_wr_dir flags */
20045 +#define AuWrDir_ADD_ENTRY 1
20046 +#define AuWrDir_ISDIR (1 << 1)
20047 +#define AuWrDir_TMPFILE (1 << 2)
20048 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
20049 +#define au_fset_wrdir(flags, name) \
20050 + do { (flags) |= AuWrDir_##name; } while (0)
20051 +#define au_fclr_wrdir(flags, name) \
20052 + do { (flags) &= ~AuWrDir_##name; } while (0)
20054 +struct au_wr_dir_args {
20055 + aufs_bindex_t force_btgt;
20056 + unsigned char flags;
20058 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
20059 + struct au_wr_dir_args *args);
20061 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
20062 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
20063 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
20064 + unsigned int udba, unsigned char flags);
20065 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
20066 + unsigned int udba, unsigned char flags) __must_check;
20067 +int au_do_pin(struct au_pin *pin) __must_check;
20068 +void au_unpin(struct au_pin *pin);
20069 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
20071 +#define AuIcpup_DID_CPUP 1
20072 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
20073 +#define au_fset_icpup(flags, name) \
20074 + do { (flags) |= AuIcpup_##name; } while (0)
20075 +#define au_fclr_icpup(flags, name) \
20076 + do { (flags) &= ~AuIcpup_##name; } while (0)
20078 +struct au_icpup_args {
20079 + unsigned char flags;
20080 + unsigned char pin_flags;
20081 + aufs_bindex_t btgt;
20082 + unsigned int udba;
20083 + struct au_pin pin;
20084 + struct path h_path;
20085 + struct inode *h_inode;
20088 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
20089 + struct au_icpup_args *a);
20091 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
20094 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
20095 + struct dentry *h_parent, int isdir);
20096 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
20098 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
20099 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
20101 +struct vfsub_aopen_args;
20102 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
20103 + struct vfsub_aopen_args *args);
20104 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
20105 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
20106 + struct dentry *dentry);
20107 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
20110 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
20111 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20112 + struct dentry *h_parent, int isdir);
20113 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
20114 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
20117 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
20118 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
20119 + struct inode *dir, struct dentry *dentry);
20122 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
20123 +void au_hiput(struct au_hinode *hinode);
20124 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
20125 + struct dentry *h_wh);
20126 +unsigned int au_hi_flags(struct inode *inode, int isdir);
20128 +/* hinode flags */
20129 +#define AuHi_XINO 1
20130 +#define AuHi_HNOTIFY (1 << 1)
20131 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
20132 +#define au_fset_hi(flags, name) \
20133 + do { (flags) |= AuHi_##name; } while (0)
20134 +#define au_fclr_hi(flags, name) \
20135 + do { (flags) &= ~AuHi_##name; } while (0)
20137 +#ifndef CONFIG_AUFS_HNOTIFY
20138 +#undef AuHi_HNOTIFY
20139 +#define AuHi_HNOTIFY 0
20142 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
20143 + struct inode *h_inode, unsigned int flags);
20145 +void au_update_iigen(struct inode *inode, int half);
20146 +void au_update_ibrange(struct inode *inode, int do_put_zero);
20148 +void au_icntnr_init_once(void *_c);
20149 +int au_iinfo_init(struct inode *inode);
20150 +void au_iinfo_fin(struct inode *inode);
20151 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
20153 +#ifdef CONFIG_PROC_FS
20155 +int au_plink_maint(struct super_block *sb, int flags);
20157 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
20158 +int au_plink_maint_enter(struct super_block *sb);
20159 +#ifdef CONFIG_AUFS_DEBUG
20160 +void au_plink_list(struct super_block *sb);
20162 +AuStubVoid(au_plink_list, struct super_block *sb)
20164 +int au_plink_test(struct inode *inode);
20165 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
20166 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
20167 + struct dentry *h_dentry);
20168 +void au_plink_put(struct super_block *sb, int verbose);
20169 +void au_plink_clean(struct super_block *sb, int verbose);
20170 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
20172 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
20173 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
20174 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
20175 +AuStubVoid(au_plink_list, struct super_block *sb);
20176 +AuStubInt0(au_plink_test, struct inode *inode);
20177 +AuStub(struct dentry *, au_plink_lkup, return NULL,
20178 + struct inode *inode, aufs_bindex_t bindex);
20179 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
20180 + struct dentry *h_dentry);
20181 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
20182 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
20183 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
20184 +#endif /* CONFIG_PROC_FS */
20186 +#ifdef CONFIG_AUFS_XATTR
20188 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
20189 + unsigned int verbose);
20190 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
20191 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
20193 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
20194 + size_t size, int flags);
20195 +int aufs_removexattr(struct dentry *dentry, const char *name);
20197 +/* void au_xattr_init(struct super_block *sb); */
20199 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
20200 + int ignore_flags, unsigned int verbose);
20201 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
20204 +#ifdef CONFIG_FS_POSIX_ACL
20205 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
20206 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
20209 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
20216 +struct au_srxattr {
20220 + const char *name;
20221 + const void *value;
20226 + const char *name;
20229 + struct posix_acl *acl;
20234 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
20237 +/* ---------------------------------------------------------------------- */
20239 +/* lock subclass for iinfo */
20241 + AuLsc_II_CHILD, /* child first */
20242 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
20243 + AuLsc_II_CHILD3, /* copyup dirs */
20244 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
20245 + AuLsc_II_PARENT2,
20246 + AuLsc_II_PARENT3, /* copyup dirs */
20247 + AuLsc_II_NEW_CHILD
20251 + * ii_read_lock_child, ii_write_lock_child,
20252 + * ii_read_lock_child2, ii_write_lock_child2,
20253 + * ii_read_lock_child3, ii_write_lock_child3,
20254 + * ii_read_lock_parent, ii_write_lock_parent,
20255 + * ii_read_lock_parent2, ii_write_lock_parent2,
20256 + * ii_read_lock_parent3, ii_write_lock_parent3,
20257 + * ii_read_lock_new_child, ii_write_lock_new_child,
20259 +#define AuReadLockFunc(name, lsc) \
20260 +static inline void ii_read_lock_##name(struct inode *i) \
20262 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20265 +#define AuWriteLockFunc(name, lsc) \
20266 +static inline void ii_write_lock_##name(struct inode *i) \
20268 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
20271 +#define AuRWLockFuncs(name, lsc) \
20272 + AuReadLockFunc(name, lsc) \
20273 + AuWriteLockFunc(name, lsc)
20275 +AuRWLockFuncs(child, CHILD);
20276 +AuRWLockFuncs(child2, CHILD2);
20277 +AuRWLockFuncs(child3, CHILD3);
20278 +AuRWLockFuncs(parent, PARENT);
20279 +AuRWLockFuncs(parent2, PARENT2);
20280 +AuRWLockFuncs(parent3, PARENT3);
20281 +AuRWLockFuncs(new_child, NEW_CHILD);
20283 +#undef AuReadLockFunc
20284 +#undef AuWriteLockFunc
20285 +#undef AuRWLockFuncs
20288 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
20290 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
20292 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
20293 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
20294 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
20296 +/* ---------------------------------------------------------------------- */
20298 +static inline void au_icntnr_init(struct au_icntnr *c)
20300 +#ifdef CONFIG_AUFS_DEBUG
20301 + c->vfs_inode.i_mode = 0;
20305 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
20307 + unsigned int gen;
20308 + struct au_iinfo *iinfo;
20309 + struct au_iigen *iigen;
20311 + iinfo = au_ii(inode);
20312 + iigen = &iinfo->ii_generation;
20313 + spin_lock(&iigen->ig_spin);
20315 + *igflags = iigen->ig_flags;
20316 + gen = iigen->ig_generation;
20317 + spin_unlock(&iigen->ig_spin);
20322 +/* tiny test for inode number */
20323 +/* tmpfs generation is too rough */
20324 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
20326 + struct au_iinfo *iinfo;
20328 + iinfo = au_ii(inode);
20329 + AuRwMustAnyLock(&iinfo->ii_rwsem);
20330 + return !(iinfo->ii_hsb1 == h_inode->i_sb
20331 + && iinfo->ii_higen == h_inode->i_generation);
20334 +static inline void au_iigen_dec(struct inode *inode)
20336 + struct au_iinfo *iinfo;
20337 + struct au_iigen *iigen;
20339 + iinfo = au_ii(inode);
20340 + iigen = &iinfo->ii_generation;
20341 + spin_lock(&iigen->ig_spin);
20342 + iigen->ig_generation--;
20343 + spin_unlock(&iigen->ig_spin);
20346 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
20351 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
20357 +/* ---------------------------------------------------------------------- */
20359 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
20360 + aufs_bindex_t bindex)
20362 + IiMustAnyLock(inode);
20363 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
20366 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
20368 + IiMustAnyLock(inode);
20369 + return au_ii(inode)->ii_bstart;
20372 +static inline aufs_bindex_t au_ibend(struct inode *inode)
20374 + IiMustAnyLock(inode);
20375 + return au_ii(inode)->ii_bend;
20378 +static inline struct au_vdir *au_ivdir(struct inode *inode)
20380 + IiMustAnyLock(inode);
20381 + return au_ii(inode)->ii_vdir;
20384 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
20386 + IiMustAnyLock(inode);
20387 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
20390 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
20392 + IiMustWriteLock(inode);
20393 + au_ii(inode)->ii_bstart = bindex;
20396 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
20398 + IiMustWriteLock(inode);
20399 + au_ii(inode)->ii_bend = bindex;
20402 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
20404 + IiMustWriteLock(inode);
20405 + au_ii(inode)->ii_vdir = vdir;
20408 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
20410 + IiMustAnyLock(inode);
20411 + return au_ii(inode)->ii_hinode + bindex;
20414 +/* ---------------------------------------------------------------------- */
20416 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
20419 + return pin->parent;
20423 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
20425 + if (pin && pin->hdir)
20426 + return pin->hdir->hi_inode;
20430 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
20433 + return pin->hdir;
20437 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
20440 + pin->dentry = dentry;
20443 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
20444 + unsigned char lflag)
20448 + au_fset_pin(pin->flags, DI_LOCKED);
20450 + au_fclr_pin(pin->flags, DI_LOCKED);
20454 +#if 0 /* reserved */
20455 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
20458 + dput(pin->parent);
20459 + pin->parent = dget(parent);
20464 +/* ---------------------------------------------------------------------- */
20467 +#ifdef CONFIG_AUFS_HNOTIFY
20468 +struct au_hnotify_op {
20469 + void (*ctl)(struct au_hinode *hinode, int do_set);
20470 + int (*alloc)(struct au_hinode *hinode);
20473 + * if it returns true, the the caller should free hinode->hi_notify,
20474 + * otherwise ->free() frees it.
20476 + int (*free)(struct au_hinode *hinode,
20477 + struct au_hnotify *hn) __must_check;
20479 + void (*fin)(void);
20480 + int (*init)(void);
20482 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
20483 + void (*fin_br)(struct au_branch *br);
20484 + int (*init_br)(struct au_branch *br, int perm);
20488 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
20489 +void au_hn_free(struct au_hinode *hinode);
20490 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
20491 +void au_hn_reset(struct inode *inode, unsigned int flags);
20492 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
20493 + struct qstr *h_child_qstr, struct inode *h_child_inode);
20494 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
20495 +int au_hnotify_init_br(struct au_branch *br, int perm);
20496 +void au_hnotify_fin_br(struct au_branch *br);
20497 +int __init au_hnotify_init(void);
20498 +void au_hnotify_fin(void);
20501 +extern const struct au_hnotify_op au_hnotify_op;
20504 +void au_hn_init(struct au_hinode *hinode)
20506 + hinode->hi_notify = NULL;
20509 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
20511 + return hinode->hi_notify;
20515 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
20516 + struct au_hinode *hinode __maybe_unused,
20517 + struct inode *inode __maybe_unused)
20518 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
20519 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
20520 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
20521 + int do_set __maybe_unused)
20522 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
20523 + unsigned int flags __maybe_unused)
20524 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
20525 + struct au_branch *br __maybe_unused,
20526 + int perm __maybe_unused)
20527 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
20528 + int perm __maybe_unused)
20529 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
20530 +AuStubInt0(__init au_hnotify_init, void)
20531 +AuStubVoid(au_hnotify_fin, void)
20532 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
20533 +#endif /* CONFIG_AUFS_HNOTIFY */
20535 +static inline void au_hn_suspend(struct au_hinode *hdir)
20537 + au_hn_ctl(hdir, /*do_set*/0);
20540 +static inline void au_hn_resume(struct au_hinode *hdir)
20542 + au_hn_ctl(hdir, /*do_set*/1);
20545 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
20547 + mutex_lock(&hdir->hi_inode->i_mutex);
20548 + au_hn_suspend(hdir);
20551 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
20552 + unsigned int sc __maybe_unused)
20554 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
20555 + au_hn_suspend(hdir);
20558 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
20560 + au_hn_resume(hdir);
20561 + mutex_unlock(&hdir->hi_inode->i_mutex);
20564 +#endif /* __KERNEL__ */
20565 +#endif /* __AUFS_INODE_H__ */
20566 diff -urNp -x '*.orig' linux-4.4/fs/aufs/ioctl.c linux-4.4/fs/aufs/ioctl.c
20567 --- linux-4.4/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
20568 +++ linux-4.4/fs/aufs/ioctl.c 2021-02-24 17:28:14.405474836 +0100
20571 + * Copyright (C) 2005-2016 Junjiro R. Okajima
20573 + * This program, aufs is free software; you can redistribute it and/or modify
20574 + * it under the terms of the GNU General Public License as published by
20575 + * the Free Software Foundation; either version 2 of the License, or
20576 + * (at your option) any later version.
20578 + * This program is distributed in the hope that it will be useful,
20579 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20580 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20581 + * GNU General Public License for more details.
20583 + * You should have received a copy of the GNU General Public License
20584 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20589 + * plink-management and readdir in userspace.
20590 + * assist the pathconf(3) wrapper library.
20592 + * File-based Hierarchical Storage Management.
20595 +#include <linux/compat.h>
20596 +#include <linux/file.h>
20599 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
20602 + aufs_bindex_t wbi, bindex, bend;
20603 + struct file *h_file;
20604 + struct super_block *sb;
20605 + struct dentry *root;
20606 + struct au_branch *br;
20607 + struct aufs_wbr_fd wbrfd = {
20608 + .oflags = au_dir_roflags,
20611 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
20612 + | O_NOATIME | O_CLOEXEC;
20614 + AuDebugOn(wbrfd.oflags & ~valid);
20617 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
20618 + if (unlikely(err)) {
20624 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
20625 + wbrfd.oflags |= au_dir_roflags;
20626 + AuDbg("0%o\n", wbrfd.oflags);
20627 + if (unlikely(wbrfd.oflags & ~valid))
20631 + fd = get_unused_fd_flags(0);
20633 + if (unlikely(fd < 0))
20636 + h_file = ERR_PTR(-EINVAL);
20639 + sb = path->dentry->d_sb;
20640 + root = sb->s_root;
20641 + aufs_read_lock(root, AuLock_IR);
20642 + bend = au_sbend(sb);
20643 + if (wbrfd.brid >= 0) {
20644 + wbi = au_br_index(sb, wbrfd.brid);
20645 + if (unlikely(wbi < 0 || wbi > bend))
20649 + h_file = ERR_PTR(-ENOENT);
20650 + br = au_sbr(sb, wbi);
20651 + if (!au_br_writable(br->br_perm)) {
20655 + bindex = wbi + 1;
20657 + for (; bindex <= bend; bindex++) {
20658 + br = au_sbr(sb, bindex);
20659 + if (au_br_writable(br->br_perm)) {
20661 + br = au_sbr(sb, wbi);
20666 + AuDbg("wbi %d\n", wbi);
20668 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
20672 + aufs_read_unlock(root, AuLock_IR);
20673 + err = PTR_ERR(h_file);
20674 + if (IS_ERR(h_file))
20677 + atomic_dec(&br->br_count); /* cf. au_h_open() */
20678 + fd_install(fd, h_file);
20680 + goto out; /* success */
20683 + put_unused_fd(fd);
20689 +/* ---------------------------------------------------------------------- */
20691 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
20694 + struct dentry *dentry;
20697 + case AUFS_CTL_RDU:
20698 + case AUFS_CTL_RDU_INO:
20699 + err = au_rdu_ioctl(file, cmd, arg);
20702 + case AUFS_CTL_WBR_FD:
20703 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20706 + case AUFS_CTL_IBUSY:
20707 + err = au_ibusy_ioctl(file, arg);
20710 + case AUFS_CTL_BRINFO:
20711 + err = au_brinfo_ioctl(file, arg);
20714 + case AUFS_CTL_FHSM_FD:
20715 + dentry = file->f_path.dentry;
20716 + if (IS_ROOT(dentry))
20717 + err = au_fhsm_fd(dentry->d_sb, arg);
20723 + /* do not call the lower */
20724 + AuDbg("0x%x\n", cmd);
20732 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
20737 + case AUFS_CTL_MVDOWN:
20738 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
20741 + case AUFS_CTL_WBR_FD:
20742 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
20746 + /* do not call the lower */
20747 + AuDbg("0x%x\n", cmd);
20755 +#ifdef CONFIG_COMPAT
20756 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
20757 + unsigned long arg)
20762 + case AUFS_CTL_RDU:
20763 + case AUFS_CTL_RDU_INO:
20764 + err = au_rdu_compat_ioctl(file, cmd, arg);
20767 + case AUFS_CTL_IBUSY:
20768 + err = au_ibusy_compat_ioctl(file, arg);
20771 + case AUFS_CTL_BRINFO:
20772 + err = au_brinfo_compat_ioctl(file, arg);
20776 + err = aufs_ioctl_dir(file, cmd, arg);
20783 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
20784 + unsigned long arg)
20786 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
20789 diff -urNp -x '*.orig' linux-4.4/fs/aufs/loop.c linux-4.4/fs/aufs/loop.c
20790 --- linux-4.4/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
20791 +++ linux-4.4/fs/aufs/loop.c 2021-02-24 17:28:14.418808602 +0100
20794 + * Copyright (C) 2005-2016 Junjiro R. Okajima
20796 + * This program, aufs is free software; you can redistribute it and/or modify
20797 + * it under the terms of the GNU General Public License as published by
20798 + * the Free Software Foundation; either version 2 of the License, or
20799 + * (at your option) any later version.
20801 + * This program is distributed in the hope that it will be useful,
20802 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20803 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20804 + * GNU General Public License for more details.
20806 + * You should have received a copy of the GNU General Public License
20807 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20811 + * support for loopback block device as a branch
20816 +/* added into drivers/block/loop.c */
20817 +static struct file *(*backing_file_func)(struct super_block *sb);
20820 + * test if two lower dentries have overlapping branches.
20822 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
20824 + struct super_block *h_sb;
20825 + struct file *backing_file;
20827 + if (unlikely(!backing_file_func)) {
20828 + /* don't load "loop" module here */
20829 + backing_file_func = symbol_get(loop_backing_file);
20830 + if (unlikely(!backing_file_func))
20831 + /* "loop" module is not loaded */
20835 + h_sb = h_adding->d_sb;
20836 + backing_file = backing_file_func(h_sb);
20837 + if (!backing_file)
20840 + h_adding = backing_file->f_path.dentry;
20842 + * h_adding can be local NFS.
20843 + * in this case aufs cannot detect the loop.
20845 + if (unlikely(h_adding->d_sb == sb))
20847 + return !!au_test_subdir(h_adding, sb->s_root);
20850 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
20851 +int au_test_loopback_kthread(void)
20854 + struct task_struct *tsk = current;
20855 + char c, comm[sizeof(tsk->comm)];
20858 + if (tsk->flags & PF_KTHREAD) {
20859 + get_task_comm(comm, tsk);
20861 + ret = ('0' <= c && c <= '9'
20862 + && !strncmp(comm, "loop", 4));
20868 +/* ---------------------------------------------------------------------- */
20870 +#define au_warn_loopback_step 16
20871 +static int au_warn_loopback_nelem = au_warn_loopback_step;
20872 +static unsigned long *au_warn_loopback_array;
20874 +void au_warn_loopback(struct super_block *h_sb)
20876 + int i, new_nelem;
20877 + unsigned long *a, magic;
20878 + static DEFINE_SPINLOCK(spin);
20880 + magic = h_sb->s_magic;
20881 + spin_lock(&spin);
20882 + a = au_warn_loopback_array;
20883 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
20884 + if (a[i] == magic) {
20885 + spin_unlock(&spin);
20889 + /* h_sb is new to us, print it */
20890 + if (i < au_warn_loopback_nelem) {
20895 + /* expand the array */
20896 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
20897 + a = au_kzrealloc(au_warn_loopback_array,
20898 + au_warn_loopback_nelem * sizeof(unsigned long),
20899 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
20901 + au_warn_loopback_nelem = new_nelem;
20902 + au_warn_loopback_array = a;
20907 + spin_unlock(&spin);
20908 + AuWarn1("realloc failed, ignored\n");
20912 + spin_unlock(&spin);
20913 + pr_warn("you may want to try another patch for loopback file "
20914 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
20917 +int au_loopback_init(void)
20920 + struct super_block *sb __maybe_unused;
20922 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
20925 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
20926 + sizeof(unsigned long), GFP_NOFS);
20927 + if (unlikely(!au_warn_loopback_array))
20933 +void au_loopback_fin(void)
20935 + if (backing_file_func)
20936 + symbol_put(loop_backing_file);
20937 + kfree(au_warn_loopback_array);
20940 +/* ---------------------------------------------------------------------- */
20942 +/* support the loopback block device insude aufs */
20944 +struct file *aufs_real_loop(struct file *file)
20948 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
20949 + fi_read_lock(file);
20950 + f = au_hf_top(file);
20951 + fi_read_unlock(file);
20955 diff -urNp -x '*.orig' linux-4.4/fs/aufs/loop.h linux-4.4/fs/aufs/loop.h
20956 --- linux-4.4/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
20957 +++ linux-4.4/fs/aufs/loop.h 2021-02-24 17:28:14.418808602 +0100
20960 + * Copyright (C) 2005-2016 Junjiro R. Okajima
20962 + * This program, aufs is free software; you can redistribute it and/or modify
20963 + * it under the terms of the GNU General Public License as published by
20964 + * the Free Software Foundation; either version 2 of the License, or
20965 + * (at your option) any later version.
20967 + * This program is distributed in the hope that it will be useful,
20968 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20969 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20970 + * GNU General Public License for more details.
20972 + * You should have received a copy of the GNU General Public License
20973 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20977 + * support for loopback mount as a branch
20980 +#ifndef __AUFS_LOOP_H__
20981 +#define __AUFS_LOOP_H__
20986 +struct super_block;
20988 +#ifdef CONFIG_AUFS_BDEV_LOOP
20989 +/* drivers/block/loop.c */
20990 +struct file *loop_backing_file(struct super_block *sb);
20993 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
20994 +int au_test_loopback_kthread(void);
20995 +void au_warn_loopback(struct super_block *h_sb);
20997 +int au_loopback_init(void);
20998 +void au_loopback_fin(void);
21000 +struct file *aufs_real_loop(struct file *file);
21002 +AuStub(struct file *, loop_backing_file, return NULL)
21004 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21005 + struct dentry *h_adding)
21006 +AuStubInt0(au_test_loopback_kthread, void)
21007 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21009 +AuStubInt0(au_loopback_init, void)
21010 +AuStubVoid(au_loopback_fin, void)
21012 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
21013 +#endif /* BLK_DEV_LOOP */
21015 +#endif /* __KERNEL__ */
21016 +#endif /* __AUFS_LOOP_H__ */
21017 diff -urNp -x '*.orig' linux-4.4/fs/aufs/magic.mk linux-4.4/fs/aufs/magic.mk
21018 --- linux-4.4/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21019 +++ linux-4.4/fs/aufs/magic.mk 2021-02-24 17:28:14.408808278 +0100
21022 +# defined in ${srctree}/fs/fuse/inode.c
21024 +ifdef CONFIG_FUSE_FS
21025 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21028 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21030 +ifdef CONFIG_XFS_FS
21031 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21034 +# defined in ${srctree}/fs/configfs/mount.c
21036 +ifdef CONFIG_CONFIGFS_FS
21037 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21040 +# defined in ${srctree}/fs/ubifs/ubifs.h
21042 +ifdef CONFIG_UBIFS_FS
21043 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21046 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21048 +ifdef CONFIG_HFSPLUS_FS
21049 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21051 diff -urNp -x '*.orig' linux-4.4/fs/aufs/module.c linux-4.4/fs/aufs/module.c
21052 --- linux-4.4/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21053 +++ linux-4.4/fs/aufs/module.c 2021-02-24 17:28:14.408808278 +0100
21056 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21058 + * This program, aufs is free software; you can redistribute it and/or modify
21059 + * it under the terms of the GNU General Public License as published by
21060 + * the Free Software Foundation; either version 2 of the License, or
21061 + * (at your option) any later version.
21063 + * This program is distributed in the hope that it will be useful,
21064 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21065 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21066 + * GNU General Public License for more details.
21068 + * You should have received a copy of the GNU General Public License
21069 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21073 + * module global variables and operations
21076 +#include <linux/module.h>
21077 +#include <linux/seq_file.h>
21080 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21082 + if (new_sz <= nused)
21085 + p = krealloc(p, new_sz, gfp);
21087 + memset(p + nused, 0, new_sz - nused);
21091 +/* ---------------------------------------------------------------------- */
21096 +struct kmem_cache *au_cachep[AuCache_Last];
21097 +static int __init au_cache_init(void)
21099 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21100 + if (au_cachep[AuCache_DINFO])
21101 + /* SLAB_DESTROY_BY_RCU */
21102 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21103 + au_icntnr_init_once);
21104 + if (au_cachep[AuCache_ICNTNR])
21105 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21106 + au_fi_init_once);
21107 + if (au_cachep[AuCache_FINFO])
21108 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21109 + if (au_cachep[AuCache_VDIR])
21110 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21111 + if (au_cachep[AuCache_DEHSTR])
21117 +static void au_cache_fin(void)
21122 + * Make sure all delayed rcu free inodes are flushed before we
21127 + /* excluding AuCache_HNOTIFY */
21128 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21129 + for (i = 0; i < AuCache_HNOTIFY; i++) {
21130 + kmem_cache_destroy(au_cachep[i]);
21131 + au_cachep[i] = NULL;
21135 +/* ---------------------------------------------------------------------- */
21137 +int au_dir_roflags;
21139 +#ifdef CONFIG_AUFS_SBILIST
21141 + * iterate_supers_type() doesn't protect us from
21142 + * remounting (branch management)
21144 +struct au_splhead au_sbilist;
21147 +struct lock_class_key au_lc_key[AuLcKey_Last];
21150 + * functions for module interface.
21152 +MODULE_LICENSE("GPL");
21153 +/* MODULE_LICENSE("GPL v2"); */
21154 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21155 +MODULE_DESCRIPTION(AUFS_NAME
21156 + " -- Advanced multi layered unification filesystem");
21157 +MODULE_VERSION(AUFS_VERSION);
21158 +MODULE_ALIAS_FS(AUFS_NAME);
21160 +/* this module parameter has no meaning when SYSFS is disabled */
21161 +int sysaufs_brs = 1;
21162 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21163 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21165 +/* this module parameter has no meaning when USER_NS is disabled */
21167 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21168 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21170 +/* ---------------------------------------------------------------------- */
21172 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21174 +int au_seq_path(struct seq_file *seq, struct path *path)
21178 + err = seq_path(seq, path, au_esc_chars);
21181 + else if (err < 0)
21187 +/* ---------------------------------------------------------------------- */
21189 +static int __init aufs_init(void)
21194 + p = au_esc_chars;
21195 + for (i = 1; i <= ' '; i++)
21201 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21203 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
21204 + for (i = 0; i < AuIop_Last; i++)
21205 + aufs_iop_nogetattr[i].getattr = NULL;
21207 + au_sbilist_init();
21208 + sysaufs_brs_init();
21211 + err = sysaufs_init();
21212 + if (unlikely(err))
21214 + err = au_procfs_init();
21215 + if (unlikely(err))
21216 + goto out_sysaufs;
21217 + err = au_wkq_init();
21218 + if (unlikely(err))
21220 + err = au_loopback_init();
21221 + if (unlikely(err))
21223 + err = au_hnotify_init();
21224 + if (unlikely(err))
21225 + goto out_loopback;
21226 + err = au_sysrq_init();
21227 + if (unlikely(err))
21229 + err = au_cache_init();
21230 + if (unlikely(err))
21233 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21234 + err = register_filesystem(&aufs_fs_type);
21235 + if (unlikely(err))
21238 + /* since we define pr_fmt, call printk directly */
21239 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21240 + goto out; /* success */
21247 + au_hnotify_fin();
21249 + au_loopback_fin();
21261 +static void __exit aufs_exit(void)
21263 + unregister_filesystem(&aufs_fs_type);
21266 + au_hnotify_fin();
21267 + au_loopback_fin();
21274 +module_init(aufs_init);
21275 +module_exit(aufs_exit);
21276 diff -urNp -x '*.orig' linux-4.4/fs/aufs/module.h linux-4.4/fs/aufs/module.h
21277 --- linux-4.4/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21278 +++ linux-4.4/fs/aufs/module.h 2021-02-24 17:28:14.408808278 +0100
21281 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21283 + * This program, aufs is free software; you can redistribute it and/or modify
21284 + * it under the terms of the GNU General Public License as published by
21285 + * the Free Software Foundation; either version 2 of the License, or
21286 + * (at your option) any later version.
21288 + * This program is distributed in the hope that it will be useful,
21289 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21290 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21291 + * GNU General Public License for more details.
21293 + * You should have received a copy of the GNU General Public License
21294 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21298 + * module initialization and module-global
21301 +#ifndef __AUFS_MODULE_H__
21302 +#define __AUFS_MODULE_H__
21306 +#include <linux/slab.h>
21311 +/* module parameters */
21312 +extern int sysaufs_brs;
21313 +extern bool au_userns;
21315 +/* ---------------------------------------------------------------------- */
21317 +extern int au_dir_roflags;
21320 + AuLcNonDir_FIINFO,
21321 + AuLcNonDir_DIINFO,
21322 + AuLcNonDir_IIINFO,
21328 + AuLcSymlink_DIINFO,
21329 + AuLcSymlink_IIINFO,
21333 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
21335 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
21336 +int au_seq_path(struct seq_file *seq, struct path *path);
21338 +#ifdef CONFIG_PROC_FS
21340 +int __init au_procfs_init(void);
21341 +void au_procfs_fin(void);
21343 +AuStubInt0(au_procfs_init, void);
21344 +AuStubVoid(au_procfs_fin, void);
21347 +/* ---------------------------------------------------------------------- */
21356 + AuCache_HNOTIFY, /* must be last */
21360 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
21361 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
21362 +#define AuCacheCtor(type, ctor) \
21363 + kmem_cache_create(#type, sizeof(struct type), \
21364 + __alignof__(struct type), AuCacheFlags, ctor)
21366 +extern struct kmem_cache *au_cachep[];
21368 +#define AuCacheFuncs(name, index) \
21369 +static inline struct au_##name *au_cache_alloc_##name(void) \
21370 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
21371 +static inline void au_cache_free_##name(struct au_##name *p) \
21372 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
21374 +AuCacheFuncs(dinfo, DINFO);
21375 +AuCacheFuncs(icntnr, ICNTNR);
21376 +AuCacheFuncs(finfo, FINFO);
21377 +AuCacheFuncs(vdir, VDIR);
21378 +AuCacheFuncs(vdir_dehstr, DEHSTR);
21379 +#ifdef CONFIG_AUFS_HNOTIFY
21380 +AuCacheFuncs(hnotify, HNOTIFY);
21383 +#endif /* __KERNEL__ */
21384 +#endif /* __AUFS_MODULE_H__ */
21385 diff -urNp -x '*.orig' linux-4.4/fs/aufs/mvdown.c linux-4.4/fs/aufs/mvdown.c
21386 --- linux-4.4/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
21387 +++ linux-4.4/fs/aufs/mvdown.c 2021-02-24 17:28:14.408808278 +0100
21390 + * Copyright (C) 2011-2016 Junjiro R. Okajima
21392 + * This program, aufs is free software; you can redistribute it and/or modify
21393 + * it under the terms of the GNU General Public License as published by
21394 + * the Free Software Foundation; either version 2 of the License, or
21395 + * (at your option) any later version.
21397 + * This program is distributed in the hope that it will be useful,
21398 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21399 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21400 + * GNU General Public License for more details.
21402 + * You should have received a copy of the GNU General Public License
21403 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21407 + * move-down, opposite of copy-up
21412 +struct au_mvd_args {
21414 + struct super_block *h_sb;
21415 + struct dentry *h_parent;
21416 + struct au_hinode *hdir;
21417 + struct inode *h_dir, *h_inode;
21418 + struct au_pin pin;
21419 + } info[AUFS_MVDOWN_NARRAY];
21421 + struct aufs_mvdown mvdown;
21422 + struct dentry *dentry, *parent;
21423 + struct inode *inode, *dir;
21424 + struct super_block *sb;
21425 + aufs_bindex_t bopq, bwh, bfound;
21426 + unsigned char rename_lock;
21429 +#define mvd_errno mvdown.au_errno
21430 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
21431 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
21432 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
21433 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
21435 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
21436 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
21437 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
21438 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
21439 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
21440 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
21442 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
21443 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
21444 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
21445 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
21446 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
21447 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
21449 +#define AU_MVD_PR(flag, ...) do { \
21451 + pr_err(__VA_ARGS__); \
21454 +static int find_lower_writable(struct au_mvd_args *a)
21456 + struct super_block *sb;
21457 + aufs_bindex_t bindex, bend;
21458 + struct au_branch *br;
21461 + bindex = a->mvd_bsrc;
21462 + bend = au_sbend(sb);
21463 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
21464 + for (bindex++; bindex <= bend; bindex++) {
21465 + br = au_sbr(sb, bindex);
21466 + if (au_br_fhsm(br->br_perm)
21467 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
21470 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
21471 + for (bindex++; bindex <= bend; bindex++) {
21472 + br = au_sbr(sb, bindex);
21473 + if (!au_br_rdonly(br))
21477 + for (bindex++; bindex <= bend; bindex++) {
21478 + br = au_sbr(sb, bindex);
21479 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21480 + if (au_br_rdonly(br))
21482 + |= AUFS_MVDOWN_ROLOWER_R;
21490 +/* make the parent dir on bdst */
21491 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
21496 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
21497 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
21498 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
21499 + a->mvd_h_dst_parent = NULL;
21500 + if (au_dbend(a->parent) >= a->mvd_bdst)
21501 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21502 + if (!a->mvd_h_dst_parent) {
21503 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
21504 + if (unlikely(err)) {
21505 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
21508 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21516 +/* lock them all */
21517 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
21520 + struct dentry *h_trap;
21522 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
21523 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
21524 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
21525 + au_opt_udba(a->sb),
21526 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21528 + if (unlikely(err)) {
21529 + AU_MVD_PR(dmsg, "pin_dst failed\n");
21533 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
21534 + a->rename_lock = 0;
21535 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
21536 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
21537 + au_opt_udba(a->sb),
21538 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21539 + err = au_do_pin(&a->mvd_pin_src);
21541 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
21542 + if (unlikely(err)) {
21543 + AU_MVD_PR(dmsg, "pin_src failed\n");
21546 + goto out; /* success */
21549 + a->rename_lock = 1;
21550 + au_pin_hdir_unlock(&a->mvd_pin_dst);
21551 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
21552 + au_opt_udba(a->sb),
21553 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21555 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
21556 + if (unlikely(err)) {
21557 + AU_MVD_PR(dmsg, "pin_src failed\n");
21558 + au_pin_hdir_lock(&a->mvd_pin_dst);
21561 + au_pin_hdir_unlock(&a->mvd_pin_src);
21562 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21563 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21565 + err = (h_trap != a->mvd_h_src_parent);
21567 + err = (h_trap != a->mvd_h_dst_parent);
21569 + BUG_ON(err); /* it should never happen */
21570 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
21573 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21574 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21575 + au_pin_hdir_lock(&a->mvd_pin_src);
21576 + au_unpin(&a->mvd_pin_src);
21577 + au_pin_hdir_lock(&a->mvd_pin_dst);
21580 + goto out; /* success */
21583 + au_unpin(&a->mvd_pin_dst);
21589 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
21591 + if (!a->rename_lock)
21592 + au_unpin(&a->mvd_pin_src);
21594 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21595 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21596 + au_pin_hdir_lock(&a->mvd_pin_src);
21597 + au_unpin(&a->mvd_pin_src);
21598 + au_pin_hdir_lock(&a->mvd_pin_dst);
21600 + au_unpin(&a->mvd_pin_dst);
21603 +/* copy-down the file */
21604 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
21607 + struct au_cp_generic cpg = {
21608 + .dentry = a->dentry,
21609 + .bdst = a->mvd_bdst,
21610 + .bsrc = a->mvd_bsrc,
21612 + .pin = &a->mvd_pin_dst,
21613 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21616 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
21617 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21618 + au_fset_cpup(cpg.flags, OVERWRITE);
21619 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
21620 + au_fset_cpup(cpg.flags, RWDST);
21621 + err = au_sio_cpdown_simple(&cpg);
21622 + if (unlikely(err))
21623 + AU_MVD_PR(dmsg, "cpdown failed\n");
21630 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
21633 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
21636 + struct path h_path;
21637 + struct au_branch *br;
21638 + struct inode *delegated;
21640 + br = au_sbr(a->sb, a->mvd_bdst);
21641 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
21642 + err = PTR_ERR(h_path.dentry);
21643 + if (IS_ERR(h_path.dentry)) {
21644 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
21649 + if (d_is_positive(h_path.dentry)) {
21650 + h_path.mnt = au_br_mnt(br);
21651 + delegated = NULL;
21652 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
21653 + &delegated, /*force*/0);
21654 + if (unlikely(err == -EWOULDBLOCK)) {
21655 + pr_warn("cannot retry for NFSv4 delegation"
21656 + " for an internal unlink\n");
21659 + if (unlikely(err))
21660 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
21662 + dput(h_path.dentry);
21670 + * unlink the topmost h_dentry
21672 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
21675 + struct path h_path;
21676 + struct inode *delegated;
21678 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
21679 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
21680 + delegated = NULL;
21681 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
21682 + if (unlikely(err == -EWOULDBLOCK)) {
21683 + pr_warn("cannot retry for NFSv4 delegation"
21684 + " for an internal unlink\n");
21687 + if (unlikely(err))
21688 + AU_MVD_PR(dmsg, "unlink failed\n");
21694 +/* Since mvdown succeeded, we ignore an error of this function */
21695 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
21698 + struct au_branch *br;
21700 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
21701 + br = au_sbr(a->sb, a->mvd_bsrc);
21702 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
21704 + br = au_sbr(a->sb, a->mvd_bdst);
21705 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
21706 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
21709 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
21711 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
21715 + * copy-down the file and unlink the bsrc file.
21716 + * - unlink the bdst whout if exist
21717 + * - copy-down the file (with whtmp name and rename)
21718 + * - unlink the bsrc file
21720 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
21724 + err = au_do_mkdir(dmsg, a);
21726 + err = au_do_lock(dmsg, a);
21727 + if (unlikely(err))
21731 + * do not revert the activities we made on bdst since they should be
21732 + * harmless in aufs.
21735 + err = au_do_cpdown(dmsg, a);
21737 + err = au_do_unlink_wh(dmsg, a);
21738 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
21739 + err = au_do_unlink(dmsg, a);
21740 + if (unlikely(err))
21743 + AuDbg("%pd2, 0x%x, %d --> %d\n",
21744 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
21745 + if (find_lower_writable(a) < 0)
21746 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
21748 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
21749 + au_do_stfs(dmsg, a);
21751 + /* maintain internal array */
21752 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
21753 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
21754 + au_set_dbstart(a->dentry, a->mvd_bdst);
21755 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
21756 + au_set_ibstart(a->inode, a->mvd_bdst);
21758 + /* hide the lower */
21759 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
21760 + au_set_dbend(a->dentry, a->mvd_bsrc);
21761 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
21762 + au_set_ibend(a->inode, a->mvd_bsrc);
21764 + if (au_dbend(a->dentry) < a->mvd_bdst)
21765 + au_set_dbend(a->dentry, a->mvd_bdst);
21766 + if (au_ibend(a->inode) < a->mvd_bdst)
21767 + au_set_ibend(a->inode, a->mvd_bdst);
21770 + au_do_unlock(dmsg, a);
21776 +/* ---------------------------------------------------------------------- */
21778 +/* make sure the file is idle */
21779 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
21781 + int err, plinked;
21784 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
21785 + if (au_dbstart(a->dentry) == a->mvd_bsrc
21786 + && au_dcount(a->dentry) == 1
21787 + && atomic_read(&a->inode->i_count) == 1
21788 + /* && a->mvd_h_src_inode->i_nlink == 1 */
21789 + && (!plinked || !au_plink_test(a->inode))
21790 + && a->inode->i_nlink == 1)
21795 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
21796 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
21797 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
21798 + a->mvd_h_src_inode->i_nlink,
21799 + plinked, plinked ? au_plink_test(a->inode) : 0);
21806 +/* make sure the parent dir is fine */
21807 +static int au_mvd_args_parent(const unsigned char dmsg,
21808 + struct au_mvd_args *a)
21811 + aufs_bindex_t bindex;
21814 + if (unlikely(au_alive_dir(a->parent))) {
21816 + AU_MVD_PR(dmsg, "parent dir is dead\n");
21820 + a->bopq = au_dbdiropq(a->parent);
21821 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
21822 + AuDbg("b%d\n", bindex);
21823 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
21824 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
21826 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
21827 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
21828 + a->bopq, a->mvd_bdst);
21836 +static int au_mvd_args_intermediate(const unsigned char dmsg,
21837 + struct au_mvd_args *a)
21840 + struct au_dinfo *dinfo, *tmp;
21842 + /* lookup the next lower positive entry */
21844 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
21845 + if (unlikely(!tmp))
21850 + dinfo = au_di(a->dentry);
21851 + au_di_cp(tmp, dinfo);
21852 + au_di_swap(tmp, dinfo);
21854 + /* returns the number of positive dentries */
21855 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
21857 + a->bwh = au_dbwh(a->dentry);
21858 + else if (err > 0)
21859 + a->bfound = au_dbstart(a->dentry);
21861 + au_di_swap(tmp, dinfo);
21862 + au_rw_write_unlock(&tmp->di_rwsem);
21864 + if (unlikely(err < 0))
21865 + AU_MVD_PR(dmsg, "failed look-up lower\n");
21868 + * here, we have these cases.
21870 + * no positive dentry under bsrc. there are more sub-cases.
21872 + * there no whiteout, we can safely move-down.
21875 + * bsrc < bwh && bwh < bdst
21876 + * there is a whiteout on RO branch. cannot proceed.
21878 + * there is a whiteout on the RW target branch. it should
21881 + * there is a whiteout somewhere unrelated branch.
21882 + * -1 < bfound && bfound <= bsrc
21885 + * found, but it is on RO branch between bsrc and bdst. cannot
21888 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
21891 + * found, after we create the file on bdst, it will be hidden.
21894 + AuDebugOn(a->bfound == -1
21896 + && a->bwh <= a->mvd_bsrc);
21897 + AuDebugOn(-1 < a->bfound
21898 + && a->bfound <= a->mvd_bsrc);
21901 + if (a->bfound == -1
21902 + && a->mvd_bsrc < a->bwh
21904 + && a->bwh < a->mvd_bdst) {
21905 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
21906 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
21907 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
21909 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
21910 + a->mvd_errno = EAU_MVDOWN_UPPER;
21911 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
21912 + a->mvd_bdst, a->bfound);
21916 + err = 0; /* success */
21923 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
21928 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21929 + && a->bfound == a->mvd_bdst)
21935 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
21938 + struct au_branch *br;
21941 + if (unlikely(S_ISDIR(a->inode->i_mode)))
21945 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
21946 + a->mvd_bsrc = au_ibstart(a->inode);
21948 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
21949 + if (unlikely(a->mvd_bsrc < 0
21950 + || (a->mvd_bsrc < au_dbstart(a->dentry)
21951 + || au_dbend(a->dentry) < a->mvd_bsrc
21952 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
21953 + || (a->mvd_bsrc < au_ibstart(a->inode)
21954 + || au_ibend(a->inode) < a->mvd_bsrc
21955 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
21956 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
21957 + AU_MVD_PR(dmsg, "no upper\n");
21961 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
21962 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
21963 + AU_MVD_PR(dmsg, "on the bottom\n");
21966 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
21967 + br = au_sbr(a->sb, a->mvd_bsrc);
21968 + err = au_br_rdonly(br);
21969 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
21970 + if (unlikely(err))
21972 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
21973 + || IS_APPEND(a->mvd_h_src_inode))) {
21975 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
21981 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
21982 + a->mvd_bdst = find_lower_writable(a);
21983 + if (unlikely(a->mvd_bdst < 0)) {
21984 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
21985 + AU_MVD_PR(dmsg, "no writable lower branch\n");
21989 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
21990 + if (unlikely(a->mvd_bdst < 0
21991 + || au_sbend(a->sb) < a->mvd_bdst)) {
21992 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
21993 + AU_MVD_PR(dmsg, "no lower brid\n");
21998 + err = au_mvd_args_busy(dmsg, a);
22000 + err = au_mvd_args_parent(dmsg, a);
22002 + err = au_mvd_args_intermediate(dmsg, a);
22004 + err = au_mvd_args_exist(dmsg, a);
22006 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22013 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22016 + unsigned char dmsg;
22017 + struct au_mvd_args *args;
22018 + struct inode *inode;
22020 + inode = d_inode(dentry);
22022 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22026 + args = kmalloc(sizeof(*args), GFP_NOFS);
22027 + if (unlikely(!args))
22030 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22032 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22033 + if (unlikely(err)) {
22038 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22039 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22040 + args->mvdown.au_errno = 0;
22041 + args->dentry = dentry;
22042 + args->inode = inode;
22043 + args->sb = dentry->d_sb;
22046 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22047 + args->parent = dget_parent(dentry);
22048 + args->dir = d_inode(args->parent);
22049 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
22050 + dput(args->parent);
22051 + if (unlikely(args->parent != dentry->d_parent)) {
22052 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22056 + mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD);
22057 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
22058 + if (unlikely(err))
22061 + di_write_lock_parent(args->parent);
22062 + err = au_mvd_args(dmsg, args);
22063 + if (unlikely(err))
22066 + err = au_do_mvdown(dmsg, args);
22067 + if (unlikely(err))
22070 + au_cpup_attr_timesizes(args->dir);
22071 + au_cpup_attr_timesizes(inode);
22072 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
22073 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
22074 + /* au_digen_dec(dentry); */
22077 + di_write_unlock(args->parent);
22078 + aufs_read_unlock(dentry, AuLock_DW);
22080 + mutex_unlock(&inode->i_mutex);
22082 + mutex_unlock(&args->dir->i_mutex);
22084 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22092 diff -urNp -x '*.orig' linux-4.4/fs/aufs/opts.c linux-4.4/fs/aufs/opts.c
22093 --- linux-4.4/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22094 +++ linux-4.4/fs/aufs/opts.c 2021-02-24 17:28:14.408808278 +0100
22097 + * Copyright (C) 2005-2016 Junjiro R. Okajima
22099 + * This program, aufs is free software; you can redistribute it and/or modify
22100 + * it under the terms of the GNU General Public License as published by
22101 + * the Free Software Foundation; either version 2 of the License, or
22102 + * (at your option) any later version.
22104 + * This program is distributed in the hope that it will be useful,
22105 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22106 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22107 + * GNU General Public License for more details.
22109 + * You should have received a copy of the GNU General Public License
22110 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22114 + * mount options/flags
22117 +#include <linux/namei.h>
22118 +#include <linux/types.h> /* a distribution requires */
22119 +#include <linux/parser.h>
22122 +/* ---------------------------------------------------------------------- */
22126 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
22127 + Opt_idel, Opt_imod,
22128 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
22129 + Opt_rdblk_def, Opt_rdhash_def,
22130 + Opt_xino, Opt_noxino,
22131 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22132 + Opt_trunc_xino_path, Opt_itrunc_xino,
22133 + Opt_trunc_xib, Opt_notrunc_xib,
22134 + Opt_shwh, Opt_noshwh,
22135 + Opt_plink, Opt_noplink, Opt_list_plink,
22137 + Opt_dio, Opt_nodio,
22138 + Opt_diropq_a, Opt_diropq_w,
22139 + Opt_warn_perm, Opt_nowarn_perm,
22140 + Opt_wbr_copyup, Opt_wbr_create,
22142 + Opt_verbose, Opt_noverbose,
22143 + Opt_sum, Opt_nosum, Opt_wsum,
22144 + Opt_dirperm1, Opt_nodirperm1,
22145 + Opt_acl, Opt_noacl,
22146 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22149 +static match_table_t options = {
22150 + {Opt_br, "br=%s"},
22151 + {Opt_br, "br:%s"},
22153 + {Opt_add, "add=%d:%s"},
22154 + {Opt_add, "add:%d:%s"},
22155 + {Opt_add, "ins=%d:%s"},
22156 + {Opt_add, "ins:%d:%s"},
22157 + {Opt_append, "append=%s"},
22158 + {Opt_append, "append:%s"},
22159 + {Opt_prepend, "prepend=%s"},
22160 + {Opt_prepend, "prepend:%s"},
22162 + {Opt_del, "del=%s"},
22163 + {Opt_del, "del:%s"},
22164 + /* {Opt_idel, "idel:%d"}, */
22165 + {Opt_mod, "mod=%s"},
22166 + {Opt_mod, "mod:%s"},
22167 + /* {Opt_imod, "imod:%d:%s"}, */
22169 + {Opt_dirwh, "dirwh=%d"},
22171 + {Opt_xino, "xino=%s"},
22172 + {Opt_noxino, "noxino"},
22173 + {Opt_trunc_xino, "trunc_xino"},
22174 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22175 + {Opt_notrunc_xino, "notrunc_xino"},
22176 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22177 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22178 + /* {Opt_zxino, "zxino=%s"}, */
22179 + {Opt_trunc_xib, "trunc_xib"},
22180 + {Opt_notrunc_xib, "notrunc_xib"},
22182 +#ifdef CONFIG_PROC_FS
22183 + {Opt_plink, "plink"},
22185 + {Opt_ignore_silent, "plink"},
22188 + {Opt_noplink, "noplink"},
22190 +#ifdef CONFIG_AUFS_DEBUG
22191 + {Opt_list_plink, "list_plink"},
22194 + {Opt_udba, "udba=%s"},
22196 + {Opt_dio, "dio"},
22197 + {Opt_nodio, "nodio"},
22199 +#ifdef CONFIG_AUFS_FHSM
22200 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22202 + {Opt_ignore_silent, "fhsm_sec=%d"},
22205 + {Opt_diropq_a, "diropq=always"},
22206 + {Opt_diropq_a, "diropq=a"},
22207 + {Opt_diropq_w, "diropq=whiteouted"},
22208 + {Opt_diropq_w, "diropq=w"},
22210 + {Opt_warn_perm, "warn_perm"},
22211 + {Opt_nowarn_perm, "nowarn_perm"},
22213 + /* keep them temporary */
22214 + {Opt_ignore_silent, "nodlgt"},
22215 + {Opt_ignore_silent, "clean_plink"},
22217 +#ifdef CONFIG_AUFS_SHWH
22218 + {Opt_shwh, "shwh"},
22220 + {Opt_noshwh, "noshwh"},
22222 + {Opt_dirperm1, "dirperm1"},
22223 + {Opt_nodirperm1, "nodirperm1"},
22225 + {Opt_verbose, "verbose"},
22226 + {Opt_verbose, "v"},
22227 + {Opt_noverbose, "noverbose"},
22228 + {Opt_noverbose, "quiet"},
22229 + {Opt_noverbose, "q"},
22230 + {Opt_noverbose, "silent"},
22232 + {Opt_sum, "sum"},
22233 + {Opt_nosum, "nosum"},
22234 + {Opt_wsum, "wsum"},
22236 + {Opt_rdcache, "rdcache=%d"},
22237 + {Opt_rdblk, "rdblk=%d"},
22238 + {Opt_rdblk_def, "rdblk=def"},
22239 + {Opt_rdhash, "rdhash=%d"},
22240 + {Opt_rdhash_def, "rdhash=def"},
22242 + {Opt_wbr_create, "create=%s"},
22243 + {Opt_wbr_create, "create_policy=%s"},
22244 + {Opt_wbr_copyup, "cpup=%s"},
22245 + {Opt_wbr_copyup, "copyup=%s"},
22246 + {Opt_wbr_copyup, "copyup_policy=%s"},
22248 + /* generic VFS flag */
22249 +#ifdef CONFIG_FS_POSIX_ACL
22250 + {Opt_acl, "acl"},
22251 + {Opt_noacl, "noacl"},
22253 + {Opt_ignore_silent, "acl"},
22254 + {Opt_ignore_silent, "noacl"},
22257 + /* internal use for the scripts */
22258 + {Opt_ignore_silent, "si=%s"},
22260 + {Opt_br, "dirs=%s"},
22261 + {Opt_ignore, "debug=%d"},
22262 + {Opt_ignore, "delete=whiteout"},
22263 + {Opt_ignore, "delete=all"},
22264 + {Opt_ignore, "imap=%s"},
22266 + /* temporary workaround, due to old mount(8)? */
22267 + {Opt_ignore_silent, "relatime"},
22272 +/* ---------------------------------------------------------------------- */
22274 +static const char *au_parser_pattern(int val, match_table_t tbl)
22276 + struct match_token *p;
22279 + while (p->pattern) {
22280 + if (p->token == val)
22281 + return p->pattern;
22288 +static const char *au_optstr(int *val, match_table_t tbl)
22290 + struct match_token *p;
22297 + while (p->pattern) {
22299 + && (v & p->token) == p->token) {
22300 + *val &= ~p->token;
22301 + return p->pattern;
22310 +/* ---------------------------------------------------------------------- */
22312 +static match_table_t brperm = {
22313 + {AuBrPerm_RO, AUFS_BRPERM_RO},
22314 + {AuBrPerm_RR, AUFS_BRPERM_RR},
22315 + {AuBrPerm_RW, AUFS_BRPERM_RW},
22319 +static match_table_t brattr = {
22321 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
22322 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
22323 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
22324 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
22325 +#ifdef CONFIG_AUFS_FHSM
22326 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
22328 +#ifdef CONFIG_AUFS_XATTR
22329 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
22330 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
22331 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
22332 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
22333 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
22334 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
22337 + /* ro/rr branch */
22338 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
22341 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
22342 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
22347 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
22354 + p = strchr(str, '+');
22357 + v = match_token(str, table, args);
22359 + if (v & AuBrAttr_CMOO_Mask)
22360 + attr &= ~AuBrAttr_CMOO_Mask;
22365 + pr_warn("ignored branch attribute %s\n", str);
22375 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
22383 + p = au_optstr(&perm, brattr);
22386 + memcpy(q, p, sz + 1);
22392 + p = au_optstr(&perm, brattr);
22396 + memcpy(q, p, sz + 1);
22402 + return q - str->a;
22405 +static int noinline_for_stack br_perm_val(char *perm)
22407 + int val, bad, sz;
22409 + substring_t args[MAX_OPT_ARGS];
22410 + au_br_perm_str_t attr;
22412 + p = strchr(perm, '+');
22415 + val = match_token(perm, brperm, args);
22419 + pr_warn("ignored branch permission %s\n", perm);
22420 + val = AuBrPerm_RO;
22426 + val |= br_attr_val(p + 1, brattr, args);
22429 + switch (val & AuBrPerm_Mask) {
22430 + case AuBrPerm_RO:
22431 + case AuBrPerm_RR:
22432 + bad = val & AuBrWAttr_Mask;
22433 + val &= ~AuBrWAttr_Mask;
22435 + case AuBrPerm_RW:
22436 + bad = val & AuBrRAttr_Mask;
22437 + val &= ~AuBrRAttr_Mask;
22442 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
22443 + * does not treat it as an error, just warning.
22444 + * this is a tiny guard for the user operation.
22446 + if (val & AuBrAttr_UNPIN) {
22447 + bad |= AuBrAttr_UNPIN;
22448 + val &= ~AuBrAttr_UNPIN;
22451 + if (unlikely(bad)) {
22452 + sz = au_do_optstr_br_attr(&attr, bad);
22454 + pr_warn("ignored branch attribute %s\n", attr.a);
22461 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
22463 + au_br_perm_str_t attr;
22469 + p = au_optstr(&perm, brperm);
22470 + AuDebugOn(!p || !*p);
22472 + memcpy(q, p, sz + 1);
22475 + sz = au_do_optstr_br_attr(&attr, perm);
22478 + memcpy(q, attr.a, sz + 1);
22481 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
22484 +/* ---------------------------------------------------------------------- */
22486 +static match_table_t udbalevel = {
22487 + {AuOpt_UDBA_REVAL, "reval"},
22488 + {AuOpt_UDBA_NONE, "none"},
22489 +#ifdef CONFIG_AUFS_HNOTIFY
22490 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
22491 +#ifdef CONFIG_AUFS_HFSNOTIFY
22492 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
22498 +static int noinline_for_stack udba_val(char *str)
22500 + substring_t args[MAX_OPT_ARGS];
22502 + return match_token(str, udbalevel, args);
22505 +const char *au_optstr_udba(int udba)
22507 + return au_parser_pattern(udba, udbalevel);
22510 +/* ---------------------------------------------------------------------- */
22512 +static match_table_t au_wbr_create_policy = {
22513 + {AuWbrCreate_TDP, "tdp"},
22514 + {AuWbrCreate_TDP, "top-down-parent"},
22515 + {AuWbrCreate_RR, "rr"},
22516 + {AuWbrCreate_RR, "round-robin"},
22517 + {AuWbrCreate_MFS, "mfs"},
22518 + {AuWbrCreate_MFS, "most-free-space"},
22519 + {AuWbrCreate_MFSV, "mfs:%d"},
22520 + {AuWbrCreate_MFSV, "most-free-space:%d"},
22522 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
22523 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
22524 + {AuWbrCreate_PMFS, "pmfs"},
22525 + {AuWbrCreate_PMFSV, "pmfs:%d"},
22526 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
22527 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
22533 + * cf. linux/lib/parser.c and cmdline.c
22534 + * gave up calling memparse() since it uses simple_strtoull() instead of
22537 +static int noinline_for_stack
22538 +au_match_ull(substring_t *s, unsigned long long *result)
22541 + unsigned int len;
22545 + len = s->to - s->from;
22546 + if (len + 1 <= sizeof(a)) {
22547 + memcpy(a, s->from, len);
22549 + err = kstrtoull(a, 0, result);
22554 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
22555 + struct au_opt_wbr_create *create)
22558 + unsigned long long ull;
22561 + if (!au_match_ull(arg, &ull))
22562 + create->mfsrr_watermark = ull;
22564 + pr_err("bad integer in %s\n", str);
22571 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
22572 + struct au_opt_wbr_create *create)
22577 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
22578 + create->mfs_second = n;
22580 + pr_err("bad integer in %s\n", str);
22587 +static int noinline_for_stack
22588 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
22591 + substring_t args[MAX_OPT_ARGS];
22593 + err = match_token(str, au_wbr_create_policy, args);
22594 + create->wbr_create = err;
22596 + case AuWbrCreate_MFSRRV:
22597 + case AuWbrCreate_PMFSRRV:
22598 + e = au_wbr_mfs_wmark(&args[0], str, create);
22600 + e = au_wbr_mfs_sec(&args[1], str, create);
22604 + case AuWbrCreate_MFSRR:
22605 + case AuWbrCreate_PMFSRR:
22606 + e = au_wbr_mfs_wmark(&args[0], str, create);
22607 + if (unlikely(e)) {
22612 + case AuWbrCreate_MFS:
22613 + case AuWbrCreate_PMFS:
22614 + create->mfs_second = AUFS_MFS_DEF_SEC;
22616 + case AuWbrCreate_MFSV:
22617 + case AuWbrCreate_PMFSV:
22618 + e = au_wbr_mfs_sec(&args[0], str, create);
22627 +const char *au_optstr_wbr_create(int wbr_create)
22629 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
22632 +static match_table_t au_wbr_copyup_policy = {
22633 + {AuWbrCopyup_TDP, "tdp"},
22634 + {AuWbrCopyup_TDP, "top-down-parent"},
22635 + {AuWbrCopyup_BUP, "bup"},
22636 + {AuWbrCopyup_BUP, "bottom-up-parent"},
22637 + {AuWbrCopyup_BU, "bu"},
22638 + {AuWbrCopyup_BU, "bottom-up"},
22642 +static int noinline_for_stack au_wbr_copyup_val(char *str)
22644 + substring_t args[MAX_OPT_ARGS];
22646 + return match_token(str, au_wbr_copyup_policy, args);
22649 +const char *au_optstr_wbr_copyup(int wbr_copyup)
22651 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
22654 +/* ---------------------------------------------------------------------- */
22656 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
22658 +static void dump_opts(struct au_opts *opts)
22660 +#ifdef CONFIG_AUFS_DEBUG
22661 + /* reduce stack space */
22663 + struct au_opt_add *add;
22664 + struct au_opt_del *del;
22665 + struct au_opt_mod *mod;
22666 + struct au_opt_xino *xino;
22667 + struct au_opt_xino_itrunc *xino_itrunc;
22668 + struct au_opt_wbr_create *create;
22670 + struct au_opt *opt;
22673 + while (opt->type != Opt_tail) {
22674 + switch (opt->type) {
22676 + u.add = &opt->add;
22677 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
22678 + u.add->bindex, u.add->pathname, u.add->perm,
22679 + u.add->path.dentry);
22683 + u.del = &opt->del;
22684 + AuDbg("del {%s, %p}\n",
22685 + u.del->pathname, u.del->h_path.dentry);
22689 + u.mod = &opt->mod;
22690 + AuDbg("mod {%s, 0x%x, %p}\n",
22691 + u.mod->path, u.mod->perm, u.mod->h_root);
22694 + u.add = &opt->add;
22695 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
22696 + u.add->bindex, u.add->pathname, u.add->perm,
22697 + u.add->path.dentry);
22699 + case Opt_prepend:
22700 + u.add = &opt->add;
22701 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
22702 + u.add->bindex, u.add->pathname, u.add->perm,
22703 + u.add->path.dentry);
22706 + AuDbg("dirwh %d\n", opt->dirwh);
22708 + case Opt_rdcache:
22709 + AuDbg("rdcache %d\n", opt->rdcache);
22712 + AuDbg("rdblk %u\n", opt->rdblk);
22714 + case Opt_rdblk_def:
22715 + AuDbg("rdblk_def\n");
22718 + AuDbg("rdhash %u\n", opt->rdhash);
22720 + case Opt_rdhash_def:
22721 + AuDbg("rdhash_def\n");
22724 + u.xino = &opt->xino;
22725 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
22727 + case Opt_trunc_xino:
22728 + AuLabel(trunc_xino);
22730 + case Opt_notrunc_xino:
22731 + AuLabel(notrunc_xino);
22733 + case Opt_trunc_xino_path:
22734 + case Opt_itrunc_xino:
22735 + u.xino_itrunc = &opt->xino_itrunc;
22736 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
22741 + case Opt_trunc_xib:
22742 + AuLabel(trunc_xib);
22744 + case Opt_notrunc_xib:
22745 + AuLabel(notrunc_xib);
22753 + case Opt_dirperm1:
22754 + AuLabel(dirperm1);
22756 + case Opt_nodirperm1:
22757 + AuLabel(nodirperm1);
22762 + case Opt_noplink:
22763 + AuLabel(noplink);
22765 + case Opt_list_plink:
22766 + AuLabel(list_plink);
22769 + AuDbg("udba %d, %s\n",
22770 + opt->udba, au_optstr_udba(opt->udba));
22778 + case Opt_diropq_a:
22779 + AuLabel(diropq_a);
22781 + case Opt_diropq_w:
22782 + AuLabel(diropq_w);
22784 + case Opt_warn_perm:
22785 + AuLabel(warn_perm);
22787 + case Opt_nowarn_perm:
22788 + AuLabel(nowarn_perm);
22790 + case Opt_verbose:
22791 + AuLabel(verbose);
22793 + case Opt_noverbose:
22794 + AuLabel(noverbose);
22805 + case Opt_wbr_create:
22806 + u.create = &opt->wbr_create;
22807 + AuDbg("create %d, %s\n", u.create->wbr_create,
22808 + au_optstr_wbr_create(u.create->wbr_create));
22809 + switch (u.create->wbr_create) {
22810 + case AuWbrCreate_MFSV:
22811 + case AuWbrCreate_PMFSV:
22812 + AuDbg("%d sec\n", u.create->mfs_second);
22814 + case AuWbrCreate_MFSRR:
22815 + AuDbg("%llu watermark\n",
22816 + u.create->mfsrr_watermark);
22818 + case AuWbrCreate_MFSRRV:
22819 + case AuWbrCreate_PMFSRRV:
22820 + AuDbg("%llu watermark, %d sec\n",
22821 + u.create->mfsrr_watermark,
22822 + u.create->mfs_second);
22826 + case Opt_wbr_copyup:
22827 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
22828 + au_optstr_wbr_copyup(opt->wbr_copyup));
22830 + case Opt_fhsm_sec:
22831 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
22847 +void au_opts_free(struct au_opts *opts)
22849 + struct au_opt *opt;
22852 + while (opt->type != Opt_tail) {
22853 + switch (opt->type) {
22856 + case Opt_prepend:
22857 + path_put(&opt->add.path);
22861 + path_put(&opt->del.h_path);
22865 + dput(opt->mod.h_root);
22868 + fput(opt->xino.file);
22875 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
22876 + aufs_bindex_t bindex)
22879 + struct au_opt_add *add = &opt->add;
22882 + add->bindex = bindex;
22883 + add->perm = AuBrPerm_RO;
22884 + add->pathname = opt_str;
22885 + p = strchr(opt_str, '=');
22889 + add->perm = br_perm_val(p);
22892 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
22895 + add->perm = AuBrPerm_RO;
22896 + if (au_test_fs_rr(add->path.dentry->d_sb))
22897 + add->perm = AuBrPerm_RR;
22898 + else if (!bindex && !(sb_flags & MS_RDONLY))
22899 + add->perm = AuBrPerm_RW;
22901 + opt->type = Opt_add;
22904 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
22911 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
22915 + del->pathname = args[0].from;
22916 + AuDbg("del path %s\n", del->pathname);
22918 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
22919 + if (unlikely(err))
22920 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
22925 +#if 0 /* reserved for future use */
22926 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
22927 + struct au_opt_del *del, substring_t args[])
22930 + struct dentry *root;
22933 + root = sb->s_root;
22934 + aufs_read_lock(root, AuLock_FLUSH);
22935 + if (bindex < 0 || au_sbend(sb) < bindex) {
22936 + pr_err("out of bounds, %d\n", bindex);
22941 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
22942 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
22945 + aufs_read_unlock(root, !AuLock_IR);
22950 +static int noinline_for_stack
22951 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
22954 + struct path path;
22958 + mod->path = args[0].from;
22959 + p = strchr(mod->path, '=');
22960 + if (unlikely(!p)) {
22961 + pr_err("no permssion %s\n", args[0].from);
22966 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
22967 + if (unlikely(err)) {
22968 + pr_err("lookup failed %s (%d)\n", mod->path, err);
22972 + mod->perm = br_perm_val(p);
22973 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
22974 + mod->h_root = dget(path.dentry);
22981 +#if 0 /* reserved for future use */
22982 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
22983 + struct au_opt_mod *mod, substring_t args[])
22986 + struct dentry *root;
22989 + root = sb->s_root;
22990 + aufs_read_lock(root, AuLock_FLUSH);
22991 + if (bindex < 0 || au_sbend(sb) < bindex) {
22992 + pr_err("out of bounds, %d\n", bindex);
22997 + mod->perm = br_perm_val(args[1].from);
22998 + AuDbg("mod path %s, perm 0x%x, %s\n",
22999 + mod->path, mod->perm, args[1].from);
23000 + mod->h_root = dget(au_h_dptr(root, bindex));
23003 + aufs_read_unlock(root, !AuLock_IR);
23008 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23009 + substring_t args[])
23012 + struct file *file;
23014 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23015 + err = PTR_ERR(file);
23016 + if (IS_ERR(file))
23020 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
23022 + pr_err("%s must be outside\n", args[0].from);
23027 + xino->file = file;
23028 + xino->path = args[0].from;
23034 +static int noinline_for_stack
23035 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23036 + struct au_opt_xino_itrunc *xino_itrunc,
23037 + substring_t args[])
23040 + aufs_bindex_t bend, bindex;
23041 + struct path path;
23042 + struct dentry *root;
23044 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23045 + if (unlikely(err)) {
23046 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23050 + xino_itrunc->bindex = -1;
23051 + root = sb->s_root;
23052 + aufs_read_lock(root, AuLock_FLUSH);
23053 + bend = au_sbend(sb);
23054 + for (bindex = 0; bindex <= bend; bindex++) {
23055 + if (au_h_dptr(root, bindex) == path.dentry) {
23056 + xino_itrunc->bindex = bindex;
23060 + aufs_read_unlock(root, !AuLock_IR);
23063 + if (unlikely(xino_itrunc->bindex < 0)) {
23064 + pr_err("no such branch %s\n", args[0].from);
23072 +/* called without aufs lock */
23073 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23075 + int err, n, token;
23076 + aufs_bindex_t bindex;
23077 + unsigned char skipped;
23078 + struct dentry *root;
23079 + struct au_opt *opt, *opt_tail;
23081 + /* reduce the stack space */
23083 + struct au_opt_xino_itrunc *xino_itrunc;
23084 + struct au_opt_wbr_create *create;
23087 + substring_t args[MAX_OPT_ARGS];
23091 + a = kmalloc(sizeof(*a), GFP_NOFS);
23092 + if (unlikely(!a))
23095 + root = sb->s_root;
23099 + opt_tail = opt + opts->max_opt - 1;
23100 + opt->type = Opt_tail;
23101 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23104 + token = match_token(opt_str, options, a->args);
23108 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23110 + err = opt_add(opt, opt_str, opts->sb_flags,
23112 + if (unlikely(!err && ++opt > opt_tail)) {
23116 + opt->type = Opt_tail;
23121 + if (unlikely(match_int(&a->args[0], &n))) {
23122 + pr_err("bad integer in %s\n", opt_str);
23126 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23129 + opt->type = token;
23132 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23133 + /*dummy bindex*/1);
23135 + opt->type = token;
23137 + case Opt_prepend:
23138 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23141 + opt->type = token;
23144 + err = au_opts_parse_del(&opt->del, a->args);
23146 + opt->type = token;
23148 +#if 0 /* reserved for future use */
23150 + del->pathname = "(indexed)";
23151 + if (unlikely(match_int(&args[0], &n))) {
23152 + pr_err("bad integer in %s\n", opt_str);
23155 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23157 + opt->type = token;
23161 + err = au_opts_parse_mod(&opt->mod, a->args);
23163 + opt->type = token;
23165 +#ifdef IMOD /* reserved for future use */
23167 + u.mod->path = "(indexed)";
23168 + if (unlikely(match_int(&a->args[0], &n))) {
23169 + pr_err("bad integer in %s\n", opt_str);
23172 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23174 + opt->type = token;
23178 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23180 + opt->type = token;
23183 + case Opt_trunc_xino_path:
23184 + err = au_opts_parse_xino_itrunc_path
23185 + (sb, &opt->xino_itrunc, a->args);
23187 + opt->type = token;
23190 + case Opt_itrunc_xino:
23191 + u.xino_itrunc = &opt->xino_itrunc;
23192 + if (unlikely(match_int(&a->args[0], &n))) {
23193 + pr_err("bad integer in %s\n", opt_str);
23196 + u.xino_itrunc->bindex = n;
23197 + aufs_read_lock(root, AuLock_FLUSH);
23198 + if (n < 0 || au_sbend(sb) < n) {
23199 + pr_err("out of bounds, %d\n", n);
23200 + aufs_read_unlock(root, !AuLock_IR);
23203 + aufs_read_unlock(root, !AuLock_IR);
23205 + opt->type = token;
23209 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23212 + opt->type = token;
23215 + case Opt_rdcache:
23216 + if (unlikely(match_int(&a->args[0], &n))) {
23217 + pr_err("bad integer in %s\n", opt_str);
23220 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23221 + pr_err("rdcache must be smaller than %d\n",
23222 + AUFS_RDCACHE_MAX);
23225 + opt->rdcache = n;
23227 + opt->type = token;
23230 + if (unlikely(match_int(&a->args[0], &n)
23232 + || n > KMALLOC_MAX_SIZE)) {
23233 + pr_err("bad integer in %s\n", opt_str);
23236 + if (unlikely(n && n < NAME_MAX)) {
23237 + pr_err("rdblk must be larger than %d\n",
23243 + opt->type = token;
23246 + if (unlikely(match_int(&a->args[0], &n)
23248 + || n * sizeof(struct hlist_head)
23249 + > KMALLOC_MAX_SIZE)) {
23250 + pr_err("bad integer in %s\n", opt_str);
23255 + opt->type = token;
23258 + case Opt_trunc_xino:
23259 + case Opt_notrunc_xino:
23261 + case Opt_trunc_xib:
23262 + case Opt_notrunc_xib:
23265 + case Opt_dirperm1:
23266 + case Opt_nodirperm1:
23268 + case Opt_noplink:
23269 + case Opt_list_plink:
23272 + case Opt_diropq_a:
23273 + case Opt_diropq_w:
23274 + case Opt_warn_perm:
23275 + case Opt_nowarn_perm:
23276 + case Opt_verbose:
23277 + case Opt_noverbose:
23281 + case Opt_rdblk_def:
23282 + case Opt_rdhash_def:
23286 + opt->type = token;
23290 + opt->udba = udba_val(a->args[0].from);
23291 + if (opt->udba >= 0) {
23293 + opt->type = token;
23295 + pr_err("wrong value, %s\n", opt_str);
23298 + case Opt_wbr_create:
23299 + u.create = &opt->wbr_create;
23300 + u.create->wbr_create
23301 + = au_wbr_create_val(a->args[0].from, u.create);
23302 + if (u.create->wbr_create >= 0) {
23304 + opt->type = token;
23306 + pr_err("wrong value, %s\n", opt_str);
23308 + case Opt_wbr_copyup:
23309 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23310 + if (opt->wbr_copyup >= 0) {
23312 + opt->type = token;
23314 + pr_err("wrong value, %s\n", opt_str);
23317 + case Opt_fhsm_sec:
23318 + if (unlikely(match_int(&a->args[0], &n)
23320 + pr_err("bad integer in %s\n", opt_str);
23323 + if (sysaufs_brs) {
23324 + opt->fhsm_second = n;
23325 + opt->type = token;
23327 + pr_warn("ignored %s\n", opt_str);
23332 + pr_warn("ignored %s\n", opt_str);
23334 + case Opt_ignore_silent:
23339 + pr_err("unknown option %s\n", opt_str);
23343 + if (!err && !skipped) {
23344 + if (unlikely(++opt > opt_tail)) {
23347 + opt->type = Opt_tail;
23350 + opt->type = Opt_tail;
23356 + if (unlikely(err))
23357 + au_opts_free(opts);
23363 +static int au_opt_wbr_create(struct super_block *sb,
23364 + struct au_opt_wbr_create *create)
23367 + struct au_sbinfo *sbinfo;
23369 + SiMustWriteLock(sb);
23371 + err = 1; /* handled */
23372 + sbinfo = au_sbi(sb);
23373 + if (sbinfo->si_wbr_create_ops->fin) {
23374 + err = sbinfo->si_wbr_create_ops->fin(sb);
23379 + sbinfo->si_wbr_create = create->wbr_create;
23380 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
23381 + switch (create->wbr_create) {
23382 + case AuWbrCreate_MFSRRV:
23383 + case AuWbrCreate_MFSRR:
23384 + case AuWbrCreate_PMFSRR:
23385 + case AuWbrCreate_PMFSRRV:
23386 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
23388 + case AuWbrCreate_MFS:
23389 + case AuWbrCreate_MFSV:
23390 + case AuWbrCreate_PMFS:
23391 + case AuWbrCreate_PMFSV:
23392 + sbinfo->si_wbr_mfs.mfs_expire
23393 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
23397 + if (sbinfo->si_wbr_create_ops->init)
23398 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
23405 + * plus: processed without an error
23406 + * zero: unprocessed
23408 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
23409 + struct au_opts *opts)
23412 + struct au_sbinfo *sbinfo;
23414 + SiMustWriteLock(sb);
23416 + err = 1; /* handled */
23417 + sbinfo = au_sbi(sb);
23418 + switch (opt->type) {
23420 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23421 + sbinfo->si_mntflags |= opt->udba;
23422 + opts->given_udba |= opt->udba;
23426 + au_opt_set(sbinfo->si_mntflags, PLINK);
23428 + case Opt_noplink:
23429 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23430 + au_plink_put(sb, /*verbose*/1);
23431 + au_opt_clr(sbinfo->si_mntflags, PLINK);
23433 + case Opt_list_plink:
23434 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23435 + au_plink_list(sb);
23439 + au_opt_set(sbinfo->si_mntflags, DIO);
23440 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23443 + au_opt_clr(sbinfo->si_mntflags, DIO);
23444 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23447 + case Opt_fhsm_sec:
23448 + au_fhsm_set(sbinfo, opt->fhsm_second);
23451 + case Opt_diropq_a:
23452 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23454 + case Opt_diropq_w:
23455 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23458 + case Opt_warn_perm:
23459 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
23461 + case Opt_nowarn_perm:
23462 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
23465 + case Opt_verbose:
23466 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
23468 + case Opt_noverbose:
23469 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
23473 + au_opt_set(sbinfo->si_mntflags, SUM);
23476 + au_opt_clr(sbinfo->si_mntflags, SUM);
23477 + au_opt_set(sbinfo->si_mntflags, SUM_W);
23479 + au_opt_clr(sbinfo->si_mntflags, SUM);
23480 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
23483 + case Opt_wbr_create:
23484 + err = au_opt_wbr_create(sb, &opt->wbr_create);
23486 + case Opt_wbr_copyup:
23487 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
23488 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
23492 + sbinfo->si_dirwh = opt->dirwh;
23495 + case Opt_rdcache:
23496 + sbinfo->si_rdcache
23497 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
23500 + sbinfo->si_rdblk = opt->rdblk;
23502 + case Opt_rdblk_def:
23503 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
23506 + sbinfo->si_rdhash = opt->rdhash;
23508 + case Opt_rdhash_def:
23509 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
23513 + au_opt_set(sbinfo->si_mntflags, SHWH);
23516 + au_opt_clr(sbinfo->si_mntflags, SHWH);
23519 + case Opt_dirperm1:
23520 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
23522 + case Opt_nodirperm1:
23523 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
23526 + case Opt_trunc_xino:
23527 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
23529 + case Opt_notrunc_xino:
23530 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
23533 + case Opt_trunc_xino_path:
23534 + case Opt_itrunc_xino:
23535 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
23540 + case Opt_trunc_xib:
23541 + au_fset_opts(opts->flags, TRUNC_XIB);
23543 + case Opt_notrunc_xib:
23544 + au_fclr_opts(opts->flags, TRUNC_XIB);
23548 + sb->s_flags |= MS_POSIXACL;
23551 + sb->s_flags &= ~MS_POSIXACL;
23563 + * returns tri-state.
23564 + * plus: processed without an error
23565 + * zero: unprocessed
23568 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
23569 + struct au_opts *opts)
23571 + int err, do_refresh;
23574 + switch (opt->type) {
23576 + opt->add.bindex = au_sbend(sb) + 1;
23577 + if (opt->add.bindex < 0)
23578 + opt->add.bindex = 0;
23580 + case Opt_prepend:
23581 + opt->add.bindex = 0;
23582 + add: /* indented label */
23584 + err = au_br_add(sb, &opt->add,
23585 + au_ftest_opts(opts->flags, REMOUNT));
23588 + au_fset_opts(opts->flags, REFRESH);
23594 + err = au_br_del(sb, &opt->del,
23595 + au_ftest_opts(opts->flags, REMOUNT));
23598 + au_fset_opts(opts->flags, TRUNC_XIB);
23599 + au_fset_opts(opts->flags, REFRESH);
23605 + err = au_br_mod(sb, &opt->mod,
23606 + au_ftest_opts(opts->flags, REMOUNT),
23611 + au_fset_opts(opts->flags, REFRESH);
23619 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
23620 + struct au_opt_xino **opt_xino,
23621 + struct au_opts *opts)
23624 + aufs_bindex_t bend, bindex;
23625 + struct dentry *root, *parent, *h_root;
23628 + switch (opt->type) {
23630 + err = au_xino_set(sb, &opt->xino,
23631 + !!au_ftest_opts(opts->flags, REMOUNT));
23632 + if (unlikely(err))
23635 + *opt_xino = &opt->xino;
23636 + au_xino_brid_set(sb, -1);
23638 + /* safe d_parent access */
23639 + parent = opt->xino.file->f_path.dentry->d_parent;
23640 + root = sb->s_root;
23641 + bend = au_sbend(sb);
23642 + for (bindex = 0; bindex <= bend; bindex++) {
23643 + h_root = au_h_dptr(root, bindex);
23644 + if (h_root == parent) {
23645 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
23653 + au_xino_brid_set(sb, -1);
23654 + *opt_xino = (void *)-1;
23661 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
23662 + unsigned int pending)
23665 + aufs_bindex_t bindex, bend;
23666 + unsigned char do_plink, skip, do_free, can_no_dreval;
23667 + struct au_branch *br;
23668 + struct au_wbr *wbr;
23669 + struct dentry *root, *dentry;
23670 + struct inode *dir, *h_dir;
23671 + struct au_sbinfo *sbinfo;
23672 + struct au_hinode *hdir;
23674 + SiMustAnyLock(sb);
23676 + sbinfo = au_sbi(sb);
23677 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
23679 + if (!(sb_flags & MS_RDONLY)) {
23680 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
23681 + pr_warn("first branch should be rw\n");
23682 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
23683 + pr_warn("shwh should be used with ro\n");
23686 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
23687 + && !au_opt_test(sbinfo->si_mntflags, XINO))
23688 + pr_warn("udba=*notify requires xino\n");
23690 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
23691 + pr_warn("dirperm1 breaks the protection"
23692 + " by the permission bits on the lower branch\n");
23696 + root = sb->s_root;
23697 + dir = d_inode(root);
23698 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
23699 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
23701 + bend = au_sbend(sb);
23702 + for (bindex = 0; !err && bindex <= bend; bindex++) {
23704 + h_dir = au_h_iptr(dir, bindex);
23705 + br = au_sbr(sb, bindex);
23707 + if ((br->br_perm & AuBrAttr_ICEX)
23708 + && !h_dir->i_op->listxattr)
23709 + br->br_perm &= ~AuBrAttr_ICEX;
23711 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
23712 + && (au_br_sb(br)->s_flags & MS_NOSEC))
23713 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
23717 + wbr = br->br_wbr;
23719 + wbr_wh_read_lock(wbr);
23721 + if (!au_br_writable(br->br_perm)) {
23724 + || (!wbr->wbr_whbase
23725 + && !wbr->wbr_plink
23726 + && !wbr->wbr_orph));
23727 + } else if (!au_br_wh_linkable(br->br_perm)) {
23728 + /* skip = (!br->br_whbase && !br->br_orph); */
23729 + skip = (!wbr || !wbr->wbr_whbase);
23730 + if (skip && wbr) {
23732 + skip = !!wbr->wbr_plink;
23734 + skip = !wbr->wbr_plink;
23737 + /* skip = (br->br_whbase && br->br_ohph); */
23738 + skip = (wbr && wbr->wbr_whbase);
23741 + skip = !!wbr->wbr_plink;
23743 + skip = !wbr->wbr_plink;
23747 + wbr_wh_read_unlock(wbr);
23749 + if (can_no_dreval) {
23750 + dentry = br->br_path.dentry;
23751 + spin_lock(&dentry->d_lock);
23752 + if (dentry->d_flags &
23753 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
23754 + can_no_dreval = 0;
23755 + spin_unlock(&dentry->d_lock);
23758 + if (au_br_fhsm(br->br_perm)) {
23760 + AuDebugOn(!br->br_fhsm);
23766 + hdir = au_hi(dir, bindex);
23767 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
23769 + wbr_wh_write_lock(wbr);
23770 + err = au_wh_init(br, sb);
23772 + wbr_wh_write_unlock(wbr);
23773 + au_hn_imtx_unlock(hdir);
23775 + if (!err && do_free) {
23777 + br->br_wbr = NULL;
23781 + if (can_no_dreval)
23782 + au_fset_si(sbinfo, NO_DREVAL);
23784 + au_fclr_si(sbinfo, NO_DREVAL);
23787 + au_fset_si(sbinfo, FHSM);
23788 + for (bindex = bend; bindex >= 0; bindex--) {
23789 + br = au_sbr(sb, bindex);
23790 + if (au_br_fhsm(br->br_perm)) {
23791 + au_fhsm_set_bottom(sb, bindex);
23796 + au_fclr_si(sbinfo, FHSM);
23797 + au_fhsm_set_bottom(sb, -1);
23803 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
23806 + unsigned int tmp;
23807 + aufs_bindex_t bindex, bend;
23808 + struct au_opt *opt;
23809 + struct au_opt_xino *opt_xino, xino;
23810 + struct au_sbinfo *sbinfo;
23811 + struct au_branch *br;
23812 + struct inode *dir;
23814 + SiMustWriteLock(sb);
23819 + while (err >= 0 && opt->type != Opt_tail)
23820 + err = au_opt_simple(sb, opt++, opts);
23823 + else if (unlikely(err < 0))
23826 + /* disable xino and udba temporary */
23827 + sbinfo = au_sbi(sb);
23828 + tmp = sbinfo->si_mntflags;
23829 + au_opt_clr(sbinfo->si_mntflags, XINO);
23830 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
23833 + while (err >= 0 && opt->type != Opt_tail)
23834 + err = au_opt_br(sb, opt++, opts);
23837 + else if (unlikely(err < 0))
23840 + bend = au_sbend(sb);
23841 + if (unlikely(bend < 0)) {
23843 + pr_err("no branches\n");
23847 + if (au_opt_test(tmp, XINO))
23848 + au_opt_set(sbinfo->si_mntflags, XINO);
23850 + while (!err && opt->type != Opt_tail)
23851 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
23852 + if (unlikely(err))
23855 + err = au_opts_verify(sb, sb->s_flags, tmp);
23856 + if (unlikely(err))
23859 + /* restore xino */
23860 + if (au_opt_test(tmp, XINO) && !opt_xino) {
23861 + xino.file = au_xino_def(sb);
23862 + err = PTR_ERR(xino.file);
23863 + if (IS_ERR(xino.file))
23866 + err = au_xino_set(sb, &xino, /*remount*/0);
23868 + if (unlikely(err))
23872 + /* restore udba */
23873 + tmp &= AuOptMask_UDBA;
23874 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23875 + sbinfo->si_mntflags |= tmp;
23876 + bend = au_sbend(sb);
23877 + for (bindex = 0; bindex <= bend; bindex++) {
23878 + br = au_sbr(sb, bindex);
23879 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
23880 + if (unlikely(err))
23881 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
23883 + /* go on even if err */
23885 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
23886 + dir = d_inode(sb->s_root);
23887 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
23894 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
23897 + unsigned char no_dreval;
23898 + struct inode *dir;
23899 + struct au_opt_xino *opt_xino;
23900 + struct au_opt *opt;
23901 + struct au_sbinfo *sbinfo;
23903 + SiMustWriteLock(sb);
23906 + dir = d_inode(sb->s_root);
23907 + sbinfo = au_sbi(sb);
23910 + while (err >= 0 && opt->type != Opt_tail) {
23911 + err = au_opt_simple(sb, opt, opts);
23913 + err = au_opt_br(sb, opt, opts);
23915 + err = au_opt_xino(sb, opt, &opt_xino, opts);
23921 + /* go on even err */
23923 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
23924 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
23925 + if (unlikely(rerr && !err))
23928 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
23929 + au_fset_opts(opts->flags, REFRESH_IDOP);
23931 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
23932 + rerr = au_xib_trunc(sb);
23933 + if (unlikely(rerr && !err))
23937 + /* will be handled by the caller */
23938 + if (!au_ftest_opts(opts->flags, REFRESH)
23939 + && (opts->given_udba
23940 + || au_opt_test(sbinfo->si_mntflags, XINO)
23941 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
23943 + au_fset_opts(opts->flags, REFRESH);
23945 + AuDbg("status 0x%x\n", opts->flags);
23949 +/* ---------------------------------------------------------------------- */
23951 +unsigned int au_opt_udba(struct super_block *sb)
23953 + return au_mntflags(sb) & AuOptMask_UDBA;
23955 diff -urNp -x '*.orig' linux-4.4/fs/aufs/opts.h linux-4.4/fs/aufs/opts.h
23956 --- linux-4.4/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
23957 +++ linux-4.4/fs/aufs/opts.h 2021-02-24 17:28:14.412141719 +0100
23960 + * Copyright (C) 2005-2016 Junjiro R. Okajima
23962 + * This program, aufs is free software; you can redistribute it and/or modify
23963 + * it under the terms of the GNU General Public License as published by
23964 + * the Free Software Foundation; either version 2 of the License, or
23965 + * (at your option) any later version.
23967 + * This program is distributed in the hope that it will be useful,
23968 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23969 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23970 + * GNU General Public License for more details.
23972 + * You should have received a copy of the GNU General Public License
23973 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23977 + * mount options/flags
23980 +#ifndef __AUFS_OPTS_H__
23981 +#define __AUFS_OPTS_H__
23985 +#include <linux/path.h>
23988 +struct super_block;
23990 +/* ---------------------------------------------------------------------- */
23993 +#define AuOpt_XINO 1 /* external inode number bitmap
23994 + and translation table */
23995 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
23996 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
23997 +#define AuOpt_UDBA_REVAL (1 << 3)
23998 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
23999 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24000 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24001 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24003 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24004 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24005 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24006 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24007 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24008 +#define AuOpt_DIO (1 << 14) /* direct io */
24010 +#ifndef CONFIG_AUFS_HNOTIFY
24011 +#undef AuOpt_UDBA_HNOTIFY
24012 +#define AuOpt_UDBA_HNOTIFY 0
24014 +#ifndef CONFIG_AUFS_SHWH
24016 +#define AuOpt_SHWH 0
24019 +#define AuOpt_Def (AuOpt_XINO \
24020 + | AuOpt_UDBA_REVAL \
24022 + /* | AuOpt_DIRPERM1 */ \
24023 + | AuOpt_WARN_PERM)
24024 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24025 + | AuOpt_UDBA_REVAL \
24026 + | AuOpt_UDBA_HNOTIFY)
24028 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24029 +#define au_opt_set(flags, name) do { \
24030 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24031 + ((flags) |= AuOpt_##name); \
24033 +#define au_opt_set_udba(flags, name) do { \
24034 + (flags) &= ~AuOptMask_UDBA; \
24035 + ((flags) |= AuOpt_##name); \
24037 +#define au_opt_clr(flags, name) do { \
24038 + ((flags) &= ~AuOpt_##name); \
24041 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24043 +#ifdef CONFIG_PROC_FS
24046 + return mntflags & ~AuOpt_PLINK;
24050 +/* ---------------------------------------------------------------------- */
24052 +/* policies to select one among multiple writable branches */
24054 + AuWbrCreate_TDP, /* top down parent */
24055 + AuWbrCreate_RR, /* round robin */
24056 + AuWbrCreate_MFS, /* most free space */
24057 + AuWbrCreate_MFSV, /* mfs with seconds */
24058 + AuWbrCreate_MFSRR, /* mfs then rr */
24059 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24060 + AuWbrCreate_PMFS, /* parent and mfs */
24061 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24062 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24063 + AuWbrCreate_PMFSRRV, /* plus seconds */
24065 + AuWbrCreate_Def = AuWbrCreate_TDP
24069 + AuWbrCopyup_TDP, /* top down parent */
24070 + AuWbrCopyup_BUP, /* bottom up parent */
24071 + AuWbrCopyup_BU, /* bottom up */
24073 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24076 +/* ---------------------------------------------------------------------- */
24078 +struct au_opt_add {
24079 + aufs_bindex_t bindex;
24082 + struct path path;
24085 +struct au_opt_del {
24087 + struct path h_path;
24090 +struct au_opt_mod {
24093 + struct dentry *h_root;
24096 +struct au_opt_xino {
24098 + struct file *file;
24101 +struct au_opt_xino_itrunc {
24102 + aufs_bindex_t bindex;
24105 +struct au_opt_wbr_create {
24108 + unsigned long long mfsrr_watermark;
24114 + struct au_opt_xino xino;
24115 + struct au_opt_xino_itrunc xino_itrunc;
24116 + struct au_opt_add add;
24117 + struct au_opt_del del;
24118 + struct au_opt_mod mod;
24121 + unsigned int rdblk;
24122 + unsigned int rdhash;
24124 + struct au_opt_wbr_create wbr_create;
24126 + unsigned int fhsm_second;
24131 +#define AuOpts_REMOUNT 1
24132 +#define AuOpts_REFRESH (1 << 1)
24133 +#define AuOpts_TRUNC_XIB (1 << 2)
24134 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24135 +#define AuOpts_REFRESH_IDOP (1 << 4)
24136 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24137 +#define au_fset_opts(flags, name) \
24138 + do { (flags) |= AuOpts_##name; } while (0)
24139 +#define au_fclr_opts(flags, name) \
24140 + do { (flags) &= ~AuOpts_##name; } while (0)
24143 + struct au_opt *opt;
24146 + unsigned int given_udba;
24147 + unsigned int flags;
24148 + unsigned long sb_flags;
24151 +/* ---------------------------------------------------------------------- */
24154 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24155 +const char *au_optstr_udba(int udba);
24156 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24157 +const char *au_optstr_wbr_create(int wbr_create);
24159 +void au_opts_free(struct au_opts *opts);
24160 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24161 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24162 + unsigned int pending);
24163 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24164 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24166 +unsigned int au_opt_udba(struct super_block *sb);
24168 +#endif /* __KERNEL__ */
24169 +#endif /* __AUFS_OPTS_H__ */
24170 diff -urNp -x '*.orig' linux-4.4/fs/aufs/plink.c linux-4.4/fs/aufs/plink.c
24171 --- linux-4.4/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24172 +++ linux-4.4/fs/aufs/plink.c 2021-02-24 17:28:14.412141719 +0100
24175 + * Copyright (C) 2005-2016 Junjiro R. Okajima
24177 + * This program, aufs is free software; you can redistribute it and/or modify
24178 + * it under the terms of the GNU General Public License as published by
24179 + * the Free Software Foundation; either version 2 of the License, or
24180 + * (at your option) any later version.
24182 + * This program is distributed in the hope that it will be useful,
24183 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24184 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24185 + * GNU General Public License for more details.
24187 + * You should have received a copy of the GNU General Public License
24188 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24198 + * the pseudo-link maintenance mode.
24199 + * during a user process maintains the pseudo-links,
24200 + * prohibit adding a new plink and branch manipulation.
24204 + * For entry functions which will handle plink, and i_mutex is already held
24206 + * They cannot wait and should return an error at once.
24207 + * Callers has to check the error.
24209 + * For entry functions which will handle plink, but i_mutex is not held
24211 + * They can wait the plink maintenance mode to finish.
24213 + * They behave like F_SETLK and F_SETLKW.
24214 + * If the caller never handle plink, then both flags are unnecessary.
24217 +int au_plink_maint(struct super_block *sb, int flags)
24221 + struct au_sbinfo *sbi;
24223 + SiMustAnyLock(sb);
24226 + if (!au_opt_test(au_mntflags(sb), PLINK))
24229 + sbi = au_sbi(sb);
24230 + pid = sbi->si_plink_maint_pid;
24231 + if (!pid || pid == current->pid)
24234 + /* todo: it highly depends upon /sbin/mount.aufs */
24236 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24237 + rcu_read_unlock();
24241 + if (au_ftest_lock(flags, NOPLMW)) {
24242 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24243 + /* AuDebugOn(!lockdep_depth(current)); */
24244 + while (sbi->si_plink_maint_pid) {
24245 + si_read_unlock(sb);
24246 + /* gave up wake_up_bit() */
24247 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24249 + if (au_ftest_lock(flags, FLUSH))
24250 + au_nwt_flush(&sbi->si_nowait);
24251 + si_noflush_read_lock(sb);
24253 + } else if (au_ftest_lock(flags, NOPLM)) {
24254 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24262 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24264 + spin_lock(&sbinfo->si_plink_maint_lock);
24265 + sbinfo->si_plink_maint_pid = 0;
24266 + spin_unlock(&sbinfo->si_plink_maint_lock);
24267 + wake_up_all(&sbinfo->si_plink_wq);
24270 +int au_plink_maint_enter(struct super_block *sb)
24273 + struct au_sbinfo *sbinfo;
24276 + sbinfo = au_sbi(sb);
24277 + /* make sure i am the only one in this fs */
24278 + si_write_lock(sb, AuLock_FLUSH);
24279 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24280 + spin_lock(&sbinfo->si_plink_maint_lock);
24281 + if (!sbinfo->si_plink_maint_pid)
24282 + sbinfo->si_plink_maint_pid = current->pid;
24285 + spin_unlock(&sbinfo->si_plink_maint_lock);
24287 + si_write_unlock(sb);
24292 +/* ---------------------------------------------------------------------- */
24294 +#ifdef CONFIG_AUFS_DEBUG
24295 +void au_plink_list(struct super_block *sb)
24298 + struct au_sbinfo *sbinfo;
24299 + struct hlist_head *plink_hlist;
24300 + struct pseudo_link *plink;
24302 + SiMustAnyLock(sb);
24304 + sbinfo = au_sbi(sb);
24305 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24306 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24308 + for (i = 0; i < AuPlink_NHASH; i++) {
24309 + plink_hlist = &sbinfo->si_plink[i].head;
24311 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24312 + AuDbg("%lu\n", plink->inode->i_ino);
24313 + rcu_read_unlock();
24318 +/* is the inode pseudo-linked? */
24319 +int au_plink_test(struct inode *inode)
24322 + struct au_sbinfo *sbinfo;
24323 + struct hlist_head *plink_hlist;
24324 + struct pseudo_link *plink;
24326 + sbinfo = au_sbi(inode->i_sb);
24327 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24328 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
24329 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24332 + i = au_plink_hash(inode->i_ino);
24333 + plink_hlist = &sbinfo->si_plink[i].head;
24335 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24336 + if (plink->inode == inode) {
24340 + rcu_read_unlock();
24344 +/* ---------------------------------------------------------------------- */
24347 + * generate a name for plink.
24348 + * the file will be stored under AUFS_WH_PLINKDIR.
24350 +/* 20 is max digits length of ulong 64 */
24351 +#define PLINK_NAME_LEN ((20 + 1) * 2)
24353 +static int plink_name(char *name, int len, struct inode *inode,
24354 + aufs_bindex_t bindex)
24357 + struct inode *h_inode;
24359 + h_inode = au_h_iptr(inode, bindex);
24360 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
24364 +struct au_do_plink_lkup_args {
24365 + struct dentry **errp;
24366 + struct qstr *tgtname;
24367 + struct dentry *h_parent;
24368 + struct au_branch *br;
24371 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
24372 + struct dentry *h_parent,
24373 + struct au_branch *br)
24375 + struct dentry *h_dentry;
24376 + struct mutex *h_mtx;
24378 + h_mtx = &d_inode(h_parent)->i_mutex;
24379 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
24380 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
24381 + mutex_unlock(h_mtx);
24385 +static void au_call_do_plink_lkup(void *args)
24387 + struct au_do_plink_lkup_args *a = args;
24388 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
24391 +/* lookup the plink-ed @inode under the branch at @bindex */
24392 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
24394 + struct dentry *h_dentry, *h_parent;
24395 + struct au_branch *br;
24397 + char a[PLINK_NAME_LEN];
24398 + struct qstr tgtname = QSTR_INIT(a, 0);
24400 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24402 + br = au_sbr(inode->i_sb, bindex);
24403 + h_parent = br->br_wbr->wbr_plink;
24404 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24406 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24407 + struct au_do_plink_lkup_args args = {
24408 + .errp = &h_dentry,
24409 + .tgtname = &tgtname,
24410 + .h_parent = h_parent,
24414 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
24415 + if (unlikely(wkq_err))
24416 + h_dentry = ERR_PTR(wkq_err);
24418 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
24423 +/* create a pseudo-link */
24424 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
24425 + struct dentry *h_dentry, struct au_branch *br)
24428 + struct path h_path = {
24429 + .mnt = au_br_mnt(br)
24431 + struct inode *h_dir, *delegated;
24433 + h_dir = d_inode(h_parent);
24434 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
24436 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
24437 + err = PTR_ERR(h_path.dentry);
24438 + if (IS_ERR(h_path.dentry))
24442 + /* wh.plink dir is not monitored */
24443 + /* todo: is it really safe? */
24444 + if (d_is_positive(h_path.dentry)
24445 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
24446 + delegated = NULL;
24447 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
24448 + if (unlikely(err == -EWOULDBLOCK)) {
24449 + pr_warn("cannot retry for NFSv4 delegation"
24450 + " for an internal unlink\n");
24453 + dput(h_path.dentry);
24454 + h_path.dentry = NULL;
24458 + if (!err && d_is_negative(h_path.dentry)) {
24459 + delegated = NULL;
24460 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
24461 + if (unlikely(err == -EWOULDBLOCK)) {
24462 + pr_warn("cannot retry for NFSv4 delegation"
24463 + " for an internal link\n");
24467 + dput(h_path.dentry);
24470 + mutex_unlock(&h_dir->i_mutex);
24474 +struct do_whplink_args {
24476 + struct qstr *tgt;
24477 + struct dentry *h_parent;
24478 + struct dentry *h_dentry;
24479 + struct au_branch *br;
24482 +static void call_do_whplink(void *args)
24484 + struct do_whplink_args *a = args;
24485 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
24488 +static int whplink(struct dentry *h_dentry, struct inode *inode,
24489 + aufs_bindex_t bindex, struct au_branch *br)
24491 + int err, wkq_err;
24492 + struct au_wbr *wbr;
24493 + struct dentry *h_parent;
24494 + char a[PLINK_NAME_LEN];
24495 + struct qstr tgtname = QSTR_INIT(a, 0);
24497 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
24498 + h_parent = wbr->wbr_plink;
24499 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24501 + /* always superio. */
24502 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24503 + struct do_whplink_args args = {
24506 + .h_parent = h_parent,
24507 + .h_dentry = h_dentry,
24510 + wkq_err = au_wkq_wait(call_do_whplink, &args);
24511 + if (unlikely(wkq_err))
24514 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
24519 +/* free a single plink */
24520 +static void do_put_plink(struct pseudo_link *plink, int do_del)
24523 + hlist_del(&plink->hlist);
24524 + iput(plink->inode);
24528 +static void do_put_plink_rcu(struct rcu_head *rcu)
24530 + struct pseudo_link *plink;
24532 + plink = container_of(rcu, struct pseudo_link, rcu);
24533 + iput(plink->inode);
24538 + * create a new pseudo-link for @h_dentry on @bindex.
24539 + * the linked inode is held in aufs @inode.
24541 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
24542 + struct dentry *h_dentry)
24544 + struct super_block *sb;
24545 + struct au_sbinfo *sbinfo;
24546 + struct hlist_head *plink_hlist;
24547 + struct pseudo_link *plink, *tmp;
24548 + struct au_sphlhead *sphl;
24549 + int found, err, cnt, i;
24551 + sb = inode->i_sb;
24552 + sbinfo = au_sbi(sb);
24553 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24554 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24556 + found = au_plink_test(inode);
24560 + i = au_plink_hash(inode->i_ino);
24561 + sphl = sbinfo->si_plink + i;
24562 + plink_hlist = &sphl->head;
24563 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
24565 + tmp->inode = au_igrab(inode);
24571 + spin_lock(&sphl->spin);
24572 + hlist_for_each_entry(plink, plink_hlist, hlist) {
24573 + if (plink->inode == inode) {
24579 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
24580 + spin_unlock(&sphl->spin);
24582 + cnt = au_sphl_count(sphl);
24583 +#define msg "unexpectedly unblanced or too many pseudo-links"
24584 + if (cnt > AUFS_PLINK_WARN)
24585 + AuWarn1(msg ", %d\n", cnt);
24587 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
24589 + do_put_plink(tmp, 0);
24594 + if (unlikely(err)) {
24595 + pr_warn("err %d, damaged pseudo link.\n", err);
24597 + au_sphl_del_rcu(&tmp->hlist, sphl);
24598 + call_rcu(&tmp->rcu, do_put_plink_rcu);
24603 +/* free all plinks */
24604 +void au_plink_put(struct super_block *sb, int verbose)
24607 + struct au_sbinfo *sbinfo;
24608 + struct hlist_head *plink_hlist;
24609 + struct hlist_node *tmp;
24610 + struct pseudo_link *plink;
24612 + SiMustWriteLock(sb);
24614 + sbinfo = au_sbi(sb);
24615 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24616 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24618 + /* no spin_lock since sbinfo is write-locked */
24620 + for (i = 0; i < AuPlink_NHASH; i++) {
24621 + plink_hlist = &sbinfo->si_plink[i].head;
24622 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
24623 + pr_warn("pseudo-link is not flushed");
24626 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
24627 + do_put_plink(plink, 0);
24628 + INIT_HLIST_HEAD(plink_hlist);
24632 +void au_plink_clean(struct super_block *sb, int verbose)
24634 + struct dentry *root;
24636 + root = sb->s_root;
24637 + aufs_write_lock(root);
24638 + if (au_opt_test(au_mntflags(sb), PLINK))
24639 + au_plink_put(sb, verbose);
24640 + aufs_write_unlock(root);
24643 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
24646 + aufs_bindex_t bstart, bend, bindex;
24649 + bstart = au_ibstart(inode);
24650 + bend = au_ibend(inode);
24651 + if (bstart >= 0) {
24652 + for (bindex = bstart; bindex <= bend; bindex++) {
24653 + if (!au_h_iptr(inode, bindex)
24654 + || au_ii_br_id(inode, bindex) != br_id)
24656 + au_set_h_iptr(inode, bindex, NULL, 0);
24661 + for (bindex = bstart; bindex <= bend; bindex++)
24662 + if (au_h_iptr(inode, bindex)) {
24672 +/* free the plinks on a branch specified by @br_id */
24673 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
24675 + struct au_sbinfo *sbinfo;
24676 + struct hlist_head *plink_hlist;
24677 + struct hlist_node *tmp;
24678 + struct pseudo_link *plink;
24679 + struct inode *inode;
24682 + SiMustWriteLock(sb);
24684 + sbinfo = au_sbi(sb);
24685 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24686 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24688 + /* no spin_lock since sbinfo is write-locked */
24689 + for (i = 0; i < AuPlink_NHASH; i++) {
24690 + plink_hlist = &sbinfo->si_plink[i].head;
24691 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
24692 + inode = au_igrab(plink->inode);
24693 + ii_write_lock_child(inode);
24694 + do_put = au_plink_do_half_refresh(inode, br_id);
24696 + do_put_plink(plink, 1);
24697 + ii_write_unlock(inode);
24702 diff -urNp -x '*.orig' linux-4.4/fs/aufs/poll.c linux-4.4/fs/aufs/poll.c
24703 --- linux-4.4/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
24704 +++ linux-4.4/fs/aufs/poll.c 2021-02-24 17:28:14.412141719 +0100
24707 + * Copyright (C) 2005-2016 Junjiro R. Okajima
24709 + * This program, aufs is free software; you can redistribute it and/or modify
24710 + * it under the terms of the GNU General Public License as published by
24711 + * the Free Software Foundation; either version 2 of the License, or
24712 + * (at your option) any later version.
24714 + * This program is distributed in the hope that it will be useful,
24715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24717 + * GNU General Public License for more details.
24719 + * You should have received a copy of the GNU General Public License
24720 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24725 + * There is only one filesystem which implements ->poll operation, currently.
24730 +unsigned int aufs_poll(struct file *file, poll_table *wait)
24732 + unsigned int mask;
24734 + struct file *h_file;
24735 + struct super_block *sb;
24737 + /* We should pretend an error happened. */
24738 + mask = POLLERR /* | POLLIN | POLLOUT */;
24739 + sb = file->f_path.dentry->d_sb;
24740 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
24742 + h_file = au_read_pre(file, /*keep_fi*/0);
24743 + err = PTR_ERR(h_file);
24744 + if (IS_ERR(h_file))
24747 + /* it is not an error if h_file has no operation */
24748 + mask = DEFAULT_POLLMASK;
24749 + if (h_file->f_op->poll)
24750 + mask = h_file->f_op->poll(h_file, wait);
24751 + fput(h_file); /* instead of au_read_post() */
24754 + si_read_unlock(sb);
24755 + AuTraceErr((int)mask);
24758 diff -urNp -x '*.orig' linux-4.4/fs/aufs/posix_acl.c linux-4.4/fs/aufs/posix_acl.c
24759 --- linux-4.4/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
24760 +++ linux-4.4/fs/aufs/posix_acl.c 2021-02-24 17:28:14.412141719 +0100
24763 + * Copyright (C) 2014-2016 Junjiro R. Okajima
24765 + * This program, aufs is free software; you can redistribute it and/or modify
24766 + * it under the terms of the GNU General Public License as published by
24767 + * the Free Software Foundation; either version 2 of the License, or
24768 + * (at your option) any later version.
24770 + * This program is distributed in the hope that it will be useful,
24771 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24772 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24773 + * GNU General Public License for more details.
24775 + * You should have received a copy of the GNU General Public License
24776 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24780 + * posix acl operations
24783 +#include <linux/fs.h>
24786 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
24788 + struct posix_acl *acl;
24790 + aufs_bindex_t bindex;
24791 + struct inode *h_inode;
24792 + struct super_block *sb;
24795 + sb = inode->i_sb;
24796 + si_read_lock(sb, AuLock_FLUSH);
24797 + ii_read_lock_child(inode);
24798 + if (!(sb->s_flags & MS_POSIXACL))
24801 + bindex = au_ibstart(inode);
24802 + h_inode = au_h_iptr(inode, bindex);
24803 + if (unlikely(!h_inode
24804 + || ((h_inode->i_mode & S_IFMT)
24805 + != (inode->i_mode & S_IFMT)))) {
24806 + err = au_busy_or_stale();
24807 + acl = ERR_PTR(err);
24811 + /* always topmost only */
24812 + acl = get_acl(h_inode, type);
24815 + ii_read_unlock(inode);
24816 + si_read_unlock(sb);
24818 + AuTraceErrPtr(acl);
24822 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
24826 + struct dentry *dentry;
24827 + struct au_srxattr arg = {
24828 + .type = AU_ACL_SET,
24835 + mutex_lock(&inode->i_mutex);
24836 + if (inode->i_ino == AUFS_ROOT_INO)
24837 + dentry = dget(inode->i_sb->s_root);
24839 + dentry = d_find_alias(inode);
24841 + dentry = d_find_any_alias(inode);
24843 + pr_warn("cannot handle this inode, "
24844 + "please report to aufs-users ML\n");
24850 + ssz = au_srxattr(dentry, &arg);
24857 + mutex_unlock(&inode->i_mutex);
24860 diff -urNp -x '*.orig' linux-4.4/fs/aufs/procfs.c linux-4.4/fs/aufs/procfs.c
24861 --- linux-4.4/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
24862 +++ linux-4.4/fs/aufs/procfs.c 2021-02-24 17:28:14.412141719 +0100
24865 + * Copyright (C) 2010-2016 Junjiro R. Okajima
24867 + * This program, aufs is free software; you can redistribute it and/or modify
24868 + * it under the terms of the GNU General Public License as published by
24869 + * the Free Software Foundation; either version 2 of the License, or
24870 + * (at your option) any later version.
24872 + * This program is distributed in the hope that it will be useful,
24873 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24874 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24875 + * GNU General Public License for more details.
24877 + * You should have received a copy of the GNU General Public License
24878 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24882 + * procfs interfaces
24885 +#include <linux/proc_fs.h>
24888 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
24890 + struct au_sbinfo *sbinfo;
24892 + sbinfo = file->private_data;
24894 + au_plink_maint_leave(sbinfo);
24895 + kobject_put(&sbinfo->si_kobj);
24901 +static void au_procfs_plm_write_clean(struct file *file)
24903 + struct au_sbinfo *sbinfo;
24905 + sbinfo = file->private_data;
24907 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
24910 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
24913 + struct super_block *sb;
24914 + struct au_sbinfo *sbinfo;
24917 + if (unlikely(file->private_data))
24921 + /* don't use au_sbilist_lock() here */
24922 + spin_lock(&au_sbilist.spin);
24923 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
24924 + if (id == sysaufs_si_id(sbinfo)) {
24925 + kobject_get(&sbinfo->si_kobj);
24926 + sb = sbinfo->si_sb;
24929 + spin_unlock(&au_sbilist.spin);
24932 + if (unlikely(!sb))
24935 + err = au_plink_maint_enter(sb);
24937 + /* keep kobject_get() */
24938 + file->private_data = sbinfo;
24940 + kobject_put(&sbinfo->si_kobj);
24946 + * Accept a valid "si=xxxx" only.
24947 + * Once it is accepted successfully, accept "clean" too.
24949 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
24950 + size_t count, loff_t *ppos)
24953 + unsigned long id;
24954 + /* last newline is allowed */
24955 + char buf[3 + sizeof(unsigned long) * 2 + 1];
24958 + if (unlikely(!capable(CAP_SYS_ADMIN)))
24962 + if (unlikely(count > sizeof(buf)))
24965 + err = copy_from_user(buf, ubuf, count);
24966 + if (unlikely(err)) {
24973 + if (!strcmp("clean", buf)) {
24974 + au_procfs_plm_write_clean(file);
24975 + goto out_success;
24976 + } else if (unlikely(strncmp("si=", buf, 3)))
24979 + err = kstrtoul(buf + 3, 16, &id);
24980 + if (unlikely(err))
24983 + err = au_procfs_plm_write_si(file, id);
24984 + if (unlikely(err))
24988 + err = count; /* success */
24993 +static const struct file_operations au_procfs_plm_fop = {
24994 + .write = au_procfs_plm_write,
24995 + .release = au_procfs_plm_release,
24996 + .owner = THIS_MODULE
24999 +/* ---------------------------------------------------------------------- */
25001 +static struct proc_dir_entry *au_procfs_dir;
25003 +void au_procfs_fin(void)
25005 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25006 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25009 +int __init au_procfs_init(void)
25012 + struct proc_dir_entry *entry;
25015 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25016 + if (unlikely(!au_procfs_dir))
25019 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25020 + au_procfs_dir, &au_procfs_plm_fop);
25021 + if (unlikely(!entry))
25025 + goto out; /* success */
25029 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25033 diff -urNp -x '*.orig' linux-4.4/fs/aufs/rdu.c linux-4.4/fs/aufs/rdu.c
25034 --- linux-4.4/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25035 +++ linux-4.4/fs/aufs/rdu.c 2021-02-24 17:28:14.412141719 +0100
25038 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25040 + * This program, aufs is free software; you can redistribute it and/or modify
25041 + * it under the terms of the GNU General Public License as published by
25042 + * the Free Software Foundation; either version 2 of the License, or
25043 + * (at your option) any later version.
25045 + * This program is distributed in the hope that it will be useful,
25046 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25047 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25048 + * GNU General Public License for more details.
25050 + * You should have received a copy of the GNU General Public License
25051 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25055 + * readdir in userspace.
25058 +#include <linux/compat.h>
25059 +#include <linux/fs_stack.h>
25060 +#include <linux/security.h>
25063 +/* bits for struct aufs_rdu.flags */
25064 +#define AuRdu_CALLED 1
25065 +#define AuRdu_CONT (1 << 1)
25066 +#define AuRdu_FULL (1 << 2)
25067 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25068 +#define au_fset_rdu(flags, name) \
25069 + do { (flags) |= AuRdu_##name; } while (0)
25070 +#define au_fclr_rdu(flags, name) \
25071 + do { (flags) &= ~AuRdu_##name; } while (0)
25073 +struct au_rdu_arg {
25074 + struct dir_context ctx;
25075 + struct aufs_rdu *rdu;
25076 + union au_rdu_ent_ul ent;
25077 + unsigned long end;
25079 + struct super_block *sb;
25083 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25084 + loff_t offset, u64 h_ino, unsigned int d_type)
25087 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25088 + struct aufs_rdu *rdu = arg->rdu;
25089 + struct au_rdu_ent ent;
25093 + au_fset_rdu(rdu->cookie.flags, CALLED);
25094 + len = au_rdu_len(nlen);
25095 + if (arg->ent.ul + len < arg->end) {
25097 + ent.bindex = rdu->cookie.bindex;
25098 + ent.type = d_type;
25100 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25101 + ent.type = DT_UNKNOWN;
25103 + /* unnecessary to support mmap_sem since this is a dir */
25105 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25107 + if (copy_to_user(arg->ent.e->name, name, nlen))
25109 + /* the terminating NULL */
25110 + if (__put_user(0, arg->ent.e->name + nlen))
25113 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25114 + arg->ent.ul += len;
25118 + au_fset_rdu(rdu->cookie.flags, FULL);
25120 + rdu->tail = arg->ent;
25124 + /* AuTraceErr(err); */
25128 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25132 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25134 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25135 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25137 + if (unlikely(offset != cookie->h_pos))
25143 + au_fclr_rdu(cookie->flags, CALLED);
25145 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25149 + && au_ftest_rdu(cookie->flags, CALLED)
25150 + && !au_ftest_rdu(cookie->flags, FULL));
25151 + cookie->h_pos = h_file->f_pos;
25158 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25161 + aufs_bindex_t bend;
25162 + struct au_rdu_arg arg = {
25164 + .actor = au_rdu_fill
25167 + struct dentry *dentry;
25168 + struct inode *inode;
25169 + struct file *h_file;
25170 + struct au_rdu_cookie *cookie = &rdu->cookie;
25172 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25173 + if (unlikely(err)) {
25179 + rdu->tail = rdu->ent;
25182 + arg.ent = rdu->ent;
25183 + arg.end = arg.ent.ul;
25184 + arg.end += rdu->sz;
25187 + if (unlikely(!file->f_op->iterate))
25190 + err = security_file_permission(file, MAY_READ);
25192 + if (unlikely(err))
25195 + dentry = file->f_path.dentry;
25196 + inode = d_inode(dentry);
25198 + mutex_lock(&inode->i_mutex);
25200 + err = mutex_lock_killable(&inode->i_mutex);
25202 + if (unlikely(err))
25206 + arg.sb = inode->i_sb;
25207 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25208 + if (unlikely(err))
25210 + err = au_alive_dir(dentry);
25211 + if (unlikely(err))
25213 + /* todo: reval? */
25214 + fi_read_lock(file);
25217 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25218 + && cookie->generation != au_figen(file)))
25223 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25225 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25227 + bend = au_fbstart(file);
25228 + if (cookie->bindex < bend)
25229 + cookie->bindex = bend;
25230 + bend = au_fbend_dir(file);
25231 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25232 + for (; !err && cookie->bindex <= bend;
25233 + cookie->bindex++, cookie->h_pos = 0) {
25234 + h_file = au_hf_dir(file, cookie->bindex);
25238 + au_fclr_rdu(cookie->flags, FULL);
25239 + err = au_rdu_do(h_file, &arg);
25241 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25244 + AuDbg("rent %llu\n", rdu->rent);
25246 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25247 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25248 + au_fset_rdu(cookie->flags, CONT);
25249 + cookie->generation = au_figen(file);
25252 + ii_read_lock_child(inode);
25253 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25254 + ii_read_unlock(inode);
25257 + fi_read_unlock(file);
25259 + si_read_unlock(arg.sb);
25261 + mutex_unlock(&inode->i_mutex);
25267 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25271 + unsigned long long nent;
25272 + union au_rdu_ent_ul *u;
25273 + struct au_rdu_ent ent;
25274 + struct super_block *sb;
25277 + nent = rdu->nent;
25279 + sb = file->f_path.dentry->d_sb;
25280 + si_read_lock(sb, AuLock_FLUSH);
25281 + while (nent-- > 0) {
25282 + /* unnecessary to support mmap_sem since this is a dir */
25283 + err = copy_from_user(&ent, u->e, sizeof(ent));
25285 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25286 + if (unlikely(err)) {
25292 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25294 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25296 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25298 + if (unlikely(err)) {
25303 + err = __put_user(ino, &u->e->ino);
25304 + if (unlikely(err)) {
25309 + u->ul += au_rdu_len(ent.nlen);
25311 + si_read_unlock(sb);
25316 +/* ---------------------------------------------------------------------- */
25318 +static int au_rdu_verify(struct aufs_rdu *rdu)
25320 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
25321 + "%llu, b%d, 0x%x, g%u}\n",
25322 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
25324 + rdu->rent, rdu->shwh, rdu->full,
25325 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
25326 + rdu->cookie.generation);
25328 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
25332 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
25336 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25339 + struct aufs_rdu rdu;
25340 + void __user *p = (void __user *)arg;
25342 + err = copy_from_user(&rdu, p, sizeof(rdu));
25343 + if (unlikely(err)) {
25348 + err = au_rdu_verify(&rdu);
25349 + if (unlikely(err))
25353 + case AUFS_CTL_RDU:
25354 + err = au_rdu(file, &rdu);
25355 + if (unlikely(err))
25358 + e = copy_to_user(p, &rdu, sizeof(rdu));
25359 + if (unlikely(e)) {
25364 + case AUFS_CTL_RDU_INO:
25365 + err = au_rdu_ino(file, &rdu);
25369 + /* err = -ENOTTY; */
25378 +#ifdef CONFIG_COMPAT
25379 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25382 + struct aufs_rdu rdu;
25383 + void __user *p = compat_ptr(arg);
25385 + /* todo: get_user()? */
25386 + err = copy_from_user(&rdu, p, sizeof(rdu));
25387 + if (unlikely(err)) {
25392 + rdu.ent.e = compat_ptr(rdu.ent.ul);
25393 + err = au_rdu_verify(&rdu);
25394 + if (unlikely(err))
25398 + case AUFS_CTL_RDU:
25399 + err = au_rdu(file, &rdu);
25400 + if (unlikely(err))
25403 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
25404 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
25405 + e = copy_to_user(p, &rdu, sizeof(rdu));
25406 + if (unlikely(e)) {
25411 + case AUFS_CTL_RDU_INO:
25412 + err = au_rdu_ino(file, &rdu);
25416 + /* err = -ENOTTY; */
25425 diff -urNp -x '*.orig' linux-4.4/fs/aufs/rwsem.h linux-4.4/fs/aufs/rwsem.h
25426 --- linux-4.4/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
25427 +++ linux-4.4/fs/aufs/rwsem.h 2021-02-24 17:28:14.412141719 +0100
25430 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25432 + * This program, aufs is free software; you can redistribute it and/or modify
25433 + * it under the terms of the GNU General Public License as published by
25434 + * the Free Software Foundation; either version 2 of the License, or
25435 + * (at your option) any later version.
25437 + * This program is distributed in the hope that it will be useful,
25438 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25439 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25440 + * GNU General Public License for more details.
25442 + * You should have received a copy of the GNU General Public License
25443 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25447 + * simple read-write semaphore wrappers
25450 +#ifndef __AUFS_RWSEM_H__
25451 +#define __AUFS_RWSEM_H__
25455 +#include "debug.h"
25458 + struct rw_semaphore rwsem;
25459 +#ifdef CONFIG_AUFS_DEBUG
25460 + /* just for debugging, not almighty counter */
25461 + atomic_t rcnt, wcnt;
25465 +#ifdef CONFIG_AUFS_DEBUG
25466 +#define AuDbgCntInit(rw) do { \
25467 + atomic_set(&(rw)->rcnt, 0); \
25468 + atomic_set(&(rw)->wcnt, 0); \
25469 + smp_mb(); /* atomic set */ \
25472 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
25473 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
25474 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
25475 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
25477 +#define AuDbgCntInit(rw) do {} while (0)
25478 +#define AuDbgRcntInc(rw) do {} while (0)
25479 +#define AuDbgRcntDec(rw) do {} while (0)
25480 +#define AuDbgWcntInc(rw) do {} while (0)
25481 +#define AuDbgWcntDec(rw) do {} while (0)
25482 +#endif /* CONFIG_AUFS_DEBUG */
25484 +/* to debug easier, do not make them inlined functions */
25485 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
25486 +/* rwsem_is_locked() is unusable */
25487 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
25488 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
25489 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
25490 + && atomic_read(&(rw)->wcnt) <= 0)
25491 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
25492 + || atomic_read(&(rw)->wcnt))
25494 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
25496 +static inline void au_rw_init(struct au_rwsem *rw)
25498 + AuDbgCntInit(rw);
25499 + init_rwsem(&rw->rwsem);
25502 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
25505 + down_write(&rw->rwsem);
25506 + AuDbgWcntInc(rw);
25509 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
25510 + unsigned int lsc)
25513 + down_write_nested(&rw->rwsem, lsc);
25514 + AuDbgWcntInc(rw);
25517 +static inline void au_rw_read_lock(struct au_rwsem *rw)
25519 + down_read(&rw->rwsem);
25520 + AuDbgRcntInc(rw);
25523 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
25525 + down_read_nested(&rw->rwsem, lsc);
25526 + AuDbgRcntInc(rw);
25529 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
25531 + AuRwMustReadLock(rw);
25532 + AuDbgRcntDec(rw);
25533 + up_read(&rw->rwsem);
25536 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
25538 + AuRwMustWriteLock(rw);
25539 + AuDbgRcntInc(rw);
25540 + AuDbgWcntDec(rw);
25541 + downgrade_write(&rw->rwsem);
25544 +static inline void au_rw_write_lock(struct au_rwsem *rw)
25546 + down_write(&rw->rwsem);
25547 + AuDbgWcntInc(rw);
25550 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
25551 + unsigned int lsc)
25553 + down_write_nested(&rw->rwsem, lsc);
25554 + AuDbgWcntInc(rw);
25557 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
25559 + AuRwMustWriteLock(rw);
25560 + AuDbgWcntDec(rw);
25561 + up_write(&rw->rwsem);
25564 +/* why is not _nested version defined */
25565 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
25569 + ret = down_read_trylock(&rw->rwsem);
25571 + AuDbgRcntInc(rw);
25575 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
25579 + ret = down_write_trylock(&rw->rwsem);
25581 + AuDbgWcntInc(rw);
25585 +#undef AuDbgCntInit
25586 +#undef AuDbgRcntInc
25587 +#undef AuDbgRcntDec
25588 +#undef AuDbgWcntInc
25589 +#undef AuDbgWcntDec
25591 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25592 +static inline void prefix##_read_lock(param) \
25593 +{ au_rw_read_lock(rwsem); } \
25594 +static inline void prefix##_write_lock(param) \
25595 +{ au_rw_write_lock(rwsem); } \
25596 +static inline int prefix##_read_trylock(param) \
25597 +{ return au_rw_read_trylock(rwsem); } \
25598 +static inline int prefix##_write_trylock(param) \
25599 +{ return au_rw_write_trylock(rwsem); }
25600 +/* why is not _nested version defined */
25601 +/* static inline void prefix##_read_trylock_nested(param, lsc)
25602 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
25603 +static inline void prefix##_write_trylock_nestd(param, lsc)
25604 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
25606 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
25607 +static inline void prefix##_read_unlock(param) \
25608 +{ au_rw_read_unlock(rwsem); } \
25609 +static inline void prefix##_write_unlock(param) \
25610 +{ au_rw_write_unlock(rwsem); } \
25611 +static inline void prefix##_downgrade_lock(param) \
25612 +{ au_rw_dgrade_lock(rwsem); }
25614 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
25615 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25616 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
25618 +#endif /* __KERNEL__ */
25619 +#endif /* __AUFS_RWSEM_H__ */
25620 diff -urNp -x '*.orig' linux-4.4/fs/aufs/sbinfo.c linux-4.4/fs/aufs/sbinfo.c
25621 --- linux-4.4/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
25622 +++ linux-4.4/fs/aufs/sbinfo.c 2021-02-24 17:28:14.412141719 +0100
25625 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25627 + * This program, aufs is free software; you can redistribute it and/or modify
25628 + * it under the terms of the GNU General Public License as published by
25629 + * the Free Software Foundation; either version 2 of the License, or
25630 + * (at your option) any later version.
25632 + * This program is distributed in the hope that it will be useful,
25633 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25635 + * GNU General Public License for more details.
25637 + * You should have received a copy of the GNU General Public License
25638 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25642 + * superblock private data
25648 + * they are necessary regardless sysfs is disabled.
25650 +void au_si_free(struct kobject *kobj)
25653 + struct au_sbinfo *sbinfo;
25654 + char *locked __maybe_unused; /* debug only */
25656 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
25657 + for (i = 0; i < AuPlink_NHASH; i++)
25658 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
25659 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
25661 + AuDebugOn(!hlist_empty(&sbinfo->si_symlink.head));
25663 + au_rw_write_lock(&sbinfo->si_rwsem);
25664 + au_br_free(sbinfo);
25665 + au_rw_write_unlock(&sbinfo->si_rwsem);
25667 + AuDebugOn(radix_tree_gang_lookup
25668 + (&sbinfo->au_si_pid.tree, (void **)&locked,
25669 + /*first_index*/PID_MAX_DEFAULT - 1,
25670 + /*max_items*/sizeof(locked)/sizeof(*locked)));
25672 + kfree(sbinfo->si_branch);
25673 + kfree(sbinfo->au_si_pid.bitmap);
25674 + mutex_destroy(&sbinfo->si_xib_mtx);
25675 + AuRwDestroy(&sbinfo->si_rwsem);
25680 +int au_si_alloc(struct super_block *sb)
25683 + struct au_sbinfo *sbinfo;
25684 + static struct lock_class_key aufs_si;
25687 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
25688 + if (unlikely(!sbinfo))
25691 + BUILD_BUG_ON(sizeof(unsigned long) !=
25692 + sizeof(*sbinfo->au_si_pid.bitmap));
25693 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
25694 + sizeof(*sbinfo->au_si_pid.bitmap),
25696 + if (unlikely(!sbinfo->au_si_pid.bitmap))
25699 + /* will be reallocated separately */
25700 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
25701 + if (unlikely(!sbinfo->si_branch))
25704 + err = sysaufs_si_init(sbinfo);
25705 + if (unlikely(err))
25708 + au_nwt_init(&sbinfo->si_nowait);
25709 + au_rw_init_wlock(&sbinfo->si_rwsem);
25710 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
25711 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
25712 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
25714 + atomic_long_set(&sbinfo->si_ninodes, 0);
25715 + atomic_long_set(&sbinfo->si_nfiles, 0);
25717 + sbinfo->si_bend = -1;
25718 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
25720 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
25721 + sbinfo->si_wbr_create = AuWbrCreate_Def;
25722 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
25723 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
25725 + au_fhsm_init(sbinfo);
25727 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
25729 + au_sphl_init(&sbinfo->si_symlink);
25731 + sbinfo->si_xino_jiffy = jiffies;
25732 + sbinfo->si_xino_expire
25733 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
25734 + mutex_init(&sbinfo->si_xib_mtx);
25735 + sbinfo->si_xino_brid = -1;
25736 + /* leave si_xib_last_pindex and si_xib_next_bit */
25738 + au_sphl_init(&sbinfo->si_aopen);
25740 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
25741 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
25742 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
25743 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
25745 + for (i = 0; i < AuPlink_NHASH; i++)
25746 + au_sphl_init(sbinfo->si_plink + i);
25747 + init_waitqueue_head(&sbinfo->si_plink_wq);
25748 + spin_lock_init(&sbinfo->si_plink_maint_lock);
25750 + au_sphl_init(&sbinfo->si_files);
25752 + /* with getattr by default */
25753 + sbinfo->si_iop_array = aufs_iop;
25755 + /* leave other members for sysaufs and si_mnt. */
25756 + sbinfo->si_sb = sb;
25757 + sb->s_fs_info = sbinfo;
25759 + return 0; /* success */
25762 + kfree(sbinfo->si_branch);
25764 + kfree(sbinfo->au_si_pid.bitmap);
25771 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
25774 + struct au_branch **brp;
25776 + AuRwMustWriteLock(&sbinfo->si_rwsem);
25779 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
25780 + if (unlikely(!sz))
25781 + sz = sizeof(*brp);
25782 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
25784 + sbinfo->si_branch = brp;
25791 +/* ---------------------------------------------------------------------- */
25793 +unsigned int au_sigen_inc(struct super_block *sb)
25795 + unsigned int gen;
25796 + struct inode *inode;
25798 + SiMustWriteLock(sb);
25800 + gen = ++au_sbi(sb)->si_generation;
25801 + au_update_digen(sb->s_root);
25802 + inode = d_inode(sb->s_root);
25803 + au_update_iigen(inode, /*half*/0);
25804 + inode->i_version++;
25808 +aufs_bindex_t au_new_br_id(struct super_block *sb)
25810 + aufs_bindex_t br_id;
25812 + struct au_sbinfo *sbinfo;
25814 + SiMustWriteLock(sb);
25816 + sbinfo = au_sbi(sb);
25817 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
25818 + br_id = ++sbinfo->si_last_br_id;
25819 + AuDebugOn(br_id < 0);
25820 + if (br_id && au_br_index(sb, br_id) < 0)
25827 +/* ---------------------------------------------------------------------- */
25829 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
25830 +int si_read_lock(struct super_block *sb, int flags)
25835 + if (au_ftest_lock(flags, FLUSH))
25836 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25838 + si_noflush_read_lock(sb);
25839 + err = au_plink_maint(sb, flags);
25840 + if (unlikely(err))
25841 + si_read_unlock(sb);
25846 +int si_write_lock(struct super_block *sb, int flags)
25850 + if (au_ftest_lock(flags, FLUSH))
25851 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25853 + si_noflush_write_lock(sb);
25854 + err = au_plink_maint(sb, flags);
25855 + if (unlikely(err))
25856 + si_write_unlock(sb);
25861 +/* dentry and super_block lock. call at entry point */
25862 +int aufs_read_lock(struct dentry *dentry, int flags)
25865 + struct super_block *sb;
25867 + sb = dentry->d_sb;
25868 + err = si_read_lock(sb, flags);
25869 + if (unlikely(err))
25872 + if (au_ftest_lock(flags, DW))
25873 + di_write_lock_child(dentry);
25875 + di_read_lock_child(dentry, flags);
25877 + if (au_ftest_lock(flags, GEN)) {
25878 + err = au_digen_test(dentry, au_sigen(sb));
25879 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
25880 + AuDebugOn(!err && au_dbrange_test(dentry));
25882 + err = au_dbrange_test(dentry);
25883 + if (unlikely(err))
25884 + aufs_read_unlock(dentry, flags);
25891 +void aufs_read_unlock(struct dentry *dentry, int flags)
25893 + if (au_ftest_lock(flags, DW))
25894 + di_write_unlock(dentry);
25896 + di_read_unlock(dentry, flags);
25897 + si_read_unlock(dentry->d_sb);
25900 +void aufs_write_lock(struct dentry *dentry)
25902 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
25903 + di_write_lock_child(dentry);
25906 +void aufs_write_unlock(struct dentry *dentry)
25908 + di_write_unlock(dentry);
25909 + si_write_unlock(dentry->d_sb);
25912 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
25915 + unsigned int sigen;
25916 + struct super_block *sb;
25919 + err = si_read_lock(sb, flags);
25920 + if (unlikely(err))
25923 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
25925 + if (au_ftest_lock(flags, GEN)) {
25926 + sigen = au_sigen(sb);
25927 + err = au_digen_test(d1, sigen);
25928 + AuDebugOn(!err && au_dbrange_test(d1));
25930 + err = au_digen_test(d2, sigen);
25931 + AuDebugOn(!err && au_dbrange_test(d2));
25933 + if (unlikely(err))
25934 + aufs_read_and_write_unlock2(d1, d2);
25941 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
25943 + di_write_unlock2(d1, d2);
25944 + si_read_unlock(d1->d_sb);
25947 +/* ---------------------------------------------------------------------- */
25949 +int si_pid_test_slow(struct super_block *sb)
25954 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
25955 + rcu_read_unlock();
25957 + return (long)!!p;
25960 +void si_pid_set_slow(struct super_block *sb)
25963 + struct au_sbinfo *sbinfo;
25965 + AuDebugOn(si_pid_test_slow(sb));
25967 + sbinfo = au_sbi(sb);
25968 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
25970 + spin_lock(&sbinfo->au_si_pid.tree_lock);
25971 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
25972 + /*any valid ptr*/sb);
25973 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
25975 + radix_tree_preload_end();
25978 +void si_pid_clr_slow(struct super_block *sb)
25981 + struct au_sbinfo *sbinfo;
25983 + AuDebugOn(!si_pid_test_slow(sb));
25985 + sbinfo = au_sbi(sb);
25986 + spin_lock(&sbinfo->au_si_pid.tree_lock);
25987 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
25988 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
25990 diff -urNp -x '*.orig' linux-4.4/fs/aufs/spl.h linux-4.4/fs/aufs/spl.h
25991 --- linux-4.4/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
25992 +++ linux-4.4/fs/aufs/spl.h 2021-02-24 17:28:14.412141719 +0100
25995 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25997 + * This program, aufs is free software; you can redistribute it and/or modify
25998 + * it under the terms of the GNU General Public License as published by
25999 + * the Free Software Foundation; either version 2 of the License, or
26000 + * (at your option) any later version.
26002 + * This program is distributed in the hope that it will be useful,
26003 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26004 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26005 + * GNU General Public License for more details.
26007 + * You should have received a copy of the GNU General Public License
26008 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26012 + * simple list protected by a spinlock
26015 +#ifndef __AUFS_SPL_H__
26016 +#define __AUFS_SPL_H__
26020 +struct au_splhead {
26022 + struct list_head head;
26025 +static inline void au_spl_init(struct au_splhead *spl)
26027 + spin_lock_init(&spl->spin);
26028 + INIT_LIST_HEAD(&spl->head);
26031 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26033 + spin_lock(&spl->spin);
26034 + list_add(list, &spl->head);
26035 + spin_unlock(&spl->spin);
26038 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26040 + spin_lock(&spl->spin);
26042 + spin_unlock(&spl->spin);
26045 +static inline void au_spl_del_rcu(struct list_head *list,
26046 + struct au_splhead *spl)
26048 + spin_lock(&spl->spin);
26049 + list_del_rcu(list);
26050 + spin_unlock(&spl->spin);
26053 +/* ---------------------------------------------------------------------- */
26055 +struct au_sphlhead {
26057 + struct hlist_head head;
26060 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26062 + spin_lock_init(&sphl->spin);
26063 + INIT_HLIST_HEAD(&sphl->head);
26066 +static inline void au_sphl_add(struct hlist_node *hlist,
26067 + struct au_sphlhead *sphl)
26069 + spin_lock(&sphl->spin);
26070 + hlist_add_head(hlist, &sphl->head);
26071 + spin_unlock(&sphl->spin);
26074 +static inline void au_sphl_del(struct hlist_node *hlist,
26075 + struct au_sphlhead *sphl)
26077 + spin_lock(&sphl->spin);
26078 + hlist_del(hlist);
26079 + spin_unlock(&sphl->spin);
26082 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26083 + struct au_sphlhead *sphl)
26085 + spin_lock(&sphl->spin);
26086 + hlist_del_rcu(hlist);
26087 + spin_unlock(&sphl->spin);
26090 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26092 + unsigned long cnt;
26093 + struct hlist_node *pos;
26096 + spin_lock(&sphl->spin);
26097 + hlist_for_each(pos, &sphl->head)
26099 + spin_unlock(&sphl->spin);
26103 +#endif /* __KERNEL__ */
26104 +#endif /* __AUFS_SPL_H__ */
26105 diff -urNp -x '*.orig' linux-4.4/fs/aufs/super.c linux-4.4/fs/aufs/super.c
26106 --- linux-4.4/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26107 +++ linux-4.4/fs/aufs/super.c 2021-02-24 17:28:14.418808602 +0100
26110 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26112 + * This program, aufs is free software; you can redistribute it and/or modify
26113 + * it under the terms of the GNU General Public License as published by
26114 + * the Free Software Foundation; either version 2 of the License, or
26115 + * (at your option) any later version.
26117 + * This program is distributed in the hope that it will be useful,
26118 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26119 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26120 + * GNU General Public License for more details.
26122 + * You should have received a copy of the GNU General Public License
26123 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26127 + * mount and super_block operations
26130 +#include <linux/mm.h>
26131 +#include <linux/seq_file.h>
26132 +#include <linux/statfs.h>
26133 +#include <linux/vmalloc.h>
26137 + * super_operations
26139 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26141 + struct au_icntnr *c;
26143 + c = au_cache_alloc_icntnr();
26145 + au_icntnr_init(c);
26146 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26147 + c->iinfo.ii_hinode = NULL;
26148 + return &c->vfs_inode;
26153 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26155 + struct inode *inode = container_of(head, struct inode, i_rcu);
26157 + INIT_HLIST_HEAD(&inode->i_dentry);
26158 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26161 +static void aufs_destroy_inode(struct inode *inode)
26163 + au_iinfo_fin(inode);
26164 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26167 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26169 + struct inode *inode;
26172 + inode = iget_locked(sb, ino);
26173 + if (unlikely(!inode)) {
26174 + inode = ERR_PTR(-ENOMEM);
26177 + if (!(inode->i_state & I_NEW))
26180 + err = au_xigen_new(inode);
26182 + err = au_iinfo_init(inode);
26184 + inode->i_version++;
26186 + iget_failed(inode);
26187 + inode = ERR_PTR(err);
26191 + /* never return NULL */
26192 + AuDebugOn(!inode);
26193 + AuTraceErrPtr(inode);
26197 +/* lock free root dinfo */
26198 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26201 + aufs_bindex_t bindex, bend;
26202 + struct path path;
26203 + struct au_hdentry *hdp;
26204 + struct au_branch *br;
26205 + au_br_perm_str_t perm;
26208 + bend = au_sbend(sb);
26209 + hdp = au_di(sb->s_root)->di_hdentry;
26210 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26211 + br = au_sbr(sb, bindex);
26212 + path.mnt = au_br_mnt(br);
26213 + path.dentry = hdp[bindex].hd_dentry;
26214 + err = au_seq_path(seq, &path);
26216 + au_optstr_br_perm(&perm, br->br_perm);
26217 + seq_printf(seq, "=%s", perm.a);
26218 + if (bindex != bend)
26219 + seq_putc(seq, ':');
26222 + if (unlikely(err || seq_has_overflowed(seq)))
26228 +static void au_show_wbr_create(struct seq_file *m, int v,
26229 + struct au_sbinfo *sbinfo)
26233 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26235 + seq_puts(m, ",create=");
26236 + pat = au_optstr_wbr_create(v);
26238 + case AuWbrCreate_TDP:
26239 + case AuWbrCreate_RR:
26240 + case AuWbrCreate_MFS:
26241 + case AuWbrCreate_PMFS:
26242 + seq_puts(m, pat);
26244 + case AuWbrCreate_MFSV:
26245 + seq_printf(m, /*pat*/"mfs:%lu",
26246 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26249 + case AuWbrCreate_PMFSV:
26250 + seq_printf(m, /*pat*/"pmfs:%lu",
26251 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26254 + case AuWbrCreate_MFSRR:
26255 + seq_printf(m, /*pat*/"mfsrr:%llu",
26256 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26258 + case AuWbrCreate_MFSRRV:
26259 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26260 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26261 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26264 + case AuWbrCreate_PMFSRR:
26265 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26266 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26268 + case AuWbrCreate_PMFSRRV:
26269 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26270 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26271 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26277 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26279 +#ifdef CONFIG_SYSFS
26283 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26284 + aufs_bindex_t bindex, brid;
26285 + struct qstr *name;
26287 + struct dentry *d, *h_root;
26288 + struct au_hdentry *hdp;
26290 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26293 + f = au_sbi(sb)->si_xib;
26297 + /* stop printing the default xino path on the first writable branch */
26299 + brid = au_xino_brid(sb);
26301 + bindex = au_br_index(sb, brid);
26302 + hdp = au_di(sb->s_root)->di_hdentry;
26303 + h_root = hdp[0 + bindex].hd_dentry;
26305 + d = f->f_path.dentry;
26306 + name = &d->d_name;
26307 + /* safe ->d_parent because the file is unlinked */
26308 + if (d->d_parent == h_root
26309 + && name->len == len
26310 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26313 + seq_puts(seq, ",xino=");
26314 + err = au_xino_path(seq, f);
26321 +/* seq_file will re-call me in case of too long string */
26322 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26325 + unsigned int mnt_flags, v;
26326 + struct super_block *sb;
26327 + struct au_sbinfo *sbinfo;
26329 +#define AuBool(name, str) do { \
26330 + v = au_opt_test(mnt_flags, name); \
26331 + if (v != au_opt_test(AuOpt_Def, name)) \
26332 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
26335 +#define AuStr(name, str) do { \
26336 + v = mnt_flags & AuOptMask_##name; \
26337 + if (v != (AuOpt_Def & AuOptMask_##name)) \
26338 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
26341 +#define AuUInt(name, str, val) do { \
26342 + if (val != AUFS_##name##_DEF) \
26343 + seq_printf(m, "," #str "=%u", val); \
26346 + sb = dentry->d_sb;
26347 + if (sb->s_flags & MS_POSIXACL)
26348 + seq_puts(m, ",acl");
26350 + /* lock free root dinfo */
26351 + si_noflush_read_lock(sb);
26352 + sbinfo = au_sbi(sb);
26353 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
26355 + mnt_flags = au_mntflags(sb);
26356 + if (au_opt_test(mnt_flags, XINO)) {
26357 + err = au_show_xino(m, sb);
26358 + if (unlikely(err))
26361 + seq_puts(m, ",noxino");
26363 + AuBool(TRUNC_XINO, trunc_xino);
26364 + AuStr(UDBA, udba);
26365 + AuBool(SHWH, shwh);
26366 + AuBool(PLINK, plink);
26367 + AuBool(DIO, dio);
26368 + AuBool(DIRPERM1, dirperm1);
26370 + v = sbinfo->si_wbr_create;
26371 + if (v != AuWbrCreate_Def)
26372 + au_show_wbr_create(m, v, sbinfo);
26374 + v = sbinfo->si_wbr_copyup;
26375 + if (v != AuWbrCopyup_Def)
26376 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
26378 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
26379 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
26380 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
26382 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
26384 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
26385 + AuUInt(RDCACHE, rdcache, v);
26387 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
26388 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
26390 + au_fhsm_show(m, sbinfo);
26392 + AuBool(SUM, sum);
26393 + /* AuBool(SUM_W, wsum); */
26394 + AuBool(WARN_PERM, warn_perm);
26395 + AuBool(VERBOSE, verbose);
26398 + /* be sure to print "br:" last */
26399 + if (!sysaufs_brs) {
26400 + seq_puts(m, ",br:");
26401 + au_show_brs(m, sb);
26403 + si_read_unlock(sb);
26411 +/* ---------------------------------------------------------------------- */
26413 +/* sum mode which returns the summation for statfs(2) */
26415 +static u64 au_add_till_max(u64 a, u64 b)
26423 + return ULLONG_MAX;
26426 +static u64 au_mul_till_max(u64 a, long mul)
26434 + return ULLONG_MAX;
26437 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
26440 + long bsize, factor;
26441 + u64 blocks, bfree, bavail, files, ffree;
26442 + aufs_bindex_t bend, bindex, i;
26443 + unsigned char shared;
26444 + struct path h_path;
26445 + struct super_block *h_sb;
26448 + bsize = LONG_MAX;
26454 + bend = au_sbend(sb);
26455 + for (bindex = 0; bindex <= bend; bindex++) {
26456 + h_path.mnt = au_sbr_mnt(sb, bindex);
26457 + h_sb = h_path.mnt->mnt_sb;
26459 + for (i = 0; !shared && i < bindex; i++)
26460 + shared = (au_sbr_sb(sb, i) == h_sb);
26464 + /* sb->s_root for NFS is unreliable */
26465 + h_path.dentry = h_path.mnt->mnt_root;
26466 + err = vfs_statfs(&h_path, buf);
26467 + if (unlikely(err))
26470 + if (bsize > buf->f_bsize) {
26472 + * we will reduce bsize, so we have to expand blocks
26473 + * etc. to match them again
26475 + factor = (bsize / buf->f_bsize);
26476 + blocks = au_mul_till_max(blocks, factor);
26477 + bfree = au_mul_till_max(bfree, factor);
26478 + bavail = au_mul_till_max(bavail, factor);
26479 + bsize = buf->f_bsize;
26482 + factor = (buf->f_bsize / bsize);
26483 + blocks = au_add_till_max(blocks,
26484 + au_mul_till_max(buf->f_blocks, factor));
26485 + bfree = au_add_till_max(bfree,
26486 + au_mul_till_max(buf->f_bfree, factor));
26487 + bavail = au_add_till_max(bavail,
26488 + au_mul_till_max(buf->f_bavail, factor));
26489 + files = au_add_till_max(files, buf->f_files);
26490 + ffree = au_add_till_max(ffree, buf->f_ffree);
26493 + buf->f_bsize = bsize;
26494 + buf->f_blocks = blocks;
26495 + buf->f_bfree = bfree;
26496 + buf->f_bavail = bavail;
26497 + buf->f_files = files;
26498 + buf->f_ffree = ffree;
26499 + buf->f_frsize = 0;
26505 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
26508 + struct path h_path;
26509 + struct super_block *sb;
26511 + /* lock free root dinfo */
26512 + sb = dentry->d_sb;
26513 + si_noflush_read_lock(sb);
26514 + if (!au_opt_test(au_mntflags(sb), SUM)) {
26515 + /* sb->s_root for NFS is unreliable */
26516 + h_path.mnt = au_sbr_mnt(sb, 0);
26517 + h_path.dentry = h_path.mnt->mnt_root;
26518 + err = vfs_statfs(&h_path, buf);
26520 + err = au_statfs_sum(sb, buf);
26521 + si_read_unlock(sb);
26524 + buf->f_type = AUFS_SUPER_MAGIC;
26525 + buf->f_namelen = AUFS_MAX_NAMELEN;
26526 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
26528 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
26533 +/* ---------------------------------------------------------------------- */
26535 +static int aufs_sync_fs(struct super_block *sb, int wait)
26538 + aufs_bindex_t bend, bindex;
26539 + struct au_branch *br;
26540 + struct super_block *h_sb;
26543 + si_noflush_read_lock(sb);
26544 + bend = au_sbend(sb);
26545 + for (bindex = 0; bindex <= bend; bindex++) {
26546 + br = au_sbr(sb, bindex);
26547 + if (!au_br_writable(br->br_perm))
26550 + h_sb = au_sbr_sb(sb, bindex);
26551 + if (h_sb->s_op->sync_fs) {
26552 + e = h_sb->s_op->sync_fs(h_sb, wait);
26553 + if (unlikely(e && !err))
26555 + /* go on even if an error happens */
26558 + si_read_unlock(sb);
26563 +/* ---------------------------------------------------------------------- */
26565 +/* final actions when unmounting a file system */
26566 +static void aufs_put_super(struct super_block *sb)
26568 + struct au_sbinfo *sbinfo;
26570 + sbinfo = au_sbi(sb);
26574 + dbgaufs_si_fin(sbinfo);
26575 + kobject_put(&sbinfo->si_kobj);
26578 +/* ---------------------------------------------------------------------- */
26580 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
26581 + struct super_block *sb, void *arg)
26584 + unsigned long long n, sz;
26591 + if (*hint > ULLONG_MAX / sizeof(array)) {
26592 + array = ERR_PTR(-EMFILE);
26593 + pr_err("hint %llu\n", *hint);
26597 + sz = sizeof(array) * *hint;
26598 + array = kzalloc(sz, GFP_NOFS);
26599 + if (unlikely(!array))
26600 + array = vzalloc(sz);
26601 + if (unlikely(!array)) {
26602 + array = ERR_PTR(-ENOMEM);
26606 + n = cb(sb, array, *hint, arg);
26607 + AuDebugOn(n > *hint);
26614 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
26615 + unsigned long long max __maybe_unused,
26618 + unsigned long long n;
26619 + struct inode **p, *inode;
26620 + struct list_head *head;
26625 + spin_lock(&sb->s_inode_list_lock);
26626 + list_for_each_entry(inode, head, i_sb_list) {
26627 + if (!is_bad_inode(inode)
26628 + && au_ii(inode)->ii_bstart >= 0) {
26629 + spin_lock(&inode->i_lock);
26630 + if (atomic_read(&inode->i_count)) {
26634 + AuDebugOn(n > max);
26636 + spin_unlock(&inode->i_lock);
26639 + spin_unlock(&sb->s_inode_list_lock);
26644 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
26646 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
26647 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
26650 +void au_iarray_free(struct inode **a, unsigned long long max)
26652 + unsigned long long ull;
26654 + for (ull = 0; ull < max; ull++)
26659 +/* ---------------------------------------------------------------------- */
26662 + * refresh dentry and inode at remount time.
26664 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
26665 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
26666 + struct dentry *parent)
26670 + di_write_lock_child(dentry);
26671 + di_read_lock_parent(parent, AuLock_IR);
26672 + err = au_refresh_dentry(dentry, parent);
26673 + if (!err && dir_flags)
26674 + au_hn_reset(d_inode(dentry), dir_flags);
26675 + di_read_unlock(parent, AuLock_IR);
26676 + di_write_unlock(dentry);
26681 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
26682 + struct au_sbinfo *sbinfo,
26683 + const unsigned int dir_flags, unsigned int do_idop)
26686 + struct dentry *parent;
26689 + parent = dget_parent(dentry);
26690 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
26691 + if (d_really_is_positive(dentry)) {
26692 + if (!d_is_dir(dentry))
26693 + err = au_do_refresh(dentry, /*dir_flags*/0,
26696 + err = au_do_refresh(dentry, dir_flags, parent);
26697 + if (unlikely(err))
26698 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
26701 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
26702 + AuDbgDentry(dentry);
26708 + au_refresh_dop(dentry, /*force_reval*/0);
26710 + au_refresh_dop(dentry, /*force_reval*/1);
26716 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
26718 + int err, i, j, ndentry, e;
26719 + unsigned int sigen;
26720 + struct au_dcsub_pages dpages;
26721 + struct au_dpage *dpage;
26722 + struct dentry **dentries, *d;
26723 + struct au_sbinfo *sbinfo;
26724 + struct dentry *root = sb->s_root;
26725 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
26728 + au_refresh_dop(root, /*force_reval*/0);
26730 + err = au_dpages_init(&dpages, GFP_NOFS);
26731 + if (unlikely(err))
26733 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
26734 + if (unlikely(err))
26737 + sigen = au_sigen(sb);
26738 + sbinfo = au_sbi(sb);
26739 + for (i = 0; i < dpages.ndpage; i++) {
26740 + dpage = dpages.dpages + i;
26741 + dentries = dpage->dentries;
26742 + ndentry = dpage->ndentry;
26743 + for (j = 0; j < ndentry; j++) {
26745 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
26747 + if (unlikely(e && !err))
26749 + /* go on even err */
26754 + au_dpages_free(&dpages);
26759 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
26762 + unsigned int sigen;
26763 + unsigned long long max, ull;
26764 + struct inode *inode, **array;
26766 + array = au_iarray_alloc(sb, &max);
26767 + err = PTR_ERR(array);
26768 + if (IS_ERR(array))
26772 + sigen = au_sigen(sb);
26773 + for (ull = 0; ull < max; ull++) {
26774 + inode = array[ull];
26775 + if (unlikely(!inode))
26779 + ii_write_lock_child(inode);
26780 + if (au_iigen(inode, NULL) != sigen) {
26781 + e = au_refresh_hinode_self(inode);
26782 + if (unlikely(e)) {
26783 + au_refresh_iop(inode, /*force_getattr*/1);
26784 + pr_err("error %d, i%lu\n", e, inode->i_ino);
26787 + /* go on even if err */
26790 + if (!e && do_idop)
26791 + au_refresh_iop(inode, /*force_getattr*/0);
26792 + ii_write_unlock(inode);
26795 + au_iarray_free(array, max);
26801 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
26804 + unsigned int udba;
26805 + aufs_bindex_t bindex, bend;
26806 + struct dentry *root;
26807 + struct inode *inode;
26808 + struct au_branch *br;
26809 + struct au_sbinfo *sbi;
26811 + au_sigen_inc(sb);
26812 + sbi = au_sbi(sb);
26813 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
26815 + root = sb->s_root;
26816 + DiMustNoWaiters(root);
26817 + inode = d_inode(root);
26818 + IiMustNoWaiters(inode);
26820 + udba = au_opt_udba(sb);
26821 + bend = au_sbend(sb);
26822 + for (bindex = 0; bindex <= bend; bindex++) {
26823 + br = au_sbr(sb, bindex);
26824 + err = au_hnotify_reset_br(udba, br, br->br_perm);
26825 + if (unlikely(err))
26826 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
26828 + /* go on even if err */
26830 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
26833 + if (au_ftest_si(sbi, NO_DREVAL)) {
26834 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
26835 + sb->s_d_op = &aufs_dop_noreval;
26836 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
26837 + sbi->si_iop_array = aufs_iop_nogetattr;
26839 + AuDebugOn(sb->s_d_op == &aufs_dop);
26840 + sb->s_d_op = &aufs_dop;
26841 + AuDebugOn(sbi->si_iop_array == aufs_iop);
26842 + sbi->si_iop_array = aufs_iop;
26844 + pr_info("reset to %pf and %pf\n",
26845 + sb->s_d_op, sbi->si_iop_array);
26848 + di_write_unlock(root);
26849 + err = au_refresh_d(sb, do_idop);
26850 + e = au_refresh_i(sb, do_idop);
26851 + if (unlikely(e && !err))
26853 + /* aufs_write_lock() calls ..._child() */
26854 + di_write_lock_child(root);
26856 + au_cpup_attr_all(inode, /*force*/1);
26858 + if (unlikely(err))
26859 + AuIOErr("refresh failed, ignored, %d\n", err);
26862 +/* stop extra interpretation of errno in mount(8), and strange error messages */
26863 +static int cvt_err(int err)
26877 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
26880 + unsigned int mntflags;
26881 + struct au_opts opts = {
26884 + struct dentry *root;
26885 + struct inode *inode;
26886 + struct au_sbinfo *sbinfo;
26889 + root = sb->s_root;
26890 + if (!data || !*data) {
26891 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
26893 + di_write_lock_child(root);
26894 + err = au_opts_verify(sb, *flags, /*pending*/0);
26895 + aufs_write_unlock(root);
26901 + opts.opt = (void *)__get_free_page(GFP_NOFS);
26902 + if (unlikely(!opts.opt))
26904 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
26905 + opts.flags = AuOpts_REMOUNT;
26906 + opts.sb_flags = *flags;
26908 + /* parse it before aufs lock */
26909 + err = au_opts_parse(sb, data, &opts);
26910 + if (unlikely(err))
26913 + sbinfo = au_sbi(sb);
26914 + inode = d_inode(root);
26915 + mutex_lock(&inode->i_mutex);
26916 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
26917 + if (unlikely(err))
26919 + di_write_lock_child(root);
26921 + /* au_opts_remount() may return an error */
26922 + err = au_opts_remount(sb, &opts);
26923 + au_opts_free(&opts);
26925 + if (au_ftest_opts(opts.flags, REFRESH))
26926 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
26928 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
26929 + mntflags = au_mntflags(sb);
26930 + do_dx = !!au_opt_test(mntflags, DIO);
26931 + au_dy_arefresh(do_dx);
26934 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
26935 + aufs_write_unlock(root);
26938 + mutex_unlock(&inode->i_mutex);
26940 + free_page((unsigned long)opts.opt);
26942 + err = cvt_err(err);
26947 +static const struct super_operations aufs_sop = {
26948 + .alloc_inode = aufs_alloc_inode,
26949 + .destroy_inode = aufs_destroy_inode,
26950 + /* always deleting, no clearing */
26951 + .drop_inode = generic_delete_inode,
26952 + .show_options = aufs_show_options,
26953 + .statfs = aufs_statfs,
26954 + .put_super = aufs_put_super,
26955 + .sync_fs = aufs_sync_fs,
26956 + .remount_fs = aufs_remount_fs,
26957 +#ifdef CONFIG_AUFS_BDEV_LOOP
26958 + .real_loop = aufs_real_loop
26962 +/* ---------------------------------------------------------------------- */
26964 +static int alloc_root(struct super_block *sb)
26967 + struct inode *inode;
26968 + struct dentry *root;
26971 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
26972 + err = PTR_ERR(inode);
26973 + if (IS_ERR(inode))
26976 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
26977 + inode->i_fop = &aufs_dir_fop;
26978 + inode->i_mode = S_IFDIR;
26979 + set_nlink(inode, 2);
26980 + unlock_new_inode(inode);
26982 + root = d_make_root(inode);
26983 + if (unlikely(!root))
26985 + err = PTR_ERR(root);
26986 + if (IS_ERR(root))
26989 + err = au_di_init(root);
26991 + sb->s_root = root;
26992 + return 0; /* success */
27000 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27001 + int silent __maybe_unused)
27004 + struct au_opts opts = {
27007 + struct au_sbinfo *sbinfo;
27008 + struct dentry *root;
27009 + struct inode *inode;
27010 + char *arg = raw_data;
27012 + if (unlikely(!arg || !*arg)) {
27014 + pr_err("no arg\n");
27019 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27020 + if (unlikely(!opts.opt))
27022 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27023 + opts.sb_flags = sb->s_flags;
27025 + err = au_si_alloc(sb);
27026 + if (unlikely(err))
27028 + sbinfo = au_sbi(sb);
27030 + /* all timestamps always follow the ones on the branch */
27031 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27032 + sb->s_op = &aufs_sop;
27033 + sb->s_d_op = &aufs_dop;
27034 + sb->s_magic = AUFS_SUPER_MAGIC;
27035 + sb->s_maxbytes = 0;
27036 + sb->s_stack_depth = 1;
27037 + au_export_init(sb);
27038 + /* au_xattr_init(sb); */
27040 + err = alloc_root(sb);
27041 + if (unlikely(err)) {
27042 + si_write_unlock(sb);
27045 + root = sb->s_root;
27046 + inode = d_inode(root);
27049 + * actually we can parse options regardless aufs lock here.
27050 + * but at remount time, parsing must be done before aufs lock.
27051 + * so we follow the same rule.
27053 + ii_write_lock_parent(inode);
27054 + aufs_write_unlock(root);
27055 + err = au_opts_parse(sb, arg, &opts);
27056 + if (unlikely(err))
27059 + /* lock vfs_inode first, then aufs. */
27060 + mutex_lock(&inode->i_mutex);
27061 + aufs_write_lock(root);
27062 + err = au_opts_mount(sb, &opts);
27063 + au_opts_free(&opts);
27064 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
27065 + sb->s_d_op = &aufs_dop_noreval;
27066 + pr_info("%pf\n", sb->s_d_op);
27067 + au_refresh_dop(root, /*force_reval*/0);
27068 + sbinfo->si_iop_array = aufs_iop_nogetattr;
27069 + au_refresh_iop(inode, /*force_getattr*/0);
27071 + aufs_write_unlock(root);
27072 + mutex_unlock(&inode->i_mutex);
27074 + goto out_opts; /* success */
27078 + sb->s_root = NULL;
27080 + dbgaufs_si_fin(sbinfo);
27081 + kobject_put(&sbinfo->si_kobj);
27082 + sb->s_fs_info = NULL;
27084 + free_page((unsigned long)opts.opt);
27087 + err = cvt_err(err);
27092 +/* ---------------------------------------------------------------------- */
27094 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27095 + const char *dev_name __maybe_unused,
27098 + struct dentry *root;
27099 + struct super_block *sb;
27101 + /* all timestamps always follow the ones on the branch */
27102 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27103 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27104 + if (IS_ERR(root))
27108 + si_write_lock(sb, !AuLock_FLUSH);
27109 + sysaufs_brs_add(sb, 0);
27110 + si_write_unlock(sb);
27111 + au_sbilist_add(sb);
27117 +static void aufs_kill_sb(struct super_block *sb)
27119 + struct au_sbinfo *sbinfo;
27121 + sbinfo = au_sbi(sb);
27123 + au_sbilist_del(sb);
27124 + aufs_write_lock(sb->s_root);
27126 + if (sbinfo->si_wbr_create_ops->fin)
27127 + sbinfo->si_wbr_create_ops->fin(sb);
27128 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27129 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27130 + au_remount_refresh(sb, /*do_idop*/0);
27132 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27133 + au_plink_put(sb, /*verbose*/1);
27135 + sbinfo->si_sb = NULL;
27136 + aufs_write_unlock(sb->s_root);
27137 + au_nwt_flush(&sbinfo->si_nowait);
27139 + kill_anon_super(sb);
27142 +struct file_system_type aufs_fs_type = {
27143 + .name = AUFS_FSTYPE,
27144 + /* a race between rename and others */
27145 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27146 + .mount = aufs_mount,
27147 + .kill_sb = aufs_kill_sb,
27148 + /* no need to __module_get() and module_put(). */
27149 + .owner = THIS_MODULE,
27151 diff -urNp -x '*.orig' linux-4.4/fs/aufs/super.h linux-4.4/fs/aufs/super.h
27152 --- linux-4.4/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27153 +++ linux-4.4/fs/aufs/super.h 2021-02-24 17:28:14.412141719 +0100
27156 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27158 + * This program, aufs is free software; you can redistribute it and/or modify
27159 + * it under the terms of the GNU General Public License as published by
27160 + * the Free Software Foundation; either version 2 of the License, or
27161 + * (at your option) any later version.
27163 + * This program is distributed in the hope that it will be useful,
27164 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27165 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27166 + * GNU General Public License for more details.
27168 + * You should have received a copy of the GNU General Public License
27169 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27173 + * super_block operations
27176 +#ifndef __AUFS_SUPER_H__
27177 +#define __AUFS_SUPER_H__
27181 +#include <linux/fs.h>
27182 +#include <linux/kobject.h>
27183 +#include "rwsem.h"
27187 +/* policies to select one among multiple writable branches */
27188 +struct au_wbr_copyup_operations {
27189 + int (*copyup)(struct dentry *dentry);
27192 +#define AuWbr_DIR 1 /* target is a dir */
27193 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27195 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27196 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27197 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27199 +struct au_wbr_create_operations {
27200 + int (*create)(struct dentry *dentry, unsigned int flags);
27201 + int (*init)(struct super_block *sb);
27202 + int (*fin)(struct super_block *sb);
27205 +struct au_wbr_mfs {
27206 + struct mutex mfs_lock; /* protect this structure */
27207 + unsigned long mfs_jiffy;
27208 + unsigned long mfs_expire;
27209 + aufs_bindex_t mfs_bindex;
27211 + unsigned long long mfsrr_bytes;
27212 + unsigned long long mfsrr_watermark;
27215 +struct pseudo_link {
27217 + struct hlist_node hlist;
27218 + struct rcu_head rcu;
27220 + struct inode *inode;
27223 +#define AuPlink_NHASH 100
27224 +static inline int au_plink_hash(ino_t ino)
27226 + return ino % AuPlink_NHASH;
27229 +/* File-based Hierarchical Storage Management */
27231 +#ifdef CONFIG_AUFS_FHSM
27232 + /* allow only one process who can receive the notification */
27233 + spinlock_t fhsm_spin;
27235 + wait_queue_head_t fhsm_wqh;
27236 + atomic_t fhsm_readable;
27238 + /* these are protected by si_rwsem */
27239 + unsigned long fhsm_expire;
27240 + aufs_bindex_t fhsm_bottom;
27245 +struct au_sbinfo {
27246 + /* nowait tasks in the system-wide workqueue */
27247 + struct au_nowait_tasks si_nowait;
27250 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27251 + * rwsem for au_sbinfo is necessary.
27253 + struct au_rwsem si_rwsem;
27255 + /* prevent recursive locking in deleting inode */
27257 + unsigned long *bitmap;
27258 + spinlock_t tree_lock;
27259 + struct radix_tree_root tree;
27263 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27266 + atomic_long_t si_ninodes, si_nfiles;
27268 + /* branch management */
27269 + unsigned int si_generation;
27271 + /* see AuSi_ flags */
27272 + unsigned char au_si_status;
27274 + aufs_bindex_t si_bend;
27276 + /* dirty trick to keep br_id plus */
27277 + unsigned int si_last_br_id :
27278 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27279 + struct au_branch **si_branch;
27281 + /* policy to select a writable branch */
27282 + unsigned char si_wbr_copyup;
27283 + unsigned char si_wbr_create;
27284 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27285 + struct au_wbr_create_operations *si_wbr_create_ops;
27287 + /* round robin */
27288 + atomic_t si_wbr_rr_next;
27290 + /* most free space */
27291 + struct au_wbr_mfs si_wbr_mfs;
27293 + /* File-based Hierarchical Storage Management */
27294 + struct au_fhsm si_fhsm;
27296 + /* mount flags */
27297 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27298 + unsigned int si_mntflags;
27300 + /* symlink to follow_link() and put_link() */
27301 + struct au_sphlhead si_symlink;
27303 + /* external inode number (bitmap and translation table) */
27304 + vfs_readf_t si_xread;
27305 + vfs_writef_t si_xwrite;
27306 + struct file *si_xib;
27307 + struct mutex si_xib_mtx; /* protect xib members */
27308 + unsigned long *si_xib_buf;
27309 + unsigned long si_xib_last_pindex;
27310 + int si_xib_next_bit;
27311 + aufs_bindex_t si_xino_brid;
27312 + unsigned long si_xino_jiffy;
27313 + unsigned long si_xino_expire;
27314 + /* reserved for future use */
27315 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
27317 +#ifdef CONFIG_AUFS_EXPORT
27318 + /* i_generation */
27319 + struct file *si_xigen;
27320 + atomic_t si_xigen_next;
27323 + /* dirty trick to suppoer atomic_open */
27324 + struct au_sphlhead si_aopen;
27326 + /* vdir parameters */
27327 + unsigned long si_rdcache; /* max cache time in jiffies */
27328 + unsigned int si_rdblk; /* deblk size */
27329 + unsigned int si_rdhash; /* hash size */
27332 + * If the number of whiteouts are larger than si_dirwh, leave all of
27333 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
27334 + * future fsck.aufs or kernel thread will remove them later.
27335 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
27337 + unsigned int si_dirwh;
27339 + /* pseudo_link list */
27340 + struct au_sphlhead si_plink[AuPlink_NHASH];
27341 + wait_queue_head_t si_plink_wq;
27342 + spinlock_t si_plink_maint_lock;
27343 + pid_t si_plink_maint_pid;
27346 + struct au_sphlhead si_files;
27348 + /* with/without getattr, brother of sb->s_d_op */
27349 + struct inode_operations *si_iop_array;
27352 + * sysfs and lifetime management.
27353 + * this is not a small structure and it may be a waste of memory in case
27354 + * of sysfs is disabled, particulary when many aufs-es are mounted.
27355 + * but using sysfs is majority.
27357 + struct kobject si_kobj;
27358 +#ifdef CONFIG_DEBUG_FS
27359 + struct dentry *si_dbgaufs;
27360 + struct dentry *si_dbgaufs_plink;
27361 + struct dentry *si_dbgaufs_xib;
27362 +#ifdef CONFIG_AUFS_EXPORT
27363 + struct dentry *si_dbgaufs_xigen;
27367 +#ifdef CONFIG_AUFS_SBILIST
27368 + struct list_head si_list;
27371 + /* dirty, necessary for unmounting, sysfs and sysrq */
27372 + struct super_block *si_sb;
27375 +/* sbinfo status flags */
27377 + * set true when refresh_dirs() failed at remount time.
27378 + * then try refreshing dirs at access time again.
27379 + * if it is false, refreshing dirs at access time is unnecesary
27381 +#define AuSi_FAILED_REFRESH_DIR 1
27382 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
27383 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
27385 +#ifndef CONFIG_AUFS_FHSM
27387 +#define AuSi_FHSM 0
27390 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
27391 + unsigned int flag)
27393 + AuRwMustAnyLock(&sbi->si_rwsem);
27394 + return sbi->au_si_status & flag;
27396 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
27397 +#define au_fset_si(sbinfo, name) do { \
27398 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27399 + (sbinfo)->au_si_status |= AuSi_##name; \
27401 +#define au_fclr_si(sbinfo, name) do { \
27402 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27403 + (sbinfo)->au_si_status &= ~AuSi_##name; \
27406 +/* ---------------------------------------------------------------------- */
27408 +/* policy to select one among writable branches */
27409 +#define AuWbrCopyup(sbinfo, ...) \
27410 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
27411 +#define AuWbrCreate(sbinfo, ...) \
27412 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
27414 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
27415 +#define AuLock_DW 1 /* write-lock dentry */
27416 +#define AuLock_IR (1 << 1) /* read-lock inode */
27417 +#define AuLock_IW (1 << 2) /* write-lock inode */
27418 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
27419 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
27420 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
27421 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
27422 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
27423 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
27424 +#define au_fset_lock(flags, name) \
27425 + do { (flags) |= AuLock_##name; } while (0)
27426 +#define au_fclr_lock(flags, name) \
27427 + do { (flags) &= ~AuLock_##name; } while (0)
27429 +/* ---------------------------------------------------------------------- */
27432 +extern struct file_system_type aufs_fs_type;
27433 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
27434 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
27435 + unsigned long long max, void *arg);
27436 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27437 + struct super_block *sb, void *arg);
27438 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
27439 +void au_iarray_free(struct inode **a, unsigned long long max);
27442 +void au_si_free(struct kobject *kobj);
27443 +int au_si_alloc(struct super_block *sb);
27444 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
27446 +unsigned int au_sigen_inc(struct super_block *sb);
27447 +aufs_bindex_t au_new_br_id(struct super_block *sb);
27449 +int si_read_lock(struct super_block *sb, int flags);
27450 +int si_write_lock(struct super_block *sb, int flags);
27451 +int aufs_read_lock(struct dentry *dentry, int flags);
27452 +void aufs_read_unlock(struct dentry *dentry, int flags);
27453 +void aufs_write_lock(struct dentry *dentry);
27454 +void aufs_write_unlock(struct dentry *dentry);
27455 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
27456 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
27458 +int si_pid_test_slow(struct super_block *sb);
27459 +void si_pid_set_slow(struct super_block *sb);
27460 +void si_pid_clr_slow(struct super_block *sb);
27462 +/* wbr_policy.c */
27463 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
27464 +extern struct au_wbr_create_operations au_wbr_create_ops[];
27465 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
27466 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
27467 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
27470 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
27472 +#ifdef CONFIG_AUFS_FHSM
27475 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
27479 + spin_lock(&fhsm->fhsm_spin);
27480 + pid = fhsm->fhsm_pid;
27481 + spin_unlock(&fhsm->fhsm_spin);
27486 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
27487 +void au_fhsm_wrote_all(struct super_block *sb, int force);
27488 +int au_fhsm_fd(struct super_block *sb, int oflags);
27489 +int au_fhsm_br_alloc(struct au_branch *br);
27490 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
27491 +void au_fhsm_fin(struct super_block *sb);
27492 +void au_fhsm_init(struct au_sbinfo *sbinfo);
27493 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
27494 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
27496 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
27498 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
27499 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
27500 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
27501 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
27502 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
27503 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
27504 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
27505 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
27506 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
27509 +/* ---------------------------------------------------------------------- */
27511 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
27513 + return sb->s_fs_info;
27516 +/* ---------------------------------------------------------------------- */
27518 +#ifdef CONFIG_AUFS_EXPORT
27519 +int au_test_nfsd(void);
27520 +void au_export_init(struct super_block *sb);
27521 +void au_xigen_inc(struct inode *inode);
27522 +int au_xigen_new(struct inode *inode);
27523 +int au_xigen_set(struct super_block *sb, struct file *base);
27524 +void au_xigen_clr(struct super_block *sb);
27526 +static inline int au_busy_or_stale(void)
27528 + if (!au_test_nfsd())
27533 +AuStubInt0(au_test_nfsd, void)
27534 +AuStubVoid(au_export_init, struct super_block *sb)
27535 +AuStubVoid(au_xigen_inc, struct inode *inode)
27536 +AuStubInt0(au_xigen_new, struct inode *inode)
27537 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
27538 +AuStubVoid(au_xigen_clr, struct super_block *sb)
27539 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
27540 +#endif /* CONFIG_AUFS_EXPORT */
27542 +/* ---------------------------------------------------------------------- */
27544 +#ifdef CONFIG_AUFS_SBILIST
27546 +extern struct au_splhead au_sbilist;
27548 +static inline void au_sbilist_init(void)
27550 + au_spl_init(&au_sbilist);
27553 +static inline void au_sbilist_add(struct super_block *sb)
27555 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
27558 +static inline void au_sbilist_del(struct super_block *sb)
27560 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
27563 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
27564 +static inline void au_sbilist_lock(void)
27566 + spin_lock(&au_sbilist.spin);
27569 +static inline void au_sbilist_unlock(void)
27571 + spin_unlock(&au_sbilist.spin);
27573 +#define AuGFP_SBILIST GFP_ATOMIC
27575 +AuStubVoid(au_sbilist_lock, void)
27576 +AuStubVoid(au_sbilist_unlock, void)
27577 +#define AuGFP_SBILIST GFP_NOFS
27578 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
27580 +AuStubVoid(au_sbilist_init, void)
27581 +AuStubVoid(au_sbilist_add, struct super_block *sb)
27582 +AuStubVoid(au_sbilist_del, struct super_block *sb)
27583 +AuStubVoid(au_sbilist_lock, void)
27584 +AuStubVoid(au_sbilist_unlock, void)
27585 +#define AuGFP_SBILIST GFP_NOFS
27588 +/* ---------------------------------------------------------------------- */
27590 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
27593 + * This function is a dynamic '__init' function actually,
27594 + * so the tiny check for si_rwsem is unnecessary.
27596 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
27597 +#ifdef CONFIG_DEBUG_FS
27598 + sbinfo->si_dbgaufs = NULL;
27599 + sbinfo->si_dbgaufs_plink = NULL;
27600 + sbinfo->si_dbgaufs_xib = NULL;
27601 +#ifdef CONFIG_AUFS_EXPORT
27602 + sbinfo->si_dbgaufs_xigen = NULL;
27607 +/* ---------------------------------------------------------------------- */
27609 +static inline pid_t si_pid_bit(void)
27611 + /* the origin of pid is 1, but the bitmap's is 0 */
27612 + return current->pid - 1;
27615 +static inline int si_pid_test(struct super_block *sb)
27619 + bit = si_pid_bit();
27620 + if (bit < PID_MAX_DEFAULT)
27621 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27622 + return si_pid_test_slow(sb);
27625 +static inline void si_pid_set(struct super_block *sb)
27629 + bit = si_pid_bit();
27630 + if (bit < PID_MAX_DEFAULT) {
27631 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27632 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27635 + si_pid_set_slow(sb);
27638 +static inline void si_pid_clr(struct super_block *sb)
27642 + bit = si_pid_bit();
27643 + if (bit < PID_MAX_DEFAULT) {
27644 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27645 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27648 + si_pid_clr_slow(sb);
27651 +/* ---------------------------------------------------------------------- */
27653 +/* lock superblock. mainly for entry point functions */
27655 + * __si_read_lock, __si_write_lock,
27656 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
27658 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
27660 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
27661 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
27662 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
27664 +static inline void si_noflush_read_lock(struct super_block *sb)
27666 + __si_read_lock(sb);
27670 +static inline int si_noflush_read_trylock(struct super_block *sb)
27674 + locked = __si_read_trylock(sb);
27680 +static inline void si_noflush_write_lock(struct super_block *sb)
27682 + __si_write_lock(sb);
27686 +static inline int si_noflush_write_trylock(struct super_block *sb)
27690 + locked = __si_write_trylock(sb);
27696 +#if 0 /* reserved */
27697 +static inline int si_read_trylock(struct super_block *sb, int flags)
27699 + if (au_ftest_lock(flags, FLUSH))
27700 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27701 + return si_noflush_read_trylock(sb);
27705 +static inline void si_read_unlock(struct super_block *sb)
27708 + __si_read_unlock(sb);
27711 +#if 0 /* reserved */
27712 +static inline int si_write_trylock(struct super_block *sb, int flags)
27714 + if (au_ftest_lock(flags, FLUSH))
27715 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27716 + return si_noflush_write_trylock(sb);
27720 +static inline void si_write_unlock(struct super_block *sb)
27723 + __si_write_unlock(sb);
27726 +#if 0 /* reserved */
27727 +static inline void si_downgrade_lock(struct super_block *sb)
27729 + __si_downgrade_lock(sb);
27733 +/* ---------------------------------------------------------------------- */
27735 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
27737 + SiMustAnyLock(sb);
27738 + return au_sbi(sb)->si_bend;
27741 +static inline unsigned int au_mntflags(struct super_block *sb)
27743 + SiMustAnyLock(sb);
27744 + return au_sbi(sb)->si_mntflags;
27747 +static inline unsigned int au_sigen(struct super_block *sb)
27749 + SiMustAnyLock(sb);
27750 + return au_sbi(sb)->si_generation;
27753 +static inline void au_ninodes_inc(struct super_block *sb)
27755 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
27758 +static inline void au_ninodes_dec(struct super_block *sb)
27760 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
27761 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
27764 +static inline void au_nfiles_inc(struct super_block *sb)
27766 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
27769 +static inline void au_nfiles_dec(struct super_block *sb)
27771 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
27772 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
27775 +static inline struct au_branch *au_sbr(struct super_block *sb,
27776 + aufs_bindex_t bindex)
27778 + SiMustAnyLock(sb);
27779 + return au_sbi(sb)->si_branch[0 + bindex];
27782 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
27784 + SiMustWriteLock(sb);
27785 + au_sbi(sb)->si_xino_brid = brid;
27788 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
27790 + SiMustAnyLock(sb);
27791 + return au_sbi(sb)->si_xino_brid;
27794 +#endif /* __KERNEL__ */
27795 +#endif /* __AUFS_SUPER_H__ */
27796 diff -urNp -x '*.orig' linux-4.4/fs/aufs/sysaufs.c linux-4.4/fs/aufs/sysaufs.c
27797 --- linux-4.4/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
27798 +++ linux-4.4/fs/aufs/sysaufs.c 2021-02-24 17:28:14.412141719 +0100
27801 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27803 + * This program, aufs is free software; you can redistribute it and/or modify
27804 + * it under the terms of the GNU General Public License as published by
27805 + * the Free Software Foundation; either version 2 of the License, or
27806 + * (at your option) any later version.
27808 + * This program is distributed in the hope that it will be useful,
27809 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27810 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27811 + * GNU General Public License for more details.
27813 + * You should have received a copy of the GNU General Public License
27814 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27818 + * sysfs interface and lifetime management
27819 + * they are necessary regardless sysfs is disabled.
27822 +#include <linux/random.h>
27825 +unsigned long sysaufs_si_mask;
27826 +struct kset *sysaufs_kset;
27828 +#define AuSiAttr(_name) { \
27829 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
27830 + .show = sysaufs_si_##_name, \
27833 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
27834 +struct attribute *sysaufs_si_attrs[] = {
27835 + &sysaufs_si_attr_xi_path.attr,
27839 +static const struct sysfs_ops au_sbi_ops = {
27840 + .show = sysaufs_si_show
27843 +static struct kobj_type au_sbi_ktype = {
27844 + .release = au_si_free,
27845 + .sysfs_ops = &au_sbi_ops,
27846 + .default_attrs = sysaufs_si_attrs
27849 +/* ---------------------------------------------------------------------- */
27851 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
27855 + sbinfo->si_kobj.kset = sysaufs_kset;
27856 + /* cf. sysaufs_name() */
27857 + err = kobject_init_and_add
27858 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
27859 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
27861 + dbgaufs_si_null(sbinfo);
27863 + err = dbgaufs_si_init(sbinfo);
27864 + if (unlikely(err))
27865 + kobject_put(&sbinfo->si_kobj);
27870 +void sysaufs_fin(void)
27873 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
27874 + kset_unregister(sysaufs_kset);
27877 +int __init sysaufs_init(void)
27882 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
27883 + } while (!sysaufs_si_mask);
27886 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
27887 + if (unlikely(!sysaufs_kset))
27889 + err = PTR_ERR(sysaufs_kset);
27890 + if (IS_ERR(sysaufs_kset))
27892 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
27893 + if (unlikely(err)) {
27894 + kset_unregister(sysaufs_kset);
27898 + err = dbgaufs_init();
27899 + if (unlikely(err))
27904 diff -urNp -x '*.orig' linux-4.4/fs/aufs/sysaufs.h linux-4.4/fs/aufs/sysaufs.h
27905 --- linux-4.4/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
27906 +++ linux-4.4/fs/aufs/sysaufs.h 2021-02-24 17:28:14.412141719 +0100
27909 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27911 + * This program, aufs is free software; you can redistribute it and/or modify
27912 + * it under the terms of the GNU General Public License as published by
27913 + * the Free Software Foundation; either version 2 of the License, or
27914 + * (at your option) any later version.
27916 + * This program is distributed in the hope that it will be useful,
27917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27919 + * GNU General Public License for more details.
27921 + * You should have received a copy of the GNU General Public License
27922 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27926 + * sysfs interface and mount lifetime management
27929 +#ifndef __SYSAUFS_H__
27930 +#define __SYSAUFS_H__
27934 +#include <linux/sysfs.h>
27935 +#include "module.h"
27937 +struct super_block;
27940 +struct sysaufs_si_attr {
27941 + struct attribute attr;
27942 + int (*show)(struct seq_file *seq, struct super_block *sb);
27945 +/* ---------------------------------------------------------------------- */
27948 +extern unsigned long sysaufs_si_mask;
27949 +extern struct kset *sysaufs_kset;
27950 +extern struct attribute *sysaufs_si_attrs[];
27951 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
27952 +int __init sysaufs_init(void);
27953 +void sysaufs_fin(void);
27955 +/* ---------------------------------------------------------------------- */
27957 +/* some people doesn't like to show a pointer in kernel */
27958 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
27960 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
27963 +#define SysaufsSiNamePrefix "si_"
27964 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
27965 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
27967 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
27968 + sysaufs_si_id(sbinfo));
27972 +#ifdef CONFIG_SYSFS
27974 +extern struct attribute_group *sysaufs_attr_group;
27976 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
27977 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
27979 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
27980 +#ifdef CONFIG_COMPAT
27981 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
27984 +void sysaufs_br_init(struct au_branch *br);
27985 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
27986 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
27988 +#define sysaufs_brs_init() do {} while (0)
27991 +#define sysaufs_attr_group NULL
27993 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
27994 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
27995 + struct attribute *attr, char *buf)
27996 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
27997 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
27998 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28000 +static inline void sysaufs_brs_init(void)
28005 +#endif /* CONFIG_SYSFS */
28007 +#endif /* __KERNEL__ */
28008 +#endif /* __SYSAUFS_H__ */
28009 diff -urNp -x '*.orig' linux-4.4/fs/aufs/sysfs.c linux-4.4/fs/aufs/sysfs.c
28010 --- linux-4.4/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28011 +++ linux-4.4/fs/aufs/sysfs.c 2021-02-24 17:28:14.412141719 +0100
28014 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28016 + * This program, aufs is free software; you can redistribute it and/or modify
28017 + * it under the terms of the GNU General Public License as published by
28018 + * the Free Software Foundation; either version 2 of the License, or
28019 + * (at your option) any later version.
28021 + * This program is distributed in the hope that it will be useful,
28022 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28023 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28024 + * GNU General Public License for more details.
28026 + * You should have received a copy of the GNU General Public License
28027 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28031 + * sysfs interface
28034 +#include <linux/compat.h>
28035 +#include <linux/seq_file.h>
28038 +#ifdef CONFIG_AUFS_FS_MODULE
28039 +/* this entry violates the "one line per file" policy of sysfs */
28040 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28044 + static char *conf =
28045 +/* this file is generated at compiling */
28046 +#include "conf.str"
28049 + err = snprintf(buf, PAGE_SIZE, conf);
28050 + if (unlikely(err >= PAGE_SIZE))
28055 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28058 +static struct attribute *au_attr[] = {
28059 +#ifdef CONFIG_AUFS_FS_MODULE
28060 + &au_config_attr.attr,
28062 + NULL, /* need to NULL terminate the list of attributes */
28065 +static struct attribute_group sysaufs_attr_group_body = {
28069 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28071 +/* ---------------------------------------------------------------------- */
28073 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28077 + SiMustAnyLock(sb);
28080 + if (au_opt_test(au_mntflags(sb), XINO)) {
28081 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28082 + seq_putc(seq, '\n');
28088 + * the lifetime of branch is independent from the entry under sysfs.
28089 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28092 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28093 + aufs_bindex_t bindex, int idx)
28096 + struct path path;
28097 + struct dentry *root;
28098 + struct au_branch *br;
28099 + au_br_perm_str_t perm;
28101 + AuDbg("b%d\n", bindex);
28104 + root = sb->s_root;
28105 + di_read_lock_parent(root, !AuLock_IR);
28106 + br = au_sbr(sb, bindex);
28109 + case AuBrSysfs_BR:
28110 + path.mnt = au_br_mnt(br);
28111 + path.dentry = au_h_dptr(root, bindex);
28112 + err = au_seq_path(seq, &path);
28114 + au_optstr_br_perm(&perm, br->br_perm);
28115 + seq_printf(seq, "=%s\n", perm.a);
28118 + case AuBrSysfs_BRID:
28119 + seq_printf(seq, "%d\n", br->br_id);
28122 + di_read_unlock(root, !AuLock_IR);
28123 + if (unlikely(err || seq_has_overflowed(seq)))
28129 +/* ---------------------------------------------------------------------- */
28131 +static struct seq_file *au_seq(char *p, ssize_t len)
28133 + struct seq_file *seq;
28135 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28137 + /* mutex_init(&seq.lock); */
28140 + return seq; /* success */
28143 + seq = ERR_PTR(-ENOMEM);
28147 +#define SysaufsBr_PREFIX "br"
28148 +#define SysaufsBrid_PREFIX "brid"
28150 +/* todo: file size may exceed PAGE_SIZE */
28151 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28157 + aufs_bindex_t bend;
28158 + struct au_sbinfo *sbinfo;
28159 + struct super_block *sb;
28160 + struct seq_file *seq;
28162 + struct attribute **cattr;
28164 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28165 + sb = sbinfo->si_sb;
28168 + * prevent a race condition between sysfs and aufs.
28169 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28170 + * prohibits maintaining the sysfs entries.
28171 + * hew we acquire read lock after sysfs_get_active_two().
28172 + * on the other hand, the remount process may maintain the sysfs/aufs
28173 + * entries after acquiring write lock.
28174 + * it can cause a deadlock.
28175 + * simply we gave up processing read here.
28178 + if (unlikely(!si_noflush_read_trylock(sb)))
28181 + seq = au_seq(buf, PAGE_SIZE);
28182 + err = PTR_ERR(seq);
28186 + name = (void *)attr->name;
28187 + cattr = sysaufs_si_attrs;
28189 + if (!strcmp(name, (*cattr)->name)) {
28190 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28197 + if (!strncmp(name, SysaufsBrid_PREFIX,
28198 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28199 + idx = AuBrSysfs_BRID;
28200 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28201 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28202 + sizeof(SysaufsBr_PREFIX) - 1)) {
28203 + idx = AuBrSysfs_BR;
28204 + name += sizeof(SysaufsBr_PREFIX) - 1;
28208 + err = kstrtol(name, 10, &l);
28210 + bend = au_sbend(sb);
28212 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28219 + err = seq->count;
28220 + /* sysfs limit */
28221 + if (unlikely(err == PAGE_SIZE))
28226 + si_read_unlock(sb);
28231 +/* ---------------------------------------------------------------------- */
28233 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28237 + aufs_bindex_t bindex, bend;
28240 + struct seq_file *seq;
28241 + struct au_branch *br;
28243 + si_read_lock(sb, AuLock_FLUSH);
28244 + bend = au_sbend(sb);
28250 + buf = (void *)__get_free_page(GFP_NOFS);
28251 + if (unlikely(!buf))
28254 + seq = au_seq(buf, PAGE_SIZE);
28255 + err = PTR_ERR(seq);
28259 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28260 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28261 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28262 + if (unlikely(err))
28265 + br = au_sbr(sb, bindex);
28266 + brid = br->br_id;
28267 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28268 + err = __put_user(brid, &arg->id);
28269 + if (unlikely(err))
28272 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28273 + err = __put_user(br->br_perm, &arg->perm);
28274 + if (unlikely(err))
28277 + err = au_seq_path(seq, &br->br_path);
28278 + if (unlikely(err))
28280 + seq_putc(seq, '\0');
28281 + if (!seq_has_overflowed(seq)) {
28282 + err = copy_to_user(arg->path, seq->buf, seq->count);
28284 + if (unlikely(err))
28291 + if (unlikely(err))
28297 + free_page((unsigned long)buf);
28299 + si_read_unlock(sb);
28303 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28305 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
28308 +#ifdef CONFIG_COMPAT
28309 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
28311 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
28315 +/* ---------------------------------------------------------------------- */
28317 +void sysaufs_br_init(struct au_branch *br)
28320 + struct au_brsysfs *br_sysfs;
28321 + struct attribute *attr;
28323 + br_sysfs = br->br_sysfs;
28324 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28325 + attr = &br_sysfs->attr;
28326 + sysfs_attr_init(attr);
28327 + attr->name = br_sysfs->name;
28328 + attr->mode = S_IRUGO;
28333 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28335 + struct au_branch *br;
28336 + struct kobject *kobj;
28337 + struct au_brsysfs *br_sysfs;
28339 + aufs_bindex_t bend;
28341 + dbgaufs_brs_del(sb, bindex);
28343 + if (!sysaufs_brs)
28346 + kobj = &au_sbi(sb)->si_kobj;
28347 + bend = au_sbend(sb);
28348 + for (; bindex <= bend; bindex++) {
28349 + br = au_sbr(sb, bindex);
28350 + br_sysfs = br->br_sysfs;
28351 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28352 + sysfs_remove_file(kobj, &br_sysfs->attr);
28358 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
28361 + aufs_bindex_t bend;
28362 + struct kobject *kobj;
28363 + struct au_branch *br;
28364 + struct au_brsysfs *br_sysfs;
28366 + dbgaufs_brs_add(sb, bindex);
28368 + if (!sysaufs_brs)
28371 + kobj = &au_sbi(sb)->si_kobj;
28372 + bend = au_sbend(sb);
28373 + for (; bindex <= bend; bindex++) {
28374 + br = au_sbr(sb, bindex);
28375 + br_sysfs = br->br_sysfs;
28376 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
28377 + SysaufsBr_PREFIX "%d", bindex);
28378 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
28379 + SysaufsBrid_PREFIX "%d", bindex);
28380 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28381 + err = sysfs_create_file(kobj, &br_sysfs->attr);
28382 + if (unlikely(err))
28383 + pr_warn("failed %s under sysfs(%d)\n",
28384 + br_sysfs->name, err);
28389 diff -urNp -x '*.orig' linux-4.4/fs/aufs/sysrq.c linux-4.4/fs/aufs/sysrq.c
28390 --- linux-4.4/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
28391 +++ linux-4.4/fs/aufs/sysrq.c 2021-02-24 17:28:14.412141719 +0100
28394 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28396 + * This program, aufs is free software; you can redistribute it and/or modify
28397 + * it under the terms of the GNU General Public License as published by
28398 + * the Free Software Foundation; either version 2 of the License, or
28399 + * (at your option) any later version.
28401 + * This program is distributed in the hope that it will be useful,
28402 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28403 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28404 + * GNU General Public License for more details.
28406 + * You should have received a copy of the GNU General Public License
28407 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28411 + * magic sysrq hanlder
28414 +/* #include <linux/sysrq.h> */
28415 +#include <linux/writeback.h>
28418 +/* ---------------------------------------------------------------------- */
28420 +static void sysrq_sb(struct super_block *sb)
28423 + struct au_sbinfo *sbinfo;
28424 + struct file *file;
28425 + struct au_sphlhead *files;
28426 + struct au_finfo *finfo;
28428 + plevel = au_plevel;
28429 + au_plevel = KERN_WARNING;
28431 + /* since we define pr_fmt, call printk directly */
28432 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
28434 + sbinfo = au_sbi(sb);
28435 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
28436 + pr("superblock\n");
28440 + pr("root dentry\n");
28441 + au_dpri_dentry(sb->s_root);
28442 + pr("root inode\n");
28443 + au_dpri_inode(d_inode(sb->s_root));
28448 + int err, i, j, ndentry;
28449 + struct au_dcsub_pages dpages;
28450 + struct au_dpage *dpage;
28452 + err = au_dpages_init(&dpages, GFP_ATOMIC);
28453 + if (unlikely(err))
28455 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
28457 + for (i = 0; i < dpages.ndpage; i++) {
28458 + dpage = dpages.dpages + i;
28459 + ndentry = dpage->ndentry;
28460 + for (j = 0; j < ndentry; j++)
28461 + au_dpri_dentry(dpage->dentries[j]);
28463 + au_dpages_free(&dpages);
28471 + pr("isolated inode\n");
28472 + spin_lock(&sb->s_inode_list_lock);
28473 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
28474 + spin_lock(&i->i_lock);
28475 + if (1 || hlist_empty(&i->i_dentry))
28476 + au_dpri_inode(i);
28477 + spin_unlock(&i->i_lock);
28479 + spin_unlock(&sb->s_inode_list_lock);
28483 + files = &au_sbi(sb)->si_files;
28484 + spin_lock(&files->spin);
28485 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
28488 + file = finfo->fi_file;
28489 + mode = file_inode(file)->i_mode;
28490 + if (!special_file(mode))
28491 + au_dpri_file(file);
28493 + spin_unlock(&files->spin);
28497 + au_plevel = plevel;
28500 +/* ---------------------------------------------------------------------- */
28502 +/* module parameter */
28503 +static char *aufs_sysrq_key = "a";
28504 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
28505 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
28507 +static void au_sysrq(int key __maybe_unused)
28509 + struct au_sbinfo *sbinfo;
28512 + au_sbilist_lock();
28513 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
28514 + sysrq_sb(sbinfo->si_sb);
28515 + au_sbilist_unlock();
28519 +static struct sysrq_key_op au_sysrq_op = {
28520 + .handler = au_sysrq,
28521 + .help_msg = "Aufs",
28522 + .action_msg = "Aufs",
28523 + .enable_mask = SYSRQ_ENABLE_DUMP
28526 +/* ---------------------------------------------------------------------- */
28528 +int __init au_sysrq_init(void)
28534 + key = *aufs_sysrq_key;
28535 + if ('a' <= key && key <= 'z')
28536 + err = register_sysrq_key(key, &au_sysrq_op);
28537 + if (unlikely(err))
28538 + pr_err("err %d, sysrq=%c\n", err, key);
28542 +void au_sysrq_fin(void)
28546 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
28547 + if (unlikely(err))
28548 + pr_err("err %d (ignored)\n", err);
28550 diff -urNp -x '*.orig' linux-4.4/fs/aufs/vdir.c linux-4.4/fs/aufs/vdir.c
28551 --- linux-4.4/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
28552 +++ linux-4.4/fs/aufs/vdir.c 2021-02-24 17:28:14.415475161 +0100
28555 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28557 + * This program, aufs is free software; you can redistribute it and/or modify
28558 + * it under the terms of the GNU General Public License as published by
28559 + * the Free Software Foundation; either version 2 of the License, or
28560 + * (at your option) any later version.
28562 + * This program is distributed in the hope that it will be useful,
28563 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28564 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28565 + * GNU General Public License for more details.
28567 + * You should have received a copy of the GNU General Public License
28568 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28572 + * virtual or vertical directory
28577 +static unsigned int calc_size(int nlen)
28579 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
28582 +static int set_deblk_end(union au_vdir_deblk_p *p,
28583 + union au_vdir_deblk_p *deblk_end)
28585 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
28586 + p->de->de_str.len = 0;
28590 + return -1; /* error */
28593 +/* returns true or false */
28594 +static int is_deblk_end(union au_vdir_deblk_p *p,
28595 + union au_vdir_deblk_p *deblk_end)
28597 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
28598 + return !p->de->de_str.len;
28602 +static unsigned char *last_deblk(struct au_vdir *vdir)
28604 + return vdir->vd_deblk[vdir->vd_nblk - 1];
28607 +/* ---------------------------------------------------------------------- */
28609 +/* estimate the appropriate size for name hash table */
28610 +unsigned int au_rdhash_est(loff_t sz)
28618 + if (sz < AUFS_RDHASH_DEF)
28619 + n = AUFS_RDHASH_DEF;
28620 + /* pr_info("n %u\n", n); */
28625 + * the allocated memory has to be freed by
28626 + * au_nhash_wh_free() or au_nhash_de_free().
28628 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
28630 + struct hlist_head *head;
28634 + sz = sizeof(*nhash->nh_head) * num_hash;
28635 + head = kmalloc(sz, gfp);
28637 + nhash->nh_num = num_hash;
28638 + nhash->nh_head = head;
28639 + for (u = 0; u < num_hash; u++)
28640 + INIT_HLIST_HEAD(head++);
28641 + return 0; /* success */
28647 +static void nhash_count(struct hlist_head *head)
28651 + struct hlist_node *pos;
28654 + hlist_for_each(pos, head)
28656 + pr_info("%lu\n", n);
28660 +static void au_nhash_wh_do_free(struct hlist_head *head)
28662 + struct au_vdir_wh *pos;
28663 + struct hlist_node *node;
28665 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
28669 +static void au_nhash_de_do_free(struct hlist_head *head)
28671 + struct au_vdir_dehstr *pos;
28672 + struct hlist_node *node;
28674 + hlist_for_each_entry_safe(pos, node, head, hash)
28675 + au_cache_free_vdir_dehstr(pos);
28678 +static void au_nhash_do_free(struct au_nhash *nhash,
28679 + void (*free)(struct hlist_head *head))
28682 + struct hlist_head *head;
28684 + n = nhash->nh_num;
28688 + head = nhash->nh_head;
28689 + while (n-- > 0) {
28690 + nhash_count(head);
28693 + kfree(nhash->nh_head);
28696 +void au_nhash_wh_free(struct au_nhash *whlist)
28698 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
28701 +static void au_nhash_de_free(struct au_nhash *delist)
28703 + au_nhash_do_free(delist, au_nhash_de_do_free);
28706 +/* ---------------------------------------------------------------------- */
28708 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
28712 + unsigned int u, n;
28713 + struct hlist_head *head;
28714 + struct au_vdir_wh *pos;
28717 + n = whlist->nh_num;
28718 + head = whlist->nh_head;
28719 + for (u = 0; u < n; u++, head++)
28720 + hlist_for_each_entry(pos, head, wh_hash)
28721 + if (pos->wh_bindex == btgt && ++num > limit)
28726 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
28727 + unsigned char *name,
28728 + unsigned int len)
28731 + /* const unsigned int magic_bit = 12; */
28733 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
28738 + /* v = hash_long(v, magic_bit); */
28739 + v %= nhash->nh_num;
28740 + return nhash->nh_head + v;
28743 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
28746 + return str->len == nlen && !memcmp(str->name, name, nlen);
28749 +/* returns found or not */
28750 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
28752 + struct hlist_head *head;
28753 + struct au_vdir_wh *pos;
28754 + struct au_vdir_destr *str;
28756 + head = au_name_hash(whlist, name, nlen);
28757 + hlist_for_each_entry(pos, head, wh_hash) {
28758 + str = &pos->wh_str;
28759 + AuDbg("%.*s\n", str->len, str->name);
28760 + if (au_nhash_test_name(str, name, nlen))
28766 +/* returns found(true) or not */
28767 +static int test_known(struct au_nhash *delist, char *name, int nlen)
28769 + struct hlist_head *head;
28770 + struct au_vdir_dehstr *pos;
28771 + struct au_vdir_destr *str;
28773 + head = au_name_hash(delist, name, nlen);
28774 + hlist_for_each_entry(pos, head, hash) {
28776 + AuDbg("%.*s\n", str->len, str->name);
28777 + if (au_nhash_test_name(str, name, nlen))
28783 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
28784 + unsigned char d_type)
28786 +#ifdef CONFIG_AUFS_SHWH
28787 + wh->wh_ino = ino;
28788 + wh->wh_type = d_type;
28792 +/* ---------------------------------------------------------------------- */
28794 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
28795 + unsigned int d_type, aufs_bindex_t bindex,
28796 + unsigned char shwh)
28799 + struct au_vdir_destr *str;
28800 + struct au_vdir_wh *wh;
28802 + AuDbg("%.*s\n", nlen, name);
28803 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
28806 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
28807 + if (unlikely(!wh))
28811 + wh->wh_bindex = bindex;
28813 + au_shwh_init_wh(wh, ino, d_type);
28814 + str = &wh->wh_str;
28816 + memcpy(str->name, name, nlen);
28817 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
28824 +static int append_deblk(struct au_vdir *vdir)
28827 + unsigned long ul;
28828 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
28829 + union au_vdir_deblk_p p, deblk_end;
28830 + unsigned char **o;
28833 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
28835 + if (unlikely(!o))
28838 + vdir->vd_deblk = o;
28839 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
28841 + ul = vdir->vd_nblk++;
28842 + vdir->vd_deblk[ul] = p.deblk;
28843 + vdir->vd_last.ul = ul;
28844 + vdir->vd_last.p.deblk = p.deblk;
28845 + deblk_end.deblk = p.deblk + deblk_sz;
28846 + err = set_deblk_end(&p, &deblk_end);
28853 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
28854 + unsigned int d_type, struct au_nhash *delist)
28858 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
28859 + union au_vdir_deblk_p p, *room, deblk_end;
28860 + struct au_vdir_dehstr *dehstr;
28862 + p.deblk = last_deblk(vdir);
28863 + deblk_end.deblk = p.deblk + deblk_sz;
28864 + room = &vdir->vd_last.p;
28865 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
28866 + || !is_deblk_end(room, &deblk_end));
28868 + sz = calc_size(nlen);
28869 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
28870 + err = append_deblk(vdir);
28871 + if (unlikely(err))
28874 + p.deblk = last_deblk(vdir);
28875 + deblk_end.deblk = p.deblk + deblk_sz;
28877 + AuDebugOn(room->deblk != p.deblk);
28881 + dehstr = au_cache_alloc_vdir_dehstr();
28882 + if (unlikely(!dehstr))
28885 + dehstr->str = &room->de->de_str;
28886 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
28887 + room->de->de_ino = ino;
28888 + room->de->de_type = d_type;
28889 + room->de->de_str.len = nlen;
28890 + memcpy(room->de->de_str.name, name, nlen);
28893 + room->deblk += sz;
28894 + if (unlikely(set_deblk_end(room, &deblk_end)))
28895 + err = append_deblk(vdir);
28902 +/* ---------------------------------------------------------------------- */
28904 +void au_vdir_free(struct au_vdir *vdir)
28906 + unsigned char **deblk;
28908 + deblk = vdir->vd_deblk;
28909 + while (vdir->vd_nblk--)
28911 + kfree(vdir->vd_deblk);
28912 + au_cache_free_vdir(vdir);
28915 +static struct au_vdir *alloc_vdir(struct file *file)
28917 + struct au_vdir *vdir;
28918 + struct super_block *sb;
28921 + sb = file->f_path.dentry->d_sb;
28922 + SiMustAnyLock(sb);
28925 + vdir = au_cache_alloc_vdir();
28926 + if (unlikely(!vdir))
28929 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
28930 + if (unlikely(!vdir->vd_deblk))
28933 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
28934 + if (!vdir->vd_deblk_sz) {
28935 + /* estimate the appropriate size for deblk */
28936 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
28937 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
28939 + vdir->vd_nblk = 0;
28940 + vdir->vd_version = 0;
28941 + vdir->vd_jiffy = 0;
28942 + err = append_deblk(vdir);
28944 + return vdir; /* success */
28946 + kfree(vdir->vd_deblk);
28949 + au_cache_free_vdir(vdir);
28951 + vdir = ERR_PTR(err);
28955 +static int reinit_vdir(struct au_vdir *vdir)
28958 + union au_vdir_deblk_p p, deblk_end;
28960 + while (vdir->vd_nblk > 1) {
28961 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
28962 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
28965 + p.deblk = vdir->vd_deblk[0];
28966 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
28967 + err = set_deblk_end(&p, &deblk_end);
28968 + /* keep vd_dblk_sz */
28969 + vdir->vd_last.ul = 0;
28970 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
28971 + vdir->vd_version = 0;
28972 + vdir->vd_jiffy = 0;
28977 +/* ---------------------------------------------------------------------- */
28979 +#define AuFillVdir_CALLED 1
28980 +#define AuFillVdir_WHABLE (1 << 1)
28981 +#define AuFillVdir_SHWH (1 << 2)
28982 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
28983 +#define au_fset_fillvdir(flags, name) \
28984 + do { (flags) |= AuFillVdir_##name; } while (0)
28985 +#define au_fclr_fillvdir(flags, name) \
28986 + do { (flags) &= ~AuFillVdir_##name; } while (0)
28988 +#ifndef CONFIG_AUFS_SHWH
28989 +#undef AuFillVdir_SHWH
28990 +#define AuFillVdir_SHWH 0
28993 +struct fillvdir_arg {
28994 + struct dir_context ctx;
28995 + struct file *file;
28996 + struct au_vdir *vdir;
28997 + struct au_nhash delist;
28998 + struct au_nhash whlist;
28999 + aufs_bindex_t bindex;
29000 + unsigned int flags;
29004 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29005 + loff_t offset __maybe_unused, u64 h_ino,
29006 + unsigned int d_type)
29008 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29009 + char *name = (void *)__name;
29010 + struct super_block *sb;
29012 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29015 + sb = arg->file->f_path.dentry->d_sb;
29016 + au_fset_fillvdir(arg->flags, CALLED);
29018 + if (nlen <= AUFS_WH_PFX_LEN
29019 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29020 + if (test_known(&arg->delist, name, nlen)
29021 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29022 + goto out; /* already exists or whiteouted */
29024 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29026 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29027 + d_type = DT_UNKNOWN;
29028 + arg->err = append_de(arg->vdir, name, nlen, ino,
29029 + d_type, &arg->delist);
29031 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29032 + name += AUFS_WH_PFX_LEN;
29033 + nlen -= AUFS_WH_PFX_LEN;
29034 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29035 + goto out; /* already whiteouted */
29038 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29041 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29042 + d_type = DT_UNKNOWN;
29043 + arg->err = au_nhash_append_wh
29044 + (&arg->whlist, name, nlen, ino, d_type,
29045 + arg->bindex, shwh);
29051 + arg->vdir->vd_jiffy = jiffies;
29053 + AuTraceErr(arg->err);
29057 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29058 + struct au_nhash *whlist, struct au_nhash *delist)
29060 +#ifdef CONFIG_AUFS_SHWH
29062 + unsigned int nh, u;
29063 + struct hlist_head *head;
29064 + struct au_vdir_wh *pos;
29065 + struct hlist_node *n;
29067 + struct au_vdir_destr *destr;
29069 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29072 + o = p = (void *)__get_free_page(GFP_NOFS);
29073 + if (unlikely(!p))
29077 + nh = whlist->nh_num;
29078 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29079 + p += AUFS_WH_PFX_LEN;
29080 + for (u = 0; u < nh; u++) {
29081 + head = whlist->nh_head + u;
29082 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29083 + destr = &pos->wh_str;
29084 + memcpy(p, destr->name, destr->len);
29085 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29086 + pos->wh_ino, pos->wh_type, delist);
29087 + if (unlikely(err))
29092 + free_page((unsigned long)o);
29102 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29105 + unsigned int rdhash;
29107 + aufs_bindex_t bend, bindex, bstart;
29108 + unsigned char shwh;
29109 + struct file *hf, *file;
29110 + struct super_block *sb;
29112 + file = arg->file;
29113 + sb = file->f_path.dentry->d_sb;
29114 + SiMustAnyLock(sb);
29116 + rdhash = au_sbi(sb)->si_rdhash;
29118 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29119 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29120 + if (unlikely(err))
29122 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29123 + if (unlikely(err))
29129 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29131 + au_fset_fillvdir(arg->flags, SHWH);
29133 + bstart = au_fbstart(file);
29134 + bend = au_fbend_dir(file);
29135 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29136 + hf = au_hf_dir(file, bindex);
29140 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29142 + if (unlikely(offset))
29145 + arg->bindex = bindex;
29146 + au_fclr_fillvdir(arg->flags, WHABLE);
29148 + || (bindex != bend
29149 + && au_br_whable(au_sbr_perm(sb, bindex))))
29150 + au_fset_fillvdir(arg->flags, WHABLE);
29153 + au_fclr_fillvdir(arg->flags, CALLED);
29155 + err = vfsub_iterate_dir(hf, &arg->ctx);
29158 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29161 + * dir_relax() may be good for concurrency, but aufs should not
29162 + * use it since it will cause a lockdep problem.
29166 + if (!err && shwh)
29167 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29169 + au_nhash_wh_free(&arg->whlist);
29172 + au_nhash_de_free(&arg->delist);
29177 +static int read_vdir(struct file *file, int may_read)
29180 + unsigned long expire;
29181 + unsigned char do_read;
29182 + struct fillvdir_arg arg = {
29184 + .actor = fillvdir
29187 + struct inode *inode;
29188 + struct au_vdir *vdir, *allocated;
29191 + inode = file_inode(file);
29192 + IMustLock(inode);
29193 + SiMustAnyLock(inode->i_sb);
29195 + allocated = NULL;
29197 + expire = au_sbi(inode->i_sb)->si_rdcache;
29198 + vdir = au_ivdir(inode);
29201 + vdir = alloc_vdir(file);
29202 + err = PTR_ERR(vdir);
29203 + if (IS_ERR(vdir))
29206 + allocated = vdir;
29207 + } else if (may_read
29208 + && (inode->i_version != vdir->vd_version
29209 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29211 + err = reinit_vdir(vdir);
29212 + if (unlikely(err))
29217 + return 0; /* success */
29221 + err = au_do_read_vdir(&arg);
29223 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29224 + vdir->vd_version = inode->i_version;
29225 + vdir->vd_last.ul = 0;
29226 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29228 + au_set_ivdir(inode, allocated);
29229 + } else if (allocated)
29230 + au_vdir_free(allocated);
29236 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29239 + unsigned long ul, n;
29240 + const unsigned int deblk_sz = src->vd_deblk_sz;
29242 + AuDebugOn(tgt->vd_nblk != 1);
29245 + if (tgt->vd_nblk < src->vd_nblk) {
29246 + unsigned char **p;
29248 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29250 + if (unlikely(!p))
29252 + tgt->vd_deblk = p;
29255 + if (tgt->vd_deblk_sz != deblk_sz) {
29256 + unsigned char *p;
29258 + tgt->vd_deblk_sz = deblk_sz;
29259 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29260 + if (unlikely(!p))
29262 + tgt->vd_deblk[0] = p;
29264 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29265 + tgt->vd_version = src->vd_version;
29266 + tgt->vd_jiffy = src->vd_jiffy;
29268 + n = src->vd_nblk;
29269 + for (ul = 1; ul < n; ul++) {
29270 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29272 + if (unlikely(!tgt->vd_deblk[ul]))
29276 + tgt->vd_nblk = n;
29277 + tgt->vd_last.ul = tgt->vd_last.ul;
29278 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29279 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29280 + - src->vd_deblk[src->vd_last.ul];
29282 + return 0; /* success */
29285 + rerr = reinit_vdir(tgt);
29290 +int au_vdir_init(struct file *file)
29293 + struct inode *inode;
29294 + struct au_vdir *vdir_cache, *allocated;
29296 + /* test file->f_pos here instead of ctx->pos */
29297 + err = read_vdir(file, !file->f_pos);
29298 + if (unlikely(err))
29301 + allocated = NULL;
29302 + vdir_cache = au_fvdir_cache(file);
29303 + if (!vdir_cache) {
29304 + vdir_cache = alloc_vdir(file);
29305 + err = PTR_ERR(vdir_cache);
29306 + if (IS_ERR(vdir_cache))
29308 + allocated = vdir_cache;
29309 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29310 + /* test file->f_pos here instead of ctx->pos */
29311 + err = reinit_vdir(vdir_cache);
29312 + if (unlikely(err))
29315 + return 0; /* success */
29317 + inode = file_inode(file);
29318 + err = copy_vdir(vdir_cache, au_ivdir(inode));
29320 + file->f_version = inode->i_version;
29322 + au_set_fvdir_cache(file, allocated);
29323 + } else if (allocated)
29324 + au_vdir_free(allocated);
29330 +static loff_t calc_offset(struct au_vdir *vdir)
29333 + union au_vdir_deblk_p p;
29335 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29336 + offset = vdir->vd_last.p.deblk - p.deblk;
29337 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
29341 +/* returns true or false */
29342 +static int seek_vdir(struct file *file, struct dir_context *ctx)
29345 + unsigned int deblk_sz;
29346 + unsigned long ul, n;
29348 + union au_vdir_deblk_p p, deblk_end;
29349 + struct au_vdir *vdir_cache;
29352 + vdir_cache = au_fvdir_cache(file);
29353 + offset = calc_offset(vdir_cache);
29354 + AuDbg("offset %lld\n", offset);
29355 + if (ctx->pos == offset)
29358 + vdir_cache->vd_last.ul = 0;
29359 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
29364 + deblk_sz = vdir_cache->vd_deblk_sz;
29365 + ul = div64_u64(ctx->pos, deblk_sz);
29366 + AuDbg("ul %lu\n", ul);
29367 + if (ul >= vdir_cache->vd_nblk)
29370 + n = vdir_cache->vd_nblk;
29371 + for (; ul < n; ul++) {
29372 + p.deblk = vdir_cache->vd_deblk[ul];
29373 + deblk_end.deblk = p.deblk + deblk_sz;
29375 + offset *= deblk_sz;
29376 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
29379 + l = calc_size(p.de->de_str.len);
29383 + if (!is_deblk_end(&p, &deblk_end)) {
29385 + vdir_cache->vd_last.ul = ul;
29386 + vdir_cache->vd_last.p = p;
29393 + AuTraceErr(!valid);
29397 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
29399 + unsigned int l, deblk_sz;
29400 + union au_vdir_deblk_p deblk_end;
29401 + struct au_vdir *vdir_cache;
29402 + struct au_vdir_de *de;
29404 + vdir_cache = au_fvdir_cache(file);
29405 + if (!seek_vdir(file, ctx))
29408 + deblk_sz = vdir_cache->vd_deblk_sz;
29410 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29411 + deblk_end.deblk += deblk_sz;
29412 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
29413 + de = vdir_cache->vd_last.p.de;
29414 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
29415 + de->de_str.len, de->de_str.name, ctx->pos,
29416 + (unsigned long)de->de_ino, de->de_type);
29417 + if (unlikely(!dir_emit(ctx, de->de_str.name,
29418 + de->de_str.len, de->de_ino,
29420 + /* todo: ignore the error caused by udba? */
29421 + /* return err; */
29425 + l = calc_size(de->de_str.len);
29426 + vdir_cache->vd_last.p.deblk += l;
29429 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
29430 + vdir_cache->vd_last.ul++;
29431 + vdir_cache->vd_last.p.deblk
29432 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29433 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
29442 diff -urNp -x '*.orig' linux-4.4/fs/aufs/vfsub.c linux-4.4/fs/aufs/vfsub.c
29443 --- linux-4.4/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
29444 +++ linux-4.4/fs/aufs/vfsub.c 2021-02-24 17:28:14.415475161 +0100
29447 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29449 + * This program, aufs is free software; you can redistribute it and/or modify
29450 + * it under the terms of the GNU General Public License as published by
29451 + * the Free Software Foundation; either version 2 of the License, or
29452 + * (at your option) any later version.
29454 + * This program is distributed in the hope that it will be useful,
29455 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29456 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29457 + * GNU General Public License for more details.
29459 + * You should have received a copy of the GNU General Public License
29460 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29464 + * sub-routines for VFS
29467 +#include <linux/namei.h>
29468 +#include <linux/nsproxy.h>
29469 +#include <linux/security.h>
29470 +#include <linux/splice.h>
29471 +#include "../fs/mount.h"
29474 +#ifdef CONFIG_AUFS_BR_FUSE
29475 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
29477 + struct nsproxy *ns;
29479 + if (!au_test_fuse(h_sb) || !au_userns)
29482 + ns = current->nsproxy;
29483 + /* no {get,put}_nsproxy(ns) */
29484 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
29488 +/* ---------------------------------------------------------------------- */
29490 +int vfsub_update_h_iattr(struct path *h_path, int *did)
29494 + struct super_block *h_sb;
29496 + /* for remote fs, leave work for its getattr or d_revalidate */
29497 + /* for bad i_attr fs, handle them in aufs_getattr() */
29498 + /* still some fs may acquire i_mutex. we need to skip them */
29502 + h_sb = h_path->dentry->d_sb;
29503 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
29505 + err = vfs_getattr(h_path, &st);
29510 +/* ---------------------------------------------------------------------- */
29512 +struct file *vfsub_dentry_open(struct path *path, int flags)
29514 + struct file *file;
29516 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
29518 + if (!IS_ERR_OR_NULL(file)
29519 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
29520 + i_readcount_inc(d_inode(path->dentry));
29525 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
29527 + struct file *file;
29530 + file = filp_open(path,
29531 + oflags /* | __FMODE_NONOTIFY */,
29534 + if (IS_ERR(file))
29536 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29543 + * Ideally this function should call VFS:do_last() in order to keep all its
29544 + * checkings. But it is very hard for aufs to regenerate several VFS internal
29545 + * structure such as nameidata. This is a second (or third) best approach.
29546 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
29548 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
29549 + struct vfsub_aopen_args *args, struct au_branch *br)
29552 + struct file *file = args->file;
29553 + /* copied from linux/fs/namei.c:atomic_open() */
29554 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
29557 + AuDebugOn(!dir->i_op->atomic_open);
29559 + err = au_br_test_oflag(args->open_flag, br);
29560 + if (unlikely(err))
29563 + args->file->f_path.dentry = DENTRY_NOT_SET;
29564 + args->file->f_path.mnt = au_br_mnt(br);
29565 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
29566 + args->create_mode, args->opened);
29568 + /* some filesystems don't set FILE_CREATED while succeeded? */
29569 + if (*args->opened & FILE_CREATED)
29570 + fsnotify_create(dir, dentry);
29576 + /* todo: call VFS:may_open() here */
29577 + err = open_check_o_direct(file);
29578 + /* todo: ima_file_check() too? */
29579 + if (!err && (args->open_flag & __FMODE_EXEC))
29580 + err = deny_write_access(file);
29581 + if (unlikely(err))
29582 + /* note that the file is created and still opened */
29586 + atomic_inc(&br->br_count);
29587 + fsnotify_open(file);
29593 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
29597 + err = kern_path(name, flags, path);
29598 + if (!err && d_is_positive(path->dentry))
29599 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
29603 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
29606 + struct path path = {
29610 + /* VFS checks it too, but by WARN_ON_ONCE() */
29611 + IMustLock(d_inode(parent));
29613 + path.dentry = lookup_one_len(name, parent, len);
29614 + if (IS_ERR(path.dentry))
29616 + if (d_is_positive(path.dentry))
29617 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
29620 + AuTraceErrPtr(path.dentry);
29621 + return path.dentry;
29624 +void vfsub_call_lkup_one(void *args)
29626 + struct vfsub_lkup_one_args *a = args;
29627 + *a->errp = vfsub_lkup_one(a->name, a->parent);
29630 +/* ---------------------------------------------------------------------- */
29632 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
29633 + struct dentry *d2, struct au_hinode *hdir2)
29635 + struct dentry *d;
29638 + d = lock_rename(d1, d2);
29640 + au_hn_suspend(hdir1);
29641 + if (hdir1 != hdir2)
29642 + au_hn_suspend(hdir2);
29647 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
29648 + struct dentry *d2, struct au_hinode *hdir2)
29650 + au_hn_resume(hdir1);
29651 + if (hdir1 != hdir2)
29652 + au_hn_resume(hdir2);
29654 + unlock_rename(d1, d2);
29658 +/* ---------------------------------------------------------------------- */
29660 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
29663 + struct dentry *d;
29667 + d = path->dentry;
29668 + path->dentry = d->d_parent;
29669 + err = security_path_mknod(path, d, mode, 0);
29670 + path->dentry = d;
29671 + if (unlikely(err))
29675 + err = vfs_create(dir, path->dentry, mode, want_excl);
29678 + struct path tmp = *path;
29681 + vfsub_update_h_iattr(&tmp, &did);
29683 + tmp.dentry = path->dentry->d_parent;
29684 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29693 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
29696 + struct dentry *d;
29700 + d = path->dentry;
29701 + path->dentry = d->d_parent;
29702 + err = security_path_symlink(path, d, symname);
29703 + path->dentry = d;
29704 + if (unlikely(err))
29708 + err = vfs_symlink(dir, path->dentry, symname);
29711 + struct path tmp = *path;
29714 + vfsub_update_h_iattr(&tmp, &did);
29716 + tmp.dentry = path->dentry->d_parent;
29717 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29726 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
29729 + struct dentry *d;
29733 + d = path->dentry;
29734 + path->dentry = d->d_parent;
29735 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
29736 + path->dentry = d;
29737 + if (unlikely(err))
29741 + err = vfs_mknod(dir, path->dentry, mode, dev);
29744 + struct path tmp = *path;
29747 + vfsub_update_h_iattr(&tmp, &did);
29749 + tmp.dentry = path->dentry->d_parent;
29750 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29759 +static int au_test_nlink(struct inode *inode)
29761 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
29763 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
29764 + || inode->i_nlink < link_max)
29769 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
29770 + struct inode **delegated_inode)
29773 + struct dentry *d;
29777 + err = au_test_nlink(d_inode(src_dentry));
29778 + if (unlikely(err))
29781 + /* we don't call may_linkat() */
29782 + d = path->dentry;
29783 + path->dentry = d->d_parent;
29784 + err = security_path_link(src_dentry, path, d);
29785 + path->dentry = d;
29786 + if (unlikely(err))
29790 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
29793 + struct path tmp = *path;
29796 + /* fuse has different memory inode for the same inumber */
29797 + vfsub_update_h_iattr(&tmp, &did);
29799 + tmp.dentry = path->dentry->d_parent;
29800 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29801 + tmp.dentry = src_dentry;
29802 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29811 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
29812 + struct inode *dir, struct path *path,
29813 + struct inode **delegated_inode)
29816 + struct path tmp = {
29819 + struct dentry *d;
29822 + IMustLock(src_dir);
29824 + d = path->dentry;
29825 + path->dentry = d->d_parent;
29826 + tmp.dentry = src_dentry->d_parent;
29827 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
29828 + path->dentry = d;
29829 + if (unlikely(err))
29833 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
29834 + delegated_inode, /*flags*/0);
29839 + tmp.dentry = d->d_parent;
29840 + vfsub_update_h_iattr(&tmp, &did);
29842 + tmp.dentry = src_dentry;
29843 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29844 + tmp.dentry = src_dentry->d_parent;
29845 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29854 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
29857 + struct dentry *d;
29861 + d = path->dentry;
29862 + path->dentry = d->d_parent;
29863 + err = security_path_mkdir(path, d, mode);
29864 + path->dentry = d;
29865 + if (unlikely(err))
29869 + err = vfs_mkdir(dir, path->dentry, mode);
29872 + struct path tmp = *path;
29875 + vfsub_update_h_iattr(&tmp, &did);
29877 + tmp.dentry = path->dentry->d_parent;
29878 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29887 +int vfsub_rmdir(struct inode *dir, struct path *path)
29890 + struct dentry *d;
29894 + d = path->dentry;
29895 + path->dentry = d->d_parent;
29896 + err = security_path_rmdir(path, d);
29897 + path->dentry = d;
29898 + if (unlikely(err))
29902 + err = vfs_rmdir(dir, path->dentry);
29905 + struct path tmp = {
29906 + .dentry = path->dentry->d_parent,
29910 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
29917 +/* ---------------------------------------------------------------------- */
29919 +/* todo: support mmap_sem? */
29920 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
29926 + err = vfs_read(file, ubuf, count, ppos);
29929 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29933 +/* todo: kernel_read()? */
29934 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
29938 + mm_segment_t oldfs;
29945 + oldfs = get_fs();
29946 + set_fs(KERNEL_DS);
29947 + err = vfsub_read_u(file, buf.u, count, ppos);
29952 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
29958 + err = vfs_write(file, ubuf, count, ppos);
29961 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29965 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
29968 + mm_segment_t oldfs;
29971 + const char __user *u;
29975 + oldfs = get_fs();
29976 + set_fs(KERNEL_DS);
29977 + err = vfsub_write_u(file, buf.u, count, ppos);
29982 +int vfsub_flush(struct file *file, fl_owner_t id)
29987 + if (file->f_op->flush) {
29988 + if (!au_test_nfs(file->f_path.dentry->d_sb))
29989 + err = file->f_op->flush(file, id);
29992 + err = file->f_op->flush(file, id);
29996 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30002 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30006 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30009 + err = iterate_dir(file, ctx);
30012 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30016 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30017 + struct pipe_inode_info *pipe, size_t len,
30018 + unsigned int flags)
30023 + err = do_splice_to(in, ppos, pipe, len, flags);
30025 + file_accessed(in);
30027 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30031 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30032 + loff_t *ppos, size_t len, unsigned int flags)
30037 + err = do_splice_from(pipe, out, ppos, len, flags);
30040 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30044 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30048 + /* file can be NULL */
30050 + err = vfs_fsync(file, datasync);
30054 + AuDebugOn(!file);
30055 + path = &file->f_path;
30057 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30062 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30063 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30064 + struct file *h_file)
30067 + struct inode *h_inode;
30068 + struct super_block *h_sb;
30071 + err = vfsub_truncate(h_path, length);
30075 + h_inode = d_inode(h_path->dentry);
30076 + h_sb = h_inode->i_sb;
30078 + sb_start_write(h_sb);
30080 + err = locks_verify_truncate(h_inode, h_file, length);
30082 + err = security_path_truncate(h_path);
30085 + err = do_truncate(h_path->dentry, length, attr, h_file);
30089 + sb_end_write(h_sb);
30096 +/* ---------------------------------------------------------------------- */
30098 +struct au_vfsub_mkdir_args {
30100 + struct inode *dir;
30101 + struct path *path;
30105 +static void au_call_vfsub_mkdir(void *args)
30107 + struct au_vfsub_mkdir_args *a = args;
30108 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30111 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30113 + int err, do_sio, wkq_err;
30115 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30118 + err = vfsub_mkdir(dir, path, mode);
30121 + struct au_vfsub_mkdir_args args = {
30127 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30128 + if (unlikely(wkq_err))
30135 +struct au_vfsub_rmdir_args {
30137 + struct inode *dir;
30138 + struct path *path;
30141 +static void au_call_vfsub_rmdir(void *args)
30143 + struct au_vfsub_rmdir_args *a = args;
30144 + *a->errp = vfsub_rmdir(a->dir, a->path);
30147 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30149 + int err, do_sio, wkq_err;
30151 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30154 + err = vfsub_rmdir(dir, path);
30157 + struct au_vfsub_rmdir_args args = {
30162 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30163 + if (unlikely(wkq_err))
30170 +/* ---------------------------------------------------------------------- */
30172 +struct notify_change_args {
30174 + struct path *path;
30175 + struct iattr *ia;
30176 + struct inode **delegated_inode;
30179 +static void call_notify_change(void *args)
30181 + struct notify_change_args *a = args;
30182 + struct inode *h_inode;
30184 + h_inode = d_inode(a->path->dentry);
30185 + IMustLock(h_inode);
30187 + *a->errp = -EPERM;
30188 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30190 + *a->errp = notify_change(a->path->dentry, a->ia,
30191 + a->delegated_inode);
30194 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30196 + AuTraceErr(*a->errp);
30199 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30200 + struct inode **delegated_inode)
30203 + struct notify_change_args args = {
30207 + .delegated_inode = delegated_inode
30210 + call_notify_change(&args);
30215 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30216 + struct inode **delegated_inode)
30218 + int err, wkq_err;
30219 + struct notify_change_args args = {
30223 + .delegated_inode = delegated_inode
30226 + wkq_err = au_wkq_wait(call_notify_change, &args);
30227 + if (unlikely(wkq_err))
30233 +/* ---------------------------------------------------------------------- */
30235 +struct unlink_args {
30237 + struct inode *dir;
30238 + struct path *path;
30239 + struct inode **delegated_inode;
30242 +static void call_unlink(void *args)
30244 + struct unlink_args *a = args;
30245 + struct dentry *d = a->path->dentry;
30246 + struct inode *h_inode;
30247 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30248 + && au_dcount(d) == 1);
30250 + IMustLock(a->dir);
30252 + a->path->dentry = d->d_parent;
30253 + *a->errp = security_path_unlink(a->path, d);
30254 + a->path->dentry = d;
30255 + if (unlikely(*a->errp))
30258 + if (!stop_sillyrename)
30261 + if (d_is_positive(d)) {
30262 + h_inode = d_inode(d);
30267 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30270 + struct path tmp = {
30271 + .dentry = d->d_parent,
30272 + .mnt = a->path->mnt
30274 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30277 + if (!stop_sillyrename)
30282 + AuTraceErr(*a->errp);
30286 + * @dir: must be locked.
30287 + * @dentry: target dentry.
30289 +int vfsub_unlink(struct inode *dir, struct path *path,
30290 + struct inode **delegated_inode, int force)
30293 + struct unlink_args args = {
30297 + .delegated_inode = delegated_inode
30301 + call_unlink(&args);
30305 + wkq_err = au_wkq_wait(call_unlink, &args);
30306 + if (unlikely(wkq_err))
30312 diff -urNp -x '*.orig' linux-4.4/fs/aufs/vfsub.h linux-4.4/fs/aufs/vfsub.h
30313 --- linux-4.4/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
30314 +++ linux-4.4/fs/aufs/vfsub.h 2021-02-24 17:28:14.415475161 +0100
30317 + * Copyright (C) 2005-2016 Junjiro R. Okajima
30319 + * This program, aufs is free software; you can redistribute it and/or modify
30320 + * it under the terms of the GNU General Public License as published by
30321 + * the Free Software Foundation; either version 2 of the License, or
30322 + * (at your option) any later version.
30324 + * This program is distributed in the hope that it will be useful,
30325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30327 + * GNU General Public License for more details.
30329 + * You should have received a copy of the GNU General Public License
30330 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30334 + * sub-routines for VFS
30337 +#ifndef __AUFS_VFSUB_H__
30338 +#define __AUFS_VFSUB_H__
30342 +#include <linux/fs.h>
30343 +#include <linux/mount.h>
30344 +#include <linux/posix_acl.h>
30345 +#include <linux/xattr.h>
30346 +#include "debug.h"
30348 +/* copied from linux/fs/internal.h */
30349 +/* todo: BAD approach!! */
30350 +extern void __mnt_drop_write(struct vfsmount *);
30351 +extern int open_check_o_direct(struct file *f);
30353 +/* ---------------------------------------------------------------------- */
30355 +/* lock subclass for lower inode */
30356 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
30357 +/* reduce? gave up. */
30359 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
30360 + AuLsc_I_PARENT, /* lower inode, parent first */
30361 + AuLsc_I_PARENT2, /* copyup dirs */
30362 + AuLsc_I_PARENT3, /* copyup wh */
30368 +/* to debug easier, do not make them inlined functions */
30369 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
30370 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
30372 +/* ---------------------------------------------------------------------- */
30374 +static inline void vfsub_drop_nlink(struct inode *inode)
30376 + AuDebugOn(!inode->i_nlink);
30377 + drop_nlink(inode);
30380 +static inline void vfsub_dead_dir(struct inode *inode)
30382 + AuDebugOn(!S_ISDIR(inode->i_mode));
30383 + inode->i_flags |= S_DEAD;
30384 + clear_nlink(inode);
30387 +static inline int vfsub_native_ro(struct inode *inode)
30389 + return (inode->i_sb->s_flags & MS_RDONLY)
30390 + || IS_RDONLY(inode)
30391 + /* || IS_APPEND(inode) */
30392 + || IS_IMMUTABLE(inode);
30395 +#ifdef CONFIG_AUFS_BR_FUSE
30396 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
30398 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
30401 +/* ---------------------------------------------------------------------- */
30403 +int vfsub_update_h_iattr(struct path *h_path, int *did);
30404 +struct file *vfsub_dentry_open(struct path *path, int flags);
30405 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
30406 +struct vfsub_aopen_args {
30407 + struct file *file;
30408 + unsigned int open_flag;
30409 + umode_t create_mode;
30413 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30414 + struct vfsub_aopen_args *args, struct au_branch *br);
30415 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
30417 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30420 +struct vfsub_lkup_one_args {
30421 + struct dentry **errp;
30422 + struct qstr *name;
30423 + struct dentry *parent;
30426 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
30427 + struct dentry *parent)
30429 + return vfsub_lookup_one_len(name->name, parent, name->len);
30432 +void vfsub_call_lkup_one(void *args);
30434 +/* ---------------------------------------------------------------------- */
30436 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
30441 + err = mnt_want_write(mnt);
30446 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
30449 + mnt_drop_write(mnt);
30453 +#if 0 /* reserved */
30454 +static inline void vfsub_mnt_drop_write_file(struct file *file)
30457 + mnt_drop_write_file(file);
30462 +/* ---------------------------------------------------------------------- */
30465 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30466 + struct dentry *d2, struct au_hinode *hdir2);
30467 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30468 + struct dentry *d2, struct au_hinode *hdir2);
30470 +int vfsub_create(struct inode *dir, struct path *path, int mode,
30472 +int vfsub_symlink(struct inode *dir, struct path *path,
30473 + const char *symname);
30474 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
30475 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
30476 + struct path *path, struct inode **delegated_inode);
30477 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
30478 + struct inode *hdir, struct path *path,
30479 + struct inode **delegated_inode);
30480 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
30481 +int vfsub_rmdir(struct inode *dir, struct path *path);
30483 +/* ---------------------------------------------------------------------- */
30485 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30487 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30489 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30491 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
30493 +int vfsub_flush(struct file *file, fl_owner_t id);
30494 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
30496 +static inline loff_t vfsub_f_size_read(struct file *file)
30498 + return i_size_read(file_inode(file));
30501 +static inline unsigned int vfsub_file_flags(struct file *file)
30503 + unsigned int flags;
30505 + spin_lock(&file->f_lock);
30506 + flags = file->f_flags;
30507 + spin_unlock(&file->f_lock);
30512 +#if 0 /* reserved */
30513 +static inline void vfsub_file_accessed(struct file *h_file)
30515 + file_accessed(h_file);
30516 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
30520 +#if 0 /* reserved */
30521 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
30522 + struct dentry *h_dentry)
30524 + struct path h_path = {
30525 + .dentry = h_dentry,
30528 + touch_atime(&h_path);
30529 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
30533 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
30536 + return generic_update_time(h_inode, ts, flags);
30537 + /* no vfsub_update_h_iattr() since we don't have struct path */
30540 +#ifdef CONFIG_FS_POSIX_ACL
30541 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
30545 + err = posix_acl_chmod(h_inode, h_mode);
30546 + if (err == -EOPNOTSUPP)
30551 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
30554 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30555 + struct pipe_inode_info *pipe, size_t len,
30556 + unsigned int flags);
30557 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30558 + loff_t *ppos, size_t len, unsigned int flags);
30560 +static inline long vfsub_truncate(struct path *path, loff_t length)
30565 + err = vfs_truncate(path, length);
30570 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30571 + struct file *h_file);
30572 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
30574 +/* ---------------------------------------------------------------------- */
30576 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
30581 + err = vfs_llseek(file, offset, origin);
30586 +/* ---------------------------------------------------------------------- */
30588 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
30589 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
30590 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30591 + struct inode **delegated_inode);
30592 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30593 + struct inode **delegated_inode);
30594 +int vfsub_unlink(struct inode *dir, struct path *path,
30595 + struct inode **delegated_inode, int force);
30597 +/* ---------------------------------------------------------------------- */
30599 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
30600 + const void *value, size_t size, int flags)
30605 + err = vfs_setxattr(dentry, name, value, size, flags);
30611 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
30616 + err = vfs_removexattr(dentry, name);
30622 +#endif /* __KERNEL__ */
30623 +#endif /* __AUFS_VFSUB_H__ */
30624 diff -urNp -x '*.orig' linux-4.4/fs/aufs/wbr_policy.c linux-4.4/fs/aufs/wbr_policy.c
30625 --- linux-4.4/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
30626 +++ linux-4.4/fs/aufs/wbr_policy.c 2021-02-24 17:28:14.415475161 +0100
30629 + * Copyright (C) 2005-2016 Junjiro R. Okajima
30631 + * This program, aufs is free software; you can redistribute it and/or modify
30632 + * it under the terms of the GNU General Public License as published by
30633 + * the Free Software Foundation; either version 2 of the License, or
30634 + * (at your option) any later version.
30636 + * This program is distributed in the hope that it will be useful,
30637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30639 + * GNU General Public License for more details.
30641 + * You should have received a copy of the GNU General Public License
30642 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30646 + * policies for selecting one among multiple writable branches
30649 +#include <linux/statfs.h>
30652 +/* subset of cpup_attr() */
30653 +static noinline_for_stack
30654 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
30658 + struct inode *h_isrc;
30660 + h_isrc = d_inode(h_src);
30661 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
30662 + ia.ia_mode = h_isrc->i_mode;
30663 + ia.ia_uid = h_isrc->i_uid;
30664 + ia.ia_gid = h_isrc->i_gid;
30665 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
30666 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
30667 + /* no delegation since it is just created */
30668 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30670 + /* is this nfs only? */
30671 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
30672 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
30673 + ia.ia_mode = h_isrc->i_mode;
30674 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30680 +#define AuCpdown_PARENT_OPQ 1
30681 +#define AuCpdown_WHED (1 << 1)
30682 +#define AuCpdown_MADE_DIR (1 << 2)
30683 +#define AuCpdown_DIROPQ (1 << 3)
30684 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
30685 +#define au_fset_cpdown(flags, name) \
30686 + do { (flags) |= AuCpdown_##name; } while (0)
30687 +#define au_fclr_cpdown(flags, name) \
30688 + do { (flags) &= ~AuCpdown_##name; } while (0)
30690 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
30691 + unsigned int *flags)
30694 + struct dentry *opq_dentry;
30696 + opq_dentry = au_diropq_create(dentry, bdst);
30697 + err = PTR_ERR(opq_dentry);
30698 + if (IS_ERR(opq_dentry))
30700 + dput(opq_dentry);
30701 + au_fset_cpdown(*flags, DIROPQ);
30707 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
30708 + struct inode *dir, aufs_bindex_t bdst)
30711 + struct path h_path;
30712 + struct au_branch *br;
30714 + br = au_sbr(dentry->d_sb, bdst);
30715 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
30716 + err = PTR_ERR(h_path.dentry);
30717 + if (IS_ERR(h_path.dentry))
30721 + if (d_is_positive(h_path.dentry)) {
30722 + h_path.mnt = au_br_mnt(br);
30723 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
30726 + dput(h_path.dentry);
30732 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
30733 + struct au_pin *pin,
30734 + struct dentry *h_parent, void *arg)
30737 + aufs_bindex_t bopq, bstart;
30738 + struct path h_path;
30739 + struct dentry *parent;
30740 + struct inode *h_dir, *h_inode, *inode, *dir;
30741 + unsigned int *flags = arg;
30743 + bstart = au_dbstart(dentry);
30744 + /* dentry is di-locked */
30745 + parent = dget_parent(dentry);
30746 + dir = d_inode(parent);
30747 + h_dir = d_inode(h_parent);
30748 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
30749 + IMustLock(h_dir);
30751 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
30752 + if (unlikely(err < 0))
30754 + h_path.dentry = au_h_dptr(dentry, bdst);
30755 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
30756 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
30757 + S_IRWXU | S_IRUGO | S_IXUGO);
30758 + if (unlikely(err))
30760 + au_fset_cpdown(*flags, MADE_DIR);
30762 + bopq = au_dbdiropq(dentry);
30763 + au_fclr_cpdown(*flags, WHED);
30764 + au_fclr_cpdown(*flags, DIROPQ);
30765 + if (au_dbwh(dentry) == bdst)
30766 + au_fset_cpdown(*flags, WHED);
30767 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
30768 + au_fset_cpdown(*flags, PARENT_OPQ);
30769 + h_inode = d_inode(h_path.dentry);
30770 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
30771 + if (au_ftest_cpdown(*flags, WHED)) {
30772 + err = au_cpdown_dir_opq(dentry, bdst, flags);
30773 + if (unlikely(err)) {
30774 + mutex_unlock(&h_inode->i_mutex);
30779 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
30780 + mutex_unlock(&h_inode->i_mutex);
30781 + if (unlikely(err))
30784 + if (au_ftest_cpdown(*flags, WHED)) {
30785 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
30786 + if (unlikely(err))
30790 + inode = d_inode(dentry);
30791 + if (au_ibend(inode) < bdst)
30792 + au_set_ibend(inode, bdst);
30793 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
30794 + au_hi_flags(inode, /*isdir*/1));
30795 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
30796 + goto out; /* success */
30800 + if (au_ftest_cpdown(*flags, DIROPQ)) {
30801 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
30802 + rerr = au_diropq_remove(dentry, bdst);
30803 + mutex_unlock(&h_inode->i_mutex);
30804 + if (unlikely(rerr)) {
30805 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
30806 + dentry, bdst, rerr);
30812 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
30813 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
30814 + if (unlikely(rerr)) {
30815 + AuIOErr("failed removing %pd b%d (%d)\n",
30816 + dentry, bdst, rerr);
30821 + au_set_h_dptr(dentry, bdst, NULL);
30822 + if (au_dbend(dentry) == bdst)
30823 + au_update_dbend(dentry);
30829 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
30832 + unsigned int flags;
30835 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
30840 +/* ---------------------------------------------------------------------- */
30842 +/* policies for create */
30844 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
30846 + int err, i, j, ndentry;
30847 + aufs_bindex_t bopq;
30848 + struct au_dcsub_pages dpages;
30849 + struct au_dpage *dpage;
30850 + struct dentry **dentries, *parent, *d;
30852 + err = au_dpages_init(&dpages, GFP_NOFS);
30853 + if (unlikely(err))
30855 + parent = dget_parent(dentry);
30856 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
30857 + if (unlikely(err))
30861 + for (i = 0; i < dpages.ndpage; i++) {
30862 + dpage = dpages.dpages + i;
30863 + dentries = dpage->dentries;
30864 + ndentry = dpage->ndentry;
30865 + for (j = 0; j < ndentry; j++) {
30867 + di_read_lock_parent2(d, !AuLock_IR);
30868 + bopq = au_dbdiropq(d);
30869 + di_read_unlock(d, !AuLock_IR);
30870 + if (bopq >= 0 && bopq < err)
30877 + au_dpages_free(&dpages);
30882 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
30884 + for (; bindex >= 0; bindex--)
30885 + if (!au_br_rdonly(au_sbr(sb, bindex)))
30890 +/* top down parent */
30891 +static int au_wbr_create_tdp(struct dentry *dentry,
30892 + unsigned int flags __maybe_unused)
30895 + aufs_bindex_t bstart, bindex;
30896 + struct super_block *sb;
30897 + struct dentry *parent, *h_parent;
30899 + sb = dentry->d_sb;
30900 + bstart = au_dbstart(dentry);
30902 + if (!au_br_rdonly(au_sbr(sb, bstart)))
30906 + parent = dget_parent(dentry);
30907 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
30908 + h_parent = au_h_dptr(parent, bindex);
30909 + if (!h_parent || d_is_negative(h_parent))
30912 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
30919 + /* bottom up here */
30920 + if (unlikely(err < 0)) {
30921 + err = au_wbr_bu(sb, bstart - 1);
30923 + err = au_wbr_nonopq(dentry, err);
30927 + AuDbg("b%d\n", err);
30931 +/* ---------------------------------------------------------------------- */
30933 +/* an exception for the policy other than tdp */
30934 +static int au_wbr_create_exp(struct dentry *dentry)
30937 + aufs_bindex_t bwh, bdiropq;
30938 + struct dentry *parent;
30941 + bwh = au_dbwh(dentry);
30942 + parent = dget_parent(dentry);
30943 + bdiropq = au_dbdiropq(parent);
30945 + if (bdiropq >= 0)
30946 + err = min(bdiropq, bwh);
30949 + AuDbg("%d\n", err);
30950 + } else if (bdiropq >= 0) {
30952 + AuDbg("%d\n", err);
30957 + err = au_wbr_nonopq(dentry, err);
30959 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
30962 + AuDbg("%d\n", err);
30966 +/* ---------------------------------------------------------------------- */
30969 +static int au_wbr_create_init_rr(struct super_block *sb)
30973 + err = au_wbr_bu(sb, au_sbend(sb));
30974 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
30977 + AuDbg("b%d\n", err);
30981 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
30985 + aufs_bindex_t bindex, bend;
30986 + struct super_block *sb;
30989 + err = au_wbr_create_exp(dentry);
30993 + sb = dentry->d_sb;
30994 + next = &au_sbi(sb)->si_wbr_rr_next;
30995 + bend = au_sbend(sb);
30997 + for (bindex = 0; bindex <= bend; bindex++) {
30998 + if (!au_ftest_wbr(flags, DIR)) {
30999 + err = atomic_dec_return(next) + 1;
31000 + /* modulo for 0 is meaningless */
31001 + if (unlikely(!err))
31002 + err = atomic_dec_return(next) + 1;
31004 + err = atomic_read(next);
31005 + AuDbg("%d\n", err);
31008 + AuDbg("%d\n", err);
31009 + if (!au_br_rdonly(au_sbr(sb, err)))
31015 + err = au_wbr_nonopq(dentry, err);
31018 + AuDbg("%d\n", err);
31022 +/* ---------------------------------------------------------------------- */
31024 +/* most free space */
31025 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31027 + struct super_block *sb;
31028 + struct au_branch *br;
31029 + struct au_wbr_mfs *mfs;
31030 + struct dentry *h_parent;
31031 + aufs_bindex_t bindex, bend;
31033 + unsigned long long b, bavail;
31034 + struct path h_path;
31035 + /* reduce the stack usage */
31036 + struct kstatfs *st;
31038 + st = kmalloc(sizeof(*st), GFP_NOFS);
31039 + if (unlikely(!st)) {
31040 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31045 + sb = dentry->d_sb;
31046 + mfs = &au_sbi(sb)->si_wbr_mfs;
31047 + MtxMustLock(&mfs->mfs_lock);
31048 + mfs->mfs_bindex = -EROFS;
31049 + mfs->mfsrr_bytes = 0;
31052 + bend = au_sbend(sb);
31054 + bindex = au_dbstart(parent);
31055 + bend = au_dbtaildir(parent);
31058 + for (; bindex <= bend; bindex++) {
31060 + h_parent = au_h_dptr(parent, bindex);
31061 + if (!h_parent || d_is_negative(h_parent))
31064 + br = au_sbr(sb, bindex);
31065 + if (au_br_rdonly(br))
31068 + /* sb->s_root for NFS is unreliable */
31069 + h_path.mnt = au_br_mnt(br);
31070 + h_path.dentry = h_path.mnt->mnt_root;
31071 + err = vfs_statfs(&h_path, st);
31072 + if (unlikely(err)) {
31073 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31077 + /* when the available size is equal, select the lower one */
31078 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31079 + || sizeof(b) < sizeof(st->f_bsize));
31080 + b = st->f_bavail * st->f_bsize;
31081 + br->br_wbr->wbr_bytes = b;
31082 + if (b >= bavail) {
31084 + mfs->mfs_bindex = bindex;
31085 + mfs->mfs_jiffy = jiffies;
31089 + mfs->mfsrr_bytes = bavail;
31090 + AuDbg("b%d\n", mfs->mfs_bindex);
31094 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31097 + struct dentry *parent;
31098 + struct super_block *sb;
31099 + struct au_wbr_mfs *mfs;
31101 + err = au_wbr_create_exp(dentry);
31105 + sb = dentry->d_sb;
31107 + if (au_ftest_wbr(flags, PARENT))
31108 + parent = dget_parent(dentry);
31109 + mfs = &au_sbi(sb)->si_wbr_mfs;
31110 + mutex_lock(&mfs->mfs_lock);
31111 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31112 + || mfs->mfs_bindex < 0
31113 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31114 + au_mfs(dentry, parent);
31115 + mutex_unlock(&mfs->mfs_lock);
31116 + err = mfs->mfs_bindex;
31120 + err = au_wbr_nonopq(dentry, err);
31123 + AuDbg("b%d\n", err);
31127 +static int au_wbr_create_init_mfs(struct super_block *sb)
31129 + struct au_wbr_mfs *mfs;
31131 + mfs = &au_sbi(sb)->si_wbr_mfs;
31132 + mutex_init(&mfs->mfs_lock);
31133 + mfs->mfs_jiffy = 0;
31134 + mfs->mfs_bindex = -EROFS;
31139 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31141 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31145 +/* ---------------------------------------------------------------------- */
31147 +/* most free space and then round robin */
31148 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31151 + struct au_wbr_mfs *mfs;
31153 + err = au_wbr_create_mfs(dentry, flags);
31155 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31156 + mutex_lock(&mfs->mfs_lock);
31157 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31158 + err = au_wbr_create_rr(dentry, flags);
31159 + mutex_unlock(&mfs->mfs_lock);
31162 + AuDbg("b%d\n", err);
31166 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31170 + au_wbr_create_init_mfs(sb); /* ignore */
31171 + err = au_wbr_create_init_rr(sb);
31176 +/* ---------------------------------------------------------------------- */
31178 +/* top down parent and most free space */
31179 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31182 + unsigned long long b;
31183 + aufs_bindex_t bindex, bstart, bend;
31184 + struct super_block *sb;
31185 + struct dentry *parent, *h_parent;
31186 + struct au_branch *br;
31188 + err = au_wbr_create_tdp(dentry, flags);
31189 + if (unlikely(err < 0))
31191 + parent = dget_parent(dentry);
31192 + bstart = au_dbstart(parent);
31193 + bend = au_dbtaildir(parent);
31194 + if (bstart == bend)
31195 + goto out_parent; /* success */
31197 + e2 = au_wbr_create_mfs(dentry, flags);
31199 + goto out_parent; /* success */
31201 + /* when the available size is equal, select upper one */
31202 + sb = dentry->d_sb;
31203 + br = au_sbr(sb, err);
31204 + b = br->br_wbr->wbr_bytes;
31205 + AuDbg("b%d, %llu\n", err, b);
31207 + for (bindex = bstart; bindex <= bend; bindex++) {
31208 + h_parent = au_h_dptr(parent, bindex);
31209 + if (!h_parent || d_is_negative(h_parent))
31212 + br = au_sbr(sb, bindex);
31213 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31214 + b = br->br_wbr->wbr_bytes;
31216 + AuDbg("b%d, %llu\n", err, b);
31221 + err = au_wbr_nonopq(dentry, err);
31226 + AuDbg("b%d\n", err);
31230 +/* ---------------------------------------------------------------------- */
31233 + * - top down parent
31234 + * - most free space with parent
31235 + * - most free space round-robin regardless parent
31237 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31240 + unsigned long long watermark;
31241 + struct super_block *sb;
31242 + struct au_branch *br;
31243 + struct au_wbr_mfs *mfs;
31245 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31246 + if (unlikely(err < 0))
31249 + sb = dentry->d_sb;
31250 + br = au_sbr(sb, err);
31251 + mfs = &au_sbi(sb)->si_wbr_mfs;
31252 + mutex_lock(&mfs->mfs_lock);
31253 + watermark = mfs->mfsrr_watermark;
31254 + mutex_unlock(&mfs->mfs_lock);
31255 + if (br->br_wbr->wbr_bytes < watermark)
31256 + /* regardless the parent dir */
31257 + err = au_wbr_create_mfsrr(dentry, flags);
31260 + AuDbg("b%d\n", err);
31264 +/* ---------------------------------------------------------------------- */
31266 +/* policies for copyup */
31268 +/* top down parent */
31269 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31271 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31274 +/* bottom up parent */
31275 +static int au_wbr_copyup_bup(struct dentry *dentry)
31278 + aufs_bindex_t bindex, bstart;
31279 + struct dentry *parent, *h_parent;
31280 + struct super_block *sb;
31283 + sb = dentry->d_sb;
31284 + parent = dget_parent(dentry);
31285 + bstart = au_dbstart(parent);
31286 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31287 + h_parent = au_h_dptr(parent, bindex);
31288 + if (!h_parent || d_is_negative(h_parent))
31291 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31298 + /* bottom up here */
31299 + if (unlikely(err < 0))
31300 + err = au_wbr_bu(sb, bstart - 1);
31302 + AuDbg("b%d\n", err);
31307 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
31311 + err = au_wbr_bu(dentry->d_sb, bstart);
31312 + AuDbg("b%d\n", err);
31313 + if (err > bstart)
31314 + err = au_wbr_nonopq(dentry, err);
31316 + AuDbg("b%d\n", err);
31320 +static int au_wbr_copyup_bu(struct dentry *dentry)
31323 + aufs_bindex_t bstart;
31325 + bstart = au_dbstart(dentry);
31326 + err = au_wbr_do_copyup_bu(dentry, bstart);
31330 +/* ---------------------------------------------------------------------- */
31332 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
31333 + [AuWbrCopyup_TDP] = {
31334 + .copyup = au_wbr_copyup_tdp
31336 + [AuWbrCopyup_BUP] = {
31337 + .copyup = au_wbr_copyup_bup
31339 + [AuWbrCopyup_BU] = {
31340 + .copyup = au_wbr_copyup_bu
31344 +struct au_wbr_create_operations au_wbr_create_ops[] = {
31345 + [AuWbrCreate_TDP] = {
31346 + .create = au_wbr_create_tdp
31348 + [AuWbrCreate_RR] = {
31349 + .create = au_wbr_create_rr,
31350 + .init = au_wbr_create_init_rr
31352 + [AuWbrCreate_MFS] = {
31353 + .create = au_wbr_create_mfs,
31354 + .init = au_wbr_create_init_mfs,
31355 + .fin = au_wbr_create_fin_mfs
31357 + [AuWbrCreate_MFSV] = {
31358 + .create = au_wbr_create_mfs,
31359 + .init = au_wbr_create_init_mfs,
31360 + .fin = au_wbr_create_fin_mfs
31362 + [AuWbrCreate_MFSRR] = {
31363 + .create = au_wbr_create_mfsrr,
31364 + .init = au_wbr_create_init_mfsrr,
31365 + .fin = au_wbr_create_fin_mfs
31367 + [AuWbrCreate_MFSRRV] = {
31368 + .create = au_wbr_create_mfsrr,
31369 + .init = au_wbr_create_init_mfsrr,
31370 + .fin = au_wbr_create_fin_mfs
31372 + [AuWbrCreate_PMFS] = {
31373 + .create = au_wbr_create_pmfs,
31374 + .init = au_wbr_create_init_mfs,
31375 + .fin = au_wbr_create_fin_mfs
31377 + [AuWbrCreate_PMFSV] = {
31378 + .create = au_wbr_create_pmfs,
31379 + .init = au_wbr_create_init_mfs,
31380 + .fin = au_wbr_create_fin_mfs
31382 + [AuWbrCreate_PMFSRR] = {
31383 + .create = au_wbr_create_pmfsrr,
31384 + .init = au_wbr_create_init_mfsrr,
31385 + .fin = au_wbr_create_fin_mfs
31387 + [AuWbrCreate_PMFSRRV] = {
31388 + .create = au_wbr_create_pmfsrr,
31389 + .init = au_wbr_create_init_mfsrr,
31390 + .fin = au_wbr_create_fin_mfs
31393 diff -urNp -x '*.orig' linux-4.4/fs/aufs/whout.c linux-4.4/fs/aufs/whout.c
31394 --- linux-4.4/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
31395 +++ linux-4.4/fs/aufs/whout.c 2021-02-24 17:28:14.415475161 +0100
31398 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31400 + * This program, aufs is free software; you can redistribute it and/or modify
31401 + * it under the terms of the GNU General Public License as published by
31402 + * the Free Software Foundation; either version 2 of the License, or
31403 + * (at your option) any later version.
31405 + * This program is distributed in the hope that it will be useful,
31406 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31407 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31408 + * GNU General Public License for more details.
31410 + * You should have received a copy of the GNU General Public License
31411 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31415 + * whiteout for logical deletion and opaque directory
31420 +#define WH_MASK S_IRUGO
31423 + * If a directory contains this file, then it is opaque. We start with the
31424 + * .wh. flag so that it is blocked by lookup.
31426 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
31427 + sizeof(AUFS_WH_DIROPQ) - 1);
31430 + * generate whiteout name, which is NOT terminated by NULL.
31431 + * @name: original d_name.name
31432 + * @len: original d_name.len
31433 + * @wh: whiteout qstr
31434 + * returns zero when succeeds, otherwise error.
31435 + * succeeded value as wh->name should be freed by kfree().
31437 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
31441 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
31442 + return -ENAMETOOLONG;
31444 + wh->len = name->len + AUFS_WH_PFX_LEN;
31445 + p = kmalloc(wh->len, GFP_NOFS);
31448 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31449 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
31456 +/* ---------------------------------------------------------------------- */
31459 + * test if the @wh_name exists under @h_parent.
31460 + * @try_sio specifies the necessary of super-io.
31462 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
31465 + struct dentry *wh_dentry;
31468 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
31470 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
31471 + err = PTR_ERR(wh_dentry);
31472 + if (IS_ERR(wh_dentry)) {
31473 + if (err == -ENAMETOOLONG)
31479 + if (d_is_negative(wh_dentry))
31480 + goto out_wh; /* success */
31483 + if (d_is_reg(wh_dentry))
31484 + goto out_wh; /* success */
31487 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
31488 + wh_dentry, d_inode(wh_dentry)->i_mode);
31497 + * test if the @h_dentry sets opaque or not.
31499 +int au_diropq_test(struct dentry *h_dentry)
31502 + struct inode *h_dir;
31504 + h_dir = d_inode(h_dentry);
31505 + err = au_wh_test(h_dentry, &diropq_name,
31506 + au_test_h_perm_sio(h_dir, MAY_EXEC));
31511 + * returns a negative dentry whose name is unique and temporary.
31513 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31514 + struct qstr *prefix)
31516 + struct dentry *dentry;
31518 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
31520 + /* strict atomic_t is unnecessary here */
31521 + static unsigned short cnt;
31524 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
31527 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
31528 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
31529 + dentry = ERR_PTR(-ENAMETOOLONG);
31530 + if (unlikely(qs.len > NAME_MAX))
31532 + dentry = ERR_PTR(-ENOMEM);
31533 + name = kmalloc(qs.len + 1, GFP_NOFS);
31534 + if (unlikely(!name))
31538 + /* doubly whiteout-ed */
31539 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
31540 + p = name + AUFS_WH_PFX_LEN * 2;
31541 + memcpy(p, prefix->name, prefix->len);
31542 + p += prefix->len;
31544 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
31547 + for (i = 0; i < 3; i++) {
31548 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
31549 + dentry = au_sio_lkup_one(&qs, h_parent);
31550 + if (IS_ERR(dentry) || d_is_negative(dentry))
31554 + /* pr_warn("could not get random name\n"); */
31555 + dentry = ERR_PTR(-EEXIST);
31556 + AuDbg("%.*s\n", AuLNPair(&qs));
31560 + if (name != defname)
31563 + AuTraceErrPtr(dentry);
31568 + * rename the @h_dentry on @br to the whiteouted temporary name.
31570 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
31573 + struct path h_path = {
31574 + .mnt = au_br_mnt(br)
31576 + struct inode *h_dir, *delegated;
31577 + struct dentry *h_parent;
31579 + h_parent = h_dentry->d_parent; /* dir inode is locked */
31580 + h_dir = d_inode(h_parent);
31581 + IMustLock(h_dir);
31583 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
31584 + err = PTR_ERR(h_path.dentry);
31585 + if (IS_ERR(h_path.dentry))
31588 + /* under the same dir, no need to lock_rename() */
31589 + delegated = NULL;
31590 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
31592 + if (unlikely(err == -EWOULDBLOCK)) {
31593 + pr_warn("cannot retry for NFSv4 delegation"
31594 + " for an internal rename\n");
31597 + dput(h_path.dentry);
31604 +/* ---------------------------------------------------------------------- */
31606 + * functions for removing a whiteout
31609 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
31612 + struct inode *delegated;
31615 + * forces superio when the dir has a sticky bit.
31616 + * this may be a violation of unix fs semantics.
31618 + force = (h_dir->i_mode & S_ISVTX)
31619 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
31620 + delegated = NULL;
31621 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
31622 + if (unlikely(err == -EWOULDBLOCK)) {
31623 + pr_warn("cannot retry for NFSv4 delegation"
31624 + " for an internal unlink\n");
31630 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
31631 + struct dentry *dentry)
31635 + err = do_unlink_wh(h_dir, h_path);
31636 + if (!err && dentry)
31637 + au_set_dbwh(dentry, -1);
31642 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
31643 + struct au_branch *br)
31646 + struct path h_path = {
31647 + .mnt = au_br_mnt(br)
31651 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
31652 + if (IS_ERR(h_path.dentry))
31653 + err = PTR_ERR(h_path.dentry);
31655 + if (d_is_reg(h_path.dentry))
31656 + err = do_unlink_wh(d_inode(h_parent), &h_path);
31657 + dput(h_path.dentry);
31663 +/* ---------------------------------------------------------------------- */
31665 + * initialize/clean whiteout for a branch
31668 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
31672 + struct inode *delegated;
31674 + if (d_is_negative(whpath->dentry))
31678 + err = vfsub_rmdir(h_dir, whpath);
31680 + delegated = NULL;
31681 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
31682 + if (unlikely(err == -EWOULDBLOCK)) {
31683 + pr_warn("cannot retry for NFSv4 delegation"
31684 + " for an internal unlink\n");
31688 + if (unlikely(err))
31689 + pr_warn("failed removing %pd (%d), ignored.\n",
31690 + whpath->dentry, err);
31693 +static int test_linkable(struct dentry *h_root)
31695 + struct inode *h_dir = d_inode(h_root);
31697 + if (h_dir->i_op->link)
31700 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
31701 + h_root, au_sbtype(h_root->d_sb));
31705 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
31706 +static int au_whdir(struct inode *h_dir, struct path *path)
31711 + if (d_is_negative(path->dentry)) {
31712 + int mode = S_IRWXU;
31714 + if (au_test_nfs(path->dentry->d_sb))
31716 + err = vfsub_mkdir(h_dir, path, mode);
31717 + } else if (d_is_dir(path->dentry))
31720 + pr_err("unknown %pd exists\n", path->dentry);
31725 +struct au_wh_base {
31726 + const struct qstr *name;
31727 + struct dentry *dentry;
31730 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
31731 + struct path *h_path)
31733 + h_path->dentry = base[AuBrWh_BASE].dentry;
31734 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31735 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31736 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31737 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31738 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31742 + * returns tri-state,
31743 + * minus: error, caller should print the message
31745 + * plus: error, caller should NOT print the message
31747 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
31748 + int do_plink, struct au_wh_base base[],
31749 + struct path *h_path)
31752 + struct inode *h_dir;
31754 + h_dir = d_inode(h_root);
31755 + h_path->dentry = base[AuBrWh_BASE].dentry;
31756 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31757 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31759 + err = test_linkable(h_root);
31760 + if (unlikely(err)) {
31765 + err = au_whdir(h_dir, h_path);
31766 + if (unlikely(err))
31768 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
31770 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31771 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31772 + err = au_whdir(h_dir, h_path);
31773 + if (unlikely(err))
31775 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
31782 + * for the moment, aufs supports the branch filesystem which does not support
31783 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
31784 + * copyup failed. finally, such filesystem will not be used as the writable
31787 + * returns tri-state, see above.
31789 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
31790 + int do_plink, struct au_wh_base base[],
31791 + struct path *h_path)
31794 + struct inode *h_dir;
31796 + WbrWhMustWriteLock(wbr);
31798 + err = test_linkable(h_root);
31799 + if (unlikely(err)) {
31805 + * todo: should this create be done in /sbin/mount.aufs helper?
31808 + h_dir = d_inode(h_root);
31809 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
31810 + h_path->dentry = base[AuBrWh_BASE].dentry;
31811 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
31812 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
31815 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
31816 + if (unlikely(err))
31819 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31821 + err = au_whdir(h_dir, h_path);
31822 + if (unlikely(err))
31824 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
31826 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31827 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
31829 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31830 + err = au_whdir(h_dir, h_path);
31831 + if (unlikely(err))
31833 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
31840 + * initialize the whiteout base file/dir for @br.
31842 +int au_wh_init(struct au_branch *br, struct super_block *sb)
31845 + const unsigned char do_plink
31846 + = !!au_opt_test(au_mntflags(sb), PLINK);
31847 + struct inode *h_dir;
31848 + struct path path = br->br_path;
31849 + struct dentry *h_root = path.dentry;
31850 + struct au_wbr *wbr = br->br_wbr;
31851 + static const struct qstr base_name[] = {
31852 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
31853 + sizeof(AUFS_BASE_NAME) - 1),
31854 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
31855 + sizeof(AUFS_PLINKDIR_NAME) - 1),
31856 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
31857 + sizeof(AUFS_ORPHDIR_NAME) - 1)
31859 + struct au_wh_base base[] = {
31860 + [AuBrWh_BASE] = {
31861 + .name = base_name + AuBrWh_BASE,
31864 + [AuBrWh_PLINK] = {
31865 + .name = base_name + AuBrWh_PLINK,
31868 + [AuBrWh_ORPH] = {
31869 + .name = base_name + AuBrWh_ORPH,
31875 + WbrWhMustWriteLock(wbr);
31877 + for (i = 0; i < AuBrWh_Last; i++) {
31878 + /* doubly whiteouted */
31879 + struct dentry *d;
31881 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
31882 + err = PTR_ERR(d);
31886 + base[i].dentry = d;
31888 + && wbr->wbr_wh[i]
31889 + && wbr->wbr_wh[i] != base[i].dentry);
31893 + for (i = 0; i < AuBrWh_Last; i++) {
31894 + dput(wbr->wbr_wh[i]);
31895 + wbr->wbr_wh[i] = NULL;
31899 + if (!au_br_writable(br->br_perm)) {
31900 + h_dir = d_inode(h_root);
31901 + au_wh_init_ro(h_dir, base, &path);
31902 + } else if (!au_br_wh_linkable(br->br_perm)) {
31903 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
31909 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
31915 + goto out; /* success */
31918 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
31919 + err, h_root, au_sbtype(h_root->d_sb));
31921 + for (i = 0; i < AuBrWh_Last; i++)
31922 + dput(base[i].dentry);
31926 +/* ---------------------------------------------------------------------- */
31928 + * whiteouts are all hard-linked usually.
31929 + * when its link count reaches a ceiling, we create a new whiteout base
31930 + * asynchronously.
31933 +struct reinit_br_wh {
31934 + struct super_block *sb;
31935 + struct au_branch *br;
31938 +static void reinit_br_wh(void *arg)
31941 + aufs_bindex_t bindex;
31942 + struct path h_path;
31943 + struct reinit_br_wh *a = arg;
31944 + struct au_wbr *wbr;
31945 + struct inode *dir, *delegated;
31946 + struct dentry *h_root;
31947 + struct au_hinode *hdir;
31950 + wbr = a->br->br_wbr;
31951 + /* big aufs lock */
31952 + si_noflush_write_lock(a->sb);
31953 + if (!au_br_writable(a->br->br_perm))
31955 + bindex = au_br_index(a->sb, a->br->br_id);
31956 + if (unlikely(bindex < 0))
31959 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
31960 + dir = d_inode(a->sb->s_root);
31961 + hdir = au_hi(dir, bindex);
31962 + h_root = au_h_dptr(a->sb->s_root, bindex);
31963 + AuDebugOn(h_root != au_br_dentry(a->br));
31965 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
31966 + wbr_wh_write_lock(wbr);
31967 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
31970 + h_path.dentry = wbr->wbr_whbase;
31971 + h_path.mnt = au_br_mnt(a->br);
31972 + delegated = NULL;
31973 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
31975 + if (unlikely(err == -EWOULDBLOCK)) {
31976 + pr_warn("cannot retry for NFSv4 delegation"
31977 + " for an internal unlink\n");
31981 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
31984 + dput(wbr->wbr_whbase);
31985 + wbr->wbr_whbase = NULL;
31987 + err = au_wh_init(a->br, a->sb);
31988 + wbr_wh_write_unlock(wbr);
31989 + au_hn_imtx_unlock(hdir);
31990 + di_read_unlock(a->sb->s_root, AuLock_IR);
31992 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
31996 + atomic_dec(&wbr->wbr_wh_running);
31997 + atomic_dec(&a->br->br_count);
31998 + si_write_unlock(a->sb);
31999 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32001 + if (unlikely(err))
32002 + AuIOErr("err %d\n", err);
32005 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32007 + int do_dec, wkq_err;
32008 + struct reinit_br_wh *arg;
32011 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32014 + /* ignore ENOMEM */
32015 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32018 + * dec(wh_running), kfree(arg) and dec(br_count)
32019 + * in reinit function
32023 + atomic_inc(&br->br_count);
32024 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32025 + if (unlikely(wkq_err)) {
32026 + atomic_dec(&br->br_wbr->wbr_wh_running);
32027 + atomic_dec(&br->br_count);
32035 + atomic_dec(&br->br_wbr->wbr_wh_running);
32038 +/* ---------------------------------------------------------------------- */
32041 + * create the whiteout @wh.
32043 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32044 + struct dentry *wh)
32047 + struct path h_path = {
32050 + struct au_branch *br;
32051 + struct au_wbr *wbr;
32052 + struct dentry *h_parent;
32053 + struct inode *h_dir, *delegated;
32055 + h_parent = wh->d_parent; /* dir inode is locked */
32056 + h_dir = d_inode(h_parent);
32057 + IMustLock(h_dir);
32059 + br = au_sbr(sb, bindex);
32060 + h_path.mnt = au_br_mnt(br);
32061 + wbr = br->br_wbr;
32062 + wbr_wh_read_lock(wbr);
32063 + if (wbr->wbr_whbase) {
32064 + delegated = NULL;
32065 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32066 + if (unlikely(err == -EWOULDBLOCK)) {
32067 + pr_warn("cannot retry for NFSv4 delegation"
32068 + " for an internal link\n");
32071 + if (!err || err != -EMLINK)
32074 + /* link count full. re-initialize br_whbase. */
32075 + kick_reinit_br_wh(sb, br);
32078 + /* return this error in this context */
32079 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32081 + au_fhsm_wrote(sb, bindex, /*force*/0);
32084 + wbr_wh_read_unlock(wbr);
32088 +/* ---------------------------------------------------------------------- */
32091 + * create or remove the diropq.
32093 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32094 + unsigned int flags)
32096 + struct dentry *opq_dentry, *h_dentry;
32097 + struct super_block *sb;
32098 + struct au_branch *br;
32101 + sb = dentry->d_sb;
32102 + br = au_sbr(sb, bindex);
32103 + h_dentry = au_h_dptr(dentry, bindex);
32104 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32105 + if (IS_ERR(opq_dentry))
32108 + if (au_ftest_diropq(flags, CREATE)) {
32109 + err = link_or_create_wh(sb, bindex, opq_dentry);
32111 + au_set_dbdiropq(dentry, bindex);
32112 + goto out; /* success */
32115 + struct path tmp = {
32116 + .dentry = opq_dentry,
32117 + .mnt = au_br_mnt(br)
32119 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
32121 + au_set_dbdiropq(dentry, -1);
32123 + dput(opq_dentry);
32124 + opq_dentry = ERR_PTR(err);
32127 + return opq_dentry;
32130 +struct do_diropq_args {
32131 + struct dentry **errp;
32132 + struct dentry *dentry;
32133 + aufs_bindex_t bindex;
32134 + unsigned int flags;
32137 +static void call_do_diropq(void *args)
32139 + struct do_diropq_args *a = args;
32140 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32143 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32144 + unsigned int flags)
32146 + struct dentry *diropq, *h_dentry;
32148 + h_dentry = au_h_dptr(dentry, bindex);
32149 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
32150 + diropq = do_diropq(dentry, bindex, flags);
32153 + struct do_diropq_args args = {
32155 + .dentry = dentry,
32156 + .bindex = bindex,
32160 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32161 + if (unlikely(wkq_err))
32162 + diropq = ERR_PTR(wkq_err);
32168 +/* ---------------------------------------------------------------------- */
32171 + * lookup whiteout dentry.
32172 + * @h_parent: lower parent dentry which must exist and be locked
32173 + * @base_name: name of dentry which will be whiteouted
32174 + * returns dentry for whiteout.
32176 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32177 + struct au_branch *br)
32180 + struct qstr wh_name;
32181 + struct dentry *wh_dentry;
32183 + err = au_wh_name_alloc(&wh_name, base_name);
32184 + wh_dentry = ERR_PTR(err);
32186 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32187 + kfree(wh_name.name);
32189 + return wh_dentry;
32193 + * link/create a whiteout for @dentry on @bindex.
32195 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32196 + struct dentry *h_parent)
32198 + struct dentry *wh_dentry;
32199 + struct super_block *sb;
32202 + sb = dentry->d_sb;
32203 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32204 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
32205 + err = link_or_create_wh(sb, bindex, wh_dentry);
32207 + au_set_dbwh(dentry, bindex);
32208 + au_fhsm_wrote(sb, bindex, /*force*/0);
32211 + wh_dentry = ERR_PTR(err);
32215 + return wh_dentry;
32218 +/* ---------------------------------------------------------------------- */
32220 +/* Delete all whiteouts in this directory on branch bindex. */
32221 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32222 + aufs_bindex_t bindex, struct au_branch *br)
32225 + unsigned long ul, n;
32226 + struct qstr wh_name;
32228 + struct hlist_head *head;
32229 + struct au_vdir_wh *pos;
32230 + struct au_vdir_destr *str;
32233 + p = (void *)__get_free_page(GFP_NOFS);
32234 + wh_name.name = p;
32235 + if (unlikely(!wh_name.name))
32239 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32240 + p += AUFS_WH_PFX_LEN;
32241 + n = whlist->nh_num;
32242 + head = whlist->nh_head;
32243 + for (ul = 0; !err && ul < n; ul++, head++) {
32244 + hlist_for_each_entry(pos, head, wh_hash) {
32245 + if (pos->wh_bindex != bindex)
32248 + str = &pos->wh_str;
32249 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32250 + memcpy(p, str->name, str->len);
32251 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32252 + err = unlink_wh_name(h_dentry, &wh_name, br);
32257 + AuIOErr("whiteout name too long %.*s\n",
32258 + str->len, str->name);
32263 + free_page((unsigned long)wh_name.name);
32269 +struct del_wh_children_args {
32271 + struct dentry *h_dentry;
32272 + struct au_nhash *whlist;
32273 + aufs_bindex_t bindex;
32274 + struct au_branch *br;
32277 +static void call_del_wh_children(void *args)
32279 + struct del_wh_children_args *a = args;
32280 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32283 +/* ---------------------------------------------------------------------- */
32285 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32287 + struct au_whtmp_rmdir *whtmp;
32289 + unsigned int rdhash;
32291 + SiMustAnyLock(sb);
32293 + whtmp = kzalloc(sizeof(*whtmp), gfp);
32294 + if (unlikely(!whtmp)) {
32295 + whtmp = ERR_PTR(-ENOMEM);
32299 + /* no estimation for dir size */
32300 + rdhash = au_sbi(sb)->si_rdhash;
32302 + rdhash = AUFS_RDHASH_DEF;
32303 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32304 + if (unlikely(err)) {
32306 + whtmp = ERR_PTR(err);
32313 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
32316 + atomic_dec(&whtmp->br->br_count);
32317 + dput(whtmp->wh_dentry);
32318 + iput(whtmp->dir);
32319 + au_nhash_wh_free(&whtmp->whlist);
32324 + * rmdir the whiteouted temporary named dir @h_dentry.
32325 + * @whlist: whiteouted children.
32327 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32328 + struct dentry *wh_dentry, struct au_nhash *whlist)
32331 + unsigned int h_nlink;
32332 + struct path h_tmp;
32333 + struct inode *wh_inode, *h_dir;
32334 + struct au_branch *br;
32336 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
32337 + IMustLock(h_dir);
32339 + br = au_sbr(dir->i_sb, bindex);
32340 + wh_inode = d_inode(wh_dentry);
32341 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
32344 + * someone else might change some whiteouts while we were sleeping.
32345 + * it means this whlist may have an obsoleted entry.
32347 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
32348 + err = del_wh_children(wh_dentry, whlist, bindex, br);
32351 + struct del_wh_children_args args = {
32353 + .h_dentry = wh_dentry,
32354 + .whlist = whlist,
32355 + .bindex = bindex,
32359 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
32360 + if (unlikely(wkq_err))
32363 + mutex_unlock(&wh_inode->i_mutex);
32366 + h_tmp.dentry = wh_dentry;
32367 + h_tmp.mnt = au_br_mnt(br);
32368 + h_nlink = h_dir->i_nlink;
32369 + err = vfsub_rmdir(h_dir, &h_tmp);
32370 + /* some fs doesn't change the parent nlink in some cases */
32371 + h_nlink -= h_dir->i_nlink;
32375 + if (au_ibstart(dir) == bindex) {
32376 + /* todo: dir->i_mutex is necessary */
32377 + au_cpup_attr_timesizes(dir);
32379 + vfsub_drop_nlink(dir);
32381 + return 0; /* success */
32384 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
32388 +static void call_rmdir_whtmp(void *args)
32391 + aufs_bindex_t bindex;
32392 + struct au_whtmp_rmdir *a = args;
32393 + struct super_block *sb;
32394 + struct dentry *h_parent;
32395 + struct inode *h_dir;
32396 + struct au_hinode *hdir;
32398 + /* rmdir by nfsd may cause deadlock with this i_mutex */
32399 + /* mutex_lock(&a->dir->i_mutex); */
32401 + sb = a->dir->i_sb;
32402 + si_read_lock(sb, !AuLock_FLUSH);
32403 + if (!au_br_writable(a->br->br_perm))
32405 + bindex = au_br_index(sb, a->br->br_id);
32406 + if (unlikely(bindex < 0))
32410 + ii_write_lock_parent(a->dir);
32411 + h_parent = dget_parent(a->wh_dentry);
32412 + h_dir = d_inode(h_parent);
32413 + hdir = au_hi(a->dir, bindex);
32414 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
32415 + if (unlikely(err))
32417 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32418 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
32421 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
32422 + au_hn_imtx_unlock(hdir);
32423 + vfsub_mnt_drop_write(au_br_mnt(a->br));
32427 + ii_write_unlock(a->dir);
32429 + /* mutex_unlock(&a->dir->i_mutex); */
32430 + au_whtmp_rmdir_free(a);
32431 + si_read_unlock(sb);
32432 + au_nwt_done(&au_sbi(sb)->si_nowait);
32433 + if (unlikely(err))
32434 + AuIOErr("err %d\n", err);
32437 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32438 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
32441 + struct super_block *sb;
32445 + /* all post-process will be done in do_rmdir_whtmp(). */
32447 + args->dir = au_igrab(dir);
32448 + args->br = au_sbr(sb, bindex);
32449 + atomic_inc(&args->br->br_count);
32450 + args->wh_dentry = dget(wh_dentry);
32451 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
32452 + if (unlikely(wkq_err)) {
32453 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
32454 + au_whtmp_rmdir_free(args);
32457 diff -urNp -x '*.orig' linux-4.4/fs/aufs/whout.h linux-4.4/fs/aufs/whout.h
32458 --- linux-4.4/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
32459 +++ linux-4.4/fs/aufs/whout.h 2021-02-24 17:28:14.415475161 +0100
32462 + * Copyright (C) 2005-2016 Junjiro R. Okajima
32464 + * This program, aufs is free software; you can redistribute it and/or modify
32465 + * it under the terms of the GNU General Public License as published by
32466 + * the Free Software Foundation; either version 2 of the License, or
32467 + * (at your option) any later version.
32469 + * This program is distributed in the hope that it will be useful,
32470 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32471 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32472 + * GNU General Public License for more details.
32474 + * You should have received a copy of the GNU General Public License
32475 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32479 + * whiteout for logical deletion and opaque directory
32482 +#ifndef __AUFS_WHOUT_H__
32483 +#define __AUFS_WHOUT_H__
32490 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
32491 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
32492 +int au_diropq_test(struct dentry *h_dentry);
32494 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32495 + struct qstr *prefix);
32496 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
32497 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32498 + struct dentry *dentry);
32499 +int au_wh_init(struct au_branch *br, struct super_block *sb);
32501 +/* diropq flags */
32502 +#define AuDiropq_CREATE 1
32503 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
32504 +#define au_fset_diropq(flags, name) \
32505 + do { (flags) |= AuDiropq_##name; } while (0)
32506 +#define au_fclr_diropq(flags, name) \
32507 + do { (flags) &= ~AuDiropq_##name; } while (0)
32509 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32510 + unsigned int flags);
32511 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32512 + struct au_branch *br);
32513 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32514 + struct dentry *h_parent);
32516 +/* real rmdir for the whiteout-ed dir */
32517 +struct au_whtmp_rmdir {
32518 + struct inode *dir;
32519 + struct au_branch *br;
32520 + struct dentry *wh_dentry;
32521 + struct au_nhash whlist;
32524 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
32525 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
32526 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32527 + struct dentry *wh_dentry, struct au_nhash *whlist);
32528 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32529 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
32531 +/* ---------------------------------------------------------------------- */
32533 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
32534 + aufs_bindex_t bindex)
32536 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
32539 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
32541 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
32544 +#endif /* __KERNEL__ */
32545 +#endif /* __AUFS_WHOUT_H__ */
32546 diff -urNp -x '*.orig' linux-4.4/fs/aufs/wkq.c linux-4.4/fs/aufs/wkq.c
32547 --- linux-4.4/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
32548 +++ linux-4.4/fs/aufs/wkq.c 2021-02-24 17:28:14.415475161 +0100
32551 + * Copyright (C) 2005-2016 Junjiro R. Okajima
32553 + * This program, aufs is free software; you can redistribute it and/or modify
32554 + * it under the terms of the GNU General Public License as published by
32555 + * the Free Software Foundation; either version 2 of the License, or
32556 + * (at your option) any later version.
32558 + * This program is distributed in the hope that it will be useful,
32559 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32560 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32561 + * GNU General Public License for more details.
32563 + * You should have received a copy of the GNU General Public License
32564 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32568 + * workqueue for asynchronous/super-io operations
32569 + * todo: try new dredential scheme
32572 +#include <linux/module.h>
32575 +/* internal workqueue named AUFS_WKQ_NAME */
32577 +static struct workqueue_struct *au_wkq;
32579 +struct au_wkinfo {
32580 + struct work_struct wk;
32581 + struct kobject *kobj;
32583 + unsigned int flags; /* see wkq.h */
32585 + au_wkq_func_t func;
32588 + struct completion *comp;
32591 +/* ---------------------------------------------------------------------- */
32593 +static void wkq_func(struct work_struct *wk)
32595 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
32597 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
32598 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
32600 + wkinfo->func(wkinfo->args);
32601 + if (au_ftest_wkq(wkinfo->flags, WAIT))
32602 + complete(wkinfo->comp);
32604 + kobject_put(wkinfo->kobj);
32605 + module_put(THIS_MODULE); /* todo: ?? */
32611 + * Since struct completion is large, try allocating it dynamically.
32613 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
32614 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
32616 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32618 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
32620 + init_completion(*comp);
32621 + wkinfo->comp = *comp;
32627 +static void au_wkq_comp_free(struct completion *comp)
32635 +#define AuWkqCompDeclare(name) \
32636 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
32637 + struct completion *comp = &_ ## name
32639 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32641 + wkinfo->comp = *comp;
32645 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
32649 +#endif /* 4KSTACKS */
32651 +static void au_wkq_run(struct au_wkinfo *wkinfo)
32653 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
32654 + if (au_wkq_test()) {
32655 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
32656 + " due to a dead dir by UDBA?\n");
32657 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
32660 + au_dbg_verify_kthread();
32662 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
32663 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
32664 + queue_work(au_wkq, &wkinfo->wk);
32666 + INIT_WORK(&wkinfo->wk, wkq_func);
32667 + schedule_work(&wkinfo->wk);
32672 + * Be careful. It is easy to make deadlock happen.
32673 + * processA: lock, wkq and wait
32674 + * processB: wkq and wait, lock in wkq
32677 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
32680 + AuWkqCompDeclare(comp);
32681 + struct au_wkinfo wkinfo = {
32687 + err = au_wkq_comp_alloc(&wkinfo, &comp);
32689 + au_wkq_run(&wkinfo);
32690 + /* no timeout, no interrupt */
32691 + wait_for_completion(wkinfo.comp);
32692 + au_wkq_comp_free(comp);
32693 + destroy_work_on_stack(&wkinfo.wk);
32701 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
32702 + * problem in a concurrent umounting.
32704 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
32705 + unsigned int flags)
32708 + struct au_wkinfo *wkinfo;
32710 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
32713 + * wkq_func() must free this wkinfo.
32714 + * it highly depends upon the implementation of workqueue.
32717 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
32719 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
32720 + wkinfo->flags = flags & ~AuWkq_WAIT;
32721 + wkinfo->func = func;
32722 + wkinfo->args = args;
32723 + wkinfo->comp = NULL;
32724 + kobject_get(wkinfo->kobj);
32725 + __module_get(THIS_MODULE); /* todo: ?? */
32727 + au_wkq_run(wkinfo);
32730 + au_nwt_done(&au_sbi(sb)->si_nowait);
32736 +/* ---------------------------------------------------------------------- */
32738 +void au_nwt_init(struct au_nowait_tasks *nwt)
32740 + atomic_set(&nwt->nw_len, 0);
32741 + /* smp_mb(); */ /* atomic_set */
32742 + init_waitqueue_head(&nwt->nw_wq);
32745 +void au_wkq_fin(void)
32747 + destroy_workqueue(au_wkq);
32750 +int __init au_wkq_init(void)
32755 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
32756 + if (IS_ERR(au_wkq))
32757 + err = PTR_ERR(au_wkq);
32758 + else if (!au_wkq)
32763 diff -urNp -x '*.orig' linux-4.4/fs/aufs/wkq.h linux-4.4/fs/aufs/wkq.h
32764 --- linux-4.4/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
32765 +++ linux-4.4/fs/aufs/wkq.h 2021-02-24 17:28:14.415475161 +0100
32768 + * Copyright (C) 2005-2016 Junjiro R. Okajima
32770 + * This program, aufs is free software; you can redistribute it and/or modify
32771 + * it under the terms of the GNU General Public License as published by
32772 + * the Free Software Foundation; either version 2 of the License, or
32773 + * (at your option) any later version.
32775 + * This program is distributed in the hope that it will be useful,
32776 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32777 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32778 + * GNU General Public License for more details.
32780 + * You should have received a copy of the GNU General Public License
32781 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32785 + * workqueue for asynchronous/super-io operations
32786 + * todo: try new credentials management scheme
32789 +#ifndef __AUFS_WKQ_H__
32790 +#define __AUFS_WKQ_H__
32794 +struct super_block;
32796 +/* ---------------------------------------------------------------------- */
32799 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
32801 +struct au_nowait_tasks {
32803 + wait_queue_head_t nw_wq;
32806 +/* ---------------------------------------------------------------------- */
32808 +typedef void (*au_wkq_func_t)(void *args);
32811 +#define AuWkq_WAIT 1
32812 +#define AuWkq_NEST (1 << 1)
32813 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
32814 +#define au_fset_wkq(flags, name) \
32815 + do { (flags) |= AuWkq_##name; } while (0)
32816 +#define au_fclr_wkq(flags, name) \
32817 + do { (flags) &= ~AuWkq_##name; } while (0)
32819 +#ifndef CONFIG_AUFS_HNOTIFY
32821 +#define AuWkq_NEST 0
32825 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
32826 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
32827 + unsigned int flags);
32828 +void au_nwt_init(struct au_nowait_tasks *nwt);
32829 +int __init au_wkq_init(void);
32830 +void au_wkq_fin(void);
32832 +/* ---------------------------------------------------------------------- */
32834 +static inline int au_wkq_test(void)
32836 + return current->flags & PF_WQ_WORKER;
32839 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
32841 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
32844 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
32846 + if (atomic_dec_and_test(&nwt->nw_len))
32847 + wake_up_all(&nwt->nw_wq);
32850 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
32852 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
32856 +#endif /* __KERNEL__ */
32857 +#endif /* __AUFS_WKQ_H__ */
32858 diff -urNp -x '*.orig' linux-4.4/fs/aufs/xattr.c linux-4.4/fs/aufs/xattr.c
32859 --- linux-4.4/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
32860 +++ linux-4.4/fs/aufs/xattr.c 2021-02-24 17:28:14.415475161 +0100
32863 + * Copyright (C) 2014-2016 Junjiro R. Okajima
32865 + * This program, aufs is free software; you can redistribute it and/or modify
32866 + * it under the terms of the GNU General Public License as published by
32867 + * the Free Software Foundation; either version 2 of the License, or
32868 + * (at your option) any later version.
32870 + * This program is distributed in the hope that it will be useful,
32871 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32872 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32873 + * GNU General Public License for more details.
32875 + * You should have received a copy of the GNU General Public License
32876 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32880 + * handling xattr functions
32883 +#include <linux/xattr.h>
32886 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
32888 + if (!ignore_flags)
32896 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
32901 +#define cmp(brattr, prefix) do { \
32902 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
32903 + XATTR_##prefix##_PREFIX_LEN)) { \
32904 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
32910 + cmp(SEC, SECURITY);
32911 + cmp(SYS, SYSTEM);
32912 + cmp(TR, TRUSTED);
32916 + if (ignore_flags & AuBrAttr_ICEX_OTH)
32923 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
32925 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
32926 + char *name, char **buf, unsigned int ignore_flags,
32927 + unsigned int verbose)
32931 + struct inode *h_idst;
32933 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
32935 + if (unlikely(err <= 0)) {
32936 + if (err == -ENODATA
32937 + || (err == -EOPNOTSUPP
32938 + && ((ignore_flags & au_xattr_out_of_list)
32939 + || (au_test_nfs_noacl(d_inode(h_src))
32940 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
32942 + XATTR_NAME_POSIX_ACL_DEFAULT))))
32945 + if (err && (verbose || au_debug_test()))
32946 + pr_err("%s, err %d\n", name, err);
32950 + /* unlock it temporary */
32951 + h_idst = d_inode(h_dst);
32952 + mutex_unlock(&h_idst->i_mutex);
32953 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
32954 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
32955 + if (unlikely(err)) {
32956 + if (verbose || au_debug_test())
32957 + pr_err("%s, err %d\n", name, err);
32958 + err = au_xattr_ignore(err, name, ignore_flags);
32965 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
32966 + unsigned int verbose)
32968 + int err, unlocked, acl_access, acl_default;
32970 + struct inode *h_isrc, *h_idst;
32971 + char *value, *p, *o, *e;
32973 + /* try stopping to update the source inode while we are referencing */
32974 + /* there should not be the parent-child relationship between them */
32975 + h_isrc = d_inode(h_src);
32976 + h_idst = d_inode(h_dst);
32977 + mutex_unlock(&h_idst->i_mutex);
32978 + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
32979 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
32982 + /* some filesystems don't list POSIX ACL, for example tmpfs */
32983 + ssz = vfs_listxattr(h_src, NULL, 0);
32985 + if (unlikely(err < 0)) {
32987 + if (err == -ENODATA
32988 + || err == -EOPNOTSUPP)
32989 + err = 0; /* ignore */
32998 + p = kmalloc(ssz, GFP_NOFS);
33000 + if (unlikely(!p))
33002 + err = vfs_listxattr(h_src, p, ssz);
33004 + mutex_unlock(&h_isrc->i_mutex);
33006 + AuDbg("err %d, ssz %zd\n", err, ssz);
33007 + if (unlikely(err < 0))
33015 + while (!err && p < e) {
33016 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33017 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33018 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33019 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33021 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
33023 + p += strlen(p) + 1;
33026 + ignore_flags |= au_xattr_out_of_list;
33027 + if (!err && !acl_access) {
33028 + err = au_do_cpup_xattr(h_dst, h_src,
33029 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33030 + ignore_flags, verbose);
33033 + if (!err && !acl_default) {
33034 + err = au_do_cpup_xattr(h_dst, h_src,
33035 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33036 + ignore_flags, verbose);
33046 + mutex_unlock(&h_isrc->i_mutex);
33051 +/* ---------------------------------------------------------------------- */
33058 +struct au_lgxattr {
33066 + const char *name;
33073 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33076 + struct path h_path;
33077 + struct super_block *sb;
33079 + sb = dentry->d_sb;
33080 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33081 + if (unlikely(err))
33083 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33084 + if (unlikely(err))
33086 + if (unlikely(!h_path.dentry))
33087 + /* illegally overlapped or something */
33088 + goto out_di; /* pretending success */
33090 + /* always topmost entry only */
33091 + switch (arg->type) {
33092 + case AU_XATTR_LIST:
33093 + err = vfs_listxattr(h_path.dentry,
33094 + arg->u.list.list, arg->u.list.size);
33096 + case AU_XATTR_GET:
33097 + err = vfs_getxattr(h_path.dentry,
33098 + arg->u.get.name, arg->u.get.value,
33099 + arg->u.get.size);
33104 + di_read_unlock(dentry, AuLock_IR);
33106 + si_read_unlock(sb);
33112 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33114 + struct au_lgxattr arg = {
33115 + .type = AU_XATTR_LIST,
33122 + return au_lgxattr(dentry, &arg);
33125 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
33128 + struct au_lgxattr arg = {
33129 + .type = AU_XATTR_GET,
33137 + return au_lgxattr(dentry, &arg);
33140 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33141 + size_t size, int flags)
33143 + struct au_srxattr arg = {
33144 + .type = AU_XATTR_SET,
33153 + return au_srxattr(dentry, &arg);
33156 +int aufs_removexattr(struct dentry *dentry, const char *name)
33158 + struct au_srxattr arg = {
33159 + .type = AU_XATTR_REMOVE,
33165 + return au_srxattr(dentry, &arg);
33168 +/* ---------------------------------------------------------------------- */
33171 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33172 + const char *name, size_t name_len, int type)
33174 + return aufs_listxattr(dentry, list, list_size);
33177 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33178 + size_t size, int type)
33180 + return aufs_getxattr(dentry, name, buffer, size);
33183 +static int au_xattr_set(struct dentry *dentry, const char *name,
33184 + const void *value, size_t size, int flags, int type)
33186 + return aufs_setxattr(dentry, name, value, size, flags);
33189 +static const struct xattr_handler au_xattr_handler = {
33190 + /* no prefix, no flags */
33191 + .list = au_xattr_list,
33192 + .get = au_xattr_get,
33193 + .set = au_xattr_set
33194 + /* why no remove? */
33197 +static const struct xattr_handler *au_xattr_handlers[] = {
33198 + &au_xattr_handler
33201 +void au_xattr_init(struct super_block *sb)
33203 + /* sb->s_xattr = au_xattr_handlers; */
33206 diff -urNp -x '*.orig' linux-4.4/fs/aufs/xino.c linux-4.4/fs/aufs/xino.c
33207 --- linux-4.4/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33208 +++ linux-4.4/fs/aufs/xino.c 2021-02-24 17:28:14.415475161 +0100
33211 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33213 + * This program, aufs is free software; you can redistribute it and/or modify
33214 + * it under the terms of the GNU General Public License as published by
33215 + * the Free Software Foundation; either version 2 of the License, or
33216 + * (at your option) any later version.
33218 + * This program is distributed in the hope that it will be useful,
33219 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33220 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33221 + * GNU General Public License for more details.
33223 + * You should have received a copy of the GNU General Public License
33224 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33228 + * external inode number translation table and bitmap
33231 +#include <linux/seq_file.h>
33232 +#include <linux/statfs.h>
33235 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33236 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
33240 + mm_segment_t oldfs;
33247 + oldfs = get_fs();
33248 + set_fs(KERNEL_DS);
33250 + /* todo: signal_pending? */
33251 + err = func(file, buf.u, size, pos);
33252 + } while (err == -EAGAIN || err == -EINTR);
33255 +#if 0 /* reserved for future use */
33257 + fsnotify_access(file->f_path.dentry);
33263 +/* ---------------------------------------------------------------------- */
33265 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
33266 + size_t size, loff_t *pos);
33268 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
33269 + size_t size, loff_t *pos)
33272 + mm_segment_t oldfs;
33275 + const char __user *u;
33278 + const int prevent_endless = 10;
33282 + oldfs = get_fs();
33283 + set_fs(KERNEL_DS);
33285 + err = func(file, buf.u, size, pos);
33286 + if (err == -EINTR
33287 + && !au_wkq_test()
33288 + && fatal_signal_pending(current)) {
33290 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
33291 + BUG_ON(err == -EINTR);
33292 + oldfs = get_fs();
33293 + set_fs(KERNEL_DS);
33295 + } while (i++ < prevent_endless
33296 + && (err == -EAGAIN || err == -EINTR));
33299 +#if 0 /* reserved for future use */
33301 + fsnotify_modify(file->f_path.dentry);
33307 +struct do_xino_fwrite_args {
33309 + vfs_writef_t func;
33310 + struct file *file;
33316 +static void call_do_xino_fwrite(void *args)
33318 + struct do_xino_fwrite_args *a = args;
33319 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
33322 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
33323 + size_t size, loff_t *pos)
33327 + struct do_xino_fwrite_args args = {
33337 + * it breaks RLIMIT_FSIZE and normal user's limit,
33338 + * users should care about quota and real 'filesystem full.'
33340 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
33341 + if (unlikely(wkq_err))
33347 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
33348 + size_t size, loff_t *pos)
33352 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
33354 + err = do_xino_fwrite(func, file, buf, size, pos);
33357 + err = xino_fwrite_wkq(func, file, buf, size, pos);
33362 +/* ---------------------------------------------------------------------- */
33365 + * create a new xinofile at the same place/path as @base_file.
33367 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
33369 + struct file *file;
33370 + struct dentry *base, *parent;
33371 + struct inode *dir, *delegated;
33372 + struct qstr *name;
33373 + struct path path;
33376 + base = base_file->f_path.dentry;
33377 + parent = base->d_parent; /* dir inode is locked */
33378 + dir = d_inode(parent);
33381 + file = ERR_PTR(-EINVAL);
33382 + name = &base->d_name;
33383 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
33384 + if (IS_ERR(path.dentry)) {
33385 + file = (void *)path.dentry;
33386 + pr_err("%pd lookup err %ld\n",
33387 + base, PTR_ERR(path.dentry));
33391 + /* no need to mnt_want_write() since we call dentry_open() later */
33392 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
33393 + if (unlikely(err)) {
33394 + file = ERR_PTR(err);
33395 + pr_err("%pd create err %d\n", base, err);
33399 + path.mnt = base_file->f_path.mnt;
33400 + file = vfsub_dentry_open(&path,
33401 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33402 + /* | __FMODE_NONOTIFY */);
33403 + if (IS_ERR(file)) {
33404 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
33408 + delegated = NULL;
33409 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
33410 + if (unlikely(err == -EWOULDBLOCK)) {
33411 + pr_warn("cannot retry for NFSv4 delegation"
33412 + " for an internal unlink\n");
33415 + if (unlikely(err)) {
33416 + pr_err("%pd unlink err %d\n", base, err);
33421 + /* no one can touch copy_src xino */
33422 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
33423 + if (unlikely(err)) {
33424 + pr_err("%pd copy err %d\n", base, err);
33428 + goto out_dput; /* success */
33432 + file = ERR_PTR(err);
33434 + dput(path.dentry);
33439 +struct au_xino_lock_dir {
33440 + struct au_hinode *hdir;
33441 + struct dentry *parent;
33442 + struct mutex *mtx;
33445 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
33446 + struct au_xino_lock_dir *ldir)
33448 + aufs_bindex_t brid, bindex;
33450 + ldir->hdir = NULL;
33452 + brid = au_xino_brid(sb);
33454 + bindex = au_br_index(sb, brid);
33455 + if (bindex >= 0) {
33456 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
33457 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
33459 + ldir->parent = dget_parent(xino->f_path.dentry);
33460 + ldir->mtx = &d_inode(ldir->parent)->i_mutex;
33461 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
33465 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
33468 + au_hn_imtx_unlock(ldir->hdir);
33470 + mutex_unlock(ldir->mtx);
33471 + dput(ldir->parent);
33475 +/* ---------------------------------------------------------------------- */
33477 +/* trucate xino files asynchronously */
33479 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
33482 + unsigned long jiffy;
33484 + aufs_bindex_t bi, bend;
33485 + struct kstatfs *st;
33486 + struct au_branch *br;
33487 + struct file *new_xino, *file;
33488 + struct super_block *h_sb;
33489 + struct au_xino_lock_dir ldir;
33492 + st = kmalloc(sizeof(*st), GFP_NOFS);
33493 + if (unlikely(!st))
33497 + bend = au_sbend(sb);
33498 + if (unlikely(bindex < 0 || bend < bindex))
33500 + br = au_sbr(sb, bindex);
33501 + file = br->br_xino.xi_file;
33505 + err = vfs_statfs(&file->f_path, st);
33506 + if (unlikely(err))
33507 + AuErr1("statfs err %d, ignored\n", err);
33509 + blocks = file_inode(file)->i_blocks;
33510 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33511 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
33513 + au_xino_lock_dir(sb, file, &ldir);
33514 + /* mnt_want_write() is unnecessary here */
33515 + new_xino = au_xino_create2(file, file);
33516 + au_xino_unlock_dir(&ldir);
33517 + err = PTR_ERR(new_xino);
33518 + if (IS_ERR(new_xino)) {
33519 + pr_err("err %d, ignored\n", err);
33524 + br->br_xino.xi_file = new_xino;
33526 + h_sb = au_br_sb(br);
33527 + for (bi = 0; bi <= bend; bi++) {
33528 + if (unlikely(bi == bindex))
33530 + br = au_sbr(sb, bi);
33531 + if (au_br_sb(br) != h_sb)
33534 + fput(br->br_xino.xi_file);
33535 + br->br_xino.xi_file = new_xino;
33536 + get_file(new_xino);
33539 + err = vfs_statfs(&new_xino->f_path, st);
33541 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33542 + bindex, (u64)file_inode(new_xino)->i_blocks,
33543 + st->f_bfree, st->f_blocks);
33544 + if (file_inode(new_xino)->i_blocks < blocks)
33545 + au_sbi(sb)->si_xino_jiffy = jiffy;
33547 + AuErr1("statfs err %d, ignored\n", err);
33555 +struct xino_do_trunc_args {
33556 + struct super_block *sb;
33557 + struct au_branch *br;
33560 +static void xino_do_trunc(void *_args)
33562 + struct xino_do_trunc_args *args = _args;
33563 + struct super_block *sb;
33564 + struct au_branch *br;
33565 + struct inode *dir;
33567 + aufs_bindex_t bindex;
33571 + dir = d_inode(sb->s_root);
33574 + si_noflush_write_lock(sb);
33575 + ii_read_lock_parent(dir);
33576 + bindex = au_br_index(sb, br->br_id);
33577 + err = au_xino_trunc(sb, bindex);
33578 + ii_read_unlock(dir);
33579 + if (unlikely(err))
33580 + pr_warn("err b%d, (%d)\n", bindex, err);
33581 + atomic_dec(&br->br_xino_running);
33582 + atomic_dec(&br->br_count);
33583 + si_write_unlock(sb);
33584 + au_nwt_done(&au_sbi(sb)->si_nowait);
33588 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
33591 + struct kstatfs st;
33592 + struct au_sbinfo *sbinfo;
33594 + /* todo: si_xino_expire and the ratio should be customizable */
33595 + sbinfo = au_sbi(sb);
33596 + if (time_before(jiffies,
33597 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
33600 + /* truncation border */
33601 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
33602 + if (unlikely(err)) {
33603 + AuErr1("statfs err %d, ignored\n", err);
33606 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
33612 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
33614 + struct xino_do_trunc_args *args;
33617 + if (!xino_trunc_test(sb, br))
33620 + if (atomic_inc_return(&br->br_xino_running) > 1)
33623 + /* lock and kfree() will be called in trunc_xino() */
33624 + args = kmalloc(sizeof(*args), GFP_NOFS);
33625 + if (unlikely(!args)) {
33626 + AuErr1("no memory\n");
33630 + atomic_inc(&br->br_count);
33633 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
33635 + return; /* success */
33637 + pr_err("wkq %d\n", wkq_err);
33638 + atomic_dec(&br->br_count);
33643 + atomic_dec(&br->br_xino_running);
33646 +/* ---------------------------------------------------------------------- */
33648 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
33649 + ino_t h_ino, ino_t ino)
33655 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
33656 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
33659 + pos *= sizeof(ino);
33660 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
33661 + if (sz == sizeof(ino))
33662 + return 0; /* success */
33664 + AuIOErr("write failed (%zd)\n", sz);
33669 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
33670 + * at the position of @h_ino.
33671 + * even if @ino is zero, it is written to the xinofile and means no entry.
33672 + * if the size of the xino file on a specific filesystem exceeds the watermark,
33673 + * try truncating it.
33675 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
33679 + unsigned int mnt_flags;
33680 + struct au_branch *br;
33682 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
33683 + || ((loff_t)-1) > 0);
33684 + SiMustAnyLock(sb);
33686 + mnt_flags = au_mntflags(sb);
33687 + if (!au_opt_test(mnt_flags, XINO))
33690 + br = au_sbr(sb, bindex);
33691 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
33694 + if (au_opt_test(mnt_flags, TRUNC_XINO)
33695 + && au_test_fs_trunc_xino(au_br_sb(br)))
33696 + xino_try_trunc(sb, br);
33697 + return 0; /* success */
33700 + AuIOErr("write failed (%d)\n", err);
33704 +/* ---------------------------------------------------------------------- */
33706 +/* aufs inode number bitmap */
33708 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
33709 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
33713 + AuDebugOn(bit < 0 || page_bits <= bit);
33714 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
33718 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
33720 + AuDebugOn(ino < AUFS_FIRST_INO);
33721 + ino -= AUFS_FIRST_INO;
33722 + *pindex = ino / page_bits;
33723 + *bit = ino % page_bits;
33726 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
33731 + struct au_sbinfo *sbinfo;
33732 + struct file *xib;
33733 + unsigned long *p;
33735 + sbinfo = au_sbi(sb);
33736 + MtxMustLock(&sbinfo->si_xib_mtx);
33737 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
33738 + || !au_opt_test(sbinfo->si_mntflags, XINO));
33740 + if (pindex == sbinfo->si_xib_last_pindex)
33743 + xib = sbinfo->si_xib;
33744 + p = sbinfo->si_xib_buf;
33745 + pos = sbinfo->si_xib_last_pindex;
33746 + pos *= PAGE_SIZE;
33747 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
33748 + if (unlikely(sz != PAGE_SIZE))
33752 + pos *= PAGE_SIZE;
33753 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
33754 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
33756 + memset(p, 0, PAGE_SIZE);
33757 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
33759 + if (sz == PAGE_SIZE) {
33760 + sbinfo->si_xib_last_pindex = pindex;
33761 + return 0; /* success */
33765 + AuIOErr1("write failed (%zd)\n", sz);
33772 +/* ---------------------------------------------------------------------- */
33774 +static void au_xib_clear_bit(struct inode *inode)
33777 + unsigned long pindex;
33778 + struct super_block *sb;
33779 + struct au_sbinfo *sbinfo;
33781 + AuDebugOn(inode->i_nlink);
33783 + sb = inode->i_sb;
33784 + xib_calc_bit(inode->i_ino, &pindex, &bit);
33785 + AuDebugOn(page_bits <= bit);
33786 + sbinfo = au_sbi(sb);
33787 + mutex_lock(&sbinfo->si_xib_mtx);
33788 + err = xib_pindex(sb, pindex);
33790 + clear_bit(bit, sbinfo->si_xib_buf);
33791 + sbinfo->si_xib_next_bit = bit;
33793 + mutex_unlock(&sbinfo->si_xib_mtx);
33796 +/* for s_op->delete_inode() */
33797 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
33800 + unsigned int mnt_flags;
33801 + aufs_bindex_t bindex, bend, bi;
33802 + unsigned char try_trunc;
33803 + struct au_iinfo *iinfo;
33804 + struct super_block *sb;
33805 + struct au_hinode *hi;
33806 + struct inode *h_inode;
33807 + struct au_branch *br;
33808 + vfs_writef_t xwrite;
33810 + sb = inode->i_sb;
33811 + mnt_flags = au_mntflags(sb);
33812 + if (!au_opt_test(mnt_flags, XINO)
33813 + || inode->i_ino == AUFS_ROOT_INO)
33817 + au_xigen_inc(inode);
33818 + au_xib_clear_bit(inode);
33821 + iinfo = au_ii(inode);
33825 + bindex = iinfo->ii_bstart;
33829 + xwrite = au_sbi(sb)->si_xwrite;
33830 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
33831 + hi = iinfo->ii_hinode + bindex;
33832 + bend = iinfo->ii_bend;
33833 + for (; bindex <= bend; bindex++, hi++) {
33834 + h_inode = hi->hi_inode;
33836 + || (!unlinked && h_inode->i_nlink))
33839 + /* inode may not be revalidated */
33840 + bi = au_br_index(sb, hi->hi_id);
33844 + br = au_sbr(sb, bi);
33845 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
33846 + h_inode->i_ino, /*ino*/0);
33847 + if (!err && try_trunc
33848 + && au_test_fs_trunc_xino(au_br_sb(br)))
33849 + xino_try_trunc(sb, br);
33853 +/* get an unused inode number from bitmap */
33854 +ino_t au_xino_new_ino(struct super_block *sb)
33857 + unsigned long *p, pindex, ul, pend;
33858 + struct au_sbinfo *sbinfo;
33859 + struct file *file;
33860 + int free_bit, err;
33862 + if (!au_opt_test(au_mntflags(sb), XINO))
33863 + return iunique(sb, AUFS_FIRST_INO);
33865 + sbinfo = au_sbi(sb);
33866 + mutex_lock(&sbinfo->si_xib_mtx);
33867 + p = sbinfo->si_xib_buf;
33868 + free_bit = sbinfo->si_xib_next_bit;
33869 + if (free_bit < page_bits && !test_bit(free_bit, p))
33870 + goto out; /* success */
33871 + free_bit = find_first_zero_bit(p, page_bits);
33872 + if (free_bit < page_bits)
33873 + goto out; /* success */
33875 + pindex = sbinfo->si_xib_last_pindex;
33876 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
33877 + err = xib_pindex(sb, ul);
33878 + if (unlikely(err))
33880 + free_bit = find_first_zero_bit(p, page_bits);
33881 + if (free_bit < page_bits)
33882 + goto out; /* success */
33885 + file = sbinfo->si_xib;
33886 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
33887 + for (ul = pindex + 1; ul <= pend; ul++) {
33888 + err = xib_pindex(sb, ul);
33889 + if (unlikely(err))
33891 + free_bit = find_first_zero_bit(p, page_bits);
33892 + if (free_bit < page_bits)
33893 + goto out; /* success */
33898 + set_bit(free_bit, p);
33899 + sbinfo->si_xib_next_bit = free_bit + 1;
33900 + pindex = sbinfo->si_xib_last_pindex;
33901 + mutex_unlock(&sbinfo->si_xib_mtx);
33902 + ino = xib_calc_ino(pindex, free_bit);
33903 + AuDbg("i%lu\n", (unsigned long)ino);
33906 + mutex_unlock(&sbinfo->si_xib_mtx);
33912 + * read @ino from xinofile for the specified branch{@sb, @bindex}
33913 + * at the position of @h_ino.
33914 + * if @ino does not exist and @do_new is true, get new one.
33916 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
33922 + struct file *file;
33923 + struct au_sbinfo *sbinfo;
33926 + if (!au_opt_test(au_mntflags(sb), XINO))
33927 + return 0; /* no xino */
33930 + sbinfo = au_sbi(sb);
33932 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
33933 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
33936 + pos *= sizeof(*ino);
33938 + file = au_sbr(sb, bindex)->br_xino.xi_file;
33939 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
33940 + return 0; /* no ino */
33942 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
33943 + if (sz == sizeof(*ino))
33944 + return 0; /* success */
33947 + if (unlikely(sz >= 0)) {
33949 + AuIOErr("xino read error (%zd)\n", sz);
33955 +/* ---------------------------------------------------------------------- */
33957 +/* create and set a new xino file */
33959 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
33961 + struct file *file;
33962 + struct dentry *h_parent, *d;
33963 + struct inode *h_dir, *inode;
33967 + * at mount-time, and the xino file is the default path,
33968 + * hnotify is disabled so we have no notify events to ignore.
33969 + * when a user specified the xino, we cannot get au_hdir to be ignored.
33971 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33972 + /* | __FMODE_NONOTIFY */,
33973 + S_IRUGO | S_IWUGO);
33974 + if (IS_ERR(file)) {
33976 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
33980 + /* keep file count */
33982 + inode = file_inode(file);
33983 + h_parent = dget_parent(file->f_path.dentry);
33984 + h_dir = d_inode(h_parent);
33985 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
33986 + /* mnt_want_write() is unnecessary here */
33987 + /* no delegation since it is just created */
33988 + if (inode->i_nlink)
33989 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
33991 + mutex_unlock(&h_dir->i_mutex);
33993 + if (unlikely(err)) {
33995 + pr_err("unlink %s(%d)\n", fname, err);
34000 + d = file->f_path.dentry;
34001 + if (unlikely(sb == d->d_sb)) {
34003 + pr_err("%s must be outside\n", fname);
34006 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34008 + pr_err("xino doesn't support %s(%s)\n",
34009 + fname, au_sbtype(d->d_sb));
34012 + return file; /* success */
34016 + file = ERR_PTR(err);
34021 + * find another branch who is on the same filesystem of the specified
34022 + * branch{@btgt}. search until @bend.
34024 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34025 + aufs_bindex_t bend)
34027 + aufs_bindex_t bindex;
34028 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34030 + for (bindex = 0; bindex < btgt; bindex++)
34031 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34033 + for (bindex++; bindex <= bend; bindex++)
34034 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34039 +/* ---------------------------------------------------------------------- */
34042 + * initialize the xinofile for the specified branch @br
34043 + * at the place/path where @base_file indicates.
34044 + * test whether another branch is on the same filesystem or not,
34045 + * if @do_test is true.
34047 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34048 + struct file *base_file, int do_test)
34052 + aufs_bindex_t bend, bindex;
34053 + struct au_branch *shared_br, *b;
34054 + struct file *file;
34055 + struct super_block *tgt_sb;
34057 + shared_br = NULL;
34058 + bend = au_sbend(sb);
34060 + tgt_sb = au_br_sb(br);
34061 + for (bindex = 0; bindex <= bend; bindex++) {
34062 + b = au_sbr(sb, bindex);
34063 + if (tgt_sb == au_br_sb(b)) {
34070 + if (!shared_br || !shared_br->br_xino.xi_file) {
34071 + struct au_xino_lock_dir ldir;
34073 + au_xino_lock_dir(sb, base_file, &ldir);
34074 + /* mnt_want_write() is unnecessary here */
34075 + file = au_xino_create2(base_file, NULL);
34076 + au_xino_unlock_dir(&ldir);
34077 + err = PTR_ERR(file);
34078 + if (IS_ERR(file))
34080 + br->br_xino.xi_file = file;
34082 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34083 + get_file(br->br_xino.xi_file);
34086 + ino = AUFS_ROOT_INO;
34087 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34089 + if (unlikely(err)) {
34090 + fput(br->br_xino.xi_file);
34091 + br->br_xino.xi_file = NULL;
34098 +/* ---------------------------------------------------------------------- */
34100 +/* trucate a xino bitmap file */
34103 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34107 + unsigned long pindex;
34108 + loff_t pos, pend;
34109 + struct au_sbinfo *sbinfo;
34110 + vfs_readf_t func;
34112 + unsigned long *p;
34115 + sbinfo = au_sbi(sb);
34116 + MtxMustLock(&sbinfo->si_xib_mtx);
34117 + p = sbinfo->si_xib_buf;
34118 + func = sbinfo->si_xread;
34119 + pend = vfsub_f_size_read(file);
34121 + while (pos < pend) {
34122 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34124 + if (unlikely(sz <= 0))
34128 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34129 + if (unlikely(*ino < AUFS_FIRST_INO))
34132 + xib_calc_bit(*ino, &pindex, &bit);
34133 + AuDebugOn(page_bits <= bit);
34134 + err = xib_pindex(sb, pindex);
34146 +static int xib_restore(struct super_block *sb)
34149 + aufs_bindex_t bindex, bend;
34153 + page = (void *)__get_free_page(GFP_NOFS);
34154 + if (unlikely(!page))
34158 + bend = au_sbend(sb);
34159 + for (bindex = 0; !err && bindex <= bend; bindex++)
34160 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34161 + err = do_xib_restore
34162 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34164 + AuDbg("b%d\n", bindex);
34165 + free_page((unsigned long)page);
34171 +int au_xib_trunc(struct super_block *sb)
34176 + struct au_xino_lock_dir ldir;
34177 + struct au_sbinfo *sbinfo;
34178 + unsigned long *p;
34179 + struct file *file;
34181 + SiMustWriteLock(sb);
34184 + sbinfo = au_sbi(sb);
34185 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34188 + file = sbinfo->si_xib;
34189 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34192 + au_xino_lock_dir(sb, file, &ldir);
34193 + /* mnt_want_write() is unnecessary here */
34194 + file = au_xino_create2(sbinfo->si_xib, NULL);
34195 + au_xino_unlock_dir(&ldir);
34196 + err = PTR_ERR(file);
34197 + if (IS_ERR(file))
34199 + fput(sbinfo->si_xib);
34200 + sbinfo->si_xib = file;
34202 + p = sbinfo->si_xib_buf;
34203 + memset(p, 0, PAGE_SIZE);
34205 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34206 + if (unlikely(sz != PAGE_SIZE)) {
34208 + AuIOErr("err %d\n", err);
34214 + mutex_lock(&sbinfo->si_xib_mtx);
34215 + /* mnt_want_write() is unnecessary here */
34216 + err = xib_restore(sb);
34217 + mutex_unlock(&sbinfo->si_xib_mtx);
34223 +/* ---------------------------------------------------------------------- */
34226 + * xino mount option handlers
34230 +static void xino_clear_xib(struct super_block *sb)
34232 + struct au_sbinfo *sbinfo;
34234 + SiMustWriteLock(sb);
34236 + sbinfo = au_sbi(sb);
34237 + sbinfo->si_xread = NULL;
34238 + sbinfo->si_xwrite = NULL;
34239 + if (sbinfo->si_xib)
34240 + fput(sbinfo->si_xib);
34241 + sbinfo->si_xib = NULL;
34242 + free_page((unsigned long)sbinfo->si_xib_buf);
34243 + sbinfo->si_xib_buf = NULL;
34246 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34250 + struct au_sbinfo *sbinfo;
34251 + struct file *file;
34253 + SiMustWriteLock(sb);
34255 + sbinfo = au_sbi(sb);
34256 + file = au_xino_create2(base, sbinfo->si_xib);
34257 + err = PTR_ERR(file);
34258 + if (IS_ERR(file))
34260 + if (sbinfo->si_xib)
34261 + fput(sbinfo->si_xib);
34262 + sbinfo->si_xib = file;
34263 + sbinfo->si_xread = vfs_readf(file);
34264 + sbinfo->si_xwrite = vfs_writef(file);
34267 + if (!sbinfo->si_xib_buf)
34268 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34269 + if (unlikely(!sbinfo->si_xib_buf))
34272 + sbinfo->si_xib_last_pindex = 0;
34273 + sbinfo->si_xib_next_bit = 0;
34274 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34276 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34277 + PAGE_SIZE, &pos);
34278 + if (unlikely(err != PAGE_SIZE))
34282 + goto out; /* success */
34285 + free_page((unsigned long)sbinfo->si_xib_buf);
34286 + sbinfo->si_xib_buf = NULL;
34290 + fput(sbinfo->si_xib);
34291 + sbinfo->si_xib = NULL;
34292 + sbinfo->si_xread = NULL;
34293 + sbinfo->si_xwrite = NULL;
34298 +/* xino for each branch */
34299 +static void xino_clear_br(struct super_block *sb)
34301 + aufs_bindex_t bindex, bend;
34302 + struct au_branch *br;
34304 + bend = au_sbend(sb);
34305 + for (bindex = 0; bindex <= bend; bindex++) {
34306 + br = au_sbr(sb, bindex);
34307 + if (!br || !br->br_xino.xi_file)
34310 + fput(br->br_xino.xi_file);
34311 + br->br_xino.xi_file = NULL;
34315 +static int au_xino_set_br(struct super_block *sb, struct file *base)
34319 + aufs_bindex_t bindex, bend, bshared;
34321 + struct file *old, *new;
34323 + struct au_branch *br;
34324 + struct inode *inode;
34325 + vfs_writef_t writef;
34327 + SiMustWriteLock(sb);
34330 + bend = au_sbend(sb);
34331 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
34332 + if (unlikely(!fpair))
34335 + inode = d_inode(sb->s_root);
34336 + ino = AUFS_ROOT_INO;
34337 + writef = au_sbi(sb)->si_xwrite;
34338 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34339 + br = au_sbr(sb, bindex);
34340 + bshared = is_sb_shared(sb, bindex, bindex - 1);
34341 + if (bshared >= 0) {
34342 + /* shared xino */
34343 + *p = fpair[bshared];
34344 + get_file(p->new);
34349 + p->old = br->br_xino.xi_file;
34350 + p->new = au_xino_create2(base, br->br_xino.xi_file);
34351 + err = PTR_ERR(p->new);
34352 + if (IS_ERR(p->new)) {
34358 + err = au_xino_do_write(writef, p->new,
34359 + au_h_iptr(inode, bindex)->i_ino, ino);
34360 + if (unlikely(err))
34364 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34365 + br = au_sbr(sb, bindex);
34366 + if (br->br_xino.xi_file)
34367 + fput(br->br_xino.xi_file);
34368 + get_file(p->new);
34369 + br->br_xino.xi_file = p->new;
34373 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
34383 +void au_xino_clr(struct super_block *sb)
34385 + struct au_sbinfo *sbinfo;
34387 + au_xigen_clr(sb);
34388 + xino_clear_xib(sb);
34389 + xino_clear_br(sb);
34390 + sbinfo = au_sbi(sb);
34391 + /* lvalue, do not call au_mntflags() */
34392 + au_opt_clr(sbinfo->si_mntflags, XINO);
34395 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
34398 + struct dentry *parent, *cur_parent;
34399 + struct qstr *dname, *cur_name;
34400 + struct file *cur_xino;
34401 + struct inode *dir;
34402 + struct au_sbinfo *sbinfo;
34404 + SiMustWriteLock(sb);
34407 + sbinfo = au_sbi(sb);
34408 + parent = dget_parent(xino->file->f_path.dentry);
34411 + dname = &xino->file->f_path.dentry->d_name;
34412 + cur_xino = sbinfo->si_xib;
34414 + cur_parent = dget_parent(cur_xino->f_path.dentry);
34415 + cur_name = &cur_xino->f_path.dentry->d_name;
34416 + skip = (cur_parent == parent
34417 + && au_qstreq(dname, cur_name));
34418 + dput(cur_parent);
34424 + au_opt_set(sbinfo->si_mntflags, XINO);
34425 + dir = d_inode(parent);
34426 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
34427 + /* mnt_want_write() is unnecessary here */
34428 + err = au_xino_set_xib(sb, xino->file);
34430 + err = au_xigen_set(sb, xino->file);
34432 + err = au_xino_set_br(sb, xino->file);
34433 + mutex_unlock(&dir->i_mutex);
34435 + goto out; /* success */
34438 + AuIOErr("failed creating xino(%d).\n", err);
34439 + au_xigen_clr(sb);
34440 + xino_clear_xib(sb);
34447 +/* ---------------------------------------------------------------------- */
34450 + * create a xinofile at the default place/path.
34452 +struct file *au_xino_def(struct super_block *sb)
34454 + struct file *file;
34456 + struct au_branch *br;
34457 + struct super_block *h_sb;
34458 + struct path path;
34459 + aufs_bindex_t bend, bindex, bwr;
34462 + bend = au_sbend(sb);
34464 + for (bindex = 0; bindex <= bend; bindex++) {
34465 + br = au_sbr(sb, bindex);
34466 + if (au_br_writable(br->br_perm)
34467 + && !au_test_fs_bad_xino(au_br_sb(br))) {
34474 + file = ERR_PTR(-ENOMEM);
34475 + page = (void *)__get_free_page(GFP_NOFS);
34476 + if (unlikely(!page))
34478 + path.mnt = au_br_mnt(br);
34479 + path.dentry = au_h_dptr(sb->s_root, bwr);
34480 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
34481 + file = (void *)p;
34482 + if (!IS_ERR(p)) {
34483 + strcat(p, "/" AUFS_XINO_FNAME);
34484 + AuDbg("%s\n", p);
34485 + file = au_xino_create(sb, p, /*silent*/0);
34486 + if (!IS_ERR(file))
34487 + au_xino_brid_set(sb, br->br_id);
34489 + free_page((unsigned long)page);
34491 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
34492 + if (IS_ERR(file))
34494 + h_sb = file->f_path.dentry->d_sb;
34495 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
34496 + pr_err("xino doesn't support %s(%s)\n",
34497 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
34499 + file = ERR_PTR(-EINVAL);
34501 + if (!IS_ERR(file))
34502 + au_xino_brid_set(sb, -1);
34509 +/* ---------------------------------------------------------------------- */
34511 +int au_xino_path(struct seq_file *seq, struct file *file)
34515 + err = au_seq_path(seq, &file->f_path);
34516 + if (unlikely(err))
34519 +#define Deleted "\\040(deleted)"
34520 + seq->count -= sizeof(Deleted) - 1;
34521 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
34522 + sizeof(Deleted) - 1));
34528 diff -urNp -x '*.orig' linux-4.4/fs/dcache.c linux-4.4/fs/dcache.c
34529 --- linux-4.4/fs/dcache.c 2021-02-24 17:28:03.261780251 +0100
34530 +++ linux-4.4/fs/dcache.c 2021-02-24 17:28:14.392141071 +0100
34531 @@ -1197,7 +1197,7 @@ enum d_walk_ret {
34533 * The @enter() and @finish() callbacks are called with d_lock held.
34535 -static void d_walk(struct dentry *parent, void *data,
34536 +void d_walk(struct dentry *parent, void *data,
34537 enum d_walk_ret (*enter)(void *, struct dentry *),
34538 void (*finish)(void *))
34540 @@ -1302,6 +1302,7 @@ rename_retry:
34544 +EXPORT_SYMBOL(d_walk);
34547 * Search for at least 1 mount point in the dentry's subdirs.
34548 diff -urNp -x '*.orig' linux-4.4/fs/exec.c linux-4.4/fs/exec.c
34549 --- linux-4.4/fs/exec.c 2021-02-24 17:28:02.401752368 +0100
34550 +++ linux-4.4/fs/exec.c 2021-02-24 17:28:14.392141071 +0100
34551 @@ -104,6 +104,7 @@ bool path_noexec(const struct path *path
34552 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
34553 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
34555 +EXPORT_SYMBOL(path_noexec);
34557 #ifdef CONFIG_USELIB
34559 diff -urNp -x '*.orig' linux-4.4/fs/file_table.c linux-4.4/fs/file_table.c
34560 --- linux-4.4/fs/file_table.c 2021-02-24 17:28:03.265113693 +0100
34561 +++ linux-4.4/fs/file_table.c 2021-02-24 17:28:14.392141071 +0100
34562 @@ -151,6 +151,7 @@ over:
34564 return ERR_PTR(-ENFILE);
34566 +EXPORT_SYMBOL(get_empty_filp);
34569 * alloc_file - allocate and initialize a 'struct file'
34570 @@ -264,6 +265,7 @@ void flush_delayed_fput(void)
34572 delayed_fput(NULL);
34574 +EXPORT_SYMBOL(flush_delayed_fput);
34576 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
34578 @@ -306,6 +308,7 @@ void __fput_sync(struct file *file)
34581 EXPORT_SYMBOL(fput);
34582 +EXPORT_SYMBOL(__fput_sync);
34584 void put_filp(struct file *file)
34586 @@ -316,6 +319,7 @@ void put_filp(struct file *file)
34590 +EXPORT_SYMBOL(put_filp);
34592 void __init files_init(void)
34594 diff -urNp -x '*.orig' linux-4.4/fs/namespace.c linux-4.4/fs/namespace.c
34595 --- linux-4.4/fs/namespace.c 2021-02-24 17:28:03.271780576 +0100
34596 +++ linux-4.4/fs/namespace.c 2021-02-24 17:28:14.392141071 +0100
34597 @@ -472,6 +472,7 @@ void __mnt_drop_write(struct vfsmount *m
34598 mnt_dec_writers(real_mount(mnt));
34601 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
34604 * mnt_drop_write - give up write access to a mount
34605 @@ -1882,6 +1883,7 @@ int iterate_mounts(int (*f)(struct vfsmo
34609 +EXPORT_SYMBOL(iterate_mounts);
34611 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
34613 diff -urNp -x '*.orig' linux-4.4/fs/notify/group.c linux-4.4/fs/notify/group.c
34614 --- linux-4.4/fs/notify/group.c 2021-02-24 17:28:02.465087755 +0100
34615 +++ linux-4.4/fs/notify/group.c 2021-02-24 17:28:14.392141071 +0100
34617 #include <linux/srcu.h>
34618 #include <linux/rculist.h>
34619 #include <linux/wait.h>
34620 +#include <linux/module.h>
34622 #include <linux/fsnotify_backend.h>
34623 #include "fsnotify.h"
34624 @@ -91,6 +92,7 @@ void fsnotify_get_group(struct fsnotify_
34626 atomic_inc(&group->refcnt);
34628 +EXPORT_SYMBOL(fsnotify_get_group);
34631 * Drop a reference to a group. Free it if it's through.
34632 @@ -100,6 +102,7 @@ void fsnotify_put_group(struct fsnotify_
34633 if (atomic_dec_and_test(&group->refcnt))
34634 fsnotify_final_destroy_group(group);
34636 +EXPORT_SYMBOL(fsnotify_put_group);
34639 * Create a new fsnotify_group and hold a reference for the group returned.
34640 @@ -128,6 +131,7 @@ struct fsnotify_group *fsnotify_alloc_gr
34644 +EXPORT_SYMBOL(fsnotify_alloc_group);
34646 int fsnotify_fasync(int fd, struct file *file, int on)
34648 diff -urNp -x '*.orig' linux-4.4/fs/notify/mark.c linux-4.4/fs/notify/mark.c
34649 --- linux-4.4/fs/notify/mark.c 2016-01-11 00:01:32.000000000 +0100
34650 +++ linux-4.4/fs/notify/mark.c 2021-02-24 17:28:14.392141071 +0100
34651 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_m
34652 mark->free_mark(mark);
34655 +EXPORT_SYMBOL(fsnotify_put_mark);
34657 /* Calculate mask of events for a list of marks */
34658 u32 fsnotify_recalc_mask(struct hlist_head *head)
34659 @@ -208,6 +209,7 @@ void fsnotify_destroy_mark(struct fsnoti
34660 mutex_unlock(&group->mark_mutex);
34661 fsnotify_free_mark(mark);
34663 +EXPORT_SYMBOL(fsnotify_destroy_mark);
34665 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
34667 @@ -392,6 +394,7 @@ err:
34671 +EXPORT_SYMBOL(fsnotify_add_mark);
34673 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
34674 struct inode *inode, struct vfsmount *mnt, int allow_dups)
34675 @@ -492,6 +495,7 @@ void fsnotify_init_mark(struct fsnotify_
34676 atomic_set(&mark->refcnt, 1);
34677 mark->free_mark = free_mark;
34679 +EXPORT_SYMBOL(fsnotify_init_mark);
34681 static int fsnotify_mark_destroy(void *ignored)
34683 diff -urNp -x '*.orig' linux-4.4/fs/open.c linux-4.4/fs/open.c
34684 --- linux-4.4/fs/open.c 2021-02-24 17:28:03.278447459 +0100
34685 +++ linux-4.4/fs/open.c 2021-02-24 17:28:14.392141071 +0100
34686 @@ -69,6 +69,7 @@ int do_truncate(struct dentry *dentry, l
34687 mutex_unlock(&dentry->d_inode->i_mutex);
34690 +EXPORT_SYMBOL(do_truncate);
34692 long vfs_truncate(struct path *path, loff_t length)
34694 @@ -720,6 +721,7 @@ int open_check_o_direct(struct file *f)
34698 +EXPORT_SYMBOL(open_check_o_direct);
34700 static int do_dentry_open(struct file *f,
34701 struct inode *inode,
34702 diff -urNp -x '*.orig' linux-4.4/fs/proc/base.c linux-4.4/fs/proc/base.c
34703 --- linux-4.4/fs/proc/base.c 2021-02-24 17:28:03.341782845 +0100
34704 +++ linux-4.4/fs/proc/base.c 2021-02-24 17:28:14.385474188 +0100
34705 @@ -1996,7 +1996,7 @@ static int proc_map_files_get_link(struc
34706 down_read(&mm->mmap_sem);
34707 vma = find_exact_vma(mm, vm_start, vm_end);
34708 if (vma && vma->vm_file) {
34709 - *path = vma->vm_file->f_path;
34710 + *path = vma_pr_or_file(vma)->f_path;
34714 diff -urNp -x '*.orig' linux-4.4/fs/proc/nommu.c linux-4.4/fs/proc/nommu.c
34715 --- linux-4.4/fs/proc/nommu.c 2016-01-11 00:01:32.000000000 +0100
34716 +++ linux-4.4/fs/proc/nommu.c 2021-02-24 17:28:14.385474188 +0100
34717 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_
34718 file = region->vm_file;
34721 - struct inode *inode = file_inode(region->vm_file);
34722 + struct inode *inode;
34724 + file = vmr_pr_or_file(region);
34725 + inode = file_inode(file);
34726 dev = inode->i_sb->s_dev;
34727 ino = inode->i_ino;
34729 diff -urNp -x '*.orig' linux-4.4/fs/proc/task_mmu.c linux-4.4/fs/proc/task_mmu.c
34730 --- linux-4.4/fs/proc/task_mmu.c 2021-02-24 17:28:02.481754962 +0100
34731 +++ linux-4.4/fs/proc/task_mmu.c 2021-02-24 17:28:14.385474188 +0100
34732 @@ -278,7 +278,10 @@ show_map_vma(struct seq_file *m, struct
34733 const char *name = NULL;
34736 - struct inode *inode = file_inode(vma->vm_file);
34737 + struct inode *inode;
34739 + file = vma_pr_or_file(vma);
34740 + inode = file_inode(file);
34741 dev = inode->i_sb->s_dev;
34742 ino = inode->i_ino;
34743 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
34744 @@ -1536,7 +1539,7 @@ static int show_numa_map(struct seq_file
34745 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
34746 struct vm_area_struct *vma = v;
34747 struct numa_maps *md = &numa_priv->md;
34748 - struct file *file = vma->vm_file;
34749 + struct file *file = vma_pr_or_file(vma);
34750 struct mm_struct *mm = vma->vm_mm;
34751 struct mm_walk walk = {
34752 .hugetlb_entry = gather_hugetlb_stats,
34753 diff -urNp -x '*.orig' linux-4.4/fs/proc/task_nommu.c linux-4.4/fs/proc/task_nommu.c
34754 --- linux-4.4/fs/proc/task_nommu.c 2021-02-24 17:28:02.485088404 +0100
34755 +++ linux-4.4/fs/proc/task_nommu.c 2021-02-24 17:28:14.385474188 +0100
34756 @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_fil
34757 file = vma->vm_file;
34760 - struct inode *inode = file_inode(vma->vm_file);
34761 + struct inode *inode;
34763 + file = vma_pr_or_file(vma);
34764 + inode = file_inode(file);
34765 dev = inode->i_sb->s_dev;
34766 ino = inode->i_ino;
34767 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
34768 diff -urNp -x '*.orig' linux-4.4/fs/read_write.c linux-4.4/fs/read_write.c
34769 --- linux-4.4/fs/read_write.c 2021-02-24 17:28:02.485088404 +0100
34770 +++ linux-4.4/fs/read_write.c 2021-02-24 17:28:14.392141071 +0100
34771 @@ -496,6 +496,30 @@ ssize_t __vfs_write(struct file *file, c
34773 EXPORT_SYMBOL(__vfs_write);
34775 +vfs_readf_t vfs_readf(struct file *file)
34777 + const struct file_operations *fop = file->f_op;
34780 + return fop->read;
34781 + if (fop->read_iter)
34782 + return new_sync_read;
34783 + return ERR_PTR(-ENOSYS);
34785 +EXPORT_SYMBOL(vfs_readf);
34787 +vfs_writef_t vfs_writef(struct file *file)
34789 + const struct file_operations *fop = file->f_op;
34792 + return fop->write;
34793 + if (fop->write_iter)
34794 + return new_sync_write;
34795 + return ERR_PTR(-ENOSYS);
34797 +EXPORT_SYMBOL(vfs_writef);
34799 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
34801 mm_segment_t old_fs;
34802 diff -urNp -x '*.orig' linux-4.4/fs/splice.c linux-4.4/fs/splice.c
34803 --- linux-4.4/fs/splice.c 2021-02-24 17:28:02.491755286 +0100
34804 +++ linux-4.4/fs/splice.c 2021-02-24 17:28:14.392141071 +0100
34805 @@ -1114,8 +1114,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
34807 * Attempt to initiate a splice from pipe to file.
34809 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
34810 - loff_t *ppos, size_t len, unsigned int flags)
34811 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
34812 + loff_t *ppos, size_t len, unsigned int flags)
34814 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
34815 loff_t *, size_t, unsigned int);
34816 @@ -1127,13 +1127,14 @@ static long do_splice_from(struct pipe_i
34818 return splice_write(pipe, out, ppos, len, flags);
34820 +EXPORT_SYMBOL(do_splice_from);
34823 * Attempt to initiate a splice from a file to a pipe.
34825 -static long do_splice_to(struct file *in, loff_t *ppos,
34826 - struct pipe_inode_info *pipe, size_t len,
34827 - unsigned int flags)
34828 +long do_splice_to(struct file *in, loff_t *ppos,
34829 + struct pipe_inode_info *pipe, size_t len,
34830 + unsigned int flags)
34832 ssize_t (*splice_read)(struct file *, loff_t *,
34833 struct pipe_inode_info *, size_t, unsigned int);
34834 @@ -1153,6 +1154,7 @@ static long do_splice_to(struct file *in
34836 return splice_read(in, ppos, pipe, len, flags);
34838 +EXPORT_SYMBOL(do_splice_to);
34841 * splice_direct_to_actor - splices data directly between two non-pipes
34842 diff -urNp -x '*.orig' linux-4.4/fs/xattr.c linux-4.4/fs/xattr.c
34843 --- linux-4.4/fs/xattr.c 2021-02-24 17:28:03.285114341 +0100
34844 +++ linux-4.4/fs/xattr.c 2021-02-24 17:28:14.392141071 +0100
34845 @@ -208,6 +208,7 @@ vfs_getxattr_alloc(struct dentry *dentry
34846 *xattr_value = value;
34849 +EXPORT_SYMBOL(vfs_getxattr_alloc);
34851 /* Compare an extended attribute value with the given value */
34852 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
34853 diff -urNp -x '*.orig' linux-4.4/include/linux/file.h linux-4.4/include/linux/file.h
34854 --- linux-4.4/include/linux/file.h 2016-01-11 00:01:32.000000000 +0100
34855 +++ linux-4.4/include/linux/file.h 2021-02-24 17:28:14.382140747 +0100
34856 @@ -19,6 +19,7 @@ struct dentry;
34858 extern struct file *alloc_file(struct path *, fmode_t mode,
34859 const struct file_operations *fop);
34860 +extern struct file *get_empty_filp(void);
34862 static inline void fput_light(struct file *file, int fput_needed)
34864 diff -urNp -x '*.orig' linux-4.4/include/linux/fs.h linux-4.4/include/linux/fs.h
34865 --- linux-4.4/include/linux/fs.h 2021-02-24 17:28:03.285114341 +0100
34866 +++ linux-4.4/include/linux/fs.h 2021-02-24 17:28:14.418808602 +0100
34867 @@ -1739,6 +1739,12 @@ ssize_t rw_copy_check_uvector(int type,
34868 struct iovec **ret_pointer);
34869 ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
34871 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
34872 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
34874 +vfs_readf_t vfs_readf(struct file *file);
34875 +vfs_writef_t vfs_writef(struct file *file);
34877 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
34878 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
34879 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
34880 @@ -1780,6 +1786,10 @@ struct super_operations {
34881 struct shrink_control *);
34882 long (*free_cached_objects)(struct super_block *,
34883 struct shrink_control *);
34884 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
34886 + struct file *(*real_loop)(struct file *);
34891 diff -urNp -x '*.orig' linux-4.4/include/linux/mm.h linux-4.4/include/linux/mm.h
34892 --- linux-4.4/include/linux/mm.h 2021-02-24 17:28:02.548423790 +0100
34893 +++ linux-4.4/include/linux/mm.h 2021-02-24 17:28:14.385474188 +0100
34894 @@ -1234,6 +1234,28 @@ static inline int fixup_user_fault(struc
34898 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
34899 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
34901 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
34902 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
34904 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
34906 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
34908 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
34909 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
34911 +#ifndef CONFIG_MMU
34912 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
34913 +extern void vmr_do_fput(struct vm_region *, const char[], int);
34915 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
34917 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
34918 +#endif /* !CONFIG_MMU */
34920 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
34921 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
34922 void *buf, int len, unsigned int gup_flags);
34923 diff -urNp -x '*.orig' linux-4.4/include/linux/mm_types.h linux-4.4/include/linux/mm_types.h
34924 --- linux-4.4/include/linux/mm_types.h 2021-02-24 17:28:02.548423790 +0100
34925 +++ linux-4.4/include/linux/mm_types.h 2021-02-24 17:28:14.385474188 +0100
34926 @@ -272,6 +272,7 @@ struct vm_region {
34927 unsigned long vm_top; /* region allocated to here */
34928 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
34929 struct file *vm_file; /* the backing file or NULL */
34930 + struct file *vm_prfile; /* the virtual backing file or NULL */
34932 int vm_usage; /* region usage count (access under nommu_region_sem) */
34933 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
34934 @@ -346,6 +347,7 @@ struct vm_area_struct {
34935 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
34936 units, *not* PAGE_CACHE_SIZE */
34937 struct file * vm_file; /* File we map to (can be NULL). */
34938 + struct file *vm_prfile; /* shadow of vm_file */
34939 void * vm_private_data; /* was vm_pte (shared mem) */
34942 diff -urNp -x '*.orig' linux-4.4/include/linux/splice.h linux-4.4/include/linux/splice.h
34943 --- linux-4.4/include/linux/splice.h 2016-01-11 00:01:32.000000000 +0100
34944 +++ linux-4.4/include/linux/splice.h 2021-02-24 17:28:14.385474188 +0100
34945 @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct spl
34946 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
34948 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
34950 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
34951 + loff_t *ppos, size_t len, unsigned int flags);
34952 +extern long do_splice_to(struct file *in, loff_t *ppos,
34953 + struct pipe_inode_info *pipe, size_t len,
34954 + unsigned int flags);
34956 diff -urNp -x '*.orig' linux-4.4/include/uapi/linux/Kbuild linux-4.4/include/uapi/linux/Kbuild
34957 --- linux-4.4/include/uapi/linux/Kbuild 2021-02-24 17:28:02.595091970 +0100
34958 +++ linux-4.4/include/uapi/linux/Kbuild 2021-02-24 17:28:14.378807305 +0100
34959 @@ -59,6 +59,7 @@ header-y += atmsvc.h
34960 header-y += atm_tcp.h
34961 header-y += atm_zatm.h
34962 header-y += audit.h
34963 +header-y += aufs_type.h
34964 header-y += auto_fs4.h
34965 header-y += auto_fs.h
34966 header-y += auxvec.h
34967 diff -urNp -x '*.orig' linux-4.4/include/uapi/linux/aufs_type.h linux-4.4/include/uapi/linux/aufs_type.h
34968 --- linux-4.4/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
34969 +++ linux-4.4/include/uapi/linux/aufs_type.h 2021-02-24 17:28:14.415475161 +0100
34972 + * Copyright (C) 2005-2016 Junjiro R. Okajima
34974 + * This program, aufs is free software; you can redistribute it and/or modify
34975 + * it under the terms of the GNU General Public License as published by
34976 + * the Free Software Foundation; either version 2 of the License, or
34977 + * (at your option) any later version.
34979 + * This program is distributed in the hope that it will be useful,
34980 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34981 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34982 + * GNU General Public License for more details.
34984 + * You should have received a copy of the GNU General Public License
34985 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34988 +#ifndef __AUFS_TYPE_H__
34989 +#define __AUFS_TYPE_H__
34991 +#define AUFS_NAME "aufs"
34995 + * define it before including all other headers.
34996 + * sched.h may use pr_* macros before defining "current", so define the
34997 + * no-current version first, and re-define later.
34999 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35000 +#include <linux/sched.h>
35002 +#define pr_fmt(fmt) \
35003 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35004 + (int)sizeof(current->comm), current->comm, current->pid
35006 +#include <stdint.h>
35007 +#include <sys/types.h>
35008 +#endif /* __KERNEL__ */
35010 +#include <linux/limits.h>
35012 +#define AUFS_VERSION "4.4-20160223"
35014 +/* todo? move this to linux-2.6.19/include/magic.h */
35015 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35017 +/* ---------------------------------------------------------------------- */
35019 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35020 +typedef int8_t aufs_bindex_t;
35021 +#define AUFS_BRANCH_MAX 127
35023 +typedef int16_t aufs_bindex_t;
35024 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35025 +#define AUFS_BRANCH_MAX 511
35026 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35027 +#define AUFS_BRANCH_MAX 1023
35028 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35029 +#define AUFS_BRANCH_MAX 32767
35034 +#ifndef AUFS_BRANCH_MAX
35035 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35037 +#endif /* __KERNEL__ */
35039 +/* ---------------------------------------------------------------------- */
35041 +#define AUFS_FSTYPE AUFS_NAME
35043 +#define AUFS_ROOT_INO 2
35044 +#define AUFS_FIRST_INO 11
35046 +#define AUFS_WH_PFX ".wh."
35047 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
35048 +#define AUFS_WH_TMP_LEN 4
35049 +/* a limit for rmdir/rename a dir and copyup */
35050 +#define AUFS_MAX_NAMELEN (NAME_MAX \
35051 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
35053 + - AUFS_WH_TMP_LEN) /* hex */
35054 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
35055 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
35056 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
35057 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
35058 +#define AUFS_DIRWH_DEF 3
35059 +#define AUFS_RDCACHE_DEF 10 /* seconds */
35060 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
35061 +#define AUFS_RDBLK_DEF 512 /* bytes */
35062 +#define AUFS_RDHASH_DEF 32
35063 +#define AUFS_WKQ_NAME AUFS_NAME "d"
35064 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
35065 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
35066 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
35067 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35069 +/* pseudo-link maintenace under /proc */
35070 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35071 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35072 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35074 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35075 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35077 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35078 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35079 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35081 +/* doubly whiteouted */
35082 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35083 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35084 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35086 +/* branch permissions and attributes */
35087 +#define AUFS_BRPERM_RW "rw"
35088 +#define AUFS_BRPERM_RO "ro"
35089 +#define AUFS_BRPERM_RR "rr"
35090 +#define AUFS_BRATTR_COO_REG "coo_reg"
35091 +#define AUFS_BRATTR_COO_ALL "coo_all"
35092 +#define AUFS_BRATTR_FHSM "fhsm"
35093 +#define AUFS_BRATTR_UNPIN "unpin"
35094 +#define AUFS_BRATTR_ICEX "icex"
35095 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35096 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35097 +#define AUFS_BRATTR_ICEX_TR "icextr"
35098 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35099 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35100 +#define AUFS_BRRATTR_WH "wh"
35101 +#define AUFS_BRWATTR_NLWH "nolwh"
35102 +#define AUFS_BRWATTR_MOO "moo"
35104 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35105 +#define AuBrPerm_RO (1 << 1) /* readonly */
35106 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35107 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35109 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35110 +#define AuBrAttr_COO_ALL (1 << 4)
35111 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35113 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35114 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35115 + branch. meaningless since
35116 + linux-3.18-rc1 */
35118 +/* ignore error in copying XATTR */
35119 +#define AuBrAttr_ICEX_SEC (1 << 7)
35120 +#define AuBrAttr_ICEX_SYS (1 << 8)
35121 +#define AuBrAttr_ICEX_TR (1 << 9)
35122 +#define AuBrAttr_ICEX_USR (1 << 10)
35123 +#define AuBrAttr_ICEX_OTH (1 << 11)
35124 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35125 + | AuBrAttr_ICEX_SYS \
35126 + | AuBrAttr_ICEX_TR \
35127 + | AuBrAttr_ICEX_USR \
35128 + | AuBrAttr_ICEX_OTH)
35130 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35131 +#define AuBrRAttr_Mask AuBrRAttr_WH
35133 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35134 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35135 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35137 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35139 +/* #warning test userspace */
35141 +#ifndef CONFIG_AUFS_FHSM
35142 +#undef AuBrAttr_FHSM
35143 +#define AuBrAttr_FHSM 0
35145 +#ifndef CONFIG_AUFS_XATTR
35146 +#undef AuBrAttr_ICEX
35147 +#define AuBrAttr_ICEX 0
35148 +#undef AuBrAttr_ICEX_SEC
35149 +#define AuBrAttr_ICEX_SEC 0
35150 +#undef AuBrAttr_ICEX_SYS
35151 +#define AuBrAttr_ICEX_SYS 0
35152 +#undef AuBrAttr_ICEX_TR
35153 +#define AuBrAttr_ICEX_TR 0
35154 +#undef AuBrAttr_ICEX_USR
35155 +#define AuBrAttr_ICEX_USR 0
35156 +#undef AuBrAttr_ICEX_OTH
35157 +#define AuBrAttr_ICEX_OTH 0
35161 +/* the longest combination */
35162 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35163 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35164 + "+" AUFS_BRATTR_COO_REG \
35165 + "+" AUFS_BRATTR_FHSM \
35166 + "+" AUFS_BRATTR_UNPIN \
35167 + "+" AUFS_BRATTR_ICEX_SEC \
35168 + "+" AUFS_BRATTR_ICEX_SYS \
35169 + "+" AUFS_BRATTR_ICEX_USR \
35170 + "+" AUFS_BRATTR_ICEX_OTH \
35171 + "+" AUFS_BRWATTR_NLWH)
35174 + char a[AuBrPermStrSz];
35175 +} au_br_perm_str_t;
35177 +static inline int au_br_writable(int brperm)
35179 + return brperm & AuBrPerm_RW;
35182 +static inline int au_br_whable(int brperm)
35184 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35187 +static inline int au_br_wh_linkable(int brperm)
35189 + return !(brperm & AuBrWAttr_NoLinkWH);
35192 +static inline int au_br_cmoo(int brperm)
35194 + return brperm & AuBrAttr_CMOO_Mask;
35197 +static inline int au_br_fhsm(int brperm)
35199 + return brperm & AuBrAttr_FHSM;
35202 +/* ---------------------------------------------------------------------- */
35206 + /* readdir in userspace */
35210 + AuCtl_WBR_FD, /* pathconf wrapper */
35211 + AuCtl_IBUSY, /* busy inode */
35212 + AuCtl_MVDOWN, /* move-down */
35213 + AuCtl_BR, /* info about branches */
35214 + AuCtl_FHSM_FD /* connection for fhsm */
35217 +/* borrowed from linux/include/linux/kernel.h */
35219 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
35220 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
35223 +/* borrowed from linux/include/linux/compiler-gcc3.h */
35225 +#define __aligned(x) __attribute__((aligned(x)))
35230 +#define __packed __attribute__((packed))
35234 +struct au_rdu_cookie {
35239 + uint32_t generation;
35242 +struct au_rdu_ent {
35251 +static inline int au_rdu_len(int nlen)
35253 + /* include the terminating NULL */
35254 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35255 + sizeof(uint64_t));
35258 +union au_rdu_ent_ul {
35259 + struct au_rdu_ent __user *e;
35271 + uint64_t sz; /* AuCtl_RDU */
35272 + uint64_t nent; /* AuCtl_RDU_INO */
35274 + union au_rdu_ent_ul ent;
35275 + uint16_t verify[AufsCtlRduV_End];
35277 + /* input/output */
35281 + union au_rdu_ent_ul tail;
35282 + /* number of entries which were added in a single call */
35287 + struct au_rdu_cookie cookie;
35290 +/* ---------------------------------------------------------------------- */
35292 +struct aufs_wbr_fd {
35297 +/* ---------------------------------------------------------------------- */
35299 +struct aufs_ibusy {
35300 + uint64_t ino, h_ino;
35304 +/* ---------------------------------------------------------------------- */
35306 +/* error code for move-down */
35307 +/* the actual message strings are implemented in aufs-util.git */
35309 + EAU_MVDOWN_OPAQUE = 1,
35310 + EAU_MVDOWN_WHITEOUT,
35311 + EAU_MVDOWN_UPPER,
35312 + EAU_MVDOWN_BOTTOM,
35313 + EAU_MVDOWN_NOUPPER,
35314 + EAU_MVDOWN_NOLOWERBR,
35318 +/* flags for move-down */
35319 +#define AUFS_MVDOWN_DMSG 1
35320 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35321 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35322 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35323 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35324 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35325 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35326 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35327 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35328 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35329 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35330 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35331 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35333 +/* index for move-down */
35335 + AUFS_MVDOWN_UPPER,
35336 + AUFS_MVDOWN_LOWER,
35337 + AUFS_MVDOWN_NARRAY
35341 + * additional info of move-down
35342 + * number of free blocks and inodes.
35343 + * subset of struct kstatfs, but smaller and always 64bit.
35345 +struct aufs_stfs {
35346 + uint64_t f_blocks;
35347 + uint64_t f_bavail;
35348 + uint64_t f_files;
35349 + uint64_t f_ffree;
35352 +struct aufs_stbr {
35353 + int16_t brid; /* optional input */
35354 + int16_t bindex; /* output */
35355 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35358 +struct aufs_mvdown {
35359 + uint32_t flags; /* input/output */
35360 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35361 + int8_t au_errno; /* output */
35364 +/* ---------------------------------------------------------------------- */
35366 +union aufs_brinfo {
35367 + /* PATH_MAX may differ between kernel-space and user-space */
35368 + char _spacer[4096];
35376 +/* ---------------------------------------------------------------------- */
35378 +#define AuCtlType 'A'
35379 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35380 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35381 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35382 + struct aufs_wbr_fd)
35383 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35384 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35385 + struct aufs_mvdown)
35386 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35387 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35389 +#endif /* __AUFS_TYPE_H__ */
35390 diff -urNp -x '*.orig' linux-4.4/kernel/fork.c linux-4.4/kernel/fork.c
35391 --- linux-4.4/kernel/fork.c 2021-02-24 17:28:03.305114990 +0100
35392 +++ linux-4.4/kernel/fork.c 2021-02-24 17:28:14.385474188 +0100
35393 @@ -477,7 +477,7 @@ static int dup_mmap(struct mm_struct *mm
35394 struct inode *inode = file_inode(file);
35395 struct address_space *mapping = file->f_mapping;
35398 + vma_get_file(tmp);
35399 if (tmp->vm_flags & VM_DENYWRITE)
35400 atomic_dec(&inode->i_writecount);
35401 i_mmap_lock_write(mapping);
35402 diff -urNp -x '*.orig' linux-4.4/kernel/task_work.c linux-4.4/kernel/task_work.c
35403 --- linux-4.4/kernel/task_work.c 2016-01-11 00:01:32.000000000 +0100
35404 +++ linux-4.4/kernel/task_work.c 2021-02-24 17:28:14.392141071 +0100
35405 @@ -118,3 +118,4 @@ void task_work_run(void)
35409 +EXPORT_SYMBOL(task_work_run);
35410 diff -urNp -x '*.orig' linux-4.4/mm/Makefile linux-4.4/mm/Makefile
35411 --- linux-4.4/mm/Makefile 2016-01-11 00:01:32.000000000 +0100
35412 +++ linux-4.4/mm/Makefile 2021-02-24 17:28:14.385474188 +0100
35413 @@ -21,7 +21,7 @@ obj-y := filemap.o mempool.o oom_kill.
35414 mm_init.o mmu_context.o percpu.o slab_common.o \
35415 compaction.o vmacache.o \
35416 interval_tree.o list_lru.o workingset.o \
35418 + prfile.o debug.o $(mmu-y)
35422 diff -urNp -x '*.orig' linux-4.4/mm/filemap.c linux-4.4/mm/filemap.c
35423 --- linux-4.4/mm/filemap.c 2021-02-24 17:28:02.675094564 +0100
35424 +++ linux-4.4/mm/filemap.c 2021-02-24 17:28:14.385474188 +0100
35425 @@ -2151,7 +2151,7 @@ int filemap_page_mkwrite(struct vm_area_
35426 int ret = VM_FAULT_LOCKED;
35428 sb_start_pagefault(inode->i_sb);
35429 - file_update_time(vma->vm_file);
35430 + vma_file_update_time(vma);
35432 if (page->mapping != inode->i_mapping) {
35434 diff -urNp -x '*.orig' linux-4.4/mm/memory.c linux-4.4/mm/memory.c
35435 --- linux-4.4/mm/memory.c 2021-02-24 17:28:02.681761447 +0100
35436 +++ linux-4.4/mm/memory.c 2021-02-24 17:28:14.388807629 +0100
35437 @@ -2122,7 +2122,7 @@ static inline int wp_page_reuse(struct m
35441 - file_update_time(vma->vm_file);
35442 + vma_file_update_time(vma);
35445 return VM_FAULT_WRITE;
35446 diff -urNp -x '*.orig' linux-4.4/mm/mmap.c linux-4.4/mm/mmap.c
35447 --- linux-4.4/mm/mmap.c 2021-02-24 17:28:02.685094888 +0100
35448 +++ linux-4.4/mm/mmap.c 2021-02-24 17:28:14.388807629 +0100
35449 @@ -276,7 +276,7 @@ static struct vm_area_struct *remove_vma
35450 if (vma->vm_ops && vma->vm_ops->close)
35451 vma->vm_ops->close(vma);
35453 - fput(vma->vm_file);
35455 mpol_put(vma_policy(vma));
35456 kmem_cache_free(vm_area_cachep, vma);
35458 @@ -906,7 +906,7 @@ again: remove_next = 1 + (end > next->
35461 uprobe_munmap(next, next->vm_start, next->vm_end);
35465 if (next->anon_vma)
35466 anon_vma_merge(vma, next);
35467 @@ -1732,8 +1732,8 @@ out:
35470 unmap_and_free_vma:
35472 vma->vm_file = NULL;
35475 /* Undo any partial mapping done by a device driver. */
35476 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
35477 @@ -2557,7 +2557,7 @@ static int __split_vma(struct mm_struct
35478 goto out_free_mpol;
35481 - get_file(new->vm_file);
35482 + vma_get_file(new);
35484 if (new->vm_ops && new->vm_ops->open)
35485 new->vm_ops->open(new);
35486 @@ -2576,7 +2576,7 @@ static int __split_vma(struct mm_struct
35487 if (new->vm_ops && new->vm_ops->close)
35488 new->vm_ops->close(new);
35490 - fput(new->vm_file);
35492 unlink_anon_vmas(new);
35494 mpol_put(vma_policy(new));
35495 @@ -2718,7 +2718,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
35496 struct vm_area_struct *vma;
35497 unsigned long populate = 0;
35498 unsigned long ret = -EINVAL;
35499 - struct file *file;
35501 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
35502 "See Documentation/vm/remap_file_pages.txt.\n",
35503 @@ -2786,10 +2785,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsign
35507 - file = get_file(vma->vm_file);
35508 + vma_get_file(vma);
35509 ret = do_mmap_pgoff(vma->vm_file, start, size,
35510 prot, flags, pgoff, &populate);
35514 up_write(&mm->mmap_sem);
35516 @@ -3063,7 +3062,7 @@ struct vm_area_struct *copy_vma(struct v
35517 if (anon_vma_clone(new_vma, vma))
35518 goto out_free_mempol;
35519 if (new_vma->vm_file)
35520 - get_file(new_vma->vm_file);
35521 + vma_get_file(new_vma);
35522 if (new_vma->vm_ops && new_vma->vm_ops->open)
35523 new_vma->vm_ops->open(new_vma);
35524 vma_link(mm, new_vma, prev, rb_link, rb_parent);
35525 diff -urNp -x '*.orig' linux-4.4/mm/nommu.c linux-4.4/mm/nommu.c
35526 --- linux-4.4/mm/nommu.c 2021-02-24 17:28:02.685094888 +0100
35527 +++ linux-4.4/mm/nommu.c 2021-02-24 17:28:14.388807629 +0100
35528 @@ -667,7 +667,7 @@ static void __put_nommu_region(struct vm
35529 up_write(&nommu_region_sem);
35531 if (region->vm_file)
35532 - fput(region->vm_file);
35533 + vmr_fput(region);
35535 /* IO memory and memory shared directly out of the pagecache
35536 * from ramfs/tmpfs mustn't be released here */
35537 @@ -825,7 +825,7 @@ static void delete_vma(struct mm_struct
35538 if (vma->vm_ops && vma->vm_ops->close)
35539 vma->vm_ops->close(vma);
35541 - fput(vma->vm_file);
35543 put_nommu_region(vma->vm_region);
35544 kmem_cache_free(vm_area_cachep, vma);
35546 @@ -1351,7 +1351,7 @@ unsigned long do_mmap(struct file *file,
35547 goto error_just_free;
35550 - fput(region->vm_file);
35551 + vmr_fput(region);
35552 kmem_cache_free(vm_region_jar, region);
35555 @@ -1426,10 +1426,10 @@ error_just_free:
35556 up_write(&nommu_region_sem);
35558 if (region->vm_file)
35559 - fput(region->vm_file);
35560 + vmr_fput(region);
35561 kmem_cache_free(vm_region_jar, region);
35563 - fput(vma->vm_file);
35565 kmem_cache_free(vm_area_cachep, vma);
35568 diff -urNp -x '*.orig' linux-4.4/mm/prfile.c linux-4.4/mm/prfile.c
35569 --- linux-4.4/mm/prfile.c 1970-01-01 01:00:00.000000000 +0100
35570 +++ linux-4.4/mm/prfile.c 2021-02-24 17:28:14.388807629 +0100
35573 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
35574 + * in /proc/PID/maps.
35575 + * Call these functions via macros defined in linux/mm.h.
35577 + * See Documentation/filesystems/aufs/design/06mmap.txt
35579 + * Copyright (c) 2014 Junjro R. Okajima
35580 + * Copyright (c) 2014 Ian Campbell
35583 +#include <linux/mm.h>
35584 +#include <linux/file.h>
35585 +#include <linux/fs.h>
35587 +/* #define PRFILE_TRACE */
35588 +static inline void prfile_trace(struct file *f, struct file *pr,
35589 + const char func[], int line, const char func2[])
35591 +#ifdef PRFILE_TRACE
35593 + pr_info("%s:%d: %s, %s\n", func, line, func2,
35594 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
35598 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
35601 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
35603 + prfile_trace(f, pr, func, line, __func__);
35604 + file_update_time(f);
35606 + file_update_time(pr);
35609 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
35612 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
35614 + prfile_trace(f, pr, func, line, __func__);
35615 + return (f && pr) ? pr : f;
35618 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
35620 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
35622 + prfile_trace(f, pr, func, line, __func__);
35628 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
35630 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
35632 + prfile_trace(f, pr, func, line, __func__);
35638 +#ifndef CONFIG_MMU
35639 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
35642 + struct file *f = region->vm_file, *pr = region->vm_prfile;
35644 + prfile_trace(f, pr, func, line, __func__);
35645 + return (f && pr) ? pr : f;
35648 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
35650 + struct file *f = region->vm_file, *pr = region->vm_prfile;
35652 + prfile_trace(f, pr, func, line, __func__);
35657 +#endif /* !CONFIG_MMU */
35658 diff -urNp -x '*.orig' linux-4.4/security/commoncap.c linux-4.4/security/commoncap.c
35659 --- linux-4.4/security/commoncap.c 2021-02-24 17:28:03.338449404 +0100
35660 +++ linux-4.4/security/commoncap.c 2021-02-24 17:28:14.392141071 +0100
35661 @@ -1064,12 +1064,14 @@ int cap_mmap_addr(unsigned long addr)
35665 +EXPORT_SYMBOL(cap_mmap_addr);
35667 int cap_mmap_file(struct file *file, unsigned long reqprot,
35668 unsigned long prot, unsigned long flags)
35672 +EXPORT_SYMBOL(cap_mmap_file);
35674 #ifdef CONFIG_SECURITY
35676 diff -urNp -x '*.orig' linux-4.4/security/device_cgroup.c linux-4.4/security/device_cgroup.c
35677 --- linux-4.4/security/device_cgroup.c 2021-02-24 17:28:02.875101049 +0100
35678 +++ linux-4.4/security/device_cgroup.c 2021-02-24 17:28:14.395474512 +0100
35680 #include <linux/device_cgroup.h>
35681 #include <linux/cgroup.h>
35682 #include <linux/ctype.h>
35683 +#include <linux/export.h>
35684 #include <linux/list.h>
35685 #include <linux/uaccess.h>
35686 #include <linux/seq_file.h>
35687 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct
35688 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
35691 +EXPORT_SYMBOL(__devcgroup_inode_permission);
35693 int devcgroup_inode_mknod(int mode, dev_t dev)
35695 diff -urNp -x '*.orig' linux-4.4/security/security.c linux-4.4/security/security.c
35696 --- linux-4.4/security/security.c 2021-02-24 17:28:02.881767931 +0100
35697 +++ linux-4.4/security/security.c 2021-02-24 17:28:14.395474512 +0100
35698 @@ -433,6 +433,7 @@ int security_path_rmdir(struct path *dir
35700 return call_int_hook(path_rmdir, 0, dir, dentry);
35702 +EXPORT_SYMBOL(security_path_rmdir);
35704 int security_path_unlink(struct path *dir, struct dentry *dentry)
35706 @@ -449,6 +450,7 @@ int security_path_symlink(struct path *d
35708 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
35710 +EXPORT_SYMBOL(security_path_symlink);
35712 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
35713 struct dentry *new_dentry)
35714 @@ -457,6 +459,7 @@ int security_path_link(struct dentry *ol
35716 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
35718 +EXPORT_SYMBOL(security_path_link);
35720 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
35721 struct path *new_dir, struct dentry *new_dentry,
35722 @@ -484,6 +487,7 @@ int security_path_truncate(struct path *
35724 return call_int_hook(path_truncate, 0, path);
35726 +EXPORT_SYMBOL(security_path_truncate);
35728 int security_path_chmod(struct path *path, umode_t mode)
35730 @@ -491,6 +495,7 @@ int security_path_chmod(struct path *pat
35732 return call_int_hook(path_chmod, 0, path, mode);
35734 +EXPORT_SYMBOL(security_path_chmod);
35736 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
35738 @@ -498,6 +503,7 @@ int security_path_chown(struct path *pat
35740 return call_int_hook(path_chown, 0, path, uid, gid);
35742 +EXPORT_SYMBOL(security_path_chown);
35744 int security_path_chroot(struct path *path)
35746 @@ -583,6 +589,7 @@ int security_inode_readlink(struct dentr
35748 return call_int_hook(inode_readlink, 0, dentry);
35750 +EXPORT_SYMBOL(security_inode_readlink);
35752 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
35754 @@ -598,6 +605,7 @@ int security_inode_permission(struct ino
35756 return call_int_hook(inode_permission, 0, inode, mask);
35758 +EXPORT_SYMBOL(security_inode_permission);
35760 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
35762 @@ -736,6 +744,7 @@ int security_file_permission(struct file
35764 return fsnotify_perm(file, mask);
35766 +EXPORT_SYMBOL(security_file_permission);
35768 int security_file_alloc(struct file *file)
35770 @@ -795,6 +804,7 @@ int security_mmap_file(struct file *file
35772 return ima_file_mmap(file, prot);
35774 +EXPORT_SYMBOL(security_mmap_file);
35776 int security_mmap_addr(unsigned long addr)