specify qcow2 compatibility version to not use very old 0.10 fallback (#1731)

Libvirt creates qcow2 volumes with very old `compat` version `0.10` if
no `compat` version is specified in the xml (see
[here](https://libvirt.org/formatstorage.html#id11)). It seems libvirt
has backwards compatibility reasons to still use `0.10` if nothing is
specified in the xml.

Unfortunately this has the effect that VMs created by vagrant-libvirt
are using the 10 year old `0.10` qcow2 version, instead of the `1.1`
version that has **better performance and stability fixes**.
This is even happening when the backing file of the vagrant box is in
compat `1.1` format.

This is the `qemu-img info` of the backing file provided by the vagrant
box:
```
# qemu-img info /var/lib/libvirt/images/vagrant_box_image_0_box.img
[...]
Format specific information:
    compat: 1.1
    [...]
```
Although the backing file provided by the box is using compat `1.1`, the
created volume by vagrant-libvirt has only compat `0.1` as shown here:
```
# qemu-img info /var/lib/libvirt/images/vagrant-01-test_default.img
[...]
backing file: /var/lib/libvirt/images/vagrant_box_image_0_box.img
Format specific information:
    compat: 0.10
    [...]
```

With this MR, the volume of the VM will use the same `compat` version as
provided by the backing image of the vagrant box.
If `qemu-img info` does not return a `compat` flag, it falls back to the
very old `0.10` version.
This commit is contained in:
Holger Finger
2023-04-22 15:03:21 +02:00
committed by GitHub
parent f6126464f1
commit cb051a8277
7 changed files with 20 additions and 5 deletions

View File

@@ -60,6 +60,7 @@ module VagrantPlugins
xml.group storage_gid(env)
xml.label 'virt_image_t'
end
xml.compat '1.1'
end
xml.backingStore do
xml.path(@backing_file)

View File

@@ -43,6 +43,7 @@ module VagrantPlugins
:name => HandleBoxImage.get_volume_name(env[:machine].box, 'box', image_path, env[:ui]),
:virtual_size => HandleBoxImage.get_virtual_size(env),
:format => box_format,
:compat => "1.1",
}]
else
# Handle box v2 format
@@ -57,7 +58,7 @@ module VagrantPlugins
raise Errors::BoxFormatMissingAttribute, attribute: "disks[#{i}]['path']" if disks[i]['path'].nil?
image_path = HandleBoxImage.get_box_image_path(env[:machine].box, disks[i]['path'])
format, virtual_size = HandleBoxImage.get_box_disk_settings(image_path)
format, virtual_size, compat = HandleBoxImage.get_box_disk_settings(image_path)
volume_name = HandleBoxImage.get_volume_name(
env[:machine].box,
disks[i].fetch('name', disks[i]['path'].sub(/#{File.extname(disks[i]['path'])}$/, '')),
@@ -76,7 +77,8 @@ module VagrantPlugins
:path => image_path,
:name => volume_name,
:virtual_size => virtual_size,
:format => HandleBoxImage.verify_box_format(format)
:format => HandleBoxImage.verify_box_format(format),
:compat => compat,
}
}
end
@@ -180,8 +182,9 @@ module VagrantPlugins
image_info = JSON.parse(stdout)
format = image_info['format']
virtual_size = ByteNumber.new(image_info['virtual-size'])
compat = image_info.fetch("format-specific", {}).fetch("data", {}).fetch("compat", "0.10")
return format, virtual_size
return format, virtual_size, compat
end
def send_box_image(env, config, box_image_file, box_volume)