All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/7] kvm tools: Guest kernel compatability
@ 2011-08-18 12:18 Sasha Levin
  2011-08-18 12:18 ` [PATCH 2/7] kvm tools: Add guest compatability warning to virtio-rng Sasha Levin
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Sasha Levin @ 2011-08-18 12:18 UTC (permalink / raw)
  To: penberg; +Cc: kvm, mingo, asias.hejun, gorcunov, Sasha Levin

The problem of users running kernel which wasn't built for kvm tools is
somewhat common. Usualy the result is a panic during boot and a user whos'
stuck and doesn't know what to do next.

Compatability checks try to solve this issue by giving the user a meaningfull
error message which can explain whats going on and how he can fix it.

The idea is to register the device during device init and unregister the
device when the device has been 'used'. In case the kernel didn't access
the device before the guest is shut down, the host will notify the user that
something is wrong.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/Makefile                   |    1 +
 tools/kvm/builtin-run.c              |    3 +
 tools/kvm/guest_compat.c             |  104 ++++++++++++++++++++++++++++++++++
 tools/kvm/include/kvm/guest_compat.h |    9 +++
 4 files changed, 117 insertions(+), 0 deletions(-)
 create mode 100644 tools/kvm/guest_compat.c
 create mode 100644 tools/kvm/include/kvm/guest_compat.h

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 85bbce7..316c2c9 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -33,6 +33,7 @@ OBJS	+= builtin-version.o
 OBJS	+= cpuid.o
 OBJS	+= disk/core.o
 OBJS	+= framebuffer.o
+OBJS	+= guest_compat.o
 OBJS	+= hw/rtc.o
 OBJS	+= hw/serial.o
 OBJS	+= interrupt.o
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 2816774..636f70e 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -27,6 +27,7 @@
 #include "kvm/rtc.h"
 #include "kvm/sdl.h"
 #include "kvm/vnc.h"
+#include "kvm/guest_compat.h"
 
 #include <linux/types.h>
 
@@ -730,6 +731,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			exit_code = 1;
 	}
 
+	compat__print_all_messages();
+
 	fb__stop();
 
 	virtio_blk__delete_all(kvm);
diff --git a/tools/kvm/guest_compat.c b/tools/kvm/guest_compat.c
new file mode 100644
index 0000000..c5bacb8
--- /dev/null
+++ b/tools/kvm/guest_compat.c
@@ -0,0 +1,104 @@
+#include "kvm/guest_compat.h"
+
+#include "kvm/mutex.h"
+
+#include <linux/kernel.h>
+#include <linux/list.h>
+
+struct compat_message {
+	int id;
+	char *title;
+	char *desc;
+
+	struct list_head list;
+};
+
+static int id;
+static DEFINE_MUTEX(compat_mtx);
+static LIST_HEAD(messages);
+
+int compat__add_message(const char *title, const char *desc)
+{
+	struct compat_message *msg;
+
+	mutex_lock(&compat_mtx);
+	msg = malloc(sizeof(*msg));
+	if (msg == NULL)
+		goto cleanup;
+
+	*msg = (struct compat_message) {
+		.id = id,
+		.title = strdup(title),
+		.desc = strdup(desc),
+	};
+
+	if (msg->title == NULL || msg->desc == NULL)
+		goto cleanup;
+
+	list_add_tail(&msg->list, &messages);
+
+	mutex_unlock(&compat_mtx);
+
+	return id++;
+
+cleanup:
+	if (msg) {
+		free(msg->title);
+		free(msg->desc);
+		free(msg);
+	}
+
+	mutex_unlock(&compat_mtx);
+
+	return -ENOMEM;
+}
+
+static void compat__free(struct compat_message *msg)
+{
+	free(msg->title);
+	free(msg->desc);
+	free(msg);
+}
+
+int compat__remove_message(int id)
+{
+	struct compat_message *pos, *n;
+
+	mutex_lock(&compat_mtx);
+
+	list_for_each_entry_safe(pos, n, &messages, list) {
+		if (pos->id == id) {
+			list_del(&pos->list);
+			compat__free(pos);
+
+			mutex_unlock(&compat_mtx);
+
+			return 0;
+		}
+	}
+
+	mutex_unlock(&compat_mtx);
+
+	return -ENOENT;
+}
+
+int compat__print_all_messages(void)
+{
+	mutex_lock(&compat_mtx);
+
+	while (!list_empty(&messages)) {
+		struct compat_message *msg;
+
+		msg = list_first_entry(&messages, struct compat_message, list);
+
+		printf("\n\n*** Compatability Warning ***\n\n\t%s\n\n%s\n",
+			msg->title, msg->desc);
+
+		list_del(&msg->list);
+		compat__free(msg);
+	}
+
+	mutex_unlock(&compat_mtx);
+
+	return 0;
+}
\ No newline at end of file
diff --git a/tools/kvm/include/kvm/guest_compat.h b/tools/kvm/include/kvm/guest_compat.h
new file mode 100644
index 0000000..ae7abbd
--- /dev/null
+++ b/tools/kvm/include/kvm/guest_compat.h
@@ -0,0 +1,9 @@
+#ifndef KVM__GUEST_COMPAT_H
+#define KVM__GUEST_COMPAT_H
+
+int compat__print_all_messages(void);
+int compat__remove_message(int id);
+int compat__add_message(const char *title, const char *description);
+
+
+#endif
\ No newline at end of file
-- 
1.7.6


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-08-18 12:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-18 12:18 [PATCH 1/7] kvm tools: Guest kernel compatability Sasha Levin
2011-08-18 12:18 ` [PATCH 2/7] kvm tools: Add guest compatability warning to virtio-rng Sasha Levin
2011-08-18 12:18 ` [PATCH 3/7] kvm tools: Add guest compatability warning to virtio-blk Sasha Levin
2011-08-18 12:18 ` [PATCH 4/7] kvm tools: Add guest compatability warning to virtio-9p Sasha Levin
2011-08-18 12:18 ` [PATCH 5/7] kvm tools: Add guest compatability warning to virtio-net Sasha Levin
2011-08-18 12:18 ` [PATCH 6/7] kvm tools: Add guest compatability warning to virtio-console Sasha Levin
2011-08-18 12:18 ` [PATCH 7/7] kvm tools: Add guest compatability warning to virtio-balloon Sasha Levin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.