1. 06 11月, 2011 12 次提交
    • J
      Btrfs: fix delayed insertion reservation · c06a0e12
      Josef Bacik 提交于
      We all keep getting those stupid warnings from use_block_rsv when running
      stress.sh, and it's because the delayed insertion stuff is being stupid.  It's
      not the delayed insertion stuffs fault, it's all just stupid.  When marking an
      inode dirty for oh say updating the time on it, we just do a
      btrfs_join_transaction, which doesn't reserve any space.  This is stupid because
      we're going to have to have space reserve to make this change, but we do it
      because it's fast because chances are we're going to call it over and over again
      and it doesn't matter.  Well thanks to the delayed insertion stuff this is
      mostly the case, so we do actually need to make this reservation.  So if
      trans->bytes_reserved is 0 then try to do a normal reservation.  If not return
      ENOSPC which will make the btrfs_dirty_inode start a proper transaction which
      will let it do the whole ENOSPC dance and reserve enough space for the delayed
      insertion to steal the reservation from the transaction.
      
      The other stupid thing we do is not reserve space for the inode when writing to
      the thing.  Usually this is ok since we have to update the time so we'd have
      already done all this work before we get to the endio stuff, so it doesn't
      matter.  But this is stupid because we could write the data after the
      transaction commits where we changed the mtime of the inode so we have to cow
      all the way down to the inode anyway.  This used to be masked by the delalloc
      reservation stuff, but because we delay the update it doesn't get masked in this
      case.  So again the delayed insertion stuff bites us in the ass.  So if our
      trans->block_rsv is delalloc, just steal the reservation from the delalloc
      reserve.  Hopefully this won't bite us in the ass, but I've said that before.
      
      With this patch stress.sh no longer spits out those stupid warnings (famous last
      words).  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      c06a0e12
    • C
      Btrfs: ClearPageError during writepage and clean_tree_block · bf0da8c1
      Chris Mason 提交于
      Failure testing was tripping up over stale PageError bits in
      metadata pages.  If we have an io error on a block, and later on
      end up reusing it, nobody ever clears PageError on those pages.
      
      During commit, we'll find PageError and think we had trouble writing
      the block, which will lead to aborts and other problems.
      
      This changes clean_tree_block and the btrfs writepage code to
      clear the PageError bit.  In both cases we're either completely
      done with the page or the page has good stuff and the error bit
      is no longer valid.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      bf0da8c1
    • J
      Btrfs: be smarter about committing the transaction in reserve_metadata_bytes · 663350ac
      Josef Bacik 提交于
      Because of the overcommit stuff I had to make it so that we committed the
      transaction all the time in reserve_metadata_bytes in case we had overcommitted
      because of delayed items.  This was because previously we had no way of knowing
      how much space was reserved for delayed items.  Now that we have the
      delayed_block_rsv we can check it to see if committing the transaction would get
      us anywhere.  This patch breaks out the committing logic into a helper function
      that will check to see if committing the transaction would free enough space for
      us to get anything done.  With this patch xfstests 83 goes from taking 445
      seconds to taking 28 seconds on my box.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      663350ac
    • J
      Btrfs: make a delayed_block_rsv for the delayed item insertion · 6d668dda
      Josef Bacik 提交于
      I've been hitting warnings in use_block_rsv when running the delayed insertion
      stuff.  It's because we will readjust global block rsv based on what is in use,
      which means we could end up discarding reservations that are for the delayed
      insertion stuff.  So instead create a seperate block rsv for the delayed
      insertion stuff.  This will also make it easier to debug problems with the
      delayed insertion reservations since we will know that only the delayed
      insertion code touches this block_rsv.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      6d668dda
    • C
      Btrfs: add a log of past tree roots · af31f5e5
      Chris Mason 提交于
      This takes some of the free space in the btrfs super block
      to record information about most of the roots in the last four
      commits.
      
      It also adds a -o recovery to use the root history log when
      we're not able to read the tree of tree roots, the extent
      tree root, the device tree root or the csum root.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      af31f5e5
    • D
      btrfs: separate superblock items out of fs_info · 6c41761f
      David Sterba 提交于
      fs_info has now ~9kb, more than fits into one page. This will cause
      mount failure when memory is too fragmented. Top space consumers are
      super block structures super_copy and super_for_commit, ~2.8kb each.
      Allocate them dynamically. fs_info will be ~3.5kb. (measured on x86_64)
      
      Add a wrapper for freeing fs_info and all of it's dynamically allocated
      members.
      Signed-off-by: NDavid Sterba <dsterba@suse.cz>
      6c41761f
    • J
      Btrfs: use the global reserve when truncating the free space cache inode · c8174313
      Josef Bacik 提交于
      We no longer use the orphan block rsv for holding the reservation for truncating
      the inode, so instead use the global block rsv and check to make sure it has
      enough space for us to truncate the space.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      c8174313
    • J
      Btrfs: release metadata from global reserve if we have to fallback for unlink · 5a77d76c
      Josef Bacik 提交于
      I fixed a problem where we weren't reserving space for an orphan item when we
      had to fallback to using the global reserve for an unlink, but I introduced
      another problem.  I was migrating the bytes from the transaction reserve to the
      global reserve and then releasing from the global reserve in
      btrfs_end_transaction().  The problem with this is that a migrate will jack up
      the size for the destination, but leave the size alone for the source, with the
      idea that you can do a release normally on the source and it all washes out, and
      then you can do a release again on the destination and it works out right.  My
      way was skipping the release on the trans_block_rsv which still had the jacked
      up size from our original reservation.  So instead release manually from the
      global reserve if this transaction was using it, and then set the
      trans->block_rsv back to the trans_block_rsv so that btrfs_end_transaction
      cleans everything up properly.  With this patch xfstest 83 doesn't emit warnings
      about leaking space.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      5a77d76c
    • C
      Btrfs: make sure to flush queued bios if write_cache_pages waits · 01d658f2
      Chris Mason 提交于
      write_cache_pages tries to build up a large bio to stuff down the pipe.
      But if it needs to wait for a page lock, it needs to make sure and send
      down any pending writes so we don't deadlock with anyone who has the
      page lock and is waiting for writeback of things inside the bio.
      
      Dave Sterba triggered this as a deadlock between the autodefrag code and
      the extent write_cache_pages
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      01d658f2
    • C
      Btrfs: fix extent pinning bugs in the tree log · e688b725
      Chris Mason 提交于
      The tree log had two important bugs that could cause corruptions after a
      crash.  Sometimes we were allowing tree log blocks to be reused after
      the tree log was committed but before the transaction commit was done.
      
      This allowed a future metadata write to overwrite the tree log data.  It
      is fixed by adding a new variant of freeing reserved extents that always
      pins them.  Credit goes to Stefan Behrens and Arne Jansen for many many
      hours spent tracking this bug down.
      
      During tree log replay, we do a pass through the tree log and pin all
      the extents we find.  This makes sure the replay code won't go in and
      use any of those blocks for new allocations during replay.  The problem
      is the free space cache isn't honoring these pinned extents.  So the
      allocator can end up handing them out, leading to all kinds of problems
      during replay.
      
      The fix here is to force any free space cache to load while we pin the
      extents, and then to make sure we remove the pinned extents from the
      free space rbtree.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      Reported-by: NStefan Behrens <sbehrens@giantdisaster.de>
      e688b725
    • C
      Btrfs: make sure btrfs_remove_free_space doesn't leak EAGAIN · 1eae31e9
      Chris Mason 提交于
      btrfs_remove_free_space needs to make sure to set ret back to a
      valid return value after setting it to EAGAIN, otherwise we return
      it to the callers.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      1eae31e9
    • C
      Btrfs: don't wait as long for more batches during SSD log commit · cd354ad6
      Chris Mason 提交于
      When we're doing log commits, we try to wait for more writers to come in
      and make the commit bigger.  This helps improve performance on rotating
      disks, but on SSDs it adds latencies.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      cd354ad6
  2. 24 10月, 2011 2 次提交
    • D
      btrfs: ratelimit WARN_ON in use_block_rsv · dff51cd1
      David Sterba 提交于
      The WARN_ON under some circumstances heavily polute log and slow down
      the machine. This is just a safety, as the warning should be fixed by
      another patch, nevertheless, it still pops up during testing.
      Signed-off-by: NDavid Sterba <dsterba@suse.cz>
      dff51cd1
    • D
      btrfs: do not allow mounting non-subvolumes via subvol option · f9d9ef62
      David Sterba 提交于
      There's a missing test whether the path passed to subvol=path option
      during mount is a real subvolume, allowing any directory located in
      default subovlume to be passed and accepted for mount.
      
      (current btrfs progs prevent this early)
      $ btrfs subvol snapshot . p1-snap
      ERROR: '.' is not a subvolume
      
      (with "is subvolume?" test bypassed)
      $ btrfs subvol snapshot . p1-snap
      Create a snapshot of '.' in './p1-snap'
      
      $ btrfs subvol list -p .
      ID 258 parent 5 top level 5 path subvol
      ID 259 parent 5 top level 5 path subvol1
      ID 260 parent 5 top level 5 path default-subvol1
      ID 262 parent 5 top level 5 path p1/p1-snapshot
      ID 263 parent 259 top level 5 path subvol1/subvol1-snap
      
      The problem I see is that this makes a false impression of snapshotting the
      given subvolume but in fact snapshots the default one: a user expects outcome
      like ID 263 but in fact gets ID 262 .
      
      This patch makes mount fail with EINVAL with a message in syslog.
      Signed-off-by: NDavid Sterba <dsterba@suse.cz>
      f9d9ef62
  3. 21 10月, 2011 18 次提交
    • I
      Btrfs: close all bdevs on mount failure · 20bcd649
      Ilya Dryomov 提交于
      Fix a bug introduced by 20b45077.  We have to return EINVAL on mount
      failure, but doing that too early in the sequence leaves all of the
      devices opened exclusively.  This also fixes an issue where under some
      scenarios only a second mount -o degraded <devices> command would
      succeed.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      20bcd649
    • I
      Btrfs: fix a bug when opening seed devices · 5f524444
      Ilya Dryomov 提交于
      Initialize fs_info->bdev_holder a bit earlier to be able to pass a
      correct holder id to blkdev_get() when opening seed devices with O_EXCL.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      5f524444
    • D
      btrfs: fix oops on failure path · 068132ba
      Daniel J Blueman 提交于
      If lookup_extent_backref fails, path->nodes[0] reasonably could be
      null along with other callers of btrfs_print_leaf, so ensure we have a
      valid extent buffer before dereferencing.
      Signed-off-by: NDaniel J Blueman <daniel.blueman@gmail.com>
      068132ba
    • M
      Btrfs: fix race between multi-task space allocation and caching space · 60d2adbb
      Miao Xie 提交于
      The task may fail to get free space though it is enough when multi-task
      space allocation and caching space happen at the same time.
      
      	Task1			Caching Thread		Task2
      	------------------------------------------------------------------------
      	find_free_extent
      	  The space has not
      	  be cached, and start
      	  caching thread. And
      	  wait for it.
      				cache space, if
      				the space is > 2MB
      				wake up Task1
      							find_free_extent
      							  get all the space that
      							  is cached.
      	  try to allocate space,
      	  but there is no space
      	  now.
      	trigger BUG_ON()
      
      The message is following:
      btrfs allocation failed flags 1, wanted 4096
      space_info has 1040187392 free, is not full
      space_info total=1082130432, used=4096, pinned=41938944, reserved=0, may_use=40828928, readonly=0
      block group 12582912 has 8388608 bytes, 0 used 8388608 pinned 0 reserved
      block group has cluster?: no
      0 blocks of free space at or bigger than bytes is
      block group 1103101952 has 1073741824 bytes, 4096 used 33550336 pinned 0 reserved
      block group has cluster?: no
      0 blocks of free space at or bigger than bytes is
      ------------[ cut here ]------------
      kernel BUG at fs/btrfs/inode.c:835!
       [<ffffffffa031261b>] __extent_writepage+0x1bf/0x5ce [btrfs]
       [<ffffffff810cbcb8>] ? __set_page_dirty_nobuffers+0xfe/0x108
       [<ffffffffa02f8ada>] ? wait_current_trans+0x23/0xec [btrfs]
       [<ffffffff810c3fbf>] ? find_get_pages_tag+0x73/0xe2
       [<ffffffffa0312d12>] extent_write_cache_pages.clone.0+0x176/0x29a [btrfs]
       [<ffffffffa0312e74>] extent_writepages+0x3e/0x53 [btrfs]
       [<ffffffff8110ad2c>] ? do_sync_write+0xc6/0x103
       [<ffffffffa0302d6e>] ? btrfs_submit_direct+0x414/0x414 [btrfs]
       [<ffffffff811380fa>] ? fsnotify+0x236/0x266
       [<ffffffffa02fc930>] btrfs_writepages+0x22/0x24 [btrfs]
       [<ffffffff810cc215>] do_writepages+0x1c/0x25
       [<ffffffff810c4958>] __filemap_fdatawrite_range+0x4e/0x50
       [<ffffffff810c4982>] filemap_write_and_wait_range+0x28/0x51
       [<ffffffffa0306b2e>] btrfs_sync_file+0x7d/0x198 [btrfs]
       [<ffffffff8110aa26>] ? fsnotify_modify+0x5d/0x65
       [<ffffffff8112d150>] vfs_fsync_range+0x18/0x21
       [<ffffffff8112d170>] vfs_fsync+0x17/0x19
       [<ffffffff8112d316>] do_fsync+0x29/0x3e
       [<ffffffff8112d348>] sys_fsync+0xb/0xf
       [<ffffffff81468352>] system_call_fastpath+0x16/0x1b
      [SNIP]
      RIP  [<ffffffffa02fe08c>] cow_file_range+0x1c4/0x32b [btrfs]
      
      We fix this bug by trying to allocate the space again if there are block groups
      in caching.
      Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
      60d2adbb
    • T
      Btrfs: fix return value of btrfs_get_acl() · cfbffc39
      Tsutomu Itoh 提交于
      In btrfs_get_acl(), when the second __btrfs_getxattr() call fails,
      acl is not correctly set.
      Therefore, a wrong value might return to the caller.
      Signed-off-by: NTsutomu Itoh <t-itoh@jp.fujitsu.com>
      cfbffc39
    • I
      Btrfs: pass the correct root to lookup_free_space_inode() · 10b2f34d
      Ilya Dryomov 提交于
      Free space items are located in tree of tree roots, not in the extent
      tree.  It didn't pop up because lookup_free_space_inode() grabs the
      inode all the time instead of actually searching the tree.
      Signed-off-by: NIlya Dryomov <idryomov@gmail.com>
      10b2f34d
    • L
      fee187d9
    • L
      Btrfs: fix direct-io vs nodatacow · f0dd9592
      Li Zefan 提交于
      To reproduce the bug:
      
        # mount -o nodatacow /dev/sda7 /mnt/
        # dd if=/dev/zero of=/mnt/tmp bs=4K count=1
        1+0 records in
        1+0 records out
        4096 bytes (4.1 kB) copied, 0.000136115 s, 30.1 MB/s
        # dd if=/dev/zero of=/mnt/tmp bs=4K count=1 conv=notrunc oflag=direct
        dd: writing `/mnt/tmp': Input/output error
        1+0 records in
        0+0 records out
      
      btrfs_ordered_update_i_size() may return 1, but btrfs_endio_direct_write()
      mistakenly takes it as an error.
      Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
      f0dd9592
    • L
      Btrfs: remove BUG_ON() in compress_file_range() · 560f7d75
      Li Zefan 提交于
      It's not a big deal if we fail to allocate the array, and instead of
      panic we can just give up compressing.
      Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
      560f7d75
    • L
      Btrfs: fix array bound checking · a05a9bb1
      Li Zefan 提交于
      Otherwise we can execced the array bound of path->slots[].
      Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
      a05a9bb1
    • L
      btrfs: return EINVAL if start > total_bytes in fitrim ioctl · f4c697e6
      Lukas Czerner 提交于
      We should retirn EINVAL if the start is beyond the end of the file
      system in the btrfs_ioctl_fitrim(). Fix that by adding the appropriate
      check for it.
      
      Also in the btrfs_trim_fs() it is possible that len+start might overflow
      if big values are passed. Fix it by decrementing the len so that start+len
      is equal to the file system size in the worst case.
      Signed-off-by: NLukas Czerner <lczerner@redhat.com>
      f4c697e6
    • L
      Btrfs: honor extent thresh during defragmentation · 008873ea
      Li Zefan 提交于
      We won't defrag an extent, if it's bigger than the threshold we
      specified and there's no small extent before it, but actually
      the code doesn't work this way.
      
      There are three bugs:
      
      - When should_defrag_range() decides we should keep on defragmenting
        an extent, last_len is not incremented. (old bug)
      
      - The length that passes to should_defrag_range() is not the length
        we're going to defrag. (new bug)
      
      - We always defrag 256K bytes data, and a big extent can be part of
        this range. (new bug)
      
      For a file with 4 extents:
      
              | 4K | 4K | 256K | 256K |
      
      The result of defrag with (the default) 256K extent thresh should be:
      
              | 264K | 256K |
      
      but with those bugs, we'll get:
      
              | 520K |
      Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
      008873ea
    • J
    • L
      Btrfs: fix wrong max_to_defrag in btrfs_defrag_file() · 5ca49660
      Li Zefan 提交于
      It's off-by-one, and thus we may skip the last page while defragmenting.
      
      An example case:
      
        # create /mnt/file with 2 4K file extents
        # btrfs fi defrag /mnt/file
        # sync
        # filefrag /mnt/file
        /mnt/file: 2 extents found
      
      So it's not defragmented.
      Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
      5ca49660
    • L
      Btrfs: use i_size_read() in btrfs_defrag_file() · 151a31b2
      Li Zefan 提交于
      Don't use inode->i_size directly, since we're not holding i_mutex.
      
      This also fixes another bug, that i_size can change after it's checked
      against 0 and then (i_size - 1) can be negative.
      Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
      151a31b2
    • L
      Btrfs: fix defragmentation regression · cbcc8326
      Li Zefan 提交于
      There's an off-by-one bug:
      
        # create a file with lots of 4K file extents
        # btrfs fi defrag /mnt/file
        # sync
        # filefrag -v /mnt/file
        Filesystem type is: 9123683e
        File size of /mnt/file is 1228800 (300 blocks, blocksize 4096)
         ext logical physical expected length flags
           0       0     3372              64
           1      64     3136     3435      1
           2      65     3436     3136     64
           3     129     3201     3499      1
           4     130     3500     3201     64
           5     194     3266     3563      1
           6     195     3564     3266     64
           7     259     3331     3627      1
           8     260     3628     3331     40 eof
      
      After this patch:
      
        ...
        # filefrag -v /mnt/file
        Filesystem type is: 9123683e
        File size of /mnt/file is 1228800 (300 blocks, blocksize 4096)
         ext logical physical expected length flags
           0       0     3372             300 eof
        /mnt/file: 1 extent found
      Signed-off-by: NLi Zefan <lizf@cn.fujitsu.com>
      cbcc8326
    • D
      btrfs: fix memory leak in btrfs_defrag_file · 60ccf82f
      Diego Calleja 提交于
      kmemleak found this:
      unreferenced object 0xffff8801b64af968 (size 512):
        comm "btrfs-cleaner", pid 3317, jiffies 4306810886 (age 903.272s)
        hex dump (first 32 bytes):
          00 82 01 07 00 ea ff ff c0 83 01 07 00 ea ff ff  ................
          80 82 01 07 00 ea ff ff c0 87 01 07 00 ea ff ff  ................
        backtrace:
          [<ffffffff816875cc>] kmemleak_alloc+0x5c/0xc0
          [<ffffffff8114aec3>] kmem_cache_alloc_trace+0x163/0x240
          [<ffffffff8127a290>] btrfs_defrag_file+0xf0/0xb20
          [<ffffffff8125d9a5>] btrfs_run_defrag_inodes+0x165/0x210
          [<ffffffff812479d7>] cleaner_kthread+0x177/0x190
          [<ffffffff81075c7d>] kthread+0x8d/0xa0
          [<ffffffff816af5f4>] kernel_thread_helper+0x4/0x10
          [<ffffffffffffffff>] 0xffffffffffffffff
      
      "pages" is not always freed. Fix it removing the unnecesary additional return.
      Signed-off-by: NDiego Calleja <diegocg@gmail.com>
      60ccf82f
    • Y
      btrfs: check file extent backref offset underflow · 84850e8d
      Yan, Zheng 提交于
      Offset field in data extent backref can underflow if clone range ioctl
      is used. We can reliably detect the underflow because max file size is
      limited to 2^63 and max data extent size is limited by block group size.
      Signed-off-by: NZheng Yan  <zheng.z.yan@intel.com>
      84850e8d
  4. 20 10月, 2011 8 次提交
    • J
      Btrfs: don't flush the cache inode before writing it · 016fc6a6
      Josef Bacik 提交于
      I noticed we had a little bit of latency when writing out the space cache
      inodes.  It's because we flush it before we write anything in case we have dirty
      pages already there.  This doesn't matter though since we're just going to
      overwrite the space, and there really shouldn't be any dirty pages anyway.  This
      makes some of my tests run a little bit faster.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      016fc6a6
    • J
      Btrfs: if we have a lot of pinned space, commit the transaction · 7e355b83
      Josef Bacik 提交于
      Mitch kept hitting a panic because he was getting ENOSPC.  One of my previous
      patches makes it so we are much better at not allocating new metadata chunks.
      Unfortunately coupled with the overcommit patch this works us into a bit of a
      problem if we are removing a bunch of space and end up chewing up all of our
      space with pinned extents.  We can allocate chunks fine and overflow is ok, but
      the only way to reclaim this space is to commit the transaction.  So if we go to
      overcommit, first check and see how much pinned space we have.  If we have more
      than 80% of the free space chewed up with pinned extents, just commit the
      transaction, this will free up enough space for our reservation and we won't
      have this problem anymore.  With this patch Mitch's test doesn't blow up
      anymore.  Thanks,
      Reported-and-tested-by: NMitch Harder <mitch.harder@sabayonlinux.org>
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      7e355b83
    • J
      Btrfs: seperate out btrfs_block_rsv_check out into 2 different functions · 36ba022a
      Josef Bacik 提交于
      Currently btrfs_block_rsv_check does 2 things, it will either refill a block
      reserve like in the truncate or refill case, or it will check to see if there is
      enough space in the global reserve and possibly refill it.  However because of
      overcommit we could be well overcommitting ourselves just to try and refill the
      global reserve, when really we should just be committing the transaction.  So
      breack this out into btrfs_block_rsv_refill and btrfs_block_rsv_check.  Refill
      will try to reserve more metadata if it can and btrfs_block_rsv_check will not,
      it will only tell you if the factor of the total space is still reserved.
      Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      36ba022a
    • J
      Btrfs: reserve some space for an orphan item when unlinking · 3880a1b4
      Josef Bacik 提交于
      In __unlink_start_trans() if we don't have enough room for a reservation we will
      check to see if the unlink will free up space.  If it does that's great, but we
      will still could add an orphan item, so we need to reserve enough space to add
      the orphan item.  Do this and migrate the space the global reserve so it all
      works out right.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      3880a1b4
    • J
      Btrfs: release trans metadata bytes before flushing delayed refs · b24e03db
      Josef Bacik 提交于
      We started setting trans->block_rsv = NULL to allow the delayed refs flushing
      stuff to use the right block_rsv and then just made
      btrfs_trans_release_metadata() unconditionally use the trans block rsv.  The
      problem with this is we need to reserve some space in the transaction and then
      migrate it to the global block rsv, so we need to be able to free that out
      properly.  So instead just move btrfs_trans_release_metadata() before the
      delayed ref flushing and use trans->block_rsv for the freeing.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      b24e03db
    • J
      Btrfs: allow shrink_delalloc flush the needed reclaimed pages · 877da174
      Josef Bacik 提交于
      Currently we only allow a maximum of 2 megabytes of pages to be flushed at a
      time.  This was ok before, but now we have overcommit which will screw us in a
      heartbeat if we are quickly filling the disk.  So instead pick either 2
      megabytes or the number of pages we need to reclaim to be safe again, which ever
      is larger.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      877da174
    • J
      Btrfs: wait for ordered extents if we're in trouble when shrinking delalloc · f104d044
      Josef Bacik 提交于
      The only way we actually reclaim delalloc space is waiting for the IO to
      completely finish.  Usually we kick off a bunch of IO and wait for a little bit
      and hope we can make our reservation, and usually this works out pretty well.
      With overcommit however we can get seriously underwater if we're filling up the
      disk quickly, so we need to be able to force the delalloc shrinker to wait for
      the ordered IO to finish to give us a better chance of actually reclaiming
      enough space to get our reservation.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      f104d044
    • J
      Btrfs: don't check bytes_pinned to determine if we should commit the transaction · bbb495c2
      Josef Bacik 提交于
      Before the only reason to commit the transaction to recover space in
      reserve_metadata_bytes() was if there were enough pinned_bytes to satisfy our
      reservation.  But now we have the delayed inode stuff which will hold it's
      reservations until we commit the transaction.  So say we max out our reservation
      by creating a bunch of files but don't have any pinned bytes we will ENOSPC out
      early even though we could commit the transaction and get that space back.  So
      now just unconditionally commit the transaction since currently there is no way
      to know how much metadata space is being reserved by delayed inode stuff.
      Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      bbb495c2