Re: [PATCH v2 0/2] btrfs: delay mounted sysfs attributes until mount is ready

From: Qu Wenruo

Date: Sat Aug 22 2026 - 00:57:55 EST




在 2026/8/22 13:11, Jiacheng Xu 写道:
Here is a potential fix following Wenruo's idea.

btrfs_sysfs_add_mounted() currently publishes the writable label and
feature attributes before the transaction kthread is created. A concurrent
sysfs write can therefore dereference a NULL transaction_kthread in
wake_up_process().

This series follows the suggested lifecycle: create only the required
subdirectories during early mount, publish the fsid attributes after mount
initialization, and remove them before the kthreads are stopped. The
feature attributes are included because their store callback has the same
transaction_kthread dependency as the label callback.

Patch 1 factors the fsid attribute handling into dedicated helpers. Patch 2
moves their publication and removal to the safe mount and unmount stages.
On unmount the cleaner is parked before attribute removal so it cannot
recreate the feature group through sysfs_update_group(). Both patches are
required for stable backports.

The resulting fs/btrfs/sysfs.o and fs/btrfs/disk-io.o were build-tested.

Changes in v2:
- Delay creation of both the root and feature attributes until mount setup
is complete.

You don't need to bother feature attributes for now, there is already a patch addressing it by completely removing the write support for feature attributes:

https://lore.kernel.org/linux-btrfs/8a598d76555b5944d34bb08fa8dbeea28fc05db9.1787307129.git.wqu@xxxxxxxx/

Considering it's only extended_iref, removing it should be much simpler.
Until that is determined, you only need to bother the label one.


Furthermore, among all the attr files in the fsid directory, there is only label that is writable, it would make more sense to split btrfs_attrs into two parts, one for those read-only members, and one for the only writebale label one.

Otherwise the series looks much better.


- Remove those attributes while their kthread dependencies are still
valid.
- Split helper extraction from the lifecycle fix for stable backports.

Jiacheng Xu (2):
btrfs: sysfs: factor out mounted fsid attribute helpers
btrfs: delay mounted fsid attributes until the fs is ready

fs/btrfs/disk-io.c | 18 ++++++++++++++++-
fs/btrfs/sysfs.c | 50 ++++++++++++++++++++++++++++++----------------
fs/btrfs/sysfs.h | 2 ++
3 files changed, 52 insertions(+), 18 deletions(-)

base-commit: 0f23d56f17fdfc7db69d51f64c8b91bbab947aa9