[PATCH 08/10] qemu: block: Format storage slice properties optionally

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Prepare the blockdev props formatter to skip formatting the slice props
in case they are not applicable.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_block.c                         | 19 ++++++++++++++-----
 .../disk-slices.x86_64-latest.args            | 10 +++++-----
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index fd914d2e70..8e2da95139 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1434,22 +1434,31 @@ qemuBlockStorageSourceGetFormatProps(virStorageSource *src,
  * qemuBlockStorageSourceGetBlockdevStorageSliceProps:
  * @src: storage source object
  * @effective: Whether this blockdev will be the 'effective' layer of @src
+ * @resize: If true, the 'size' and 'offset' parameters are not formatted
  *
  * Formats the JSON object representing -blockdev configuration required to
  * configure a 'slice' of @src. If @effective is true, the slice layer is the
- * topmost/effective blockdev layer of @src.
+ * topmost/effective blockdev layer of @src. If @resize is true the 'size' and
+ * 'offset' are not formatted, which is used to remove a slice restriction
+ * to resize the image.
  */
 static virJSONValue *
 qemuBlockStorageSourceGetBlockdevStorageSliceProps(virStorageSource *src,
-                                                   bool effective)
+                                                   bool effective,
+                                                   bool resize)
 {
     g_autoptr(virJSONValue) props = NULL;

     if (virJSONValueObjectAdd(&props,
                               "s:driver", "raw",
+                              "s:file", qemuBlockStorageSourceGetStorageNodename(src),
+                              NULL) < 0)
+        return NULL;
+
+    if (!resize &&
+        virJSONValueObjectAdd(&props,
                               "U:offset", src->sliceStorage->offset,
                               "U:size", src->sliceStorage->size,
-                              "s:file", qemuBlockStorageSourceGetStorageNodename(src),
                               NULL) < 0)
         return NULL;

@@ -1530,7 +1539,7 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSource *src,
     }

     if ((data->storageSliceNodeName = qemuBlockStorageSourceGetSliceNodename(src))) {
-        if (!(data->storageSliceProps = qemuBlockStorageSourceGetBlockdevStorageSliceProps(src, effective)))
+        if (!(data->storageSliceProps = qemuBlockStorageSourceGetBlockdevStorageSliceProps(src, effective, false)))
             return NULL;

         effective = false;
@@ -3150,7 +3159,7 @@ qemuBlockReopenAccess(virDomainObj *vm,
         if (!(srcprops = qemuBlockStorageSourceGetFormatProps(src, src->backingStore)))
             return -1;
     } else if (qemuBlockStorageSourceGetSliceNodename(src)) {
-        if (!(srcprops = qemuBlockStorageSourceGetBlockdevStorageSliceProps(src, true)))
+        if (!(srcprops = qemuBlockStorageSourceGetBlockdevStorageSliceProps(src, true, false)))
             return -1;
     } else {
         if (!(srcprops = qemuBlockStorageSourceGetBackendProps(src,
diff --git a/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args b/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args
index c28eeb827e..658391c477 100644
--- a/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args
@@ -28,25 +28,25 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
 -boot strict=on \
 -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":"raw","offset":0,"size":321,"file":"libvirt-6-storage","node-name":"libvirt-6-slice-sto","read-only":false}' \
+-blockdev '{"driver":"raw","file":"libvirt-6-storage","offset":0,"size":321,"node-name":"libvirt-6-slice-sto","read-only":false}' \
 -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":"raw","offset":9876,"size":123456789,"file":"libvirt-5-storage","node-name":"libvirt-5-slice-sto","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"driver":"raw","file":"libvirt-5-storage","offset":9876,"size":123456789,"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 '{"driver":"file","filename":"/var/lib/libvirt/images/overlay.qcow2","node-name":"libvirt-4-storage","auto-read-only":true,"discard":"unmap"}' \
 -blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"qcow2","file":"libvirt-4-storage","backing":"libvirt-5-format"}' \
 -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x3","drive":"libvirt-4-format","id":"virtio-disk1"}' \
 -object '{"qom-type":"secret","id":"libvirt-3-format-encryption-secret0","data":"9eao5F8qtkGt+seB1HYivWIxbtwUu6MQtg1zpj/oDtUsPr1q8wBYM91uEHCn6j/1","keyid":"masterKey0","iv":"AAECAwQFBgcICQoLDA0ODw==","format":"base64"}' \
 -blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/luks.img","node-name":"libvirt-3-storage","auto-read-only":true,"discard":"unmap"}' \
--blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-3-storage","node-name":"libvirt-3-slice-sto","auto-read-only":true,"discard":"unmap"}' \
+-blockdev '{"driver":"raw","file":"libvirt-3-storage","offset":1234,"size":321,"node-name":"libvirt-3-slice-sto","auto-read-only":true,"discard":"unmap"}' \
 -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"}' \
 -blockdev '{"driver":"nvme","device":"0000:02:00.0","namespace":1,"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \
--blockdev '{"driver":"raw","offset":1234,"size":321,"file":"libvirt-2-storage","node-name":"libvirt-2-slice-sto","read-only":false}' \
+-blockdev '{"driver":"raw","file":"libvirt-2-storage","offset":1234,"size":321,"node-name":"libvirt-2-slice-sto","read-only":false}' \
 -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"}' \
 -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","file":"libvirt-1-storage","offset":1234,"size":321,"node-name":"libvirt-1-slice-sto","auto-read-only":true,"discard":"unmap","cache":{"direct":true,"no-flush":false}}' \
 -blockdev '{"node-name":"libvirt-1-format","read-only":false,"cache":{"direct":true,"no-flush":false},"driver":"qcow2","encrypt":{"format":"luks","key-secret":"libvirt-1-format-encryption-secret0"},"file":"libvirt-1-slice-sto"}' \
 -device '{"driver":"virtio-blk-pci","bus":"pci.0","addr":"0x7","drive":"libvirt-1-format","id":"virtio-disk4","write-cache":"on"}' \
 -audiodev '{"id":"audio1","driver":"none"}' \
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux