<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/btrfs/ctree.c, branch linux-3.14.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-3.14.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-3.14.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2015-07-04T02:49:05Z</updated>
<entry>
<title>Btrfs: make xattr replace operations atomic</title>
<updated>2015-07-04T02:49:05Z</updated>
<author>
<name>Filipe Manana</name>
</author>
<published>2014-11-09T08:38:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=02590fd855d1690568b2fa439c942e933221b57a'/>
<id>urn:sha1:02590fd855d1690568b2fa439c942e933221b57a</id>
<content type='text'>
commit 5f5bc6b1e2d5a6f827bc860ef2dc5b6f365d1339 upstream.

Replacing a xattr consists of doing a lookup for its existing value, delete
the current value from the respective leaf, release the search path and then
finally insert the new value. This leaves a time window where readers (getxattr,
listxattrs) won't see any value for the xattr. Xattrs are used to store ACLs,
so this has security implications.

This change also fixes 2 other existing issues which were:

*) Deleting the old xattr value without verifying first if the new xattr will
   fit in the existing leaf item (in case multiple xattrs are packed in the
   same item due to name hash collision);

*) Returning -EEXIST when the flag XATTR_CREATE is given and the xattr doesn't
   exist but we have have an existing item that packs muliple xattrs with
   the same name hash as the input xattr. In this case we should return ENOSPC.

A test case for xfstests follows soon.

Thanks to Alexandre Oliva for reporting the non-atomicity of the xattr replace
implementation.

Reported-by: Alexandre Oliva &lt;oliva@gnu.org&gt;
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>btrfs: fix leak of path in btrfs_find_item</title>
<updated>2015-03-06T22:43:32Z</updated>
<author>
<name>David Sterba</name>
</author>
<published>2015-01-02T17:45:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f9e2ba638c32dff17ee6404e2c8245fd49d99b8b'/>
<id>urn:sha1:f9e2ba638c32dff17ee6404e2c8245fd49d99b8b</id>
<content type='text'>
commit 381cf6587f8a8a8e981bc0c1aaaa8859b51dc756 upstream.

If btrfs_find_item is called with NULL path it allocates one locally but
does not free it. Affected paths are inserting an orphan item for a file
and for a subvol root.

Move the path allocation to the callers.

Fixes: 3f870c289900 ("btrfs: expand btrfs_find_item() to include find_orphan_item functionality")
Signed-off-by: David Sterba &lt;dsterba@suse.cz&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>Btrfs: fix btrfs_search_slot_for_read backwards iteration</title>
<updated>2014-01-29T15:06:28Z</updated>
<author>
<name>Filipe David Borba Manana</name>
</author>
<published>2014-01-11T21:28:54Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=23c6bf6a91e96c17a452e07b12b38ed66504e799'/>
<id>urn:sha1:23c6bf6a91e96c17a452e07b12b38ed66504e799</id>
<content type='text'>
If the current path's leaf slot is 0, we do search for the previous
leaf (via btrfs_prev_leaf) and set the new path's leaf slot to a
value corresponding to the number of items - 1 of the former leaf.
Fix this by using the slot set by btrfs_prev_leaf, decrementing it
by 1 if it's equal to the leaf's number of items.

Use of btrfs_search_slot_for_read() for backward iteration is used in
particular by the send feature, which could miss items when the input
leaf has less items than its previous leaf.

This could be reproduced by running btrfs/007 from xfstests in a loop.

Signed-off-by: Filipe David Borba Manana &lt;fdmanana@gmail.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: fix to search previous metadata extent item since skinny metadata</title>
<updated>2014-01-28T21:20:33Z</updated>
<author>
<name>Wang Shilong</name>
</author>
<published>2014-01-12T13:38:33Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ade2e0b3eeca941a5cd486bac21599ff87f288c8'/>
<id>urn:sha1:ade2e0b3eeca941a5cd486bac21599ff87f288c8</id>
<content type='text'>
There is a bug that using btrfs_previous_item() to search metadata extent item.
This is because in btrfs_previous_item(), we need type match, however, since
skinny metada was introduced by josef, we may mix this two types. So just
use btrfs_previous_item() is not working right.

