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.
11 #include <linux/namei.h>
12 #include <linux/pagemap.h>
13 #include <linux/xattr.h>
14 #include <linux/security.h>
15 #include <linux/mount.h>
16 #include <linux/slab.h>
17 #include <linux/parser.h>
18 #include <linux/module.h>
19 #include <linux/sched.h>
20 #include <linux/statfs.h>
21 #include <linux/seq_file.h>
22 #include "overlayfs.h"
24 MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
25 MODULE_DESCRIPTION("Overlay filesystem");
26 MODULE_LICENSE("GPL");
28 #define OVERLAYFS_SUPER_MAGIC 0x794c7630
36 /* private information held for overlayfs's superblock */
38 struct vfsmount *upper_mnt;
40 struct vfsmount **lower_mnt;
41 struct dentry *workdir;
43 /* pathnames of lower and upper dirs, for show_options */
44 struct ovl_config config;
49 /* private information held for every overlayfs dentry */
51 struct dentry *__upperdentry;
52 struct ovl_dir_cache *cache;
61 struct path lowerstack[];
64 #define OVL_MAX_STACK 500
66 static struct dentry *__ovl_dentry_lower(struct ovl_entry *oe)
68 return oe->numlower ? oe->lowerstack[0].dentry : NULL;
71 enum ovl_path_type ovl_path_type(struct dentry *dentry)
73 struct ovl_entry *oe = dentry->d_fsdata;
74 enum ovl_path_type type = 0;
76 if (oe->__upperdentry) {
77 type = __OVL_PATH_UPPER;
80 * Non-dir dentry can hold lower dentry from previous
81 * location. Its purity depends only on opaque flag.
83 if (oe->numlower && S_ISDIR(dentry->d_inode->i_mode))
84 type |= __OVL_PATH_MERGE;
86 type |= __OVL_PATH_PURE;
89 type |= __OVL_PATH_MERGE;
94 static struct dentry *ovl_upperdentry_dereference(struct ovl_entry *oe)
96 return lockless_dereference(oe->__upperdentry);
99 void ovl_path_upper(struct dentry *dentry, struct path *path)
101 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
102 struct ovl_entry *oe = dentry->d_fsdata;
104 path->mnt = ofs->upper_mnt;
105 path->dentry = ovl_upperdentry_dereference(oe);
108 enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path)
110 enum ovl_path_type type = ovl_path_type(dentry);
112 if (!OVL_TYPE_UPPER(type))
113 ovl_path_lower(dentry, path);
115 ovl_path_upper(dentry, path);
120 struct dentry *ovl_dentry_upper(struct dentry *dentry)
122 struct ovl_entry *oe = dentry->d_fsdata;
124 return ovl_upperdentry_dereference(oe);
127 struct dentry *ovl_dentry_lower(struct dentry *dentry)
129 struct ovl_entry *oe = dentry->d_fsdata;
131 return __ovl_dentry_lower(oe);
134 struct dentry *ovl_dentry_real(struct dentry *dentry)
136 struct ovl_entry *oe = dentry->d_fsdata;
137 struct dentry *realdentry;
139 realdentry = ovl_upperdentry_dereference(oe);
141 realdentry = __ovl_dentry_lower(oe);
146 struct dentry *ovl_entry_real(struct ovl_entry *oe, bool *is_upper)
148 struct dentry *realdentry;
150 realdentry = ovl_upperdentry_dereference(oe);
154 realdentry = __ovl_dentry_lower(oe);
160 struct ovl_dir_cache *ovl_dir_cache(struct dentry *dentry)
162 struct ovl_entry *oe = dentry->d_fsdata;
167 void ovl_set_dir_cache(struct dentry *dentry, struct ovl_dir_cache *cache)
169 struct ovl_entry *oe = dentry->d_fsdata;
174 void ovl_path_lower(struct dentry *dentry, struct path *path)
176 struct ovl_entry *oe = dentry->d_fsdata;
178 *path = oe->numlower ? oe->lowerstack[0] : (struct path) { NULL, NULL };
181 int ovl_want_write(struct dentry *dentry)
183 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
184 return mnt_want_write(ofs->upper_mnt);
187 void ovl_drop_write(struct dentry *dentry)
189 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
190 mnt_drop_write(ofs->upper_mnt);
193 struct dentry *ovl_workdir(struct dentry *dentry)
195 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
199 bool ovl_dentry_is_opaque(struct dentry *dentry)
201 struct ovl_entry *oe = dentry->d_fsdata;
205 void ovl_dentry_set_opaque(struct dentry *dentry, bool opaque)
207 struct ovl_entry *oe = dentry->d_fsdata;
211 void ovl_dentry_update(struct dentry *dentry, struct dentry *upperdentry)
213 struct ovl_entry *oe = dentry->d_fsdata;
215 WARN_ON(!mutex_is_locked(&upperdentry->d_parent->d_inode->i_mutex));
216 WARN_ON(oe->__upperdentry);
217 BUG_ON(!upperdentry->d_inode);
219 * Make sure upperdentry is consistent before making it visible to
220 * ovl_upperdentry_dereference().
223 oe->__upperdentry = upperdentry;
226 void ovl_dentry_version_inc(struct dentry *dentry)
228 struct ovl_entry *oe = dentry->d_fsdata;
230 WARN_ON(!mutex_is_locked(&dentry->d_inode->i_mutex));
234 u64 ovl_dentry_version_get(struct dentry *dentry)
236 struct ovl_entry *oe = dentry->d_fsdata;
238 WARN_ON(!mutex_is_locked(&dentry->d_inode->i_mutex));
242 bool ovl_is_whiteout(struct dentry *dentry)
244 struct inode *inode = dentry->d_inode;
246 return inode && IS_WHITEOUT(inode);
249 static bool ovl_is_opaquedir(struct dentry *dentry)
253 struct inode *inode = dentry->d_inode;
255 if (!S_ISDIR(inode->i_mode) || !inode->i_op->getxattr)
258 res = inode->i_op->getxattr(dentry, OVL_XATTR_OPAQUE, &val, 1);
259 if (res == 1 && val == 'y')
265 static void ovl_dentry_release(struct dentry *dentry)
267 struct ovl_entry *oe = dentry->d_fsdata;
272 dput(oe->__upperdentry);
273 for (i = 0; i < oe->numlower; i++)
274 dput(oe->lowerstack[i].dentry);
279 static struct dentry *ovl_d_real(struct dentry *dentry, struct inode *inode)
283 if (d_is_dir(dentry)) {
284 if (!inode || inode == d_inode(dentry))
289 real = ovl_dentry_upper(dentry);
290 if (real && (!inode || inode == d_inode(real)))
293 real = ovl_dentry_lower(dentry);
297 if (!inode || inode == d_inode(real))
300 /* Handle recursion */
301 if (real->d_flags & DCACHE_OP_REAL)
302 return real->d_op->d_real(real, inode);
305 WARN(1, "ovl_d_real(%pd4, %s:%lu\n): real dentry not found\n", dentry,
306 inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0);
310 static int ovl_dentry_revalidate(struct dentry *dentry, unsigned int flags)
312 struct ovl_entry *oe = dentry->d_fsdata;
316 for (i = 0; i < oe->numlower; i++) {
317 struct dentry *d = oe->lowerstack[i].dentry;
319 if (d->d_flags & DCACHE_OP_REVALIDATE) {
320 ret = d->d_op->d_revalidate(d, flags);
324 if (!(flags & LOOKUP_RCU))
333 static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags)
335 struct ovl_entry *oe = dentry->d_fsdata;
339 for (i = 0; i < oe->numlower; i++) {
340 struct dentry *d = oe->lowerstack[i].dentry;
342 if (d->d_flags & DCACHE_OP_WEAK_REVALIDATE) {
343 ret = d->d_op->d_weak_revalidate(d, flags);
351 static const struct dentry_operations ovl_dentry_operations = {
352 .d_release = ovl_dentry_release,
353 .d_select_inode = ovl_d_select_inode,
354 .d_real = ovl_d_real,
357 static const struct dentry_operations ovl_reval_dentry_operations = {
358 .d_release = ovl_dentry_release,
359 .d_select_inode = ovl_d_select_inode,
360 .d_real = ovl_d_real,
361 .d_revalidate = ovl_dentry_revalidate,
362 .d_weak_revalidate = ovl_dentry_weak_revalidate,
365 static struct ovl_entry *ovl_alloc_entry(unsigned int numlower)
367 size_t size = offsetof(struct ovl_entry, lowerstack[numlower]);
368 struct ovl_entry *oe = kzalloc(size, GFP_KERNEL);
371 oe->numlower = numlower;
376 static bool ovl_dentry_remote(struct dentry *dentry)
378 return dentry->d_flags &
379 (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE |
383 static bool ovl_dentry_weird(struct dentry *dentry)
385 return dentry->d_flags & (DCACHE_NEED_AUTOMOUNT |
386 DCACHE_MANAGE_TRANSIT |
391 static inline struct dentry *ovl_lookup_real(struct dentry *dir,
394 struct dentry *dentry;
396 mutex_lock(&dir->d_inode->i_mutex);
397 dentry = lookup_one_len(name->name, dir, name->len);
398 mutex_unlock(&dir->d_inode->i_mutex);
400 if (IS_ERR(dentry)) {
401 if (PTR_ERR(dentry) == -ENOENT)
403 } else if (!dentry->d_inode) {
406 } else if (ovl_dentry_weird(dentry)) {
408 /* Don't support traversing automounts and other weirdness */
409 dentry = ERR_PTR(-EREMOTE);
415 * Returns next layer in stack starting from top.
416 * Returns -1 if this is the last layer.
418 int ovl_path_next(int idx, struct dentry *dentry, struct path *path)
420 struct ovl_entry *oe = dentry->d_fsdata;
424 ovl_path_upper(dentry, path);
426 return oe->numlower ? 1 : -1;
429 BUG_ON(idx > oe->numlower);
430 *path = oe->lowerstack[idx - 1];
432 return (idx < oe->numlower) ? idx + 1 : -1;
435 struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
438 struct ovl_entry *oe;
439 struct ovl_entry *poe = dentry->d_parent->d_fsdata;
440 struct path *stack = NULL;
441 struct dentry *upperdir, *upperdentry = NULL;
442 unsigned int ctr = 0;
443 struct inode *inode = NULL;
444 bool upperopaque = false;
445 struct dentry *this, *prev = NULL;
449 upperdir = ovl_upperdentry_dereference(poe);
451 this = ovl_lookup_real(upperdir, &dentry->d_name);
457 if (unlikely(ovl_dentry_remote(this))) {
462 if (ovl_is_whiteout(this)) {
466 } else if (poe->numlower && ovl_is_opaquedir(this)) {
470 upperdentry = prev = this;
473 if (!upperopaque && poe->numlower) {
475 stack = kcalloc(poe->numlower, sizeof(struct path), GFP_KERNEL);
480 for (i = 0; !upperopaque && i < poe->numlower; i++) {
482 struct path lowerpath = poe->lowerstack[i];
484 this = ovl_lookup_real(lowerpath.dentry, &dentry->d_name);
488 * If it's positive, then treat ENAMETOOLONG as ENOENT.
490 if (err == -ENAMETOOLONG && (upperdentry || ctr))
496 if (ovl_is_whiteout(this)) {
501 * Only makes sense to check opaque dir if this is not the
504 if (i < poe->numlower - 1 && ovl_is_opaquedir(this))
507 if (prev && (!S_ISDIR(prev->d_inode->i_mode) ||
508 !S_ISDIR(this->d_inode->i_mode))) {
510 * FIXME: check for upper-opaqueness maybe better done
513 if (prev == upperdentry)
519 * If this is a non-directory then stop here.
521 if (!S_ISDIR(this->d_inode->i_mode))
524 stack[ctr].dentry = this;
525 stack[ctr].mnt = lowerpath.mnt;
532 oe = ovl_alloc_entry(ctr);
537 if (upperdentry || ctr) {
538 struct dentry *realdentry;
540 realdentry = upperdentry ? upperdentry : stack[0].dentry;
543 inode = ovl_new_inode(dentry->d_sb, realdentry->d_inode->i_mode,
547 ovl_copyattr(realdentry->d_inode, inode);
550 oe->opaque = upperopaque;
551 oe->__upperdentry = upperdentry;
552 memcpy(oe->lowerstack, stack, sizeof(struct path) * ctr);
554 dentry->d_fsdata = oe;
555 d_add(dentry, inode);
562 for (i = 0; i < ctr; i++)
563 dput(stack[i].dentry);
571 struct file *ovl_path_open(struct path *path, int flags)
573 return dentry_open(path, flags, current_cred());
576 static void ovl_put_super(struct super_block *sb)
578 struct ovl_fs *ufs = sb->s_fs_info;
582 mntput(ufs->upper_mnt);
583 for (i = 0; i < ufs->numlower; i++)
584 mntput(ufs->lower_mnt[i]);
585 kfree(ufs->lower_mnt);
587 kfree(ufs->config.lowerdir);
588 kfree(ufs->config.upperdir);
589 kfree(ufs->config.workdir);
595 * @sb: The overlayfs super block
596 * @buf: The struct kstatfs to fill in with stats
598 * Get the filesystem statistics. As writes always target the upper layer
599 * filesystem pass the statfs to the upper filesystem (if it exists)
601 static int ovl_statfs(struct dentry *dentry, struct kstatfs *buf)
603 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
604 struct dentry *root_dentry = dentry->d_sb->s_root;
608 ovl_path_real(root_dentry, &path);
610 err = vfs_statfs(&path, buf);
612 buf->f_namelen = max(buf->f_namelen, ofs->lower_namelen);
613 buf->f_type = OVERLAYFS_SUPER_MAGIC;
622 * Prints the mount options for a given superblock.
623 * Returns zero; does not fail.
625 static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
627 struct super_block *sb = dentry->d_sb;
628 struct ovl_fs *ufs = sb->s_fs_info;
630 seq_show_option(m, "lowerdir", ufs->config.lowerdir);
631 if (ufs->config.upperdir) {
632 seq_show_option(m, "upperdir", ufs->config.upperdir);
633 seq_show_option(m, "workdir", ufs->config.workdir);
638 static int ovl_remount(struct super_block *sb, int *flags, char *data)
640 struct ovl_fs *ufs = sb->s_fs_info;
642 if (!(*flags & MS_RDONLY) && (!ufs->upper_mnt || !ufs->workdir))
648 static const struct super_operations ovl_super_operations = {
649 .put_super = ovl_put_super,
650 .statfs = ovl_statfs,
651 .show_options = ovl_show_options,
652 .remount_fs = ovl_remount,
662 static const match_table_t ovl_tokens = {
663 {OPT_LOWERDIR, "lowerdir=%s"},
664 {OPT_UPPERDIR, "upperdir=%s"},
665 {OPT_WORKDIR, "workdir=%s"},
669 static char *ovl_next_opt(char **s)
677 for (p = sbegin; *p; p++) {
682 } else if (*p == ',') {
692 static int ovl_parse_opt(char *opt, struct ovl_config *config)
696 while ((p = ovl_next_opt(&opt)) != NULL) {
698 substring_t args[MAX_OPT_ARGS];
703 token = match_token(p, ovl_tokens, args);
706 kfree(config->upperdir);
707 config->upperdir = match_strdup(&args[0]);
708 if (!config->upperdir)
713 kfree(config->lowerdir);
714 config->lowerdir = match_strdup(&args[0]);
715 if (!config->lowerdir)
720 kfree(config->workdir);
721 config->workdir = match_strdup(&args[0]);
722 if (!config->workdir)
727 pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p);
732 /* Workdir is useless in non-upper mount */
733 if (!config->upperdir && config->workdir) {
734 pr_info("overlayfs: option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
736 kfree(config->workdir);
737 config->workdir = NULL;
743 #define OVL_WORKDIR_NAME "work"
745 static struct dentry *ovl_workdir_create(struct vfsmount *mnt,
746 struct dentry *dentry)
748 struct inode *dir = dentry->d_inode;
751 bool retried = false;
753 err = mnt_want_write(mnt);
757 mutex_lock_nested(&dir->i_mutex, I_MUTEX_PARENT);
759 work = lookup_one_len(OVL_WORKDIR_NAME, dentry,
760 strlen(OVL_WORKDIR_NAME));
763 struct kstat stat = {
773 ovl_cleanup(dir, work);
778 err = ovl_create_real(dir, work, &stat, NULL, NULL, true);
783 mutex_unlock(&dir->i_mutex);
794 static void ovl_unescape(char *s)
807 static int ovl_mount_dir_noesc(const char *name, struct path *path)
812 pr_err("overlayfs: empty lowerdir\n");
815 err = kern_path(name, LOOKUP_FOLLOW, path);
817 pr_err("overlayfs: failed to resolve '%s': %i\n", name, err);
821 if (ovl_dentry_weird(path->dentry)) {
822 pr_err("overlayfs: filesystem on '%s' not supported\n", name);
825 if (!S_ISDIR(path->dentry->d_inode->i_mode)) {
826 pr_err("overlayfs: '%s' not a directory\n", name);
837 static int ovl_mount_dir(const char *name, struct path *path)
840 char *tmp = kstrdup(name, GFP_KERNEL);
844 err = ovl_mount_dir_noesc(tmp, path);
847 if (ovl_dentry_remote(path->dentry)) {
848 pr_err("overlayfs: filesystem on '%s' not supported as upperdir\n",
858 static int ovl_lower_dir(const char *name, struct path *path, long *namelen,
859 int *stack_depth, bool *remote)
862 struct kstatfs statfs;
864 err = ovl_mount_dir_noesc(name, path);
868 err = vfs_statfs(path, &statfs);
870 pr_err("overlayfs: statfs failed on '%s'\n", name);
873 *namelen = max(*namelen, statfs.f_namelen);
874 *stack_depth = max(*stack_depth, path->mnt->mnt_sb->s_stack_depth);
876 if (ovl_dentry_remote(path->dentry))
887 /* Workdir should not be subdir of upperdir and vice versa */
888 static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir)
892 if (workdir != upperdir) {
893 ok = (lock_rename(workdir, upperdir) == NULL);
894 unlock_rename(workdir, upperdir);
899 static unsigned int ovl_split_lowerdirs(char *str)
901 unsigned int ctr = 1;
904 for (s = d = str;; s++, d++) {
907 } else if (*s == ':') {
919 static int ovl_fill_super(struct super_block *sb, void *data, int silent)
921 struct path upperpath = { NULL, NULL };
922 struct path workpath = { NULL, NULL };
923 struct dentry *root_dentry;
924 struct ovl_entry *oe;
926 struct path *stack = NULL;
929 unsigned int numlower;
930 unsigned int stacklen = 0;
936 ufs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL);
940 err = ovl_parse_opt((char *) data, &ufs->config);
942 goto out_free_config;
945 if (!ufs->config.lowerdir) {
946 pr_err("overlayfs: missing 'lowerdir'\n");
947 goto out_free_config;
950 sb->s_stack_depth = 0;
951 sb->s_maxbytes = MAX_LFS_FILESIZE;
952 if (ufs->config.upperdir) {
953 if (!ufs->config.workdir) {
954 pr_err("overlayfs: missing 'workdir'\n");
955 goto out_free_config;
958 err = ovl_mount_dir(ufs->config.upperdir, &upperpath);
960 goto out_free_config;
962 /* Upper fs should not be r/o */
963 if (upperpath.mnt->mnt_sb->s_flags & MS_RDONLY) {
964 pr_err("overlayfs: upper fs is r/o, try multi-lower layers mount\n");
966 goto out_put_upperpath;
969 err = ovl_mount_dir(ufs->config.workdir, &workpath);
971 goto out_put_upperpath;
974 if (upperpath.mnt != workpath.mnt) {
975 pr_err("overlayfs: workdir and upperdir must reside under the same mount\n");
976 goto out_put_workpath;
978 if (!ovl_workdir_ok(workpath.dentry, upperpath.dentry)) {
979 pr_err("overlayfs: workdir and upperdir must be separate subtrees\n");
980 goto out_put_workpath;
982 sb->s_stack_depth = upperpath.mnt->mnt_sb->s_stack_depth;
985 lowertmp = kstrdup(ufs->config.lowerdir, GFP_KERNEL);
987 goto out_put_workpath;
990 stacklen = ovl_split_lowerdirs(lowertmp);
991 if (stacklen > OVL_MAX_STACK) {
992 pr_err("overlayfs: too many lower directries, limit is %d\n",
994 goto out_free_lowertmp;
995 } else if (!ufs->config.upperdir && stacklen == 1) {
996 pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n");
997 goto out_free_lowertmp;
1000 stack = kcalloc(stacklen, sizeof(struct path), GFP_KERNEL);
1002 goto out_free_lowertmp;
1005 for (numlower = 0; numlower < stacklen; numlower++) {
1006 err = ovl_lower_dir(lower, &stack[numlower],
1007 &ufs->lower_namelen, &sb->s_stack_depth,
1010 goto out_put_lowerpath;
1012 lower = strchr(lower, '\0') + 1;
1016 sb->s_stack_depth++;
1017 if (sb->s_stack_depth > FILESYSTEM_MAX_STACK_DEPTH) {
1018 pr_err("overlayfs: maximum fs stacking depth exceeded\n");
1019 goto out_put_lowerpath;
1022 if (ufs->config.upperdir) {
1023 ufs->upper_mnt = clone_private_mount(&upperpath);
1024 err = PTR_ERR(ufs->upper_mnt);
1025 if (IS_ERR(ufs->upper_mnt)) {
1026 pr_err("overlayfs: failed to clone upperpath\n");
1027 goto out_put_lowerpath;
1030 ufs->workdir = ovl_workdir_create(ufs->upper_mnt, workpath.dentry);
1031 err = PTR_ERR(ufs->workdir);
1032 if (IS_ERR(ufs->workdir)) {
1033 pr_warn("overlayfs: failed to create directory %s/%s (errno: %i); mounting read-only\n",
1034 ufs->config.workdir, OVL_WORKDIR_NAME, -err);
1035 sb->s_flags |= MS_RDONLY;
1036 ufs->workdir = NULL;
1041 ufs->lower_mnt = kcalloc(numlower, sizeof(struct vfsmount *), GFP_KERNEL);
1042 if (ufs->lower_mnt == NULL)
1043 goto out_put_workdir;
1044 for (i = 0; i < numlower; i++) {
1045 struct vfsmount *mnt = clone_private_mount(&stack[i]);
1049 pr_err("overlayfs: failed to clone lowerpath\n");
1050 goto out_put_lower_mnt;
1053 * Make lower_mnt R/O. That way fchmod/fchown on lower file
1054 * will fail instead of modifying lower fs.
1056 mnt->mnt_flags |= MNT_READONLY;
1058 ufs->lower_mnt[ufs->numlower] = mnt;
1062 /* If the upper fs is nonexistent, we mark overlayfs r/o too */
1063 if (!ufs->upper_mnt)
1064 sb->s_flags |= MS_RDONLY;
1067 sb->s_d_op = &ovl_reval_dentry_operations;
1069 sb->s_d_op = &ovl_dentry_operations;
1072 oe = ovl_alloc_entry(numlower);
1074 goto out_put_lower_mnt;
1076 root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, oe));
1080 mntput(upperpath.mnt);
1081 for (i = 0; i < numlower; i++)
1082 mntput(stack[i].mnt);
1083 path_put(&workpath);
1086 oe->__upperdentry = upperpath.dentry;
1087 for (i = 0; i < numlower; i++) {
1088 oe->lowerstack[i].dentry = stack[i].dentry;
1089 oe->lowerstack[i].mnt = ufs->lower_mnt[i];
1093 root_dentry->d_fsdata = oe;
1095 ovl_copyattr(ovl_dentry_real(root_dentry)->d_inode,
1096 root_dentry->d_inode);
1098 sb->s_magic = OVERLAYFS_SUPER_MAGIC;
1099 sb->s_op = &ovl_super_operations;
1100 sb->s_root = root_dentry;
1101 sb->s_fs_info = ufs;
1108 for (i = 0; i < ufs->numlower; i++)
1109 mntput(ufs->lower_mnt[i]);
1110 kfree(ufs->lower_mnt);
1113 mntput(ufs->upper_mnt);
1115 for (i = 0; i < numlower; i++)
1116 path_put(&stack[i]);
1121 path_put(&workpath);
1123 path_put(&upperpath);
1125 kfree(ufs->config.lowerdir);
1126 kfree(ufs->config.upperdir);
1127 kfree(ufs->config.workdir);
1133 static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags,
1134 const char *dev_name, void *raw_data)
1136 return mount_nodev(fs_type, flags, raw_data, ovl_fill_super);
1139 static struct file_system_type ovl_fs_type = {
1140 .owner = THIS_MODULE,
1143 .kill_sb = kill_anon_super,
1145 MODULE_ALIAS_FS("overlay");
1147 static int __init ovl_init(void)
1149 return register_filesystem(&ovl_fs_type);
1152 static void __exit ovl_exit(void)
1154 unregister_filesystem(&ovl_fs_type);
1157 module_init(ovl_init);
1158 module_exit(ovl_exit);