Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > aadbe78a25743146bb784eee19f007c5 > files > 206

kvm-83-164.el5_5.9.src.rpm

From f7c0198882eee9281e1cb3d0bfc736bd54cf2ae0 Mon Sep 17 00:00:00 2001
From: Gleb Natapov <gleb@redhat.com>
Date: Mon, 2 Mar 2009 15:18:39 +0200
Subject: [PATCH 1/2] add notification for vmstops

Print notification when vm is stopped because of write error.

This is not upstream since I haven't found upstream that has
term_printf_async ;)

[ehabkost: added vmstop option to "notify" command help text]

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Bugzilla: 481863
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
---
 qemu/console.h       |    3 ++-
 qemu/hw/ide.c        |    3 +++
 qemu/hw/scsi-disk.c  |    3 +++
 qemu/hw/virtio-blk.c |    3 +++
 qemu/monitor.c       |    4 +++-
 5 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/qemu/console.h b/qemu/console.h
index 398c8ec..b33d177 100644
--- a/qemu/console.h
+++ b/qemu/console.h
@@ -193,7 +193,8 @@ extern uint8_t _translate_keycode(const int key);
 #define SHUTDOWN_ASYNC_EVENT 3
 #define MIGRATION_ASYNC_EVENT 4
 #define REBOOT_ASYNC_EVENT 5
-#define MAX_ASYNC_EVENTS  REBOOT_ASYNC_EVENT
+#define VMSTOP_ASYNC_EVENT 6
+#define MAX_ASYNC_EVENTS  VMSTOP_ASYNC_EVENT
 
 /* FIXME: term_printf et al should probably go elsewhere so everything
    does not need to include console.h  */
diff --git a/qemu/hw/ide.c b/qemu/hw/ide.c
index 7a2ab9e..a312a94 100644
--- a/qemu/hw/ide.c
+++ b/qemu/hw/ide.c
@@ -33,6 +33,7 @@
 #include "sysemu.h"
 #include "ppc_mac.h"
 #include "sh.h"
+#include <console.h>
 
 /* debug IDE devices */
 //#define DEBUG_IDE
@@ -883,6 +884,8 @@ static int ide_handle_write_error(IDEState *s, int error, int op)
         s->bmdma->ide_if = s;
         s->bmdma->status |= op;
         vm_stop(0);
+        term_printf_async(VMSTOP_ASYNC_EVENT,
+                "VM is stopped due to disk write error: %s\n", strerror(error));
     } else {
         if (op == BM_STATUS_DMA_RETRY)
             ide_dma_error(s);
diff --git a/qemu/hw/scsi-disk.c b/qemu/hw/scsi-disk.c
index 5d1ff12..961a148 100644
--- a/qemu/hw/scsi-disk.c
+++ b/qemu/hw/scsi-disk.c
@@ -15,6 +15,7 @@
 
 #include <qemu-common.h>
 #include <sysemu.h>
+#include <console.h>
 //#define DEBUG_SCSI
 
 #ifdef DEBUG_SCSI
@@ -228,6 +229,8 @@ static int scsi_handle_write_error(SCSIRequest *r, int error)
             || action == BLOCK_ERR_STOP_ANY) {
         r->status |= SCSI_REQ_STATUS_RETRY;
         vm_stop(0);
+        term_printf_async(VMSTOP_ASYNC_EVENT,
+                "VM is stopped due to disk write error: %s\n", strerror(error));
     } else {
         scsi_command_complete(r, STATUS_CHECK_CONDITION,
                 SENSE_HARDWARE_ERROR);
diff --git a/qemu/hw/virtio-blk.c b/qemu/hw/virtio-blk.c
index 15dd830..ec27efb 100644
--- a/qemu/hw/virtio-blk.c
+++ b/qemu/hw/virtio-blk.c
@@ -13,6 +13,7 @@
 
 #include <qemu-common.h>
 #include <sysemu.h>
+#include <console.h>
 #include "virtio-blk.h"
 #include "block_int.h"
 
@@ -65,6 +66,8 @@ static int virtio_blk_handle_write_error(VirtIOBlockReq *req, int error)
         req->next = s->rq;
         s->rq = req;
         vm_stop(0);
+        term_printf_async(VMSTOP_ASYNC_EVENT,
+                "VM is stopped due to disk write error: %s\n", strerror(error));
     } else {
         virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
     }
diff --git a/qemu/monitor.c b/qemu/monitor.c
index c71827c..131c389 100644
--- a/qemu/monitor.c
+++ b/qemu/monitor.c
@@ -257,6 +257,8 @@ static void do_notify_async_events(char *event_str, char *enable)
         event = MIGRATION_ASYNC_EVENT;
     else if (!strcmp(event_str, "reboot"))
         event = REBOOT_ASYNC_EVENT;
+    else if (!strcmp(event_str, "vmstop"))
+        event = VMSTOP_ASYNC_EVENT;
     else
         return;
 
@@ -1615,7 +1617,7 @@ static term_cmd_t term_cmds[] = {
     { "set_qxl_log_level", "i", qxl_do_set_log_level, "", "set qxl log level" },
 #endif
     { "notify", "ss", do_notify_async_events,
-      "vnc|rtc|migration|reboot|shutdown on|off", "enable / disable printing of notifications for the specified event" },
+      "vnc|rtc|migration|reboot|shutdown|vmstop on|off", "enable / disable printing of notifications for the specified event" },
     { NULL, NULL, },
 };
 
-- 
1.6.1