• Josef Bacik's avatar
    btrfs: push the extent lock into btrfs_run_delalloc_range · c0707c9e
    Josef Bacik authored
    We want to limit the scope of the extent lock to be around operations
    that can change in flight.  Currently we hold the extent lock through
    the entire writepage operation, which isn't really necessary.
    
    We want to protect to make sure nobody has updated DELALLOC.  In
    find_lock_delalloc_range we must lock the range in order to validate the
    contents of our io_tree.  However once we've done that we're safe to
    unlock the range and continue, as we have the page lock already held for
    the range.
    
    We are protected from all operations at this point.
    
    * mmap() - we're holding the page lock, thus are protected.
    * buffered writes - again, we're protected because we take the page lock
      for the first and last page in our range for buffered writes so we
      won't create new delalloc ranges in this area.
    * direct IO - we invalidate pagecache before attempting to write a new
      area, which requires the page lock, so again are protected once we're
      holding the page lock on this range.
    
    Additionally this behavior actually already exists for compressed, we
    unlock the range as soon as we start to process the async extents, and
    re-lock it during compression.  So this is completely safe, and makes
    the locking more consistent.
    
    Make this simple by just pushing the extent lock into
    btrfs_run_delalloc_range.  From there followup patches will push the
    lock further down into its users.
    Reviewed-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
    Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    c0707c9e
extent_io.c 146 KB