1. 22 11月, 2010 4 次提交
    • M
      btrfs: fix panic caused by direct IO · e65e1535
      Miao Xie 提交于
      btrfs paniced when we write >64KB data by direct IO at one time.
      
      Reproduce steps:
       # mkfs.btrfs /dev/sda5 /dev/sda6
       # mount /dev/sda5 /mnt
       # dd if=/dev/zero of=/mnt/tmpfile bs=100K count=1 oflag=direct
      
      Then btrfs paniced:
      mapping failed logical 1103155200 bio len 69632 len 12288
      ------------[ cut here ]------------
      kernel BUG at fs/btrfs/volumes.c:3010!
      [SNIP]
      Pid: 1992, comm: btrfs-worker-0 Not tainted 2.6.37-rc1 #1 D2399/PRIMERGY
      RIP: 0010:[<ffffffffa03d1462>]  [<ffffffffa03d1462>] btrfs_map_bio+0x202/0x210 [btrfs]
      [SNIP]
      Call Trace:
       [<ffffffffa03ab3eb>] __btrfs_submit_bio_done+0x1b/0x20 [btrfs]
       [<ffffffffa03a35ff>] run_one_async_done+0x9f/0xb0 [btrfs]
       [<ffffffffa03d3d20>] run_ordered_completions+0x80/0xc0 [btrfs]
       [<ffffffffa03d45a4>] worker_loop+0x154/0x5f0 [btrfs]
       [<ffffffffa03d4450>] ? worker_loop+0x0/0x5f0 [btrfs]
       [<ffffffffa03d4450>] ? worker_loop+0x0/0x5f0 [btrfs]
       [<ffffffff81083216>] kthread+0x96/0xa0
       [<ffffffff8100cec4>] kernel_thread_helper+0x4/0x10
       [<ffffffff81083180>] ? kthread+0x0/0xa0
       [<ffffffff8100cec0>] ? kernel_thread_helper+0x0/0x10
      
      We fix this problem by splitting bios when we submit bios.
      Reported-by: NTsutomu Itoh <t-itoh@jp.fujitsu.com>
      Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
      Tested-by: NTsutomu Itoh <t-itoh@jp.fujitsu.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      e65e1535
    • M
      btrfs: cleanup duplicate bio allocating functions · 88f794ed
      Miao Xie 提交于
      extent_bio_alloc() and compressed_bio_alloc() are similar, cleanup
      similar source code.
      Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      88f794ed
    • M
      btrfs: fix free dip and dip->csums twice · 0c56fa96
      Miao Xie 提交于
      bio_endio() will free dip and dip->csums, so dip and dip->csums twice will
      be freed twice. Fix it.
      Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      0c56fa96
    • C
      Btrfs: add migrate page for metadata inode · 784b4e29
      Chris Mason 提交于
      Migrate page will directly call the btrfs btree writepage function,
      which isn't actually allowed.
      
      Our writepage assumes that you have locked the extent_buffer and
      flagged the block as written.  Without doing these steps, we can
      corrupt metadata blocks.
      
      A later commit will remove the btree writepage function since
      it is really only safely used internally by btrfs.  We
      use writepages for everything else.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      784b4e29
  2. 30 10月, 2010 15 次提交
  3. 29 10月, 2010 15 次提交
    • C
      Btrfs: fix raid code for removing missing drives · 18e503d6
      Chris Mason 提交于
      When btrfs is mounted in degraded mode, it has some internal structures
      to track the missing devices.  This missing device is setup as readonly,
      but the mapping code can get upset when we try to write to it.
      
      This changes the mapping code to return -EIO instead of oops when we try
      to write to the readonly device.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      18e503d6
    • M
      Btrfs: Switch the extent buffer rbtree into a radix tree · 19fe0a8b
      Miao Xie 提交于
      This patch reduces the CPU time spent in the extent buffer search by using the
      radix tree instead of the rbtree and using the rcu lock instead of the spin
      lock.
      
      I did a quick test by the benchmark tool[1] and found the patch improve the
      file creation/deletion performance problem that I have reported[2].
      
      Before applying this patch:
      Create files:
      	Total files: 50000
      	Total time: 0.971531
      	Average time: 0.000019
      Delete files:
      	Total files: 50000
      	Total time: 1.366761
      	Average time: 0.000027
      
      After applying this patch:
      Create files:
      	Total files: 50000
      	Total time: 0.927455
      	Average time: 0.000019
      Delete files:
      	Total files: 50000
      	Total time: 1.292280
      	Average time: 0.000026
      
      [1] http://marc.info/?l=linux-btrfs&m=128212635122920&q=p3
      [2] http://marc.info/?l=linux-btrfs&m=128212635122920&w=2Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      19fe0a8b
    • M
      Btrfs: restructure try_release_extent_buffer() · 897ca6e9
      Miao Xie 提交于
      restructure try_release_extent_buffer() and write a function to release the
      extent buffer. It will be used later.
      Signed-off-by: NMiao Xie <miaox@cn.fujitsu.com>
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      897ca6e9
    • C
      Btrfs: use the flusher threads for delalloc throttling · bf9022e0
      Chris Mason 提交于
      We have a fairly complex set of loops around walking our list of
      delalloc inodes when we find metadata delalloc space running low.
      It doesn't work very well, can use large amounts of CPU and doesn't
      do very efficient writeback.
      
      This switches us to kick the bdi flusher threads instead.  All dirty
      data in btrfs is accounted as delalloc data, so this is very similar
      in terms of what it writes, but we're able to just kick off the IO
      and wait for progress.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      bf9022e0
    • C
      Btrfs: tune the chunk allocation to 5% of the FS as metadata · e5bc2458
      Chris Mason 提交于
      An earlier commit tried to keep us from allocating too many
      empty metadata chunks.  It was somewhat too restrictive and could
      lead to ENOSPC errors on empty filesystems.
      
      This increases the limits to about 5% of the FS size, allowing more
      metadata chunks to be preallocated.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      e5bc2458
    • C
      Add new functions for triggering inode writeback · 3259f8be
      Chris Mason 提交于
      When btrfs is running low on metadata space, it needs to force delayed
      allocation pages to disk.  It currently does this with a suboptimal walk
      of a private list of inodes with delayed allocation, and it would be
      much better if we used the generic flusher threads.
      
      writeback_inodes_sb_if_idle would be ideal, but it waits for the flusher
      thread to start IO on all the dirty pages in the FS before it returns.
      This adds variants of writeback_inodes_sb* that allow the caller to
      control how many pages get sent down.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      3259f8be
    • C
      Btrfs: don't loop forever on bad btree blocks · cb44921a
      Chris Mason 提交于
      When btrfs discovers the generation number in a btree block is
      incorrect, it can loop forever without forcing the RAID
      code to try a valid mirror, and without returning EIO.
      
      This changes things to properly kick out the EIO.
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      cb44921a
    • C
      Merge branch 'bug-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/josef/btrfs-work · 6b5b817f
      Chris Mason 提交于
      Conflicts:
      	fs/btrfs/extent-tree.c
      Signed-off-by: NChris Mason <chris.mason@oracle.com>
      6b5b817f
    • J
      Btrfs: let the user know space caching is enabled · 8216ef86
      Josef Bacik 提交于
      If you mount -o space_cache, the option will be persistent across mounts, but to
      make sure the user knows that they did this, emit a message telling them if they
      didn't mount with -o space_cache but the feature is still used.
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      8216ef86
    • J
      Btrfs: Add a clear_cache mount option · 88c2ba3b
      Josef Bacik 提交于
      If something goes wrong with the free space cache we need a way to make sure
      it's not loaded on mount and that it's cleared for everybody.  When you pass the
      clear_cache option it will make it so all block groups are setup to be cleared,
      which keeps them from being loaded and then they will be truncated when the
      transaction is committed.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      88c2ba3b
    • J
      Btrfs: add support for mixed data+metadata block groups · 67377734
      Josef Bacik 提交于
      There are just a few things that need to be fixed in the kernel to support mixed
      data+metadata block groups.  Mostly we just need to make sure that if we are
      using mixed block groups that we continue to allocate mixed block groups as we
      need them.  Also we need to make sure __find_space_info will find our space info
      if we search for DATA or METADATA only.  Tested this with xfstests and it works
      nicely.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      67377734
    • J
      Btrfs: check cache->caching_ctl before returning if caching has started · dde5abee
      Josef Bacik 提交于
      With the free space disk caching we can mark the block group as started with the
      caching, but we don't have a caching ctl.  This can race with anybody else who
      tries to get the caching ctl before we cache (this is very hard to do btw).  So
      instead check to see if cache->caching_ctl is set, and if not return NULL.
      Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      dde5abee
    • J
      Btrfs: load free space cache if it exists · 9d66e233
      Josef Bacik 提交于
      This patch actually loads the free space cache if it exists.  The only thing
      that really changes here is that we need to cache the block group if we're going
      to remove an extent from it.  Previously we did not do this since the caching
      kthread would pick it up.  With the on disk cache we don't have this luxury so
      we need to make sure we read the on disk cache in first, and then remove the
      extent, that way when the extent is unpinned the free space is added to the
      block group.  This has been tested with all sorts of things.
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      9d66e233
    • J
      Btrfs: write out free space cache · 0cb59c99
      Josef Bacik 提交于
      This is a simple bit, just dump the free space cache out to our preallocated
      inode when we're writing out dirty block groups.  There are a bunch of changes
      in inode.c in order to account for special cases.  Mostly when we're doing the
      writeout we're holding trans_mutex, so we need to use the nolock transacation
      functions.  Also we can't do asynchronous completions since the async thread
      could be blocked on already completed IO waiting for the transaction lock.  This
      has been tested with xfstests and btrfs filesystem balance, as well as my ENOSPC
      tests.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      0cb59c99
    • J
      Btrfs: create special free space cache inode · 0af3d00b
      Josef Bacik 提交于
      In order to save free space cache, we need an inode to hold the data, and we
      need a special item to point at the right inode for the right block group.  So
      first, create a special item that will point to the right inode, and the number
      of extent entries we will have and the number of bitmaps we will have.  We
      truncate and pre-allocate space everytime to make sure it's uptodate.
      
      This feature will be turned on as soon as you mount with -o space_cache, however
      it is safe to boot into old kernels, they will just generate the cache the old
      fashion way.  When you boot back into a newer kernel we will notice that we
      modified and not the cache and automatically discard the cache.
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      0af3d00b
  4. 27 10月, 2010 2 次提交
    • J
      Btrfs: remove warn_on from use_block_rsv · e9bb7f10
      Josef Bacik 提交于
      Because btrfs_dirty_inode does a btrfs_join_transaction, it doesn't actually
      reserve space.  It does this so we can try and dirty the inode quickly without
      having to deal with the ENOSPC problems.  But if it does get back ENOSPC it
      handles it properly.  The problem is use_block_rsv does a WARN_ON whenever this
      case happens, even tho btrfs_dirty_inode takes it into account and actually
      expects to get -ENOSPC if things are particularly tight.  So instead just remove
      the warning.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      e9bb7f10
    • J
      Btrfs: set trans to null in reserve_metadata_bytes if we commit the transaction · 38227933
      Josef Bacik 提交于
      btrfs_commit_transaction will free our trans, but because we pass trans to
      shrink_delalloc we could possibly have a use after free situation.  So instead
      if we commit the transaction, set trans to null and set committed to true so we
      don't keep trying to commit a transaction.  This fixes a panic I could reproduce
      at will.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      38227933
  5. 23 10月, 2010 4 次提交
    • J
      Btrfs: fix error handling in btrfs_get_sb · 0e78340f
      Josef Bacik 提交于
      If we failed to find the root subvol id, or the subvol=<name>, we would
      deactivate the locked super and close the devices.  The problem is at this point
      we have gotten the SB all setup, which includes setting super_operations, so
      when we'd deactiveate the super, we'd do a close_ctree() which closes the
      devices, so we'd end up closing the devices twice.  So if you do something like
      this
      
      mount /dev/sda1 /mnt/test1
      mount /dev/sda1 /mnt/test2 -o subvol=xxx
      umount /mnt/test1
      
      it would blow up (if subvol xxx doesn't exist).  This patch fixes that problem.
      Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      0e78340f
    • J
      Btrfs: rework how we reserve metadata bytes · 8bb8ab2e
      Josef Bacik 提交于
      With multi-threaded writes we were getting ENOSPC early because somebody would
      come in, start flushing delalloc because they couldn't make their reservation,
      and in the meantime other threads would come in and use the space that was
      getting freed up, so when the original thread went to check to see if they had
      space they didn't and they'd return ENOSPC.  So instead if we have some free
      space but not enough for our reservation, take the reservation and then start
      doing the flushing.  The only time we don't take reservations is when we've
      already overcommitted our space, that way we don't have people who come late to
      the party way overcommitting ourselves.  This also moves all of the retrying and
      flushing code into reserve_metdata_bytes so it's all uniform.  This keeps my
      fs_mark test from returning -ENOSPC as soon as it starts and actually lets me
      fill up the disk.  Thanks,
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      8bb8ab2e
    • J
      Btrfs: don't allocate chunks as aggressively · 14ed0ca6
      Josef Bacik 提交于
      Because the ENOSPC code over reserves super aggressively we end up allocating
      chunks way more often than we should.  For example with my fs_mark tests on a
      2gb fs I can end up reserved 1gb just for metadata, when only 34mb of that is
      being used.  So instead check to see if the amount of space actually used is
      less than 30% of the total space, and if so don't allocate a chunk, but only if
      we have at least 256mb of free space to make sure we don't put too much pressure
      on free space.
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      14ed0ca6
    • J
      Btrfs: re-work delalloc flushing · 0019f10d
      Josef Bacik 提交于
      Currently we try and flush delalloc, but we only do that in a sort of weak way,
      which works fine in most cases but if we're under heavy pressure we need to be
      able to wait for flushing to happen.  Also instead of checking the bytes
      reserved in the block_rsv, check the space info since it is more accurate.  The
      sync option will be used in a future patch.
      Signed-off-by: NJosef Bacik <josef@redhat.com>
      0019f10d