<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/fs/btrfs/qgroup.c, branch v4.4.110</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: fix qgroup rescan worker initialization</title>
<updated>2017-01-06T10:16:06+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2016-11-24T02:09:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=1f5adadcd03266a461ebe752964c40a3dc95bf2f'/>
<id>1f5adadcd03266a461ebe752964c40a3dc95bf2f</id>
<content type='text'>
commit 8d9eddad19467b008e0c881bc3133d7da94b7ec1 upstream.

We were setting the qgroup_rescan_running flag to true only after the
rescan worker started (which is a task run by a queue). So if a user
space task starts a rescan and immediately after asks to wait for the
rescan worker to finish, this second call might happen before the rescan
worker task starts running, in which case the rescan wait ioctl returns
immediatley, not waiting for the rescan worker to finish.

This was making the fstest btrfs/022 fail very often.

Fixes: d2c609b834d6 (btrfs: properly track when rescan worker is running)
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 8d9eddad19467b008e0c881bc3133d7da94b7ec1 upstream.

We were setting the qgroup_rescan_running flag to true only after the
rescan worker started (which is a task run by a queue). So if a user
space task starts a rescan and immediately after asks to wait for the
rescan worker to finish, this second call might happen before the rescan
worker task starts running, in which case the rescan wait ioctl returns
immediatley, not waiting for the rescan worker to finish.

This was making the fstest btrfs/022 fail very often.

Fixes: d2c609b834d6 (btrfs: properly track when rescan worker is running)
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: properly track when rescan worker is running</title>
<updated>2016-09-07T06:32:43+00:00</updated>
<author>
<name>Jeff Mahoney</name>
<email>jeffm@suse.com</email>
</author>
<published>2016-08-15T16:10:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=cc79d3982d9c77f36cebe8f1033e6715c55ac726'/>
<id>cc79d3982d9c77f36cebe8f1033e6715c55ac726</id>
<content type='text'>
commit d2c609b834d62f1e91f1635a27dca29f7806d3d6 upstream.

The qgroup_flags field is overloaded such that it reflects the on-disk
status of qgroups and the runtime state.  The BTRFS_QGROUP_STATUS_FLAG_RESCAN
flag is used to indicate that a rescan operation is in progress, but if
the file system is unmounted while a rescan is running, the rescan
operation is paused.  If the file system is then mounted read-only,
the flag will still be present but the rescan operation will not have
been resumed.  When we go to umount, btrfs_qgroup_wait_for_completion
will see the flag and interpret it to mean that the rescan worker is
still running and will wait for a completion that will never come.

This patch uses a separate flag to indicate when the worker is
running.  The locking and state surrounding the qgroup rescan worker
needs a lot of attention beyond this patch but this is enough to
avoid a hung umount.

Signed-off-by; Jeff Mahoney &lt;jeffm@suse.com&gt;
Reviewed-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

Signed-off-by: Chris Mason &lt;clm@fb.com&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit d2c609b834d62f1e91f1635a27dca29f7806d3d6 upstream.

The qgroup_flags field is overloaded such that it reflects the on-disk
status of qgroups and the runtime state.  The BTRFS_QGROUP_STATUS_FLAG_RESCAN
flag is used to indicate that a rescan operation is in progress, but if
the file system is unmounted while a rescan is running, the rescan
operation is paused.  If the file system is then mounted read-only,
the flag will still be present but the rescan operation will not have
been resumed.  When we go to umount, btrfs_qgroup_wait_for_completion
will see the flag and interpret it to mean that the rescan worker is
still running and will wait for a completion that will never come.

This patch uses a separate flag to indicate when the worker is
running.  The locking and state surrounding the qgroup rescan worker
needs a lot of attention beyond this patch but this is enough to
avoid a hung umount.

Signed-off-by; Jeff Mahoney &lt;jeffm@suse.com&gt;
Reviewed-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

Signed-off-by: Chris Mason &lt;clm@fb.com&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: waiting on qgroup rescan should not always be interruptible</title>
<updated>2016-09-07T06:32:43+00:00</updated>
<author>
<name>Jeff Mahoney</name>
<email>jeffm@suse.com</email>
</author>
<published>2016-08-09T02:08:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=f31d48a091877f7580c0c6aa70e3d35d9b6e8625'/>
<id>f31d48a091877f7580c0c6aa70e3d35d9b6e8625</id>
<content type='text'>
commit d06f23d6a947c9abae41dc46be69a56baf36f436 upstream.

