<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/fs/btrfs, branch v4.0.6</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 regression in raid level conversion</title>
<updated>2015-06-23T00:03:37+00:00</updated>
<author>
<name>Chris Mason</name>
<email>clm@fb.com</email>
</author>
<published>2015-05-20T01:54:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=e8b62da46bb19a5e9e72de77dc36c1d5c5c50ab1'/>
<id>e8b62da46bb19a5e9e72de77dc36c1d5c5c50ab1</id>
<content type='text'>
commit 153c35b6cccc0c72de9fae06c8e2c8b2c47d79d4 upstream.

Commit 2f0810880f082fa8ba66ab2c33b02e4ff9770a5e changed
btrfs_set_block_group_ro to avoid trying to allocate new chunks with the
new raid profile during conversion.  This fixed failures when there was
no space on the drive to allocate a new chunk, but the metadata
reserves were sufficient to continue the conversion.

But this ended up causing a regression when the drive had plenty of
space to allocate new chunks, mostly because reduce_alloc_profile isn't
using the new raid profile.

Fixing btrfs_reduce_alloc_profile is a bigger patch.  For now, do a
partial revert of 2f0810880, and don't error out if we hit ENOSPC.

Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Tested-by: Dave Sterba &lt;dsterba@suse.cz&gt;
Reported-by: Holger Hoffstaette &lt;holger.hoffstaette@googlemail.com&gt;
[adapted for stable kernel branch, v4.0.5]
Signed-off-by: David Sterba &lt;dsterba@suse.cz&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 153c35b6cccc0c72de9fae06c8e2c8b2c47d79d4 upstream.

Commit 2f0810880f082fa8ba66ab2c33b02e4ff9770a5e changed
btrfs_set_block_group_ro to avoid trying to allocate new chunks with the
new raid profile during conversion.  This fixed failures when there was
no space on the drive to allocate a new chunk, but the metadata
reserves were sufficient to continue the conversion.

But this ended up causing a regression when the drive had plenty of
space to allocate new chunks, mostly because reduce_alloc_profile isn't
using the new raid profile.

Fixing btrfs_reduce_alloc_profile is a bigger patch.  For now, do a
partial revert of 2f0810880, and don't error out if we hit ENOSPC.

Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
Tested-by: Dave Sterba &lt;dsterba@suse.cz&gt;
Reported-by: Holger Hoffstaette &lt;holger.hoffstaette@googlemail.com&gt;
[adapted for stable kernel branch, v4.0.5]
Signed-off-by: David Sterba &lt;dsterba@suse.cz&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Btrfs: fix uninit variable in clone ioctl</title>
<updated>2015-06-23T00:03:37+00:00</updated>
<author>
<name>Chris Mason</name>
<email>clm@fb.com</email>
</author>
<published>2015-04-11T12:09:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=1e24644ae5af0b11a9153c0b6d981c215d7c3585'/>
<id>1e24644ae5af0b11a9153c0b6d981c215d7c3585</id>
<content type='text'>
commit de249e66a73d696666281cd812087979c6fae552 upstream.

Commit 0d97a64e0 creates a new variable but doesn't always set it up.
This puts it back to the original method (key.offset + 1) for the cases
not covered by Filipe's new logic.

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 de249e66a73d696666281cd812087979c6fae552 upstream.

Commit 0d97a64e0 creates a new variable but doesn't always set it up.
This puts it back to the original method (key.offset + 1) for the cases
not covered by Filipe's new logic.

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: fix range cloning when same inode used as source and destination</title>
<updated>2015-06-23T00:03:36+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-03-31T13:56:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=64b02777ad421be063075f483aa50ec54e729333'/>
<id>64b02777ad421be063075f483aa50ec54e729333</id>
<content type='text'>
commit df858e76723ace61342b118aa4302bd09de4e386 upstream.

While searching for extents to clone we might find one where we only use
a part of it coming from its tail. If our destination inode is the same
the source inode, we end up removing the tail part of the extent item and
insert after a new one that point to the same extent with an adjusted
key file offset and data offset. After this we search for the next extent
item in the fs/subvol tree with a key that has an offset incremented by
one. But this second search leaves us at the new extent item we inserted
previously, and since that extent item has a non-zero data offset, it
it can make us call btrfs_drop_extents with an empty range (start == end)
which causes the following warning:

[23978.537119] WARNING: CPU: 6 PID: 16251 at fs/btrfs/file.c:550 btrfs_drop_extent_cache+0x43/0x385 [btrfs]()
(...)
[23978.557266] Call Trace:
[23978.557978]  [&lt;ffffffff81425fd9&gt;] dump_stack+0x4c/0x65
[23978.559191]  [&lt;ffffffff81045390&gt;] warn_slowpath_common+0xa1/0xbb
[23978.560699]  [&lt;ffffffffa047f0ea&gt;] ? btrfs_drop_extent_cache+0x43/0x385 [btrfs]
[23978.562389]  [&lt;ffffffff8104544d&gt;] warn_slowpath_null+0x1a/0x1c
[23978.563613]  [&lt;ffffffffa047f0ea&gt;] btrfs_drop_extent_cache+0x43/0x385 [btrfs]
[23978.565103]  [&lt;ffffffff810e3a18&gt;] ? time_hardirqs_off+0x15/0x28
[23978.566294]  [&lt;ffffffff81079ff8&gt;] ? trace_hardirqs_off+0xd/0xf
[23978.567438]  [&lt;ffffffffa047f73d&gt;] __btrfs_drop_extents+0x6b/0x9e1 [btrfs]
[23978.568702]  [&lt;ffffffff8107c03f&gt;] ? trace_hardirqs_on+0xd/0xf
[23978.569763]  [&lt;ffffffff811441c0&gt;] ? ____cache_alloc+0x69/0x2eb
[23978.570817]  [&lt;ffffffff81142269&gt;] ? virt_to_head_page+0x9/0x36
[23978.571872]  [&lt;ffffffff81143c15&gt;] ? cache_alloc_debugcheck_after.isra.42+0x16c/0x1cb
[23978.573466]  [&lt;ffffffff811420d5&gt;] ? kmemleak_alloc_recursive.constprop.52+0x16/0x18
[23978.574962]  [&lt;ffffffffa0480d07&gt;] btrfs_drop_extents+0x66/0x7f [btrfs]
[23978.576179]  [&lt;ffffffffa049aa35&gt;] btrfs_clone+0x516/0xaf5 [btrfs]
[23978.577311]  [&lt;ffffffffa04983dc&gt;] ? lock_extent_range+0x7b/0xcd [btrfs]
[23978.578520]  [&lt;ffffffffa049b2a2&gt;] btrfs_ioctl_clone+0x28e/0x39f [btrfs]
[23978.580282]  [&lt;ffffffffa049d9ae&gt;] btrfs_ioctl+0xb51/0x219a [btrfs]
(...)
[23978.591887] ---[ end trace 988ec2a653d03ed3 ]---

Then we attempt to insert a new extent item with a key that already
exists, which makes btrfs_insert_empty_item return -EEXIST resulting in
abortion of the current transaction:

[23978.594355] WARNING: CPU: 6 PID: 16251 at fs/btrfs/super.c:260 __btrfs_abort_transaction+0x52/0x114 [btrfs]()
(...)
[23978.622589] Call Trace:
[23978.623181]  [&lt;ffffffff81425fd9&gt;] dump_stack+0x4c/0x65
[23978.624359]  [&lt;ffffffff81045390&gt;] warn_slowpath_common+0xa1/0xbb
[23978.625573]  [&lt;ffffffffa044ab6c&gt;] ? __btrfs_abort_transaction+0x52/0x114 [btrfs]
[23978.626971]  [&lt;ffffffff810453f0&gt;] warn_slowpath_fmt+0x46/0x48
[23978.628003]  [&lt;ffffffff8108a6c8&gt;] ? vprintk_default+0x1d/0x1f
[23978.629138]  [&lt;ffffffffa044ab6c&gt;] __btrfs_abort_transaction+0x52/0x114 [btrfs]
[23978.630528]  [&lt;ffffffffa049ad1b&gt;] btrfs_clone+0x7fc/0xaf5 [btrfs]
[23978.631635]  [&lt;ffffffffa04983dc&gt;] ? lock_extent_range+0x7b/0xcd [btrfs]
[23978.632886]  [&lt;ffffffffa049b2a2&gt;] btrfs_ioctl_clone+0x28e/0x39f [btrfs]
[23978.634119]  [&lt;ffffffffa049d9ae&gt;] btrfs_ioctl+0xb51/0x219a [btrfs]
(...)
[23978.647714] ---[ end trace 988ec2a653d03ed4 ]---

