1. 12 2月, 2022 1 次提交
    • B
      gfs2: Fix gfs2_release for non-writers regression · d3add1a9
      Bob Peterson 提交于
      When a file is opened for writing, the vfs code (do_dentry_open)
      calls get_write_access for the inode, thus incrementing the inode's write
      count. That writer normally then creates a multi-block reservation for
      the inode (i_res) that can be re-used by other writers, which speeds up
      writes for applications that stupidly loop on open/write/close.
      When the writes are all done, the multi-block reservation should be
      deleted when the file is closed by the last "writer."
      
      Commit 0ec9b9ea broke that concept when it moved the call to
      gfs2_rs_delete before the check for FMODE_WRITE.  Non-writers have no
      business removing the multi-block reservations of writers. In fact, if
      someone opens and closes the file for RO while a writer has a
      multi-block reservation, the RO closer will delete the reservation
      midway through the write, and this results in:
      
      kernel BUG at fs/gfs2/rgrp.c:677! (or thereabouts) which is:
      BUG_ON(rs->rs_requested); from function gfs2_rs_deltree.
      
      This patch moves the check back inside the check for FMODE_WRITE.
      
      Fixes: 0ec9b9ea ("gfs2: Check for active reservation in gfs2_release")
      Cc: stable@vger.kernel.org # v5.12+
      Signed-off-by: NBob Peterson <rpeterso@redhat.com>
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      d3add1a9
  2. 11 11月, 2021 1 次提交
    • A
      gfs2: Prevent endless loops in gfs2_file_buffered_write · 554c577c
      Andreas Gruenbacher 提交于
      Currently, instead of performing a short write,
      iomap_file_buffered_write will fail when part of its iov iterator cannot
      be read.  In contrast, gfs2_file_buffered_write will loop around if it
      can read part of the iov iterator, so we can end up in an endless loop.
      
      This should be fixed in iomap_file_buffered_write (and also
      generic_perform_write), but this comes a bit late in the 5.16
      development cycle, so work around it in the filesystem by
      trimming the iov iterator to the known-good size for now.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      554c577c
  3. 03 11月, 2021 1 次提交
  4. 25 10月, 2021 3 次提交
    • T
      gfs2: Fix unused value warning in do_gfs2_set_flags() · e34e6f81
      Tim Gardner 提交于
      Coverity complains of an unused value:
      
      CID 119623 (#1 of 1): Unused value (UNUSED_VALUE)
      assigned_value: Assigning value -1 to error here, but that stored value is
      overwritten before it can be used.
      237        error = -EPERM;
      
      Fix it by removing the assignment.
      Signed-off-by: NTim Gardner <tim.gardner@canonical.com>
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      e34e6f81
    • B
      gfs2: Allow append and immutable bits to coexist · a500bd31
      Bob Peterson 提交于
      Before this patch, function do_gfs2_set_flags checked if the append
      and immutable flags were being set while already set. If so, error -EPERM
      was given. There's no reason why these two flags should be mutually
      exclusive, and if you set them separately, you will, in essence, set
      one while it is already set. For example:
      
      chattr +a /mnt/gfs2/file1
      chattr +i /mnt/gfs2/file1
      
      The first command sets the append-only flag. Since they are additive,
      the second command sets the immutable flag AND append-only flag,
      since they both coexist in i_diskflags. So the second command should
      not return an error. This bug caused xfstests generic/545 to fail.
      
      This patch simply removes the invalid checks.
      I also eliminated an unused parm from do_gfs2_set_flags.
      Signed-off-by: NBob Peterson <rpeterso@redhat.com>
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      a500bd31
    • A
      gfs2: Fix mmap + page fault deadlocks for direct I/O · b01b2d72
      Andreas Gruenbacher 提交于
      Also disable page faults during direct I/O requests and implement a
      similar kind of retry logic as in the buffered I/O case.
      
      The retry logic in the direct I/O case differs from the buffered I/O
      case in the following way: direct I/O doesn't provide the kinds of
      consistency guarantees between concurrent reads and writes that buffered
      I/O provides, so once we lose the inode glock while faulting in user
      pages, we always resume the operation.  We never need to return a
      partial read or write.
      
      This locking problem was originally reported by Jan Kara.  Linus came up
      with the idea of disabling page faults.  Many thanks to Al Viro and
      Matthew Wilcox for their feedback.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      b01b2d72
  5. 24 10月, 2021 2 次提交
    • A
      iomap: Add done_before argument to iomap_dio_rw · 4fdccaa0
      Andreas Gruenbacher 提交于
      Add a done_before argument to iomap_dio_rw that indicates how much of
      the request has already been transferred.  When the request succeeds, we
      report that done_before additional bytes were tranferred.  This is
      useful for finishing a request asynchronously when part of the request
      has already been completed synchronously.
      
      We'll use that to allow iomap_dio_rw to be used with page faults
      disabled: when a page fault occurs while submitting a request, we
      synchronously complete the part of the request that has already been
      submitted.  The caller can then take care of the page fault and call
      iomap_dio_rw again for the rest of the request, passing in the number of
      bytes already tranferred.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      Reviewed-by: NDarrick J. Wong <djwong@kernel.org>
      4fdccaa0
    • A
      gfs2: Fix mmap + page fault deadlocks for buffered I/O · 00bfe02f
      Andreas Gruenbacher 提交于
      In the .read_iter and .write_iter file operations, we're accessing
      user-space memory while holding the inode glock.  There is a possibility
      that the memory is mapped to the same file, in which case we'd recurse
      on the same glock.
      
      We could detect and work around this simple case of recursive locking,
      but more complex scenarios exist that involve multiple glocks,
      processes, and cluster nodes, and working around all of those cases
      isn't practical or even possible.
      
      Avoid these kinds of problems by disabling page faults while holding the
      inode glock.  If a page fault would occur, we either end up with a
      partial read or write or with -EFAULT if nothing could be read or
      written.  In either case, we know that we're not done with the
      operation, so we indicate that we're willing to give up the inode glock
      and then we fault in the missing pages.  If that made us lose the inode
      glock, we return a partial read or write.  Otherwise, we resume the
      operation.
      
      This locking problem was originally reported by Jan Kara.  Linus came up
      with the idea of disabling page faults.  Many thanks to Al Viro and
      Matthew Wilcox for their feedback.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      00bfe02f
  6. 21 10月, 2021 3 次提交
    • A
      gfs2: Eliminate ip->i_gh · 1b223f70
      Andreas Gruenbacher 提交于
      Now that gfs2_file_buffered_write is the only remaining user of
      ip->i_gh, we can move the glock holder to the stack (or rather, use the
      one we already have on the stack); there is no need for keeping the
      holder in the inode anymore.
      
      This is slightly complicated by the fact that we're using ip->i_gh for
      the statfs inode in gfs2_file_buffered_write as well.  Writing to the
      statfs inode isn't very common, so allocate the statfs holder
      dynamically when needed.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      1b223f70
    • A
      gfs2: Move the inode glock locking to gfs2_file_buffered_write · b924bdab
      Andreas Gruenbacher 提交于
      So far, for buffered writes, we were taking the inode glock in
      gfs2_iomap_begin and dropping it in gfs2_iomap_end with the intention of
      not holding the inode glock while iomap_write_actor faults in user
      pages.  It turns out that iomap_write_actor is called inside iomap_begin
      ... iomap_end, so the user pages were still faulted in while holding the
      inode glock and the locking code in iomap_begin / iomap_end was
      completely pointless.
      
      Move the locking into gfs2_file_buffered_write instead.  We'll take care
      of the potential deadlocks due to faulting in user pages while holding a
      glock in a subsequent patch.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      b924bdab
    • A
      gfs2: Add wrapper for iomap_file_buffered_write · 2eb7509a
      Andreas Gruenbacher 提交于
      Add a wrapper around iomap_file_buffered_write.  We'll add code for when
      the operation needs to be retried here later.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      2eb7509a
  7. 18 10月, 2021 1 次提交
  8. 11 9月, 2021 1 次提交
    • J
      locks: remove LOCK_MAND flock lock support · 90f7d7a0
      Jeff Layton 提交于
      As best I can tell, the logic for these has been broken for a long time
      (at least before the move to git), such that they never conflict with
      anything. Also, nothing checks for these flags and prevented opens or
      read/write behavior on the files. They don't seem to do anything.
      
      Given that, we can rip these symbols out of the kernel, and just make
      flock(2) return 0 when LOCK_MAND is set in order to preserve existing
      behavior.
      
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: Stephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: NJeff Layton <jlayton@kernel.org>
      90f7d7a0
  9. 23 8月, 2021 1 次提交
    • J
      fs: remove mandatory file locking support · f7e33bdb
      Jeff Layton 提交于
      We added CONFIG_MANDATORY_FILE_LOCKING in 2015, and soon after turned it
      off in Fedora and RHEL8. Several other distros have followed suit.
      
      I've heard of one problem in all that time: Someone migrated from an
      older distro that supported "-o mand" to one that didn't, and the host
      had a fstab entry with "mand" in it which broke on reboot. They didn't
      actually _use_ mandatory locking so they just removed the mount option
      and moved on.
      
      This patch rips out mandatory locking support wholesale from the kernel,
      along with the Kconfig option and the Documentation file. It also
      changes the mount code to ignore the "mand" mount option instead of
      erroring out, and to throw a big, ugly warning.
      Signed-off-by: NJeff Layton <jlayton@kernel.org>
      f7e33bdb
  10. 29 6月, 2021 3 次提交
  11. 28 6月, 2021 2 次提交
  12. 02 6月, 2021 1 次提交
  13. 21 5月, 2021 1 次提交
  14. 20 5月, 2021 1 次提交
  15. 12 4月, 2021 1 次提交
  16. 10 4月, 2021 1 次提交
  17. 04 4月, 2021 1 次提交
  18. 18 2月, 2021 2 次提交
    • A
      gfs2: Add per-reservation reserved block accounting · 725d0e9d
      Andreas Gruenbacher 提交于
      Add a rs_reserved field to struct gfs2_blkreserv to keep track of the number of
      blocks reserved by this particular reservation, and a rd_reserved field to
      struct gfs2_rgrpd to keep track of the total number of reserved blocks in the
      resource group.  Those blocks are exclusively reserved, as opposed to the
      rs_requested / rd_requested blocks which are tracked in the reservation tree
      (rd_rstree) and which can be stolen if necessary.
      
      When making a reservation with gfs2_inplace_reserve, rs_reserved is set to
      somewhere between ap->min_target and ap->target depending on the number of free
      blocks in the resource group.  When allocating blocks with gfs2_alloc_blocks,
      rs_reserved is decremented accordingly.  Eventually, any reserved but not
      consumed blocks are returned to the resource group by gfs2_inplace_release.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      725d0e9d
    • A
      gfs2: Check for active reservation in gfs2_release · 0ec9b9ea
      Andreas Gruenbacher 提交于
      In gfs2_release, check if the inode has an active reservation to avoid
      unnecessary lock taking.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      0ec9b9ea
  19. 24 1月, 2021 3 次提交
  20. 14 1月, 2021 1 次提交
  21. 06 8月, 2020 1 次提交
  22. 03 8月, 2020 1 次提交
  23. 08 7月, 2020 1 次提交
    • A
      gfs2: Rework read and page fault locking · 20f82999
      Andreas Gruenbacher 提交于
      So far, gfs2 has taken the inode glocks inside the ->readpage and
      ->readahead address space operations.  Since commit d4388340 ("fs:
      convert mpage_readpages to mpage_readahead"), gfs2_readahead is passed
      the pages to read ahead locked.  With that, the current holder of the
      inode glock may be trying to lock one of those pages while
      gfs2_readahead is trying to take the inode glock, resulting in a
      deadlock.
      
      Fix that by moving the lock taking to the higher-level ->read_iter file
      and ->fault vm operations.  This also gets rid of an ugly lock inversion
      workaround in gfs2_readpage.
      
      The cache consistency model of filesystems like gfs2 is such that if
      data is found in the page cache, the data is up to date and can be used
      without taking any filesystem locks.  If a page is not cached,
      filesystem locks must be taken before populating the page cache.
      
      To avoid taking the inode glock when the data is already cached,
      gfs2_file_read_iter first tries to read the data with the IOCB_NOIO flag
      set.  If that fails, the inode glock is taken and the operation is
      retried with the IOCB_NOIO flag cleared.
      Signed-off-by: NAndreas Gruenbacher <agruenba@redhat.com>
      20f82999
  24. 28 3月, 2020 4 次提交
  25. 07 2月, 2020 2 次提交