[libvirt] [PATCH] save state as string

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

 



Hi,
current domstatus code saves the domain as number, attached patch safes
it as string which looks a bit nicer.
Cheers,
 -- Guido
>From b266ff63d9a96a5901e2171b94acef287685109a Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@xxxxxxxxxxx>
Date: Mon, 29 Dec 2008 12:21:31 +0100
Subject: [PATCH] save domstate as string in status file

---
 src/domain_conf.c          |    9 +++++++++
 src/domain_conf.h          |    2 ++
 src/libvirt_sym.version.in |    3 ++-
 src/qemu_conf.c            |   12 ++++++++----
 4 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/domain_conf.c b/src/domain_conf.c
index f63b846..c50db75 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 3ad518b..b13ea0b 100644
--- a/src/domain_conf.h
+++ b/src/domain_conf.h
@@ -622,5 +622,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_sym.version.in b/src/libvirt_sym.version.in
index de919da..7d39480 100644
--- a/src/libvirt_sym.version.in
+++ b/src/libvirt_sym.version.in
@@ -370,7 +370,8 @@ LIBVIRT_PRIVATE_@VERSION@ {
 	virDomainFSDefFree;
 	virDomainObjLock;
 	virDomainObjUnlock;
-
+	virDomainStateTypeToString;
+	virDomainStateTypeFromString;
 
 	# domain_event.h
 	virDomainEventCallbackListAdd;
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 5d84f85..24975cc 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1356,12 +1356,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,
@@ -1414,7 +1416,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.3

--
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]