This is wrong because we should not process the extent item that we just
inserted previously, and instead process the extent item that follows it
in the tree

For example for the test case I wrote for fstests:

   bs=$((64 * 1024))
   mkfs.btrfs -f -l $bs -O ^no-holes /dev/sdc
   mount /dev/sdc /mnt

   xfs_io -f -c "pwrite -S 0xaa $(($bs * 2)) $(($bs * 2))" /mnt/foo

   $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 /mnt/foo /mnt/foo
   $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 /mnt/foo /mnt/foo

The second clone call fails with -EEXIST, because when we process the
first extent item (offset 262144), we drop part of it (counting from the
end) and then insert a new extent item with a key greater then the key we
found. The next time we search the tree we search for a key with offset
262144 + 1, which leaves us at the new extent item we have just inserted
but we think it refers to an extent that we need to clone.

Fix this by ensuring the next search key uses an offset corresponding to
the offset of the key we found previously plus the data length of the
corresponding extent item. This ensures we skip new extent items that we
inserted and works for the case of implicit holes too (NO_HOLES feature).

A test case for fstests follows soon.

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>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit df858e76723ace61342b118aa4302bd09de4e386 upstream.

While searching for extents to clone we might find one where we only use
a part of it coming from its tail. If our destination inode is the same
the source inode, we end up removing the tail part of the extent item and
insert after a new one that point to the same extent with an adjusted
key file offset and data offset. After this we search for the next extent
item in the fs/subvol tree with a key that has an offset incremented by
one. But this second search leaves us at the new extent item we inserted
previously, and since that extent item has a non-zero data offset, it
it can make us call btrfs_drop_extents with an empty range (start == end)
which causes the following warning:

[23978.537119] WARNING: CPU: 6 PID: 16251 at fs/btrfs/file.c:550 btrfs_drop_extent_cache+0x43/0x385 [btrfs]()
(...)
[23978.557266] Call Trace:
[23978.557978]  [&lt;ffffffff81425fd9&gt;] dump_stack+0x4c/0x65
[23978.559191]  [&lt;ffffffff81045390&gt;] warn_slowpath_common+0xa1/0xbb
[23978.560699]  [&lt;ffffffffa047f0ea&gt;] ? btrfs_drop_extent_cache+0x43/0x385 [btrfs]
[23978.562389]  [&lt;ffffffff8104544d&gt;] warn_slowpath_null+0x1a/0x1c
[23978.563613]  [&lt;ffffffffa047f0ea&gt;] btrfs_drop_extent_cache+0x43/0x385 [btrfs]
[23978.565103]  [&lt;ffffffff810e3a18&gt;] ? time_hardirqs_off+0x15/0x28
[23978.566294]  [&lt;ffffffff81079ff8&gt;] ? trace_hardirqs_off+0xd/0xf
[23978.567438]  [&lt;ffffffffa047f73d&gt;] __btrfs_drop_extents+0x6b/0x9e1 [btrfs]
[23978.568702]  [&lt;ffffffff8107c03f&gt;] ? trace_hardirqs_on+0xd/0xf
[23978.569763]  [&lt;ffffffff811441c0&gt;] ? ____cache_alloc+0x69/0x2eb
[23978.570817]  [&lt;ffffffff81142269&gt;] ? virt_to_head_page+0x9/0x36
[23978.571872]  [&lt;ffffffff81143c15&gt;] ? cache_alloc_debugcheck_after.isra.42+0x16c/0x1cb
[23978.573466]  [&lt;ffffffff811420d5&gt;] ? kmemleak_alloc_recursive.constprop.52+0x16/0x18
[23978.574962]  [&lt;ffffffffa0480d07&gt;] btrfs_drop_extents+0x66/0x7f [btrfs]
[23978.576179]  [&lt;ffffffffa049aa35&gt;] btrfs_clone+0x516/0xaf5 [btrfs]
[23978.577311]  [&lt;ffffffffa04983dc&gt;] ? lock_extent_range+0x7b/0xcd [btrfs]
[23978.578520]  [&lt;ffffffffa049b2a2&gt;] btrfs_ioctl_clone+0x28e/0x39f [btrfs]
[23978.580282]  [&lt;ffffffffa049d9ae&gt;] btrfs_ioctl+0xb51/0x219a [btrfs]
(...)
[23978.591887] ---[ end trace 988ec2a653d03ed3 ]---

