Re: [PATCH] btrfs: lock balance status ioctls against shutdown

From: David Sterba

Date: Tue May 12 2026 - 10:30:23 EST


On Tue, May 12, 2026 at 02:53:41PM +0800, ZhengYuan Huang wrote:
> BTRFS_IOC_BALANCE_PROGRESS and BTRFS_IOC_BALANCE_CTL only take fs_info
> and then touch fs_info->balance_mutex and balance state directly. They
> do not pin the superblock against shutdown and they do not reject a
> dying superblock before taking balance_mutex.

So the reproducer is a number of processes querying the balance status
and there's a filesystem unmount running in parallel, right?

This can be considered as a general pattern and maybe more ioctls need
the 'want write' protection. We do have it for all the write actions,
but as can be seen here it's for the read-only ones too.