1. 24 1月, 2018 8 次提交
    • A
      ovl: factor out ovl_get_index_fh() helper · 91ffe7be
      Amir Goldstein 提交于
      The helper is needed to lookup an index by file handle for NFS export.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      91ffe7be
    • A
      ovl: whiteout index when union nlink drops to zero · e7dd0e71
      Amir Goldstein 提交于
      With NFS export feature enabled, when overlay inode nlink drops to
      zero, instead of removing the index entry, replace it with a whiteout
      index entry.
      
      This is needed for NFS export in order to prevent future open by handle
      from opening the lower file directly.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      e7dd0e71
    • A
      ovl: create ovl_need_index() helper · 24b33ee1
      Amir Goldstein 提交于
      The helper determines which lower file needs to be indexed
      on copy up and before nlink changes.
      
      For index=on, the helper evaluates to true for lower hardlinks.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      24b33ee1
    • A
      ovl: use directory index entries for consistency verification · ad1d615c
      Amir Goldstein 提交于
      A directory index is a directory type entry in index dir with a
      "trusted.overlay.upper" xattr containing an encoded ovl_fh of the merge
      directory upper dir inode.
      
      On lookup of non-dir files, lower file is followed by origin file handle.
      On lookup of dir entries, lower dir is found by name and then compared
      to origin file handle. We only trust dir index if we verified that lower
      dir matches origin file handle, otherwise index may be inconsistent and
      we ignore it.
      
      If we find an indexed non-upper dir or an indexed merged dir, whose
      index 'upper' xattr points to a different upper dir, that means that the
      lower directory may be also referenced by another upper dir via redirect,
      so we fail the lookup on inconsistency error.
      
      To be consistent with directory index entries format, the association of
      index dir to upper root dir, that was stored by older kernels in
      "trusted.overlay.origin" xattr is now stored in "trusted.overlay.upper"
      xattr. This also serves as an indication that overlay was mounted with a
      kernel that support index directory entries. For backward compatibility,
      if an 'origin' xattr exists on the index dir we also verify it on mount.
      
      Directory index entries are going to be used for NFS export.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      ad1d615c
    • A
      ovl: add support for "nfs_export" configuration · f168f109
      Amir Goldstein 提交于
      Introduce the "nfs_export" config, module and mount options.
      
      The NFS export feature depends on the "index" feature and enables two
      implicit overlayfs features: "index_all" and "verify_lower".
      The "index_all" feature creates an index on copy up of every file and
      directory. The "verify_lower" feature uses the full index to detect
      overlay filesystems inconsistencies on lookup, like redirect from
      multiple upper dirs to the same lower dir.
      
      NFS export can be enabled for non-upper mount with no index. However,
      because lower layer redirects cannot be verified with the index, enabling
      NFS export support on an overlay with no upper layer requires turning off
      redirect follow (e.g. "redirect_dir=nofollow").
      
      The full index may incur some overhead on mount time, especially when
      verifying that lower directory file handles are not stale.
      
      NFS export support, full index and consistency verification will be
      implemented by following patches.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      f168f109
    • A
      ovl: generalize ovl_verify_origin() and helpers · 05122443
      Amir Goldstein 提交于
      Remove the "origin" language from the functions that handle set, get
      and verify of "origin" xattr and pass the xattr name as an argument.
      
      The same helpers are going to be used for NFS export to get, get and
      verify the "upper" xattr for directory index entries.
      
      ovl_verify_origin() is now a helper used only to verify non upper
      file handle stored in "origin" xattr of upper inode.
      
      The upper root dir file handle is still stored in "origin" xattr on
      the index dir for backward compatibility. This is going to be changed
      by the patch that adds directory index entries support.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      05122443
    • A
      ovl: simplify arguments to ovl_check_origin_fh() · 1eff1a1d
      Amir Goldstein 提交于
      Pass the fs instance with lower_layers array instead of the dentry
      lowerstack array to ovl_check_origin_fh(), because the dentry members
      of lowerstack play no role in this helper.
      
      This change simplifies the argument list of ovl_check_origin(),
      ovl_cleanup_index() and ovl_verify_index().
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      1eff1a1d
    • A
      ovl: fix inconsistent d_ino for legacy merge dir · 9678e630
      Amir Goldstein 提交于
      For a merge dir that was copied up before v4.12 or that was hand crafted
      offline (e.g. mkdir {upper/lower}/dir), upper dir does not contain the
      'trusted.overlay.origin' xattr.  In that case, stat(2) on the merge dir
      returns the lower dir st_ino, but getdents(2) returns the upper dir d_ino.
      
      After this change, on merge dir lookup, missing origin xattr on upper
      dir will be fixed and 'impure' xattr will be fixed on parent of the legacy
      merge dir.
      Suggested-by: Nzhangyi (F) <yi.zhang@huawei.com>
      Reviewed-by: Nzhangyi (F) <yi.zhang@huawei.com>
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      9678e630
  2. 11 12月, 2017 1 次提交
  3. 10 11月, 2017 1 次提交
  4. 09 11月, 2017 3 次提交
    • C
      ovl: re-structure overlay lower layers in-memory · b9343632
      Chandan Rajendra 提交于
      Define new structures to represent overlay instance lower layers and
      overlay merge dir lower layers to make room for storing more per layer
      information in-memory.
      
      Instead of keeping the fs instance lower layers in an array of struct
      vfsmount, keep them in an array of new struct ovl_layer, that has a
      pointer to struct vfsmount.
      
      Instead of keeping the dentry lower layers in an array of struct path,
      keep them in an array of new struct ovl_path, that has a pointer to
      struct dentry and to struct ovl_layer.
      
      Add a small helper to find the fs layer id that correspopnds to a lower
      struct ovl_path and use it in ovl_lookup().
      
      [amir: split re-structure from anonymous bdev patch]
      Signed-off-by: NChandan Rajendra <chandan@linux.vnet.ibm.com>
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      b9343632
    • A
      ovl: move include of ovl_entry.h into overlayfs.h · ee023c30
      Amir Goldstein 提交于
      Most overlayfs c files already explicitly include ovl_entry.h
      to use overlay entry struct definitions and upcoming changes
      are going to require even more c files to include this header.
      
      All overlayfs c files include overlayfs.h and overlayfs.h itself
      refers to some structs defined in ovl_entry.h, so it seems more
      logic to include ovl_entry.h from overlayfs.h than from c files.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      ee023c30
    • A
      ovl: no direct iteration for dir with origin xattr · b79e05aa
      Amir Goldstein 提交于
      If a non-merge dir in an overlay mount has an overlay.origin xattr, it
      means it was once an upper merge dir, which may contain whiteouts and
      then the lower dir was removed under it.
      
      Do not iterate real dir directly in this case to avoid exposing whiteouts.
      
      [SzM] Set OVL_WHITEOUT for all merge directories as well.
      
      [amir] A directory that was just copied up does not have the OVL_WHITEOUTS
      flag. We need to set it to fix merge dir iteration.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      b79e05aa
  5. 24 10月, 2017 1 次提交
    • A
      ovl: fix EIO from lookup of non-indexed upper · 6eaf0111
      Amir Goldstein 提交于
      Commit fbaf94ee ("ovl: don't set origin on broken lower hardlink")
      attempt to avoid the condition of non-indexed upper inode with lower
      hardlink as origin. If this condition is found, lookup returns EIO.
      
      The protection of commit mentioned above does not cover the case of lower
      that is not a hardlink when it is copied up (with either index=off/on)
      and then lower is hardlinked while overlay is offline.
      
      Changes to lower layer while overlayfs is offline should not result in
      unexpected behavior, so a permanent EIO error after creating a link in
      lower layer should not be considered as correct behavior.
      
      This fix replaces EIO error with success in cases where upper has origin
      but no index is found, or index is found that does not match upper
      inode. In those cases, lookup will not fail and the returned overlay inode
      will be hashed by upper inode instead of by lower origin inode.
      
      Fixes: 359f392c ("ovl: lookup index entry for copy up origin")
      Cc: <stable@vger.kernel.org> # v4.13
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      6eaf0111
  6. 05 10月, 2017 1 次提交
  7. 28 7月, 2017 1 次提交
    • 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
  8. 20 7月, 2017 1 次提交
  9. 14 7月, 2017 1 次提交
  10. 05 7月, 2017 13 次提交
    • A
      ovl: cleanup orphan index entries · caf70cb2
      Amir Goldstein 提交于
      index entry should live only as long as there are upper or lower
      hardlinks.
      
      Cleanup orphan index entries on mount and when dropping the last
      overlay inode nlink.
      
      When about to cleanup or link up to orphan index and the index inode
      nlink > 1, admit that something went wrong and adjust overlay nlink
      to index inode nlink - 1 to prevent it from dropping below zero.
      This could happen when adding lower hardlinks underneath a mounted
      overlay and then trying to unlink them.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      caf70cb2
    • A
      ovl: persistent overlay inode nlink for indexed inodes · 5f8415d6
      Amir Goldstein 提交于
      With inodes index enabled, an overlay inode nlink counts the union of upper
      and non-covered lower hardlinks. During the lifetime of a non-pure upper
      inode, the following nlink modifying operations can happen:
      
      1. Lower hardlink copy up
      2. Upper hardlink created, unlinked or renamed over
      3. Lower hardlink whiteout or renamed over
      
      For the first, copy up case, the union nlink does not change, whether the
      operation succeeds or fails, but the upper inode nlink may change.
      Therefore, before copy up, we store the union nlink value relative to the
      lower inode nlink in the index inode xattr trusted.overlay.nlink.
      
      For the second, upper hardlink case, the union nlink should be incremented
      or decremented IFF the operation succeeds, aligned with nlink change of the
      upper inode. Therefore, before link/unlink/rename, we store the union nlink
      value relative to the upper inode nlink in the index inode.
      
      For the last, lower cover up case, we simplify things by preceding the
      whiteout or cover up with copy up. This makes sure that there is an index
      upper inode where the nlink xattr can be stored before the copied up upper
      entry is unlink.
      
      Return the overlay inode nlinks for indexed upper inodes on stat(2).
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      5f8415d6
    • M
      ovl: add flag for upper in ovl_entry · 55acc661
      Miklos Szeredi 提交于
      For rename, we need to ensure that an upper alias exists for hard links
      before attempting the operation.  Introduce a flag in ovl_entry to track
      the state of the upper alias.
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      55acc661
    • 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
    • A
      ovl: lookup index entry for copy up origin · 359f392c
      Amir Goldstein 提交于
      When inodes index feature is enabled, lookup in indexdir for the index
      entry of lower real inode or copy up origin inode. The index entry name
      is the hex representation of the lower inode file handle.
      
      If the index dentry in negative, then either no lower aliases have been
      copied up yet, or aliases have been copied up in older kernels and are
      not indexed.
      
      If the index dentry for a copy up origin inode is positive, but points
      to an inode different than the upper inode, then either the upper inode
      has been copied up and not indexed or it was indexed, but since then
      index dir was cleared. Either way, that index cannot be used to indentify
      the overlay inode.
      
      If a positive dentry that matches the upper inode was found, then it is
      safe to use the copy up origin st_ino for upper hardlinks, because all
      indexed upper hardlinks are represented by the same overlay inode as the
      copy up origin.
      
      Set the INDEX type flag on an indexed upper dentry. A non-upper dentry
      may also have a positive index from copy up of another lower hardlink.
      This situation will be handled by following patches.
      
      Index lookup is going to be used to prevent breaking hardlinks on copy up.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      359f392c
    • A
      ovl: verify index dir matches upper dir · 54fb347e
      Amir Goldstein 提交于
      An index dir contains persistent hardlinks to files in upper dir.
      Therefore, we must never mount an existing index dir with a differnt
      upper dir.
      
      Store the upper root dir file handle in index dir inode when index
      dir is created and verify the file handle before using an existing
      index dir on mount.
      
      Add an 'is_upper' flag to the overlay file handle encoding and set it
      when encoding the upper root file handle. This is not critical for index
      dir verification, but it is good practice towards a standard overlayfs
      file handle format for NFS export.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      54fb347e
    • A
      ovl: verify upper root dir matches lower root dir · 8b88a2e6
      Amir Goldstein 提交于
      When inodes index feature is enabled, verify that the file handle stored
      in upper root dir matches the lower root dir or fail to mount.
      
      If upper root dir has no stored file handle, encode and store the lower
      root dir file handle in overlay.origin xattr.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      8b88a2e6
    • A
      ovl: introduce the inodes index dir feature · 02bcd157
      Amir Goldstein 提交于
      Create the index dir on mount. The index dir will contain hardlinks to
      upper inodes, named after the hex representation of their origin lower
      inodes.
      
      The index dir is going to be used to prevent breaking lower hardlinks
      on copy up and to implement overlayfs NFS export.
      
      Because the feature is not fully backward compat, enabling the feature
      is opt-in by config/module/mount option.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      02bcd157
    • A
      vfs: introduce inode 'inuse' lock · ad0af710
      Amir Goldstein 提交于
      Added an i_state flag I_INUSE and helpers to set/clear/test the bit.
      
      The 'inuse' lock is an 'advisory' inode lock, that can be used to extend
      exclusive create protection beyond parent->i_mutex lock among cooperating
      users.
      
      This is going to be used by overlayfs to get exclusive ownership on upper
      and work dirs among overlayfs mounts.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      ad0af710
    • M
      ovl: move impure to ovl_inode · 13c72075
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      13c72075
    • M
      ovl: move __upperdentry to ovl_inode · 09d8b586
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      09d8b586
    • M
      ovl: use i_private only as a key · 25b7713a
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      25b7713a
    • M
      ovl: simplify getting inode · e6d2ebdd
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      e6d2ebdd
  11. 05 6月, 2017 1 次提交
  12. 29 5月, 2017 1 次提交
    • A
      ovl: mark upper merge dir with type origin entries "impure" · f3a15685
      Amir Goldstein 提交于
      An upper dir is marked "impure" to let ovl_iterate() know that this
      directory may contain non pure upper entries whose d_ino may need to be
      read from the origin inode.
      
      We already mark a non-merge dir "impure" when moving a non-pure child
      entry inside it, to let ovl_iterate() know not to iterate the non-merge
      dir directly.
      
      Mark also a merge dir "impure" when moving a non-pure child entry inside
      it and when copying up a child entry inside it.
      
      This can be used to optimize ovl_iterate() to perform a "pure merge" of
      upper and lower directories, merging the content of the directories,
      without having to read d_ino from origin inodes.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      f3a15685
  13. 19 5月, 2017 3 次提交
  14. 18 5月, 2017 1 次提交
  15. 05 5月, 2017 3 次提交
    • M
      ovl: merge getattr for dir and nondir · 5b712091
      Miklos Szeredi 提交于
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      5b712091
    • A
      ovl: set the ORIGIN type flag · 59548503
      Amir Goldstein 提交于
      For directory entries, non zero oe->numlower implies OVL_TYPE_MERGE.
      Define a new type flag OVL_TYPE_ORIGIN to indicate that an entry holds a
      reference to its lower copy up origin.
      
      For directory entries ORIGIN := MERGE && UPPER. For non-dir entries ORIGIN
      means that a lower type dentry has been recently copied up or that we were
      able to find the copy up origin from overlay.origin xattr.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      59548503
    • A
      ovl: store file handle of lower inode on copy up · 3a1e819b
      Amir Goldstein 提交于
      Sometimes it is interesting to know if an upper file is pure upper or a
      copy up target, and if it is a copy up target, it may be interesting to
      find the copy up origin.
      
      This will be used to preserve lower inode numbers across copy up.
      
      Store the lower inode file handle in upper inode extended attribute
      overlay.origin on copy up to use it later for these cases.  Store the lower
      filesystem uuid along side the file handle, so we can validate that we are
      looking for the origin file in the original fs.
      
      If lower fs does not support NFS export ops store a zero sized xattr so we
      can always use the overlay.origin xattr to distinguish between a copy up
      and a pure upper inode.
      Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
      Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
      3a1e819b