xburst: Remove unmaintained target
[openwrt/staging/dedeckeh.git] / target / linux / generic / pending-3.18 / 090-overlayfs-fallback-to-readonly-when-full.patch
1 [linux-unionfs added to Cc]
2
3 On Tue, May 19, 2015 at 09:51:20AM +0200, Bastian Bittorf wrote:
4 > Hi Miklos,
5 >
6 > sorry for writing directly to you, feel free to forward
7 > this to the appropriate mailinglist.
8 >
9 > we have a problem with mainline overlay filesystem on kernel 3.18:
10 > https://dev.openwrt.org/ticket/19564
11 >
12 > 2 things are odd:
13 > when the working filesystem is full, overlays fails with:
14 >
15 > overlayfs: failed to create directory /overlay/work/work
16 >
17 > what is strange, that we call it with:
18 >
19 > mount(overlay, "/mnt", "overlay", MS_NOATIME, lowerdir)
20 >
21 > see here:
22 > http://nbd.name/gitweb.cgi?p=fstools.git;a=blob;f=libfstools/mount.c;h=81176ce399b4cd8e2d347c0008c13dec92407f55;hb=e6004000ff15d7bd32cf5663e8690fc94d7ec747#l125
23 >
24 > do you have an idea whats wrong?
25 > 1) is it really needed, that we need space for creating dir "/overlay/work"?
26 > 2) why does overlay need "/overlay/work/work"?
27
28 The work directory is needed for atomic copy-up and similar. It is not actually
29 necessary to mount a read-only overlay. Post 4.0 it is possible to mount the
30 overlay without workdir (but even then it won't happen automatically in case the
31 upper fs is full, so this should be fixed in the latest kernel too).
32
33 Could you please try the following patch? If the workdir can't be created it
34 will fall back to mounting the overlay read-only.
35
36 Thanks,
37 Miklos
38
39 ---
40 fs/overlayfs/copy_up.c | 3 +++
41 fs/overlayfs/dir.c | 9 +++++++++
42 fs/overlayfs/super.c | 12 +++++++++---
43 3 files changed, 21 insertions(+), 3 deletions(-)
44
45 --- a/fs/overlayfs/copy_up.c
46 +++ b/fs/overlayfs/copy_up.c
47 @@ -315,6 +315,9 @@ int ovl_copy_up_one(struct dentry *paren
48 struct cred *override_cred;
49 char *link = NULL;
50
51 + if (WARN_ON(!workdir))
52 + return -EROFS;
53 +
54 ovl_path_upper(parent, &parentpath);
55 upperdir = parentpath.dentry;
56
57 --- a/fs/overlayfs/dir.c
58 +++ b/fs/overlayfs/dir.c
59 @@ -222,6 +222,9 @@ static struct dentry *ovl_clear_empty(st
60 struct kstat stat;
61 int err;
62
63 + if (WARN_ON(!workdir))
64 + return ERR_PTR(-EROFS);
65 +
66 err = ovl_lock_rename_workdir(workdir, upperdir);
67 if (err)
68 goto out;
69 @@ -322,6 +325,9 @@ static int ovl_create_over_whiteout(stru
70 struct dentry *newdentry;
71 int err;
72
73 + if (WARN_ON(!workdir))
74 + return -EROFS;
75 +
76 err = ovl_lock_rename_workdir(workdir, upperdir);
77 if (err)
78 goto out;
79 @@ -507,6 +513,9 @@ static int ovl_remove_and_whiteout(struc
80 int err;
81 int flags = 0;
82
83 + if (WARN_ON(!workdir))
84 + return -EROFS;
85 +
86 if (is_dir) {
87 opaquedir = ovl_check_empty_and_clear(dentry);
88 err = PTR_ERR(opaquedir);
89 --- a/fs/overlayfs/super.c
90 +++ b/fs/overlayfs/super.c
91 @@ -760,9 +760,15 @@ static int ovl_fill_super(struct super_b
92 ufs->workdir = ovl_workdir_create(ufs->upper_mnt, workpath.dentry);
93 err = PTR_ERR(ufs->workdir);
94 if (IS_ERR(ufs->workdir)) {
95 - pr_err("overlayfs: failed to create directory %s/%s\n",
96 - ufs->config.workdir, OVL_WORKDIR_NAME);
97 - goto out_put_lower_mnt;
98 + if (err == -ENOSPC || err == -EROFS) {
99 + pr_warning("overlayfs: failed to create work directory (%s), mounting read-only\n", err == ENOSPC ? "ENOSPC" : "EROFS");
100 + sb->s_flags |= MS_RDONLY;
101 + ufs->workdir = NULL;
102 + } else {
103 + pr_err("overlayfs: failed to create directory %s/%s\n",
104 + ufs->config.workdir, OVL_WORKDIR_NAME);
105 + goto out_put_lower_mnt;
106 + }
107 }
108
109 /*