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

[libvirt] [RFC PATCHv2 2/5] qemu: move monitor device out of domain_conf common code



* src/conf/domain_conf.h (virDomainChrDeviceType): Drop monitor.
* src/conf/domain_conf.c (virDomainChrDevice)
(virDomainChrDefParseTargetXML, virDomainChrDefFormat): Drop
monitor support.
* src/qemu/qemu_command.h (qemuBuildCommandLine): Alter signature.
* src/qemu/qemu_monitor.h (qemuMonitorOpen): Likewise.
* src/qemu/qemu_domain.h (_qemuDomainObjPrivate): Change type of
monConfig.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateFree)
(qemuDomainObjPrivateXMLFormat, qemuDomainObjPrivateXMLParse):
Adjust to type change.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
* src/qemu/qemu_driver.c (qemuPrepareMonitorChr)
(qemudStartVMDaemon, qemuDomainXMLToNative, qemuConnectMonitor)
(qemudShutdownVMDaemon): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorOpen): Likewise.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Likewise.
---
 src/conf/domain_conf.c   |    9 ---------
 src/conf/domain_conf.h   |    3 +--
 src/qemu/qemu_command.c  |    7 +++----
 src/qemu/qemu_command.h  |    2 +-
 src/qemu/qemu_domain.c   |   29 ++++++++++++-----------------
 src/qemu/qemu_domain.h   |    4 ++--
 src/qemu/qemu_driver.c   |   23 ++++++++---------------
 src/qemu/qemu_hotplug.c  |    4 ++--
 src/qemu/qemu_monitor.c  |   10 +++++-----
 src/qemu/qemu_monitor.h  |    4 ++--
 tests/qemuxml2argvtest.c |    9 ++++-----
 11 files changed, 40 insertions(+), 64 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0ab2e02..674eddb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -198,7 +198,6 @@ VIR_ENUM_IMPL(virDomainChrConsoleTarget,
               "virtio")

 VIR_ENUM_IMPL(virDomainChrDevice, VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
-              "monitor",
               "parallel",
               "serial",
               "console",
@@ -2746,10 +2745,6 @@ virDomainChrDefParseTargetXML(virCapsPtr caps,
         }
         break;

-    case VIR_DOMAIN_CHR_DEVICE_TYPE_MONITOR:
-        /* Nothing to parse */
-        break;
-
     default:
         portStr = virXMLPropString(cur, "port");
         if (portStr == NULL) {
@@ -6514,10 +6509,6 @@ virDomainChrDefFormat(virBufferPtr buf,
         break;
     }

-    case VIR_DOMAIN_CHR_DEVICE_TYPE_MONITOR:
-        /* Nothing to format */
-        break;
-
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
         virBufferVSprintf(buf,
                           "      <target type='%s' port='%d'/>\n",
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ebc725c..24b82b3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -344,8 +344,7 @@ struct _virDomainNetDef {
 };

 enum virDomainChrDeviceType {
-    VIR_DOMAIN_CHR_DEVICE_TYPE_MONITOR = 0,
-    VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL,
+    VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL = 0,
     VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL,
     VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE,
     VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6bc2f8e..205c303 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2452,7 +2452,7 @@ virCommandPtr
 qemuBuildCommandLine(virConnectPtr conn,
                      struct qemud_driver *driver,
                      virDomainDefPtr def,
-                     virDomainChrDefPtr monitor_chr,
+                     virDomainChrSourceDefPtr monitor_chr,
                      bool monitor_json,
                      unsigned long long qemuCmdFlags,
                      const char *migrateFrom,
@@ -2734,8 +2734,7 @@ qemuBuildCommandLine(virConnectPtr conn,
         if (qemuCmdFlags & QEMUD_CMD_FLAG_CHARDEV) {

             virCommandAddArg(cmd, "-chardev");
-            if (!(chrdev = qemuBuildChrChardevStr(&monitor_chr->source,
-                                                  monitor_chr->info.alias)))
+            if (!(chrdev = qemuBuildChrChardevStr(monitor_chr, "monitor")))
                 goto error;
             virCommandAddArg(cmd, chrdev);
             VIR_FREE(chrdev);
@@ -2749,7 +2748,7 @@ qemuBuildCommandLine(virConnectPtr conn,
                 prefix = "control,";

             virCommandAddArg(cmd, "-monitor");
-            if (!(chrdev = qemuBuildChrArgStr(&monitor_chr->source, prefix)))
+            if (!(chrdev = qemuBuildChrArgStr(monitor_chr, prefix)))
                 goto error;
             virCommandAddArg(cmd, chrdev);
             VIR_FREE(chrdev);
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index b84fa3a..b3adc22 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -40,7 +40,7 @@
 virCommandPtr qemuBuildCommandLine(virConnectPtr conn,
                                    struct qemud_driver *driver,
                                    virDomainDefPtr def,
-                                   virDomainChrDefPtr monitor_chr,
+                                   virDomainChrSourceDefPtr monitor_chr,
                                    bool monitor_json,
                                    unsigned long long qemuCmdFlags,
                                    const char *migrateFrom,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 48820bb..fa7c8bd 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -56,7 +56,7 @@ static void qemuDomainObjPrivateFree(void *data)
     qemuDomainObjPrivatePtr priv = data;

     qemuDomainPCIAddressSetFree(priv->pciaddrs);
-    virDomainChrDefFree(priv->monConfig);
+    virDomainChrSourceDefFree(priv->monConfig);
     VIR_FREE(priv->vcpupids);

     /* This should never be non-NULL if we get here, but just in case... */
@@ -75,13 +75,13 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)

     /* priv->monitor_chr is set only for qemu */
     if (priv->monConfig) {
-        switch (priv->monConfig->source.type) {
+        switch (priv->monConfig->type) {
         case VIR_DOMAIN_CHR_TYPE_UNIX:
-            monitorpath = priv->monConfig->source.data.nix.path;
+            monitorpath = priv->monConfig->data.nix.path;
             break;
         default:
         case VIR_DOMAIN_CHR_TYPE_PTY:
-            monitorpath = priv->monConfig->source.data.file.path;
+            monitorpath = priv->monConfig->data.file.path;
             break;
         }

@@ -89,7 +89,7 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
         if (priv->monJSON)
             virBufferAddLit(buf, " json='1'");
         virBufferVSprintf(buf, " type='%s'/>\n",
-                          virDomainChrTypeToString(priv->monConfig->source.type));
+                          virDomainChrTypeToString(priv->monConfig->type));
     }


@@ -118,11 +118,6 @@ static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
         goto error;
     }

-    if (!(priv->monConfig->info.alias = strdup("monitor"))) {
-        virReportOOMError();
-        goto error;
-    }
-
     if (!(monitorpath =
           virXPathString("string(./monitor[1]/@path)", ctxt))) {
         qemuReportError(VIR_ERR_INTERNAL_ERROR,
@@ -132,9 +127,9 @@ static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)

     tmp = virXPathString("string(./monitor[1]/@type)", ctxt);
     if (tmp)
-        priv->monConfig->source.type = virDomainChrTypeFromString(tmp);
+        priv->monConfig->type = virDomainChrTypeFromString(tmp);
     else
-        priv->monConfig->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
+        priv->monConfig->type = VIR_DOMAIN_CHR_TYPE_PTY;
     VIR_FREE(tmp);

     if (virXPathBoolean("count(./monitor[ json = '1']) > 0", ctxt)) {
@@ -143,18 +138,18 @@ static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
         priv->monJSON = 0;
     }

-    switch (priv->monConfig->source.type) {
+    switch (priv->monConfig->type) {
     case VIR_DOMAIN_CHR_TYPE_PTY:
-        priv->monConfig->source.data.file.path = monitorpath;
+        priv->monConfig->data.file.path = monitorpath;
         break;
     case VIR_DOMAIN_CHR_TYPE_UNIX:
-        priv->monConfig->source.data.nix.path = monitorpath;
+        priv->monConfig->data.nix.path = monitorpath;
         break;
     default:
         VIR_FREE(monitorpath);
         qemuReportError(VIR_ERR_INTERNAL_ERROR,
                         _("unsupported monitor type '%s'"),
-                        virDomainChrTypeToString(priv->monConfig->source.type));
+                        virDomainChrTypeToString(priv->monConfig->type));
         goto error;
     }

@@ -185,7 +180,7 @@ static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
     return 0;

 error:
-    virDomainChrDefFree(priv->monConfig);
+    virDomainChrSourceDefFree(priv->monConfig);
     priv->monConfig = NULL;
     VIR_FREE(nodes);
     return -1;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 870a900..f14fb79 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1,7 +1,7 @@
 /*
  * qemu_domain.h: QEMU domain private state
  *
- * Copyright (C) 2006-2007, 2009-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2011 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -65,7 +65,7 @@ struct _qemuDomainObjPrivate {
     unsigned long long jobStart;

     qemuMonitorPtr mon;
-    virDomainChrDefPtr monConfig;
+    virDomainChrSourceDefPtr monConfig;
     int monJSON;
     int monitor_warned;
     bool gotShutdown;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 59f2c14..29b1d74 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2570,20 +2570,13 @@ static int qemudSecurityHook(void *data) {

 static int
 qemuPrepareMonitorChr(struct qemud_driver *driver,
-                      virDomainChrDefPtr monConfig,
+                      virDomainChrSourceDefPtr monConfig,
                       const char *vm)
 {
-    monConfig->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_MONITOR;
+    monConfig->type = VIR_DOMAIN_CHR_TYPE_UNIX;
+    monConfig->data.nix.listen = true;

-    monConfig->source.type = VIR_DOMAIN_CHR_TYPE_UNIX;
-    monConfig->source.data.nix.listen = true;
-
-    if (!(monConfig->info.alias = strdup("monitor"))) {
-        virReportOOMError();
-        return -1;
-    }
-
-    if (virAsprintf(&monConfig->source.data.nix.path, "%s/%s.monitor",
+    if (virAsprintf(&monConfig->data.nix.path, "%s/%s.monitor",
                     driver->libDir, vm) < 0) {
         virReportOOMError();
         return -1;
@@ -3018,9 +3011,9 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver,
         qemuMonitorClose(priv->mon);

     if (priv->monConfig) {
-        if (priv->monConfig->source.type == VIR_DOMAIN_CHR_TYPE_UNIX)
-            unlink(priv->monConfig->source.data.nix.path);
-        virDomainChrDefFree(priv->monConfig);
+        if (priv->monConfig->type == VIR_DOMAIN_CHR_TYPE_UNIX)
+            unlink(priv->monConfig->data.nix.path);
+        virDomainChrSourceDefFree(priv->monConfig);
         priv->monConfig = NULL;
     }

@@ -6030,7 +6023,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
                                    unsigned int flags ATTRIBUTE_UNUSED) {
     struct qemud_driver *driver = conn->privateData;
     virDomainDefPtr def = NULL;
-    virDomainChrDef monConfig;
+    virDomainChrSourceDef monConfig;
     unsigned long long qemuCmdFlags;
     virCommandPtr cmd = NULL;
     char *ret = NULL;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index b40150d..9d6697e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -567,7 +567,7 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,

     if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
         net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
-        if (priv->monConfig->source.type != VIR_DOMAIN_CHR_TYPE_UNIX) {
+        if (priv->monConfig->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
             qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                             _("network device type '%s' cannot be attached: "
                               "qemu is not using a unix socket monitor"),
@@ -578,7 +578,7 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
         if ((tapfd = qemuNetworkIfaceConnect(conn, driver, net, qemuCmdFlags)) < 0)
             return -1;
     } else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
-        if (priv->monConfig->source.type != VIR_DOMAIN_CHR_TYPE_UNIX) {
+        if (priv->monConfig->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
             qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                             _("network device type '%s' cannot be attached: "
                             "qemu is not using a unix socket monitor"),
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index cc8b374..055e7ce 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -588,7 +588,7 @@ qemuMonitorIO(int watch, int fd, int events, void *opaque) {

 qemuMonitorPtr
 qemuMonitorOpen(virDomainObjPtr vm,
-                virDomainChrDefPtr config,
+                virDomainChrSourceDefPtr config,
                 int json,
                 qemuMonitorCallbacksPtr cb)
 {
@@ -625,20 +625,20 @@ qemuMonitorOpen(virDomainObjPtr vm,
     mon->cb = cb;
     qemuMonitorLock(mon);

-    switch (config->source.type) {
+    switch (config->type) {
     case VIR_DOMAIN_CHR_TYPE_UNIX:
         mon->hasSendFD = 1;
-        mon->fd = qemuMonitorOpenUnix(config->source.data.nix.path);
+        mon->fd = qemuMonitorOpenUnix(config->data.nix.path);
         break;

     case VIR_DOMAIN_CHR_TYPE_PTY:
-        mon->fd = qemuMonitorOpenPty(config->source.data.file.path);
+        mon->fd = qemuMonitorOpenPty(config->data.file.path);
         break;

     default:
         qemuReportError(VIR_ERR_INTERNAL_ERROR,
                         _("unable to handle monitor type: %s"),
-                        virDomainChrTypeToString(config->source.type));
+                        virDomainChrTypeToString(config->type));
         goto cleanup;
     }

diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 3ac5024..718ea13 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1,7 +1,7 @@
 /*
  * qemu_monitor.h: interaction with QEMU monitor console
  *
- * Copyright (C) 2006-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2011 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -119,7 +119,7 @@ char *qemuMonitorEscapeArg(const char *in);
 char *qemuMonitorEscapeShell(const char *in);

 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
-                               virDomainChrDefPtr config,
+                               virDomainChrSourceDefPtr config,
                                int json,
                                qemuMonitorCallbacksPtr cb);

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 7e3ce2e..d7951df 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -39,7 +39,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
     int ret = -1;
     unsigned long long flags;
     virDomainDefPtr vmdef = NULL;
-    virDomainChrDef monitor_chr;
+    virDomainChrSourceDef monitor_chr;
     virConnectPtr conn;
     char *log = NULL;
     char *emulator = NULL;
@@ -84,10 +84,9 @@ static int testCompareXMLToArgvFiles(const char *xml,
         vmdef->id = -1;

     memset(&monitor_chr, 0, sizeof(monitor_chr));
-    monitor_chr.source.type = VIR_DOMAIN_CHR_TYPE_UNIX;
-    monitor_chr.source.data.nix.path = (char *)"/tmp/test-monitor";
-    monitor_chr.source.data.nix.listen = true;
-    monitor_chr.info.alias = (char *)"monitor";
+    monitor_chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
+    monitor_chr.data.nix.path = (char *)"/tmp/test-monitor";
+    monitor_chr.data.nix.listen = true;

     flags = QEMUD_CMD_FLAG_VNC_COLON |
         QEMUD_CMD_FLAG_NO_REBOOT |
-- 
1.7.3.4


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