2
0

090-overlayfs-fallback-to-readonly-when-full.patch 3.2 KB

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