1. 05 10月, 2017 1 次提交
  2. 10 8月, 2017 1 次提交
  3. 28 7月, 2017 3 次提交
    • M
      ovl: constant d_ino for non-merge dirs · 4edb83bb
      Miklos Szeredi 提交于
      Impure directories are ones which contain objects with origins (i.e. those
      that have been copied up).  These are relevant to readdir operation only
      because of the d_ino field, no other transformation is necessary.  Also a
      directory can become impure between two getdents(2) calls.
      
      This patch creates a cache for impure directories.  Unlike the cache for
      merged directories, this one only contains entries with origin and is not
      refcounted but has a its lifetime tied to that of the dentry.
      
      Similarly to the merged cache, the impure cache is invalidated based on a
      version number.  This version number is incremented when an entry with
      origin is added or removed from the directory.
      
      If the cache is empty, then the impure xattr is removed from the directory.
      
      This patch also fixes up handling of d_ino for the ".." entry if the parent
      directory is merged.
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      4edb83bb
    • A
      ovl: constant d_ino across copy up · b5efccbe
      Amir Goldstein 提交于
      When all layers are on the same fs, and iterating a directory which may
      contain copy up entries, call vfs_getattr() on the overlay entries to make
      sure that d_ino will be consistent with st_ino from stat(2).
      
      There is an overhead of lookup per upper entry in readdir.
      
      The overhead is minimal if the iterated entries are already in dcache.  It
      is also quite useful for the common case of 'ls -l' that readdir() pre
      populates the dcache with the listed entries, making the following stat()
      calls faster.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      b5efccbe
    • M
      ovl: fix readdir error value · 31e8ccea
      Miklos Szeredi 提交于
      actor's return value is taken as a bool (filled/not filled) so we need to
      return the error in the context.
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      31e8ccea
  4. 20 7月, 2017 1 次提交
    • A
      ovl: do not cleanup directory and whiteout index entries · 61b67471
      Amir Goldstein 提交于
      Directory index entries are going to be used for looking up
      redirected upper dirs by lower dir fh when decoding an overlay
      file handle of a merge dir.
      
      Whiteout index entries are going to be used as an indication that
      an exported overlay file handle should be treated as stale (i.e.
      after unlink of the overlay inode).
      
      We don't know the verification rules for directory and whiteout
      index entries, because they have not been implemented yet, so fail
      to mount overlay rw if those entries are found to avoid corrupting
      an index that was created by a newer kernel.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      61b67471
  5. 05 7月, 2017 1 次提交
    • A
      ovl: cleanup bad and stale index entries on mount · 415543d5
      Amir Goldstein 提交于
      Bad index entries are entries whose name does not match the
      origin file handle stored in trusted.overlay.origin xattr.
      Bad index entries could be a result of a system power off in
      the middle of copy up.
      
      Stale index entries are entries whose origin file handle is
      stale. Stale index entries could be a result of copying layers
      or removing lower entries while the overlay is not mounted.
      The case of copying layers should be detected earlier by the
      verification of upper root dir origin and index dir origin.
      
      Both bad and stale index entries are detected and removed
      on mount.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      415543d5
  6. 01 9月, 2016 1 次提交
    • M
      ovl: proper cleanup of workdir · eea2fb48
      Miklos Szeredi 提交于
      When mounting overlayfs it needs a clean "work" directory under the
      supplied workdir.
      
      Previously the mount code removed this directory if it already existed and
      created a new one.  If the removal failed (e.g. directory was not empty)
      then it fell back to a read-only mount not using the workdir.
      
      While this has never been reported, it is possible to get a non-empty
      "work" dir from a previous mount of overlayfs in case of crash in the
      middle of an operation using the work directory.
      
      In this case the left over state should be discarded and the overlay
      filesystem will be consistent, guaranteed by the atomicity of operations on
      moving to/from the workdir to the upper layer.
      
      This patch implements cleaning out any files left in workdir.  It is
      implemented using real recursion for simplicity, but the depth is limited
      to 2, because the worst case is that of a directory containing whiteouts
      under "work".
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      Cc: <stable@vger.kernel.org>
      eea2fb48
  7. 27 5月, 2016 1 次提交
    • A
      ovl: override creds with the ones from the superblock mounter · 3fe6e52f
      Antonio Murdaca 提交于
      In user namespace the whiteout creation fails with -EPERM because the
      current process isn't capable(CAP_SYS_ADMIN) when setting xattr.
      
      A simple reproducer:
      
      $ mkdir upper lower work merged lower/dir
      $ sudo mount -t overlay overlay -olowerdir=lower,upperdir=upper,workdir=work merged
      $ unshare -m -p -f -U -r bash
      
      Now as root in the user namespace:
      
      \# touch merged/dir/{1,2,3} # this will force a copy up of lower/dir
      \# rm -fR merged/*
      
      This ends up failing with -EPERM after the files in dir has been
      correctly deleted:
      
      unlinkat(4, "2", 0)                     = 0
      unlinkat(4, "1", 0)                     = 0
      unlinkat(4, "3", 0)                     = 0
      close(4)                                = 0
      unlinkat(AT_FDCWD, "merged/dir", AT_REMOVEDIR) = -1 EPERM (Operation not
      permitted)
      
      Interestingly, if you don't place files in merged/dir you can remove it,
      meaning if upper/dir does not exist, creating the char device file works
      properly in that same location.
      
      This patch uses ovl_sb_creator_cred() to get the cred struct from the
      superblock mounter and override the old cred with these new ones so that
      the whiteout creation is possible because overlay is wrong in assuming that
      the creds it will get with prepare_creds will be in the initial user
      namespace.  The old cap_raise game is removed in favor of just overriding
      the old cred struct.
      
      This patch also drops from ovl_copy_up_one() the following two lines:
      
      override_cred->fsuid = stat->uid;
      override_cred->fsgid = stat->gid;
      
      This is because the correct uid and gid are taken directly with the stat
      struct and correctly set with ovl_set_attr().
      Signed-off-by: NAntonio Murdaca <runcom@redhat.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      3fe6e52f
  8. 26 5月, 2016 1 次提交
  9. 03 5月, 2016 1 次提交
  10. 22 3月, 2016 2 次提交
    • M
      ovl: rename is_merge to is_lowest · 56656e96
      Miklos Szeredi 提交于
      The 'is_merge' is an historical naming from when only a single lower layer
      could exist.  With the introduction of multiple lower layers the meaning of
      this flag was changed to mean only the "lowest layer" (while all lower
      layers were being merged).
      
      So now 'is_merge' is inaccurate and hence renaming to 'is_lowest'
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      56656e96
    • V
      ovl: Ensure upper filesystem supports d_type · 45aebeaf
      Vivek Goyal 提交于
      In some instances xfs has been created with ftype=0 and there if a file
      on lower fs is removed, overlay leaves a whiteout in upper fs but that
      whiteout does not get filtered out and is visible to overlayfs users.
      
      And reason it does not get filtered out because upper filesystem does
      not report file type of whiteout as DT_CHR during iterate_dir().
      
      So it seems to be a requirement that upper filesystem support d_type for
      overlayfs to work properly. Do this check during mount and fail if d_type
      is not supported.
      Suggested-by: NDave Chinner <dchinner@redhat.com>
      Signed-off-by: NVivek Goyal <vgoyal@redhat.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      45aebeaf
  11. 23 1月, 2016 1 次提交
    • A
      wrappers for ->i_mutex access · 5955102c
      Al Viro 提交于
      parallel to mutex_{lock,unlock,trylock,is_locked,lock_nested},
      inode_foo(inode) being mutex_foo(&inode->i_mutex).
      
      Please, use those for access to ->i_mutex; over the coming cycle
      ->i_mutex will become rwsem, with ->lookup() done with it held
      only shared.
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      5955102c
  12. 11 12月, 2015 1 次提交
    • K
      ovl: check dentry positiveness in ovl_cleanup_whiteouts() · 84889d49
      Konstantin Khlebnikov 提交于
      This patch fixes kernel crash at removing directory which contains
      whiteouts from lower layers.
      
      Cache of directory content passed as "list" contains entries from all
      layers, including whiteouts from lower layers. So, lookup in upper dir
      (moved into work at this stage) will return negative entry. Plus this
      cache is filled long before and we can race with external removal.
      
      Example:
       mkdir -p lower0/dir lower1/dir upper work overlay
       touch lower0/dir/a lower0/dir/b
       mknod lower1/dir/a c 0 0
       mount -t overlay none overlay -o lowerdir=lower1:lower0,upperdir=upper,workdir=work
       rm -fr overlay/dir
      Signed-off-by: NKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
      Signed-off-by: NMiklos Szeredi <miklos@szeredi.hu>
      Cc: <stable@vger.kernel.org> # 3.18+
      84889d49
  13. 22 6月, 2015 1 次提交
    • M
      ovl: lookup whiteouts outside iterate_dir() · cdb67279
      Miklos Szeredi 提交于
      If jffs2 can deadlock on overlayfs readdir because it takes the same lock
      on ->iterate() as in ->lookup().
      
      Fix by moving whiteout checking outside iterate_dir().  Optimized by
      collecting potential whiteouts (DT_CHR) in a temporary list and if
      non-empty iterating throug these and checking for a 0/0 chardev.
      Signed-off-by: NMiklos Szeredi <mszeredi@suse.cz>
      Fixes: 49c21e1c ("ovl: check whiteout while reading directory")
      Reported-by: Roman Yeryomin <leroi.lists@gmail.com> 
      cdb67279
  14. 09 1月, 2015 1 次提交
  15. 13 12月, 2014 4 次提交
  16. 20 11月, 2014 2 次提交
  17. 05 11月, 2014 1 次提交
  18. 01 11月, 2014 2 次提交
  19. 29 10月, 2014 3 次提交
  20. 25 10月, 2014 4 次提交
  21. 24 10月, 2014 1 次提交
    • M
      overlay filesystem · e9be9d5e
      Miklos Szeredi 提交于
      Overlayfs allows one, usually read-write, directory tree to be
      overlaid onto another, read-only directory tree.  All modifications
      go to the upper, writable layer.
      
      This type of mechanism is most often used for live CDs but there's a
      wide variety of other uses.
      
      The implementation differs from other "union filesystem"
      implementations in that after a file is opened all operations go
      directly to the underlying, lower or upper, filesystems.  This
      simplifies the implementation and allows native performance in these
      cases.
      
      The dentry tree is duplicated from the underlying filesystems, this
      enables fast cached lookups without adding special support into the
      VFS.  This uses slightly more memory than union mounts, but dentries
      are relatively small.
      
      Currently inodes are duplicated as well, but it is a possible
      optimization to share inodes for non-directories.
      
      Opening non directories results in the open forwarded to the
      underlying filesystem.  This makes the behavior very similar to union
      mounts (with the same limitations vs. fchmod/fchown on O_RDONLY file
      descriptors).
      
      Usage:
      
        mount -t overlayfs overlayfs -olowerdir=/lower,upperdir=/upper/upper,workdir=/upper/work /overlay
      
      The following cotributions have been folded into this patch:
      
      Neil Brown <neilb@suse.de>:
       - minimal remount support
       - use correct seek function for directories
       - initialise is_real before use
       - rename ovl_fill_cache to ovl_dir_read
      
      Felix Fietkau <nbd@openwrt.org>:
       - fix a deadlock in ovl_dir_read_merged
       - fix a deadlock in ovl_remove_whiteouts
      
      Erez Zadok <ezk@fsl.cs.sunysb.edu>
       - fix cleanup after WARN_ON
      
      Sedat Dilek <sedat.dilek@googlemail.com>
       - fix up permission to confirm to new API
      
      Robin Dong <hao.bigrat@gmail.com>
       - fix possible leak in ovl_new_inode
       - create new inode in ovl_link
      
      Andy Whitcroft <apw@canonical.com>
       - switch to __inode_permission()
       - copy up i_uid/i_gid from the underlying inode
      
      AV:
       - ovl_copy_up_locked() - dput(ERR_PTR(...)) on two failure exits
       - ovl_clear_empty() - one failure exit forgetting to do unlock_rename(),
         lack of check for udir being the parent of upper, dropping and regaining
         the lock on udir (which would require _another_ check for parent being
         right).
       - bogus d_drop() in copyup and rename [fix from your mail]
       - copyup/remove and copyup/rename races [fix from your mail]
       - ovl_dir_fsync() leaving ERR_PTR() in ->realfile
       - ovl_entry_free() is pointless - it's just a kfree_rcu()
       - fold ovl_do_lookup() into ovl_lookup()
       - manually assigning ->d_op is wrong.  Just use ->s_d_op.
       [patches picked from Miklos]:
       * copyup/remove and copyup/rename races
       * bogus d_drop() in copyup and rename
      
      Also thanks to the following people for testing and reporting bugs:
      
        Jordi Pujol <jordipujolp@gmail.com>
        Andy Whitcroft <apw@canonical.com>
        Michal Suchanek <hramrach@centrum.cz>
        Felix Fietkau <nbd@openwrt.org>
        Erez Zadok <ezk@fsl.cs.sunysb.edu>
        Randy Dunlap <rdunlap@xenotime.net>
      Signed-off-by: NMiklos Szeredi <mszeredi@suse.cz>
      e9be9d5e