We wait on qgroup rescan completion in three places: file system
shutdown, the quota disable ioctl, and the rescan wait ioctl.  If the
user sends a signal while we're waiting, we continue happily along.  This
is expected behavior for the rescan wait ioctl.  It's racy in the shutdown
path but mostly works due to other unrelated synchronization points.
In the quota disable path, it Oopses the kernel pretty much immediately.

Signed-off-by: Jeff Mahoney &lt;jeffm@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@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>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit d06f23d6a947c9abae41dc46be69a56baf36f436 upstream.

We wait on qgroup rescan completion in three places: file system
shutdown, the quota disable ioctl, and the rescan wait ioctl.  If the
user sends a signal while we're waiting, we continue happily along.  This
is expected behavior for the rescan wait ioctl.  It's racy in the shutdown
path but mostly works due to other unrelated synchronization points.
In the quota disable path, it Oopses the kernel pretty much immediately.

Signed-off-by: Jeff Mahoney &lt;jeffm@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: qgroup: account shared subtree during snapshot delete</title>
<updated>2015-11-25T13:27:33+00:00</updated>
<author>
<name>Mark Fasheh</name>
<email>mfasheh@suse.de</email>
</author>
<published>2015-11-05T22:38:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=82bd101b5240d3d1c4078a8017917a40c0dcc514'/>
<id>82bd101b5240d3d1c4078a8017917a40c0dcc514</id>
<content type='text'>
Commit 0ed4792 ('btrfs: qgroup: Switch to new extent-oriented qgroup
mechanism.') removed our qgroup accounting during
btrfs_drop_snapshot(). Predictably, this results in qgroup numbers
going bad shortly after a snapshot is removed.

Fix this by adding a dirty extent record when we encounter extents during
our shared subtree walk. This effectively restores the functionality we had
with the original shared subtree walking code in 1152651 (btrfs: qgroup:
account shared subtrees during snapshot delete).

The idea with the original patch (and this one) is that shared subtrees can
get skipped during drop_snapshot. The shared subtree walk then allows us a
chance to visit those extents and add them to the qgroup work for later
processing. This ultimately makes the accounting for drop snapshot work.

The new qgroup code nicely handles all the other extents during the tree
walk via the ref dec/inc functions so we don't have to add actions beyond
what we had originally.

Signed-off-by: Mark Fasheh &lt;mfasheh@suse.de&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Commit 0ed4792 ('btrfs: qgroup: Switch to new extent-oriented qgroup
mechanism.') removed our qgroup accounting during
btrfs_drop_snapshot(). Predictably, this results in qgroup numbers
going bad shortly after a snapshot is removed.

Fix this by adding a dirty extent record when we encounter extents during
our shared subtree walk. This effectively restores the functionality we had
with the original shared subtree walking code in 1152651 (btrfs: qgroup:
account shared subtrees during snapshot delete).

The idea with the original patch (and this one) is that shared subtrees can
get skipped during drop_snapshot. The shared subtree walk then allows us a
chance to visit those extents and add them to the qgroup work for later
processing. This ultimately makes the accounting for drop snapshot work.

The new qgroup code nicely handles all the other extents during the tree
walk via the ref dec/inc functions so we don't have to add actions beyond
what we had originally.

Signed-off-by: Mark Fasheh &lt;mfasheh@suse.de&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: qgroup: fix quota disable during rescan</title>
<updated>2015-11-25T13:22:08+00:00</updated>
<author>
<name>Justin Maggard</name>
<email>jmaggard10@gmail.com</email>
</author>
<published>2015-11-06T18:36:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=967ef5131e42d6e3bb216c44161d893048a49957'/>
<id>967ef5131e42d6e3bb216c44161d893048a49957</id>
<content type='text'>
There's a race condition that leads to a NULL pointer dereference if you
disable quotas while a quota rescan is running.  To fix this, we just need
to wait for the quota rescan worker to actually exit before tearing down
the quota structures.

Signed-off-by: Justin Maggard &lt;jmaggard@netgear.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>
There's a race condition that leads to a NULL pointer dereference if you
disable quotas while a quota rescan is running.  To fix this, we just need
to wait for the quota rescan worker to actually exit before tearing down
the quota structures.

Signed-off-by: Justin Maggard &lt;jmaggard@netgear.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: fix sleeping inside atomic context in qgroup rescan worker</title>
<updated>2015-11-05T11:02:22+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-11-05T10:51:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=3b2ba7b31d56c3d8f57cd5d32b8fb5101ab446e4'/>
<id>3b2ba7b31d56c3d8f57cd5d32b8fb5101ab446e4</id>
<content type='text'>
We are holding a btree path with spinning locks and then we attempt to
clone an extent buffer, which calls kmem_cache_alloc() and this function
can sleep, causing the following trace to be reported on a debug kernel:

[107118.218536] BUG: sleeping function called from invalid context at mm/slab.c:2871
[107118.224110] in_atomic(): 1, irqs_disabled(): 0, pid: 19148, name: kworker/u32:3
[107118.226120] INFO: lockdep is turned off.
[107118.226843] Preemption disabled at:[&lt;ffffffffa05ffa22&gt;] btrfs_clear_lock_blocking_rw+0x96/0xea [btrfs]

[107118.229175] CPU: 3 PID: 19148 Comm: kworker/u32:3 Tainted: G        W       4.3.0-rc5-btrfs-next-17+ #1
[107118.231326] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.8.1-0-g4adadbd-20150316_085822-nilsson.home.kraxel.org 04/01/2014
[107118.233687] Workqueue: btrfs-qgroup-rescan btrfs_qgroup_rescan_helper [btrfs]
[107118.236835]  0000000000000000 ffff880424bf3b78 ffffffff812566f4 0000000000000000
[107118.238369]  ffff880424bf3ba0 ffffffff81070664 ffffffff817f1cd5 0000000000000b37
[107118.239769]  0000000000000000 ffff880424bf3bc8 ffffffff8107070a 0000000000008850
[107118.241244] Call Trace:
[107118.241729]  [&lt;ffffffff812566f4&gt;] dump_stack+0x4e/0x79
[107118.242602]  [&lt;ffffffff81070664&gt;] ___might_sleep+0x23a/0x241
[107118.243586]  [&lt;ffffffff8107070a&gt;] __might_sleep+0x9f/0xa6
[107118.244532]  [&lt;ffffffff8115af70&gt;] cache_alloc_debugcheck_before+0x25/0x36
[107118.245939]  [&lt;ffffffff8115d52b&gt;] kmem_cache_alloc+0x50/0x215
[107118.246930]  [&lt;ffffffffa05e627e&gt;] __alloc_extent_buffer+0x2a/0x11f [btrfs]
[107118.248121]  [&lt;ffffffffa05ecb1a&gt;] btrfs_clone_extent_buffer+0x3d/0xdd [btrfs]
[107118.249451]  [&lt;ffffffffa06239ea&gt;] btrfs_qgroup_rescan_worker+0x16d/0x434 [btrfs]
[107118.250755]  [&lt;ffffffff81087481&gt;] ? arch_local_irq_save+0x9/0xc
[107118.251754]  [&lt;ffffffffa05f7952&gt;] normal_work_helper+0x14c/0x32a [btrfs]
[107118.252899]  [&lt;ffffffffa05f7952&gt;] ? normal_work_helper+0x14c/0x32a [btrfs]
[107118.254195]  [&lt;ffffffffa05f7c82&gt;] btrfs_qgroup_rescan_helper+0x12/0x14 [btrfs]
[107118.255436]  [&lt;ffffffff81063b23&gt;] process_one_work+0x24a/0x4ac
[107118.263690]  [&lt;ffffffff81064285&gt;] worker_thread+0x206/0x2c2
[107118.264888]  [&lt;ffffffff8106407f&gt;] ? rescuer_thread+0x2cb/0x2cb
[107118.267413]  [&lt;ffffffff8106904d&gt;] kthread+0xef/0xf7
[107118.268417]  [&lt;ffffffff81068f5e&gt;] ? kthread_parkme+0x24/0x24
[107118.269505]  [&lt;ffffffff8147d10f&gt;] ret_from_fork+0x3f/0x70
[107118.270491]  [&lt;ffffffff81068f5e&gt;] ? kthread_parkme+0x24/0x24

So just use blocking locks for our path to solve this.
This fixes the patch titled:
  "btrfs: qgroup: Don't copy extent buffer to do qgroup rescan"

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We are holding a btree path with spinning locks and then we attempt to
clone an extent buffer, which calls kmem_cache_alloc() and this function
can sleep, causing the following trace to be reported on a debug kernel:

[107118.218536] BUG: sleeping function called from invalid context at mm/slab.c:2871
[107118.224110] in_atomic(): 1, irqs_disabled(): 0, pid: 19148, name: kworker/u32:3
[107118.226120] INFO: lockdep is turned off.
[107118.226843] Preemption disabled at:[&lt;ffffffffa05ffa22&gt;] btrfs_clear_lock_blocking_rw+0x96/0xea [btrfs]

[107118.229175] CPU: 3 PID: 19148 Comm: kworker/u32:3 Tainted: G        W       4.3.0-rc5-btrfs-next-17+ #1
[107118.231326] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.8.1-0-g4adadbd-20150316_085822-nilsson.home.kraxel.org 04/01/2014
[107118.233687] Workqueue: btrfs-qgroup-rescan btrfs_qgroup_rescan_helper [btrfs]
[107118.236835]  0000000000000000 ffff880424bf3b78 ffffffff812566f4 0000000000000000
[107118.238369]  ffff880424bf3ba0 ffffffff81070664 ffffffff817f1cd5 0000000000000b37
[107118.239769]  0000000000000000 ffff880424bf3bc8 ffffffff8107070a 0000000000008850
[107118.241244] Call Trace:
[107118.241729]  [&lt;ffffffff812566f4&gt;] dump_stack+0x4e/0x79
[107118.242602]  [&lt;ffffffff81070664&gt;] ___might_sleep+0x23a/0x241
[107118.243586]  [&lt;ffffffff8107070a&gt;] __might_sleep+0x9f/0xa6
[107118.244532]  [&lt;ffffffff8115af70&gt;] cache_alloc_debugcheck_before+0x25/0x36
[107118.245939]  [&lt;ffffffff8115d52b&gt;] kmem_cache_alloc+0x50/0x215
[107118.246930]  [&lt;ffffffffa05e627e&gt;] __alloc_extent_buffer+0x2a/0x11f [btrfs]
[107118.248121]  [&lt;ffffffffa05ecb1a&gt;] btrfs_clone_extent_buffer+0x3d/0xdd [btrfs]
[107118.249451]  [&lt;ffffffffa06239ea&gt;] btrfs_qgroup_rescan_worker+0x16d/0x434 [btrfs]
[107118.250755]  [&lt;ffffffff81087481&gt;] ? arch_local_irq_save+0x9/0xc
[107118.251754]  [&lt;ffffffffa05f7952&gt;] normal_work_helper+0x14c/0x32a [btrfs]
[107118.252899]  [&lt;ffffffffa05f7952&gt;] ? normal_work_helper+0x14c/0x32a [btrfs]
[107118.254195]  [&lt;ffffffffa05f7c82&gt;] btrfs_qgroup_rescan_helper+0x12/0x14 [btrfs]
[107118.255436]  [&lt;ffffffff81063b23&gt;] process_one_work+0x24a/0x4ac
[107118.263690]  [&lt;ffffffff81064285&gt;] worker_thread+0x206/0x2c2
[107118.264888]  [&lt;ffffffff8106407f&gt;] ? rescuer_thread+0x2cb/0x2cb
[107118.267413]  [&lt;ffffffff8106904d&gt;] kthread+0xef/0xf7
[107118.268417]  [&lt;ffffffff81068f5e&gt;] ? kthread_parkme+0x24/0x24
[107118.269505]  [&lt;ffffffff8147d10f&gt;] ret_from_fork+0x3f/0x70
[107118.270491]  [&lt;ffffffff81068f5e&gt;] ? kthread_parkme+0x24/0x24

So just use blocking locks for our path to solve this.
This fixes the patch titled:
  "btrfs: qgroup: Don't copy extent buffer to do qgroup rescan"

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: fix race waiting for qgroup rescan worker</title>
<updated>2015-11-05T10:32:21+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-11-05T10:06:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=190631f1c8cb7e4d5c27ff87e22ed53817e78759'/>
<id>190631f1c8cb7e4d5c27ff87e22ed53817e78759</id>
<content type='text'>
We were initializing the completion (fs_info-&gt;qgroup_rescan_completion)
object after releasing the qgroup rescan lock, which gives a small time
window for a rescan waiter to not actually wait for the rescan worker
to finish. Example:

         CPU 1                                                     CPU 2

 fs_info-&gt;qgroup_rescan_completion-&gt;done is 0

 btrfs_qgroup_rescan_worker()
   complete_all(&amp;fs_info-&gt;qgroup_rescan_completion)
     sets fs_info-&gt;qgroup_rescan_completion-&gt;done
     to UINT_MAX / 2

 ... do some other stuff ....

 qgroup_rescan_init()
   mutex_lock(&amp;fs_info-&gt;qgroup_rescan_lock)
   set flag BTRFS_QGROUP_STATUS_FLAG_RESCAN
     in fs_info-&gt;qgroup_flags
   mutex_unlock(&amp;fs_info-&gt;qgroup_rescan_lock)

                                                       btrfs_qgroup_wait_for_completion()
                                                         mutex_lock(&amp;fs_info-&gt;qgroup_rescan_lock)
                                                         sees flag BTRFS_QGROUP_STATUS_FLAG_RESCAN
                                                           in fs_info-&gt;qgroup_flags
                                                         mutex_unlock(&amp;fs_info-&gt;qgroup_rescan_lock)

                                                         wait_for_completion_interruptible(
                                                           &amp;fs_info-&gt;qgroup_rescan_completion)

                                                           fs_info-&gt;qgroup_rescan_completion-&gt;done
                                                           is &gt; 0 so it returns immediately

  init_completion(&amp;fs_info-&gt;qgroup_rescan_completion)
    sets fs_info-&gt;qgroup_rescan_completion-&gt;done to 0

So fix this by initializing the completion object while holding the mutex
fs_info-&gt;qgroup_rescan_lock.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We were initializing the completion (fs_info-&gt;qgroup_rescan_completion)
object after releasing the qgroup rescan lock, which gives a small time
window for a rescan waiter to not actually wait for the rescan worker
to finish. Example:

         CPU 1                                                     CPU 2

 fs_info-&gt;qgroup_rescan_completion-&gt;done is 0

 btrfs_qgroup_rescan_worker()
   complete_all(&amp;fs_info-&gt;qgroup_rescan_completion)
     sets fs_info-&gt;qgroup_rescan_completion-&gt;done
     to UINT_MAX / 2

 ... do some other stuff ....

 qgroup_rescan_init()
   mutex_lock(&amp;fs_info-&gt;qgroup_rescan_lock)
   set flag BTRFS_QGROUP_STATUS_FLAG_RESCAN
     in fs_info-&gt;qgroup_flags
   mutex_unlock(&amp;fs_info-&gt;qgroup_rescan_lock)

                                                       btrfs_qgroup_wait_for_completion()
                                                         mutex_lock(&amp;fs_info-&gt;qgroup_rescan_lock)
                                                         sees flag BTRFS_QGROUP_STATUS_FLAG_RESCAN
                                                           in fs_info-&gt;qgroup_flags
                                                         mutex_unlock(&amp;fs_info-&gt;qgroup_rescan_lock)

                                                         wait_for_completion_interruptible(
                                                           &amp;fs_info-&gt;qgroup_rescan_completion)

                                                           fs_info-&gt;qgroup_rescan_completion-&gt;done
                                                           is &gt; 0 so it returns immediately

  init_completion(&amp;fs_info-&gt;qgroup_rescan_completion)
    sets fs_info-&gt;qgroup_rescan_completion-&gt;done to 0

So fix this by initializing the completion object while holding the mutex
fs_info-&gt;qgroup_rescan_lock.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: qgroup: exit the rescan worker during umount</title>
<updated>2015-11-05T10:32:20+00:00</updated>
<author>
<name>Justin Maggard</name>
<email>jmaggard10@gmail.com</email>
</author>
<published>2015-11-04T23:56:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7343dd61fd1b57c40cc06a5b5b5386df7f73c3ac'/>
<id>7343dd61fd1b57c40cc06a5b5b5386df7f73c3ac</id>
<content type='text'>
I was hitting a consistent NULL pointer dereference during shutdown that
showed the trace running through end_workqueue_bio().  I traced it back to
the endio_meta_workers workqueue being poked after it had already been
destroyed.

Eventually I found that the root cause was a qgroup rescan that was still
in progress while we were stopping all the btrfs workers.

Currently we explicitly pause balance and scrub operations in
close_ctree(), but we do nothing to stop the qgroup rescan.  We should
probably be doing the same for qgroup rescan, but that's a much larger
change.  This small change is good enough to allow me to unmount without
crashing.

Signed-off-by: Justin Maggard &lt;jmaggard@netgear.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
I was hitting a consistent NULL pointer dereference during shutdown that
showed the trace running through end_workqueue_bio().  I traced it back to
the endio_meta_workers workqueue being poked after it had already been
destroyed.

Eventually I found that the root cause was a qgroup rescan that was still
in progress while we were stopping all the btrfs workers.

Currently we explicitly pause balance and scrub operations in
close_ctree(), but we do nothing to stop the qgroup rescan.  We should
probably be doing the same for qgroup rescan, but that's a much larger
change.  This small change is good enough to allow me to unmount without
crashing.

Signed-off-by: Justin Maggard &lt;jmaggard@netgear.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: qgroup: Fix a rebase bug which will cause qgroup double free</title>
<updated>2015-10-27T02:44:39+00:00</updated>
<author>
<name>Qu Wenruo</name>
<email>quwenruo@cn.fujitsu.com</email>
</author>
<published>2015-10-26T06:11:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=90ce321da8ce3d00e19586993887346286208386'/>
<id>90ce321da8ce3d00e19586993887346286208386</id>
<content type='text'>
When rebasing my patchset, I forgot to pick up a cleanup patch to remove
old hotfix in 4.2 release.

Witouth the cleanup, it will screw up new qgroup reserve framework and
always cause minus reserved number.

Signed-off-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>
When rebasing my patchset, I forgot to pick up a cleanup patch to remove
old hotfix in 4.2 release.

Witouth the cleanup, it will screw up new qgroup reserve framework and
always cause minus reserved number.

Signed-off-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: qgroup: Don't copy extent buffer to do qgroup rescan</title>
<updated>2015-10-27T02:42:30+00:00</updated>
<author>
<name>Qu Wenruo</name>
<email>quwenruo@cn.fujitsu.com</email>
</author>
<published>2015-10-26T01:19:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=0a0e8b89389266bed9cc074c57ea662e4b9b2621'/>
<id>0a0e8b89389266bed9cc074c57ea662e4b9b2621</id>
<content type='text'>
Ancient qgroup code call memcpy() on a extent buffer and use it for leaf
iteration.

As extent buffer contains lock, pointers to pages, it's never sane to do
such copy.

The following bug may be caused by this insane operation:
[92098.841309] general protection fault: 0000 [#1] SMP
[92098.841338] Modules linked in: ...
[92098.841814] CPU: 1 PID: 24655 Comm: kworker/u4:12 Not tainted
4.3.0-rc1 #1
[92098.841868] Workqueue: btrfs-qgroup-rescan btrfs_qgroup_rescan_helper
[btrfs]
[92098.842261] Call Trace:
[92098.842277]  [&lt;ffffffffc035a5d8&gt;] ? read_extent_buffer+0xb8/0x110
[btrfs]
[92098.842304]  [&lt;ffffffffc0396d00&gt;] ? btrfs_find_all_roots+0x60/0x70
[btrfs]
[92098.842329]  [&lt;ffffffffc039af3d&gt;]
btrfs_qgroup_rescan_worker+0x28d/0x5a0 [btrfs]

Where btrfs_qgroup_rescan_worker+0x28d is btrfs_disk_key_to_cpu(),
called in reading key from the copied extent_buffer.

This patch will use btrfs_clone_extent_buffer() to a better copy of
extent buffer to deal such case.

Reported-by: Stephane Lesimple &lt;stephane_btrfs@lesimple.fr&gt;
Suggested-by: Filipe Manana &lt;fdmanana@kernel.org&gt;
Signed-off-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.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>
Ancient qgroup code call memcpy() on a extent buffer and use it for leaf
iteration.

As extent buffer contains lock, pointers to pages, it's never sane to do
such copy.

The following bug may be caused by this insane operation:
[92098.841309] general protection fault: 0000 [#1] SMP
[92098.841338] Modules linked in: ...
[92098.841814] CPU: 1 PID: 24655 Comm: kworker/u4:12 Not tainted
4.3.0-rc1 #1
[92098.841868] Workqueue: btrfs-qgroup-rescan btrfs_qgroup_rescan_helper
[btrfs]
[92098.842261] Call Trace:
[92098.842277]  [&lt;ffffffffc035a5d8&gt;] ? read_extent_buffer+0xb8/0x110
[btrfs]
[92098.842304]  [&lt;ffffffffc0396d00&gt;] ? btrfs_find_all_roots+0x60/0x70
[btrfs]
[92098.842329]  [&lt;ffffffffc039af3d&gt;]
btrfs_qgroup_rescan_worker+0x28d/0x5a0 [btrfs]

Where btrfs_qgroup_rescan_worker+0x28d is btrfs_disk_key_to_cpu(),
called in reading key from the copied extent_buffer.

This patch will use btrfs_clone_extent_buffer() to a better copy of
extent buffer to deal such case.

Reported-by: Stephane Lesimple &lt;stephane_btrfs@lesimple.fr&gt;
Suggested-by: Filipe Manana &lt;fdmanana@kernel.org&gt;
Signed-off-by: Qu Wenruo &lt;quwenruo@cn.fujitsu.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