Then we attempt to insert a new extent item with a key that already
exists, which makes btrfs_insert_empty_item return -EEXIST resulting in
abortion of the current transaction:

[23978.594355] WARNING: CPU: 6 PID: 16251 at fs/btrfs/super.c:260 __btrfs_abort_transaction+0x52/0x114 [btrfs]()
(...)
[23978.622589] Call Trace:
[23978.623181]  [&lt;ffffffff81425fd9&gt;] dump_stack+0x4c/0x65
[23978.624359]  [&lt;ffffffff81045390&gt;] warn_slowpath_common+0xa1/0xbb
[23978.625573]  [&lt;ffffffffa044ab6c&gt;] ? __btrfs_abort_transaction+0x52/0x114 [btrfs]
[23978.626971]  [&lt;ffffffff810453f0&gt;] warn_slowpath_fmt+0x46/0x48
[23978.628003]  [&lt;ffffffff8108a6c8&gt;] ? vprintk_default+0x1d/0x1f
[23978.629138]  [&lt;ffffffffa044ab6c&gt;] __btrfs_abort_transaction+0x52/0x114 [btrfs]
[23978.630528]  [&lt;ffffffffa049ad1b&gt;] btrfs_clone+0x7fc/0xaf5 [btrfs]
[23978.631635]  [&lt;ffffffffa04983dc&gt;] ? lock_extent_range+0x7b/0xcd [btrfs]
[23978.632886]  [&lt;ffffffffa049b2a2&gt;] btrfs_ioctl_clone+0x28e/0x39f [btrfs]
[23978.634119]  [&lt;ffffffffa049d9ae&gt;] btrfs_ioctl+0xb51/0x219a [btrfs]
(...)
[23978.647714] ---[ end trace 988ec2a653d03ed4 ]---

This is wrong because we should not process the extent item that we just
inserted previously, and instead process the extent item that follows it
in the tree

For example for the test case I wrote for fstests:

   bs=$((64 * 1024))
   mkfs.btrfs -f -l $bs -O ^no-holes /dev/sdc
   mount /dev/sdc /mnt

   xfs_io -f -c "pwrite -S 0xaa $(($bs * 2)) $(($bs * 2))" /mnt/foo

   $CLONER_PROG -s $((3 * $bs)) -d $((267 * $bs)) -l 0 /mnt/foo /mnt/foo
   $CLONER_PROG -s $((217 * $bs)) -d $((95 * $bs)) -l 0 /mnt/foo /mnt/foo

The second clone call fails with -EEXIST, because when we process the
first extent item (offset 262144), we drop part of it (counting from the
end) and then insert a new extent item with a key greater then the key we
found. The next time we search the tree we search for a key with offset
262144 + 1, which leaves us at the new extent item we have just inserted
but we think it refers to an extent that we need to clone.

Fix this by ensuring the next search key uses an offset corresponding to
the offset of the key we found previously plus the data length of the
corresponding extent item. This ensures we skip new extent items that we
inserted and works for the case of implicit holes too (NO_HOLES feature).

