1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

fix(vrtManager): a VM's new disk in an NFS or filesystem pool keeps its format

A new VM's disk and a disk added to a VM were built by a copy of the
volume XML of the Storage page that kept the format in dir pools only:
in an fs or netfs pool a qcow2 disk became a raw one allocated whole,
and a qcow disk got qcow2's compat and lazy_refcounts, which libvirt
refuses. Both now use the Storage page's builder, where every pool of
files keeps the format and the other pools make a raw volume without
metadata preallocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-08 14:34:51 +03:00
parent 8f09812b7d
commit f952d4e0d0
4 changed files with 58 additions and 43 deletions

View file

@ -1,4 +1,3 @@
import contextlib
import io
import json
import string
@ -6,6 +5,7 @@ import string
import pycdlib
from vrtManager import util
from vrtManager.connection import wvmConnect
from vrtManager.storage import wvmStorage
# libvirt's CPU modes a new VM can have; any other value is a CPU model's name (mode custom)
CPU_MODES = ("host-model", "host-passthrough", "maximum")
@ -61,41 +61,10 @@ def get_rbd_storage_data(stg):
class wvmCreate(wvmConnect):
def create_volume(self, storage, name, size, image_format, metadata=False, disk_owner_uid=0, disk_owner_gid=0):
size = int(size) * 1073741824
stg = self.get_storage(storage)
storage_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
if storage_type == "dir":
name += f".{image_format}" if image_format in ("qcow", "qcow2") else ".img"
alloc = 0
else:
image_format = 'raw'
alloc = size
metadata = False
xml = f"""
<volume>
<name>{name}</name>
<capacity>{size}</capacity>
<allocation>{alloc}</allocation>
<target>
<format type='{image_format}'/>
<permissions>
<owner>{disk_owner_uid}</owner>
<group>{disk_owner_gid}</group>
<mode>0644</mode>
<label>virt_image_t</label>
</permissions>
<compat>1.1</compat>
<features>
<lazy_refcounts/>
</features>
</target>
</volume>"""
stg.createXML(xml, metadata)
with contextlib.suppress(Exception):
stg.refresh(0)
vol = stg.storageVolLookupByName(name)
return vol.path()
"""A new volume of size GiB in the pool storage, as the Storage page makes one; its path."""
stg = wvmStorage(self.host, self.login, self.passwd, self.conn, storage)
name = stg.create_volume(name, size, image_format, metadata, disk_owner_uid, disk_owner_gid)
return stg.get_volume(name).path()
def get_volume_format_type(self, path):
vol = self.get_volume_by_path(path)