1 From 7dd7dc8ba5f16e494206477d3880b7ed09aff118 Mon Sep 17 00:00:00 2001
2 From: Miklos Szeredi <mszeredi@suse.cz>
3 Date: Thu, 30 Aug 2012 16:13:49 +0200
4 Subject: [PATCH 04/13] overlay filesystem
5 Patch-mainline: not yet
7 Overlayfs allows one, usually read-write, directory tree to be
8 overlaid onto another, read-only directory tree. All modifications
9 go to the upper, writable layer.
11 This type of mechanism is most often used for live CDs but there's a
12 wide variety of other uses.
14 The implementation differs from other "union filesystem"
15 implementations in that after a file is opened all operations go
16 directly to the underlying, lower or upper, filesystems. This
17 simplifies the implementation and allows native performance in these
20 The dentry tree is duplicated from the underlying filesystems, this
21 enables fast cached lookups without adding special support into the
22 VFS. This uses slightly more memory than union mounts, but dentries
25 Currently inodes are duplicated as well, but it is a possible
26 optimization to share inodes for non-directories.
28 Opening non directories results in the open forwarded to the
29 underlying filesystem. This makes the behavior very similar to union
30 mounts (with the same limitations vs. fchmod/fchown on O_RDONLY file
35 mount -t overlay -olowerdir=/lower,upperdir=/upper overlay /mnt
43 - Currently a crash in the middle of copy-up, rename, unlink, rmdir or create
44 over a whiteout may result in filesystem corruption on the overlay level.
45 IOW these operations need to become atomic or at least the corruption needs
49 The following cotributions have been folded into this patch:
51 Neil Brown <neilb@suse.de>:
52 - minimal remount support
53 - use correct seek function for directories
54 - initialise is_real before use
55 - rename ovl_fill_cache to ovl_dir_read
57 Felix Fietkau <nbd@openwrt.org>:
58 - fix a deadlock in ovl_dir_read_merged
59 - fix a deadlock in ovl_remove_whiteouts
61 Erez Zadok <ezk@fsl.cs.sunysb.edu>
62 - fix cleanup after WARN_ON
64 Sedat Dilek <sedat.dilek@googlemail.com>
65 - fix up permission to confirm to new API
67 Robin Dong <hao.bigrat@gmail.com>
68 - fix possible leak in ovl_new_inode
69 - create new inode in ovl_link
71 Andy Whitcroft <apw@canonical.com>
72 - switch to __inode_permission()
73 - copy up i_uid/i_gid from the underlying inode
75 Also thanks to the following people for testing and reporting bugs:
77 Jordi Pujol <jordipujolp@gmail.com>
78 Andy Whitcroft <apw@canonical.com>
79 Michal Suchanek <hramrach@centrum.cz>
80 Felix Fietkau <nbd@openwrt.org>
81 Erez Zadok <ezk@fsl.cs.sunysb.edu>
82 Randy Dunlap <rdunlap@xenotime.net>
84 Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
88 fs/overlayfs/Kconfig | 10
89 fs/overlayfs/Makefile | 7
90 fs/overlayfs/copy_up.c | 388 +++++++++++++++++++++++++++++
91 fs/overlayfs/dir.c | 605 ++++++++++++++++++++++++++++++++++++++++++++++
92 fs/overlayfs/inode.c | 372 ++++++++++++++++++++++++++++
93 fs/overlayfs/overlayfs.h | 70 +++++
94 fs/overlayfs/readdir.c | 567 +++++++++++++++++++++++++++++++++++++++++++
95 fs/overlayfs/super.c | 612 +++++++++++++++++++++++++++++++++++++++++++++++
96 10 files changed, 2633 insertions(+)
100 @@ -67,6 +67,7 @@ source "fs/quota/Kconfig"
102 source "fs/autofs4/Kconfig"
103 source "fs/fuse/Kconfig"
104 +source "fs/overlayfs/Kconfig"
110 @@ -105,6 +105,7 @@ obj-$(CONFIG_QNX6FS_FS) += qnx6/
111 obj-$(CONFIG_AUTOFS4_FS) += autofs4/
112 obj-$(CONFIG_ADFS_FS) += adfs/
113 obj-$(CONFIG_FUSE_FS) += fuse/
114 +obj-$(CONFIG_OVERLAYFS_FS) += overlayfs/
115 obj-$(CONFIG_UDF_FS) += udf/
116 obj-$(CONFIG_SUN_OPENPROMFS) += openpromfs/
117 obj-$(CONFIG_OMFS_FS) += omfs/
119 +++ b/fs/overlayfs/Kconfig
122 + tristate "Overlay filesystem support"
124 + An overlay filesystem combines two filesystems - an 'upper' filesystem
125 + and a 'lower' filesystem. When a name exists in both filesystems, the
126 + object in the 'upper' filesystem is visible while the object in the
127 + 'lower' filesystem is either hidden or, in the case of directories,
128 + merged with the 'upper' object.
130 + For more information see Documentation/filesystems/overlayfs.txt
132 +++ b/fs/overlayfs/Makefile
135 +# Makefile for the overlay filesystem.
138 +obj-$(CONFIG_OVERLAYFS_FS) += overlayfs.o
140 +overlayfs-objs := super.o inode.o dir.o readdir.o copy_up.o
142 +++ b/fs/overlayfs/copy_up.c
146 + * Copyright (C) 2011 Novell Inc.
148 + * This program is free software; you can redistribute it and/or modify it
149 + * under the terms of the GNU General Public License version 2 as published by
150 + * the Free Software Foundation.
153 +#include <linux/fs.h>
154 +#include <linux/slab.h>
155 +#include <linux/file.h>
156 +#include <linux/splice.h>
157 +#include <linux/xattr.h>
158 +#include <linux/security.h>
159 +#include <linux/uaccess.h>
160 +#include <linux/sched.h>
161 +#include "overlayfs.h"
163 +#define OVL_COPY_UP_CHUNK_SIZE (1 << 20)
165 +static int ovl_copy_up_xattr(struct dentry *old, struct dentry *new)
167 + ssize_t list_size, size;
168 + char *buf, *name, *value;
171 + if (!old->d_inode->i_op->getxattr ||
172 + !new->d_inode->i_op->getxattr)
175 + list_size = vfs_listxattr(old, NULL, 0);
176 + if (list_size <= 0) {
177 + if (list_size == -EOPNOTSUPP)
182 + buf = kzalloc(list_size, GFP_KERNEL);
187 + value = kmalloc(XATTR_SIZE_MAX, GFP_KERNEL);
191 + list_size = vfs_listxattr(old, buf, list_size);
192 + if (list_size <= 0) {
194 + goto out_free_value;
197 + for (name = buf; name < (buf + list_size); name += strlen(name) + 1) {
198 + size = vfs_getxattr(old, name, value, XATTR_SIZE_MAX);
201 + goto out_free_value;
203 + error = vfs_setxattr(new, name, value, size, 0);
205 + goto out_free_value;
215 +static int ovl_copy_up_data(struct path *old, struct path *new, loff_t len)
217 + struct file *old_file;
218 + struct file *new_file;
219 + loff_t old_pos = 0;
220 + loff_t new_pos = 0;
226 + old_file = ovl_path_open(old, O_RDONLY);
227 + if (IS_ERR(old_file))
228 + return PTR_ERR(old_file);
230 + new_file = ovl_path_open(new, O_WRONLY);
231 + if (IS_ERR(new_file)) {
232 + error = PTR_ERR(new_file);
236 + /* FIXME: copy up sparse files efficiently */
238 + size_t this_len = OVL_COPY_UP_CHUNK_SIZE;
241 + if (len < this_len)
244 + if (signal_pending_state(TASK_KILLABLE, current)) {
249 + bytes = do_splice_direct(old_file, &old_pos,
250 + new_file, &new_pos,
251 + this_len, SPLICE_F_MOVE);
256 + WARN_ON(old_pos != new_pos);
267 +static char *ovl_read_symlink(struct dentry *realdentry)
271 + struct inode *inode = realdentry->d_inode;
272 + mm_segment_t old_fs;
275 + if (!inode->i_op->readlink)
279 + buf = (char *) __get_free_page(GFP_KERNEL);
285 + /* The cast to a user pointer is valid due to the set_fs() */
286 + res = inode->i_op->readlink(realdentry,
287 + (char __user *)buf, PAGE_SIZE - 1);
290 + free_page((unsigned long) buf);
298 + return ERR_PTR(res);
301 +static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat)
303 + struct iattr attr = {
305 + ATTR_ATIME | ATTR_MTIME | ATTR_ATIME_SET | ATTR_MTIME_SET,
306 + .ia_atime = stat->atime,
307 + .ia_mtime = stat->mtime,
310 + return notify_change(upperdentry, &attr, NULL);
313 +static int ovl_set_mode(struct dentry *upperdentry, umode_t mode)
315 + struct iattr attr = {
316 + .ia_valid = ATTR_MODE,
320 + return notify_change(upperdentry, &attr, NULL);
323 +static int ovl_copy_up_locked(struct dentry *upperdir, struct dentry *dentry,
324 + struct path *lowerpath, struct kstat *stat,
328 + struct path newpath;
329 + umode_t mode = stat->mode;
331 + /* Can't properly set mode on creation because of the umask */
332 + stat->mode &= S_IFMT;
334 + ovl_path_upper(dentry, &newpath);
335 + WARN_ON(newpath.dentry);
336 + newpath.dentry = ovl_upper_create(upperdir, dentry, stat, link);
337 + if (IS_ERR(newpath.dentry))
338 + return PTR_ERR(newpath.dentry);
340 + if (S_ISREG(stat->mode)) {
341 + err = ovl_copy_up_data(lowerpath, &newpath, stat->size);
346 + err = ovl_copy_up_xattr(lowerpath->dentry, newpath.dentry);
350 + mutex_lock(&newpath.dentry->d_inode->i_mutex);
351 + if (!S_ISLNK(stat->mode))
352 + err = ovl_set_mode(newpath.dentry, mode);
354 + err = ovl_set_timestamps(newpath.dentry, stat);
355 + mutex_unlock(&newpath.dentry->d_inode->i_mutex);
359 + ovl_dentry_update(dentry, newpath.dentry);
362 + * Easiest way to get rid of the lower dentry reference is to
363 + * drop this dentry. This is neither needed nor possible for
366 + if (!S_ISDIR(stat->mode))
372 + if (S_ISDIR(stat->mode))
373 + vfs_rmdir(upperdir->d_inode, newpath.dentry);
375 + vfs_unlink(upperdir->d_inode, newpath.dentry, NULL);
377 + dput(newpath.dentry);
383 + * Copy up a single dentry
385 + * Directory renames only allowed on "pure upper" (already created on
386 + * upper filesystem, never copied up). Directories which are on lower or
387 + * are merged may not be renamed. For these -EXDEV is returned and
388 + * userspace has to deal with it. This means, when copying up a
389 + * directory we can rely on it and ancestors being stable.
391 + * Non-directory renames start with copy up of source if necessary. The
392 + * actual rename will only proceed once the copy up was successful. Copy
393 + * up uses upper parent i_mutex for exclusion. Since rename can change
394 + * d_parent it is possible that the copy up will lock the old parent. At
395 + * that point the file will have already been copied up anyway.
397 +static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
398 + struct path *lowerpath, struct kstat *stat)
401 + struct kstat pstat;
402 + struct path parentpath;
403 + struct dentry *upperdir;
404 + const struct cred *old_cred;
405 + struct cred *override_cred;
408 + ovl_path_upper(parent, &parentpath);
409 + upperdir = parentpath.dentry;
411 + err = vfs_getattr(&parentpath, &pstat);
415 + if (S_ISLNK(stat->mode)) {
416 + link = ovl_read_symlink(lowerpath->dentry);
418 + return PTR_ERR(link);
422 + override_cred = prepare_creds();
423 + if (!override_cred)
424 + goto out_free_link;
426 + override_cred->fsuid = stat->uid;
427 + override_cred->fsgid = stat->gid;
429 + * CAP_SYS_ADMIN for copying up extended attributes
430 + * CAP_DAC_OVERRIDE for create
431 + * CAP_FOWNER for chmod, timestamp update
432 + * CAP_FSETID for chmod
433 + * CAP_MKNOD for mknod
435 + cap_raise(override_cred->cap_effective, CAP_SYS_ADMIN);
436 + cap_raise(override_cred->cap_effective, CAP_DAC_OVERRIDE);
437 + cap_raise(override_cred->cap_effective, CAP_FOWNER);
438 + cap_raise(override_cred->cap_effective, CAP_FSETID);
439 + cap_raise(override_cred->cap_effective, CAP_MKNOD);
440 + old_cred = override_creds(override_cred);
442 + mutex_lock_nested(&upperdir->d_inode->i_mutex, I_MUTEX_PARENT);
443 + if (ovl_path_type(dentry) != OVL_PATH_LOWER) {
446 + err = ovl_copy_up_locked(upperdir, dentry, lowerpath,
449 + /* Restore timestamps on parent (best effort) */
450 + ovl_set_timestamps(upperdir, &pstat);
454 + mutex_unlock(&upperdir->d_inode->i_mutex);
456 + revert_creds(old_cred);
457 + put_cred(override_cred);
461 + free_page((unsigned long) link);
466 +int ovl_copy_up(struct dentry *dentry)
472 + struct dentry *next;
473 + struct dentry *parent;
474 + struct path lowerpath;
476 + enum ovl_path_type type = ovl_path_type(dentry);
478 + if (type != OVL_PATH_LOWER)
481 + next = dget(dentry);
482 + /* find the topmost dentry not yet copied up */
484 + parent = dget_parent(next);
486 + type = ovl_path_type(parent);
487 + if (type != OVL_PATH_LOWER)
494 + ovl_path_lower(next, &lowerpath);
495 + err = vfs_getattr(&lowerpath, &stat);
497 + err = ovl_copy_up_one(parent, next, &lowerpath, &stat);
506 +/* Optimize by not copying up the file first and truncating later */
507 +int ovl_copy_up_truncate(struct dentry *dentry, loff_t size)
511 + struct path lowerpath;
512 + struct dentry *parent = dget_parent(dentry);
514 + err = ovl_copy_up(parent);
516 + goto out_dput_parent;
518 + ovl_path_lower(dentry, &lowerpath);
519 + err = vfs_getattr(&lowerpath, &stat);
521 + goto out_dput_parent;
523 + if (size < stat.size)
526 + err = ovl_copy_up_one(parent, dentry, &lowerpath, &stat);
533 +++ b/fs/overlayfs/dir.c
537 + * Copyright (C) 2011 Novell Inc.
539 + * This program is free software; you can redistribute it and/or modify it
540 + * under the terms of the GNU General Public License version 2 as published by
541 + * the Free Software Foundation.
544 +#include <linux/fs.h>
545 +#include <linux/namei.h>
546 +#include <linux/xattr.h>
547 +#include <linux/security.h>
548 +#include <linux/cred.h>
549 +#include "overlayfs.h"
551 +static const char *ovl_whiteout_symlink = "(overlay-whiteout)";
553 +static int ovl_whiteout(struct dentry *upperdir, struct dentry *dentry)
556 + struct dentry *newdentry;
557 + const struct cred *old_cred;
558 + struct cred *override_cred;
560 + /* FIXME: recheck lower dentry to see if whiteout is really needed */
563 + override_cred = prepare_creds();
564 + if (!override_cred)
568 + * CAP_SYS_ADMIN for setxattr
569 + * CAP_DAC_OVERRIDE for symlink creation
570 + * CAP_FOWNER for unlink in sticky directory
572 + cap_raise(override_cred->cap_effective, CAP_SYS_ADMIN);
573 + cap_raise(override_cred->cap_effective, CAP_DAC_OVERRIDE);
574 + cap_raise(override_cred->cap_effective, CAP_FOWNER);
575 + override_cred->fsuid = GLOBAL_ROOT_UID;
576 + override_cred->fsgid = GLOBAL_ROOT_GID;
577 + old_cred = override_creds(override_cred);
579 + newdentry = lookup_one_len(dentry->d_name.name, upperdir,
580 + dentry->d_name.len);
581 + err = PTR_ERR(newdentry);
582 + if (IS_ERR(newdentry))
585 + /* Just been removed within the same locked region */
586 + WARN_ON(newdentry->d_inode);
588 + err = vfs_symlink(upperdir->d_inode, newdentry, ovl_whiteout_symlink);
592 + ovl_dentry_version_inc(dentry->d_parent);
594 + err = vfs_setxattr(newdentry, ovl_whiteout_xattr, "y", 1, 0);
596 + vfs_unlink(upperdir->d_inode, newdentry, NULL);
601 + revert_creds(old_cred);
602 + put_cred(override_cred);
606 + * There's no way to recover from failure to whiteout.
607 + * What should we do? Log a big fat error and... ?
609 + pr_err("overlayfs: ERROR - failed to whiteout '%s'\n",
610 + dentry->d_name.name);
616 +static struct dentry *ovl_lookup_create(struct dentry *upperdir,
617 + struct dentry *template)
620 + struct dentry *newdentry;
621 + struct qstr *name = &template->d_name;
623 + newdentry = lookup_one_len(name->name, upperdir, name->len);
624 + if (IS_ERR(newdentry))
627 + if (newdentry->d_inode) {
628 + const struct cred *old_cred;
629 + struct cred *override_cred;
631 + /* No need to check whiteout if lower parent is non-existent */
633 + if (!ovl_dentry_lower(template->d_parent))
636 + if (!S_ISLNK(newdentry->d_inode->i_mode))
640 + override_cred = prepare_creds();
641 + if (!override_cred)
645 + * CAP_SYS_ADMIN for getxattr
646 + * CAP_FOWNER for unlink in sticky directory
648 + cap_raise(override_cred->cap_effective, CAP_SYS_ADMIN);
649 + cap_raise(override_cred->cap_effective, CAP_FOWNER);
650 + old_cred = override_creds(override_cred);
653 + if (ovl_is_whiteout(newdentry))
654 + err = vfs_unlink(upperdir->d_inode, newdentry, NULL);
656 + revert_creds(old_cred);
657 + put_cred(override_cred);
662 + newdentry = lookup_one_len(name->name, upperdir, name->len);
663 + if (IS_ERR(newdentry)) {
664 + ovl_whiteout(upperdir, template);
669 + * Whiteout just been successfully removed, parent
670 + * i_mutex is still held, there's no way the lookup
671 + * could return positive.
673 + WARN_ON(newdentry->d_inode);
680 + return ERR_PTR(err);
683 +struct dentry *ovl_upper_create(struct dentry *upperdir, struct dentry *dentry,
684 + struct kstat *stat, const char *link)
687 + struct dentry *newdentry;
688 + struct inode *dir = upperdir->d_inode;
690 + newdentry = ovl_lookup_create(upperdir, dentry);
691 + if (IS_ERR(newdentry))
694 + switch (stat->mode & S_IFMT) {
696 + err = vfs_create(dir, newdentry, stat->mode, NULL);
700 + err = vfs_mkdir(dir, newdentry, stat->mode);
707 + err = vfs_mknod(dir, newdentry, stat->mode, stat->rdev);
711 + err = vfs_symlink(dir, newdentry, link);
718 + if (ovl_dentry_is_opaque(dentry))
719 + ovl_whiteout(upperdir, dentry);
721 + newdentry = ERR_PTR(err);
722 + } else if (WARN_ON(!newdentry->d_inode)) {
724 + * Not quite sure if non-instantiated dentry is legal or not.
725 + * VFS doesn't seem to care so check and warn here.
728 + newdentry = ERR_PTR(-ENOENT);
736 +static int ovl_set_opaque(struct dentry *upperdentry)
739 + const struct cred *old_cred;
740 + struct cred *override_cred;
742 + override_cred = prepare_creds();
743 + if (!override_cred)
746 + /* CAP_SYS_ADMIN for setxattr of "trusted" namespace */
747 + cap_raise(override_cred->cap_effective, CAP_SYS_ADMIN);
748 + old_cred = override_creds(override_cred);
749 + err = vfs_setxattr(upperdentry, ovl_opaque_xattr, "y", 1, 0);
750 + revert_creds(old_cred);
751 + put_cred(override_cred);
756 +static int ovl_remove_opaque(struct dentry *upperdentry)
759 + const struct cred *old_cred;
760 + struct cred *override_cred;
762 + override_cred = prepare_creds();
763 + if (!override_cred)
766 + /* CAP_SYS_ADMIN for removexattr of "trusted" namespace */
767 + cap_raise(override_cred->cap_effective, CAP_SYS_ADMIN);
768 + old_cred = override_creds(override_cred);
769 + err = vfs_removexattr(upperdentry, ovl_opaque_xattr);
770 + revert_creds(old_cred);
771 + put_cred(override_cred);
776 +static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry,
777 + struct kstat *stat)
780 + enum ovl_path_type type;
781 + struct path realpath;
783 + type = ovl_path_real(dentry, &realpath);
784 + err = vfs_getattr(&realpath, stat);
788 + stat->dev = dentry->d_sb->s_dev;
789 + stat->ino = dentry->d_inode->i_ino;
792 + * It's probably not worth it to count subdirs to get the
793 + * correct link count. nlink=1 seems to pacify 'find' and
796 + if (type == OVL_PATH_MERGE)
802 +static int ovl_create_object(struct dentry *dentry, int mode, dev_t rdev,
806 + struct dentry *newdentry;
807 + struct dentry *upperdir;
808 + struct inode *inode;
809 + struct kstat stat = {
815 + inode = ovl_new_inode(dentry->d_sb, mode, dentry->d_fsdata);
819 + err = ovl_copy_up(dentry->d_parent);
823 + upperdir = ovl_dentry_upper(dentry->d_parent);
824 + mutex_lock_nested(&upperdir->d_inode->i_mutex, I_MUTEX_PARENT);
826 + newdentry = ovl_upper_create(upperdir, dentry, &stat, link);
827 + err = PTR_ERR(newdentry);
828 + if (IS_ERR(newdentry))
831 + ovl_dentry_version_inc(dentry->d_parent);
832 + if (ovl_dentry_is_opaque(dentry) && S_ISDIR(mode)) {
833 + err = ovl_set_opaque(newdentry);
835 + vfs_rmdir(upperdir->d_inode, newdentry);
836 + ovl_whiteout(upperdir, dentry);
840 + ovl_dentry_update(dentry, newdentry);
841 + ovl_copyattr(newdentry->d_inode, inode);
842 + d_instantiate(dentry, inode);
850 + mutex_unlock(&upperdir->d_inode->i_mutex);
857 +static int ovl_create(struct inode *dir, struct dentry *dentry, umode_t mode,
860 + return ovl_create_object(dentry, (mode & 07777) | S_IFREG, 0, NULL);
863 +static int ovl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
865 + return ovl_create_object(dentry, (mode & 07777) | S_IFDIR, 0, NULL);
868 +static int ovl_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
871 + return ovl_create_object(dentry, mode, rdev, NULL);
874 +static int ovl_symlink(struct inode *dir, struct dentry *dentry,
877 + return ovl_create_object(dentry, S_IFLNK, 0, link);
880 +static int ovl_do_remove(struct dentry *dentry, bool is_dir)
883 + enum ovl_path_type type;
884 + struct path realpath;
885 + struct dentry *upperdir;
887 + err = ovl_copy_up(dentry->d_parent);
891 + upperdir = ovl_dentry_upper(dentry->d_parent);
892 + mutex_lock_nested(&upperdir->d_inode->i_mutex, I_MUTEX_PARENT);
893 + type = ovl_path_real(dentry, &realpath);
894 + if (type != OVL_PATH_LOWER) {
896 + if (realpath.dentry->d_parent != upperdir)
899 + /* FIXME: create whiteout up front and rename to target */
902 + err = vfs_rmdir(upperdir->d_inode, realpath.dentry);
904 + err = vfs_unlink(upperdir->d_inode, realpath.dentry,
909 + ovl_dentry_version_inc(dentry->d_parent);
912 + if (type != OVL_PATH_UPPER || ovl_dentry_is_opaque(dentry))
913 + err = ovl_whiteout(upperdir, dentry);
916 + * Keeping this dentry hashed would mean having to release
917 + * upperpath/lowerpath, which could only be done if we are the
918 + * sole user of this dentry. Too tricky... Just unhash for
923 + mutex_unlock(&upperdir->d_inode->i_mutex);
928 +static int ovl_unlink(struct inode *dir, struct dentry *dentry)
930 + return ovl_do_remove(dentry, false);
934 +static int ovl_rmdir(struct inode *dir, struct dentry *dentry)
937 + enum ovl_path_type type;
939 + type = ovl_path_type(dentry);
940 + if (type != OVL_PATH_UPPER) {
941 + err = ovl_check_empty_and_clear(dentry, type);
946 + return ovl_do_remove(dentry, true);
949 +static int ovl_link(struct dentry *old, struct inode *newdir,
950 + struct dentry *new)
953 + struct dentry *olddentry;
954 + struct dentry *newdentry;
955 + struct dentry *upperdir;
956 + struct inode *newinode;
958 + err = ovl_copy_up(old);
962 + err = ovl_copy_up(new->d_parent);
966 + upperdir = ovl_dentry_upper(new->d_parent);
967 + mutex_lock_nested(&upperdir->d_inode->i_mutex, I_MUTEX_PARENT);
968 + newdentry = ovl_lookup_create(upperdir, new);
969 + err = PTR_ERR(newdentry);
970 + if (IS_ERR(newdentry))
973 + olddentry = ovl_dentry_upper(old);
974 + err = vfs_link(olddentry, upperdir->d_inode, newdentry, NULL);
976 + if (WARN_ON(!newdentry->d_inode)) {
981 + newinode = ovl_new_inode(old->d_sb, newdentry->d_inode->i_mode,
987 + ovl_copyattr(upperdir->d_inode, newinode);
989 + ovl_dentry_version_inc(new->d_parent);
990 + ovl_dentry_update(new, newdentry);
992 + d_instantiate(new, newinode);
995 + if (ovl_dentry_is_opaque(new))
996 + ovl_whiteout(upperdir, new);
1000 + mutex_unlock(&upperdir->d_inode->i_mutex);
1005 +static int ovl_rename(struct inode *olddir, struct dentry *old,
1006 + struct inode *newdir, struct dentry *new)
1009 + enum ovl_path_type old_type;
1010 + enum ovl_path_type new_type;
1011 + struct dentry *old_upperdir;
1012 + struct dentry *new_upperdir;
1013 + struct dentry *olddentry;
1014 + struct dentry *newdentry;
1015 + struct dentry *trap;
1018 + bool new_create = false;
1019 + bool is_dir = S_ISDIR(old->d_inode->i_mode);
1021 + /* Don't copy up directory trees */
1022 + old_type = ovl_path_type(old);
1023 + if (old_type != OVL_PATH_UPPER && is_dir)
1026 + if (new->d_inode) {
1027 + new_type = ovl_path_type(new);
1029 + if (new_type == OVL_PATH_LOWER && old_type == OVL_PATH_LOWER) {
1030 + if (ovl_dentry_lower(old)->d_inode ==
1031 + ovl_dentry_lower(new)->d_inode)
1034 + if (new_type != OVL_PATH_LOWER && old_type != OVL_PATH_LOWER) {
1035 + if (ovl_dentry_upper(old)->d_inode ==
1036 + ovl_dentry_upper(new)->d_inode)
1040 + if (new_type != OVL_PATH_UPPER &&
1041 + S_ISDIR(new->d_inode->i_mode)) {
1042 + err = ovl_check_empty_and_clear(new, new_type);
1047 + new_type = OVL_PATH_UPPER;
1050 + err = ovl_copy_up(old);
1054 + err = ovl_copy_up(new->d_parent);
1058 + old_upperdir = ovl_dentry_upper(old->d_parent);
1059 + new_upperdir = ovl_dentry_upper(new->d_parent);
1061 + trap = lock_rename(new_upperdir, old_upperdir);
1063 + olddentry = ovl_dentry_upper(old);
1064 + newdentry = ovl_dentry_upper(new);
1068 + new_create = true;
1069 + newdentry = ovl_lookup_create(new_upperdir, new);
1070 + err = PTR_ERR(newdentry);
1071 + if (IS_ERR(newdentry))
1076 + if (olddentry->d_parent != old_upperdir)
1078 + if (newdentry->d_parent != new_upperdir)
1080 + if (olddentry == trap)
1082 + if (newdentry == trap)
1085 + old_opaque = ovl_dentry_is_opaque(old);
1086 + new_opaque = ovl_dentry_is_opaque(new) || new_type != OVL_PATH_UPPER;
1088 + if (is_dir && !old_opaque && new_opaque) {
1089 + err = ovl_set_opaque(olddentry);
1094 + err = vfs_rename(old_upperdir->d_inode, olddentry,
1095 + new_upperdir->d_inode, newdentry, NULL);
1098 + if (new_create && ovl_dentry_is_opaque(new))
1099 + ovl_whiteout(new_upperdir, new);
1100 + if (is_dir && !old_opaque && new_opaque)
1101 + ovl_remove_opaque(olddentry);
1105 + if (old_type != OVL_PATH_UPPER || old_opaque)
1106 + err = ovl_whiteout(old_upperdir, old);
1107 + if (is_dir && old_opaque && !new_opaque)
1108 + ovl_remove_opaque(olddentry);
1110 + if (old_opaque != new_opaque)
1111 + ovl_dentry_set_opaque(old, new_opaque);
1113 + ovl_dentry_version_inc(old->d_parent);
1114 + ovl_dentry_version_inc(new->d_parent);
1119 + unlock_rename(new_upperdir, old_upperdir);
1123 +const struct inode_operations ovl_dir_inode_operations = {
1124 + .lookup = ovl_lookup,
1125 + .mkdir = ovl_mkdir,
1126 + .symlink = ovl_symlink,
1127 + .unlink = ovl_unlink,
1128 + .rmdir = ovl_rmdir,
1129 + .rename = ovl_rename,
1131 + .setattr = ovl_setattr,
1132 + .create = ovl_create,
1133 + .mknod = ovl_mknod,
1134 + .permission = ovl_permission,
1135 + .getattr = ovl_dir_getattr,
1136 + .setxattr = ovl_setxattr,
1137 + .getxattr = ovl_getxattr,
1138 + .listxattr = ovl_listxattr,
1139 + .removexattr = ovl_removexattr,
1142 +++ b/fs/overlayfs/inode.c
1146 + * Copyright (C) 2011 Novell Inc.
1148 + * This program is free software; you can redistribute it and/or modify it
1149 + * under the terms of the GNU General Public License version 2 as published by
1150 + * the Free Software Foundation.
1153 +#include <linux/fs.h>
1154 +#include <linux/slab.h>
1155 +#include <linux/xattr.h>
1156 +#include "overlayfs.h"
1158 +int ovl_setattr(struct dentry *dentry, struct iattr *attr)
1160 + struct dentry *upperdentry;
1163 + if ((attr->ia_valid & ATTR_SIZE) && !ovl_dentry_upper(dentry))
1164 + err = ovl_copy_up_truncate(dentry, attr->ia_size);
1166 + err = ovl_copy_up(dentry);
1170 + upperdentry = ovl_dentry_upper(dentry);
1172 + if (attr->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
1173 + attr->ia_valid &= ~ATTR_MODE;
1175 + mutex_lock(&upperdentry->d_inode->i_mutex);
1176 + err = notify_change(upperdentry, attr, NULL);
1178 + ovl_copyattr(upperdentry->d_inode, dentry->d_inode);
1179 + mutex_unlock(&upperdentry->d_inode->i_mutex);
1184 +static int ovl_getattr(struct vfsmount *mnt, struct dentry *dentry,
1185 + struct kstat *stat)
1187 + struct path realpath;
1189 + ovl_path_real(dentry, &realpath);
1190 + return vfs_getattr(&realpath, stat);
1193 +int ovl_permission(struct inode *inode, int mask)
1195 + struct ovl_entry *oe;
1196 + struct dentry *alias = NULL;
1197 + struct inode *realinode;
1198 + struct dentry *realdentry;
1202 + if (S_ISDIR(inode->i_mode)) {
1203 + oe = inode->i_private;
1204 + } else if (mask & MAY_NOT_BLOCK) {
1208 + * For non-directories find an alias and get the info
1211 + alias = d_find_any_alias(inode);
1212 + if (WARN_ON(!alias))
1215 + oe = alias->d_fsdata;
1218 + realdentry = ovl_entry_real(oe, &is_upper);
1220 + /* Careful in RCU walk mode */
1221 + realinode = ACCESS_ONCE(realdentry->d_inode);
1223 + WARN_ON(!(mask & MAY_NOT_BLOCK));
1228 + if (mask & MAY_WRITE) {
1229 + umode_t mode = realinode->i_mode;
1232 + * Writes will always be redirected to upper layer, so
1233 + * ignore lower layer being read-only.
1235 + * If the overlay itself is read-only then proceed
1236 + * with the permission check, don't return EROFS.
1237 + * This will only happen if this is the lower layer of
1238 + * another overlayfs.
1240 + * If upper fs becomes read-only after the overlay was
1241 + * constructed return EROFS to prevent modification of
1245 + if (is_upper && !IS_RDONLY(inode) && IS_RDONLY(realinode) &&
1246 + (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
1250 + err = __inode_permission(realinode, mask);
1257 +struct ovl_link_data {
1258 + struct dentry *realdentry;
1262 +static void *ovl_follow_link(struct dentry *dentry, struct nameidata *nd)
1265 + struct dentry *realdentry;
1266 + struct inode *realinode;
1268 + realdentry = ovl_dentry_real(dentry);
1269 + realinode = realdentry->d_inode;
1271 + if (WARN_ON(!realinode->i_op->follow_link))
1272 + return ERR_PTR(-EPERM);
1274 + ret = realinode->i_op->follow_link(realdentry, nd);
1278 + if (realinode->i_op->put_link) {
1279 + struct ovl_link_data *data;
1281 + data = kmalloc(sizeof(struct ovl_link_data), GFP_KERNEL);
1283 + realinode->i_op->put_link(realdentry, nd, ret);
1284 + return ERR_PTR(-ENOMEM);
1286 + data->realdentry = realdentry;
1287 + data->cookie = ret;
1295 +static void ovl_put_link(struct dentry *dentry, struct nameidata *nd, void *c)
1297 + struct inode *realinode;
1298 + struct ovl_link_data *data = c;
1303 + realinode = data->realdentry->d_inode;
1304 + realinode->i_op->put_link(data->realdentry, nd, data->cookie);
1308 +static int ovl_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
1310 + struct path realpath;
1311 + struct inode *realinode;
1313 + ovl_path_real(dentry, &realpath);
1314 + realinode = realpath.dentry->d_inode;
1316 + if (!realinode->i_op->readlink)
1319 + touch_atime(&realpath);
1321 + return realinode->i_op->readlink(realpath.dentry, buf, bufsiz);
1325 +static bool ovl_is_private_xattr(const char *name)
1327 + return strncmp(name, "trusted.overlay.", 14) == 0;
1330 +int ovl_setxattr(struct dentry *dentry, const char *name,
1331 + const void *value, size_t size, int flags)
1334 + struct dentry *upperdentry;
1336 + if (ovl_is_private_xattr(name))
1339 + err = ovl_copy_up(dentry);
1343 + upperdentry = ovl_dentry_upper(dentry);
1344 + return vfs_setxattr(upperdentry, name, value, size, flags);
1347 +ssize_t ovl_getxattr(struct dentry *dentry, const char *name,
1348 + void *value, size_t size)
1350 + if (ovl_path_type(dentry->d_parent) == OVL_PATH_MERGE &&
1351 + ovl_is_private_xattr(name))
1354 + return vfs_getxattr(ovl_dentry_real(dentry), name, value, size);
1357 +ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
1362 + res = vfs_listxattr(ovl_dentry_real(dentry), list, size);
1363 + if (res <= 0 || size == 0)
1366 + if (ovl_path_type(dentry->d_parent) != OVL_PATH_MERGE)
1369 + /* filter out private xattrs */
1370 + for (off = 0; off < res;) {
1371 + char *s = list + off;
1372 + size_t slen = strlen(s) + 1;
1374 + BUG_ON(off + slen > res);
1376 + if (ovl_is_private_xattr(s)) {
1378 + memmove(s, s + slen, res - off);
1387 +int ovl_removexattr(struct dentry *dentry, const char *name)
1390 + struct path realpath;
1391 + enum ovl_path_type type;
1393 + if (ovl_path_type(dentry->d_parent) == OVL_PATH_MERGE &&
1394 + ovl_is_private_xattr(name))
1397 + type = ovl_path_real(dentry, &realpath);
1398 + if (type == OVL_PATH_LOWER) {
1399 + err = vfs_getxattr(realpath.dentry, name, NULL, 0);
1403 + err = ovl_copy_up(dentry);
1407 + ovl_path_upper(dentry, &realpath);
1410 + return vfs_removexattr(realpath.dentry, name);
1413 +static bool ovl_open_need_copy_up(int flags, enum ovl_path_type type,
1414 + struct dentry *realdentry)
1416 + if (type != OVL_PATH_LOWER)
1419 + if (special_file(realdentry->d_inode->i_mode))
1422 + if (!(OPEN_FMODE(flags) & FMODE_WRITE) && !(flags & O_TRUNC))
1428 +static int ovl_dentry_open(struct dentry *dentry, struct file *file,
1429 + const struct cred *cred)
1432 + struct path realpath;
1433 + enum ovl_path_type type;
1435 + type = ovl_path_real(dentry, &realpath);
1436 + if (ovl_open_need_copy_up(file->f_flags, type, realpath.dentry)) {
1437 + if (file->f_flags & O_TRUNC)
1438 + err = ovl_copy_up_truncate(dentry, 0);
1440 + err = ovl_copy_up(dentry);
1444 + ovl_path_upper(dentry, &realpath);
1447 + return vfs_open(&realpath, file, cred);
1450 +static const struct inode_operations ovl_file_inode_operations = {
1451 + .setattr = ovl_setattr,
1452 + .permission = ovl_permission,
1453 + .getattr = ovl_getattr,
1454 + .setxattr = ovl_setxattr,
1455 + .getxattr = ovl_getxattr,
1456 + .listxattr = ovl_listxattr,
1457 + .removexattr = ovl_removexattr,
1458 + .dentry_open = ovl_dentry_open,
1461 +static const struct inode_operations ovl_symlink_inode_operations = {
1462 + .setattr = ovl_setattr,
1463 + .follow_link = ovl_follow_link,
1464 + .put_link = ovl_put_link,
1465 + .readlink = ovl_readlink,
1466 + .getattr = ovl_getattr,
1467 + .setxattr = ovl_setxattr,
1468 + .getxattr = ovl_getxattr,
1469 + .listxattr = ovl_listxattr,
1470 + .removexattr = ovl_removexattr,
1473 +struct inode *ovl_new_inode(struct super_block *sb, umode_t mode,
1474 + struct ovl_entry *oe)
1476 + struct inode *inode;
1478 + inode = new_inode(sb);
1484 + inode->i_ino = get_next_ino();
1485 + inode->i_mode = mode;
1486 + inode->i_flags |= S_NOATIME | S_NOCMTIME;
1490 + inode->i_private = oe;
1491 + inode->i_op = &ovl_dir_inode_operations;
1492 + inode->i_fop = &ovl_dir_operations;
1496 + inode->i_op = &ovl_symlink_inode_operations;
1504 + inode->i_op = &ovl_file_inode_operations;
1508 + WARN(1, "illegal file type: %i\n", mode);
1517 +++ b/fs/overlayfs/overlayfs.h
1521 + * Copyright (C) 2011 Novell Inc.
1523 + * This program is free software; you can redistribute it and/or modify it
1524 + * under the terms of the GNU General Public License version 2 as published by
1525 + * the Free Software Foundation.
1530 +enum ovl_path_type {
1536 +extern const char *ovl_opaque_xattr;
1537 +extern const char *ovl_whiteout_xattr;
1538 +extern const struct dentry_operations ovl_dentry_operations;
1540 +enum ovl_path_type ovl_path_type(struct dentry *dentry);
1541 +u64 ovl_dentry_version_get(struct dentry *dentry);
1542 +void ovl_dentry_version_inc(struct dentry *dentry);
1543 +void ovl_path_upper(struct dentry *dentry, struct path *path);
1544 +void ovl_path_lower(struct dentry *dentry, struct path *path);
1545 +enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path);
1546 +struct dentry *ovl_dentry_upper(struct dentry *dentry);
1547 +struct dentry *ovl_dentry_lower(struct dentry *dentry);
1548 +struct dentry *ovl_dentry_real(struct dentry *dentry);
1549 +struct dentry *ovl_entry_real(struct ovl_entry *oe, bool *is_upper);
1550 +bool ovl_dentry_is_opaque(struct dentry *dentry);
1551 +void ovl_dentry_set_opaque(struct dentry *dentry, bool opaque);
1552 +bool ovl_is_whiteout(struct dentry *dentry);
1553 +void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry);
1554 +struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
1555 + unsigned int flags);
1556 +struct file *ovl_path_open(struct path *path, int flags);
1558 +struct dentry *ovl_upper_create(struct dentry *upperdir, struct dentry *dentry,
1559 + struct kstat *stat, const char *link);
1562 +extern const struct file_operations ovl_dir_operations;
1563 +int ovl_check_empty_and_clear(struct dentry *dentry, enum ovl_path_type type);
1566 +int ovl_setattr(struct dentry *dentry, struct iattr *attr);
1567 +int ovl_permission(struct inode *inode, int mask);
1568 +int ovl_setxattr(struct dentry *dentry, const char *name,
1569 + const void *value, size_t size, int flags);
1570 +ssize_t ovl_getxattr(struct dentry *dentry, const char *name,
1571 + void *value, size_t size);
1572 +ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
1573 +int ovl_removexattr(struct dentry *dentry, const char *name);
1575 +struct inode *ovl_new_inode(struct super_block *sb, umode_t mode,
1576 + struct ovl_entry *oe);
1577 +static inline void ovl_copyattr(struct inode *from, struct inode *to)
1579 + to->i_uid = from->i_uid;
1580 + to->i_gid = from->i_gid;
1584 +extern const struct inode_operations ovl_dir_inode_operations;
1587 +int ovl_copy_up(struct dentry *dentry);
1588 +int ovl_copy_up_truncate(struct dentry *dentry, loff_t size);
1590 +++ b/fs/overlayfs/readdir.c
1594 + * Copyright (C) 2011 Novell Inc.
1596 + * This program is free software; you can redistribute it and/or modify it
1597 + * under the terms of the GNU General Public License version 2 as published by
1598 + * the Free Software Foundation.
1601 +#include <linux/fs.h>
1602 +#include <linux/slab.h>
1603 +#include <linux/namei.h>
1604 +#include <linux/file.h>
1605 +#include <linux/xattr.h>
1606 +#include <linux/rbtree.h>
1607 +#include <linux/security.h>
1608 +#include <linux/cred.h>
1609 +#include "overlayfs.h"
1611 +struct ovl_cache_entry {
1614 + unsigned int type;
1617 + struct list_head l_node;
1618 + struct rb_node node;
1621 +struct ovl_readdir_data {
1622 + struct dir_context ctx;
1624 + struct rb_root *root;
1625 + struct list_head *list;
1626 + struct list_head *middle;
1627 + struct dentry *dir;
1632 +struct ovl_dir_file {
1635 + struct list_head cursor;
1636 + u64 cache_version;
1637 + struct list_head cache;
1638 + struct file *realfile;
1641 +static struct ovl_cache_entry *ovl_cache_entry_from_node(struct rb_node *n)
1643 + return container_of(n, struct ovl_cache_entry, node);
1646 +static struct ovl_cache_entry *ovl_cache_entry_find(struct rb_root *root,
1647 + const char *name, int len)
1649 + struct rb_node *node = root->rb_node;
1653 + struct ovl_cache_entry *p = ovl_cache_entry_from_node(node);
1655 + cmp = strncmp(name, p->name, len);
1657 + node = p->node.rb_right;
1658 + else if (cmp < 0 || len < p->len)
1659 + node = p->node.rb_left;
1667 +static struct ovl_cache_entry *ovl_cache_entry_new(const char *name, int len,
1668 + u64 ino, unsigned int d_type)
1670 + struct ovl_cache_entry *p;
1672 + p = kmalloc(sizeof(*p) + len + 1, GFP_KERNEL);
1674 + char *name_copy = (char *) (p + 1);
1675 + memcpy(name_copy, name, len);
1676 + name_copy[len] = '\0';
1677 + p->name = name_copy;
1681 + p->is_whiteout = false;
1687 +static int ovl_cache_entry_add_rb(struct ovl_readdir_data *rdd,
1688 + const char *name, int len, u64 ino,
1689 + unsigned int d_type)
1691 + struct rb_node **newp = &rdd->root->rb_node;
1692 + struct rb_node *parent = NULL;
1693 + struct ovl_cache_entry *p;
1697 + struct ovl_cache_entry *tmp;
1700 + tmp = ovl_cache_entry_from_node(*newp);
1701 + cmp = strncmp(name, tmp->name, len);
1703 + newp = &tmp->node.rb_right;
1704 + else if (cmp < 0 || len < tmp->len)
1705 + newp = &tmp->node.rb_left;
1710 + p = ovl_cache_entry_new(name, len, ino, d_type);
1714 + list_add_tail(&p->l_node, rdd->list);
1715 + rb_link_node(&p->node, parent, newp);
1716 + rb_insert_color(&p->node, rdd->root);
1721 +static int ovl_fill_lower(struct ovl_readdir_data *rdd,
1722 + const char *name, int namelen,
1723 + loff_t offset, u64 ino, unsigned int d_type)
1725 + struct ovl_cache_entry *p;
1727 + p = ovl_cache_entry_find(rdd->root, name, namelen);
1729 + list_move_tail(&p->l_node, rdd->middle);
1731 + p = ovl_cache_entry_new(name, namelen, ino, d_type);
1733 + rdd->err = -ENOMEM;
1735 + list_add_tail(&p->l_node, rdd->middle);
1741 +static void ovl_cache_free(struct list_head *list)
1743 + struct ovl_cache_entry *p;
1744 + struct ovl_cache_entry *n;
1746 + list_for_each_entry_safe(p, n, list, l_node)
1749 + INIT_LIST_HEAD(list);
1752 +static int ovl_fill_merge(void *buf, const char *name, int namelen,
1753 + loff_t offset, u64 ino, unsigned int d_type)
1755 + struct ovl_readdir_data *rdd = buf;
1758 + if (!rdd->is_merge)
1759 + return ovl_cache_entry_add_rb(rdd, name, namelen, ino, d_type);
1761 + return ovl_fill_lower(rdd, name, namelen, offset, ino, d_type);
1764 +static inline int ovl_dir_read(struct path *realpath,
1765 + struct ovl_readdir_data *rdd)
1767 + struct file *realfile;
1770 + realfile = ovl_path_open(realpath, O_RDONLY | O_DIRECTORY);
1771 + if (IS_ERR(realfile))
1772 + return PTR_ERR(realfile);
1778 + err = iterate_dir(realfile, &rdd->ctx);
1781 + } while (!err && rdd->count);
1787 +static void ovl_dir_reset(struct file *file)
1789 + struct ovl_dir_file *od = file->private_data;
1790 + enum ovl_path_type type = ovl_path_type(file->f_path.dentry);
1792 + if (ovl_dentry_version_get(file->f_path.dentry) != od->cache_version) {
1793 + list_del_init(&od->cursor);
1794 + ovl_cache_free(&od->cache);
1795 + od->is_cached = false;
1797 + WARN_ON(!od->is_real && type != OVL_PATH_MERGE);
1798 + if (od->is_real && type == OVL_PATH_MERGE) {
1799 + fput(od->realfile);
1800 + od->realfile = NULL;
1801 + od->is_real = false;
1805 +static int ovl_dir_mark_whiteouts(struct ovl_readdir_data *rdd)
1807 + struct ovl_cache_entry *p;
1808 + struct dentry *dentry;
1809 + const struct cred *old_cred;
1810 + struct cred *override_cred;
1812 + override_cred = prepare_creds();
1813 + if (!override_cred) {
1814 + ovl_cache_free(rdd->list);
1819 + * CAP_SYS_ADMIN for getxattr
1820 + * CAP_DAC_OVERRIDE for lookup
1822 + cap_raise(override_cred->cap_effective, CAP_SYS_ADMIN);
1823 + cap_raise(override_cred->cap_effective, CAP_DAC_OVERRIDE);
1824 + old_cred = override_creds(override_cred);
1826 + mutex_lock(&rdd->dir->d_inode->i_mutex);
1827 + list_for_each_entry(p, rdd->list, l_node) {
1828 + if (p->type != DT_LNK)
1831 + dentry = lookup_one_len(p->name, rdd->dir, p->len);
1832 + if (IS_ERR(dentry))
1835 + p->is_whiteout = ovl_is_whiteout(dentry);
1838 + mutex_unlock(&rdd->dir->d_inode->i_mutex);
1840 + revert_creds(old_cred);
1841 + put_cred(override_cred);
1846 +static inline int ovl_dir_read_merged(struct path *upperpath,
1847 + struct path *lowerpath,
1848 + struct list_head *list)
1851 + struct rb_root root = RB_ROOT;
1852 + struct list_head middle;
1853 + struct ovl_readdir_data rdd = {
1854 + .ctx.actor = ovl_fill_merge,
1857 + .is_merge = false,
1860 + if (upperpath->dentry) {
1861 + rdd.dir = upperpath->dentry;
1862 + err = ovl_dir_read(upperpath, &rdd);
1866 + err = ovl_dir_mark_whiteouts(&rdd);
1871 + * Insert lowerpath entries before upperpath ones, this allows
1872 + * offsets to be reasonably constant
1874 + list_add(&middle, rdd.list);
1875 + rdd.middle = &middle;
1876 + rdd.is_merge = true;
1877 + err = ovl_dir_read(lowerpath, &rdd);
1878 + list_del(&middle);
1883 +static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos)
1885 + struct list_head *l;
1888 + l = od->cache.next;
1889 + for (off = 0; off < pos; off++) {
1890 + if (l == &od->cache)
1894 + list_move_tail(&od->cursor, l);
1897 +static int ovl_iterate(struct file *file, struct dir_context *ctx)
1899 + struct ovl_dir_file *od = file->private_data;
1903 + ovl_dir_reset(file);
1905 + if (od->is_real) {
1906 + res = iterate_dir(od->realfile, ctx);
1911 + if (!od->is_cached) {
1912 + struct path lowerpath;
1913 + struct path upperpath;
1915 + ovl_path_lower(file->f_path.dentry, &lowerpath);
1916 + ovl_path_upper(file->f_path.dentry, &upperpath);
1918 + res = ovl_dir_read_merged(&upperpath, &lowerpath, &od->cache);
1920 + ovl_cache_free(&od->cache);
1924 + od->cache_version = ovl_dentry_version_get(file->f_path.dentry);
1925 + od->is_cached = true;
1927 + ovl_seek_cursor(od, ctx->pos);
1930 + while (od->cursor.next != &od->cache) {
1931 + struct ovl_cache_entry *p;
1933 + p = list_entry(od->cursor.next, struct ovl_cache_entry, l_node);
1934 + if (!p->is_whiteout) {
1935 + if (!dir_emit(ctx, p->name, p->len, p->ino, p->type))
1939 + list_move(&od->cursor, &p->l_node);
1945 +static loff_t ovl_dir_llseek(struct file *file, loff_t offset, int origin)
1948 + struct ovl_dir_file *od = file->private_data;
1950 + mutex_lock(&file_inode(file)->i_mutex);
1952 + ovl_dir_reset(file);
1954 + if (od->is_real) {
1955 + res = vfs_llseek(od->realfile, offset, origin);
1956 + file->f_pos = od->realfile->f_pos;
1962 + offset += file->f_pos;
1972 + if (offset != file->f_pos) {
1973 + file->f_pos = offset;
1974 + if (od->is_cached)
1975 + ovl_seek_cursor(od, offset);
1980 + mutex_unlock(&file_inode(file)->i_mutex);
1985 +static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
1988 + struct ovl_dir_file *od = file->private_data;
1990 + /* May need to reopen directory if it got copied up */
1991 + if (!od->realfile) {
1992 + struct path upperpath;
1994 + ovl_path_upper(file->f_path.dentry, &upperpath);
1995 + od->realfile = ovl_path_open(&upperpath, O_RDONLY);
1996 + if (IS_ERR(od->realfile))
1997 + return PTR_ERR(od->realfile);
2000 + return vfs_fsync_range(od->realfile, start, end, datasync);
2003 +static int ovl_dir_release(struct inode *inode, struct file *file)
2005 + struct ovl_dir_file *od = file->private_data;
2007 + list_del(&od->cursor);
2008 + ovl_cache_free(&od->cache);
2010 + fput(od->realfile);
2016 +static int ovl_dir_open(struct inode *inode, struct file *file)
2018 + struct path realpath;
2019 + struct file *realfile;
2020 + struct ovl_dir_file *od;
2021 + enum ovl_path_type type;
2023 + od = kzalloc(sizeof(struct ovl_dir_file), GFP_KERNEL);
2027 + type = ovl_path_real(file->f_path.dentry, &realpath);
2028 + realfile = ovl_path_open(&realpath, file->f_flags);
2029 + if (IS_ERR(realfile)) {
2031 + return PTR_ERR(realfile);
2033 + INIT_LIST_HEAD(&od->cache);
2034 + INIT_LIST_HEAD(&od->cursor);
2035 + od->is_cached = false;
2036 + od->realfile = realfile;
2037 + od->is_real = (type != OVL_PATH_MERGE);
2038 + file->private_data = od;
2043 +const struct file_operations ovl_dir_operations = {
2044 + .read = generic_read_dir,
2045 + .open = ovl_dir_open,
2046 + .iterate = ovl_iterate,
2047 + .llseek = ovl_dir_llseek,
2048 + .fsync = ovl_dir_fsync,
2049 + .release = ovl_dir_release,
2052 +static int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
2055 + struct path lowerpath;
2056 + struct path upperpath;
2057 + struct ovl_cache_entry *p;
2059 + ovl_path_upper(dentry, &upperpath);
2060 + ovl_path_lower(dentry, &lowerpath);
2062 + err = ovl_dir_read_merged(&upperpath, &lowerpath, list);
2068 + list_for_each_entry(p, list, l_node) {
2069 + if (p->is_whiteout)
2072 + if (p->name[0] == '.') {
2075 + if (p->len == 2 && p->name[1] == '.')
2085 +static int ovl_remove_whiteouts(struct dentry *dir, struct list_head *list)
2087 + struct path upperpath;
2088 + struct dentry *upperdir;
2089 + struct ovl_cache_entry *p;
2090 + const struct cred *old_cred;
2091 + struct cred *override_cred;
2094 + ovl_path_upper(dir, &upperpath);
2095 + upperdir = upperpath.dentry;
2097 + override_cred = prepare_creds();
2098 + if (!override_cred)
2102 + * CAP_DAC_OVERRIDE for lookup and unlink
2103 + * CAP_SYS_ADMIN for setxattr of "trusted" namespace
2104 + * CAP_FOWNER for unlink in sticky directory
2106 + cap_raise(override_cred->cap_effective, CAP_DAC_OVERRIDE);
2107 + cap_raise(override_cred->cap_effective, CAP_SYS_ADMIN);
2108 + cap_raise(override_cred->cap_effective, CAP_FOWNER);
2109 + old_cred = override_creds(override_cred);
2111 + err = vfs_setxattr(upperdir, ovl_opaque_xattr, "y", 1, 0);
2113 + goto out_revert_creds;
2115 + mutex_lock_nested(&upperdir->d_inode->i_mutex, I_MUTEX_PARENT);
2116 + list_for_each_entry(p, list, l_node) {
2117 + struct dentry *dentry;
2120 + if (!p->is_whiteout)
2123 + dentry = lookup_one_len(p->name, upperdir, p->len);
2124 + if (IS_ERR(dentry)) {
2126 + "overlayfs: failed to lookup whiteout %.*s: %li\n",
2127 + p->len, p->name, PTR_ERR(dentry));
2130 + ret = vfs_unlink(upperdir->d_inode, dentry, NULL);
2134 + "overlayfs: failed to unlink whiteout %.*s: %i\n",
2135 + p->len, p->name, ret);
2137 + mutex_unlock(&upperdir->d_inode->i_mutex);
2140 + revert_creds(old_cred);
2141 + put_cred(override_cred);
2146 +int ovl_check_empty_and_clear(struct dentry *dentry, enum ovl_path_type type)
2151 + err = ovl_check_empty_dir(dentry, &list);
2152 + if (!err && type == OVL_PATH_MERGE)
2153 + err = ovl_remove_whiteouts(dentry, &list);
2155 + ovl_cache_free(&list);
2160 +++ b/fs/overlayfs/super.c
2164 + * Copyright (C) 2011 Novell Inc.
2166 + * This program is free software; you can redistribute it and/or modify it
2167 + * under the terms of the GNU General Public License version 2 as published by
2168 + * the Free Software Foundation.
2171 +#include <linux/fs.h>
2172 +#include <linux/namei.h>
2173 +#include <linux/xattr.h>
2174 +#include <linux/security.h>
2175 +#include <linux/mount.h>
2176 +#include <linux/slab.h>
2177 +#include <linux/parser.h>
2178 +#include <linux/module.h>
2179 +#include <linux/cred.h>
2180 +#include <linux/sched.h>
2181 +#include "overlayfs.h"
2183 +MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
2184 +MODULE_DESCRIPTION("Overlay filesystem");
2185 +MODULE_LICENSE("GPL");
2188 + struct vfsmount *upper_mnt;
2189 + struct vfsmount *lower_mnt;
2194 + * Keep "double reference" on upper dentries, so that
2195 + * d_delete() doesn't think it's OK to reset d_inode to NULL.
2197 + struct dentry *__upperdentry;
2198 + struct dentry *lowerdentry;
2204 + struct rcu_head rcu;
2208 +const char *ovl_whiteout_xattr = "trusted.overlay.whiteout";
2209 +const char *ovl_opaque_xattr = "trusted.overlay.opaque";
2212 +enum ovl_path_type ovl_path_type(struct dentry *dentry)
2214 + struct ovl_entry *oe = dentry->d_fsdata;
2216 + if (oe->__upperdentry) {
2217 + if (oe->lowerdentry && S_ISDIR(dentry->d_inode->i_mode))
2218 + return OVL_PATH_MERGE;
2220 + return OVL_PATH_UPPER;
2222 + return OVL_PATH_LOWER;
2226 +static struct dentry *ovl_upperdentry_dereference(struct ovl_entry *oe)
2228 + struct dentry *upperdentry = ACCESS_ONCE(oe->__upperdentry);
2229 + smp_read_barrier_depends();
2230 + return upperdentry;
2233 +void ovl_path_upper(struct dentry *dentry, struct path *path)
2235 + struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
2236 + struct ovl_entry *oe = dentry->d_fsdata;
2238 + path->mnt = ofs->upper_mnt;
2239 + path->dentry = ovl_upperdentry_dereference(oe);
2242 +void ovl_path_lower(struct dentry *dentry, struct path *path)
2244 + struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
2245 + struct ovl_entry *oe = dentry->d_fsdata;
2247 + path->mnt = ofs->lower_mnt;
2248 + path->dentry = oe->lowerdentry;
2251 +enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path)
2254 + enum ovl_path_type type = ovl_path_type(dentry);
2256 + if (type == OVL_PATH_LOWER)
2257 + ovl_path_lower(dentry, path);
2259 + ovl_path_upper(dentry, path);
2264 +struct dentry *ovl_dentry_upper(struct dentry *dentry)
2266 + struct ovl_entry *oe = dentry->d_fsdata;
2268 + return ovl_upperdentry_dereference(oe);
2271 +struct dentry *ovl_dentry_lower(struct dentry *dentry)
2273 + struct ovl_entry *oe = dentry->d_fsdata;
2275 + return oe->lowerdentry;
2278 +struct dentry *ovl_dentry_real(struct dentry *dentry)
2280 + struct ovl_entry *oe = dentry->d_fsdata;
2281 + struct dentry *realdentry;
2283 + realdentry = ovl_upperdentry_dereference(oe);
2285 + realdentry = oe->lowerdentry;
2287 + return realdentry;
2290 +struct dentry *ovl_entry_real(struct ovl_entry *oe, bool *is_upper)
2292 + struct dentry *realdentry;
2294 + realdentry = ovl_upperdentry_dereference(oe);
2298 + realdentry = oe->lowerdentry;
2299 + *is_upper = false;
2301 + return realdentry;
2304 +bool ovl_dentry_is_opaque(struct dentry *dentry)
2306 + struct ovl_entry *oe = dentry->d_fsdata;
2307 + return oe->opaque;
2310 +void ovl_dentry_set_opaque(struct dentry *dentry, bool opaque)
2312 + struct ovl_entry *oe = dentry->d_fsdata;
2313 + oe->opaque = opaque;
2316 +void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry)
2318 + struct ovl_entry *oe = dentry->d_fsdata;
2320 + WARN_ON(!mutex_is_locked(&upperdentry->d_parent->d_inode->i_mutex));
2321 + WARN_ON(oe->__upperdentry);
2322 + BUG_ON(!upperdentry->d_inode);
2324 + oe->__upperdentry = dget(upperdentry);
2327 +void ovl_dentry_version_inc(struct dentry *dentry)
2329 + struct ovl_entry *oe = dentry->d_fsdata;
2331 + WARN_ON(!mutex_is_locked(&dentry->d_inode->i_mutex));
2335 +u64 ovl_dentry_version_get(struct dentry *dentry)
2337 + struct ovl_entry *oe = dentry->d_fsdata;
2339 + WARN_ON(!mutex_is_locked(&dentry->d_inode->i_mutex));
2340 + return oe->version;
2343 +bool ovl_is_whiteout(struct dentry *dentry)
2350 + if (!dentry->d_inode)
2352 + if (!S_ISLNK(dentry->d_inode->i_mode))
2355 + res = vfs_getxattr(dentry, ovl_whiteout_xattr, &val, 1);
2356 + if (res == 1 && val == 'y')
2362 +static bool ovl_is_opaquedir(struct dentry *dentry)
2367 + if (!S_ISDIR(dentry->d_inode->i_mode))
2370 + res = vfs_getxattr(dentry, ovl_opaque_xattr, &val, 1);
2371 + if (res == 1 && val == 'y')
2377 +static void ovl_entry_free(struct rcu_head *head)
2379 + struct ovl_entry *oe = container_of(head, struct ovl_entry, rcu);
2383 +static void ovl_dentry_release(struct dentry *dentry)
2385 + struct ovl_entry *oe = dentry->d_fsdata;
2388 + dput(oe->__upperdentry);
2389 + dput(oe->__upperdentry);
2390 + dput(oe->lowerdentry);
2391 + call_rcu(&oe->rcu, ovl_entry_free);
2395 +const struct dentry_operations ovl_dentry_operations = {
2396 + .d_release = ovl_dentry_release,
2399 +static struct ovl_entry *ovl_alloc_entry(void)
2401 + return kzalloc(sizeof(struct ovl_entry), GFP_KERNEL);
2404 +static inline struct dentry *ovl_lookup_real(struct dentry *dir,
2405 + struct qstr *name)
2407 + struct dentry *dentry;
2409 + mutex_lock(&dir->d_inode->i_mutex);
2410 + dentry = lookup_one_len(name->name, dir, name->len);
2411 + mutex_unlock(&dir->d_inode->i_mutex);
2413 + if (IS_ERR(dentry)) {
2414 + if (PTR_ERR(dentry) == -ENOENT)
2416 + } else if (!dentry->d_inode) {
2423 +static int ovl_do_lookup(struct dentry *dentry)
2425 + struct ovl_entry *oe;
2426 + struct dentry *upperdir;
2427 + struct dentry *lowerdir;
2428 + struct dentry *upperdentry = NULL;
2429 + struct dentry *lowerdentry = NULL;
2430 + struct inode *inode = NULL;
2434 + oe = ovl_alloc_entry();
2438 + upperdir = ovl_dentry_upper(dentry->d_parent);
2439 + lowerdir = ovl_dentry_lower(dentry->d_parent);
2442 + upperdentry = ovl_lookup_real(upperdir, &dentry->d_name);
2443 + err = PTR_ERR(upperdentry);
2444 + if (IS_ERR(upperdentry))
2447 + if (lowerdir && upperdentry &&
2448 + (S_ISLNK(upperdentry->d_inode->i_mode) ||
2449 + S_ISDIR(upperdentry->d_inode->i_mode))) {
2450 + const struct cred *old_cred;
2451 + struct cred *override_cred;
2454 + override_cred = prepare_creds();
2455 + if (!override_cred)
2456 + goto out_dput_upper;
2458 + /* CAP_SYS_ADMIN needed for getxattr */
2459 + cap_raise(override_cred->cap_effective, CAP_SYS_ADMIN);
2460 + old_cred = override_creds(override_cred);
2462 + if (ovl_is_opaquedir(upperdentry)) {
2463 + oe->opaque = true;
2464 + } else if (ovl_is_whiteout(upperdentry)) {
2465 + dput(upperdentry);
2466 + upperdentry = NULL;
2467 + oe->opaque = true;
2469 + revert_creds(old_cred);
2470 + put_cred(override_cred);
2473 + if (lowerdir && !oe->opaque) {
2474 + lowerdentry = ovl_lookup_real(lowerdir, &dentry->d_name);
2475 + err = PTR_ERR(lowerdentry);
2476 + if (IS_ERR(lowerdentry))
2477 + goto out_dput_upper;
2480 + if (lowerdentry && upperdentry &&
2481 + (!S_ISDIR(upperdentry->d_inode->i_mode) ||
2482 + !S_ISDIR(lowerdentry->d_inode->i_mode))) {
2483 + dput(lowerdentry);
2484 + lowerdentry = NULL;
2485 + oe->opaque = true;
2488 + if (lowerdentry || upperdentry) {
2489 + struct dentry *realdentry;
2491 + realdentry = upperdentry ? upperdentry : lowerdentry;
2493 + inode = ovl_new_inode(dentry->d_sb, realdentry->d_inode->i_mode,
2497 + ovl_copyattr(realdentry->d_inode, inode);
2501 + oe->__upperdentry = dget(upperdentry);
2504 + oe->lowerdentry = lowerdentry;
2506 + dentry->d_fsdata = oe;
2507 + dentry->d_op = &ovl_dentry_operations;
2508 + d_add(dentry, inode);
2513 + dput(lowerdentry);
2515 + dput(upperdentry);
2522 +struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
2523 + unsigned int flags)
2525 + int err = ovl_do_lookup(dentry);
2528 + return ERR_PTR(err);
2533 +struct file *ovl_path_open(struct path *path, int flags)
2535 + return dentry_open(path, flags, current_cred());
2538 +static void ovl_put_super(struct super_block *sb)
2540 + struct ovl_fs *ufs = sb->s_fs_info;
2542 + if (!(sb->s_flags & MS_RDONLY))
2543 + mnt_drop_write(ufs->upper_mnt);
2545 + mntput(ufs->upper_mnt);
2546 + mntput(ufs->lower_mnt);
2551 +static int ovl_remount_fs(struct super_block *sb, int *flagsp, char *data)
2553 + int flags = *flagsp;
2554 + struct ovl_fs *ufs = sb->s_fs_info;
2556 + /* When remounting rw or ro, we need to adjust the write access to the
2559 + if (((flags ^ sb->s_flags) & MS_RDONLY) == 0)
2560 + /* No change to readonly status */
2563 + if (flags & MS_RDONLY) {
2564 + mnt_drop_write(ufs->upper_mnt);
2567 + return mnt_want_write(ufs->upper_mnt);
2570 +static const struct super_operations ovl_super_operations = {
2571 + .put_super = ovl_put_super,
2572 + .remount_fs = ovl_remount_fs,
2575 +struct ovl_config {
2586 +static const match_table_t ovl_tokens = {
2587 + {OPT_LOWERDIR, "lowerdir=%s"},
2588 + {OPT_UPPERDIR, "upperdir=%s"},
2592 +static int ovl_parse_opt(char *opt, struct ovl_config *config)
2596 + config->upperdir = NULL;
2597 + config->lowerdir = NULL;
2599 + while ((p = strsep(&opt, ",")) != NULL) {
2601 + substring_t args[MAX_OPT_ARGS];
2606 + token = match_token(p, ovl_tokens, args);
2608 + case OPT_UPPERDIR:
2609 + kfree(config->upperdir);
2610 + config->upperdir = match_strdup(&args[0]);
2611 + if (!config->upperdir)
2615 + case OPT_LOWERDIR:
2616 + kfree(config->lowerdir);
2617 + config->lowerdir = match_strdup(&args[0]);
2618 + if (!config->lowerdir)
2629 +static int ovl_fill_super(struct super_block *sb, void *data, int silent)
2631 + struct path lowerpath;
2632 + struct path upperpath;
2633 + struct inode *root_inode;
2634 + struct dentry *root_dentry;
2635 + struct ovl_entry *oe;
2636 + struct ovl_fs *ufs;
2637 + struct ovl_config config;
2640 + err = ovl_parse_opt((char *) data, &config);
2645 + if (!config.upperdir || !config.lowerdir) {
2646 + pr_err("overlayfs: missing upperdir or lowerdir\n");
2647 + goto out_free_config;
2651 + ufs = kmalloc(sizeof(struct ovl_fs), GFP_KERNEL);
2653 + goto out_free_config;
2655 + oe = ovl_alloc_entry();
2657 + goto out_free_ufs;
2659 + err = kern_path(config.upperdir, LOOKUP_FOLLOW, &upperpath);
2663 + err = kern_path(config.lowerdir, LOOKUP_FOLLOW, &lowerpath);
2665 + goto out_put_upperpath;
2668 + if (!S_ISDIR(upperpath.dentry->d_inode->i_mode) ||
2669 + !S_ISDIR(lowerpath.dentry->d_inode->i_mode))
2670 + goto out_put_lowerpath;
2672 + ufs->upper_mnt = clone_private_mount(&upperpath);
2673 + err = PTR_ERR(ufs->upper_mnt);
2674 + if (IS_ERR(ufs->upper_mnt)) {
2675 + pr_err("overlayfs: failed to clone upperpath\n");
2676 + goto out_put_lowerpath;
2679 + ufs->lower_mnt = clone_private_mount(&lowerpath);
2680 + err = PTR_ERR(ufs->lower_mnt);
2681 + if (IS_ERR(ufs->lower_mnt)) {
2682 + pr_err("overlayfs: failed to clone lowerpath\n");
2683 + goto out_put_upper_mnt;
2687 + * Make lower_mnt R/O. That way fchmod/fchown on lower file
2688 + * will fail instead of modifying lower fs.
2690 + ufs->lower_mnt->mnt_flags |= MNT_READONLY;
2692 + /* If the upper fs is r/o, we mark overlayfs r/o too */
2693 + if (ufs->upper_mnt->mnt_sb->s_flags & MS_RDONLY)
2694 + sb->s_flags |= MS_RDONLY;
2696 + if (!(sb->s_flags & MS_RDONLY)) {
2697 + err = mnt_want_write(ufs->upper_mnt);
2699 + goto out_put_lower_mnt;
2703 + root_inode = ovl_new_inode(sb, S_IFDIR, oe);
2705 + goto out_drop_write;
2707 + root_dentry = d_make_root(root_inode);
2709 + goto out_drop_write;
2711 + mntput(upperpath.mnt);
2712 + mntput(lowerpath.mnt);
2714 + oe->__upperdentry = dget(upperpath.dentry);
2715 + oe->lowerdentry = lowerpath.dentry;
2717 + root_dentry->d_fsdata = oe;
2718 + root_dentry->d_op = &ovl_dentry_operations;
2720 + sb->s_op = &ovl_super_operations;
2721 + sb->s_root = root_dentry;
2722 + sb->s_fs_info = ufs;
2727 + if (!(sb->s_flags & MS_RDONLY))
2728 + mnt_drop_write(ufs->upper_mnt);
2730 + mntput(ufs->lower_mnt);
2732 + mntput(ufs->upper_mnt);
2734 + path_put(&lowerpath);
2736 + path_put(&upperpath);
2742 + kfree(config.lowerdir);
2743 + kfree(config.upperdir);
2748 +static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags,
2749 + const char *dev_name, void *raw_data)
2751 + return mount_nodev(fs_type, flags, raw_data, ovl_fill_super);
2754 +static struct file_system_type ovl_fs_type = {
2755 + .owner = THIS_MODULE,
2756 + .name = "overlayfs",
2757 + .mount = ovl_mount,
2758 + .kill_sb = kill_anon_super,
2760 +MODULE_ALIAS_FS("overlayfs");
2762 +static int __init ovl_init(void)
2764 + return register_filesystem(&ovl_fs_type);
2767 +static void __exit ovl_exit(void)
2769 + unregister_filesystem(&ovl_fs_type);
2772 +module_init(ovl_init);
2773 +module_exit(ovl_exit);