A test case for fstests follows soon.

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;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: cleanup orphans while looking up default subvolume</title>
<updated>2015-06-23T00:03:36+00:00</updated>
<author>
<name>Jeff Mahoney</name>
<email>jeffm@suse.com</email>
</author>
<published>2015-03-20T18:02:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=845f2c2fdf8a351d98e8d12371a713a785333982'/>
<id>845f2c2fdf8a351d98e8d12371a713a785333982</id>
<content type='text'>
commit 727b9784b6085c99c2f836bf4fcc2848dc9cf904 upstream.

Orphans in the fs tree are cleaned up via open_ctree and subvolume
orphans are cleaned via btrfs_lookup_dentry -- except when a default
subvolume is in use.  The name for the default subvolume uses a manual
lookup that doesn't trigger orphan cleanup and needs to trigger it
manually as well. This doesn't apply to the remount case since the
subvolumes are cleaned up by walking the root radix tree.

Signed-off-by: Jeff Mahoney &lt;jeffm@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&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 727b9784b6085c99c2f836bf4fcc2848dc9cf904 upstream.

Orphans in the fs tree are cleaned up via open_ctree and subvolume
orphans are cleaned via btrfs_lookup_dentry -- except when a default
subvolume is in use.  The name for the default subvolume uses a manual
lookup that doesn't trigger orphan cleanup and needs to trigger it
manually as well. This doesn't apply to the remount case since the
subvolumes are cleaned up by walking the root radix tree.

Signed-off-by: Jeff Mahoney &lt;jeffm@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&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: incorrect handling for fiemap_fill_next_extent return</title>
<updated>2015-06-23T00:03:36+00:00</updated>
<author>
<name>Chengyu Song</name>
<email>csong84@gatech.edu</email>
</author>
<published>2015-03-24T22:12:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=2c45304d93598f1049e8d4d9bd44218b200befea'/>
<id>2c45304d93598f1049e8d4d9bd44218b200befea</id>
<content type='text'>
commit 26e726afe01c1c82072cf23a5ed89ce25f39d9f2 upstream.

fiemap_fill_next_extent returns 0 on success, -errno on error, 1 if this was
the last extent that will fit in user array. If 1 is returned, the return
value may eventually returned to user space, which should not happen, according
to manpage of ioctl.

Signed-off-by: Chengyu Song &lt;csong84@gatech.edu&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&gt;
Reviewed-by: Liu Bo &lt;bo.li.liu@oracle.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 26e726afe01c1c82072cf23a5ed89ce25f39d9f2 upstream.

fiemap_fill_next_extent returns 0 on success, -errno on error, 1 if this was
the last extent that will fit in user array. If 1 is returned, the return
value may eventually returned to user space, which should not happen, according
to manpage of ioctl.

Signed-off-by: Chengyu Song &lt;csong84@gatech.edu&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&gt;
Reviewed-by: Liu Bo &lt;bo.li.liu@oracle.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: send, don't leave without decrementing clone root's send_progress</title>
<updated>2015-06-23T00:03:36+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-03-02T20:53:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=3a1e1ca1ba46fef415b663b44dae50cf1c0447f0'/>
<id>3a1e1ca1ba46fef415b663b44dae50cf1c0447f0</id>
<content type='text'>
commit 2f1f465ae6da244099af55c066e5355abd8ff620 upstream.

If the clone root was not readonly or the dead flag was set on it, we were
leaving without decrementing the root's send_progress counter (and before
we just incremented it). If a concurrent snapshot deletion was in progress
and ended up being aborted, it would be impossible to later attempt to
delete again the snapshot, since the root's send_in_progress counter could
never go back to 0.

We were also setting clone_sources_to_rollback to i + 1 too early - if we
bailed out because the clone root we got is not readonly or flagged as dead
we ended up later derreferencing a null pointer because we didn't assign
the clone root to sctx-&gt;clone_roots[i].root:

		for (i = 0; sctx &amp;&amp; i &lt; clone_sources_to_rollback; i++)
			btrfs_root_dec_send_in_progress(
					sctx-&gt;clone_roots[i].root);

