I deleted all containers and all images from the BTRFS server, when I run this command this what I am left with, not sure if this is relevant. Maybe problem is I am trying to set a quota less than what is being used in total, which its not handling well.
$ sudo btrfs fi show
Label: none uuid: 916f6d6a-c243-477c-b43b-20d12eb15518
Total devices 1 FS bytes used 656.00KiB
devid 1 size 53.50GiB used 2.01GiB path /dev/sda3
$ sudo btrfs balance start /btrfs
WARNING:
Full balance without filters requested. This operation is very
intense and takes potentially very long. It is recommended to
use the balance filters to narrow down the scope of balance.
Use 'btrfs balance start --full-balance' option to skip this
warning. The operation will start in 10 seconds.
Use Ctrl-C to stop it.
10 9 8 7 6 5 4 3 2 1
Starting balance without any filters.
$ sudo btrfs fi show
Label: none uuid: 916f6d6a-c243-477c-b43b-20d12eb15518
Total devices 1 FS bytes used 656.00KiB
devid 1 size 53.50GiB used 2.03GiB path /dev/sda3
Sorry yesterday it was a long day, I went in with a fresh approach today, and it appears the problem is that LXD is reporting the process as complete, but BTRFS is still doing things behind the scenes, going back to the container and starting it some time afterwards, it starts up without errors.
The same problem occurs when restoring from a backup, trying to start the container immediately after this causes errors, until BTRFS finishes what it is doing.
So just to confirm, create a container, and then patch it to set the quota, and then trying to start through the API causes these problems, you might not get this from the command line unless you paste in the commands, as it there a period of 20 seconds or so that BTRFS needs. If not BTRFS reports the quota as exceeding. Also tested with Alpine container and 1GB limit, no problem, But Ubuntu this fails.
It needs approx 20 seconds after being reported as complete before it can be booted without any errors. I don’t remember this problem existing when using BTRFS loopback device, I am only experiencing this now that I am using custom BTRFS partition of 50GB.