[libvirt] [PATCH 1/4] save domstate as string in status file

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

 



This one is as posted before. Not really necessary, but makes things look
nicer.
 -- Guido

---
 src/domain_conf.c        |    9 +++++++++
 src/domain_conf.h        |    2 ++
 src/libvirt_private.syms |    2 ++
 src/qemu_conf.c          |   12 ++++++++----
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/domain_conf.c b/src/domain_conf.c
index 94196e8..8deb992 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -142,6 +142,15 @@ VIR_ENUM_IMPL(virDomainHostdevSubsys, VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST,
               "usb",
               "pci")
 
+VIR_ENUM_IMPL(virDomainState, VIR_DOMAIN_CRASHED+1,
+              "nostate",
+              "running",
+              "blocked",
+              "paused",
+              "shutdown",
+              "shutoff",
+              "crashed")
+
 #define virDomainReportError(conn, code, fmt...)                           \
         virReportErrorHelper(conn, VIR_FROM_DOMAIN, code, __FILE__,        \
                                __FUNCTION__, __LINE__, fmt)
diff --git a/src/domain_conf.h b/src/domain_conf.h
index 1e5c103..45b3e10 100644
--- a/src/domain_conf.h
+++ b/src/domain_conf.h
@@ -625,5 +625,7 @@ VIR_ENUM_DECL(virDomainHostdevSubsys)
 VIR_ENUM_DECL(virDomainInput)
 VIR_ENUM_DECL(virDomainInputBus)
 VIR_ENUM_DECL(virDomainGraphics)
+/* from libvirt.h */
+VIR_ENUM_DECL(virDomainState)
 
 #endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c76b6c2..3f83a07 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -94,6 +94,8 @@ virDomainVirtTypeToString;
 virDomainFSDefFree;
 virDomainObjLock;
 virDomainObjUnlock;
+virDomainStateTypeToString;
+virDomainStateTypeFromString;
 
 
 # domain_event.h
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index faf1e12..45108f3 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1375,12 +1375,14 @@ qemudDomainStatusParseFile(virConnectPtr conn,
     }
 
     ctxt->node = root;
-    if((virXPathLong(conn, "string(./@state)", ctxt, &val)) < 0) {
+    if(!(tmp = virXPathString(conn, "string(./@state)", ctxt))) {
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
                              "%s", _("invalid domain state"));
         goto error;
-    } else
-        status->state = (int)val;
+    } else {
+        status->state = virDomainStateTypeFromString(tmp);
+        VIR_FREE(tmp);
+    }
 
     if((virXPathLong(conn, "string(./@pid)", ctxt, &val)) < 0) {
         qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
@@ -1433,7 +1435,9 @@ qemudDomainStatusFormat(virConnectPtr conn,
     char *config_xml = NULL, *xml = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
 
-    virBufferVSprintf(&buf, "<domstatus state='%d' pid='%d'>\n", vm->state, vm->pid);
+    virBufferVSprintf(&buf, "<domstatus state='%s' pid='%d'>\n",
+                      virDomainStateTypeToString(vm->state),
+                      vm->pid);
     virBufferEscapeString(&buf, "  <monitor path='%s'/>\n", vm->monitorpath);
 
     if (!(config_xml = virDomainDefFormat(conn,
-- 
1.6.0.6

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]