canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.39k stars 929 forks source link

"unable to create quota group: File exists" when creating new container #11210

Closed broizter closed 1 year ago

broizter commented 1 year ago

Required information

Issue description

Trying to create new containers fails with this message Error: Failed instance creation: Failed creating instance from image: Failed to run: btrfs qgroup create 0/104960 /var/lib/lxd/storage-pools/default/images/f161c60ebcfe5806986bcfef748df7cf23bf7eb39eb5b7c130d0e5aa5371522f: exit status 1 (ERROR: unable to create quota group: File exists). My guess is that it started after upgrading btrfs-progs to 6.0.1. Upgrading to the latest version (6.0.2) did not fix the issue.

Steps to reproduce

  1. Use BTRFS as the storage backend
  2. Create a container

Information to attach

casperx commented 1 year ago

Sadly, disabling quota only fixes the issue if you didn't set the disk size for the container. If you set size of the disk device (for example, lxc launch -d root,size=512MiB images:debian/bookworm where root is disk device), LXD is going to enable btrfs quota on that storage pool and the issue occurs again.

tomponline commented 1 year ago

What were the reproducer steps in lxd to get to that state? That is what I'm after.

broizter commented 1 year ago

I managed to reproduce the issue on a fresh Arch install.

  1. Use BTRFS as the filesystem on root
  2. lxd init with all defaults (make sure btrfs is used as the storage backend)
  3. Edit the "default" profile and add "size: 5GB" to the "root" device (I guess this activates qgroups)
  4. Launch a container and you will get the error

As soon as you revert step 3 and also run btrfs quota disable /var/lib/lxd/storage-pools/default things will go back to working as normal again.

casperx commented 1 year ago

just install lxd on latest Arch system with all default lxd init except using btrfs as a storage for default storage pool and lxc launch -d root,size=512MiB images:debian/bookworm

broizter commented 1 year ago

just install lxd on latest Arch system with all default lxd init except using btrfs as a storage for default pool and lxc launch -d root,size=512MiB images:debian/bookworm

btrfs is the default for me during lxd init but I'll update my instructions just in case.

casperx commented 1 year ago

look like btrfs-progs after version 6.0, btrfs qgroup show added path column to be display by default, thus increasing fields from 4 to 5. because https://github.com/lxc/lxd/blob/master/lxd/storage/drivers/driver_btrfs_utils.go#L256 skip line that has more or less than 4 field, it won't find any Qgroupid.

tomponline commented 1 year ago

Ah good spot. Let me try and reproduce.

tomponline commented 1 year ago

Thanks I've reproduced this on Ubuntu Lunar Lobster now:

lxc storage create btrfs btrfs
Storage pool btrfs created

lxc launch images:alpine/3.17 c1 -s btrfs
Creating c1
Starting c1                                   

lxc config device set c1 root size=1GiB
Error: Failed to update device "root": Failed to run: btrfs qgroup create 0/257 /var/lib/lxd/storage-pools/btrfs/containers/c1: exit status 1 (ERROR: unable to create quota group: File exists)