Implement the virDomainAgentSetResponseTimeout() which allows to
set the qemu guest agent timeout.

The change consists of two main parts:

 - bhyveDomainAgentSetResponseTimeout() driver method implementation
   which actually sets the agent timeout.
 - Updating virDomainXMLPrivateDataCallbacks with "parse" and "format"
   methods implementation for parsing and formatting of the agent
   timeout value in domain's XML.

Signed-off-by: Roman Bogorodskiy <[email protected]>
---
 src/bhyve/bhyve_domain.c | 29 +++++++++++++++++++++++++
 src/bhyve/bhyve_driver.c | 47 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index b6344185b7..3b5a9b47a3 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -62,9 +62,38 @@ bhyveDomainObjPrivateFree(void *data)
     g_free(priv);
 }
 
+static int
+bhyveDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
+                              virDomainObj *vm,
+                              virDomainDefParserConfig *config G_GNUC_UNUSED)
+{
+    bhyveDomainObjPrivate *priv = vm->privateData;
+
+    if (virXPathInt("string(./agentTimeout)", ctxt, &priv->agentTimeout) == 
-2) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("failed to parse agent timeout"));
+        return -1;
+    }
+
+    return 0;
+}
+
+static int
+bhyveDomainObjPrivateXMLFormat(virBuffer *buf,
+                               virDomainObj *vm)
+{
+    bhyveDomainObjPrivate *priv = vm->privateData;
+
+    virBufferAsprintf(buf, "<agentTimeout>%i</agentTimeout>\n", 
priv->agentTimeout);
+
+    return 0;
+}
+
 virDomainXMLPrivateDataCallbacks virBhyveDriverPrivateDataCallbacks = {
     .alloc = bhyveDomainObjPrivateAlloc,
     .free = bhyveDomainObjPrivateFree,
+    .parse = bhyveDomainObjPrivateXMLParse,
+    .format = bhyveDomainObjPrivateXMLFormat,
 };
 
 static bool
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 4abcd70aba..0823b54b0d 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -2808,6 +2808,52 @@ bhyveDomainRename(virDomainPtr domain,
     return ret;
 }
 
+static int
+bhyveDomainAgentSetResponseTimeout(virDomainPtr domain,
+                                   int timeout,
+                                   unsigned int flags)
+{
+    virDomainObj *vm = NULL;
+    bhyveDomainObjPrivate *priv = NULL;
+    struct _bhyveConn *privconn = domain->conn->privateData;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (timeout < VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("guest agent timeout '%1$d' is less than the minimum 
'%2$d'"),
+                       timeout, VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN);
+        return -1;
+    }
+
+    if (!(vm = bhyveDomObjFromDomain(domain)))
+        return -1;
+
+    if (virDomainAgentSetResponseTimeoutEnsureACL(domain->conn, vm->def) < 0)
+        goto cleanup;
+
+    priv = vm->privateData;
+    if (priv->agent != NULL) {
+        virObjectLock(priv->agent);
+        qemuAgentSetResponseTimeout(priv->agent, timeout);
+        virObjectUnlock(priv->agent);
+    }
+
+    priv->agentTimeout = timeout;
+
+    if (virDomainObjIsActive(vm)) {
+        if (virDomainObjSave(vm, privconn->xmlopt, BHYVE_STATE_DIR) < 0)
+            VIR_WARN("Failed to save status on vm %s", vm->def->name);
+    }
+
+    ret = 0;
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
 static virHypervisorDriver bhyveHypervisorDriver = {
     .name = "bhyve",
     .connectURIProbe = bhyveConnectURIProbe,
@@ -2886,6 +2932,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
     .domainAuthorizedSSHKeysGet = bhyveDomainAuthorizedSSHKeysGet, /* 12.5.0 */
     .domainAuthorizedSSHKeysSet = bhyveDomainAuthorizedSSHKeysSet, /* 12.5.0 */
     .domainRename = bhyveDomainRename, /* 12.6.0 */
+    .domainAgentSetResponseTimeout = bhyveDomainAgentSetResponseTimeout, /* 
12.7.0 */
 };
 
 
-- 
2.52.0

Reply via email to