render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
fbe740
From b4840a983e10b8cca99fa50ed3cf99af370a19c9 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <b4840a983e10b8cca99fa50ed3cf99af370a19c9@dist-git>
fbe740
From: Jonathon Jongsma <jjongsma@redhat.com>
fbe740
Date: Thu, 20 Feb 2020 10:52:25 -0600
fbe740
Subject: [PATCH] qemu: Don't store disk alias in qemuAgentDiskInfo
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
The qemuAgentDiskInfo structure is filled with information received from
fbe740
the agent command response, except for the 'alias' field, which is
fbe740
retrieved from the vm definition. Limit this structure only to data that
fbe740
was received from the agent message.
fbe740
fbe740
This is another intermediate step in moving the responsibility for
fbe740
searching the vmdef from qemu_agent.c to qemu_driver.c so that we can
fbe740
avoid holding an agent job and a normal job at the same time.
fbe740
fbe740
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
fbe740
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
(cherry picked from commit 306b4cb070b8f57a22a261d1f097283f4ef84e65)
fbe740
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1759566
fbe740
Message-Id: <20200220165227.11491-4-jjongsma@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/qemu/qemu_agent.c | 64 ++++++++++++++++++++++++-------------------
fbe740
 1 file changed, 36 insertions(+), 28 deletions(-)
fbe740
fbe740
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
fbe740
index 077b5538de..4739faeed8 100644
fbe740
--- a/src/qemu/qemu_agent.c
fbe740
+++ b/src/qemu/qemu_agent.c
fbe740
@@ -1847,7 +1847,6 @@ qemuAgentSetTime(qemuAgentPtr mon,
fbe740
 typedef struct _qemuAgentDiskInfo qemuAgentDiskInfo;
fbe740
 typedef qemuAgentDiskInfo *qemuAgentDiskInfoPtr;
fbe740
 struct _qemuAgentDiskInfo {
fbe740
-    char *alias;
fbe740
     char *serial;
fbe740
     virPCIDeviceAddress pci_controller;
fbe740
     char *bus_type;
fbe740
@@ -1876,7 +1875,6 @@ qemuAgentDiskInfoFree(qemuAgentDiskInfoPtr info)
fbe740
         return;
fbe740
 
fbe740
     VIR_FREE(info->serial);
fbe740
-    VIR_FREE(info->alias);
fbe740
     VIR_FREE(info->bus_type);
fbe740
     VIR_FREE(info->devnode);
fbe740
     VIR_FREE(info);
fbe740
@@ -1902,7 +1900,8 @@ qemuAgentFSInfoFree(qemuAgentFSInfoPtr info)
fbe740
 }
fbe740
 
fbe740
 static virDomainFSInfoPtr
fbe740
-qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent)
fbe740
+qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent,
fbe740
+                        virDomainDefPtr vmdef)
fbe740
 {
fbe740
     virDomainFSInfoPtr ret = NULL;
fbe740
     size_t i;
fbe740
@@ -1920,8 +1919,19 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent)
fbe740
 
fbe740
     ret->ndevAlias = agent->ndisks;
fbe740
 
fbe740
-    for (i = 0; i < ret->ndevAlias; i++)
fbe740
-        ret->devAlias[i] = g_strdup(agent->disks[i]->alias);
fbe740
+    for (i = 0; i < ret->ndevAlias; i++) {
fbe740
+        qemuAgentDiskInfoPtr agentdisk = agent->disks[i];
fbe740
+        virDomainDiskDefPtr diskDef;
fbe740
+
fbe740
+        if (!(diskDef = virDomainDiskByAddress(vmdef,
fbe740
+                                               &agentdisk->pci_controller,
fbe740
+                                               agentdisk->bus,
fbe740
+                                               agentdisk->target,
fbe740
+                                               agentdisk->unit)))
fbe740
+            continue;
fbe740
+
fbe740
+        ret->devAlias[i] = g_strdup(diskDef->dst);
fbe740
+    }
fbe740
 
fbe740
     return ret;
fbe740
 
fbe740
@@ -1932,8 +1942,7 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent)
fbe740
 
fbe740
 static int
fbe740
 qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