So just don't increment the send_in_progress counter if the root is readonly
or flagged as dead.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&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 2f1f465ae6da244099af55c066e5355abd8ff620 upstream.

If the clone root was not readonly or the dead flag was set on it, we were
leaving without decrementing the root's send_progress counter (and before
we just incremented it). If a concurrent snapshot deletion was in progress
and ended up being aborted, it would be impossible to later attempt to
delete again the snapshot, since the root's send_in_progress counter could
never go back to 0.

We were also setting clone_sources_to_rollback to i + 1 too early - if we
bailed out because the clone root we got is not readonly or flagged as dead
we ended up later derreferencing a null pointer because we didn't assign
the clone root to sctx-&gt;clone_roots[i].root:

		for (i = 0; sctx &amp;&amp; i &lt; clone_sources_to_rollback; i++)
			btrfs_root_dec_send_in_progress(
					sctx-&gt;clone_roots[i].root);

So just don't increment the send_in_progress counter if the root is readonly
or flagged as dead.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&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: send, add missing check for dead clone root</title>
<updated>2015-06-23T00:03:36+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-03-02T20:53:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=146a4565fa80cb586abcda5575922d5ac71162c9'/>
<id>146a4565fa80cb586abcda5575922d5ac71162c9</id>
<content type='text'>
commit 5cc2b17e80cf5770f2e585c2d90fd8af1b901258 upstream.

After we locked the root's root item, a concurrent snapshot deletion
call might have set the dead flag on it. So check if the dead flag
is set and abort if it is, just like we do for the parent root.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&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 5cc2b17e80cf5770f2e585c2d90fd8af1b901258 upstream.

After we locked the root's root item, a concurrent snapshot deletion
call might have set the dead flag on it. So check if the dead flag
is set and abort if it is, just like we do for the parent root.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&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: fix racy system chunk allocation when setting block group ro</title>
<updated>2015-06-06T15:20:52+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-05-18T18:11:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=68482f12d90fb757eef19493fb7bf7fdc1029a7a'/>
<id>68482f12d90fb757eef19493fb7bf7fdc1029a7a</id>
<content type='text'>
commit a96295965b600f2dc6ad661c4803c86e87db3d7b upstream.

If while setting a block group read-only we end up allocating a system
chunk, through check_system_chunk(), we were not doing it while holding
the chunk mutex which is a problem if a concurrent chunk allocation is
happening, through do_chunk_alloc(), as it means both block groups can
end up using the same logical addresses and physical regions in the
device(s). So make sure we hold the chunk mutex.

