3 * Copyright (C) 2011 Novell Inc.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
10 #include <uapi/linux/magic.h>
12 #include <linux/namei.h>
13 #include <linux/xattr.h>
14 #include <linux/mount.h>
15 #include <linux/parser.h>
16 #include <linux/module.h>
17 #include <linux/statfs.h>
18 #include <linux/seq_file.h>
19 #include <linux/posix_acl_xattr.h>
20 #include "overlayfs.h"
21 #include "ovl_entry.h"
23 MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
24 MODULE_DESCRIPTION("Overlay filesystem");
25 MODULE_LICENSE("GPL");
30 #define OVL_MAX_STACK 500
32 static bool ovl_redirect_dir_def = IS_ENABLED(CONFIG_OVERLAY_FS_REDIRECT_DIR);
33 module_param_named(redirect_dir, ovl_redirect_dir_def, bool, 0644);
34 MODULE_PARM_DESC(ovl_redirect_dir_def,
35 "Default to on or off for the redirect_dir feature");
37 static void ovl_dentry_release(struct dentry *dentry)
39 struct ovl_entry *oe = dentry->d_fsdata;
44 for (i = 0; i < oe->numlower; i++)
45 dput(oe->lowerstack[i].dentry);
50 static int ovl_check_append_only(struct inode *inode, int flag)
53 * This test was moot in vfs may_open() because overlay inode does
54 * not have the S_APPEND flag, so re-check on real upper inode
56 if (IS_APPEND(inode)) {
57 if ((flag & O_ACCMODE) != O_RDONLY && !(flag & O_APPEND))
66 static struct dentry *ovl_d_real(struct dentry *dentry,
67 const struct inode *inode,
68 unsigned int open_flags)
73 if (!d_is_reg(dentry)) {
74 if (!inode || inode == d_inode(dentry))
79 if (d_is_negative(dentry))
83 err = ovl_open_maybe_copy_up(dentry, open_flags);
88 real = ovl_dentry_upper(dentry);
89 if (real && (!inode || inode == d_inode(real))) {
91 err = ovl_check_append_only(d_inode(real), open_flags);
98 real = ovl_dentry_lower(dentry);
102 /* Handle recursion */
103 real = d_real(real, inode, open_flags);
105 if (!inode || inode == d_inode(real))
108 WARN(1, "ovl_d_real(%pd4, %s:%lu): real dentry not found\n", dentry,
109 inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0);
113 static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags)
115 struct ovl_entry *oe = dentry->d_fsdata;
119 for (i = 0; i < oe->numlower; i++) {
120 struct dentry *d = oe->lowerstack[i].dentry;
122 if (d->d_flags & DCACHE_OP_REVALIDATE) {
123 ret = d->d_op->d_revalidate(d, flags);
127 if (!(flags & LOOKUP_RCU))
136 static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
138 struct ovl_entry *oe = dentry->d_fsdata;
142 for (i = 0; i < oe->numlower; i++) {
143 struct dentry *d = oe->lowerstack[i].dentry;
145 if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) {
146 ret = d->d_op->d_weak_revalidate(d, flags);
154 static const struct dentry_operations ovl_dentry_operations = {
155 .d_release = ovl_dentry_release,
156 .d_real = ovl_d_real,
159 static const struct dentry_operations ovl_reval_dentry_operations = {
160 .d_release = ovl_dentry_release,
161 .d_real = ovl_d_real,
162 .d_revalidate = ovl_dentry_revalidate,
163 .d_weak_revalidate = ovl_dentry_weak_revalidate,
166 static struct kmem_cache *ovl_inode_cachep;
168 static struct inode *ovl_alloc_inode(struct super_block *sb)
170 struct ovl_inode *oi = kmem_cache_alloc(ovl_inode_cachep, GFP_KERNEL);
173 oi->__upperdentry = NULL;
176 return &oi->vfs_inode;
179 static void ovl_i_callback(struct rcu_head *head)
181 struct inode *inode = container_of(head, struct inode, i_rcu);
183 kmem_cache_free(ovl_inode_cachep, OVL_I(inode));
186 static void ovl_destroy_inode(struct inode *inode)
188 struct ovl_inode *oi = OVL_I(inode);
190 dput(oi->__upperdentry);
193 call_rcu(&inode->i_rcu, ovl_i_callback);
196 static void ovl_put_super(struct super_block *sb)
198 struct ovl_fs *ufs = sb->s_fs_info;
202 mntput(ufs->upper_mnt);
203 for (i = 0; i < ufs->numlower; i++)
204 mntput(ufs->lower_mnt[i]);
205 kfree(ufs->lower_mnt);
207 kfree(ufs->config.lowerdir);
208 kfree(ufs->config.upperdir);
209 kfree(ufs->config.workdir);
210 put_cred(ufs->creator_cred);
214 static int ovl_sync_fs(struct super_block *sb, int wait)
216 struct ovl_fs *ufs = sb->s_fs_info;
217 struct super_block *upper_sb;
222 upper_sb = ufs->upper_mnt->mnt_sb;
223 if (!upper_sb->s_op->sync_fs)
226 /* real inodes have already been synced by sync_filesystem(ovl_sb) */
227 down_read(&upper_sb->s_umount);
228 ret = upper_sb->s_op->sync_fs(upper_sb, wait);
229 up_read(&upper_sb->s_umount);
235 * @sb: The overlayfs super block
236 * @buf: The struct kstatfs to fill in with stats
238 * Get the filesystem statistics. As writes always target the upper layer
239 * filesystem pass the statfs to the upper filesystem (if it exists)
241 static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf)
243 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
244 struct dentry *root_dentry = dentry->d_sb->s_root;
248 ovl_path_real(root_dentry, &path);
250 err = vfs_statfs(&path, buf);
252 buf->f_namelen = ofs->namelen;
253 buf->f_type = OVERLAYFS_SUPER_MAGIC;
262 * Prints the mount options for a given superblock.
263 * Returns zero; does not fail.
265 static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
267 struct super_block *sb = dentry->d_sb;
268 struct ovl_fs *ufs = sb->s_fs_info;
270 seq_show_option(m, "lowerdir", ufs->config.lowerdir);
271 if (ufs->config.upperdir) {
272 seq_show_option(m, "upperdir", ufs->config.upperdir);
273 seq_show_option(m, "workdir", ufs->config.workdir);
275 if (ufs->config.default_permissions)
276 seq_puts(m, ",default_permissions");
277 if (ufs->config.redirect_dir != ovl_redirect_dir_def)
278 seq_printf(m, ",redirect_dir=%s",
279 ufs->config.redirect_dir ? "on" : "off");
283 static int ovl_remount(struct super_block *sb, int *flags, char *data)
285 struct ovl_fs *ufs = sb->s_fs_info;
287 if (!(*flags & MS_RDONLY) && (!ufs->upper_mnt || !ufs->workdir))
293 static const struct super_operations ovl_super_operations = {
294 .alloc_inode = ovl_alloc_inode,
295 .destroy_inode = ovl_destroy_inode,
296 .drop_inode = generic_delete_inode,
297 .put_super = ovl_put_super,
298 .sync_fs = ovl_sync_fs,
299 .statfs = ovl_statfs,
300 .show_options = ovl_show_options,
301 .remount_fs = ovl_remount,
308 OPT_DEFAULT_PERMISSIONS,
310 OPT_REDIRECT_DIR_OFF,
314 static const match_table_t ovl_tokens = {
315 {OPT_LOWERDIR, "lowerdir=%s"},
316 {OPT_UPPERDIR, "upperdir=%s"},
317 {OPT_WORKDIR, "workdir=%s"},
318 {OPT_DEFAULT_PERMISSIONS, "default_permissions"},
319 {OPT_REDIRECT_DIR_ON, "redirect_dir=on"},
320 {OPT_REDIRECT_DIR_OFF, "redirect_dir=off"},
324 static char *ovl_next_opt(char **s)
332 for (p = sbegin; *p; p++) {
337 } else if (*p == ',') {
347 static int ovl_parse_opt(char *opt, struct ovl_config *config)
351 while ((p = ovl_next_opt(&opt)) != NULL) {
353 substring_t args[MAX_OPT_ARGS];
358 token = match_token(p, ovl_tokens, args);
361 kfree(config->upperdir);
362 config->upperdir = match_strdup(&args[0]);
363 if (!config->upperdir)
368 kfree(config->lowerdir);
369 config->lowerdir = match_strdup(&args[0]);
370 if (!config->lowerdir)
375 kfree(config->workdir);
376 config->workdir = match_strdup(&args[0]);
377 if (!config->workdir)
381 case OPT_DEFAULT_PERMISSIONS:
382 config->default_permissions = true;
385 case OPT_REDIRECT_DIR_ON:
386 config->redirect_dir = true;
389 case OPT_REDIRECT_DIR_OFF:
390 config->redirect_dir = false;
394 pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p);
399 /* Workdir is useless in non-upper mount */
400 if (!config->upperdir && config->workdir) {
401 pr_info("overlayfs: option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
403 kfree(config->workdir);
404 config->workdir = NULL;
410 #define OVL_WORKDIR_NAME "work"
412 static struct dentry *ovl_workdir_create(struct vfsmount *mnt,
413 struct dentry *dentry)
415 struct inode *dir = dentry->d_inode;
418 bool retried = false;
420 err = mnt_want_write(mnt);
424 inode_lock_nested(dir, I_MUTEX_PARENT);
426 work = lookup_one_len(OVL_WORKDIR_NAME, dentry,
427 strlen(OVL_WORKDIR_NAME));
430 struct iattr attr = {
431 .ia_valid = ATTR_MODE,
432 .ia_mode = S_IFDIR | 0,
441 ovl_workdir_cleanup(dir, mnt, work, 0);
446 err = ovl_create_real(dir, work,
447 &(struct cattr){.mode = S_IFDIR | 0},
453 * Try to remove POSIX ACL xattrs from workdir. We are good if:
455 * a) success (there was a POSIX ACL xattr and was removed)
456 * b) -ENODATA (there was no POSIX ACL xattr)
457 * c) -EOPNOTSUPP (POSIX ACL xattrs are not supported)
459 * There are various other error values that could effectively
460 * mean that the xattr doesn't exist (e.g. -ERANGE is returned
461 * if the xattr name is too long), but the set of filesystems
462 * allowed as upper are limited to "normal" ones, where checking
463 * for the above two errors is sufficient.
465 err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_DEFAULT);
466 if (err && err != -ENODATA && err != -EOPNOTSUPP)
469 err = vfs_removexattr(work, XATTR_NAME_POSIX_ACL_ACCESS);
470 if (err && err != -ENODATA && err != -EOPNOTSUPP)
473 /* Clear any inherited mode bits */
474 inode_lock(work->d_inode);
475 err = notify_change(work, &attr, NULL);
476 inode_unlock(work->d_inode);
492 static void ovl_unescape(char *s)
505 static int ovl_mount_dir_noesc(const char *name, struct path *path)
510 pr_err("overlayfs: empty lowerdir\n");
513 err = kern_path(name, LOOKUP_FOLLOW, path);
515 pr_err("overlayfs: failed to resolve '%s': %i\n", name, err);
519 if (ovl_dentry_weird(path->dentry)) {
520 pr_err("overlayfs: filesystem on '%s' not supported\n", name);
523 if (!d_is_dir(path->dentry)) {
524 pr_err("overlayfs: '%s' not a directory\n", name);
535 static int ovl_mount_dir(const char *name, struct path *path)
538 char *tmp = kstrdup(name, GFP_KERNEL);
542 err = ovl_mount_dir_noesc(tmp, path);
545 if (ovl_dentry_remote(path->dentry)) {
546 pr_err("overlayfs: filesystem on '%s' not supported as upperdir\n",
556 static int ovl_check_namelen(struct path *path, struct ovl_fs *ofs,
559 struct kstatfs statfs;
560 int err = vfs_statfs(path, &statfs);
563 pr_err("overlayfs: statfs failed on '%s'\n", name);
565 ofs->namelen = max(ofs->namelen, statfs.f_namelen);
570 static int ovl_lower_dir(const char *name, struct path *path,
571 struct ovl_fs *ofs, int *stack_depth, bool *remote)
575 err = ovl_mount_dir_noesc(name, path);
579 err = ovl_check_namelen(path, ofs, name);
583 *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth);
585 if (ovl_dentry_remote(path->dentry))
596 /* Workdir should not be subdir of upperdir and vice versa */
597 static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir)
601 if (workdir != upperdir) {
602 ok = (lock_rename(workdir, upperdir) == NULL);
603 unlock_rename(workdir, upperdir);
608 static unsigned int ovl_split_lowerdirs(char *str)
610 unsigned int ctr = 1;
613 for (s = d = str;; s++, d++) {
616 } else if (*s == ':') {
628 static int __maybe_unused
629 ovl_posix_acl_xattr_get(const struct xattr_handler *handler,
630 struct dentry *dentry, struct inode *inode,
631 const char *name, void *buffer, size_t size)
633 return ovl_xattr_get(dentry, handler->name, buffer, size);
636 static int __maybe_unused
637 ovl_posix_acl_xattr_set(const struct xattr_handler *handler,
638 struct dentry *dentry, struct inode *inode,
639 const char *name, const void *value,
640 size_t size, int flags)
642 struct dentry *workdir = ovl_workdir(dentry);
643 struct inode *realinode = ovl_inode_real(inode);
644 struct posix_acl *acl = NULL;
647 /* Check that everything is OK before copy-up */
649 acl = posix_acl_from_xattr(&init_user_ns, value, size);
654 if (!IS_POSIXACL(d_inode(workdir)))
655 goto out_acl_release;
656 if (!realinode->i_op->set_acl)
657 goto out_acl_release;
658 if (handler->flags == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) {
659 err = acl ? -EACCES : 0;
660 goto out_acl_release;
663 if (!inode_owner_or_capable(inode))
664 goto out_acl_release;
666 posix_acl_release(acl);
669 * Check if sgid bit needs to be cleared (actual setacl operation will
670 * be done with mounter's capabilities and so that won't do it for us).
672 if (unlikely(inode->i_mode & S_ISGID) &&
673 handler->flags == ACL_TYPE_ACCESS &&
674 !in_group_p(inode->i_gid) &&
675 !capable_wrt_inode_uidgid(inode, CAP_FSETID)) {
676 struct iattr iattr = { .ia_valid = ATTR_KILL_SGID };
678 err = ovl_setattr(dentry, &iattr);
683 err = ovl_xattr_set(dentry, handler->name, value, size, flags);
685 ovl_copyattr(ovl_inode_real(inode), inode);
690 posix_acl_release(acl);
694 static int ovl_own_xattr_get(const struct xattr_handler *handler,
695 struct dentry *dentry, struct inode *inode,
696 const char *name, void *buffer, size_t size)
701 static int ovl_own_xattr_set(const struct xattr_handler *handler,
702 struct dentry *dentry, struct inode *inode,
703 const char *name, const void *value,
704 size_t size, int flags)
709 static int ovl_other_xattr_get(const struct xattr_handler *handler,
710 struct dentry *dentry, struct inode *inode,
711 const char *name, void *buffer, size_t size)
713 return ovl_xattr_get(dentry, name, buffer, size);
716 static int ovl_other_xattr_set(const struct xattr_handler *handler,
717 struct dentry *dentry, struct inode *inode,
718 const char *name, const void *value,
719 size_t size, int flags)
721 return ovl_xattr_set(dentry, name, value, size, flags);
724 static const struct xattr_handler __maybe_unused
725 ovl_posix_acl_access_xattr_handler = {
726 .name = XATTR_NAME_POSIX_ACL_ACCESS,
727 .flags = ACL_TYPE_ACCESS,
728 .get = ovl_posix_acl_xattr_get,
729 .set = ovl_posix_acl_xattr_set,
732 static const struct xattr_handler __maybe_unused
733 ovl_posix_acl_default_xattr_handler = {
734 .name = XATTR_NAME_POSIX_ACL_DEFAULT,
735 .flags = ACL_TYPE_DEFAULT,
736 .get = ovl_posix_acl_xattr_get,
737 .set = ovl_posix_acl_xattr_set,
740 static const struct xattr_handler ovl_own_xattr_handler = {
741 .prefix = OVL_XATTR_PREFIX,
742 .get = ovl_own_xattr_get,
743 .set = ovl_own_xattr_set,
746 static const struct xattr_handler ovl_other_xattr_handler = {
747 .prefix = "", /* catch all */
748 .get = ovl_other_xattr_get,
749 .set = ovl_other_xattr_set,
752 static const struct xattr_handler *ovl_xattr_handlers[] = {
753 #ifdef CONFIG_FS_POSIX_ACL
754 &ovl_posix_acl_access_xattr_handler,
755 &ovl_posix_acl_default_xattr_handler,
757 &ovl_own_xattr_handler,
758 &ovl_other_xattr_handler,
762 static int ovl_fill_super(struct super_block *sb, void *data, int silent)
764 struct path upperpath = { };
765 struct path workpath = { };
766 struct dentry *root_dentry;
767 struct ovl_entry *oe;
769 struct path *stack = NULL;
772 unsigned int numlower;
773 unsigned int stacklen = 0;
780 ufs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL);
784 init_waitqueue_head(&ufs->copyup_wq);
785 ufs->config.redirect_dir = ovl_redirect_dir_def;
786 err = ovl_parse_opt((char *) data, &ufs->config);
788 goto out_free_config;
791 if (!ufs->config.lowerdir) {
793 pr_err("overlayfs: missing 'lowerdir'\n");
794 goto out_free_config;
797 sb->s_stack_depth = 0;
798 sb->s_maxbytes = MAX_LFS_FILESIZE;
799 if (ufs->config.upperdir) {
800 if (!ufs->config.workdir) {
801 pr_err("overlayfs: missing 'workdir'\n");
802 goto out_free_config;
805 err = ovl_mount_dir(ufs->config.upperdir, &upperpath);
807 goto out_free_config;
809 /* Upper fs should not be r/o */
810 if (upperpath.mnt->mnt_sb->s_flags & MS_RDONLY) {
811 pr_err("overlayfs: upper fs is r/o, try multi-lower layers mount\n");
813 goto out_put_upperpath;
816 err = ovl_check_namelen(&upperpath, ufs, ufs->config.upperdir);
818 goto out_put_upperpath;
820 err = ovl_mount_dir(ufs->config.workdir, &workpath);
822 goto out_put_upperpath;
825 if (upperpath.mnt != workpath.mnt) {
826 pr_err("overlayfs: workdir and upperdir must reside under the same mount\n");
827 goto out_put_workpath;
829 if (!ovl_workdir_ok(workpath.dentry, upperpath.dentry)) {
830 pr_err("overlayfs: workdir and upperdir must be separate subtrees\n");
831 goto out_put_workpath;
833 sb->s_stack_depth = upperpath.mnt->mnt_sb->s_stack_depth;
836 lowertmp = kstrdup(ufs->config.lowerdir, GFP_KERNEL);
838 goto out_put_workpath;
841 stacklen = ovl_split_lowerdirs(lowertmp);
842 if (stacklen > OVL_MAX_STACK) {
843 pr_err("overlayfs: too many lower directories, limit is %d\n",
845 goto out_free_lowertmp;
846 } else if (!ufs->config.upperdir && stacklen == 1) {
847 pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n");
848 goto out_free_lowertmp;
852 stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL);
854 goto out_free_lowertmp;
858 for (numlower = 0; numlower < stacklen; numlower++) {
859 err = ovl_lower_dir(lower, &stack[numlower], ufs,
860 &sb->s_stack_depth, &remote);
862 goto out_put_lowerpath;
864 lower = strchr(lower, '\0') + 1;
869 if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
870 pr_err("overlayfs: maximum fs stacking depth exceeded\n");
871 goto out_put_lowerpath;
874 if (ufs->config.upperdir) {
875 ufs->upper_mnt = clone_private_mount(&upperpath);
876 err = PTR_ERR(ufs->upper_mnt);
877 if (IS_ERR(ufs->upper_mnt)) {
878 pr_err("overlayfs: failed to clone upperpath\n");
879 goto out_put_lowerpath;
881 /* Don't inherit atime flags */
882 ufs->upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME);
884 sb->s_time_gran = ufs->upper_mnt->mnt_sb->s_time_gran;
886 ufs->workdir = ovl_workdir_create(ufs->upper_mnt, workpath.dentry);
887 err = PTR_ERR(ufs->workdir);
888 if (IS_ERR(ufs->workdir)) {
889 pr_warn("overlayfs: failed to create directory %s/%s (errno: %i); mounting read-only\n",
890 ufs->config.workdir, OVL_WORKDIR_NAME, -err);
891 sb->s_flags |= MS_RDONLY;
896 * Upper should support d_type, else whiteouts are visible.
897 * Given workdir and upper are on same fs, we can do
898 * iterate_dir() on workdir. This check requires successful
899 * creation of workdir in previous step.
904 err = ovl_check_d_type_supported(&workpath);
906 goto out_put_workdir;
909 * We allowed this configuration and don't want to
910 * break users over kernel upgrade. So warn instead
914 pr_warn("overlayfs: upper fs needs to support d_type.\n");
916 /* Check if upper/work fs supports O_TMPFILE */
917 temp = ovl_do_tmpfile(ufs->workdir, S_IFREG | 0);
918 ufs->tmpfile = !IS_ERR(temp);
922 pr_warn("overlayfs: upper fs does not support tmpfile.\n");
925 * Check if upper/work fs supports trusted.overlay.*
928 err = ovl_do_setxattr(ufs->workdir, OVL_XATTR_OPAQUE,
932 pr_warn("overlayfs: upper fs does not support xattr.\n");
934 vfs_removexattr(ufs->workdir, OVL_XATTR_OPAQUE);
940 ufs->lower_mnt = kcalloc(numlower, sizeof(struct vfsmount *), GFP_KERNEL);
941 if (ufs->lower_mnt == NULL)
942 goto out_put_workdir;
943 for (i = 0; i < numlower; i++) {
944 struct vfsmount *mnt = clone_private_mount(&stack[i]);
948 pr_err("overlayfs: failed to clone lowerpath\n");
949 goto out_put_lower_mnt;
952 * Make lower_mnt R/O. That way fchmod/fchown on lower file
953 * will fail instead of modifying lower fs.
955 mnt->mnt_flags |= MNT_READONLY | MNT_NOATIME;
957 ufs->lower_mnt[ufs->numlower] = mnt;
960 /* Check if all lower layers are on same sb */
962 ufs->same_sb = mnt->mnt_sb;
963 else if (ufs->same_sb != mnt->mnt_sb)
967 /* If the upper fs is nonexistent, we mark overlayfs r/o too */
969 sb->s_flags |= MS_RDONLY;
970 else if (ufs->upper_mnt->mnt_sb != ufs->same_sb)
974 sb->s_d_op = &ovl_reval_dentry_operations;
976 sb->s_d_op = &ovl_dentry_operations;
978 ufs->creator_cred = cred = prepare_creds();
980 goto out_put_lower_mnt;
982 /* Never override disk quota limits or use reserved space */
983 cap_lower(cred->cap_effective, CAP_SYS_RESOURCE);
986 oe = ovl_alloc_entry(numlower);
990 sb->s_magic = OVERLAYFS_SUPER_MAGIC;
991 sb->s_op = &ovl_super_operations;
992 sb->s_xattr = ovl_xattr_handlers;
994 sb->s_flags |= MS_POSIXACL | MS_NOREMOTELOCK;
996 root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
1000 mntput(upperpath.mnt);
1001 for (i = 0; i < numlower; i++)
1002 mntput(stack[i].mnt);
1003 path_put(&workpath);
1006 if (upperpath.dentry) {
1007 oe->impure = ovl_is_impuredir(upperpath.dentry);
1009 for (i = 0; i < numlower; i++) {
1010 oe->lowerstack[i].dentry = stack[i].dentry;
1011 oe->lowerstack[i].mnt = ufs->lower_mnt[i];
1015 root_dentry->d_fsdata = oe;
1017 ovl_inode_init(d_inode(root_dentry), upperpath.dentry,
1018 ovl_dentry_lower(root_dentry));
1020 sb->s_root = root_dentry;
1027 put_cred(ufs->creator_cred);
1029 for (i = 0; i < ufs->numlower; i++)
1030 mntput(ufs->lower_mnt[i]);
1031 kfree(ufs->lower_mnt);
1034 mntput(ufs->upper_mnt);
1036 for (i = 0; i < numlower; i++)
1037 path_put(&stack[i]);
1042 path_put(&workpath);
1044 path_put(&upperpath);
1046 kfree(ufs->config.lowerdir);
1047 kfree(ufs->config.upperdir);
1048 kfree(ufs->config.workdir);
1054 static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags,
1055 const char *dev_name, void *raw_data)
1057 return mount_nodev(fs_type, flags, raw_data, ovl_fill_super);
1060 static struct file_system_type ovl_fs_type = {
1061 .owner = THIS_MODULE,
1064 .kill_sb = kill_anon_super,
1066 MODULE_ALIAS_FS("overlay");
1068 static void ovl_inode_init_once(void *foo)
1070 struct ovl_inode *oi = foo;
1072 inode_init_once(&oi->vfs_inode);
1075 static int __init ovl_init(void)
1079 ovl_inode_cachep = kmem_cache_create("ovl_inode",
1080 sizeof(struct ovl_inode), 0,
1081 (SLAB_RECLAIM_ACCOUNT|
1082 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
1083 ovl_inode_init_once);
1084 if (ovl_inode_cachep == NULL)
1087 err = register_filesystem(&ovl_fs_type);
1089 kmem_cache_destroy(ovl_inode_cachep);
1094 static void __exit ovl_exit(void)
1096 unregister_filesystem(&ovl_fs_type);
1099 * Make sure all delayed rcu free inodes are flushed before we
1103 kmem_cache_destroy(ovl_inode_cachep);
1107 module_init(ovl_init);
1108 module_exit(ovl_exit);