fbe740
-                            qemuAgentFSInfoPtr fsinfo,
fbe740
-                            virDomainDefPtr vmdef)
fbe740
+                            qemuAgentFSInfoPtr fsinfo)
fbe740
 {
fbe740
     size_t ndisks;
fbe740
     size_t i;
fbe740
@@ -1956,7 +1965,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
fbe740
         virJSONValuePtr jsondisk = virJSONValueArrayGet(jsondisks, i);
fbe740
         virJSONValuePtr pci;
fbe740
         qemuAgentDiskInfoPtr disk;
fbe740
-        virDomainDiskDefPtr diskDef;
fbe740
         const char *val;
fbe740
 
fbe740
         if (!jsondisk) {
fbe740
@@ -2007,14 +2015,6 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
fbe740
         GET_DISK_ADDR(pci, &disk->pci_controller.function, "function");
fbe740
 
fbe740
 #undef GET_DISK_ADDR
fbe740
-        if (!(diskDef = virDomainDiskByAddress(vmdef,
fbe740
-                                               &disk->pci_controller,
fbe740
-                                               disk->bus,
fbe740
-                                               disk->target,
fbe740
-                                               disk->unit)))
fbe740
-            continue;
fbe740
-
fbe740
-        disk->alias = g_strdup(diskDef->dst);
fbe740
     }
fbe740
 
fbe740
     return 0;
fbe740
@@ -2026,8 +2026,7 @@ qemuAgentGetFSInfoFillDisks(virJSONValuePtr jsondisks,
fbe740
  */
fbe740
 static int
fbe740
 qemuAgentGetFSInfoInternal(qemuAgentPtr mon,
fbe740
-                           qemuAgentFSInfoPtr **info,
fbe740
-                           virDomainDefPtr vmdef)
fbe740
+                           qemuAgentFSInfoPtr **info)
fbe740
 {
fbe740
     size_t i;
fbe740
     int ret = -1;
fbe740
@@ -2143,7 +2142,7 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon,
fbe740
             goto cleanup;
fbe740
         }
fbe740
 
fbe740
-        if (qemuAgentGetFSInfoFillDisks(disk, info_ret[i], vmdef) < 0)
fbe740
+        if (qemuAgentGetFSInfoFillDisks(disk, info_ret[i]) < 0)
fbe740
             goto cleanup;
fbe740
     }
fbe740
 
fbe740
@@ -2173,14 +2172,14 @@ qemuAgentGetFSInfo(qemuAgentPtr mon,
fbe740
     size_t i;
fbe740
     int nfs;
fbe740
 
fbe740
-    nfs = qemuAgentGetFSInfoInternal(mon, &agentinfo, vmdef);
fbe740
+    nfs = qemuAgentGetFSInfoInternal(mon, &agentinfo);
fbe740
     if (nfs < 0)
fbe740
         return ret;
fbe740
     if (VIR_ALLOC_N(info_ret, nfs) < 0)
fbe740
         goto cleanup;
fbe740
 
fbe740
     for (i = 0; i < nfs; i++) {
fbe740
-        if (!(info_ret[i] = qemuAgentFSInfoToPublic(agentinfo[i])))
fbe740
+        if (!(info_ret[i] = qemuAgentFSInfoToPublic(agentinfo[i], vmdef)))
fbe740
             goto cleanup;
fbe740
     }
fbe740
 
fbe740
@@ -2215,7 +2214,7 @@ qemuAgentGetFSInfoParams(qemuAgentPtr mon,
fbe740
     size_t i, j;
fbe740
     int nfs;
fbe740
 
fbe740
-    if ((nfs = qemuAgentGetFSInfoInternal(mon, &fsinfo, vmdef)) < 0)
fbe740
+    if ((nfs = qemuAgentGetFSInfoInternal(mon, &fsinfo)) < 0)
fbe740
         return nfs;
fbe740
 
fbe740
     if (virTypedParamsAddUInt(params, nparams, maxparams,
fbe740
@@ -2262,13 +2261,22 @@ qemuAgentGetFSInfoParams(qemuAgentPtr mon,
fbe740
                                   param_name, fsinfo[i]->ndisks) < 0)
fbe740
             goto cleanup;
fbe740
         for (j = 0; j < fsinfo[i]->ndisks; j++) {
fbe740
+            virDomainDiskDefPtr diskdef = NULL;
fbe740
             qemuAgentDiskInfoPtr d = fsinfo[i]->disks[j];
fbe740
-            g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
fbe740
-                       "fs.%zu.disk.%zu.alias", i, j);
fbe740
-            if (d->alias &&
fbe740
-                virTypedParamsAddString(params, nparams, maxparams,
fbe740
-                                        param_name, d->alias) < 0)
fbe740
-                goto cleanup;
fbe740
+            /* match the disk to the target in the vm definition */
fbe740
+            diskdef = virDomainDiskByAddress(vmdef,
fbe740
+                                             &d->pci_controller,
fbe740
+                                             d->bus,
fbe740
+                                             d->target,
fbe740
+                                             d->unit);
fbe740
+            if (diskdef) {
fbe740
+                g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
fbe740
+                           "fs.%zu.disk.%zu.alias", i, j);
fbe740
+                if (diskdef->dst &&
fbe740
+                    virTypedParamsAddString(params, nparams, maxparams,
fbe740
+                                            param_name, diskdef->dst) < 0)
fbe740
+                    goto cleanup;
fbe740
+            }
fbe740
 
fbe740
             g_snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH,
fbe740
                        "fs.%zu.disk.%zu.serial", i, j);
fbe740
-- 
fbe740
2.25.0
fbe740