]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Prepare storage backing chain traversal code for FD passed images
authorPeter Krempa <pkrempa@redhat.com>
Wed, 14 Dec 2022 14:35:29 +0000 (15:35 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 9 Jan 2023 13:59:43 +0000 (14:59 +0100)
We assume that FD passed images already exist so all existance checks
are skipped.

For the case that a FD-passed image is passed without a terminated
backing chain (thus forcing us to detect) we attempt to read the header
from the FD.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/qemu/qemu_domain.c
src/storage_file/storage_source.c

index 9fd3c39646f59e27f25c6784f4e8d141025c145b..00a54e18fef4bb5e08973c901800e296febef731 100644 (file)
@@ -7611,16 +7611,20 @@ qemuDomainDetermineDiskChain(virQEMUDriver *driver,
         disksrc->format > VIR_STORAGE_FILE_NONE &&
         disksrc->format < VIR_STORAGE_FILE_BACKING) {
 
+        /* terminate the chain for such images as the code below would do */
+        if (!disksrc->backingStore)
+            disksrc->backingStore = virStorageSourceNew();
+
+        /* we assume that FD-passed disks always exist */
+        if (virStorageSourceIsFD(disksrc))
+            return 0;
+
         if (!virFileExists(disksrc->path)) {
             virStorageSourceReportBrokenChain(errno, disksrc, disksrc);
 
             return -1;
         }
 
-        /* terminate the chain for such images as the code below would do */
-        if (!disksrc->backingStore)
-            disksrc->backingStore = virStorageSourceNew();
-
         /* host cdrom requires special treatment in qemu, so we need to check
          * whether a block device is a cdrom */
         if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
@@ -7632,12 +7636,14 @@ qemuDomainDetermineDiskChain(virQEMUDriver *driver,
         return 0;
     }
 
-    src = disksrc;
     /* skip to the end of the chain if there is any */
-    while (virStorageSourceHasBacking(src)) {
-        int rv = virStorageSourceSupportsAccess(src);
+    for (src = disksrc; virStorageSourceHasBacking(src); src = src->backingStore) {
+        int rv;
+
+        if (virStorageSourceIsFD(src))
+            continue;
 
-        if (rv < 0)
+        if ((rv = virStorageSourceSupportsAccess(src)) < 0)
             return -1;
 
         if (rv > 0) {
@@ -7652,7 +7658,6 @@ qemuDomainDetermineDiskChain(virQEMUDriver *driver,
 
             virStorageSourceDeinit(src);
         }
-        src = src->backingStore;
     }
 
     /* We skipped to the end of the chain. Skip detection if there's the
index 0db6e695915323a04878d4819b78b6bd78dc9ba7..baa182261f68b22b538bcc682b71a9708db65260 100644 (file)
@@ -1304,6 +1304,21 @@ virStorageSourceGetMetadataRecurseReadHeader(virStorageSource *src,
     int ret = -1;
     ssize_t len;
 
+    if (virStorageSourceIsFD(src)) {
+        if (!src->fdtuple) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("fd passed image source not initialized"));
+            return -1;
+        }
+
+        if ((len = virFileReadHeaderFD(src->fdtuple->fds[0],
+                                       VIR_STORAGE_MAX_HEADER, buf)) < 0)
+            return -1;
+
+        *headerLen = len;
+        return 0;
+    }
+
     if (virStorageSourceInitAs(src, uid, gid) < 0)
         return -1;