Introduce qemuBlockStorageSourceNeedsStorageSliceLayer which will hold the decision logic and fix all places that open-code it. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_block.c | 24 +++++++++++++++++++++--- src/qemu/qemu_block.h | 3 +++ src/qemu/qemu_domain.c | 3 +-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 4ed17b6df3..b5b34ab441 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1446,8 +1446,7 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src, g_autoptr(virJSONValue) props = NULL; const char *storagenode = src->nodestorage; - if (src->sliceStorage && - src->format != VIR_STORAGE_FILE_RAW) + if (qemuBlockStorageSourceNeedsStorageSliceLayer(src)) storagenode = src->sliceStorage->nodename; if (!(props = qemuBlockStorageSourceGetBlockdevFormatProps(src))) @@ -1568,7 +1567,7 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src, data->storageNodeName = src->nodestorage; data->formatNodeName = src->nodeformat; - if (src->sliceStorage && src->format != VIR_STORAGE_FILE_RAW) { + if (qemuBlockStorageSourceNeedsStorageSliceLayer(src)) { if (!(data->storageSliceProps = qemuBlockStorageSourceGetBlockdevStorageSliceProps(src))) return NULL; @@ -3308,3 +3307,22 @@ qemuBlockReopenReadOnly(virDomainObjPtr vm, return 0; } + +/** + * qemuBlockStorageSourceNeedSliceLayer: + * @src: source to inspect + * + * Returns true if @src requires an extra 'raw' layer for handling of the storage + * slice. + */ +bool +qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src) +{ + if (!src->sliceStorage) + return false; + + if (src->format != VIR_STORAGE_FILE_RAW) + return true; + + return false; +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 75b25bfea5..28475b25c1 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -254,3 +254,6 @@ int qemuBlockReopenReadOnly(virDomainObjPtr vm, virStorageSourcePtr src, qemuDomainAsyncJob asyncJob); + +bool +qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0e2252f6cf..7dda986e3a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -16590,8 +16590,7 @@ qemuDomainPrepareStorageSourceBlockdev(virDomainDiskDefPtr disk, src->nodestorage = g_strdup_printf("libvirt-%u-storage", src->id); src->nodeformat = g_strdup_printf("libvirt-%u-format", src->id); - if (src->sliceStorage && - src->format != VIR_STORAGE_FILE_RAW) + if (qemuBlockStorageSourceNeedsStorageSliceLayer(src)) src->sliceStorage->nodename = g_strdup_printf("libvirt-%u-slice-sto", src->id); if (qemuDomainValidateStorageSource(src, priv->qemuCaps) < 0) -- 2.24.1