<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/btrfs/extent-tree.c, branch master</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=master</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2026-02-26T14:03:26Z</updated>
<entry>
<title>btrfs: handle discard errors in in btrfs_finish_extent_commit()</title>
<updated>2026-02-26T14:03:26Z</updated>
<author>
<name>Jingkai Tan</name>
</author>
<published>2026-01-22T21:14:10Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=2970525f789c080e7e82ecb09cd85a8bb1d284e4'/>
<id>urn:sha1:2970525f789c080e7e82ecb09cd85a8bb1d284e4</id>
<content type='text'>
Coverity (ID: 1226842) reported that the return value of
btrfs_discard_extent() is assigned to ret but is immediately
overwritten by unpin_extent_range() without being checked.

Use the same error handling that is done later in the same function.

Signed-off-by: Jingkai Tan &lt;contact@jingk.ai&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: fix transaction commit blocking during trim of unallocated space</title>
<updated>2026-02-03T06:56:25Z</updated>
<author>
<name>jinbaohong</name>
</author>
<published>2026-01-28T07:06:41Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b291ad4458df8311626dfa0a089918f6a542d6bc'/>
<id>urn:sha1:b291ad4458df8311626dfa0a089918f6a542d6bc</id>
<content type='text'>
When trimming unallocated space, btrfs_trim_fs() holds the device_list_mutex
for the entire duration while iterating through all devices. On large
filesystems with significant unallocated space, this operation can take
minutes to hours on large storage systems.

This causes a problem because btrfs_run_dev_stats(), which is called
during transaction commit, also requires device_list_mutex:

  btrfs_trim_fs()
    mutex_lock(&amp;fs_devices-&gt;device_list_mutex)
    list_for_each_entry(device, ...)
      btrfs_trim_free_extents(device)
    mutex_unlock(&amp;fs_devices-&gt;device_list_mutex)

  commit_transaction()
    btrfs_run_dev_stats()
      mutex_lock(&amp;fs_devices-&gt;device_list_mutex)  // blocked!
      ...

While trim is running, all transaction commits are blocked waiting for
the mutex.

Fix this by refactoring btrfs_trim_free_extents() to process devices in
bounded chunks (up to 2GB per iteration) and release device_list_mutex
between chunks.

Signed-off-by: robbieko &lt;robbieko@synology.com&gt;
Signed-off-by: jinbaohong &lt;jinbaohong@synology.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: handle user interrupt properly in btrfs_trim_fs()</title>
<updated>2026-02-03T06:56:25Z</updated>
<author>
<name>jinbaohong</name>
</author>
<published>2026-01-28T07:06:40Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=bfb670b9183b0e4ba660aff2e396ec1cc01d0761'/>
<id>urn:sha1:bfb670b9183b0e4ba660aff2e396ec1cc01d0761</id>
<content type='text'>
When a fatal signal is pending or the process is freezing,
btrfs_trim_block_group() and btrfs_trim_free_extents() return -ERESTARTSYS.
Currently this is treated as a regular error: the loops continue to the
next iteration and count it as a block group or device failure.

Instead, break out of the loops immediately and return -ERESTARTSYS to
userspace without counting it as a failure. Also skip the device loop
entirely if the block group loop was interrupted.

Reviewed-by: Qu Wenruo &lt;wqu@suse.com&gt;
Signed-off-by: Robbie Ko &lt;robbieko@synology.com&gt;
Signed-off-by: jinbaohong &lt;jinbaohong@synology.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: preserve first error in btrfs_trim_fs()</title>
<updated>2026-02-03T06:56:24Z</updated>
<author>
<name>jinbaohong</name>
</author>
<published>2026-01-28T07:06:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1cc4ada4182fadb82837831cabf1027bff0322d7'/>
<id>urn:sha1:1cc4ada4182fadb82837831cabf1027bff0322d7</id>
<content type='text'>
When multiple block groups or devices fail during trim, preserve the
first error encountered rather than the last one. The first error is
typically more useful for debugging as it represents the original
failure, while subsequent errors may be cascading effects.