Fixes: 2f0810880f08 ("btrfs: delete chunk allocation attemp when
                      setting block group ro")

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>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit a96295965b600f2dc6ad661c4803c86e87db3d7b upstream.

If while setting a block group read-only we end up allocating a system
chunk, through check_system_chunk(), we were not doing it while holding
the chunk mutex which is a problem if a concurrent chunk allocation is
happening, through do_chunk_alloc(), as it means both block groups can
end up using the same logical addresses and physical regions in the
device(s). So make sure we hold the chunk mutex.

Fixes: 2f0810880f08 ("btrfs: delete chunk allocation attemp when
                      setting block group ro")

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;

</pre>
</div>
</content>
</entry>
<entry>
<title>btrfs: unlock i_mutex after attempting to delete subvolume during send</title>
<updated>2015-05-13T12:14:27+00:00</updated>
<author>
<name>Omar Sandoval</name>
<email>osandov@osandov.com</email>
</author>
<published>2015-04-10T21:20:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=8ab261bcddc4010cb395e659a58b67d854be7ede'/>
<id>8ab261bcddc4010cb395e659a58b67d854be7ede</id>
<content type='text'>
commit 909e26dce3f7600f5e293ac0522c28790a0c8c9c upstream.

Whenever the check for a send in progress introduced in commit
521e0546c970 (btrfs: protect snapshots from deleting during send) is
hit, we return without unlocking inode-&gt;i_mutex. This is easy to see
with lockdep enabled:

[  +0.000059] ================================================
[  +0.000028] [ BUG: lock held when returning to user space! ]
[  +0.000029] 4.0.0-rc5-00096-g3c435c1 #93 Not tainted
[  +0.000026] ------------------------------------------------
[  +0.000029] btrfs/211 is leaving the kernel with locks still held!
[  +0.000029] 1 lock held by btrfs/211:
[  +0.000023]  #0:  (&amp;type-&gt;i_mutex_dir_key){+.+.+.}, at: [&lt;ffffffff8135b8df&gt;] btrfs_ioctl_snap_destroy+0x2df/0x7a0

Make sure we unlock it in the error path.

Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&gt;
Signed-off-by: Omar Sandoval &lt;osandov@osandov.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 909e26dce3f7600f5e293ac0522c28790a0c8c9c upstream.

Whenever the check for a send in progress introduced in commit
521e0546c970 (btrfs: protect snapshots from deleting during send) is
hit, we return without unlocking inode-&gt;i_mutex. This is easy to see
with lockdep enabled:

[  +0.000059] ================================================
[  +0.000028] [ BUG: lock held when returning to user space! ]
[  +0.000029] 4.0.0-rc5-00096-g3c435c1 #93 Not tainted
[  +0.000026] ------------------------------------------------
[  +0.000029] btrfs/211 is leaving the kernel with locks still held!
[  +0.000029] 1 lock held by btrfs/211:
[  +0.000023]  #0:  (&amp;type-&gt;i_mutex_dir_key){+.+.+.}, at: [&lt;ffffffff8135b8df&gt;] btrfs_ioctl_snap_destroy+0x2df/0x7a0

Make sure we unlock it in the error path.

Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.cz&gt;
Signed-off-by: Omar Sandoval &lt;osandov@osandov.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: fix inode eviction infinite loop after extent_same ioctl</title>
<updated>2015-05-06T20:03:38+00:00</updated>
<author>
<name>Filipe Manana</name>
<email>fdmanana@suse.com</email>
</author>
<published>2015-03-30T17:26:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=68ea2629745f61ddf8a603970e74b294737bc5d7'/>
<id>68ea2629745f61ddf8a603970e74b294737bc5d7</id>
<content type='text'>
commit 113e8283869b9855c8b999796aadd506bbac155f upstream.

If we pass a length of 0 to the extent_same ioctl, we end up locking an
extent range with a start offset greater then its end offset (if the
destination file's offset is greater than zero). This results in a warning
from extent_io.c:insert_state through the following call chain:

  btrfs_extent_same()
    btrfs_double_lock()
      lock_extent_range()
        lock_extent(inode-&gt;io_tree, offset, offset + len - 1)
          lock_extent_bits()
            __set_extent_bit()
              insert_state()
                --&gt; WARN_ON(end &lt; start)

This leads to an infinite loop when evicting the inode. This is the same
problem that my previous patch titled
"Btrfs: fix inode eviction infinite loop after cloning into it" addressed
but for the extent_same ioctl instead of the clone ioctl.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: Omar Sandoval &lt;osandov@osandov.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 113e8283869b9855c8b999796aadd506bbac155f upstream.

If we pass a length of 0 to the extent_same ioctl, we end up locking an
extent range with a start offset greater then its end offset (if the
destination file's offset is greater than zero). This results in a warning
from extent_io.c:insert_state through the following call chain:

  btrfs_extent_same()
    btrfs_double_lock()
      lock_extent_range()
        lock_extent(inode-&gt;io_tree, offset, offset + len - 1)
          lock_extent_bits()
            __set_extent_bit()
              insert_state()
                --&gt; WARN_ON(end &lt; start)

This leads to an infinite loop when evicting the inode. This is the same
problem that my previous patch titled
"Btrfs: fix inode eviction infinite loop after cloning into it" addressed
but for the extent_same ioctl instead of the clone ioctl.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: Omar Sandoval &lt;osandov@osandov.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>
</feed>
