Workaround for 'read-only file system' error when deleting a storage pool of LXD

hi there,

This is my workaround for ‘read-only file system’ error when deleting a storage pool of LXD. I hope this is useful for you.

$ lxc storage delete default
Error: Failed removing mount path "/var/snap/lxd/common/lxd/storage-pools/default": Failed removing "/var/snap/lxd/common/lxd/storage-pools/default/containers": unlinkat /var/snap/lxd/common/lxd/storage-pools/default/containers/backup.2264386518/.backup/metadata.yaml: read-only file system

‘default’ pool is a dedicated partition (/dev/vde1) by btrfs driver.

I have never taken snapshots of instances or custom volumes.
However, I’ve seen errors when running “lxd export” or “lxc storage volume export”.
I gues that “read-only filesystem” is a orphaned snapshot left by the failed export

$ mkdir /mnt/vde1
$ mount /dev/vde1 /mnt/vde1
$ cd /mnt/vde1
$ btrfs subvol list .
ID 537 gen 993954 top level 5 path containers/backup.2264386518/.backup
ID 538 gen 993962 top level 5 path containers/backup.3880797388/.backup
ID 724 gen 1303155 top level 5 path custom/backup.2332913389/.backup
ID 725 gen 1303160 top level 5 path custom/backup.2127012284/.backup
$ btrfs subvol show containers/backup.2264386518/.backup
containers/backup.2264386518/.backup
	Name: 			.backup
	UUID: 			7ea874e0-98e9-ad47-924d-48c051d5004e
	Parent UUID: 		610ffd12-77a0-c349-b7ba-e93dcfa88c0f
	Received UUID: 		-
	Creation time: 		2023-03-25 20:39:17 +0000
	Subvolume ID: 		537
	Generation: 		993954
	Gen at creation: 	993954
	Parent ID: 		5
	Top level ID: 		5
	Flags: 			readonly
	Snapshot(s):
$ btrfs property set containers/backup.2264386518/.backup ro false
$ btrfs subvol show containers/backup.2264386518/.backup
	Name: 			.backup
	UUID: 			7ea874e0-98e9-ad47-924d-48c051d5004e
	Parent UUID: 		610ffd12-77a0-c349-b7ba-e93dcfa88c0f
	Received UUID: 		-
	Creation time: 		2023-03-25 20:39:17 +0000
	Subvolume ID: 		537
	Generation: 		993954
	Gen at creation: 	993954
	Parent ID: 		5
	Top level ID: 		5
	Flags: 			-
	Snapshot(s):
$ btrfs property set containers/backup.3880797388/.backup ro false
$ btrfs property set tustom/backup.2332913389/.backup ro false
$ btrfs property set custom/backup.2127012284/.backup ro false
$ lxc storage delete default
Storage pool default deleted

If you can get a reproducer with LXD 5.15 (some volume clean up went in recently), that’d be nice to have it reported here: https://github.com/lxc/lxd/issues
Thanks!