1. 14 Jun, 2012 5 commits
    • Jan Schmidt's avatar
      Btrfs: fix race in tree mod log addition · 3310c36e
      Jan Schmidt authored
      When adding to the tree modification log, we grab two locks at different
      stages. We must not drop the outer lock until we're done with section
      protected by the inner lock. This moves the unlock call for the outer lock
      to the appropriate position.
      Signed-off-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
      3310c36e
    • Jan Schmidt's avatar
      Btrfs: add btrfs_next_old_leaf · 3d7806ec
      Jan Schmidt authored
      To make sense of the tree mod log, the backref walker not only needs
      btrfs_search_old_slot, but it also called btrfs_next_leaf, which in turn was
      calling btrfs_search_slot. This obviously didn't give the correct result.
      
      This commit adds btrfs_next_old_leaf, a drop-in replacement for
      btrfs_next_leaf with a time_seq parameter. If it is zero, it behaves exactly
      like btrfs_next_leaf. If it is non-zero, it will use btrfs_search_old_slot
      with this time_seq parameter.
      Signed-off-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
      3d7806ec
    • Jan Schmidt's avatar
      Btrfs: fix return value for __tree_mod_log_oldest_root · a95236d9
      Jan Schmidt authored
      In __tree_mod_log_oldest_root() we must return the found operation even if
      it's not a ROOT_REPLACE operation. Otherwise, the caller assumes that there
      are no operations to be rewinded and returns immediately.
      
      The code in the caller is modified to improve readability.
      Signed-off-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
      a95236d9
    • Jan Schmidt's avatar
      Btrfs: use btrfs_read_lock_root_node in get_old_root · 8ba97a15
      Jan Schmidt authored
      get_old_root could race with root node updates because we weren't locking
      the node early enough. Use btrfs_read_lock_root_node to grab the root locked
      in the very beginning and release the lock as soon as possible (just like
      btrfs_search_slot does).
      Signed-off-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
      8ba97a15
    • Jan Schmidt's avatar
      Btrfs: remove obsolete btrfs_next_leaf call from __resolve_indirect_ref · f617e2fd
      Jan Schmidt authored
      When resolving indirect refs, we used to call btrfs_next_leaf in case we
      didn't find an exact match. While we should find exact matches most of the
      time, in case we don't, we must continue searching. Treating those matches
      differently depending on the level we're searching doesn't make sense.
      
      Even worse, we might end up searching for a key larger than the largest, in
      which case there is no next_leaf and subsequent jobs would fail. This commit
      drops the bogous lines.
      Signed-off-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
      f617e2fd
  2. 04 Jun, 2012 1 commit
  3. 31 May, 2012 6 commits
  4. 30 May, 2012 28 commits
    • Jan Schmidt's avatar
      Btrfs: use delayed ref sequence numbers for all fs-tree updates · 95a06077
      Jan Schmidt authored
      The sequence number for delayed refs is needed to postpone certain delayed
      refs for a very short period while walking backrefs. Before the tree
      modification log, we thought we'd only have to hold back those references
      that don't have a counter operation.
      
      While now we've the tree mod log, we're rewinding fs tree blocks to a
      defined consistent state. We cannot know in advance for which tree block
      we'll be doing rewind operations later. Therefore, we must postpone all the
      delayed refs for fs-tree blocks, even those having a counter operation.
      Signed-off-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
      95a06077
    • Chris Mason's avatar
      Merge branch 'for-chris' of... · cfc442b6
      Chris Mason authored
      Merge branch 'for-chris' of git://git.kernel.org/pub/scm/linux/kernel/git/josef/btrfs-next into HEAD
      cfc442b6
    • Stefan Behrens's avatar
      Btrfs: fix false positive in check-integrity on unmount · 48235a68
      Stefan Behrens authored
      During unmount, it could happen that the integrity checker printed a
      warning message "attempt to free ... on umount which is not yet iodone"
      which turned out to be a false positive.
      Signed-off-by: default avatarStefan Behrens <sbehrens@giantdisaster.de>
      48235a68
    • Stefan Behrens's avatar
      Btrfs: fix runtime warning in check-integrity check data mode · 86ff7ffc
      Stefan Behrens authored
      If a file_extent_item was located at the very end of a leaf and there was
      not enough space to hold a full item, but there was enough space to hold
      one of type BTRFS_FILE_EXTENT_INLINE or PREALLOC, and it was only such a
      short item, a warning was printed anyway. This check is now fixed.
      Signed-off-by: default avatarStefan Behrens <sbehrens@giantdisaster.de>
      86ff7ffc
    • Stefan Behrens's avatar
      Btrfs: set ioprio of scrub readahead to idle · 3d136a11
      Stefan Behrens authored
      Reduce ioprio class of scrub readahead threads to idle priority.
      This setting is fixed. This priority has shown the best performance
      during all measurements.
      Signed-off-by: default avatarStefan Behrens <sbehrens@giantdisaster.de>
      3d136a11
    • Josef Bacik's avatar
      Btrfs: fix return code in drop_objectid_items · 5bdbeb21
      Josef Bacik authored
      So dpkg fsync()'s the file and the directory containing the file whenever it
      writes to a file which is really slow in btrfs.  This is partly because
      fsync()'ing a directory _always_ committed the transaction instead of just
      going to the tree log.  This is because drop_objectid_items() would return 1
      since it does a btrfs_search_slot() which returns 1.  In tree-log jargon
      this means that we have to commit the transaction to be safe.  So just check
      if ret is greater than 0 and set it to 0 if it does.  With this patch we now
      use the tree-log instead of committing the entire transaction, which is
      twice as fast on my box.  Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      5bdbeb21
    • Josef Bacik's avatar
      Btrfs: check to see if the inode is in the log before fsyncing · 22ee6985
      Josef Bacik authored
      We have this check down in the actual logging code, but this is after we
      start a transaction and all that good stuff.  So move the helper
      inode_in_log() out so we can call it in fsync() and avoid starting a
      transaction altogether and just exit if we've already fsync()'ed this file
      recently.  You would notice this issue if you fsync()'ed a file over and
      over again until the transaction committed.  Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      22ee6985
    • Tsutomu Itoh's avatar
      Btrfs: return value of btrfs_read_buffer is checked correctly · 018642a1
      Tsutomu Itoh authored
      btrfs_read_buffer() has the possibility of returning the error.
      Therefore, I add the code in which the return value of btrfs_read_buffer()
      is checked.
      Signed-off-by: default avatarTsutomu Itoh <t-itoh@jp.fujitsu.com>
      018642a1
    • Stefan Behrens's avatar
      Btrfs: read device stats on mount, write modified ones during commit · 733f4fbb
      Stefan Behrens authored
      The device statistics are written into the device tree with each
      transaction commit. Only modified statistics are written.
      When a filesystem is mounted, the device statistics for each involved
      device are read from the device tree and used to initialize the
      counters.
      Signed-off-by: default avatarStefan Behrens <sbehrens@giantdisaster.de>
      733f4fbb
    • Stefan Behrens's avatar
      Btrfs: add ioctl to get and reset the device stats · c11d2c23
      Stefan Behrens authored
      An ioctl interface is added to get the device statistic counters.
      A second ioctl is added to atomically get and reset these counters.
      Signed-off-by: default avatarStefan Behrens <sbehrens@giantdisaster.de>
      c11d2c23
    • Stefan Behrens's avatar
      Btrfs: add device counters for detected IO and checksum errors · 442a4f63
      Stefan Behrens authored
      The goal is to detect when drives start to get an increased error rate,
      when drives should be replaced soon. Therefore statistic counters are
      added that count IO errors (read, write and flush). Additionally, the
      software detected errors like checksum errors and corrupted blocks are
      counted.
      Signed-off-by: default avatarStefan Behrens <sbehrens@giantdisaster.de>
      442a4f63
    • Asias He's avatar
      btrfs: Drop unused function btrfs_abort_devices() · d07eb911
      Asias He authored
      1) This function is not used anywhere.
      
      2) Using the blk_abort_queue() to abort the queue seems not correct.
      blk_abort_queue() is used for timeout handling (block/blk-timeout.c).
      
      Cc: Chris Mason <chris.mason@oracle.com>
      Cc: linux-btrfs@vger.kernel.org
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: default avatarAsias He <asias@redhat.com>
      d07eb911
    • Miao Xie's avatar
      Btrfs: fix the same inode id problem when doing auto defragment · 762f2263
      Miao Xie authored
      Two files in the different subvolumes may have the same inode id, so
      The rb-tree which is used to manage the defragment object must take it
      into account. This patch fix this problem.
      Signed-off-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
      762f2263
    • Josef Bacik's avatar
      Btrfs: fall back to non-inline if we don't have enough space · 2adcac1a
      Josef Bacik authored
      If cow_file_range_inline fails with ENOSPC we abort the transaction which
      isn't very nice.  This really shouldn't be happening anyways but there's no
      sense in making it a horrible error when we can easily just go allocate
      normal data space for this stuff.  Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      2adcac1a
    • Josef Bacik's avatar
      Btrfs: fix how we deal with the orphan block rsv · 8a35d95f
      Josef Bacik authored
      Ceph was hitting this race where we would remove an inode from the per-root
      orphan list before we would release the space we had reserved for the inode.
      We actually don't need a list or anything, we just need to make sure the
      root doesn't try to free up the orphan reserve until after the inodes have
      released their reservations.  So use an atomic counter instead of a list on
      the root and only decrement the counter after we've released our
      reservation.  I've tested this as well as several others and we no longer
      see the warnings that you would see while running ceph.  Thanks,
      Btrfs: fix how we deal with the orphan block rsv
      
      Ceph was hitting this race where we would remove an inode from the per-root
      orphan list before we would release the space we had reserved for the inode.
      We actually don't need a list or anything, we just need to make sure the
      root doesn't try to free up the orphan reserve until after the inodes have
      released their reservations.  So use an atomic counter instead of a list on
      the root and only decrement the counter after we've released our
      reservation.  I've tested this as well as several others and we no longer
      see the warnings that you would see while running ceph.  Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      8a35d95f
    • Josef Bacik's avatar
      Btrfs: convert the inode bit field to use the actual bit operations · 72ac3c0d
      Josef Bacik authored
      Miao pointed this out while I was working on an orphan problem that messing
      with a bitfield where different ranges are protected by different locks
      doesn't work out right.  Turns out we've been doing this forever where we
      have different parts of the bit field protected by either no lock at all or
      different locks which could cause all sorts of weird problems including the
      issue I was hitting.  So instead make a runtime_flags thing that we use the
      normal bit operations on that are all atomic so we can keep having our
      no/different locking for the different flags and then make force_compress
      it's own thing so it can be treated normally.  Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      72ac3c0d
    • Josef Bacik's avatar
      Btrfs: merge contigous regions when loading free space cache · cd023e7b
      Josef Bacik authored
      When we write out the free space cache we will write out everything that is
      in our in memory tree, and then we will just walk the pinned extents tree
      and write anything we see there.  The problem with this is that during
      normal operations the pinned extents will be merged back into the free space
      tree normally, and then we can allocate space from the merged areas and
      commit them to the tree log.  If we crash and replay the tree log we will
      crash again because the tree log will try to free up space from what looks
      like 2 seperate but contiguous entries, since one entry is from the original
      free space cache and the other was a pinned extent that was merged back.  To
      fix this we just need to walk the free space tree after we load it and merge
      contiguous entries back together.  This will keep the tree log stuff from
      breaking and it will make the allocator behave more nicely.  Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      cd023e7b
    • Liu Bo's avatar
      Btrfs: do not do balance in readonly mode · 9ba1f6e4
      Liu Bo authored
      In normal cases, we would not be allowed to do balance in RO mode.
      However, when we're using a seeding device and adding another device to sprout,
      things will change:
      
      $ mkfs.btrfs /dev/sdb7
      $ btrfstune -S 1 /dev/sdb7
      $ mount /dev/sdb7 /mnt/btrfs -o ro
      $ btrfs fi bal /mnt/btrfs   -----------------------> fail.
      $ btrfs dev add /dev/sdb8 /mnt/btrfs
      $ btrfs fi bal /mnt/btrfs   -----------------------> works!
      
      It should not be designed as an exception, and we'd better add another check for
      mnt flags.
      Signed-off-by: default avatarLiu Bo <liubo2009@cn.fujitsu.com>
      Reviewed-by: default avatarJosef Bacik <josef@redhat.com>
      9ba1f6e4
    • Liu Bo's avatar
      Btrfs: use fastpath in extent state ops as much as possible · d1ac6e41
      Liu Bo authored
      Fully utilize our extent state's new helper functions to use
      fastpath as much as possible.
      Signed-off-by: default avatarLiu Bo <liubo2009@cn.fujitsu.com>
      Reviewed-by: default avatarJosef Bacik <josef@redhat.com>
      d1ac6e41
    • Liu Bo's avatar
      Btrfs: fix wrong error returned by adding a device · f8c5d0b4
      Liu Bo authored
      Reproduce:
      $ mkfs.btrfs /dev/sdb7
      $ mount /dev/sdb7 /mnt/btrfs -o ro
      $ btrfs dev add /dev/sdb8 /mnt/btrfs
      ERROR: error adding the device '/dev/sdb8' - Invalid argument
      
      Since we mount with readonly options, and /dev/sdb7 is not a seeding one,
      a readonly notification is preferred.
      Signed-off-by: default avatarLiu Bo <liubo2009@cn.fujitsu.com>
      Reviewed-by: default avatarJosef Bacik <josef@redhat.com>
      f8c5d0b4
    • Josef Bacik's avatar
      Btrfs: finish ordered extents in their own thread · 5fd02043
      Josef Bacik authored
      We noticed that the ordered extent completion doesn't really rely on having
      a page and that it could be done independantly of ending the writeback on a
      page.  This patch makes us not do the threaded endio stuff for normal
      buffered writes and direct writes so we can end page writeback as soon as
      possible (in irq context) and only start threads to do the ordered work when
      it is actually done.  Compression needs to be reworked some to take
      advantage of this as well, but atm it has to do a find_get_page in its endio
      handler so it must be done in its own thread.  This makes direct writes
      quite a bit faster.  Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      5fd02043
    • Josef Bacik's avatar
      Btrfs: do not check delalloc when updating disk_i_size · 4e899152
      Josef Bacik authored
      We are checking delalloc to see if it is ok to update the i_size.  There are
      2 cases it stops us from updating
      
      1) If there is delalloc between our current disk_i_size and this ordered
      extent
      
      2) If there is delalloc between our current ordered extent and the next
      ordered extent
      
      These tests are racy however since we can set delalloc for these ranges at
      any time.  Also for the first case if we notice there is delalloc between
      disk_i_size and our ordered extent we will not update disk_i_size and assume
      that when that delalloc bit gets written out it will update everything
      properly.  However if we crash before that we will have file extents outside
      of our i_size, which is not good, so this test is dangerous as well as racy.
      Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      4e899152
    • Jim Meyering's avatar
      Btrfs: avoid buffer overrun in mount option handling · f60d16a8
      Jim Meyering authored
      There is an off-by-one error: allocating room for a maximal result
      string but without room for a trailing NUL.  That, can lead to
      returning a transformed string that is not NUL-terminated, and
      then to a caller reading beyond end of the malloc'd buffer.
      
      Rewrite to s/kzalloc/kmalloc/, remove unwarranted use of strncpy
      (the result is guaranteed to fit), remove dead strlen at end, and
      change a few variable names and comments.
      Reviewed-by: default avatarJosef Bacik <josef@redhat.com>
      Signed-off-by: default avatarJim Meyering <meyering@redhat.com>
      f60d16a8
    • Jim Meyering's avatar
      Btrfs: NUL-terminate path buffer in DEV_INFO ioctl result · a27202fb
      Jim Meyering authored
      A device with name of length BTRFS_DEVICE_PATH_NAME_MAX or longer
      would not be NUL-terminated in the DEV_INFO ioctl result buffer.
      Signed-off-by: default avatarJim Meyering <meyering@redhat.com>
      a27202fb
    • Jim Meyering's avatar
      Btrfs: avoid buffer overrun in btrfs_printk · f07c9a79
      Jim Meyering authored
      The buffer read-overrun would be triggered by a printk format
      starting with <N>, where N is a single digit.  NUL-terminate
      after strncpy.  Use memcpy, not strncpy, since we know the
      string we're copying fits in the destination buffer and
      contains no NUL byte.
      Signed-off-by: default avatarJim Meyering <meyering@redhat.com>
      f07c9a79
    • Daniel J Blueman's avatar
      Fix minor type issues · 2eec6c81
      Daniel J Blueman authored
      Address some minor type issues identified by sparse checker.
      Signed-off-by: default avatarDaniel J Blueman <daniel@quora.org>
      2eec6c81
    • Sergei Trofimovich's avatar
      btrfs: allow changing 'thread_pool' size at remount time · 0d2450ab
      Sergei Trofimovich authored
      Changing 'mount -oremount,thread_pool=2 /' didn't make any effect:
      
      maximum amount of worker threads is specified in 2 places:
      - in 'strict btrfs_fs_info::thread_pool_size'
      - in each worker struct: 'struct btrfs_workers::max_workers'
      
      'mount -oremount' updated only 'btrfs_fs_info::thread_pool_size'.
      
      Fix it by pushing new maximum value to all created worker structures
      as well.
      
      Cc: Josef Bacik <josef@redhat.com>
      Cc: Chris Mason <chris.mason@oracle.com>
      Reviewed-by: default avatarJosef Bacik <josef@redhat.com>
      Signed-off-by: default avatarSergei Trofimovich <slyfox@gentoo.org>
      0d2450ab
    • Josef Bacik's avatar
      Btrfs: do not do filemap_write_and_wait_range in fsync · 0885ef5b
      Josef Bacik authored
      We already do the btrfs_wait_ordered_range which will do this for us, so
      just remove this call so we don't call it twice.  Thanks,
      Signed-off-by: default avatarJosef Bacik <josef@redhat.com>
      0885ef5b