qemu: block: Make 'slice' layer effective for 'raw' storage source

Rather than pulling the configuration of the storage slice into the
'format' layer make the 'slice' layer effective for raw disks with a
storage slice. This was made possible by the recent refactors which made
the 'format' layer optional if not needed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa
2023-12-14 16:11:07 +01:00
parent d09f46a9fb
commit a2cc772031
2 changed files with 13 additions and 35 deletions
+9 -31
View File
@@ -1203,27 +1203,6 @@ qemuBlockStorageSourceGetFormatLUKSProps(virStorageSource *src,
} }
static int
qemuBlockStorageSourceGetFormatRawProps(virStorageSource *src,
virJSONValue *props)
{
if (virJSONValueObjectAdd(&props, "s:driver", "raw", NULL) < 0)
return -1;
/* Currently only storage slices are supported. We'll have to calculate
* the union of the slices here if we don't want to be adding needless
* 'raw' nodes. */
if (src->sliceStorage &&
virJSONValueObjectAdd(&props,
"U:offset", src->sliceStorage->offset,
"U:size", src->sliceStorage->size,
NULL) < 0)
return -1;
return 0;
}
static int static int
qemuBlockStorageSourceGetCryptoProps(virStorageSource *src, qemuBlockStorageSourceGetCryptoProps(virStorageSource *src,
virJSONValue **encprops) virJSONValue **encprops)
@@ -1336,8 +1315,7 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSource *src)
case VIR_STORAGE_FILE_FAT: case VIR_STORAGE_FILE_FAT:
/* The fat layer is emulated by the storage access layer, so we need to /* The fat layer is emulated by the storage access layer, so we need to
* put a raw layer on top */ * put a raw layer on top */
if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0) driver = "raw";
return NULL;
break; break;
case VIR_STORAGE_FILE_RAW: case VIR_STORAGE_FILE_RAW:
@@ -1345,8 +1323,7 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSource *src)
if (qemuBlockStorageSourceGetFormatLUKSProps(src, props) < 0) if (qemuBlockStorageSourceGetFormatLUKSProps(src, props) < 0)
return NULL; return NULL;
} else { } else {
if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0) driver = "raw";
return NULL;
} }
break; break;
@@ -3295,10 +3272,7 @@ qemuBlockStorageSourceIsRaw(const virStorageSource *src)
bool bool
qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src) qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src)
{ {
if (!src->sliceStorage) return !!src->sliceStorage;
return false;
return !qemuBlockStorageSourceIsRaw(src);
} }
@@ -3314,9 +3288,13 @@ qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src)
* existence of the format layer nodename. * existence of the format layer nodename.
*/ */
bool bool
qemuBlockStorageSourceNeedsFormatLayer(const virStorageSource *src G_GNUC_UNUSED) qemuBlockStorageSourceNeedsFormatLayer(const virStorageSource *src)
{ {
/* Currently we always create a 'format' layer */ /* Skip 'format' layer, when a storage slice for a raw image is in use */
if (qemuBlockStorageSourceIsRaw(src) &&
src->sliceStorage)
return false;
return true; return true;
} }
@@ -28,8 +28,8 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-boot strict=on \ -boot strict=on \
-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ -device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \
-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/raw.img","node-name":"libvirt-6-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/raw.img","node-name":"libvirt-6-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-6-format","read-only":false,"driver":"raw","offset":0,"size":321,"file":"libvirt-6-storage"}' \ -blockdev '{"driver":"raw","offset":0,"size":321,"file":"libvirt-6-storage","node-name":"libvirt-6-slice-sto","read-only":false}' \
-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"libvirt-6-format","id":"virtio-disk0","bootindex":1}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x2","drive":"libvirt-6-slice-sto","id":"virtio-disk0","bootindex":1}' \
-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/raw.img","node-name":"libvirt-5-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/raw.img","node-name":"libvirt-5-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"driver":"raw","offset":9876,"size":123456789,"file":"libvirt-5-storage","node-name":"libvirt-5-slice-sto","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"driver":"raw","offset":9876,"size":123456789,"file":"libvirt-5-storage","node-name":"libvirt-5-slice-sto","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-5-format","read-only":true,"driver":"qcow2","file":"libvirt-5-slice-sto","backing":null}' \ -blockdev '{"node-name":"libvirt-5-format","read-only":true,"driver":"qcow2","file":"libvirt-5-slice-sto","backing":null}' \
@@ -42,8 +42,8 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"luks","key-secret":"libvirt-3-format-encryption-secret0","file":"libvirt-3-slice-sto"}' \ -blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"luks","key-secret":"libvirt-3-format-encryption-secret0","file":"libvirt-3-slice-sto"}' \
-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"libvirt-3-format","id":"virtio-disk2"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x4","drive":"libvirt-3-format","id":"virtio-disk2"}' \
-blockdev '{"driver":"nvme","device":"0000:02:00.0","namespace":1,"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ -blockdev '{"driver":"nvme","device":"0000:02:00.0","namespace":1,"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw","offset":1234,"size":321,"file":"libvirt-2-storage"}' \ -blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-2-storage","node-name":"libvirt-2-slice-sto","read-only":false}' \
-device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x6","drive":"libvirt-2-format","id":"virtio-disk3"}' \ -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x6","drive":"libvirt-2-slice-sto","id":"virtio-disk3"}' \
-object '{"qom-type":"secret","id":"libvirt-1-format-encryption-secret0","data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw==","format":"base64"}' \ -object '{"qom-type":"secret","id":"libvirt-1-format-encryption-secret0","data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw==","format":"base64"}' \
-blockdev '{"driver":"nvme","device":"0001:02:00.0","namespace":2,"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap","cache":{"direct":true,"no-flush":false}}' \ -blockdev '{"driver":"nvme","device":"0001:02:00.0","namespace":2,"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap","cache":{"direct":true,"no-flush":false}}' \
-blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-1-storage","node-name":"libvirt-1-slice-sto","auto-read-only":true,"discard":"unmap","cache":{"direct":true,"no-flush":false}}' \ -blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-1-storage","node-name":"libvirt-1-slice-sto","auto-read-only":true,"discard":"unmap","cache":{"direct":true,"no-flush":false}}' \