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.group storage_gid(env)
xml.label 'virt_image_t' xml.label 'virt_image_t'
end end
xml.compat '1.1'
end end
xml.backingStore do xml.backingStore do
xml.path(@backing_file) 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]), :name => HandleBoxImage.get_volume_name(env[:machine].box, 'box', image_path, env[:ui]),
:virtual_size => HandleBoxImage.get_virtual_size(env), :virtual_size => HandleBoxImage.get_virtual_size(env),
:format => box_format, :format => box_format,
:compat => "1.1",
}] }]
else else
# Handle box v2 format # Handle box v2 format
@@ -57,7 +58,7 @@ module VagrantPlugins
raise Errors::BoxFormatMissingAttribute, attribute: "disks[#{i}]['path']" if disks[i]['path'].nil? 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']) 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( volume_name = HandleBoxImage.get_volume_name(
env[:machine].box, env[:machine].box,
disks[i].fetch('name', disks[i]['path'].sub(/#{File.extname(disks[i]['path'])}$/, '')), disks[i].fetch('name', disks[i]['path'].sub(/#{File.extname(disks[i]['path'])}$/, '')),
@@ -76,7 +77,8 @@ module VagrantPlugins
:path => image_path, :path => image_path,
:name => volume_name, :name => volume_name,
:virtual_size => virtual_size, :virtual_size => virtual_size,
:format => HandleBoxImage.verify_box_format(format) :format => HandleBoxImage.verify_box_format(format),
:compat => compat,
} }
} }
end end
@@ -180,8 +182,9 @@ module VagrantPlugins
image_info = JSON.parse(stdout) image_info = JSON.parse(stdout)
format = image_info['format'] format = image_info['format']
virtual_size = ByteNumber.new(image_info['virtual-size']) 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 end
def send_box_image(env, config, box_image_file, box_volume) def send_box_image(env, config, box_image_file, box_volume)

View File

@@ -8,6 +8,7 @@
<group>0</group> <group>0</group>
<label>virt_image_t</label> <label>virt_image_t</label>
</permissions> </permissions>
<compat>1.1</compat>
</target> </target>
<backingStore> <backingStore>
<path>/test/path_0.img</path> <path>/test/path_0.img</path>

View File

@@ -8,6 +8,7 @@
<group>0</group> <group>0</group>
<label>virt_image_t</label> <label>virt_image_t</label>
</permissions> </permissions>
<compat>1.1</compat>
</target> </target>
<backingStore> <backingStore>
<path>/test/path_0.img</path> <path>/test/path_0.img</path>

View File

@@ -8,6 +8,7 @@
<group>0</group> <group>0</group>
<label>virt_image_t</label> <label>virt_image_t</label>
</permissions> </permissions>
<compat>1.1</compat>
</target> </target>
<backingStore> <backingStore>
<path>/test/path_1.img</path> <path>/test/path_1.img</path>

View File

@@ -8,6 +8,7 @@
<group>0</group> <group>0</group>
<label>virt_image_t</label> <label>virt_image_t</label>
</permissions> </permissions>
<compat>1.1</compat>
</target> </target>
<backingStore> <backingStore>
<path>/test/path_2.img</path> <path>/test/path_2.img</path>

View File

@@ -88,6 +88,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
:virtual_size=>byte_number_5G, :virtual_size=>byte_number_5G,
:format=>"qcow2", :format=>"qcow2",
:device=>'vda', :device=>'vda',
:compat=>"1.1",
} }
] ]
) )
@@ -118,6 +119,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
:virtual_size=>byte_number_5G, :virtual_size=>byte_number_5G,
:format=>"qcow2", :format=>"qcow2",
:device=>'vda', :device=>'vda',
:compat=>"1.1",
} }
] ]
) )
@@ -156,6 +158,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
:virtual_size=>byte_number_5G, :virtual_size=>byte_number_5G,
:format=>"qcow2", :format=>"qcow2",
:device=>'vda', :device=>'vda',
:compat=>"1.1",
} }
] ]
) )
@@ -177,6 +180,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
:virtual_size=>byte_number_20G, :virtual_size=>byte_number_20G,
:format=>"qcow2", :format=>"qcow2",
:device=>'vda', :device=>'vda',
:compat=>"1.1",
} }
] ]
) )
@@ -269,18 +273,21 @@ describe VagrantPlugins::ProviderLibvirt::Action::HandleBoxImage do
:virtual_size=>byte_number_5G, :virtual_size=>byte_number_5G,
:format=>"qcow2", :format=>"qcow2",
:device=>'vda', :device=>'vda',
:compat=>"0.10"
}, },
{ {
:path=>"/test/disk.qcow2", :path=>"/test/disk.qcow2",
:name=>"test_vagrant_box_image_1.1.1_disk.img", :name=>"test_vagrant_box_image_1.1.1_disk.img",
:virtual_size=>byte_number_10G, :virtual_size=>byte_number_10G,
:format=>"qcow2" :format=>"qcow2",
:compat=>"0.10"
}, },
{ {
:path=>"/test/box_2.img", :path=>"/test/box_2.img",
:name=>"test_vagrant_box_image_1.1.1_box_2.img", :name=>"test_vagrant_box_image_1.1.1_box_2.img",
:virtual_size=>byte_number_20G, :virtual_size=>byte_number_20G,
:format=>"qcow2" :format=>"qcow2",
:compat=>"0.10"
} }
] ]
) )