1. 18 4月, 2017 3 次提交
    • G
      btrfs: qgroups: Retry after commit on getting EDQUOT · 48a89bc4
      Goldwyn Rodrigues 提交于
      We are facing the same problem with EDQUOT which was experienced with
      ENOSPC. Not sure if we require a full ticketing system such as ENOSPC, but
      here is a quick fix, which may be too big a hammer.
      
      Quotas are reserved during the start of an operation, incrementing
      qg->reserved. However, it is written to disk in a commit_transaction
      which could take as long as commit_interval. In the meantime there
      could be deletions which are not accounted for because deletions are
      accounted for only while committed (free_refroot). So, when we get
      a EDQUOT flush the data to disk and try again.
      
      This fixes fstests btrfs/139.
      
      Here is a sample script which shows this issue.
      
      DEVICE=/dev/vdb
      MOUNTPOINT=/mnt
      TESTVOL=$MOUNTPOINT/tmp
      QUOTA=5
      PROG=btrfs
      DD_BS="4k"
      DD_COUNT="256"
      RUN_TIMES=5000
      
      mkfs.btrfs -f $DEVICE
      mount -o commit=240 $DEVICE $MOUNTPOINT
      $PROG subvolume create $TESTVOL
      $PROG quota enable $TESTVOL
      $PROG qgroup limit ${QUOTA}G $TESTVOL
      
      typeset -i DD_RUN_GOOD
      typeset -i QUOTA
      
      function _check_cmd() {
              if [[ ${?} > 0 ]]; then
                      echo -n "$(date) E: Running previous command"
                      echo ${*}
                      echo "Without sync"
                      $PROG qgroup show -pcreFf ${TESTVOL}
                      echo "With sync"
                      $PROG qgroup show -pcreFf --sync ${TESTVOL}
                      exit 1
              fi
      }
      
      while true; do
        DD_RUN_GOOD=$RUN_TIMES
      
        while (( ${DD_RUN_GOOD} != 0 )); do
              dd if=/dev/zero of=${TESTVOL}/quotatest${DD_RUN_GOOD} bs=${DD_BS} count=${DD_COUNT}
              _check_cmd "dd if=/dev/zero of=${TESTVOL}/quotatest${DD_RUN_GOOD} bs=${DD_BS} count=${DD_COUNT}"
              DD_RUN_GOOD=(${DD_RUN_GOOD}-1)
        done
      
        $PROG qgroup show -pcref $TESTVOL
        echo "----------- Cleanup ---------- "
        rm $TESTVOL/quotatest*
      
      done
      Signed-off-by: NGoldwyn Rodrigues <rgoldwyn@suse.com>
      Reviewed-by: NQu Wenruo <quwenruo@cn.fujitsu.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      48a89bc4
    • E
      btrfs: replace hardcoded value with SEQ_LAST macro · de47c9d3
      Edmund Nadolski 提交于
      Define the SEQ_LAST macro to replace (u64)-1 in places where said
      value triggers a special-case ref search behavior.
      Signed-off-by: NEdmund Nadolski <enadolski@suse.com>
      Reviewed-by: NJeff Mahoney <jeffm@suse.com>
      Reviewed-by: NQu Wenruo <quwenruo@cn.fujitsu.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      de47c9d3
    • D
      btrfs: remove unused qgroup members from btrfs_trans_handle · f486135e
      David Sterba 提交于
      The members have been effectively unused since "Btrfs: rework qgroup
      accounting" (fcebe456), there's no substitute for
      assert_qgroups_uptodate so it's removed as well.
      Reviewed-by: NQu Wenruo <quwenruo@cn.fujitsu.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      f486135e
  2. 29 3月, 2017 1 次提交
    • G
      btrfs: Change qgroup_meta_rsv to 64bit · ce0dcee6
      Goldwyn Rodrigues 提交于
      Using an int value is causing qg->reserved to become negative and
      exclusive -EDQUOT to be reached prematurely.
      
      This affects exclusive qgroups only.
      
      TEST CASE:
      
      DEVICE=/dev/vdb
      MOUNTPOINT=/mnt
      SUBVOL=$MOUNTPOINT/tmp
      
      umount $SUBVOL
      umount $MOUNTPOINT
      
      mkfs.btrfs -f $DEVICE
      mount /dev/vdb $MOUNTPOINT
      btrfs quota enable $MOUNTPOINT
      btrfs subvol create $SUBVOL
      umount $MOUNTPOINT
      mount /dev/vdb $MOUNTPOINT
      mount -o subvol=tmp $DEVICE $SUBVOL
      btrfs qgroup limit -e 3G $SUBVOL
      
      btrfs quota rescan /mnt -w
      
      for i in `seq 1 44000`; do
        dd if=/dev/zero of=/mnt/tmp/test_$i bs=10k count=1
        if [[ $? > 0 ]]; then
           btrfs qgroup show -pcref $SUBVOL
           exit 1
        fi
      done
      Signed-off-by: NGoldwyn Rodrigues <rgoldwyn@suse.com>
      [ add reproducer to changelog ]
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      ce0dcee6
  3. 17 2月, 2017 12 次提交
  4. 14 2月, 2017 2 次提交
    • J
      btrfs: allow unlink to exceed subvolume quota · 003d7c59
      Jeff Mahoney 提交于
      Once a qgroup limit is exceeded, it's impossible to restore normal
      operation to the subvolume without modifying the limit or removing
      the subvolume.  This is a surprising situation for many users used
      to the typical workflow with quotas on other file systems where it's
      possible to remove files until the used space is back under the limit.
      
      When we go to unlink a file and start the transaction, we'll hit
      the qgroup limit while trying to reserve space for the items we'll
      modify while removing the file.  We discussed last month how best
      to handle this situation and agreed that there is no perfect solution.
      The best principle-of-least-surprise solution is to handle it similarly
      to how we already handle ENOSPC when unlinking, which is to allow
      the operation to succeed with the expectation that it will ultimately
      release space under most circumstances.
      
      This patch modifies the transaction start path to select whether to
      honor the qgroups limits.  btrfs_start_transaction_fallback_global_rsv
      is the only caller that skips enforcement.  The reservation and tracking
      still happens normally -- it just skips the enforcement step.
      Signed-off-by: NJeff Mahoney <jeffm@suse.com>
      Reviewed-by: NQu Wenruo <quwenruo@cn.fujitsu.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      003d7c59
    • Q
      btrfs: Add WARN_ON for qgroup reserved underflow · 18dc22c1
      Qu Wenruo 提交于
      Goldwyn Rodrigues has exposed and fixed a bug which underflows btrfs
      qgroup reserved space, and leads to non-writable fs.
      
      This reminds us that we don't have enough underflow check for qgroup
      reserved space.
      
      For underflow case, we should not really underflow the numbers but warn
      and keeps qgroup still work.
      
      So add more check on qgroup reserved space and add WARN_ON() and
      btrfs_warn() for any underflow case.
      Signed-off-by: NQu Wenruo <quwenruo@cn.fujitsu.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Reviewed-by: NGoldwyn Rodrigues <rgoldwyn@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      18dc22c1
  5. 06 12月, 2016 4 次提交
  6. 30 11月, 2016 3 次提交
  7. 26 11月, 2016 1 次提交
    • F
      Btrfs: fix qgroup rescan worker initialization · 8d9eddad
      Filipe Manana 提交于
      We were setting the qgroup_rescan_running flag to true only after the
      rescan worker started (which is a task run by a queue). So if a user
      space task starts a rescan and immediately after asks to wait for the
      rescan worker to finish, this second call might happen before the rescan
      worker task starts running, in which case the rescan wait ioctl returns
      immediatley, not waiting for the rescan worker to finish.
      
      This was making the fstest btrfs/022 fail very often.
      
      Fixes: d2c609b8 (btrfs: properly track when rescan worker is running)
      Cc: stable@vger.kernel.org # 4.4+
      Signed-off-by: NFilipe Manana <fdmanana@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      8d9eddad
  8. 27 9月, 2016 2 次提交
  9. 26 9月, 2016 1 次提交
    • J
      Btrfs: add a flags field to btrfs_fs_info · afcdd129
      Josef Bacik 提交于
      We have a lot of random ints in btrfs_fs_info that can be put into flags.  This
      is mostly equivalent with the exception of how we deal with quota going on or
      off, now instead we set a flag when we are turning it on or off and deal with
      that appropriately, rather than just having a pending state that the current
      quota_enabled gets set to.  Thanks,
      Signed-off-by: NJosef Bacik <jbacik@fb.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      afcdd129
  10. 25 8月, 2016 3 次提交
    • Q
      btrfs: qgroup: Refactor btrfs_qgroup_insert_dirty_extent() · cb93b52c
      Qu Wenruo 提交于
      Refactor btrfs_qgroup_insert_dirty_extent() function, to two functions:
      1. btrfs_qgroup_insert_dirty_extent_nolock()
         Almost the same with original code.
         For delayed_ref usage, which has delayed refs locked.
      
         Change the return value type to int, since caller never needs the
         pointer, but only needs to know if they need to free the allocated
         memory.
      
      2. btrfs_qgroup_insert_dirty_extent()
         The more encapsulated version.
      
         Will do the delayed_refs lock, memory allocation, quota enabled check
         and other things.
      
      The original design is to keep exported functions to minimal, but since
      more btrfs hacks exposed, like replacing path in balance, we need to
      record dirty extents manually, so we have to add such functions.
      
      Also, add comment for both functions, to info developers how to keep
      qgroup correct when doing hacks.
      
      Cc: Mark Fasheh <mfasheh@suse.de>
      Signed-off-by: NQu Wenruo <quwenruo@cn.fujitsu.com>
      Reviewed-and-Tested-by: NGoldwyn Rodrigues <rgoldwyn@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NChris Mason <clm@fb.com>
      cb93b52c
    • J
      btrfs: waiting on qgroup rescan should not always be interruptible · d06f23d6
      Jeff Mahoney 提交于
      We wait on qgroup rescan completion in three places: file system
      shutdown, the quota disable ioctl, and the rescan wait ioctl.  If the
      user sends a signal while we're waiting, we continue happily along.  This
      is expected behavior for the rescan wait ioctl.  It's racy in the shutdown
      path but mostly works due to other unrelated synchronization points.
      In the quota disable path, it Oopses the kernel pretty much immediately.
      
      Cc: <stable@vger.kernel.org> # v4.4+
      Signed-off-by: NJeff Mahoney <jeffm@suse.com>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NChris Mason <clm@fb.com>
      d06f23d6
    • J
      btrfs: properly track when rescan worker is running · d2c609b8
      Jeff Mahoney 提交于
      The qgroup_flags field is overloaded such that it reflects the on-disk
      status of qgroups and the runtime state.  The BTRFS_QGROUP_STATUS_FLAG_RESCAN
      flag is used to indicate that a rescan operation is in progress, but if
      the file system is unmounted while a rescan is running, the rescan
      operation is paused.  If the file system is then mounted read-only,
      the flag will still be present but the rescan operation will not have
      been resumed.  When we go to umount, btrfs_qgroup_wait_for_completion
      will see the flag and interpret it to mean that the rescan worker is
      still running and will wait for a completion that will never come.
      
      This patch uses a separate flag to indicate when the worker is
      running.  The locking and state surrounding the qgroup rescan worker
      needs a lot of attention beyond this patch but this is enough to
      avoid a hung umount.
      
      Cc: <stable@vger.kernel.org> # v4.4+
      Signed-off-by; Jeff Mahoney <jeffm@suse.com>
      Reviewed-by: NQu Wenruo <quwenruo@cn.fujitsu.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NChris Mason <clm@fb.com>
      d2c609b8
  11. 26 7月, 2016 3 次提交
  12. 26 5月, 2016 1 次提交
  13. 29 4月, 2016 2 次提交
  14. 04 4月, 2016 2 次提交
    • M
      btrfs: Add qgroup tracing · 0f5dcf8d
      Mark Fasheh 提交于
      This patch adds tracepoints to the qgroup code on both the reporting side
      (insert_dirty_extents) and the accounting side. Taken together it allows us
      to see what qgroup operations have happened, and what their result was.
      Signed-off-by: NMark Fasheh <mfasheh@suse.de>
      Reviewed-by: NDavid Sterba <dsterba@suse.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      0f5dcf8d
    • M
      btrfs: handle non-fatal errors in btrfs_qgroup_inherit() · 918c2ee1
      Mark Fasheh 提交于
      create_pending_snapshot() will go readonly on _any_ error return from
      btrfs_qgroup_inherit(). If qgroups are enabled, a user can crash their fs by
      just making a snapshot and asking it to inherit from an invalid qgroup. For
      example:
      
      $ btrfs sub snap -i 1/10 /btrfs/ /btrfs/foo
      
      Will cause a transaction abort.
      
      Fix this by only throwing errors in btrfs_qgroup_inherit() when we know
      going readonly is acceptable.
      
      The following xfstests test case reproduces this bug:
      
        seq=`basename $0`
        seqres=$RESULT_DIR/$seq
        echo "QA output created by $seq"
      
        here=`pwd`
        tmp=/tmp/$$
        status=1	# failure is the default!
        trap "_cleanup; exit \$status" 0 1 2 3 15
      
        _cleanup()
        {
        	cd /
        	rm -f $tmp.*
        }
      
        # get standard environment, filters and checks
        . ./common/rc
        . ./common/filter
      
        # remove previous $seqres.full before test
        rm -f $seqres.full
      
        # real QA test starts here
        _supported_fs btrfs
        _supported_os Linux
        _require_scratch
      
        rm -f $seqres.full
      
        _scratch_mkfs
        _scratch_mount
        _run_btrfs_util_prog quota enable $SCRATCH_MNT
        # The qgroup '1/10' does not exist and should be silently ignored
        _run_btrfs_util_prog subvolume snapshot -i 1/10 $SCRATCH_MNT $SCRATCH_MNT/snap1
      
        _scratch_unmount
      
        echo "Silence is golden"
      
        status=0
        exit
      Signed-off-by: NMark Fasheh <mfasheh@suse.de>
      Reviewed-by: NQu Wenruo <quwenruo@cn.fujitsu.com>
      Signed-off-by: NDavid Sterba <dsterba@suse.com>
      918c2ee1