1. 22 Nov, 2010 7 commits
  2. 30 Oct, 2010 4 commits
  3. 29 Oct, 2010 25 commits
    • Sage Weil's avatar
      Btrfs: add START_SYNC, WAIT_SYNC ioctls · 46204592
      Sage Weil authored
      START_SYNC will start a sync/commit, but not wait for it to
      complete.  Any modification started after the ioctl returns is
      guaranteed not to be included in the commit.  If a non-NULL
      pointer is passed, the transaction id will be returned to
      userspace.
      
      WAIT_SYNC will wait for any in-progress commit to complete.  If a
      transaction id is specified, the ioctl will block and then
      return (success) when the specified transaction has committed.
      If it has already committed when we call the ioctl, it returns
      immediately.  If the specified transaction doesn't exist, it
      returns EINVAL.
      
      If no transaction id is specified, WAIT_SYNC will wait for the
      currently committing transaction to finish it's commit to disk.
      If there is no currently committing transaction, it returns
      success.
      
      These ioctls are useful for applications which want to impose an
      ordering on when fs modifications reach disk, but do not want to
      wait for the full (slow) commit process to do so.
      
      Picky callers can take the transid returned by START_SYNC and
      feed it to WAIT_SYNC, and be certain to wait only as long as
      necessary for the transaction _they_ started to reach disk.
      
      Sloppy callers can START_SYNC and WAIT_SYNC without a transid,
      and provided they didn't wait too long between the calls, they
      will get the same result.  However, if a second commit starts
      before they call WAIT_SYNC, they may end up waiting longer for
      it to commit as well.  Even so, a START_SYNC+WAIT_SYNC still
      guarantees that any operation completed before the START_SYNC
      reaches disk.
      Signed-off-by: default avatarSage Weil <sage@newdream.net>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      46204592
    • Sage Weil's avatar
      Btrfs: async transaction commit · bb9c12c9
      Sage Weil authored
      Add support for an async transaction commit that is ordered such that any
      subsequent operations will join the following transaction, but does not
      wait until the current commit is fully on disk.  This avoids much of the
      latency associated with the btrfs_commit_transaction for callers concerned
      with serialization and not safety.
      
      The wait_for_unblock flag controls whether we wait for the 'middle' portion
      of commit_transaction to complete, which is necessary if the caller expects
      some of the modifications contained in the commit to be available (this is
      the case for subvol/snapshot creation).
      Signed-off-by: default avatarSage Weil <sage@newdream.net>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      bb9c12c9
    • Sage Weil's avatar
      Btrfs: fix deadlock in btrfs_commit_transaction · 99d16cbc
      Sage Weil authored
      We calculate timeout (either 1 or MAX_SCHEDULE_TIMEOUT) based on whether
      num_writers > 1 or should_grow at the top of the loop.  Then, much much
      later, we wait for that timeout if either num_writers or should_grow is
      true.  However, it's possible for a racing process (calling
      btrfs_end_transaction()) to decrement num_writers such that we wait
      forever instead of for 1.
      
      Fix this by deciding how long to wait when we wait.  Include a smp_mb()
      before checking if the waitqueue is active to ensure the num_writers
      is visible.
      Signed-off-by: default avatarSage Weil <sage@newdream.net>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      99d16cbc
    • Sage Weil's avatar
      Btrfs: fix lockdep warning on clone ioctl · fccdae43
      Sage Weil authored
      I'm no lockdep expert, but this appears to make the lockdep warning go
      away for the i_mutex locking in the clone ioctl.
      Signed-off-by: default avatarSage Weil <sage@newdream.net>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      fccdae43
    • Sage Weil's avatar
      Btrfs: fix clone ioctl where range is adjacent to extent · 050006a7
      Sage Weil authored
      We had an edge case issue where the requested range was just
      following an existing extent. Instead of skipping to the next
      extent, we used the previous one which lead to having zero
      sized extents.
      Signed-off-by: default avatarYehuda Sadeh <yehuda@hq.newdream.net>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      050006a7
    • Sage Weil's avatar
      Btrfs: fix delalloc checks in clone ioctl · 9a019196
      Sage Weil authored
      The lookup_first_ordered_extent() was done on the wrong inode, and the
      ->delalloc_bytes test was wrong, as the following
      btrfs_wait_ordered_range() would only invoke a range write and wouldn't
      write the entire file data range. Also, a bad parameter was passed to
      btrfs_wait_ordered_range().
      Signed-off-by: default avatarYehuda Sadeh <yehuda@hq.newdream.net>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      9a019196
    • Chris Mason's avatar
      Btrfs: drop unused variable in block_alloc_rsv · d8e39c45
      Chris Mason authored
      The alloc_target variable is not really used.
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      d8e39c45
    • Andi Kleen's avatar
      Btrfs: cleanup warnings from gcc 4.6 (nonbugs) · 559af821
      Andi Kleen authored
      These are all the cases where a variable is set, but not read which are
      not bugs as far as I can see, but simply leftovers.
      
      Still needs more review.
      
      Found by gcc 4.6's new warnings
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Cc: Chris Mason <chris.mason@oracle.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      559af821
    • Andi Kleen's avatar
      Btrfs: Fix variables set but not read (bugs found by gcc 4.6) · 411fc6bc
      Andi Kleen authored
      These are all the cases where a variable is set, but not
      read which are really bugs.
      
      - Couple of incorrect error handling fixed.
      - One incorrect use of a allocation policy
      - Some other things
      
      Still needs more review.
      
      Found by gcc 4.6's new warnings.
      
      [akpm@linux-foundation.org: fix build.  Might have been bitrot]
      Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
      Cc: Chris Mason <chris.mason@oracle.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      411fc6bc
    • Julia Lawall's avatar
      Btrfs: Use ERR_CAST helpers · d0b678cb
      Julia Lawall authored
      Use ERR_CAST(x) rather than ERR_PTR(PTR_ERR(x)).  The former makes more
      clear what is the purpose of the operation, which otherwise looks like a
      no-op.
      
      The semantic patch that makes this change is as follows:
      (http://coccinelle.lip6.fr/)
      
      // <smpl>
      @@
      type T;
      T x;
      identifier f;
      @@
      
      T f (...) { <+...
      - ERR_PTR(PTR_ERR(x))
      + x
       ...+> }
      
      @@
      expression x;
      @@
      
      - ERR_PTR(PTR_ERR(x))
      + ERR_CAST(x)
      // </smpl>
      Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
      Cc: Chris Mason <chris.mason@oracle.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      d0b678cb
    • Julia Lawall's avatar
      Btrfs: use memdup_user helpers · 2354d08f
      Julia Lawall authored
      Use memdup_user when user data is immediately copied into the
      allocated region.
      
      The semantic patch that makes this change is as follows:
      (http://coccinelle.lip6.fr/)
      
      // <smpl>
      @@
      expression from,to,size,flag;
      position p;
      identifier l1,l2;
      @@
      
      -  to = \(kmalloc@p\|kzalloc@p\)(size,flag);
      +  to = memdup_user(from,size);
         if (
      -      to==NULL
      +      IS_ERR(to)
                       || ...) {
         <+... when != goto l1;
      -  -ENOMEM
      +  PTR_ERR(to)
         ...+>
         }
      -  if (copy_from_user(to, from, size) != 0) {
      -    <+... when != goto l2;
      -    -EFAULT
      -    ...+>
      -  }
      // </smpl>
      Signed-off-by: default avatarJulia Lawall <julia@diku.dk>
      Cc: Chris Mason <chris.mason@oracle.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      2354d08f
    • Chris Mason's avatar
      Btrfs: fix raid code for removing missing drives · 18e503d6
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
      18e503d6
    • Miao Xie's avatar
      Btrfs: Switch the extent buffer rbtree into a radix tree · 19fe0a8b
      Miao Xie authored
      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: default avatarMiao Xie <miaox@cn.fujitsu.com>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      19fe0a8b
    • Miao Xie's avatar
      Btrfs: restructure try_release_extent_buffer() · 897ca6e9
      Miao Xie authored
      restructure try_release_extent_buffer() and write a function to release the
      extent buffer. It will be used later.
      Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      897ca6e9
    • Chris Mason's avatar
      Btrfs: use the flusher threads for delalloc throttling · bf9022e0
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
      bf9022e0
    • Chris Mason's avatar
      Btrfs: tune the chunk allocation to 5% of the FS as metadata · e5bc2458
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
      e5bc2458
    • Chris Mason's avatar
      Add new functions for triggering inode writeback · 3259f8be
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
      3259f8be
    • Chris Mason's avatar
      Btrfs: don't loop forever on bad btree blocks · cb44921a
      Chris Mason authored
      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: default avatarChris Mason <chris.mason@oracle.com>
      cb44921a
    • Chris Mason's avatar
      Merge branch 'bug-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/josef/btrfs-work · 6b5b817f
      Chris Mason authored
      Conflicts:
      	fs/btrfs/extent-tree.c
      Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
      6b5b817f
    • Josef Bacik's avatar
      Btrfs: let the user know space caching is enabled · 8216ef86
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      8216ef86
    • Josef Bacik's avatar
      Btrfs: Add a clear_cache mount option · 88c2ba3b
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      88c2ba3b
    • Josef Bacik's avatar
      Btrfs: add support for mixed data+metadata block groups · 67377734
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      67377734
    • Josef Bacik's avatar
      Btrfs: check cache->caching_ctl before returning if caching has started · dde5abee
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      dde5abee
    • Josef Bacik's avatar
      Btrfs: load free space cache if it exists · 9d66e233
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      9d66e233
    • Josef Bacik's avatar
      Btrfs: write out free space cache · 0cb59c99
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      0cb59c99
  4. 28 Oct, 2010 1 commit
    • Josef Bacik's avatar
      Btrfs: create special free space cache inode · 0af3d00b
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      0af3d00b
  5. 26 Oct, 2010 2 commits
    • Josef Bacik's avatar
      Btrfs: remove warn_on from use_block_rsv · e9bb7f10
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      e9bb7f10
    • Josef Bacik's avatar
      Btrfs: set trans to null in reserve_metadata_bytes if we commit the transaction · 38227933
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      38227933
  6. 22 Oct, 2010 1 commit
    • Josef Bacik's avatar
      Btrfs: fix error handling in btrfs_get_sb · 0e78340f
      Josef Bacik authored
      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: default avatarJosef Bacik <josef@redhat.com>
      0e78340f