<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/btrfs/file.c, branch linux-4.8.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.8.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.8.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2016-08-25T10:58:32Z</updated>
<entry>
<title>Btrfs: fix lockdep warning on deadlock against an inode's log mutex</title>
<updated>2016-08-25T10:58:32Z</updated>
<author>
<name>Filipe Manana</name>
</author>
<published>2016-08-23T20:13:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=28a235931b56d4e7bdd51f6733daf95f2b269da8'/>
<id>urn:sha1:28a235931b56d4e7bdd51f6733daf95f2b269da8</id>
<content type='text'>
Commit 44f714dae50a ("Btrfs: improve performance on fsync against new
inode after rename/unlink"), which landed in 4.8-rc2, introduced a
possibility for a deadlock due to double locking of an inode's log mutex
by the same task, which lockdep reports with:

[23045.433975] =============================================
[23045.434748] [ INFO: possible recursive locking detected ]
[23045.435426] 4.7.0-rc6-btrfs-next-34+ #1 Not tainted
[23045.436044] ---------------------------------------------
[23045.436044] xfs_io/3688 is trying to acquire lock:
[23045.436044]  (&amp;ei-&gt;log_mutex){+.+...}, at: [&lt;ffffffffa038552d&gt;] btrfs_log_inode+0x13a/0xc95 [btrfs]
[23045.436044]
               but task is already holding lock:
[23045.436044]  (&amp;ei-&gt;log_mutex){+.+...}, at: [&lt;ffffffffa038552d&gt;] btrfs_log_inode+0x13a/0xc95 [btrfs]
[23045.436044]
               other info that might help us debug this:
[23045.436044]  Possible unsafe locking scenario:

[23045.436044]        CPU0
[23045.436044]        ----
[23045.436044]   lock(&amp;ei-&gt;log_mutex);
[23045.436044]   lock(&amp;ei-&gt;log_mutex);
[23045.436044]
                *** DEADLOCK ***

[23045.436044]  May be due to missing lock nesting notation

[23045.436044] 3 locks held by xfs_io/3688:
[23045.436044]  #0:  (&amp;sb-&gt;s_type-&gt;i_mutex_key#15){+.+...}, at: [&lt;ffffffffa035f2ae&gt;] btrfs_sync_file+0x14e/0x425 [btrfs]
[23045.436044]  #1:  (sb_internal#2){.+.+.+}, at: [&lt;ffffffff8118446b&gt;] __sb_start_write+0x5f/0xb0
[23045.436044]  #2:  (&amp;ei-&gt;log_mutex){+.+...}, at: [&lt;ffffffffa038552d&gt;] btrfs_log_inode+0x13a/0xc95 [btrfs]
[23045.436044]
               stack backtrace:
[23045.436044] CPU: 4 PID: 3688 Comm: xfs_io Not tainted 4.7.0-rc6-btrfs-next-34+ #1
[23045.436044] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.1-0-gb3ef39f-prebuilt.qemu-project.org 04/01/2014
[23045.436044]  0000000000000000 ffff88022f5f7860 ffffffff8127074d ffffffff82a54b70
[23045.436044]  ffffffff82a54b70 ffff88022f5f7920 ffffffff81092897 ffff880228015d68
[23045.436044]  0000000000000000 ffffffff82a54b70 ffffffff829c3f00 ffff880228015d68
[23045.436044] Call Trace:
[23045.436044]  [&lt;ffffffff8127074d&gt;] dump_stack+0x67/0x90
[23045.436044]  [&lt;ffffffff81092897&gt;] __lock_acquire+0xcbb/0xe4e
[23045.436044]  [&lt;ffffffff8109155f&gt;] ? mark_lock+0x24/0x201
[23045.436044]  [&lt;ffffffff8109179a&gt;] ? mark_held_locks+0x5e/0x74
[23045.436044]  [&lt;ffffffff81092de0&gt;] lock_acquire+0x12f/0x1c3
[23045.436044]  [&lt;ffffffff81092de0&gt;] ? lock_acquire+0x12f/0x1c3
[23045.436044]  [&lt;ffffffffa038552d&gt;] ? btrfs_log_inode+0x13a/0xc95 [btrfs]
[23045.436044]  [&lt;ffffffffa038552d&gt;] ? btrfs_log_inode+0x13a/0xc95 [btrfs]
[23045.436044]  [&lt;ffffffff814a51a4&gt;] mutex_lock_nested+0x77/0x3a7
[23045.436044]  [&lt;ffffffffa038552d&gt;] ? btrfs_log_inode+0x13a/0xc95 [btrfs]
[23045.436044]  [&lt;ffffffffa039705e&gt;] ? btrfs_release_delayed_node+0xb/0xd [btrfs]
[23045.436044]  [&lt;ffffffffa038552d&gt;] btrfs_log_inode+0x13a/0xc95 [btrfs]
[23045.436044]  [&lt;ffffffffa038552d&gt;] ? btrfs_log_inode+0x13a/0xc95 [btrfs]
[23045.436044]  [&lt;ffffffff810a0ed1&gt;] ? vprintk_emit+0x453/0x465
[23045.436044]  [&lt;ffffffffa0385a61&gt;] btrfs_log_inode+0x66e/0xc95 [btrfs]
[23045.436044]  [&lt;ffffffffa03c084d&gt;] log_new_dir_dentries+0x26c/0x359 [btrfs]
[23045.436044]  [&lt;ffffffffa03865aa&gt;] btrfs_log_inode_parent+0x4a6/0x628 [btrfs]
[23045.436044]  [&lt;ffffffffa0387552&gt;] btrfs_log_dentry_safe+0x5a/0x75 [btrfs]
[23045.436044]  [&lt;ffffffffa035f464&gt;] btrfs_sync_file+0x304/0x425 [btrfs]
[23045.436044]  [&lt;ffffffff811acaf4&gt;] vfs_fsync_range+0x8c/0x9e
[23045.436044]  [&lt;ffffffff811acb22&gt;] vfs_fsync+0x1c/0x1e
[23045.436044]  [&lt;ffffffff811acc79&gt;] do_fsync+0x31/0x4a
[23045.436044]  [&lt;ffffffff811ace99&gt;] SyS_fsync+0x10/0x14
[23045.436044]  [&lt;ffffffff814a88e5&gt;] entry_SYSCALL_64_fastpath+0x18/0xa8
[23045.436044]  [&lt;ffffffff8108f039&gt;] ? trace_hardirqs_off_caller+0x3f/0xaa

An example reproducer for this is:

   $ mkfs.btrfs -f /dev/sdb
   $ mount /dev/sdb /mnt
   $ mkdir /mnt/dir
   $ touch /mnt/dir/foo
   $ sync
   $ mv /mnt/dir/foo /mnt/dir/bar
   $ touch /mnt/dir/foo
   $ xfs_io -c "fsync" /mnt/dir/bar

This is because while logging the inode of file bar we end up logging its
parent directory (since its inode has an unlink_trans field matching the
current transaction id due to the rename operation), which in turn logs
the inodes for all its new dentries, so that the new inode for the new
file named foo gets logged which in turn triggered another logging attempt
for the inode we are fsync'ing, since that inode had an old name that
corresponds to the name of the new inode.

So fix this by ensuring that when logging the inode for a new dentry that
has a name matching an old name of some other inode, we don't log again
the original inode that we are fsync'ing.

Fixes: 44f714dae50a ("Btrfs: improve performance on fsync against new inode after rename/unlink")
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>btrfs: update btrfs_space_info's bytes_may_use timely</title>
<updated>2016-08-25T10:58:26Z</updated>
<author>
<name>Wang Xiaoguang</name>
</author>
<published>2016-07-25T07:51:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=18513091af9483ba84328d42092bd4d42a3c958f'/>
<id>urn:sha1:18513091af9483ba84328d42092bd4d42a3c958f</id>
<content type='text'>
This patch can fix some false ENOSPC errors, below test script can
reproduce one false ENOSPC error:
	#!/bin/bash
	dd if=/dev/zero of=fs.img bs=$((1024*1024)) count=128
	dev=$(losetup --show -f fs.img)
	mkfs.btrfs -f -M $dev
	mkdir /tmp/mntpoint
	mount $dev /tmp/mntpoint
	cd /tmp/mntpoint
	xfs_io -f -c "falloc 0 $((64*1024*1024))" testfile

Above script will fail for ENOSPC reason, but indeed fs still has free
space to satisfy this request. Please see call graph:
btrfs_fallocate()
|-&gt; btrfs_alloc_data_chunk_ondemand()
|   bytes_may_use += 64M
|-&gt; btrfs_prealloc_file_range()
    |-&gt; btrfs_reserve_extent()
        |-&gt; btrfs_add_reserved_bytes()
        |   alloc_type is RESERVE_ALLOC_NO_ACCOUNT, so it does not
        |   change bytes_may_use, and bytes_reserved += 64M. Now
        |   bytes_may_use + bytes_reserved == 128M, which is greater
        |   than btrfs_space_info's total_bytes, false enospc occurs.
        |   Note, the bytes_may_use decrease operation will be done in
        |   end of btrfs_fallocate(), which is too late.

Here is another simple case for buffered write:
                    CPU 1              |              CPU 2
                                       |
|-&gt; cow_file_range()                   |-&gt; __btrfs_buffered_write()
    |-&gt; btrfs_reserve_extent()         |   |
    |                                  |   |
    |                                  |   |
    |    .....                         |   |-&gt; btrfs_check_data_free_space()
    |                                  |
    |                                  |
    |-&gt; extent_clear_unlock_delalloc() |

In CPU 1, btrfs_reserve_extent()-&gt;find_free_extent()-&gt;
btrfs_add_reserved_bytes() do not decrease bytes_may_use, the decrease
operation will be delayed to be done in extent_clear_unlock_delalloc().
Assume in this case, btrfs_reserve_extent() reserved 128MB data, CPU2's
btrfs_check_data_free_space() tries to reserve 100MB data space.
If
	100MB &gt; data_sinfo-&gt;total_bytes - data_sinfo-&gt;bytes_used -
		data_sinfo-&gt;bytes_reserved - data_sinfo-&gt;bytes_pinned -
		data_sinfo-&gt;bytes_readonly - data_sinfo-&gt;bytes_may_use
btrfs_check_data_free_space() will try to allcate new data chunk or call
btrfs_start_delalloc_roots(), or commit current transaction in order to
reserve some free space, obviously a lot of work. But indeed it's not
necessary as long as decreasing bytes_may_use timely, we still have
free space, decreasing 128M from bytes_may_use.

To fix this issue, this patch chooses to update bytes_may_use for both
data and metadata in btrfs_add_reserved_bytes(). For compress path, real
extent length may not be equal to file content length, so introduce a
ram_bytes argument for btrfs_reserve_extent(), find_free_extent() and
btrfs_add_reserved_bytes(), it's becasue bytes_may_use is increased by
file content length. Then compress path can update bytes_may_use
correctly. Also now we can discard RESERVE_ALLOC_NO_ACCOUNT, RESERVE_ALLOC
and RESERVE_FREE.

As we know, usually EXTENT_DO_ACCOUNTING is used for error path. In
run_delalloc_nocow(), for inode marked as NODATACOW or extent marked as
PREALLOC, we also need to update bytes_may_use, but can not pass
EXTENT_DO_ACCOUNTING, because it also clears metadata reservation, so
here we introduce EXTENT_CLEAR_DATA_RESV flag to indicate btrfs_clear_bit_hook()
to update btrfs_space_info's bytes_may_use.

Meanwhile __btrfs_prealloc_file_range() will call
btrfs_free_reserved_data_space() internally for both sucessful and failed
path, btrfs_prealloc_file_range()'s callers does not need to call
btrfs_free_reserved_data_space() any more.

Signed-off-by: Wang Xiaoguang &lt;wangxg.fnst@cn.fujitsu.com&gt;
Reviewed-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'integration-4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/fdmanana/linux into for-linus-4.8</title>
<updated>2016-08-05T19:25:05Z</updated>
<author>
<name>Chris Mason</name>
</author>
<published>2016-08-05T19:25:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=10838816547a28696ca10e038b3b32f2efec5a42'/>
<id>urn:sha1:10838816547a28696ca10e038b3b32f2efec5a42</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Btrfs: add missing check for writeback errors on fsync</title>
<updated>2016-08-01T06:21:13Z</updated>
<author>
<name>Filipe Manana</name>
</author>
<published>2016-06-14T13:18:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=0596a9048bf2aca2a74b312493f39e4d5ac3b653'/>
<id>urn:sha1:0596a9048bf2aca2a74b312493f39e4d5ac3b653</id>
<content type='text'>
When we start an fsync we start ordered extents for all delalloc ranges.
However before attempting to log the inode, we only wait for those ordered
extents if we are not doing a full sync (bit BTRFS_INODE_NEEDS_FULL_SYNC
is set in the inode's flags). This means that if an ordered extent
completes with an IO error before we check if we can skip logging the
inode, we will not catch and report the IO error to user space. This is
because on an IO error, when the ordered extent completes we do not
update the inode, so if the inode was not previously updated by the
current transaction we end up not logging it through calls to fsync and
therefore not check its mapping flags for the presence of IO errors.

Fix this by checking for errors in the flags of the inode's mapping when
we notice we can skip logging the inode.

This caused sporadic failures in the test generic/331 (which explicitly
tests for IO errors during an fsync call).

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: Liu Bo &lt;bo.li.liu@oracle.com&gt;
</content>
</entry>
<entry>
<title>btrfs: btrfs_abort_transaction, drop root parameter</title>
<updated>2016-07-26T11:54:26Z</updated>
<author>
<name>Jeff Mahoney</name>
</author>
<published>2016-06-10T22:19:25Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=66642832f06a4351e23cea6cf254967c227f8224'/>
<id>urn:sha1:66642832f06a4351e23cea6cf254967c227f8224</id>
<content type='text'>
__btrfs_abort_transaction doesn't use its root parameter except to
obtain an fs_info pointer.  We can obtain that from trans-&gt;root-&gt;fs_info
for now and from trans-&gt;fs_info in a later patch.

Signed-off-by: Jeff Mahoney &lt;jeffm@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: btrfs_test_opt and friends should take a btrfs_fs_info</title>
<updated>2016-07-26T11:53:16Z</updated>
<author>
<name>Jeff Mahoney</name>
</author>
<published>2016-06-10T01:38:35Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3cdde2240d4533ff71fbb8dc9c32d5d57d3cdeed'/>
<id>urn:sha1:3cdde2240d4533ff71fbb8dc9c32d5d57d3cdeed</id>
<content type='text'>
btrfs_test_opt and friends only use the root pointer to access
the fs_info.  Let's pass the fs_info directly in preparation to
eliminate similar patterns all over btrfs.

Signed-off-by: Jeff Mahoney &lt;jeffm@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: Fix slab accounting flags</title>
<updated>2016-07-26T11:52:25Z</updated>
<author>
<name>Nikolay Borisov</name>
</author>
<published>2016-06-23T18:17:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fba4b697710eb2a4bee456b9d39e9239c66f8bee'/>
<id>urn:sha1:fba4b697710eb2a4bee456b9d39e9239c66f8bee</id>
<content type='text'>
BTRFS is using a variety of slab caches to satisfy internal needs.
Those slab caches are always allocated with the SLAB_RECLAIM_ACCOUNT,
meaning allocations from the caches are going to be accounted as
SReclaimable. At the same time btrfs is not registering any shrinkers
whatsoever, thus preventing memory from the slabs to be shrunk. This
means those caches are not in fact reclaimable.

To fix this remove the SLAB_RECLAIM_ACCOUNT on all caches apart from the
inode cache, since this one is being freed by the generic VFS super_block
shrinker. Also set the transaction related caches as SLAB_TEMPORARY,
to better document the lifetime of the objects (it just translates
to SLAB_RECLAIM_ACCOUNT).

Signed-off-by: Nikolay Borisov &lt;n.borisov.lkml@gmail.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: fix delalloc accounting after copy_from_user faults</title>
<updated>2016-07-21T11:03:40Z</updated>
<author>
<name>Chris Mason</name>
</author>
<published>2016-07-19T12:52:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8b8b08cbfb9021af4b54b4175fc4c51d655aac8c'/>
<id>urn:sha1:8b8b08cbfb9021af4b54b4175fc4c51d655aac8c</id>
<content type='text'>
Commit 56244ef151c3cd11 was almost but not quite enough to fix the
reservation math after btrfs_copy_from_user returned partial copies.

Some users are still seeing warnings in btrfs_destroy_inode, and with a
long enough test run I'm able to trigger them as well.

This patch fixes the accounting math again, bringing it much closer to
the way it was before the sectorsize conversion Chandan did.  The
problem is accounting for the offset into the page/sector when we do a
partial copy.  This one just uses the dirty_sectors variable which
should already be updated properly.

Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
cc: stable@vger.kernel.org # v4.6+
</content>
</entry>
<entry>
<title>Btrfs: fix callers of btrfs_block_rsv_migrate</title>
<updated>2016-07-07T16:45:53Z</updated>
<author>
<name>Josef Bacik</name>
</author>
<published>2016-03-25T17:25:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=25d609f86d6808eb1f0e8a6cafc3edb4a2b5ae35'/>
<id>urn:sha1:25d609f86d6808eb1f0e8a6cafc3edb4a2b5ae35</id>
<content type='text'>
So btrfs_block_rsv_migrate just unconditionally calls block_rsv_migrate_bytes.
Not only this but it unconditionally changes the size of the block_rsv.  This
isn't a bug strictly speaking, but it makes truncate block rsv's look funny
because every time we migrate bytes over its size grows, even though we only
want it to be a specific size.  So collapse this into one function that takes an
update_size argument and make truncate and evict not update the size for
consistency sake.  Thanks,

Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'for-linus-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs</title>
<updated>2016-06-25T15:42:31Z</updated>
<author>
<name>Linus Torvalds</name>
</author>
<published>2016-06-25T15:42:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b971712afc8dd0de38e943ea9d904fe8c8aff956'/>
<id>urn:sha1:b971712afc8dd0de38e943ea9d904fe8c8aff956</id>
<content type='text'>
Pull btrfs fixes from Chris Mason:
 "I have a two part pull this time because one of the patches Dave
  Sterba collected needed to be against v4.7-rc2 or higher (we used
  rc4).  I try to make my for-linus-xx branch testable on top of the
  last major so we can hand fixes to people on the list more easily, so
  I've split this pull in two.

  This first part has some fixes and two performance improvements that
  we've been testing for some time.

  Josef's two performance fixes are most notable.  The transid tracking
  patch makes a big improvement on pretty much every workload"

* 'for-linus-4.7' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs:
  Btrfs: Force stripesize to the value of sectorsize
  btrfs: fix disk_i_size update bug when fallocate() fails
  Btrfs: fix error handling in map_private_extent_buffer
  Btrfs: fix error return code in btrfs_init_test_fs()
  Btrfs: don't do nocow check unless we have to
  btrfs: fix deadlock in delayed_ref_async_start
  Btrfs: track transid for delayed ref flushing
</content>
</entry>
</feed>
