<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/fs/btrfs/tree-defrag.c, branch v5.11</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>btrfs: locking: remove all the blocking helpers</title>
<updated>2020-12-08T14:54:01+00:00</updated>
<author>
<name>Josef Bacik</name>
<email>josef@toxicpanda.com</email>
</author>
<published>2020-08-20T15:46:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=ac5887c8e013d6754d36e6d51dc03448ee0b0065'/>
<id>ac5887c8e013d6754d36e6d51dc03448ee0b0065</id>
<content type='text'>
Now that we're using a rw_semaphore we no longer need to indicate if a
lock is blocking or not, nor do we need to flip the entire path from
blocking to spinning.  Remove these helpers and all the places they are
called.

Signed-off-by: Josef Bacik &lt;josef@toxicpanda.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Now that we're using a rw_semaphore we no longer need to indicate if a
lock is blocking or not, nor do we need to flip the entire path from
blocking to spinning.  Remove these helpers and all the places they are
called.

Signed-off-by: Josef Bacik &lt;josef@toxicpanda.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: remove unused btrfs_root::defrag_trans_start</title>
<updated>2020-07-27T10:55:28+00:00</updated>
<author>
<name>David Sterba</name>
<email>dsterba@suse.com</email>
</author>
<published>2020-06-23T19:23:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=a2570ef330b959eb37e3a437b9884d9cc4b6a3d9'/>
<id>a2570ef330b959eb37e3a437b9884d9cc4b6a3d9</id>
<content type='text'>
Last touched in 2013 by commit de78b51a2852 ("btrfs: remove cache only
arguments from defrag path") that was the only code that used the value.
Now it's only set but never used for anything, so we can remove it.

Reviewed-by: Nikolay Borisov &lt;nborisov@suse.com&gt;
Reviewed-by: Anand Jain &lt;anand.jain@oracle.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Last touched in 2013 by commit de78b51a2852 ("btrfs: remove cache only
arguments from defrag path") that was the only code that used the value.
Now it's only set but never used for anything, so we can remove it.

Reviewed-by: Nikolay Borisov &lt;nborisov@suse.com&gt;
Reviewed-by: Anand Jain &lt;anand.jain@oracle.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: rename BTRFS_ROOT_REF_COWS to BTRFS_ROOT_SHAREABLE</title>
<updated>2020-05-25T09:25:35+00:00</updated>
<author>
<name>Qu Wenruo</name>
<email>wqu@suse.com</email>
</author>
<published>2020-05-15T06:01:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=92a7cc4252231d1641b36c38cf845cfc50308ab0'/>
<id>92a7cc4252231d1641b36c38cf845cfc50308ab0</id>
<content type='text'>
The name BTRFS_ROOT_REF_COWS is not very clear about the meaning.

In fact, that bit can only be set to those trees:

- Subvolume roots
- Data reloc root
- Reloc roots for above roots

All other trees won't get this bit set.  So just by the result, it is
obvious that, roots with this bit set can have tree blocks shared with
other trees.  Either shared by snapshots, or by reloc roots (an special
snapshot created by relocation).

This patch will rename BTRFS_ROOT_REF_COWS to BTRFS_ROOT_SHAREABLE to
make it easier to understand, and update all comment mentioning
"reference counted" to follow the rename.

Signed-off-by: Qu Wenruo &lt;wqu@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The name BTRFS_ROOT_REF_COWS is not very clear about the meaning.

In fact, that bit can only be set to those trees:

- Subvolume roots
- Data reloc root
- Reloc roots for above roots

All other trees won't get this bit set.  So just by the result, it is
obvious that, roots with this bit set can have tree blocks shared with
other trees.  Either shared by snapshots, or by reloc roots (an special
snapshot created by relocation).

This patch will rename BTRFS_ROOT_REF_COWS to BTRFS_ROOT_SHAREABLE to
make it easier to understand, and update all comment mentioning
"reference counted" to follow the rename.

Signed-off-by: Qu Wenruo &lt;wqu@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: open code now trivial btrfs_set_lock_blocking</title>
<updated>2019-02-25T13:13:27+00:00</updated>
<author>
<name>David Sterba</name>
<email>dsterba@suse.com</email>
</author>
<published>2018-04-04T00:03:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=8bead258206f4d4f485ad55bc1e39d23bbfe2fdd'/>
<id>8bead258206f4d4f485ad55bc1e39d23bbfe2fdd</id>
<content type='text'>
btrfs_set_lock_blocking is now only a simple wrapper around
btrfs_set_lock_blocking_write. The name does not bring any semantic
value that could not be inferred from the new function so there's no
point keeping it.

Reviewed-by: Johannes Thumshirn &lt;jthumshirn@suse.de&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
btrfs_set_lock_blocking is now only a simple wrapper around
btrfs_set_lock_blocking_write. The name does not bring any semantic
value that could not be inferred from the new function so there's no
point keeping it.

Reviewed-by: Johannes Thumshirn &lt;jthumshirn@suse.de&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: replace GPL boilerplate by SPDX -- sources</title>
<updated>2018-04-12T14:29:51+00:00</updated>
<author>
<name>David Sterba</name>
<email>dsterba@suse.com</email>
</author>
<published>2018-04-03T17:23:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=c1d7c514f745628eb096c5cbb10737855879ae25'/>
<id>c1d7c514f745628eb096c5cbb10737855879ae25</id>
<content type='text'>
Remove GPL boilerplate text (long, short, one-line) and keep the rest,
ie. personal, company or original source copyright statements. Add the
SPDX header.

Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Remove GPL boilerplate text (long, short, one-line) and keep the rest,
ie. personal, company or original source copyright statements. Add the
SPDX header.

Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: add define for oldest generation</title>
<updated>2018-03-30T23:26:50+00:00</updated>
<author>
<name>Anand Jain</name>
<email>anand.jain@oracle.com</email>
</author>
<published>2018-03-07T09:29:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7c829b722dffb22aaf9e3ea1b1d88dac49bd0768'/>
<id>7c829b722dffb22aaf9e3ea1b1d88dac49bd0768</id>
<content type='text'>
Some functions can filter metadata by the generation. Add a define that
will annotate such arguments.

Signed-off-by: Anand Jain &lt;anand.jain@oracle.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
[ update changelog ]
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Some functions can filter metadata by the generation. Add a define that
will annotate such arguments.

Signed-off-by: Anand Jain &lt;anand.jain@oracle.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
[ update changelog ]
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: fix locking bugs when defragging leaves</title>
<updated>2015-12-18T02:51:32+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-12-18T01:57:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0376374a98abd533fb49c6db12967bddc2f4b4b3'/>
<id>0376374a98abd533fb49c6db12967bddc2f4b4b3</id>
<content type='text'>
When running fstests btrfs/070, with a higher number of fsstress
operations, I ran frequently into two different locking bugs when
defragging directories.

The first bug produced the following traces:

[133860.229792] ------------[ cut here ]------------
[133860.251062] WARNING: CPU: 2 PID: 26057 at fs/btrfs/locking.c:46 btrfs_set_lock_blocking_rw+0x57/0xbd [btrfs]()
[133860.253576] Modules linked in: btrfs crc32c_generic xor raid6_pq nfsd auth_rpcgss oid_registry nfs_acl nfs lockd grace fscache sunrpc loop fuse parport_pc i2c_piix4 psmouse parport
[133860.282566] CPU: 2 PID: 26057 Comm: btrfs Tainted: G        W       4.3.0-rc5-btrfs-next-17+ #1
[133860.284393] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.8.1-0-g4adadbd-20150316_085822-nilsson.home.kraxel.org 04/01/2014
[133860.286827]  0000000000000000 ffff880207697b78 ffffffff812566f4 0000000000000000
[133860.288341]  ffff880207697bb0 ffffffff8104d0a6 ffffffffa052d4c1 ffff880178f60e00
[133860.294219]  ffff880178f60e00 0000000000000000 00000000000000f6 ffff880207697bc0
[133860.295831] Call Trace:
[133860.306518]  [&lt;ffffffff812566f4&gt;] dump_stack+0x4e/0x79
[133860.307473]  [&lt;ffffffff8104d0a6&gt;] warn_slowpath_common+0x9f/0xb8
[133860.308619]  [&lt;ffffffffa052d4c1&gt;] ? btrfs_set_lock_blocking_rw+0x57/0xbd [btrfs]
[133860.310068]  [&lt;ffffffff8104d172&gt;] warn_slowpath_null+0x1a/0x1c
[133860.312552]  [&lt;ffffffffa052d4c1&gt;] btrfs_set_lock_blocking_rw+0x57/0xbd [btrfs]
[133860.314630]  [&lt;ffffffffa04d5787&gt;] btrfs_set_lock_blocking+0xe/0x10 [btrfs]
[133860.323596]  [&lt;ffffffffa04d99cb&gt;] btrfs_realloc_node+0xb3/0x341 [btrfs]
[133860.325233]  [&lt;ffffffffa050e396&gt;] btrfs_defrag_leaves+0x239/0x2fa [btrfs]
[133860.332427]  [&lt;ffffffffa04fc2ce&gt;] btrfs_defrag_root+0x63/0xca [btrfs]
[133860.337259]  [&lt;ffffffffa052a34e&gt;] btrfs_ioctl_defrag+0x78/0x14e [btrfs]
[133860.340147]  [&lt;ffffffffa052b00b&gt;] btrfs_ioctl+0x746/0x24c6 [btrfs]
[133860.344833]  [&lt;ffffffff81087481&gt;] ? arch_local_irq_save+0x9/0xc
[133860.346343]  [&lt;ffffffff8113ad61&gt;] ? __might_fault+0x4c/0xa7
[133860.353248]  [&lt;ffffffff8113ad61&gt;] ? __might_fault+0x4c/0xa7
[133860.354242]  [&lt;ffffffff8113adba&gt;] ? __might_fault+0xa5/0xa7
[133860.355232]  [&lt;ffffffff81171139&gt;] ? cp_new_stat+0x15d/0x174
[133860.356237]  [&lt;ffffffff8117c610&gt;] do_vfs_ioctl+0x427/0x4e6
[133860.358587]  [&lt;ffffffff81171175&gt;] ? SYSC_newfstat+0x25/0x2e
[133860.360195]  [&lt;ffffffff8118574d&gt;] ? __fget_light+0x4d/0x71
[133860.361380]  [&lt;ffffffff8117c726&gt;] SyS_ioctl+0x57/0x79
[133860.363578]  [&lt;ffffffff8147cd97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6f
[133860.366217] ---[ end trace 2cadb2f653437e49 ]---
[133860.367399] ------------[ cut here ]------------
[133860.368162] kernel BUG at fs/btrfs/locking.c:307!
[133860.369430] invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
[133860.370205] Modules linked in: btrfs crc32c_generic xor raid6_pq nfsd auth_rpcgss oid_registry nfs_acl nfs lockd grace fscache sunrpc loop fuse parport_pc i2c_piix4 psmouse parport
[133860.370205] CPU: 2 PID: 26057 Comm: btrfs Tainted: G        W       4.3.0-rc5-btrfs-next-17+ #1
[133860.370205] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.8.1-0-g4adadbd-20150316_085822-nilsson.home.kraxel.org 04/01/2014
[133860.370205] task: ffff8800aec6db40 ti: ffff880207694000 task.ti: ffff880207694000
[133860.370205] RIP: 0010:[&lt;ffffffffa052d466&gt;]  [&lt;ffffffffa052d466&gt;] btrfs_assert_tree_locked+0x10/0x14 [btrfs]
[133860.370205] RSP: 0018:ffff880207697bc0  EFLAGS: 00010246
[133860.370205] RAX: 0000000000000000 RBX: ffff880178f60e00 RCX: 0000000000000000
[133860.370205] RDX: ffff88023ec4fb50 RSI: 00000000ffffffff RDI: ffff880178f60e00
[133860.370205] RBP: ffff880207697bc0 R08: 0000000000000001 R09: 0000000000000000
[133860.370205] R10: 0000160000000000 R11: ffffffff81651000 R12: ffff880178f60e00
[133860.370205] R13: 0000000000000000 R14: 00000000000000f6 R15: ffff8801ff409000
[133860.370205] FS:  00007f763efd48c0(0000) GS:ffff88023ec40000(0000) knlGS:0000000000000000
[133860.370205] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[133860.370205] CR2: 0000000002158048 CR3: 000000003fd6c000 CR4: 00000000000006e0
[133860.370205] Stack:
[133860.370205]  ffff880207697bd8 ffffffffa052d4d0 0000000000000000 ffff880207697be8
[133860.370205]  ffffffffa04d5787 ffff880207697c80 ffffffffa04d99cb ffff8801ff409590
[133860.370205]  ffff880207697ca8 000000f507697c80 ffff880183c11bb8 0000000000000000
[133860.370205] Call Trace:
[133860.370205]  [&lt;ffffffffa052d4d0&gt;] btrfs_set_lock_blocking_rw+0x66/0xbd [btrfs]
[133860.370205]  [&lt;ffffffffa04d5787&gt;] btrfs_set_lock_blocking+0xe/0x10 [btrfs]
[133860.370205]  [&lt;ffffffffa04d99cb&gt;] btrfs_realloc_node+0xb3/0x341 [btrfs]
[133860.370205]  [&lt;ffffffffa050e396&gt;] btrfs_defrag_leaves+0x239/0x2fa [btrfs]
[133860.370205]  [&lt;ffffffffa04fc2ce&gt;] btrfs_defrag_root+0x63/0xca [btrfs]
[133860.370205]  [&lt;ffffffffa052a34e&gt;] btrfs_ioctl_defrag+0x78/0x14e [btrfs]
[133860.370205]  [&lt;ffffffffa052b00b&gt;] btrfs_ioctl+0x746/0x24c6 [btrfs]
[133860.370205]  [&lt;ffffffff81087481&gt;] ? arch_local_irq_save+0x9/0xc
[133860.370205]  [&lt;ffffffff8113ad61&gt;] ? __might_fault+0x4c/0xa7
[133860.370205]  [&lt;ffffffff8113ad61&gt;] ? __might_fault+0x4c/0xa7
[133860.370205]  [&lt;ffffffff8113adba&gt;] ? __might_fault+0xa5/0xa7
[133860.370205]  [&lt;ffffffff81171139&gt;] ? cp_new_stat+0x15d/0x174
[133860.370205]  [&lt;ffffffff8117c610&gt;] do_vfs_ioctl+0x427/0x4e6
[133860.370205]  [&lt;ffffffff81171175&gt;] ? SYSC_newfstat+0x25/0x2e
[133860.370205]  [&lt;ffffffff8118574d&gt;] ? __fget_light+0x4d/0x71
[133860.370205]  [&lt;ffffffff8117c726&gt;] SyS_ioctl+0x57/0x79
[133860.370205]  [&lt;ffffffff8147cd97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6f

This bug happened because we assumed that by setting keep_locks to 1 in
our search path, our path after a call to btrfs_search_slot() would have
all nodes locked, which is not always true because unlock_up() (called by
btrfs_search_slot()) will unlock a node in a path if the slot of the node
below it doesn't point to the last item or beyond the last item. For
example, when the tree has a heigth of 2 and path-&gt;slots[0] has a value
smaller than btrfs_header_nritems(path-&gt;nodes[0]) - 1, the node at level 2
will be unlocked (also because lowest_unlock is set to 1 due to the fact
that the value passed as ins_len to btrfs_search_slot is 0).
This resulted in btrfs_find_next_key(), called before btrfs_realloc_node(),
to release out path and call again btrfs_search_slot(), but this time with
the cow parameter set to 0, meaning the resulting path got only read locks.
Therefore when we called btrfs_realloc_node(), with path-&gt;nodes[1] having
a read lock, it resulted in the warning and BUG_ON when calling
btrfs_set_lock_blocking() against the node, as that function expects the
node to have a write lock.

The second bug happened often when the first bug didn't happen, and made
us hang and hitting the following warning at fs/btrfs/locking.c:

   251  void btrfs_tree_lock(struct extent_buffer *eb)
   252  {
   253          WARN_ON(eb-&gt;lock_owner == current-&gt;pid);

This happened because the tree search we made at btrfs_defrag_leaves()
before calling btrfs_find_next_key() locked a leaf and all the other
nodes in the path, so btrfs_find_next_key() had no need to release the
path and make a new search (with path-&gt;lowest_level set to 1). This
made btrfs_realloc_node() attempt to write lock the same leaf again,
resulting in a hang/deadlock.

So fix these issues by calling btrfs_find_next_key() after calling
btrfs_realloc_node() and setting the search path's lowest_level to 1
to avoid the hang/deadlock when attempting to write lock the leaves
at btrfs_realloc_node().

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When running fstests btrfs/070, with a higher number of fsstress
operations, I ran frequently into two different locking bugs when
defragging directories.

The first bug produced the following traces:

[133860.229792] ------------[ cut here ]------------
[133860.251062] WARNING: CPU: 2 PID: 26057 at fs/btrfs/locking.c:46 btrfs_set_lock_blocking_rw+0x57/0xbd [btrfs]()
[133860.253576] Modules linked in: btrfs crc32c_generic xor raid6_pq nfsd auth_rpcgss oid_registry nfs_acl nfs lockd grace fscache sunrpc loop fuse parport_pc i2c_piix4 psmouse parport
[133860.282566] CPU: 2 PID: 26057 Comm: btrfs Tainted: G        W       4.3.0-rc5-btrfs-next-17+ #1
[133860.284393] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.8.1-0-g4adadbd-20150316_085822-nilsson.home.kraxel.org 04/01/2014
[133860.286827]  0000000000000000 ffff880207697b78 ffffffff812566f4 0000000000000000
[133860.288341]  ffff880207697bb0 ffffffff8104d0a6 ffffffffa052d4c1 ffff880178f60e00
[133860.294219]  ffff880178f60e00 0000000000000000 00000000000000f6 ffff880207697bc0
[133860.295831] Call Trace:
[133860.306518]  [&lt;ffffffff812566f4&gt;] dump_stack+0x4e/0x79
[133860.307473]  [&lt;ffffffff8104d0a6&gt;] warn_slowpath_common+0x9f/0xb8
[133860.308619]  [&lt;ffffffffa052d4c1&gt;] ? btrfs_set_lock_blocking_rw+0x57/0xbd [btrfs]
[133860.310068]  [&lt;ffffffff8104d172&gt;] warn_slowpath_null+0x1a/0x1c
[133860.312552]  [&lt;ffffffffa052d4c1&gt;] btrfs_set_lock_blocking_rw+0x57/0xbd [btrfs]
[133860.314630]  [&lt;ffffffffa04d5787&gt;] btrfs_set_lock_blocking+0xe/0x10 [btrfs]
[133860.323596]  [&lt;ffffffffa04d99cb&gt;] btrfs_realloc_node+0xb3/0x341 [btrfs]
[133860.325233]  [&lt;ffffffffa050e396&gt;] btrfs_defrag_leaves+0x239/0x2fa [btrfs]
[133860.332427]  [&lt;ffffffffa04fc2ce&gt;] btrfs_defrag_root+0x63/0xca [btrfs]
[133860.337259]  [&lt;ffffffffa052a34e&gt;] btrfs_ioctl_defrag+0x78/0x14e [btrfs]
[133860.340147]  [&lt;ffffffffa052b00b&gt;] btrfs_ioctl+0x746/0x24c6 [btrfs]
[133860.344833]  [&lt;ffffffff81087481&gt;] ? arch_local_irq_save+0x9/0xc
[133860.346343]  [&lt;ffffffff8113ad61&gt;] ? __might_fault+0x4c/0xa7
[133860.353248]  [&lt;ffffffff8113ad61&gt;] ? __might_fault+0x4c/0xa7
[133860.354242]  [&lt;ffffffff8113adba&gt;] ? __might_fault+0xa5/0xa7
[133860.355232]  [&lt;ffffffff81171139&gt;] ? cp_new_stat+0x15d/0x174
[133860.356237]  [&lt;ffffffff8117c610&gt;] do_vfs_ioctl+0x427/0x4e6
[133860.358587]  [&lt;ffffffff81171175&gt;] ? SYSC_newfstat+0x25/0x2e
[133860.360195]  [&lt;ffffffff8118574d&gt;] ? __fget_light+0x4d/0x71
[133860.361380]  [&lt;ffffffff8117c726&gt;] SyS_ioctl+0x57/0x79
[133860.363578]  [&lt;ffffffff8147cd97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6f
[133860.366217] ---[ end trace 2cadb2f653437e49 ]---
[133860.367399] ------------[ cut here ]------------
[133860.368162] kernel BUG at fs/btrfs/locking.c:307!
[133860.369430] invalid opcode: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC
[133860.370205] Modules linked in: btrfs crc32c_generic xor raid6_pq nfsd auth_rpcgss oid_registry nfs_acl nfs lockd grace fscache sunrpc loop fuse parport_pc i2c_piix4 psmouse parport
[133860.370205] CPU: 2 PID: 26057 Comm: btrfs Tainted: G        W       4.3.0-rc5-btrfs-next-17+ #1
[133860.370205] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.8.1-0-g4adadbd-20150316_085822-nilsson.home.kraxel.org 04/01/2014
[133860.370205] task: ffff8800aec6db40 ti: ffff880207694000 task.ti: ffff880207694000
[133860.370205] RIP: 0010:[&lt;ffffffffa052d466&gt;]  [&lt;ffffffffa052d466&gt;] btrfs_assert_tree_locked+0x10/0x14 [btrfs]
[133860.370205] RSP: 0018:ffff880207697bc0  EFLAGS: 00010246
[133860.370205] RAX: 0000000000000000 RBX: ffff880178f60e00 RCX: 0000000000000000
[133860.370205] RDX: ffff88023ec4fb50 RSI: 00000000ffffffff RDI: ffff880178f60e00
[133860.370205] RBP: ffff880207697bc0 R08: 0000000000000001 R09: 0000000000000000
[133860.370205] R10: 0000160000000000 R11: ffffffff81651000 R12: ffff880178f60e00
[133860.370205] R13: 0000000000000000 R14: 00000000000000f6 R15: ffff8801ff409000
[133860.370205] FS:  00007f763efd48c0(0000) GS:ffff88023ec40000(0000) knlGS:0000000000000000
[133860.370205] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[133860.370205] CR2: 0000000002158048 CR3: 000000003fd6c000 CR4: 00000000000006e0
[133860.370205] Stack:
[133860.370205]  ffff880207697bd8 ffffffffa052d4d0 0000000000000000 ffff880207697be8
[133860.370205]  ffffffffa04d5787 ffff880207697c80 ffffffffa04d99cb ffff8801ff409590
[133860.370205]  ffff880207697ca8 000000f507697c80 ffff880183c11bb8 0000000000000000
[133860.370205] Call Trace:
[133860.370205]  [&lt;ffffffffa052d4d0&gt;] btrfs_set_lock_blocking_rw+0x66/0xbd [btrfs]
[133860.370205]  [&lt;ffffffffa04d5787&gt;] btrfs_set_lock_blocking+0xe/0x10 [btrfs]
[133860.370205]  [&lt;ffffffffa04d99cb&gt;] btrfs_realloc_node+0xb3/0x341 [btrfs]
[133860.370205]  [&lt;ffffffffa050e396&gt;] btrfs_defrag_leaves+0x239/0x2fa [btrfs]
[133860.370205]  [&lt;ffffffffa04fc2ce&gt;] btrfs_defrag_root+0x63/0xca [btrfs]
[133860.370205]  [&lt;ffffffffa052a34e&gt;] btrfs_ioctl_defrag+0x78/0x14e [btrfs]
[133860.370205]  [&lt;ffffffffa052b00b&gt;] btrfs_ioctl+0x746/0x24c6 [btrfs]
[133860.370205]  [&lt;ffffffff81087481&gt;] ? arch_local_irq_save+0x9/0xc
[133860.370205]  [&lt;ffffffff8113ad61&gt;] ? __might_fault+0x4c/0xa7
[133860.370205]  [&lt;ffffffff8113ad61&gt;] ? __might_fault+0x4c/0xa7
[133860.370205]  [&lt;ffffffff8113adba&gt;] ? __might_fault+0xa5/0xa7
[133860.370205]  [&lt;ffffffff81171139&gt;] ? cp_new_stat+0x15d/0x174
[133860.370205]  [&lt;ffffffff8117c610&gt;] do_vfs_ioctl+0x427/0x4e6
[133860.370205]  [&lt;ffffffff81171175&gt;] ? SYSC_newfstat+0x25/0x2e
[133860.370205]  [&lt;ffffffff8118574d&gt;] ? __fget_light+0x4d/0x71
[133860.370205]  [&lt;ffffffff8117c726&gt;] SyS_ioctl+0x57/0x79
[133860.370205]  [&lt;ffffffff8147cd97&gt;] entry_SYSCALL_64_fastpath+0x12/0x6f

This bug happened because we assumed that by setting keep_locks to 1 in
our search path, our path after a call to btrfs_search_slot() would have
all nodes locked, which is not always true because unlock_up() (called by
btrfs_search_slot()) will unlock a node in a path if the slot of the node
below it doesn't point to the last item or beyond the last item. For
example, when the tree has a heigth of 2 and path-&gt;slots[0] has a value
smaller than btrfs_header_nritems(path-&gt;nodes[0]) - 1, the node at level 2
will be unlocked (also because lowest_unlock is set to 1 due to the fact
that the value passed as ins_len to btrfs_search_slot is 0).
This resulted in btrfs_find_next_key(), called before btrfs_realloc_node(),
to release out path and call again btrfs_search_slot(), but this time with
the cow parameter set to 0, meaning the resulting path got only read locks.
Therefore when we called btrfs_realloc_node(), with path-&gt;nodes[1] having
a read lock, it resulted in the warning and BUG_ON when calling
btrfs_set_lock_blocking() against the node, as that function expects the
node to have a write lock.

The second bug happened often when the first bug didn't happen, and made
us hang and hitting the following warning at fs/btrfs/locking.c:

   251  void btrfs_tree_lock(struct extent_buffer *eb)
   252  {
   253          WARN_ON(eb-&gt;lock_owner == current-&gt;pid);

This happened because the tree search we made at btrfs_defrag_leaves()
before calling btrfs_find_next_key() locked a leaf and all the other
nodes in the path, so btrfs_find_next_key() had no need to release the
path and make a new search (with path-&gt;lowest_level set to 1). This
made btrfs_realloc_node() attempt to write lock the same leaf again,
resulting in a hang/deadlock.

So fix these issues by calling btrfs_find_next_key() after calling
btrfs_realloc_node() and setting the search path's lowest_level to 1
to avoid the hang/deadlock when attempting to write lock the leaves
at btrfs_realloc_node().

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: cleanup: remove unnecessary check before btrfs_free_path is called</title>
<updated>2015-08-31T18:46:41+00:00</updated>
<author>
<name>Tsutomu Itoh</name>
<email>t-itoh@jp.fujitsu.com</email>
</author>
<published>2015-08-19T05:55:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=527afb4493c2892ce89fb74648e72a30b68ba120'/>
<id>527afb4493c2892ce89fb74648e72a30b68ba120</id>
<content type='text'>
We need not check path before btrfs_free_path() is called because
path is checked in btrfs_free_path().

Signed-off-by: Tsutomu Itoh &lt;t-itoh@jp.fujitsu.com&gt;
Reviewed-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We need not check path before btrfs_free_path() is called because
path is checked in btrfs_free_path().

Signed-off-by: Tsutomu Itoh &lt;t-itoh@jp.fujitsu.com&gt;
Reviewed-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: let tree defrag work in SSD mode</title>
<updated>2015-06-03T02:34:33+00:00</updated>
<author>
<name>David Sterba</name>
<email>dsterba@suse.cz</email>
</author>
<published>2015-04-24T14:44:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=13028901a4a62096e97a0fc44388ea859587f690'/>
<id>13028901a4a62096e97a0fc44388ea859587f690</id>
<content type='text'>
Long time ago (2008) the defrag was automatic for new b-tree writes but
has been disabled after performance problems. There was a leftover in
tree-defrag.c that effectively stops any defragmentation on b-trees.
This is a bit unexpected and IMHO undesired. The SSD mode is an
optimization and defrag is supposed to work if the users asks for it.

Related commits:

6702ed490ca0bb44e17131818a5a18b773957c5a
Btrfs: Add run time btree defrag, and an ioctl to force btree defrag

e18e4809b10e6c9efb5fe10c1ddcb4ebb690d517
Btrfs: Add mount -o ssd, which includes optimizations for seek free
storage

b3236e68bf86b3ae87f58984a1822369225211cb
Btrfs: Leave on the tree defragger in mount -o ssd, it still helps there

9afbb0b752ef30a429c45b9de6706e28ad1a36e1
Btrfs: Disable tree defrag in SSD mode

The last three commits switch the defrag+ssd off/on/off and the last one

3f157a2fd2ad731e1ed9964fecdc5f459f04a4a4
Btrfs: Online btree defragmentation fixes

misses the bits from tree-defrag.c to revert to the behaviour introduced
in e18e4809b10e.

Signed-off-by: David Sterba &lt;dsterba@suse.cz&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Long time ago (2008) the defrag was automatic for new b-tree writes but
has been disabled after performance problems. There was a leftover in
tree-defrag.c that effectively stops any defragmentation on b-trees.
This is a bit unexpected and IMHO undesired. The SSD mode is an
optimization and defrag is supposed to work if the users asks for it.

Related commits:

6702ed490ca0bb44e17131818a5a18b773957c5a
Btrfs: Add run time btree defrag, and an ioctl to force btree defrag

e18e4809b10e6c9efb5fe10c1ddcb4ebb690d517
Btrfs: Add mount -o ssd, which includes optimizations for seek free
storage

b3236e68bf86b3ae87f58984a1822369225211cb
Btrfs: Leave on the tree defragger in mount -o ssd, it still helps there

9afbb0b752ef30a429c45b9de6706e28ad1a36e1
Btrfs: Disable tree defrag in SSD mode

The last three commits switch the defrag+ssd off/on/off and the last one

3f157a2fd2ad731e1ed9964fecdc5f459f04a4a4
Btrfs: Online btree defragmentation fixes

misses the bits from tree-defrag.c to revert to the behaviour introduced
in e18e4809b10e.

Signed-off-by: David Sterba &lt;dsterba@suse.cz&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: use bitfield instead of integer data type for the some variants in btrfs_root</title>
<updated>2014-06-10T00:20:40+00:00</updated>
<author>
<name>Miao Xie</name>
<email>miaox@cn.fujitsu.com</email>
</author>
<published>2014-04-02T11:51:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=27cdeb7096b86f05ad018a24cdb63acdf0850a5d'/>
<id>27cdeb7096b86f05ad018a24cdb63acdf0850a5d</id>
<content type='text'>
Signed-off-by: Miao Xie &lt;miaox@cn.fujitsu.com&gt;
Signed-off-by: Wang Shilong &lt;wangsl.fnst@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Signed-off-by: Miao Xie &lt;miaox@cn.fujitsu.com&gt;
Signed-off-by: Wang Shilong &lt;wangsl.fnst@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