To keep btrfs_previous_item() like normal tree search, i introduce another
function btrfs_previous_extent_item().

Signed-off-by: Wang Shilong &lt;wangsl.fnst@cn.fujitsu.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: reduce btree node locking duration on item update</title>
<updated>2014-01-28T21:20:11Z</updated>
<author>
<name>Filipe David Borba Manana</name>
</author>
<published>2013-12-23T11:53:02Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=eb653de15987612444b6cde3b0e67b1edd94625f'/>
<id>urn:sha1:eb653de15987612444b6cde3b0e67b1edd94625f</id>
<content type='text'>
If we do a btree search with the goal of updating an existing item
without changing its size (ins_len == 0 and cow == 1), then we never
need to hold locks on upper level nodes (even when slot == 0) after we
COW their child nodes/leaves, as we won't have node splits or merges
in this scenario (that is, no key additions, removals or shifts on any
nodes or leaves).

Therefore release the locks immediately after COWing the child nodes/leaves
while navigating the btree, even if their parent slot is 0, instead of
returning a path to the caller with those nodes locked, which would get
released only when the caller releases or frees the path (or if it calls
btrfs_unlock_up_safe).

This is a common scenario, for example when updating inode items in fs
trees and block group items in the extent tree.

The following benchmarks were performed on a quad core machine with 32Gb
of ram, using a leaf/node size of 4Kb (to generate deeper fs trees more
quickly).

  sysbench --test=fileio --file-num=131072 --file-total-size=8G \
    --file-test-mode=seqwr --num-threads=512 --file-block-size=8192 \
    --max-requests=100000 --file-io-mode=sync [prepare|run]

Before this change:  49.85Mb/s (average of 5 runs)
After this change:   50.38Mb/s (average of 5 runs)

Signed-off-by: Filipe David Borba Manana &lt;fdmanana@gmail.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: convert printk to btrfs_ and fix BTRFS prefix</title>
<updated>2014-01-28T21:20:05Z</updated>
<author>
<name>Frank Holton</name>
</author>
<published>2013-12-20T16:37:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=efe120a067c8674a8ae21b194f0e68f098b61ee2'/>
<id>urn:sha1:efe120a067c8674a8ae21b194f0e68f098b61ee2</id>
<content type='text'>
Convert all applicable cases of printk and pr_* to the btrfs_* macros.

Fix all uses of the BTRFS prefix.

