On Fri, Sep 14, 2018 at 03:49:44PM +0800, Qu Wenruo wrote: > In github issues, one user reports unexpected ENOSPC error if enabling > datasum. > After some investigation, it looks like that during ext2_saved/image > creation, we could create large file extent whose size can be 128M (max > data extent size). > > In that case, its csum will be at least 128K. Under certain case we need > to allocate extra metadata chunks to fulfill such space requirement. > > However we only do metadata prealloc if we're reserving extents for fs > trees. > (we use btrfs_root::ref_cows to determine whether we should do metadata > prealloc, and that member is only set for fs trees). > > There is no explaination on why we only do metadata prealloc for file > trees, but at least from my investigation, it could be related to avoid > nested extent tree modication. > > At least extent reservation for csum tree shouldn't be a problem with > metadata block group preallocation. > > So change the metadata block group preallocation check from > "root->ref_cow" to "root->root_key.objectid != > BTRFS_EXTENT_TREE_OBJECTID", and add some comment for it.
This looks a bit fragile to me but I don't have a better suggestion for a fix. Added to devel, thanks.