Signed-off-by: Robbie Ko &lt;robbieko@synology.com&gt;
Signed-off-by: jinbaohong &lt;jinbaohong@synology.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: continue trimming remaining devices on failure</title>
<updated>2026-02-03T06:56:24Z</updated>
<author>
<name>jinbaohong</name>
</author>
<published>2026-01-28T07:06:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=912d1c6680bdb40b72b1b9204706f32b6eb842c3'/>
<id>urn:sha1:912d1c6680bdb40b72b1b9204706f32b6eb842c3</id>
<content type='text'>
Commit 93bba24d4b5a ("btrfs: Enhance btrfs_trim_fs function to handle
error better") intended to make device trimming continue even if one
device fails, tracking failures and reporting them at the end. However,
it used 'break' instead of 'continue', causing the loop to exit on the
first device failure.

Fix this by replacing 'break' with 'continue'.

Fixes: 93bba24d4b5a ("btrfs: Enhance btrfs_trim_fs function to handle error better")
CC: stable@vger.kernel.org # 5.4+
Reviewed-by: Qu Wenruo &lt;wqu@suse.com&gt;
Signed-off-by: Robbie Ko &lt;robbieko@synology.com&gt;
Signed-off-by: jinbaohong &lt;jinbaohong@synology.com&gt;
Reviewed-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: remove pointless out labels from extent-tree.c</title>
<updated>2026-02-03T06:56:21Z</updated>
<author>
<name>Filipe Manana</name>
</author>
<published>2026-01-20T19:52:10Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ea8f9210050136bdd14f5e32b04cd01c8bd5c0ca'/>
<id>urn:sha1:ea8f9210050136bdd14f5e32b04cd01c8bd5c0ca</id>
<content type='text'>
Some functions (lookup_extent_data_ref(), __btrfs_mod_ref() and
btrfs_free_tree_block()) have an 'out' label that does nothing but
return, making it pointless. Simplify this by removing the label and
returning instead of gotos plus setting the 'ret' variable.

Reviewed-by: Johannes Thumshirn &lt;johannes.thumshirn@wdc.com&gt;
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: use the btrfs_block_group_end() helper everywhere</title>
<updated>2026-02-03T06:54:36Z</updated>
<author>
<name>Filipe Manana</name>
</author>
<published>2026-01-16T10:24:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=4ac81c381102bebf09a47946b343d70ed455c646'/>
<id>urn:sha1:4ac81c381102bebf09a47946b343d70ed455c646</id>
<content type='text'>
We have a helper to calculate a block group's exclusive end offset, but
we only use it in some places. Update every site that open codes the
calculation to use the helper.

Reviewed-by: Johannes Thumshirn &lt;johannes.thumshirn@wdc.com&gt;
Signed-off-by: Filipe Manana &lt;fdmanana@suse.com&gt;
Reviewed-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: handle discarding fully-remapped block groups</title>
<updated>2026-02-03T06:54:36Z</updated>
<author>
<name>Mark Harmstone</name>
</author>
<published>2026-01-07T14:09:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7cddbb4339d4be16aa5341e3a27e63c34d2c4e0d'/>
<id>urn:sha1:7cddbb4339d4be16aa5341e3a27e63c34d2c4e0d</id>
<content type='text'>
Discard normally works by iterating over the free-space entries of a
block group. This doesn't work for fully-remapped block groups, as we
removed their free-space entries when we started relocation.

For sync discard, call btrfs_discard_extent() when we commit the
transaction in which the last identity remap was removed.

For async discard, add a new function btrfs_trim_fully_remapped_block_group()
to be called by the discard worker, which iterates over the block
group's range using the normal async discard rules. Once we reach the
end, remove the chunk's stripes and device extents to get back its free
space.

Reviewed-by: Boris Burkov &lt;boris@bur.io&gt;
Signed-off-by: Mark Harmstone &lt;mark@harmstone.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: add do_remap parameter to btrfs_discard_extent()</title>
<updated>2026-02-03T06:54:35Z</updated>
<author>
<name>Mark Harmstone</name>
</author>
<published>2026-01-07T14:09:14Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a645372e7e40be088828ad99aa9a6c68f83ef00d'/>
<id>urn:sha1:a645372e7e40be088828ad99aa9a6c68f83ef00d</id>
<content type='text'>
btrfs_discard_extent() can be called either when an extent is removed
or from walking the free-space tree. With a remapped block group these
two things are no longer equivalent: the extent's addresses are
remapped, while the free-space tree exclusively uses underlying
addresses.

Add a do_remap parameter to btrfs_discard_extent() and
btrfs_map_discard(), saying whether or not the address needs to be run
through the remap tree first.

Reviewed-by: Boris Burkov &lt;boris@bur.io&gt;
Signed-off-by: Mark Harmstone &lt;mark@harmstone.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
<entry>
<title>btrfs: move existing remaps before relocating block group</title>
<updated>2026-02-03T06:54:35Z</updated>
<author>
<name>Mark Harmstone</name>
</author>
<published>2026-01-07T14:09:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=bbea42dfb91f6901243958c83f26bbbd3a4a85fa'/>
<id>urn:sha1:bbea42dfb91f6901243958c83f26bbbd3a4a85fa</id>
<content type='text'>
If when relocating a block group we find that `remap_bytes` &gt; 0 in its
block group item, that means that it has been the destination block
group for another that has been remapped.

We need to search the remap tree for any remap backrefs within this
range, and move the data to a third block group. This is because
otherwise btrfs_translate_remap() could end up following an unbounded
chain of remaps, which would only get worse over time.

We only relocate one block group at a time, so `remap_bytes` will only
ever go down while we are doing this. Once we're finished we set the
REMAPPED flag on the block group, which will permanently prevent any
other data from being moved to within it.

Reviewed-by: Boris Burkov &lt;boris@bur.io&gt;
Signed-off-by: Mark Harmstone &lt;mark@harmstone.com&gt;
Signed-off-by: David Sterba &lt;dsterba@suse.com&gt;
</content>
</entry>
</feed>