Signed-off-by: Frank Holton &lt;fholton@gmail.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: fix tree mod logging</title>
<updated>2014-01-28T21:20:04Z</updated>
<author>
<name>Filipe David Borba Manana</name>
</author>
<published>2013-12-20T15:17:46Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5de865eebb8330eee19c37b31fb6f315a09d4273'/>
<id>urn:sha1:5de865eebb8330eee19c37b31fb6f315a09d4273</id>
<content type='text'>
While running the test btrfs/004 from xfstests in a loop, it failed
about 1 time out of 20 runs in my desktop. The failure happened in
the backref walking part of the test, and the test's error message was
like this:

  btrfs/004 93s ... [failed, exit status 1] - output mismatch (see /home/fdmanana/git/hub/xfstests_2/results//btrfs/004.out.bad)
      --- tests/btrfs/004.out	2013-11-26 18:25:29.263333714 +0000
      +++ /home/fdmanana/git/hub/xfstests_2/results//btrfs/004.out.bad	2013-12-10 15:25:10.327518516 +0000
      @@ -1,3 +1,8 @@
       QA output created by 004
       *** test backref walking
      -*** done
      +unexpected output from
      +	/home/fdmanana/git/hub/btrfs-progs/btrfs inspect-internal logical-resolve -P 141512704 /home/fdmanana/btrfs-tests/scratch_1
      +expected inum: 405, expected address: 454656, file: /home/fdmanana/btrfs-tests/scratch_1/snap1/p0/d6/d3d/d156/fce, got:
      +
       ...
       (Run 'diff -u tests/btrfs/004.out /home/fdmanana/git/hub/xfstests_2/results//btrfs/004.out.bad' to see the entire diff)
  Ran: btrfs/004
  Failures: btrfs/004
  Failed 1 of 1 tests

But immediately after the test finished, the btrfs inspect-internal command
returned the expected output:

  $ btrfs inspect-internal logical-resolve -P 141512704 /home/fdmanana/btrfs-tests/scratch_1
  inode 405 offset 454656 root 258
  inode 405 offset 454656 root 5

It turned out this was because the btrfs_search_old_slot() calls performed
during backref walking (backref.c:__resolve_indirect_ref) were not finding
anything. The reason for this turned out to be that the tree mod logging
code was not logging some node multi-step operations atomically, therefore
btrfs_search_old_slot() callers iterated often over an incomplete tree that
wasn't fully consistent with any tree state from the past. Besides missing
items, this often (but not always) resulted in -EIO errors during old slot
searches, reported in dmesg like this:

[ 4299.933936] ------------[ cut here ]------------
[ 4299.933949] WARNING: CPU: 0 PID: 23190 at fs/btrfs/ctree.c:1343 btrfs_search_old_slot+0x57b/0xab0 [btrfs]()
[ 4299.933950] Modules linked in: btrfs raid6_pq xor pci_stub vboxpci(O) vboxnetadp(O) vboxnetflt(O) vboxdrv(O) bnep rfcomm bluetooth parport_pc ppdev binfmt_misc joydev snd_hda_codec_h
[ 4299.933977] CPU: 0 PID: 23190 Comm: btrfs Tainted: G        W  O 3.12.0-fdm-btrfs-next-16+ #70
[ 4299.933978] Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./Z77 Pro4, BIOS P1.50 09/04/2012
[ 4299.933979]  000000000000053f ffff8806f3fd98f8 ffffffff8176d284 0000000000000007
[ 4299.933982]  0000000000000000 ffff8806f3fd9938 ffffffff8104a81c ffff880659c64b70
[ 4299.933984]  ffff880659c643d0 ffff8806599233d8 ffff880701e2e938 0000160000000000
[ 4299.933987] Call Trace:
[ 4299.933991]  [&lt;ffffffff8176d284&gt;] dump_stack+0x55/0x76
[ 4299.933994]  [&lt;ffffffff8104a81c&gt;] warn_slowpath_common+0x8c/0xc0
[ 4299.933997]  [&lt;ffffffff8104a86a&gt;] warn_slowpath_null+0x1a/0x20
[ 4299.934003]  [&lt;ffffffffa065d3bb&gt;] btrfs_search_old_slot+0x57b/0xab0 [btrfs]
[ 4299.934005]  [&lt;ffffffff81775f3b&gt;] ? _raw_read_unlock+0x2b/0x50
[ 4299.934010]  [&lt;ffffffffa0655001&gt;] ? __tree_mod_log_search+0x81/0xc0 [btrfs]
[ 4299.934019]  [&lt;ffffffffa06dd9b0&gt;] __resolve_indirect_refs+0x130/0x5f0 [btrfs]
[ 4299.934027]  [&lt;ffffffffa06a21f1&gt;] ? free_extent_buffer+0x61/0xc0 [btrfs]
[ 4299.934034]  [&lt;ffffffffa06de39c&gt;] find_parent_nodes+0x1fc/0xe40 [btrfs]
[ 4299.934042]  [&lt;ffffffffa06b13e0&gt;] ? defrag_lookup_extent+0xe0/0xe0 [btrfs]
[ 4299.934048]  [&lt;ffffffffa06b13e0&gt;] ? defrag_lookup_extent+0xe0/0xe0 [btrfs]
[ 4299.934056]  [&lt;ffffffffa06df980&gt;] iterate_extent_inodes+0xe0/0x250 [btrfs]
[ 4299.934058]  [&lt;ffffffff817762db&gt;] ? _raw_spin_unlock+0x2b/0x50
[ 4299.934065]  [&lt;ffffffffa06dfb82&gt;] iterate_inodes_from_logical+0x92/0xb0 [btrfs]
[ 4299.934071]  [&lt;ffffffffa06b13e0&gt;] ? defrag_lookup_extent+0xe0/0xe0 [btrfs]
[ 4299.934078]  [&lt;ffffffffa06b7015&gt;] btrfs_ioctl+0xf65/0x1f60 [btrfs]
[ 4299.934080]  [&lt;ffffffff811658b8&gt;] ? handle_mm_fault+0x278/0xb00
[ 4299.934083]  [&lt;ffffffff81075563&gt;] ? up_read+0x23/0x40
[ 4299.934085]  [&lt;ffffffff8177a41c&gt;] ? __do_page_fault+0x20c/0x5a0
[ 4299.934088]  [&lt;ffffffff811b2946&gt;] do_vfs_ioctl+0x96/0x570
[ 4299.934090]  [&lt;ffffffff81776e23&gt;] ? error_sti+0x5/0x6
[ 4299.934093]  [&lt;ffffffff810b71e8&gt;] ? trace_hardirqs_off_caller+0x28/0xd0
[ 4299.934096]  [&lt;ffffffff81776a09&gt;] ? retint_swapgs+0xe/0x13
[ 4299.934098]  [&lt;ffffffff811b2eb1&gt;] SyS_ioctl+0x91/0xb0
[ 4299.934100]  [&lt;ffffffff813eecde&gt;] ? trace_hardirqs_on_thunk+0x3a/0x3f
[ 4299.934102]  [&lt;ffffffff8177ef12&gt;] system_call_fastpath+0x16/0x1b
[ 4299.934102]  [&lt;ffffffff8177ef12&gt;] system_call_fastpath+0x16/0x1b
[ 4299.934104] ---[ end trace 48f0cfc902491414 ]---
[ 4299.934378] btrfs bad fsid on block 0

These tree mod log operations that must be performed atomically, tree_mod_log_free_eb,
tree_mod_log_eb_copy, tree_mod_log_insert_root and tree_mod_log_insert_move, used to
be performed atomically before the following commit:

  c8cc6341653721b54760480b0d0d9b5f09b46741
  (Btrfs: stop using GFP_ATOMIC for the tree mod log allocations)

That change removed the atomicity of such operations. This patch restores the
atomicity while still not doing the GFP_ATOMIC allocations of tree_mod_elem
structures, so it has to do the allocations using GFP_NOFS before acquiring
the mod log lock.

This issue has been experienced by several users recently, such as for example:

  http://www.spinics.net/lists/linux-btrfs/msg28574.html

After running the btrfs/004 test for 679 consecutive iterations with this
patch applied, I didn't ran into the issue anymore.

Cc: stable@vger.kernel.org
Signed-off-by: Filipe David Borba Manana &lt;fdmanana@gmail.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: return immediately if tree log mod is not necessary</title>
<updated>2014-01-28T21:19:56Z</updated>
<author>
<name>Filipe David Borba Manana</name>
</author>
<published>2013-12-12T19:19:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=783577663507411e36e459390ef056556e93ef29'/>
<id>urn:sha1:783577663507411e36e459390ef056556e93ef29</id>
<content type='text'>
In ctree.c:tree_mod_log_set_node_key() we were calling
__tree_mod_log_insert_key() even when the modification doesn't need
to be logged. This would allocate a tree_mod_elem structure, fill it
and pass it to  __tree_mod_log_insert(), which would just acquire
the tree mod log write lock and then free the tree_mod_elem structure
and return (that is, a no-op).

Therefore call tree_mod_log_insert() instead of __tree_mod_log_insert()
which just returns immediately if the modification doesn't need to be
logged (without allocating the structure, fill it, acquire write lock,
free structure).

Signed-off-by: Filipe David Borba Manana &lt;fdmanana@gmail.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: more efficient push_leaf_right</title>
<updated>2014-01-28T21:19:53Z</updated>
<author>
<name>Filipe David Borba Manana</name>
</author>
<published>2013-12-04T22:17:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2ef1fed285d58e77ce777d9a525fed4788b5a6d0'/>
<id>urn:sha1:2ef1fed285d58e77ce777d9a525fed4788b5a6d0</id>
<content type='text'>
Currently when finding the leaf to insert a key into a btree, if the
leaf doesn't have enough space to store the item we attempt to move
off some items from our leaf to its right neighbor leaf, and if this
fails to create enough free space in our leaf, we try to move off more
items to the left neighbor leaf as well.

When trying to move off items to the right neighbor leaf, if it has
enough room to store the new key but not not enough room to move off
at least one item from our target leaf, __push_leaf_right returns 1 and
we have to attempt to move items to the left neighbor (push_leaf_left
function) without touching the right neighbor leaf.
For the case where the right leaf has enough room to store at least 1
item from our leaf, we end up modifying (and dirtying) both our leaf
and the right leaf. This is non-optimal for the case where the new key
is greater than any key in our target leaf because it can be inserted at
slot 0 of the right neighbor leaf and we don't need to touch our leaf
at all nor to attempt to move off items to the left neighbor leaf.

Therefore this change just selects the right neighbor leaf as our new
target leaf if it has enough room for the new key without modifying our
initial target leaf - we do this only if the new key is higher than any
key in the initial target leaf.

While running the following test, push_leaf_right was called by split_leaf
4802 times. Out of those 4802 calls, for 2571 calls (53.5%) we hit this
special case (right leaf has enough room and new key is higher than any key
in the initial target leaf).

Test:

  sysbench --test=fileio --file-num=512 --file-total-size=5G \
    --file-test-mode=[seqwr|rndwr] --num-threads=512 --file-block-size=8192 \
    --max-requests=100000 --file-io-mode=sync [prepare|run]

Results:

sequential writes

Throughput before this change: 65.71Mb/sec (average of 10 runs)
Throughput after this change:  66.58Mb/sec (average of 10 runs)

random writes

Throughput before this change: 10.75Mb/sec (average of 10 runs)
Throughput after this change:  11.56Mb/sec (average of 10 runs)

Signed-off-by: Filipe David Borba Manana &lt;fdmanana@gmail.com&gt;
Reviewed-by: Liu Bo &lt;bo.li.liu@oracle.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: try harder to avoid btree node splits</title>
<updated>2014-01-28T21:19:46Z</updated>
<author>
<name>Filipe David Borba Manana</name>
</author>
<published>2013-11-25T03:20:46Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5a4267ca20d4c452a97dace4612f1dfc04147fbd'/>
<id>urn:sha1:5a4267ca20d4c452a97dace4612f1dfc04147fbd</id>
<content type='text'>
When attempting to move items from our target leaf to its neighbor
leaves (right and left), we only need to free data_size - free_space
bytes from our leaf in order to add the new item (which has size of
data_size bytes). Therefore attempt to move items to the right and
left leaves if they have at least data_size - free_space bytes free,
instead of data_size bytes free.

After 5 runs of the following test, I got a smaller number of btree
node splits overall:

sysbench --test=fileio --file-num=512 --file-total-size=5G \
  --file-test-mode=seqwr --num-threads=512 \
   --file-block-size=8192 --max-requests=100000 --file-io-mode=sync

Before this change:
* 6171 splits (average of 5 test runs)
* 61.508Mb/sec of throughput (average of 5 test runs)

After this change:
* 6036 splits (average of 5 test runs)
* 63.533Mb/sec of throughput (average of 5 test runs)

An ideal test would not just have multiple threads/processes writing
to a file (insertion of file extent items) but also do other operations
that result in insertion of items with varied sizes, like file/directory
creations, creation of links, symlinks, xattrs, etc.

Signed-off-by: Filipe David Borba Manana &lt;fdmanana@gmail.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fb.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
</feed>
