[Kimchi-devel] [PATCH V2] [Kimchi] Handle Libvirt host ENOSPC event

Lucio Correia luciojhc at linux.vnet.ibm.com
Tue May 17 14:39:03 UTC 2016


When storage pool is out of space and guest requires more,
guest is paused and nothing is told to the user. This patch
uses Libvirt Event handling and Asynchronous Notifications
mechanism to tell web users about what happened.

Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 i18n.py                |  1 +
 model/libvirtevents.py | 25 +++++++++++++++++++++++++
 model/model.py         |  3 +++
 3 files changed, 29 insertions(+)

Change in V2:
- Rebase with latest master

diff --git a/i18n.py b/i18n.py
index 49b7f1c..c697d52 100644
--- a/i18n.py
+++ b/i18n.py
@@ -337,4 +337,5 @@ messages = {
     "KCHEVENT0001E": _("Failed to register the default event implementation."),
     "KCHEVENT0002E": _("Failed to register timeout event."),
     "KCHEVENT0003E": _("Failed to Run the default event implementation."),
+    "KCHEVENT0004W": _("I/O error on guest '%(vm)s': storage pool out of space for %(devAlias)s (%(srcPath)s)."),
 }
diff --git a/model/libvirtevents.py b/model/libvirtevents.py
index ab5c17d..00e9433 100644
--- a/model/libvirtevents.py
+++ b/model/libvirtevents.py
@@ -22,6 +22,9 @@ import libvirt
 import time
 
 from wok.exception import OperationFailed
+from wok.message import WokMessage
+from wok.model.notifications import add_notification
+from wok.utils import wok_log
 
 
 class LibvirtEvents(object):
@@ -57,3 +60,25 @@ class LibvirtEvents(object):
     # Event loop handler used to limit length of waiting for any other event.
     def _kimchi_EventTimeout(self, timer, opaque):
         time.sleep(1)
+
+    def event_enospc_cb(self, conn, dom, path, dev, action, reason, args):
+        if reason == "enospc":
+            info = {
+                "vm": dom.name(),
+                "srcPath": path,
+                "devAlias": dev,
+            }
+            add_notification("KCHEVENT0004W", info, '/plugins/kimchi')
+            msg = WokMessage("KCHEVENT0004W", info, '/plugins/kimchi')
+            wok_log.warning(msg.get_text())
+
+    def handleEnospc(self, conn):
+        """
+        Register Libvirt IO_ERROR_REASON event to handle host ENOSPC
+        """
+        conn.get().domainEventRegisterAny(
+            None,
+            libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON,
+            self.event_enospc_cb,
+            libvirt.VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON
+        )
diff --git a/model/model.py b/model/model.py
index ed474d2..327d5a7 100644
--- a/model/model.py
+++ b/model/model.py
@@ -50,6 +50,9 @@ class Model(BaseModel):
                  'eventsloop': self.events}
         models = []
 
+        # Register for Libvirt's host ENOSPC event and notify UI if it happens
+        self.events.handleEnospc(self.conn)
+
         # Import task model from Wok
         instances = get_instances('wok.model.tasks')
         for instance in instances:
-- 
1.9.1




More information about the Kimchi-devel mailing list