<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/btrfs/inode-map.c, branch linux-4.0.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.0.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-4.0.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2014-12-03T02:35:09Z</updated>
<entry>
<title>Btrfs: fix race between writing free space cache and trimming</title>
<updated>2014-12-03T02:35:09Z</updated>
<author>
<name>Filipe Manana</name>
</author>
<published>2014-12-01T17:04:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=55507ce3612365a5173dfb080a4baf45d1ef8cd1'/>
<id>urn:sha1:55507ce3612365a5173dfb080a4baf45d1ef8cd1</id>
<content type='text'>
Trimming is completely transactionless, and the way it operates consists
of hiding free space entries from a block group, perform the trim/discard
and then make the free space entries visible again.
Therefore while a free space entry is being trimmed, we can have free space
cache writing running in parallel (as part of a transaction commit) which
will miss the free space entry. This means that an unmount (or crash/reboot)
after that transaction commit and mount again before another transaction
starts/commits after the discard finishes, we will have some free space
that won't be used again unless the free space cache is rebuilt. After the
unmount, fsck (btrfsck, btrfs check) reports the issue like the following
example:

        *** fsck.btrfs output ***
        checking extents
        checking free space cache
        There is no free space entry for 521764864-521781248
        There is no free space entry for 521764864-1103101952
        cache appears valid but isnt 29360128
        Checking filesystem on /dev/sdc
        UUID: b4789e27-4774-4626-98e9-ae8dfbfb0fb5
        found 1235681286 bytes used err is -22
        (...)

Another issue caused by this race is a crash while writing bitmap entries
to the cache, because while the cache writeout task accesses the bitmaps,
the trim task can be concurrently modifying the bitmap or worse might
be freeing the bitmap. The later case results in the following crash:

[55650.804460] general protection fault: 0000 [#1] SMP DEBUG_PAGEALLOC
[55650.804835] Modules linked in: btrfs dm_flakey dm_mod crc32c_generic xor raid6_pq nfsd auth_rpcgss oid_registry nfs_acl nfs lockd fscache sunrpc loop parport_pc parport i2c_piix4 psmouse evdev pcspkr microcode processor i2ccore serio_raw thermal_sys button ext4 crc16 jbd2 mbcache sg sd_mod crc_t10dif sr_mod cdrom crct10dif_generic crct10dif_common ata_generic virtio_scsi floppy ata_piix libata virtio_pci virtio_ring virtio scsi_mod e1000 [last unloaded: btrfs]
[55650.806169] CPU: 1 PID: 31002 Comm: btrfs-transacti Tainted: G        W      3.17.0-rc5-btrfs-next-1+ #1
[55650.806493] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014
[55650.806867] task: ffff8800b12f6410 ti: ffff880071538000 task.ti: ffff880071538000
[55650.807166] RIP: 0010:[&lt;ffffffffa037cf45&gt;]  [&lt;ffffffffa037cf45&gt;] write_bitmap_entries+0x65/0xbb [btrfs]
[55650.807514] RSP: 0018:ffff88007153bc30  EFLAGS: 00010246
[55650.807687] RAX: 000000005d1ec000 RBX: ffff8800a665df08 RCX: 0000000000000400
[55650.807885] RDX: ffff88005d1ec000 RSI: 6b6b6b6b6b6b6b6b RDI: ffff88005d1ec000
[55650.808017] RBP: ffff88007153bc58 R08: 00000000ddd51536 R09: 00000000000001e0
[55650.808017] R10: 0000000000000000 R11: 0000000000000037 R12: 6b6b6b6b6b6b6b6b
[55650.808017] R13: ffff88007153bca8 R14: 6b6b6b6b6b6b6b6b R15: ffff88007153bc98
[55650.808017] FS:  0000000000000000(0000) GS:ffff88023ec80000(0000) knlGS:0000000000000000
[55650.808017] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[55650.808017] CR2: 0000000002273b88 CR3: 00000000b18f6000 CR4: 00000000000006e0
[55650.808017] Stack:
[55650.808017]  ffff88020e834e00 ffff880172d68db0 0000000000000000 ffff88019257c800
[55650.808017]  ffff8801d42ea720 ffff88007153bd10 ffffffffa037d2fa ffff880224e99180
[55650.808017]  ffff8801469a6188 ffff880224e99140 ffff880172d68c50 00000003000000b7
[55650.808017] Call Trace:
[55650.808017]  [&lt;ffffffffa037d2fa&gt;] __btrfs_write_out_cache+0x1ea/0x37f [btrfs]
[55650.808017]  [&lt;ffffffffa037d959&gt;] btrfs_write_out_cache+0xa1/0xd8 [btrfs]
[55650.808017]  [&lt;ffffffffa033936b&gt;] btrfs_write_dirty_block_groups+0x4b5/0x505 [btrfs]
[55650.808017]  [&lt;ffffffffa03aa98e&gt;] commit_cowonly_roots+0x15e/0x1f7 [btrfs]
[55650.808017]  [&lt;ffffffff813eb9c7&gt;] ? _raw_spin_lock+0xe/0x10
[55650.808017]  [&lt;ffffffffa0346e46&gt;] btrfs_commit_transaction+0x411/0x882 [btrfs]
[55650.808017]  [&lt;ffffffffa03432a4&gt;] transaction_kthread+0xf2/0x1a4 [btrfs]
[55650.808017]  [&lt;ffffffffa03431b2&gt;] ? btrfs_cleanup_transaction+0x3d8/0x3d8 [btrfs]
[55650.808017]  [&lt;ffffffff8105966b&gt;] kthread+0xb7/0xbf
[55650.808017]  [&lt;ffffffff810595b4&gt;] ? __kthread_parkme+0x67/0x67
[55650.808017]  [&lt;ffffffff813ebeac&gt;] ret_from_fork+0x7c/0xb0
[55650.808017]  [&lt;ffffffff810595b4&gt;] ? __kthread_parkme+0x67/0x67
[55650.808017] Code: 4c 89 ef 8d 70 ff e8 d4 fc ff ff 41 8b 45 34 41 39 45 30 7d 5c 31 f6 4c 89 ef e8 80 f6 ff ff 49 8b 7d 00 4c 89 f6 b9 00 04 00 00 &lt;f3&gt; a5 4c 89 ef 41 8b 45 30 8d 70 ff e8 a3 fc ff ff 41 8b 45 34
[55650.808017] RIP  [&lt;ffffffffa037cf45&gt;] write_bitmap_entries+0x65/0xbb [btrfs]
[55650.808017]  RSP &lt;ffff88007153bc30&gt;
[55650.815725] ---[ end trace 1c032e96b149ff86 ]---

Fix this by serializing both tasks in such a way that cache writeout
doesn't wait for the trim/discard of free space entries to finish and
doesn't miss any free space entry.

Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>btrfs: switch inode_cache option handling to pending changes</title>
<updated>2014-11-12T15:53:13Z</updated>
<author>
<name>David Sterba</name>
</author>
<published>2014-02-05T14:26:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7e1876aca815029d5c3023a66a91e249eca3e533'/>
<id>urn:sha1:7e1876aca815029d5c3023a66a91e249eca3e533</id>
<content type='text'>
The pending mount option(s) now share namespace and bits with the normal
options, and the existing one for (inode_cache) is unset unconditionally
at each transaction commit.

Introduce a separate namespace for pending changes and enhance the
descriptions of the intended change to use separate bits for each
action.

Signed-off-by: David Sterba &lt;dsterba@suse.cz&gt;
</content>
</entry>
<entry>
<title>btrfs: cleanup ino cache members of btrfs_root</title>
<updated>2014-09-17T20:37:09Z</updated>
<author>
<name>David Sterba</name>
</author>
<published>2014-02-05T01:37:48Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=57cdc8db21bf9cfa6b2e45310d56e74e263e8609'/>
<id>urn:sha1:57cdc8db21bf9cfa6b2e45310d56e74e263e8609</id>
<content type='text'>
The naming is confusing, generic yet used for a specific cache. Add a
prefix 'ino_' or rename appropriately.

Signed-off-by: David Sterba &lt;dsterba@suse.cz&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>btrfs: remove newline from inode cache kthread name</title>
<updated>2014-06-10T00:20:53Z</updated>
<author>
<name>David Sterba</name>
</author>
<published>2014-05-16T13:15:45Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=67a77eb147a36fdc346f1b9ff84649209d51f1da'/>
<id>urn:sha1:67a77eb147a36fdc346f1b9ff84649209d51f1da</id>
<content type='text'>
Signed-off-by: David Sterba &lt;dsterba@suse.cz&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: fix inode caching vs tree log</title>
<updated>2014-04-24T23:43:33Z</updated>
<author>
<name>Miao Xie</name>
</author>
<published>2014-04-23T11:33:36Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1c70d8fb4dfa95bee491816b2a6767b5ca1080e7'/>
<id>urn:sha1:1c70d8fb4dfa95bee491816b2a6767b5ca1080e7</id>
<content type='text'>
Currently, with inode cache enabled, we will reuse its inode id immediately
after unlinking file, we may hit something like following:

|-&gt;iput inode
|-&gt;return inode id into inode cache
|-&gt;create dir,fsync
|-&gt;power off

An easy way to reproduce this problem is:

mkfs.btrfs -f /dev/sdb
mount /dev/sdb /mnt -o inode_cache,commit=100
dd if=/dev/zero of=/mnt/data bs=1M count=10 oflag=sync
inode_id=`ls -i /mnt/data | awk '{print $1}'`
rm -f /mnt/data

i=1
while [ 1 ]
do
        mkdir /mnt/dir_$i
        test1=`stat /mnt/dir_$i | grep Inode: | awk '{print $4}'`
        if [ $test1 -eq $inode_id ]
        then
		dd if=/dev/zero of=/mnt/dir_$i/data bs=1M count=1 oflag=sync
		echo b &gt; /proc/sysrq-trigger
	fi
	sleep 1
        i=$(($i+1))
done

mount /dev/sdb /mnt
umount /dev/sdb
btrfs check /dev/sdb

We fix this problem by adding unlinked inode's id into pinned tree,
and we can not reuse them until committing transaction.

Cc: stable@vger.kernel.org
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>
</entry>
<entry>
<title>Btrfs: avoid triggering bug_on() when we fail to start inode caching task</title>
<updated>2014-04-24T23:43:32Z</updated>
<author>
<name>Wang Shilong</name>
</author>
<published>2014-04-23T11:33:34Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e60efa84252c059bde5f65fccc6af94478d39e3b'/>
<id>urn:sha1:e60efa84252c059bde5f65fccc6af94478d39e3b</id>
<content type='text'>
When running stress test(including snapshots,balance,fstress), we trigger
the following BUG_ON() which is because we fail to start inode caching task.

[  181.131945] kernel BUG at fs/btrfs/inode-map.c:179!
[  181.137963] invalid opcode: 0000 [#1] SMP
[  181.217096] CPU: 11 PID: 2532 Comm: btrfs Not tainted 3.14.0 #1
[  181.240521] task: ffff88013b621b30 ti: ffff8800b6ada000 task.ti: ffff8800b6ada000
[  181.367506] Call Trace:
[  181.371107]  [&lt;ffffffffa036c1be&gt;] btrfs_return_ino+0x9e/0x110 [btrfs]
[  181.379191]  [&lt;ffffffffa038082b&gt;] btrfs_evict_inode+0x46b/0x4c0 [btrfs]
[  181.387464]  [&lt;ffffffff810b5a70&gt;] ? autoremove_wake_function+0x40/0x40
[  181.395642]  [&lt;ffffffff811dc5fe&gt;] evict+0x9e/0x190
[  181.401882]  [&lt;ffffffff811dcde3&gt;] iput+0xf3/0x180
[  181.408025]  [&lt;ffffffffa03812de&gt;] btrfs_orphan_cleanup+0x1ee/0x430 [btrfs]
[  181.416614]  [&lt;ffffffffa03a6abd&gt;] btrfs_mksubvol.isra.29+0x3bd/0x450 [btrfs]
[  181.425399]  [&lt;ffffffffa03a6cd6&gt;] btrfs_ioctl_snap_create_transid+0x186/0x190 [btrfs]
[  181.435059]  [&lt;ffffffffa03a6e3b&gt;] btrfs_ioctl_snap_create_v2+0xeb/0x130 [btrfs]
[  181.444148]  [&lt;ffffffffa03a9656&gt;] btrfs_ioctl+0xf76/0x2b90 [btrfs]
[  181.451971]  [&lt;ffffffff8117e565&gt;] ? handle_mm_fault+0x475/0xe80
[  181.459509]  [&lt;ffffffff8167ba0c&gt;] ? __do_page_fault+0x1ec/0x520
[  181.467046]  [&lt;ffffffff81185b35&gt;] ? do_mmap_pgoff+0x2f5/0x3c0
[  181.474393]  [&lt;ffffffff811d4da8&gt;] do_vfs_ioctl+0x2d8/0x4b0
[  181.481450]  [&lt;ffffffff811d5001&gt;] SyS_ioctl+0x81/0xa0
[  181.488021]  [&lt;ffffffff81680b69&gt;] system_call_fastpath+0x16/0x1b

We should avoid triggering BUG_ON() here, instead, we output warning messages
and clear inode_cache option.

Signed-off-by: Wang Shilong &lt;wangsl.fnst@cn.fujitsu.com&gt;
Signed-off-by: Chris Mason &lt;clm@fb.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: remove transaction from send</title>
<updated>2014-04-07T00:39:30Z</updated>
<author>
<name>Josef Bacik</name>
</author>
<published>2014-03-13T19:42:13Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9e351cc862b098d8ec8f8022d110932490794925'/>
<id>urn:sha1:9e351cc862b098d8ec8f8022d110932490794925</id>
<content type='text'>
Lets try this again.  We can deadlock the box if we send on a box and try to
write onto the same fs with the app that is trying to listen to the send pipe.
This is because the writer could get stuck waiting for a transaction commit
which is being blocked by the send.  So fix this by making sure looking at the
commit roots is always going to be consistent.  We do this by keeping track of
which roots need to have their commit roots swapped during commit, and then
taking the commit_root_sem and swapping them all at once.  Then make sure we
take a read lock on the commit_root_sem in cases where we search the commit root
to make sure we're always looking at a consistent view of the commit roots.
Previously we had problems with this because we would swap a fs tree commit root
and then swap the extent tree commit root independently which would cause the
backref walking code to screw up sometimes.  With this patch we no longer
deadlock and pass all the weird send/receive corner cases.  Thanks,

Reportedy-by: Hugo Mills &lt;hugo@carfax.org.uk&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: Use WARN_ON()'s return value in place of WARN_ON(1)</title>
<updated>2013-11-12T03:11:53Z</updated>
<author>
<name>Dulshani Gunawardhana</name>
</author>
<published>2013-10-31T05:00:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fae7f21cece9a4c181a8d8131870c7247e153f65'/>
<id>urn:sha1:fae7f21cece9a4c181a8d8131870c7247e153f65</id>
<content type='text'>
Use WARN_ON()'s return value in place of WARN_ON(1) for cleaner source
code that outputs a more descriptive warnings. Also fix the styling
warning of redundant braces that came up as a result of this fix.

Signed-off-by: Dulshani Gunawardhana &lt;dulshani.gunawardhana89@gmail.com&gt;
Reviewed-by: Zach Brown &lt;zab@redhat.com&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fusionio.com&gt;
Signed-off-by: Chris Mason &lt;chris.mason@fusionio.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: Don't allocate inode that is already in use</title>
<updated>2013-11-12T03:02:36Z</updated>
<author>
<name>Stefan Behrens</name>
</author>
<published>2013-10-15T18:08:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ff76b0565523319d7c1c0b51d5a5a8915d33efab'/>
<id>urn:sha1:ff76b0565523319d7c1c0b51d5a5a8915d33efab</id>
<content type='text'>
Due to an off-by-one error, it is possible to reproduce a bug
when the inode cache is used.

The same inode number is assigned twice, the second time this
leads to an EEXIST in btrfs_insert_empty_items().

The issue can happen when a file is removed right after a subvolume
is created and then a new inode number is created before the
inodes in free_inode_pinned are processed.
unlink() calls btrfs_return_ino() which calls start_caching() in this
case which adds [highest_ino + 1, BTRFS_LAST_FREE_OBJECTID] by
searching for the highest inode (which already cannot find the
unlinked one anymore in btrfs_find_free_objectid()). So if this
unlinked inode's number is equal to the highest_ino + 1 (or &gt;= this value
instead of &gt; this value which was the off-by-one error), we mustn't add
the inode number to free_ino_pinned (caching_thread() does it right).
In this case we need to try directly to add the number to the inode_cache
which will fail in this case.

When this inode number is allocated while it is still in free_ino_pinned,
it is allocated and still added to the free inode cache when the
pinned inodes are processed, thus one of the following inode number
allocations will get an inode that is already in use and fail with EEXIST
in btrfs_insert_empty_items().

One example which was created with the reproducer below:
Create a snapshot, work in the newly created snapshot for the rest.
In unlink(inode 34284) call btrfs_return_ino() which calls start_caching().
start_caching() calls add_free_space [34284, 18446744073709517077].
In btrfs_return_ino(), call start_caching pinned [34284, 1] which is wrong.
mkdir() call btrfs_find_ino_for_alloc() which returns the number 34284.
btrfs_unpin_free_ino calls add_free_space [34284, 1].
mkdir() call btrfs_find_ino_for_alloc() which returns the number 34284.
EEXIST when the new inode is inserted.

One possible reproducer is this one:
 #!/bin/sh
 # preparation
TEST_DEV=/dev/sdc1
TEST_MNT=/mnt
umount ${TEST_MNT} 2&gt;/dev/null || true
mkfs.btrfs -f ${TEST_DEV}
mount ${TEST_DEV} ${TEST_MNT} -o \
 rw,relatime,compress=lzo,space_cache,inode_cache
btrfs subv create ${TEST_MNT}/s1
for i in `seq 34027`; do touch ${TEST_MNT}/s1/${i}; done
btrfs subv snap ${TEST_MNT}/s1 ${TEST_MNT}/s2
FILENAME=`find ${TEST_MNT}/s1/ -inum 4085 | sed 's|^.*/\([^/]*\)$|\1|'`
rm ${TEST_MNT}/s2/$FILENAME
touch ${TEST_MNT}/s2/$FILENAME
 # the following steps can be repeated to reproduce the issue again and again
[ -e ${TEST_MNT}/s3 ] &amp;&amp; btrfs subv del ${TEST_MNT}/s3
btrfs subv snap ${TEST_MNT}/s2 ${TEST_MNT}/s3
rm ${TEST_MNT}/s3/$FILENAME
touch ${TEST_MNT}/s3/$FILENAME
ls -alFi ${TEST_MNT}/s?/$FILENAME
touch ${TEST_MNT}/s3/_1 || logger FAILED
ls -alFi ${TEST_MNT}/s?/_1
touch ${TEST_MNT}/s3/_2 || logger FAILED
ls -alFi ${TEST_MNT}/s?/_2
touch ${TEST_MNT}/s3/__1 || logger FAILED
ls -alFi ${TEST_MNT}/s?/__1
touch ${TEST_MNT}/s3/__2 || logger FAILED
ls -alFi ${TEST_MNT}/s?/__2
 # if the above is not enough, add the following loop:
for i in `seq 3 9`; do touch ${TEST_MNT}/s3/__${i} || logger FAILED; done
 #for i in `seq 3 34027`; do touch ${TEST_MNT}/s3/__${i} || logger FAILED; done
 # one of the touch(1) calls in s3 fail due to EEXIST because the inode is
 # already in use that btrfs_find_ino_for_alloc() returns.

Signed-off-by: Stefan Behrens &lt;sbehrens@giantdisaster.de&gt;
Reviewed-by: Jan Schmidt &lt;list.btrfs@jan-o-sch.net&gt;
Signed-off-by: Josef Bacik &lt;jbacik@fusionio.com&gt;
Signed-off-by: Chris Mason &lt;chris.mason@fusionio.com&gt;
</content>
</entry>
<entry>
<title>Btrfs: remove path arg from btrfs_truncate_free_space_cache</title>
<updated>2013-11-12T02:51:33Z</updated>
<author>
<name>Filipe David Borba Manana</name>
</author>
<published>2013-09-20T13:46:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=74514323947ef27347564bfd7a663fdb3429cb20'/>
<id>urn:sha1:74514323947ef27347564bfd7a663fdb3429cb20</id>
<content type='text'>
Not used for anything, and removing it avoids caller's need to
allocate a path structure.

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