On Fri, Jul 04, 2025 at 07:08:03PM +0930, Qu Wenruo wrote: > [WEIRD FLAG EXCLUSION] > Commit ead622674df5 ("btrfs: Do not restrict writes to btrfs devices") > removes the BLK_OPEN_RESTRICT_WRITES flag when opening the devices > during mount. > > However there is no filesystem except btrfs excluding this flag, which > is weird, and lacks a proper explanation why we need such an exception. It's somewhere in the discussions for the patch and there was a dependency on the series reworking the device opening to be read-only which I did not consider safe for inclusion. You've worked on that recently and fixed a few problems and it made it all possible. The code this patch is removing was added by Linus during merge and was not obvious that was needed. > [REASON TO EXCLUDE THAT FLAG] > Btrfs needs to call btrfs_scan_one_device() to determine the fsid, no > matter if we're mounting a new fs or an existing one. > > But if a fs is already mounted and that BLK_OPEN_RESTRICT_WRITES is > honored, meaning no other write open is allowed for the block device. > > Then we want to mount a subvolume of the mounted fs to another mount > point, we will call btrfs_scan_one_device() again, but it will fail due > to the BLK_OPEN_RESTRICT_WRITES flag (no more write open allowed), > causing only one mount point for the fs. > > Thus at that time, we have to exclude the BLK_OPEN_RESTRICT_WRITES to > allow multiple mount points for one fs. > > [WHY IT'S SAFE NOW] > The root problem is, we do not need to nor should use BLK_OPEN_WRITE for > btrfs_scan_one_device(). > That function is only to read out the super block, no write at all, and > BLK_OPEN_WRITE is only going to cause problems for such usage. > > The root problem is fixed by patch "btrfs: always open the device > read-only in btrfs_scan_one_device", so btrfs_scan_one_device() will > always work no matter if the device is opened with > BLK_OPEN_RESTRICT_WRITES. > > [ENHANCEMENT] > Just remove the btrfs_open_mode(), as the only call site can be replaced > with regular sb_open_mode(). > > Signed-off-by: Qu Wenruo <wqu@xxxxxxxx> > --- > Changelog: > v2: > - Add more details about the original problem > And the fix that unintentionally solved the original problem. Please add it to for-next, thanks.