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/pagemap.h>
20 #include <linux/sched.h>
21 #include <linux/statfs.h>
22 #include <linux/seq_file.h>
23 #include "overlayfs.h"
25 MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
26 MODULE_DESCRIPTION("Overlay filesystem");
27 MODULE_LICENSE("GPL");
33 bool default_permissions
;
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 if (S_ISDIR(dentry
->d_inode
->i_mode
))
81 type
|= __OVL_PATH_MERGE
;
82 } else if (!oe
->opaque
) {
83 type
|= __OVL_PATH_PURE
;
87 type
|= __OVL_PATH_MERGE
;
92 static struct dentry
*ovl_upperdentry_dereference(struct ovl_entry
*oe
)
94 return lockless_dereference(oe
->__upperdentry
);
97 void ovl_path_upper(struct dentry
*dentry
, struct path
*path
)
99 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
100 struct ovl_entry
*oe
= dentry
->d_fsdata
;
102 path
->mnt
= ofs
->upper_mnt
;
103 path
->dentry
= ovl_upperdentry_dereference(oe
);
106 enum ovl_path_type
ovl_path_real(struct dentry
*dentry
, struct path
*path
)
108 enum ovl_path_type type
= ovl_path_type(dentry
);
110 if (!OVL_TYPE_UPPER(type
))
111 ovl_path_lower(dentry
, path
);
113 ovl_path_upper(dentry
, path
);
118 struct dentry
*ovl_dentry_upper(struct dentry
*dentry
)
120 struct ovl_entry
*oe
= dentry
->d_fsdata
;
122 return ovl_upperdentry_dereference(oe
);
125 struct dentry
*ovl_dentry_lower(struct dentry
*dentry
)
127 struct ovl_entry
*oe
= dentry
->d_fsdata
;
129 return __ovl_dentry_lower(oe
);
132 struct dentry
*ovl_dentry_real(struct dentry
*dentry
)
134 struct ovl_entry
*oe
= dentry
->d_fsdata
;
135 struct dentry
*realdentry
;
137 realdentry
= ovl_upperdentry_dereference(oe
);
139 realdentry
= __ovl_dentry_lower(oe
);
144 struct dentry
*ovl_entry_real(struct ovl_entry
*oe
, bool *is_upper
)
146 struct dentry
*realdentry
;
148 realdentry
= ovl_upperdentry_dereference(oe
);
152 realdentry
= __ovl_dentry_lower(oe
);
158 struct vfsmount
*ovl_entry_mnt_real(struct ovl_entry
*oe
, struct inode
*inode
,
162 struct ovl_fs
*ofs
= inode
->i_sb
->s_fs_info
;
164 return ofs
->upper_mnt
;
166 return oe
->numlower
? oe
->lowerstack
[0].mnt
: NULL
;
170 struct ovl_dir_cache
*ovl_dir_cache(struct dentry
*dentry
)
172 struct ovl_entry
*oe
= dentry
->d_fsdata
;
177 bool ovl_is_default_permissions(struct inode
*inode
)
179 struct ovl_fs
*ofs
= inode
->i_sb
->s_fs_info
;
181 return ofs
->config
.default_permissions
;
184 void ovl_set_dir_cache(struct dentry
*dentry
, struct ovl_dir_cache
*cache
)
186 struct ovl_entry
*oe
= dentry
->d_fsdata
;
191 void ovl_path_lower(struct dentry
*dentry
, struct path
*path
)
193 struct ovl_entry
*oe
= dentry
->d_fsdata
;
195 *path
= oe
->numlower
? oe
->lowerstack
[0] : (struct path
) { NULL
, NULL
};
198 int ovl_want_write(struct dentry
*dentry
)
200 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
201 return mnt_want_write(ofs
->upper_mnt
);
204 void ovl_drop_write(struct dentry
*dentry
)
206 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
207 mnt_drop_write(ofs
->upper_mnt
);
210 struct dentry
*ovl_workdir(struct dentry
*dentry
)
212 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
216 bool ovl_dentry_is_opaque(struct dentry
*dentry
)
218 struct ovl_entry
*oe
= dentry
->d_fsdata
;
222 void ovl_dentry_set_opaque(struct dentry
*dentry
, bool opaque
)
224 struct ovl_entry
*oe
= dentry
->d_fsdata
;
228 void ovl_dentry_update(struct dentry
*dentry
, struct dentry
*upperdentry
)
230 struct ovl_entry
*oe
= dentry
->d_fsdata
;
232 WARN_ON(!inode_is_locked(upperdentry
->d_parent
->d_inode
));
233 WARN_ON(oe
->__upperdentry
);
234 BUG_ON(!upperdentry
->d_inode
);
236 * Make sure upperdentry is consistent before making it visible to
237 * ovl_upperdentry_dereference().
240 oe
->__upperdentry
= upperdentry
;
243 void ovl_dentry_version_inc(struct dentry
*dentry
)
245 struct ovl_entry
*oe
= dentry
->d_fsdata
;
247 WARN_ON(!inode_is_locked(dentry
->d_inode
));
251 u64
ovl_dentry_version_get(struct dentry
*dentry
)
253 struct ovl_entry
*oe
= dentry
->d_fsdata
;
255 WARN_ON(!inode_is_locked(dentry
->d_inode
));
259 bool ovl_is_whiteout(struct dentry
*dentry
)
261 struct inode
*inode
= dentry
->d_inode
;
263 return inode
&& IS_WHITEOUT(inode
);
266 static bool ovl_is_opaquedir(struct dentry
*dentry
)
270 struct inode
*inode
= dentry
->d_inode
;
272 if (!S_ISDIR(inode
->i_mode
) || !inode
->i_op
->getxattr
)
275 res
= inode
->i_op
->getxattr(dentry
, OVL_XATTR_OPAQUE
, &val
, 1);
276 if (res
== 1 && val
== 'y')
282 static void ovl_dentry_release(struct dentry
*dentry
)
284 struct ovl_entry
*oe
= dentry
->d_fsdata
;
289 dput(oe
->__upperdentry
);
290 for (i
= 0; i
< oe
->numlower
; i
++)
291 dput(oe
->lowerstack
[i
].dentry
);
296 static int ovl_dentry_revalidate(struct dentry
*dentry
, unsigned int flags
)
298 struct ovl_entry
*oe
= dentry
->d_fsdata
;
302 for (i
= 0; i
< oe
->numlower
; i
++) {
303 struct dentry
*d
= oe
->lowerstack
[i
].dentry
;
305 if (d
->d_flags
& DCACHE_OP_REVALIDATE
) {
306 ret
= d
->d_op
->d_revalidate(d
, flags
);
310 if (!(flags
& LOOKUP_RCU
))
319 static int ovl_dentry_weak_revalidate(struct dentry
*dentry
, unsigned int flags
)
321 struct ovl_entry
*oe
= dentry
->d_fsdata
;
325 for (i
= 0; i
< oe
->numlower
; i
++) {
326 struct dentry
*d
= oe
->lowerstack
[i
].dentry
;
328 if (d
->d_flags
& DCACHE_OP_WEAK_REVALIDATE
) {
329 ret
= d
->d_op
->d_weak_revalidate(d
, flags
);
337 static const struct dentry_operations ovl_dentry_operations
= {
338 .d_release
= ovl_dentry_release
,
339 .d_select_inode
= ovl_d_select_inode
,
342 static const struct dentry_operations ovl_reval_dentry_operations
= {
343 .d_release
= ovl_dentry_release
,
344 .d_revalidate
= ovl_dentry_revalidate
,
345 .d_weak_revalidate
= ovl_dentry_weak_revalidate
,
348 static struct ovl_entry
*ovl_alloc_entry(unsigned int numlower
)
350 size_t size
= offsetof(struct ovl_entry
, lowerstack
[numlower
]);
351 struct ovl_entry
*oe
= kzalloc(size
, GFP_KERNEL
);
354 oe
->numlower
= numlower
;
359 static bool ovl_dentry_remote(struct dentry
*dentry
)
361 return dentry
->d_flags
&
362 (DCACHE_OP_REVALIDATE
| DCACHE_OP_WEAK_REVALIDATE
);
365 static bool ovl_dentry_weird(struct dentry
*dentry
)
367 return dentry
->d_flags
& (DCACHE_NEED_AUTOMOUNT
|
368 DCACHE_MANAGE_TRANSIT
|
373 static inline struct dentry
*ovl_lookup_real(struct dentry
*dir
,
376 struct dentry
*dentry
;
378 inode_lock(dir
->d_inode
);
379 dentry
= lookup_one_len(name
->name
, dir
, name
->len
);
380 inode_unlock(dir
->d_inode
);
382 if (IS_ERR(dentry
)) {
383 if (PTR_ERR(dentry
) == -ENOENT
)
385 } else if (!dentry
->d_inode
) {
388 } else if (ovl_dentry_weird(dentry
)) {
390 /* Don't support traversing automounts and other weirdness */
391 dentry
= ERR_PTR(-EREMOTE
);
397 * Returns next layer in stack starting from top.
398 * Returns -1 if this is the last layer.
400 int ovl_path_next(int idx
, struct dentry
*dentry
, struct path
*path
)
402 struct ovl_entry
*oe
= dentry
->d_fsdata
;
406 ovl_path_upper(dentry
, path
);
408 return oe
->numlower
? 1 : -1;
411 BUG_ON(idx
> oe
->numlower
);
412 *path
= oe
->lowerstack
[idx
- 1];
414 return (idx
< oe
->numlower
) ? idx
+ 1 : -1;
417 struct dentry
*ovl_lookup(struct inode
*dir
, struct dentry
*dentry
,
420 struct ovl_entry
*oe
;
421 struct ovl_entry
*poe
= dentry
->d_parent
->d_fsdata
;
422 struct path
*stack
= NULL
;
423 struct dentry
*upperdir
, *upperdentry
= NULL
;
424 unsigned int ctr
= 0;
425 struct inode
*inode
= NULL
;
426 bool upperopaque
= false;
427 struct dentry
*this, *prev
= NULL
;
431 upperdir
= ovl_upperdentry_dereference(poe
);
433 this = ovl_lookup_real(upperdir
, &dentry
->d_name
);
439 if (unlikely(ovl_dentry_remote(this))) {
444 if (ovl_is_whiteout(this)) {
448 } else if (poe
->numlower
&& ovl_is_opaquedir(this)) {
452 upperdentry
= prev
= this;
455 if (!upperopaque
&& poe
->numlower
) {
457 stack
= kcalloc(poe
->numlower
, sizeof(struct path
), GFP_KERNEL
);
462 for (i
= 0; !upperopaque
&& i
< poe
->numlower
; i
++) {
464 struct path lowerpath
= poe
->lowerstack
[i
];
466 this = ovl_lookup_real(lowerpath
.dentry
, &dentry
->d_name
);
470 * If it's positive, then treat ENAMETOOLONG as ENOENT.
472 if (err
== -ENAMETOOLONG
&& (upperdentry
|| ctr
))
478 if (ovl_is_whiteout(this)) {
483 * Only makes sense to check opaque dir if this is not the
486 if (i
< poe
->numlower
- 1 && ovl_is_opaquedir(this))
489 if (prev
&& (!S_ISDIR(prev
->d_inode
->i_mode
) ||
490 !S_ISDIR(this->d_inode
->i_mode
))) {
492 * FIXME: check for upper-opaqueness maybe better done
495 if (prev
== upperdentry
)
501 * If this is a non-directory then stop here.
503 if (!S_ISDIR(this->d_inode
->i_mode
))
506 stack
[ctr
].dentry
= this;
507 stack
[ctr
].mnt
= lowerpath
.mnt
;
514 oe
= ovl_alloc_entry(ctr
);
519 if (upperdentry
|| ctr
) {
520 struct dentry
*realdentry
;
522 realdentry
= upperdentry
? upperdentry
: stack
[0].dentry
;
525 inode
= ovl_new_inode(dentry
->d_sb
, realdentry
->d_inode
->i_mode
,
529 ovl_copyattr(realdentry
->d_inode
, inode
);
532 oe
->opaque
= upperopaque
;
533 oe
->__upperdentry
= upperdentry
;
534 memcpy(oe
->lowerstack
, stack
, sizeof(struct path
) * ctr
);
536 dentry
->d_fsdata
= oe
;
537 d_add(dentry
, inode
);
544 for (i
= 0; i
< ctr
; i
++)
545 dput(stack
[i
].dentry
);
553 struct file
*ovl_path_open(struct path
*path
, int flags
)
555 return dentry_open(path
, flags
, current_cred());
558 static void ovl_put_super(struct super_block
*sb
)
560 struct ovl_fs
*ufs
= sb
->s_fs_info
;
564 mntput(ufs
->upper_mnt
);
565 for (i
= 0; i
< ufs
->numlower
; i
++)
566 mntput(ufs
->lower_mnt
[i
]);
567 kfree(ufs
->lower_mnt
);
569 kfree(ufs
->config
.lowerdir
);
570 kfree(ufs
->config
.upperdir
);
571 kfree(ufs
->config
.workdir
);
577 * @sb: The overlayfs super block
578 * @buf: The struct kstatfs to fill in with stats
580 * Get the filesystem statistics. As writes always target the upper layer
581 * filesystem pass the statfs to the upper filesystem (if it exists)
583 static int ovl_statfs(struct dentry
*dentry
, struct kstatfs
*buf
)
585 struct ovl_fs
*ofs
= dentry
->d_sb
->s_fs_info
;
586 struct dentry
*root_dentry
= dentry
->d_sb
->s_root
;
590 ovl_path_real(root_dentry
, &path
);
592 err
= vfs_statfs(&path
, buf
);
594 buf
->f_namelen
= max(buf
->f_namelen
, ofs
->lower_namelen
);
595 buf
->f_type
= OVERLAYFS_SUPER_MAGIC
;
604 * Prints the mount options for a given superblock.
605 * Returns zero; does not fail.
607 static int ovl_show_options(struct seq_file
*m
, struct dentry
*dentry
)
609 struct super_block
*sb
= dentry
->d_sb
;
610 struct ovl_fs
*ufs
= sb
->s_fs_info
;
612 seq_show_option(m
, "lowerdir", ufs
->config
.lowerdir
);
613 if (ufs
->config
.upperdir
) {
614 seq_show_option(m
, "upperdir", ufs
->config
.upperdir
);
615 seq_show_option(m
, "workdir", ufs
->config
.workdir
);
617 if (ufs
->config
.default_permissions
)
618 seq_puts(m
, ",default_permissions");
622 static int ovl_remount(struct super_block
*sb
, int *flags
, char *data
)
624 struct ovl_fs
*ufs
= sb
->s_fs_info
;
626 if (!(*flags
& MS_RDONLY
) && (!ufs
->upper_mnt
|| !ufs
->workdir
))
632 static const struct super_operations ovl_super_operations
= {
633 .put_super
= ovl_put_super
,
634 .statfs
= ovl_statfs
,
635 .show_options
= ovl_show_options
,
636 .remount_fs
= ovl_remount
,
643 OPT_DEFAULT_PERMISSIONS
,
647 static const match_table_t ovl_tokens
= {
648 {OPT_LOWERDIR
, "lowerdir=%s"},
649 {OPT_UPPERDIR
, "upperdir=%s"},
650 {OPT_WORKDIR
, "workdir=%s"},
651 {OPT_DEFAULT_PERMISSIONS
, "default_permissions"},
655 static char *ovl_next_opt(char **s
)
663 for (p
= sbegin
; *p
; p
++) {
668 } else if (*p
== ',') {
678 static int ovl_parse_opt(char *opt
, struct ovl_config
*config
)
682 while ((p
= ovl_next_opt(&opt
)) != NULL
) {
684 substring_t args
[MAX_OPT_ARGS
];
689 token
= match_token(p
, ovl_tokens
, args
);
692 kfree(config
->upperdir
);
693 config
->upperdir
= match_strdup(&args
[0]);
694 if (!config
->upperdir
)
699 kfree(config
->lowerdir
);
700 config
->lowerdir
= match_strdup(&args
[0]);
701 if (!config
->lowerdir
)
706 kfree(config
->workdir
);
707 config
->workdir
= match_strdup(&args
[0]);
708 if (!config
->workdir
)
712 case OPT_DEFAULT_PERMISSIONS
:
713 config
->default_permissions
= true;
717 pr_err("overlayfs: unrecognized mount option \"%s\" or missing value\n", p
);
722 /* Workdir is useless in non-upper mount */
723 if (!config
->upperdir
&& config
->workdir
) {
724 pr_info("overlayfs: option \"workdir=%s\" is useless in a non-upper mount, ignore\n",
726 kfree(config
->workdir
);
727 config
->workdir
= NULL
;
733 #define OVL_WORKDIR_NAME "work"
735 static struct dentry
*ovl_workdir_create(struct vfsmount
*mnt
,
736 struct dentry
*dentry
)
738 struct inode
*dir
= dentry
->d_inode
;
741 bool retried
= false;
743 err
= mnt_want_write(mnt
);
747 inode_lock_nested(dir
, I_MUTEX_PARENT
);
749 work
= lookup_one_len(OVL_WORKDIR_NAME
, dentry
,
750 strlen(OVL_WORKDIR_NAME
));
753 struct kstat stat
= {
763 ovl_cleanup(dir
, work
);
768 err
= ovl_create_real(dir
, work
, &stat
, NULL
, NULL
, true);
784 static void ovl_unescape(char *s
)
797 static int ovl_mount_dir_noesc(const char *name
, struct path
*path
)
802 pr_err("overlayfs: empty lowerdir\n");
805 err
= kern_path(name
, LOOKUP_FOLLOW
, path
);
807 pr_err("overlayfs: failed to resolve '%s': %i\n", name
, err
);
811 if (ovl_dentry_weird(path
->dentry
)) {
812 pr_err("overlayfs: filesystem on '%s' not supported\n", name
);
815 if (!S_ISDIR(path
->dentry
->d_inode
->i_mode
)) {
816 pr_err("overlayfs: '%s' not a directory\n", name
);
827 static int ovl_mount_dir(const char *name
, struct path
*path
)
830 char *tmp
= kstrdup(name
, GFP_KERNEL
);
834 err
= ovl_mount_dir_noesc(tmp
, path
);
837 if (ovl_dentry_remote(path
->dentry
)) {
838 pr_err("overlayfs: filesystem on '%s' not supported as upperdir\n",
848 static int ovl_lower_dir(const char *name
, struct path
*path
, long *namelen
,
849 int *stack_depth
, bool *remote
)
852 struct kstatfs statfs
;
854 err
= ovl_mount_dir_noesc(name
, path
);
858 err
= vfs_statfs(path
, &statfs
);
860 pr_err("overlayfs: statfs failed on '%s'\n", name
);
863 *namelen
= max(*namelen
, statfs
.f_namelen
);
864 *stack_depth
= max(*stack_depth
, path
->mnt
->mnt_sb
->s_stack_depth
);
866 if (ovl_dentry_remote(path
->dentry
))
877 /* Workdir should not be subdir of upperdir and vice versa */
878 static bool ovl_workdir_ok(struct dentry
*workdir
, struct dentry
*upperdir
)
882 if (workdir
!= upperdir
) {
883 ok
= (lock_rename(workdir
, upperdir
) == NULL
);
884 unlock_rename(workdir
, upperdir
);
889 static unsigned int ovl_split_lowerdirs(char *str
)
891 unsigned int ctr
= 1;
894 for (s
= d
= str
;; s
++, d
++) {
897 } else if (*s
== ':') {
909 static int ovl_fill_super(struct super_block
*sb
, void *data
, int silent
)
911 struct path upperpath
= { NULL
, NULL
};
912 struct path workpath
= { NULL
, NULL
};
913 struct dentry
*root_dentry
;
914 struct ovl_entry
*oe
;
916 struct path
*stack
= NULL
;
919 unsigned int numlower
;
920 unsigned int stacklen
= 0;
926 ufs
= kzalloc(sizeof(struct ovl_fs
), GFP_KERNEL
);
930 err
= ovl_parse_opt((char *) data
, &ufs
->config
);
932 goto out_free_config
;
935 if (!ufs
->config
.lowerdir
) {
936 pr_err("overlayfs: missing 'lowerdir'\n");
937 goto out_free_config
;
940 sb
->s_stack_depth
= 0;
941 sb
->s_maxbytes
= MAX_LFS_FILESIZE
;
942 if (ufs
->config
.upperdir
) {
943 if (!ufs
->config
.workdir
) {
944 pr_err("overlayfs: missing 'workdir'\n");
945 goto out_free_config
;
948 err
= ovl_mount_dir(ufs
->config
.upperdir
, &upperpath
);
950 goto out_free_config
;
952 /* Upper fs should not be r/o */
953 if (upperpath
.mnt
->mnt_sb
->s_flags
& MS_RDONLY
) {
954 pr_err("overlayfs: upper fs is r/o, try multi-lower layers mount\n");
956 goto out_put_upperpath
;
959 err
= ovl_mount_dir(ufs
->config
.workdir
, &workpath
);
961 goto out_put_upperpath
;
964 if (upperpath
.mnt
!= workpath
.mnt
) {
965 pr_err("overlayfs: workdir and upperdir must reside under the same mount\n");
966 goto out_put_workpath
;
968 if (!ovl_workdir_ok(workpath
.dentry
, upperpath
.dentry
)) {
969 pr_err("overlayfs: workdir and upperdir must be separate subtrees\n");
970 goto out_put_workpath
;
972 sb
->s_stack_depth
= upperpath
.mnt
->mnt_sb
->s_stack_depth
;
975 lowertmp
= kstrdup(ufs
->config
.lowerdir
, GFP_KERNEL
);
977 goto out_put_workpath
;
980 stacklen
= ovl_split_lowerdirs(lowertmp
);
981 if (stacklen
> OVL_MAX_STACK
) {
982 pr_err("overlayfs: too many lower directries, limit is %d\n",
984 goto out_free_lowertmp
;
985 } else if (!ufs
->config
.upperdir
&& stacklen
== 1) {
986 pr_err("overlayfs: at least 2 lowerdir are needed while upperdir nonexistent\n");
987 goto out_free_lowertmp
;
990 stack
= kcalloc(stacklen
, sizeof(struct path
), GFP_KERNEL
);
992 goto out_free_lowertmp
;
995 for (numlower
= 0; numlower
< stacklen
; numlower
++) {
996 err
= ovl_lower_dir(lower
, &stack
[numlower
],
997 &ufs
->lower_namelen
, &sb
->s_stack_depth
,
1000 goto out_put_lowerpath
;
1002 lower
= strchr(lower
, '\0') + 1;
1006 sb
->s_stack_depth
++;
1007 if (sb
->s_stack_depth
> FILESYSTEM_MAX_STACK_DEPTH
) {
1008 pr_err("overlayfs: maximum fs stacking depth exceeded\n");
1009 goto out_put_lowerpath
;
1012 if (ufs
->config
.upperdir
) {
1013 ufs
->upper_mnt
= clone_private_mount(&upperpath
);
1014 err
= PTR_ERR(ufs
->upper_mnt
);
1015 if (IS_ERR(ufs
->upper_mnt
)) {
1016 pr_err("overlayfs: failed to clone upperpath\n");
1017 goto out_put_lowerpath
;
1020 ufs
->workdir
= ovl_workdir_create(ufs
->upper_mnt
, workpath
.dentry
);
1021 err
= PTR_ERR(ufs
->workdir
);
1022 if (IS_ERR(ufs
->workdir
)) {
1023 pr_warn("overlayfs: failed to create directory %s/%s (errno: %i); mounting read-only\n",
1024 ufs
->config
.workdir
, OVL_WORKDIR_NAME
, -err
);
1025 sb
->s_flags
|= MS_RDONLY
;
1026 ufs
->workdir
= NULL
;
1031 ufs
->lower_mnt
= kcalloc(numlower
, sizeof(struct vfsmount
*), GFP_KERNEL
);
1032 if (ufs
->lower_mnt
== NULL
)
1033 goto out_put_workdir
;
1034 for (i
= 0; i
< numlower
; i
++) {
1035 struct vfsmount
*mnt
= clone_private_mount(&stack
[i
]);
1039 pr_err("overlayfs: failed to clone lowerpath\n");
1040 goto out_put_lower_mnt
;
1043 * Make lower_mnt R/O. That way fchmod/fchown on lower file
1044 * will fail instead of modifying lower fs.
1046 mnt
->mnt_flags
|= MNT_READONLY
;
1048 ufs
->lower_mnt
[ufs
->numlower
] = mnt
;
1052 /* If the upper fs is nonexistent, we mark overlayfs r/o too */
1053 if (!ufs
->upper_mnt
)
1054 sb
->s_flags
|= MS_RDONLY
;
1057 sb
->s_d_op
= &ovl_reval_dentry_operations
;
1059 sb
->s_d_op
= &ovl_dentry_operations
;
1062 oe
= ovl_alloc_entry(numlower
);
1064 goto out_put_lower_mnt
;
1066 root_dentry
= d_make_root(ovl_new_inode(sb
, S_IFDIR
, oe
));
1070 mntput(upperpath
.mnt
);
1071 for (i
= 0; i
< numlower
; i
++)
1072 mntput(stack
[i
].mnt
);
1073 path_put(&workpath
);
1076 oe
->__upperdentry
= upperpath
.dentry
;
1077 for (i
= 0; i
< numlower
; i
++) {
1078 oe
->lowerstack
[i
].dentry
= stack
[i
].dentry
;
1079 oe
->lowerstack
[i
].mnt
= ufs
->lower_mnt
[i
];
1083 root_dentry
->d_fsdata
= oe
;
1085 ovl_copyattr(ovl_dentry_real(root_dentry
)->d_inode
,
1086 root_dentry
->d_inode
);
1088 sb
->s_magic
= OVERLAYFS_SUPER_MAGIC
;
1089 sb
->s_op
= &ovl_super_operations
;
1090 sb
->s_root
= root_dentry
;
1091 sb
->s_fs_info
= ufs
;
1098 for (i
= 0; i
< ufs
->numlower
; i
++)
1099 mntput(ufs
->lower_mnt
[i
]);
1100 kfree(ufs
->lower_mnt
);
1103 mntput(ufs
->upper_mnt
);
1105 for (i
= 0; i
< numlower
; i
++)
1106 path_put(&stack
[i
]);
1111 path_put(&workpath
);
1113 path_put(&upperpath
);
1115 kfree(ufs
->config
.lowerdir
);
1116 kfree(ufs
->config
.upperdir
);
1117 kfree(ufs
->config
.workdir
);
1123 static struct dentry
*ovl_mount(struct file_system_type
*fs_type
, int flags
,
1124 const char *dev_name
, void *raw_data
)
1126 return mount_nodev(fs_type
, flags
, raw_data
, ovl_fill_super
);
1129 static struct file_system_type ovl_fs_type
= {
1130 .owner
= THIS_MODULE
,
1133 .kill_sb
= kill_anon_super
,
1135 MODULE_ALIAS_FS("overlay");
1137 static int __init
ovl_init(void)
1139 return register_filesystem(&ovl_fs_type
);
1142 static void __exit
ovl_exit(void)
1144 unregister_filesystem(&ovl_fs_type
);
1147 module_init(ovl_init
);
1148 module_exit(ovl_exit
);