[Qemu-devel] [PATCH 03/17] Introduce os-win32.c and move polling functions from vl.c

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

This introduces os-win32.c. It is meant to carry win32 specific
functions thata are not relevant for all of QEMU as well as win32
versions of various pieces like signal handling etc.

Move win32 polling handler helper functions from vl.c to os-win32.c

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 Makefile.objs |1 +
 os-win32.c|  111 +
 vl.c  |   80 -
 3 files changed, 112 insertions(+), 80 deletions(-)
 create mode 100644 os-win32.c

diff --git a/Makefile.objs b/Makefile.objs
index 9796dcb..58fdb03 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -144,6 +144,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
 hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-$(CONFIG_WIN32) += os-win32.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-win32.c b/os-win32.c
new file mode 100644
index 000..5a464cc
--- /dev/null
+++ b/os-win32.c
@@ -0,0 +1,111 @@
+/*
+ * os-win32.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include windows.h
+#include unistd.h
+#include fcntl.h
+#include signal.h
+#include time.h
+#include errno.h
+#include sys/time.h
+#include config-host.h
+#include sysemu.h
+
+/***/
+/* Polling handling */
+
+typedef struct PollingEntry {
+PollingFunc *func;
+void *opaque;
+struct PollingEntry *next;
+} PollingEntry;
+
+static PollingEntry *first_polling_entry;
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque)
+{
+PollingEntry **ppe, *pe;
+pe = qemu_mallocz(sizeof(PollingEntry));
+pe-func = func;
+pe-opaque = opaque;
+for(ppe = first_polling_entry; *ppe != NULL; ppe = (*ppe)-next);
+*ppe = pe;
+return 0;
+}
+
+void qemu_del_polling_cb(PollingFunc *func, void *opaque)
+{
+PollingEntry **ppe, *pe;
+for(ppe = first_polling_entry; *ppe != NULL; ppe = (*ppe)-next) {
+pe = *ppe;
+if (pe-func == func  pe-opaque == opaque) {
+*ppe = pe-next;
+qemu_free(pe);
+break;
+}
+}
+}
+
+/***/
+/* Wait objects support */
+typedef struct WaitObjects {
+int num;
+HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
+WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
+void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
+} WaitObjects;
+
+static WaitObjects wait_objects = {0};
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+WaitObjects *w = wait_objects;
+
+if (w-num = MAXIMUM_WAIT_OBJECTS)
+return -1;
+w-events[w-num] = handle;
+w-func[w-num] = func;
+w-opaque[w-num] = opaque;
+w-num++;
+return 0;
+}
+
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+int i, found;
+WaitObjects *w = wait_objects;
+
+found = 0;
+for (i = 0; i  w-num; i++) {
+if (w-events[i] == handle)
+found = 1;
+if (found) {
+w-events[i] = w-events[i + 1];
+w-func[i] = w-func[i + 1];
+w-opaque[i] = w-opaque[i + 1];
+}
+}
+if (found)
+w-num--;
+}
diff --git a/vl.c b/vl.c
index 7c4298a..afbb26c 100644
--- a/vl.c
+++ b/vl.c
@@ -1497,86 +1497,6 @@ int qemu_set_fd_handler(int fd,
 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
 }
 
-#ifdef _WIN32
-/***/
-/* Polling handling */
-
-typedef struct PollingEntry {
-PollingFunc *func;
-void *opaque;
-struct PollingEntry *next;
-} PollingEntry;
-
-static PollingEntry *first_polling_entry;
-
-int

[Qemu-devel] [PATCH 16/17] Move line-buffering setup to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move line-buffering setup to OS specific files.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |5 +
 qemu-os-posix.h |1 +
 qemu-os-win32.h |2 ++
 vl.c|5 +
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 3a96c91..9bae8fe 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -298,3 +298,8 @@ void os_pidfile_error(void)
 } else
 fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno));
 }
+
+void os_set_line_buffering(void)
+{
+setvbuf(stdout, NULL, _IOLBF, 0);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 8be583d..cb210ba 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,6 +30,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_set_line_buffering(void);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 39df333..5a97d8d 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
+/* Win32 doesn't support line-buffering and requires size = 2 */
+static inline void os_set_line_buffering(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index c22d16f..c3641d6 100644
--- a/vl.c
+++ b/vl.c
@@ -3214,10 +3214,7 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
-#ifndef _WIN32
-/* Win32 doesn't support line-buffering and requires size = 2 */
-setvbuf(stdout, NULL, _IOLBF, 0);
-#endif
+os_set_line_buffering();
 
 if (init_timer_alarm()  0) {
 fprintf(stderr, could not initialize alarm timer\n);
-- 
1.6.5.2




[Qemu-devel] [PATCH 17/17] Move set_proc_name() to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move handling to change process name to POSIX specific files
plus add a better error message to cover the case where the
feature isn't supported.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |   24 
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   19 +--
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 9bae8fe..d89020d 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -37,6 +37,10 @@
 #include net/slirp.h
 #include qemu-options.h
 
+#ifdef CONFIG_LINUX
+#include sys/prctl.h
+#endif
+
 static struct passwd *user_pwd;
 static const char *chroot_dir;
 static int daemonize;
@@ -139,6 +143,26 @@ char *os_find_datadir(const char *argv0)
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
 
+void os_set_proc_name(const char *s)
+{
+#if defined(PR_SET_NAME)
+char name[16];
+if (!s)
+return;
+name[sizeof(name) - 1] = 0;
+strncpy(name, s, sizeof(name));
+/* Could rewrite argv[0] too, but that's a bit more complicated.
+   This simple way is enough for `top'. */
+if (prctl(PR_SET_NAME, name)) {
+perror(unable to change process name);
+exit(1);
+}
+#else
+fprintf(stderr, Change of process name not supported by your OS\n);
+exit(1);
+#endif 
+}
+
 /*
  * Parse OS specific command line options.
  * return 0 if option handled, -1 otherwise
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index cb210ba..ed5c058 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,6 +31,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_set_line_buffering(void);
+void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 5a97d8d..6323f7f 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -47,5 +47,6 @@ static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 /* Win32 doesn't support line-buffering and requires size = 2 */
 static inline void os_set_line_buffering(void) {}
+static inline void os_set_proc_name(const char *dummy) {}
 
 #endif
diff --git a/vl.c b/vl.c
index c3641d6..ce501e2 100644
--- a/vl.c
+++ b/vl.c
@@ -59,7 +59,6 @@
 #ifdef __linux__
 #include pty.h
 #include malloc.h
-#include sys/prctl.h
 
 #include linux/ppdev.h
 #include linux/parport.h
@@ -284,22 +283,6 @@ static int default_driver_check(QemuOpts *opts, void 
*opaque)
 }
 
 /***/
-
-static void set_proc_name(const char *s)
-{
-#if defined(__linux__)  defined(PR_SET_NAME)
-char name[16];
-if (!s)
-return;
-name[sizeof(name) - 1] = 0;
-strncpy(name, s, sizeof(name));
-/* Could rewrite argv[0] too, but that's a bit more complicated.
-   This simple way is enough for `top'. */
-prctl(PR_SET_NAME, name);
-#endif 
-}
- 
-/***/
 /* real time host monotonic timer */
 
 /* compute with 96 bit intermediate result: (a*b)/c */
@@ -2988,7 +2971,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
p += 8;
-   set_proc_name(p);
+   os_set_proc_name(p);
 }  
 }  
 break;
-- 
1.6.5.2




[Qemu-devel] [PATCH 08/17] Move main signal handler setup to os specificfiles.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move main signal handler setup to os specific files.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |   27 +++
 qemu-os-posix.h |2 ++
 qemu-os-win32.h |3 +++
 vl.c|   33 +
 4 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 948f662..01dbec2 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -26,6 +26,8 @@
 #include unistd.h
 #include fcntl.h
 #include signal.h
+#include sys/types.h
+#include sys/wait.h
 
 /* Needed early for CONFIG_BSD etc. */
 #include config-host.h
@@ -39,3 +41,28 @@ void os_setup_early_signal_handling(void)
 act.sa_handler = SIG_IGN;
 sigaction(SIGPIPE, act, NULL);
 }
+
+static void termsig_handler(int signal)
+{
+qemu_system_shutdown_request();
+}
+
+static void sigchld_handler(int signal)
+{
+waitpid(-1, NULL, WNOHANG);
+}
+
+void os_setup_signal_handling(void)
+{
+struct sigaction act;
+
+memset(act, 0, sizeof(act));
+act.sa_handler = termsig_handler;
+sigaction(SIGINT,  act, NULL);
+sigaction(SIGHUP,  act, NULL);
+sigaction(SIGTERM, act, NULL);
+
+act.sa_handler = sigchld_handler;
+act.sa_flags = SA_NOCLDSTOP;
+sigaction(SIGCHLD, act, NULL);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 96d1036..ff5adb1 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,4 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_setup_signal_handling(void);
+
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 4d1cac8..e7e2ee3 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -41,4 +41,7 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, 
void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
 void os_host_main_loop_wait(int *timeout);
+
+static inline void os_setup_signal_handling(void) {}
+
 #endif
diff --git a/vl.c b/vl.c
index 372f931..fc5e8d8 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,35 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifndef _WIN32
-
-static void termsig_handler(int signal)
-{
-qemu_system_shutdown_request();
-}
-
-static void sigchld_handler(int signal)
-{
-waitpid(-1, NULL, WNOHANG);
-}
-
-static void sighandler_setup(void)
-{
-struct sigaction act;
-
-memset(act, 0, sizeof(act));
-act.sa_handler = termsig_handler;
-sigaction(SIGINT,  act, NULL);
-sigaction(SIGHUP,  act, NULL);
-sigaction(SIGTERM, act, NULL);
-
-act.sa_handler = sigchld_handler;
-act.sa_flags = SA_NOCLDSTOP;
-sigaction(SIGCHLD, act, NULL);
-}
-
-#endif
-
 #ifdef _WIN32
 /* Look for support files in the same directory as the executable.  */
 static char *find_datadir(const char *argv0)
@@ -3556,10 +3527,8 @@ int main(int argc, char **argv, char **envp)
 
 cpu_synchronize_all_post_init();
 
-#ifndef _WIN32
 /* must be after terminal init, SDL library changes signal handlers */
-sighandler_setup();
-#endif
+os_setup_signal_handling();
 
 set_numa_modes();
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move daemonize handling from vl.c to OS specific files. Provide dummy
stubs for Win32.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |  102 
 os-win32.c  |5 +++
 qemu-os-posix.h |2 +
 qemu-os-win32.h |2 +
 sysemu.h|1 +
 vl.c|  106 ++-
 6 files changed, 115 insertions(+), 103 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 6417d16..1672e06 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -39,6 +39,8 @@
 
 static struct passwd *user_pwd;
 static const char *chroot_dir;
+static int daemonize;
+static int fds[2];
 
 void os_setup_early_signal_handling(void)
 {
@@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg)
 case QEMU_OPTION_chroot:
 chroot_dir = optarg;
 break;
+case QEMU_OPTION_daemonize:
+daemonize = 1;
+break;
 }
 return;
 }
@@ -196,3 +201,100 @@ void os_change_root(void)
 }
 
 }
+
+void os_daemonize(void)
+{
+if (daemonize) {
+   pid_t pid;
+
+   if (pipe(fds) == -1)
+   exit(1);
+
+   pid = fork();
+   if (pid  0) {
+   uint8_t status;
+   ssize_t len;
+
+   close(fds[1]);
+
+   again:
+len = read(fds[0], status, 1);
+if (len == -1  (errno == EINTR))
+goto again;
+
+if (len != 1)
+exit(1);
+else if (status == 1) {
+fprintf(stderr, Could not acquire pidfile: %s\n, 
strerror(errno));
+exit(1);
+} else
+exit(0);
+   } else if (pid  0)
+exit(1);
+
+   close(fds[0]);
+   qemu_set_cloexec(fds[1]);
+
+   setsid();
+
+   pid = fork();
+   if (pid  0)
+   exit(0);
+   else if (pid  0)
+   exit(1);
+
+   umask(027);
+
+signal(SIGTSTP, SIG_IGN);
+signal(SIGTTOU, SIG_IGN);
+signal(SIGTTIN, SIG_IGN);
+}
+}
+
+void os_setup_post(void)
+{
+int fd = 0;
+
+if (daemonize) {
+   uint8_t status = 0;
+   ssize_t len;
+
+again1:
+   len = write(fds[1], status, 1);
+   if (len == -1  (errno == EINTR))
+   goto again1;
+
+   if (len != 1)
+   exit(1);
+
+if (chdir(/)) {
+perror(not able to chdir to /);
+exit(1);
+}
+   TFR(fd = qemu_open(/dev/null, O_RDWR));
+   if (fd == -1)
+   exit(1);
+}
+
+os_change_root();
+os_change_process_uid();
+
+if (daemonize) {
+dup2(fd, 0);
+dup2(fd, 1);
+dup2(fd, 2);
+
+close(fd);
+}
+}
+
+void os_pidfile_error(void)
+{
+if (daemonize) {
+uint8_t status = 1;
+if (write(fds[1], status, 1) != 1) {
+perror(daemonize. Writing to pipe\n);
+}
+} else
+fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno));
+}
diff --git a/os-win32.c b/os-win32.c
index aefc535..d98fd77 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -214,3 +214,8 @@ void os_parse_cmd_args(int index, const char *optarg)
 {
 return;
 }
+
+void os_pidfile_error(void)
+{
+fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno));
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 91c7b68..9b07660 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -33,5 +33,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
 void os_change_root(void);
+void os_daemonize(void);
+void os_setup_post(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index e2a97d2..c4aa84a 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {}
 static inline void os_change_process_uid(void) {}
 static inline void os_change_root(void) {}
+static inline void os_daemonize(void) {}
+static inline void os_setup_post(void) {}
 
 #endif
diff --git a/sysemu.h b/sysemu.h
index 2162b1d..346cccd 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -83,6 +83,7 @@ void do_info_slirp(Monitor *mon);
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(const char *argv0);
 void os_parse_cmd_args(int index, const char *optarg);
+void os_pidfile_error(void);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index fc0e23d..c22d16f 100644
--- a/vl.c
+++ b/vl.c
@@ -216,9 +216,6 @@ int no_shutdown = 0;
 int cursor_hide = 1;
 int graphic_rotate = 0;
 uint8_t irq0override = 1;
-#ifndef _WIN32
-int daemonize = 0;
-#endif
 const char *watchdog;
 const char *option_rom[MAX_OPTION_ROMS];
 int nb_option_roms;
@@ -2301,15 +2298,9 @@ int main(int argc, char **argv, char **envp)
 const char *loadvm = NULL;
 QEMUMachine *machine;
 const char *cpu_model;
-#ifndef _WIN32
-int fds

[Qemu-devel] [PATCH 01/17] vl.c: Remove double include of netinet/in.h for Solaris

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

vl.c: netinet/in.h is already included once above for in the generic
POSIX section.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 vl.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 417554f..7c4298a 100644
--- a/vl.c
+++ b/vl.c
@@ -70,7 +70,6 @@
 #include sys/ethernet.h
 #include sys/sockio.h
 #include netinet/arp.h
-#include netinet/in.h
 #include netinet/in_systm.h
 #include netinet/ip.h
 #include netinet/ip_icmp.h // must come after ip.h
-- 
1.6.5.2




[Qemu-devel] [PATCH 11/17] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Introduce OS specific cmdline argument handling by calling
os_parse_cmd_args() at the end of switch() statement. Move option
enum to qemu-options.h and have it included from os-posix.c and
os-win32.c in addition to vl.c.

In addition move SMB argument to os-posix.c

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 Makefile.objs  |2 ++
 os-posix.c |   19 +++
 os-win32.c |   10 ++
 qemu-options.h |   41 +
 sysemu.h   |1 +
 vl.c   |   19 +++
 6 files changed, 76 insertions(+), 16 deletions(-)
 create mode 100644 qemu-options.h

diff --git a/Makefile.objs b/Makefile.objs
index 124afe7..27595df 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -259,6 +259,8 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
 vl.o: qemu-options.def
+os-posix.o: qemu-options.def
+os-win32.o: qemu-options.def
 
 qemu-options.def: $(SRC_PATH)/qemu-options.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h  $  $@,  GEN   
$(TARGET_DIR)$@)
diff --git a/os-posix.c b/os-posix.c
index 621ad06..0deddf3 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -33,6 +33,8 @@
 /* Needed early for CONFIG_BSD etc. */
 #include config-host.h
 #include sysemu.h
+#include net/slirp.h
+#include qemu-options.h
 
 void os_setup_early_signal_handling(void)
 {
@@ -130,3 +132,20 @@ char *os_find_datadir(const char *argv0)
 }
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+void os_parse_cmd_args(int index, const char *optarg)
+{
+switch (index) {
+#ifdef CONFIG_SLIRP
+case QEMU_OPTION_smb:
+if (net_slirp_smb(optarg)  0)
+exit(1);
+break;
+#endif
+}
+return;
+}
diff --git a/os-win32.c b/os-win32.c
index 1758538..aefc535 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -31,6 +31,7 @@
 #include sys/time.h
 #include config-host.h
 #include sysemu.h
+#include qemu-options.h
 
 /***/
 /* Polling handling */
@@ -204,3 +205,12 @@ char *os_find_datadir(const char *argv0)
 }
 return NULL;
 }
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+void os_parse_cmd_args(int index, const char *optarg)
+{
+return;
+}
diff --git a/qemu-options.h b/qemu-options.h
new file mode 100644
index 000..c96f994
--- /dev/null
+++ b/qemu-options.h
@@ -0,0 +1,41 @@
+/*
+ * qemu-options.h
+ *
+ * Defines needed for command line argument processing.
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen jes.soren...@redhat.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _QEMU_OPTIONS_H_
+#define _QEMU_OPTIONS_H_
+
+enum {
+#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
+opt_enum,
+#define DEFHEADING(text)
+#include qemu-options.def
+#undef DEF
+#undef DEFHEADING
+#undef GEN_DOCS
+};
+
+#endif
diff --git a/sysemu.h b/sysemu.h
index 72f3734..2162b1d 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -82,6 +82,7 @@ void do_info_slirp(Monitor *mon);
 /* OS specific functions */
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(const char *argv0);
+void os_parse_cmd_args(int index, const char *optarg);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index 8cd0f8f..7c48024 100644
--- a/vl.c
+++ b/vl.c
@@ -148,6 +148,7 @@ int main(int argc, char **argv)
 #include qemu-option.h
 #include qemu-config.h
 #include qemu-objects.h
+#include qemu-options.h
 #ifdef CONFIG_LINUX
 #include fsdev/qemu-fsdev.h
 #endif
@@ -1899,16 +1900,6 @@ static void help(int exitcode)
 
 #define HAS_ARG 0x0001
 
-enum {
-#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
-opt_enum,
-#define DEFHEADING(text)
-#include qemu-options.def
-#undef DEF
-#undef DEFHEADING

[Qemu-devel] [PATCH 02/17] Create qemu-os-win32.h and move WIN32 specific declarations there

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Create qemu-os-win32.h for WIN32 specific declarations. Move polling
handling declaration into this file from sysemu.h

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 qemu-os-win32.h |   43 +++
 sysemu.h|   17 +
 2 files changed, 44 insertions(+), 16 deletions(-)
 create mode 100644 qemu-os-win32.h

diff --git a/qemu-os-win32.h b/qemu-os-win32.h
new file mode 100644
index 000..be108ad
--- /dev/null
+++ b/qemu-os-win32.h
@@ -0,0 +1,43 @@
+/*
+ * win32 specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen jes.soren...@redhat.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_WIN32_H
+#define QEMU_OS_WIN32_H
+
+/* Polling handling */
+
+/* return TRUE if no sleep should be done afterwards */
+typedef int PollingFunc(void *opaque);
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque);
+void qemu_del_polling_cb(PollingFunc *func, void *opaque);
+
+/* Wait objects handling */
+typedef void WaitObjectFunc(void *opaque);
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+
+#endif
diff --git a/sysemu.h b/sysemu.h
index 879446a..13fc9a9 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -9,6 +9,7 @@
 
 #ifdef _WIN32
 #include windows.h
+#include qemu-os-win32.h
 #endif
 
 /* vl.c */
@@ -71,22 +72,6 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
 void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
 int qemu_loadvm_state(QEMUFile *f);
 
-#ifdef _WIN32
-/* Polling handling */
-
-/* return TRUE if no sleep should be done afterwards */
-typedef int PollingFunc(void *opaque);
-
-int qemu_add_polling_cb(PollingFunc *func, void *opaque);
-void qemu_del_polling_cb(PollingFunc *func, void *opaque);
-
-/* Wait objects handling */
-typedef void WaitObjectFunc(void *opaque);
-
-int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
-void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
-#endif
-
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 06/17] Move win32 early signal handling setup to os_setup_signal_handling()

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move win32 early signal handling setup to os_setup_signal_handling()

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-win32.c  |   29 +
 qemu-os-posix.h |2 --
 sysemu.h|2 ++
 vl.c|   30 --
 4 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/os-win32.c b/os-win32.c
index 1f7e28b..dfa90bc 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -152,3 +152,32 @@ void os_host_main_loop_wait(int *timeout)
 
 *timeout = 0;
 }
+
+static BOOL WINAPI qemu_ctrl_handler(DWORD type)
+{
+exit(STATUS_CONTROL_C_EXIT);
+return TRUE;
+}
+
+void os_setup_signal_handling(void)
+{
+/* Note: cpu_interrupt() is currently not SMP safe, so we force
+   QEMU to run on a single CPU */
+HANDLE h;
+DWORD mask, smask;
+int i;
+
+SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
+
+h = GetCurrentProcess();
+if (GetProcessAffinityMask(h, mask, smask)) {
+for(i = 0; i  32; i++) {
+if (mask  (1  i))
+break;
+}
+if (i != 32) {
+mask = 1  i;
+SetProcessAffinityMask(h, mask);
+}
+}
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ff5adb1..96d1036 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,6 +30,4 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
-void os_setup_signal_handling(void);
-
 #endif
diff --git a/sysemu.h b/sysemu.h
index 5e4feae..e3643ad 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,6 +79,8 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
+void os_setup_signal_handling(void);
+
 typedef enum DisplayType
 {
 DT_DEFAULT,
diff --git a/vl.c b/vl.c
index 7a46fee..f43456a 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,14 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifdef _WIN32
-static BOOL WINAPI qemu_ctrl_handler(DWORD type)
-{
-exit(STATUS_CONTROL_C_EXIT);
-return TRUE;
-}
-#endif
-
 #ifndef _WIN32
 
 static void termsig_handler(int signal)
@@ -2459,29 +2451,7 @@ int main(int argc, char **argv, char **envp)
 qemu_cache_utils_init(envp);
 
 QLIST_INIT (vm_change_state_head);
-#ifndef _WIN32
 os_setup_signal_handling();
-#else
-SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
-/* Note: cpu_interrupt() is currently not SMP safe, so we force
-   QEMU to run on a single CPU */
-{
-HANDLE h;
-DWORD mask, smask;
-int i;
-h = GetCurrentProcess();
-if (GetProcessAffinityMask(h, mask, smask)) {
-for(i = 0; i  32; i++) {
-if (mask  (1  i))
-break;
-}
-if (i != 32) {
-mask = 1  i;
-SetProcessAffinityMask(h, mask);
-}
-}
-}
-#endif
 
 module_call_init(MODULE_INIT_MACHINE);
 machine = find_default_machine();
-- 
1.6.5.2




[Qemu-devel] [PATCH 15/17] Make os_change_process_uid and os_change_root os-posix.c local

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

os_change_process_uid() and os_change_root() are now only called
from os-posix.c, so no need to keep win32 stubs for them.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |8 
 qemu-os-posix.h |2 --
 qemu-os-win32.h |2 --
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 1672e06..3a96c91 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -169,7 +169,7 @@ void os_parse_cmd_args(int index, const char *optarg)
 return;
 }
 
-void os_change_process_uid(void)
+static void change_process_uid(void)
 {
 if (user_pwd) {
 if (setgid(user_pwd-pw_gid)  0) {
@@ -187,7 +187,7 @@ void os_change_process_uid(void)
 }
 }
 
-void os_change_root(void)
+static void change_root(void)
 {
 if (chroot_dir) {
 if (chroot(chroot_dir)  0) {
@@ -276,8 +276,8 @@ void os_setup_post(void)
exit(1);
 }
 
-os_change_root();
-os_change_process_uid();
+change_root();
+change_process_uid();
 
 if (daemonize) {
 dup2(fd, 0);
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 9b07660..8be583d 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,8 +31,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_setup_signal_handling(void);
-void os_change_process_uid(void);
-void os_change_root(void);
 void os_daemonize(void);
 void os_setup_post(void);
 
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index c4aa84a..39df333 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -43,8 +43,6 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque);
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
-static inline void os_change_process_uid(void) {}
-static inline void os_change_root(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move host_main_loop_wait() to OS specific files. Create
qemu-os-posix.h and provide empty inline for the POSIX case.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-win32.c  |   43 +++
 qemu-os-posix.h |   33 +
 qemu-os-win32.h |1 +
 sysemu.h|4 
 vl.c|   52 +---
 5 files changed, 82 insertions(+), 51 deletions(-)
 create mode 100644 qemu-os-posix.h

diff --git a/os-win32.c b/os-win32.c
index 5a464cc..1f7e28b 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -109,3 +109,46 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque)
 if (found)
 w-num--;
 }
+
+void os_host_main_loop_wait(int *timeout)
+{
+int ret, ret2, i;
+PollingEntry *pe;
+
+/* XXX: need to suppress polling by better using win32 events */
+ret = 0;
+for(pe = first_polling_entry; pe != NULL; pe = pe-next) {
+ret |= pe-func(pe-opaque);
+}
+if (ret == 0) {
+int err;
+WaitObjects *w = wait_objects;
+
+ret = WaitForMultipleObjects(w-num, w-events, FALSE, *timeout);
+if (WAIT_OBJECT_0 + 0 = ret  ret = WAIT_OBJECT_0 + w-num - 1) {
+if (w-func[ret - WAIT_OBJECT_0])
+w-func[ret - WAIT_OBJECT_0](w-opaque[ret - WAIT_OBJECT_0]);
+
+/* Check for additional signaled events */
+for(i = (ret - WAIT_OBJECT_0 + 1); i  w-num; i++) {
+
+/* Check if event is signaled */
+ret2 = WaitForSingleObject(w-events[i], 0);
+if(ret2 == WAIT_OBJECT_0) {
+if (w-func[i])
+w-func[i](w-opaque[i]);
+} else if (ret2 == WAIT_TIMEOUT) {
+} else {
+err = GetLastError();
+fprintf(stderr, WaitForSingleObject error %d %d\n, i, 
err);
+}
+}
+} else if (ret == WAIT_TIMEOUT) {
+} else {
+err = GetLastError();
+fprintf(stderr, WaitForMultipleObjects error %d %d\n, ret, err);
+}
+}
+
+*timeout = 0;
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
new file mode 100644
index 000..96d1036
--- /dev/null
+++ b/qemu-os-posix.h
@@ -0,0 +1,33 @@
+/*
+ * posix specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen jes.soren...@redhat.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_POSIX_H
+#define QEMU_OS_POSIX_H
+
+static inline void os_host_main_loop_wait(int *timeout)
+{
+}
+
+#endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index be108ad..4d1cac8 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -40,4 +40,5 @@ typedef void WaitObjectFunc(void *opaque);
 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
+void os_host_main_loop_wait(int *timeout);
 #endif
diff --git a/sysemu.h b/sysemu.h
index 13fc9a9..5e4feae 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -12,6 +12,10 @@
 #include qemu-os-win32.h
 #endif
 
+#ifdef CONFIG_POSIX
+#include qemu-os-posix.h
+#endif
+
 /* vl.c */
 extern const char *bios_name;
 
diff --git a/vl.c b/vl.c
index afbb26c..c655582 100644
--- a/vl.c
+++ b/vl.c
@@ -1722,56 +1722,6 @@ void qemu_system_powerdown_request(void)
 qemu_notify_event();
 }
 
-#ifdef _WIN32
-static void host_main_loop_wait(int *timeout)
-{
-int ret, ret2, i;
-PollingEntry *pe;
-
-
-/* XXX: need to suppress polling by better using win32 events */
-ret = 0;
-for(pe = first_polling_entry; pe != NULL; pe = pe-next) {
-ret |= pe-func(pe-opaque);
-}
-if (ret == 0) {
-int err;
-WaitObjects *w = wait_objects;
-
-ret

[Qemu-devel] [PATCH 01/16] vl.c: Remove double include of netinet/in.h for Solaris

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

vl.c: netinet/in.h is already included once above for the generic
non win32 code.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 vl.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 417554f..7c4298a 100644
--- a/vl.c
+++ b/vl.c
@@ -70,7 +70,6 @@
 #include sys/ethernet.h
 #include sys/sockio.h
 #include netinet/arp.h
-#include netinet/in.h
 #include netinet/in_systm.h
 #include netinet/ip.h
 #include netinet/ip_icmp.h // must come after ip.h
-- 
1.6.5.2




[Qemu-devel] [PATCH 03/16] Introduce os-win32.c and move polling functions from vl.c

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

This introduces os-win32.c. It is meant to carry win32 specific
functions thata are not relevant for all of QEMU as well as win32
versions of various pieces like signal handling etc.

Move win32 polling handler helper functions from vl.c to os-win32.c

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 Makefile.objs |1 +
 os-win32.c|  111 +
 vl.c  |   80 -
 3 files changed, 112 insertions(+), 80 deletions(-)
 create mode 100644 os-win32.c

diff --git a/Makefile.objs b/Makefile.objs
index 9796dcb..58fdb03 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -144,6 +144,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
 hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-$(CONFIG_WIN32) += os-win32.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-win32.c b/os-win32.c
new file mode 100644
index 000..5a464cc
--- /dev/null
+++ b/os-win32.c
@@ -0,0 +1,111 @@
+/*
+ * os-win32.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include windows.h
+#include unistd.h
+#include fcntl.h
+#include signal.h
+#include time.h
+#include errno.h
+#include sys/time.h
+#include config-host.h
+#include sysemu.h
+
+/***/
+/* Polling handling */
+
+typedef struct PollingEntry {
+PollingFunc *func;
+void *opaque;
+struct PollingEntry *next;
+} PollingEntry;
+
+static PollingEntry *first_polling_entry;
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque)
+{
+PollingEntry **ppe, *pe;
+pe = qemu_mallocz(sizeof(PollingEntry));
+pe-func = func;
+pe-opaque = opaque;
+for(ppe = first_polling_entry; *ppe != NULL; ppe = (*ppe)-next);
+*ppe = pe;
+return 0;
+}
+
+void qemu_del_polling_cb(PollingFunc *func, void *opaque)
+{
+PollingEntry **ppe, *pe;
+for(ppe = first_polling_entry; *ppe != NULL; ppe = (*ppe)-next) {
+pe = *ppe;
+if (pe-func == func  pe-opaque == opaque) {
+*ppe = pe-next;
+qemu_free(pe);
+break;
+}
+}
+}
+
+/***/
+/* Wait objects support */
+typedef struct WaitObjects {
+int num;
+HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
+WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
+void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
+} WaitObjects;
+
+static WaitObjects wait_objects = {0};
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+WaitObjects *w = wait_objects;
+
+if (w-num = MAXIMUM_WAIT_OBJECTS)
+return -1;
+w-events[w-num] = handle;
+w-func[w-num] = func;
+w-opaque[w-num] = opaque;
+w-num++;
+return 0;
+}
+
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+int i, found;
+WaitObjects *w = wait_objects;
+
+found = 0;
+for (i = 0; i  w-num; i++) {
+if (w-events[i] == handle)
+found = 1;
+if (found) {
+w-events[i] = w-events[i + 1];
+w-func[i] = w-func[i + 1];
+w-opaque[i] = w-opaque[i + 1];
+}
+}
+if (found)
+w-num--;
+}
diff --git a/vl.c b/vl.c
index 7c4298a..afbb26c 100644
--- a/vl.c
+++ b/vl.c
@@ -1497,86 +1497,6 @@ int qemu_set_fd_handler(int fd,
 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
 }
 
-#ifdef _WIN32
-/***/
-/* Polling handling */
-
-typedef struct PollingEntry {
-PollingFunc *func;
-void *opaque;
-struct PollingEntry *next;
-} PollingEntry;
-
-static PollingEntry *first_polling_entry;
-
-int

[Qemu-devel] [PATCH 00/16] clean up vl.c code

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Hi,

I have been working on a set of patches to clean up the vl.c code, by
separating out OS specific code into OS specific files. Basically it
introduces two header files: qemu-os-win32.h and qemu-os-posix.h as
well as os-win32.c and os-posix.c.

I have tried to be as careful as I can to not break non Linux support,
but as I only have a Linux build environment handy, I would appreciate
it if people with other OSes could check that I didn't break anything
for them. In particular I would like to know if win32 still builds.

Thanks,
Jes


Jes Sorensen (16):
  vl.c: Remove double include of netinet/in.h for Solaris
  Create qemu-os-win32.h and move WIN32 specific declarations there
  Introduce os-win32.c and move polling functions from vl.c
  vl.c: Move host_main_loop_wait() to OS specific files.
  Introduce os-posix.c and create os_setup_signal_handling()
  Move win32 early signal handling setup to os_setup_signal_handling()
  Rename os_setup_signal_handling() to os_setup_early_signal_handling()
  Move main signal handler setup to os specificfiles.
  Move find_datadir to OS specific files.
  Introduce OS specific cmdline argument handling and move SMB arg to
os-posix.c
  Move runas handling from vl.c to OS specific files.
  Move chroot handling to OS specific files.
  Move daemonize handling to OS specific files
  Make os_change_process_uid and os_change_root os-posix.c local
  Move line-buffering setup to OS specific files.
  Move set_proc_name() to OS specific files.

 Makefile.objs   |2 +
 os-posix.c  |  344 ++
 os-win32.c  |  233 ++
 qemu-os-posix.h |   39 +
 qemu-os-win32.h |   52 ++
 sysemu.h|   35 ++--
 vl.c|  490 ++-
 7 files changed, 703 insertions(+), 492 deletions(-)
 create mode 100644 os-posix.c
 create mode 100644 os-win32.c
 create mode 100644 qemu-os-posix.h
 create mode 100644 qemu-os-win32.h




[Qemu-devel] [PATCH 16/16] Move set_proc_name() to OS specific files.

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move handling to change process name to POSIX specific files
plus add a better error message to cover the case where the
feature isn't supported.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |   24 
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   19 +--
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 7530276..03105f7 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -36,6 +36,10 @@
 #include sysemu.h
 #include net/slirp.h
 
+#ifdef CONFIG_LINUX
+#include sys/prctl.h
+#endif
+
 static struct passwd *user_pwd;
 static const char *chroot_dir;
 static int daemonize;
@@ -138,6 +142,26 @@ char *os_find_datadir(const char *argv0)
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
 
+void os_set_proc_name(const char *s)
+{
+#if defined(PR_SET_NAME)
+char name[16];
+if (!s)
+return;
+name[sizeof(name) - 1] = 0;
+strncpy(name, s, sizeof(name));
+/* Could rewrite argv[0] too, but that's a bit more complicated.
+   This simple way is enough for `top'. */
+if (prctl(PR_SET_NAME, name)) {
+perror(unable to change process name);
+exit(1);
+}
+#else
+fprintf(stderr, Change of process name not supported by your OS\n);
+exit(1);
+#endif 
+}
+
 /*
  * Duplicate definition from vl.c to avoid messing up the entire build
  */
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index cb210ba..ed5c058 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,6 +31,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_set_line_buffering(void);
+void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 1709cf6..bb7126b 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -47,5 +47,6 @@ static inline void os_daemonize(void) {};
 static inline void os_setup_post(void) {};
 /* Win32 doesn't support line-buffering and requires size = 2 */
 static inline void os_set_line_buffering(void) {};
+static inline void os_set_proc_name(const char *dummy) {};
 
 #endif
diff --git a/vl.c b/vl.c
index 3dbc789..b77dce8 100644
--- a/vl.c
+++ b/vl.c
@@ -59,7 +59,6 @@
 #ifdef __linux__
 #include pty.h
 #include malloc.h
-#include sys/prctl.h
 
 #include linux/ppdev.h
 #include linux/parport.h
@@ -283,22 +282,6 @@ static int default_driver_check(QemuOpts *opts, void 
*opaque)
 }
 
 /***/
-
-static void set_proc_name(const char *s)
-{
-#if defined(__linux__)  defined(PR_SET_NAME)
-char name[16];
-if (!s)
-return;
-name[sizeof(name) - 1] = 0;
-strncpy(name, s, sizeof(name));
-/* Could rewrite argv[0] too, but that's a bit more complicated.
-   This simple way is enough for `top'. */
-prctl(PR_SET_NAME, name);
-#endif 
-}
- 
-/***/
 /* real time host monotonic timer */
 
 /* compute with 96 bit intermediate result: (a*b)/c */
@@ -2990,7 +2973,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
p += 8;
-   set_proc_name(p);
+   os_set_proc_name(p);
 }  
 }  
 break;
-- 
1.6.5.2




[Qemu-devel] [PATCH 02/16] Create qemu-os-win32.h and move WIN32 specific declarations there

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Create qemu-os-win32.h for WIN32 specific declarations. Move polling
handling declaration into this file from sysemu.h

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 qemu-os-win32.h |   43 +++
 sysemu.h|   17 +
 2 files changed, 44 insertions(+), 16 deletions(-)
 create mode 100644 qemu-os-win32.h

diff --git a/qemu-os-win32.h b/qemu-os-win32.h
new file mode 100644
index 000..be108ad
--- /dev/null
+++ b/qemu-os-win32.h
@@ -0,0 +1,43 @@
+/*
+ * win32 specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen jes.soren...@redhat.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_WIN32_H
+#define QEMU_OS_WIN32_H
+
+/* Polling handling */
+
+/* return TRUE if no sleep should be done afterwards */
+typedef int PollingFunc(void *opaque);
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque);
+void qemu_del_polling_cb(PollingFunc *func, void *opaque);
+
+/* Wait objects handling */
+typedef void WaitObjectFunc(void *opaque);
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+
+#endif
diff --git a/sysemu.h b/sysemu.h
index 879446a..13fc9a9 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -9,6 +9,7 @@
 
 #ifdef _WIN32
 #include windows.h
+#include qemu-os-win32.h
 #endif
 
 /* vl.c */
@@ -71,22 +72,6 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
 void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
 int qemu_loadvm_state(QEMUFile *f);
 
-#ifdef _WIN32
-/* Polling handling */
-
-/* return TRUE if no sleep should be done afterwards */
-typedef int PollingFunc(void *opaque);
-
-int qemu_add_polling_cb(PollingFunc *func, void *opaque);
-void qemu_del_polling_cb(PollingFunc *func, void *opaque);
-
-/* Wait objects handling */
-typedef void WaitObjectFunc(void *opaque);
-
-int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
-void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
-#endif
-
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 05/16] Introduce os-posix.c and create os_setup_signal_handling()

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Introcuce os-posix.c and move posix specific signal handling
there.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 Makefile.objs |1 +
 os-posix.c|   41 +
 sysemu.h  |3 +++
 vl.c  |8 +---
 4 files changed, 46 insertions(+), 7 deletions(-)
 create mode 100644 os-posix.c

diff --git a/Makefile.objs b/Makefile.objs
index 58fdb03..2d94677 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -145,6 +145,7 @@ hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
 hw-obj-$(CONFIG_WIN32) += os-win32.o
+hw-obj-$(CONFIG_POSIX) += os-posix.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-posix.c b/os-posix.c
new file mode 100644
index 000..914a4d1
--- /dev/null
+++ b/os-posix.c
@@ -0,0 +1,41 @@
+/*
+ * os-posix.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include unistd.h
+#include fcntl.h
+#include signal.h
+
+/* Needed early for CONFIG_BSD etc. */
+#include config-host.h
+#include sysemu.h
+
+void os_setup_signal_handling(void)
+{
+struct sigaction act;
+sigfillset(act.sa_mask);
+act.sa_flags = 0;
+act.sa_handler = SIG_IGN;
+sigaction(SIGPIPE, act, NULL);
+}
diff --git a/sysemu.h b/sysemu.h
index 5e4feae..fc438c5 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,6 +79,9 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
+/* OS specific functions */
+void os_setup_signal_handling(void);
+
 typedef enum DisplayType
 {
 DT_DEFAULT,
diff --git a/vl.c b/vl.c
index c655582..7a46fee 100644
--- a/vl.c
+++ b/vl.c
@@ -2460,13 +2460,7 @@ int main(int argc, char **argv, char **envp)
 
 QLIST_INIT (vm_change_state_head);
 #ifndef _WIN32
-{
-struct sigaction act;
-sigfillset(act.sa_mask);
-act.sa_flags = 0;
-act.sa_handler = SIG_IGN;
-sigaction(SIGPIPE, act, NULL);
-}
+os_setup_signal_handling();
 #else
 SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
 /* Note: cpu_interrupt() is currently not SMP safe, so we force
-- 
1.6.5.2




[Qemu-devel] [PATCH 04/16] vl.c: Move host_main_loop_wait() to OS specific files.

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move host_main_loop_wait() to OS specific files. Create
qemu-os-posix.h and provide empty inline for the POSIX case.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-win32.c  |   43 +++
 qemu-os-posix.h |   33 +
 qemu-os-win32.h |1 +
 sysemu.h|4 
 vl.c|   52 +---
 5 files changed, 82 insertions(+), 51 deletions(-)
 create mode 100644 qemu-os-posix.h

diff --git a/os-win32.c b/os-win32.c
index 5a464cc..1f7e28b 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -109,3 +109,46 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque)
 if (found)
 w-num--;
 }
+
+void os_host_main_loop_wait(int *timeout)
+{
+int ret, ret2, i;
+PollingEntry *pe;
+
+/* XXX: need to suppress polling by better using win32 events */
+ret = 0;
+for(pe = first_polling_entry; pe != NULL; pe = pe-next) {
+ret |= pe-func(pe-opaque);
+}
+if (ret == 0) {
+int err;
+WaitObjects *w = wait_objects;
+
+ret = WaitForMultipleObjects(w-num, w-events, FALSE, *timeout);
+if (WAIT_OBJECT_0 + 0 = ret  ret = WAIT_OBJECT_0 + w-num - 1) {
+if (w-func[ret - WAIT_OBJECT_0])
+w-func[ret - WAIT_OBJECT_0](w-opaque[ret - WAIT_OBJECT_0]);
+
+/* Check for additional signaled events */
+for(i = (ret - WAIT_OBJECT_0 + 1); i  w-num; i++) {
+
+/* Check if event is signaled */
+ret2 = WaitForSingleObject(w-events[i], 0);
+if(ret2 == WAIT_OBJECT_0) {
+if (w-func[i])
+w-func[i](w-opaque[i]);
+} else if (ret2 == WAIT_TIMEOUT) {
+} else {
+err = GetLastError();
+fprintf(stderr, WaitForSingleObject error %d %d\n, i, 
err);
+}
+}
+} else if (ret == WAIT_TIMEOUT) {
+} else {
+err = GetLastError();
+fprintf(stderr, WaitForMultipleObjects error %d %d\n, ret, err);
+}
+}
+
+*timeout = 0;
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
new file mode 100644
index 000..96d1036
--- /dev/null
+++ b/qemu-os-posix.h
@@ -0,0 +1,33 @@
+/*
+ * posix specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen jes.soren...@redhat.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_POSIX_H
+#define QEMU_OS_POSIX_H
+
+static inline void os_host_main_loop_wait(int *timeout)
+{
+}
+
+#endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index be108ad..4d1cac8 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -40,4 +40,5 @@ typedef void WaitObjectFunc(void *opaque);
 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
+void os_host_main_loop_wait(int *timeout);
 #endif
diff --git a/sysemu.h b/sysemu.h
index 13fc9a9..5e4feae 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -12,6 +12,10 @@
 #include qemu-os-win32.h
 #endif
 
+#ifdef CONFIG_POSIX
+#include qemu-os-posix.h
+#endif
+
 /* vl.c */
 extern const char *bios_name;
 
diff --git a/vl.c b/vl.c
index afbb26c..c655582 100644
--- a/vl.c
+++ b/vl.c
@@ -1722,56 +1722,6 @@ void qemu_system_powerdown_request(void)
 qemu_notify_event();
 }
 
-#ifdef _WIN32
-static void host_main_loop_wait(int *timeout)
-{
-int ret, ret2, i;
-PollingEntry *pe;
-
-
-/* XXX: need to suppress polling by better using win32 events */
-ret = 0;
-for(pe = first_polling_entry; pe != NULL; pe = pe-next) {
-ret |= pe-func(pe-opaque);
-}
-if (ret == 0) {
-int err;
-WaitObjects *w = wait_objects;
-
-ret

[Qemu-devel] [PATCH 06/16] Move win32 early signal handling setup to os_setup_signal_handling()

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move win32 early signal handling setup to os_setup_signal_handling()

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-win32.c |   29 +
 vl.c   |   30 --
 2 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/os-win32.c b/os-win32.c
index 1f7e28b..dfa90bc 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -152,3 +152,32 @@ void os_host_main_loop_wait(int *timeout)
 
 *timeout = 0;
 }
+
+static BOOL WINAPI qemu_ctrl_handler(DWORD type)
+{
+exit(STATUS_CONTROL_C_EXIT);
+return TRUE;
+}
+
+void os_setup_signal_handling(void)
+{
+/* Note: cpu_interrupt() is currently not SMP safe, so we force
+   QEMU to run on a single CPU */
+HANDLE h;
+DWORD mask, smask;
+int i;
+
+SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
+
+h = GetCurrentProcess();
+if (GetProcessAffinityMask(h, mask, smask)) {
+for(i = 0; i  32; i++) {
+if (mask  (1  i))
+break;
+}
+if (i != 32) {
+mask = 1  i;
+SetProcessAffinityMask(h, mask);
+}
+}
+}
diff --git a/vl.c b/vl.c
index 7a46fee..f43456a 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,14 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifdef _WIN32
-static BOOL WINAPI qemu_ctrl_handler(DWORD type)
-{
-exit(STATUS_CONTROL_C_EXIT);
-return TRUE;
-}
-#endif
-
 #ifndef _WIN32
 
 static void termsig_handler(int signal)
@@ -2459,29 +2451,7 @@ int main(int argc, char **argv, char **envp)
 qemu_cache_utils_init(envp);
 
 QLIST_INIT (vm_change_state_head);
-#ifndef _WIN32
 os_setup_signal_handling();
-#else
-SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
-/* Note: cpu_interrupt() is currently not SMP safe, so we force
-   QEMU to run on a single CPU */
-{
-HANDLE h;
-DWORD mask, smask;
-int i;
-h = GetCurrentProcess();
-if (GetProcessAffinityMask(h, mask, smask)) {
-for(i = 0; i  32; i++) {
-if (mask  (1  i))
-break;
-}
-if (i != 32) {
-mask = 1  i;
-SetProcessAffinityMask(h, mask);
-}
-}
-}
-#endif
 
 module_call_init(MODULE_INIT_MACHINE);
 machine = find_default_machine();
-- 
1.6.5.2




[Qemu-devel] [PATCH 07/16] Rename os_setup_signal_handling() to os_setup_early_signal_handling()

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Rename os_setup_signal_handling() to os_setup_early_signal_handling()

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c |2 +-
 os-win32.c |2 +-
 sysemu.h   |2 +-
 vl.c   |2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 914a4d1..948f662 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -31,7 +31,7 @@
 #include config-host.h
 #include sysemu.h
 
-void os_setup_signal_handling(void)
+void os_setup_early_signal_handling(void)
 {
 struct sigaction act;
 sigfillset(act.sa_mask);
diff --git a/os-win32.c b/os-win32.c
index dfa90bc..a936f7a 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -159,7 +159,7 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 return TRUE;
 }
 
-void os_setup_signal_handling(void)
+void os_setup_early_signal_handling(void)
 {
 /* Note: cpu_interrupt() is currently not SMP safe, so we force
QEMU to run on a single CPU */
diff --git a/sysemu.h b/sysemu.h
index fc438c5..79ffd9f 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -80,7 +80,7 @@ int qemu_loadvm_state(QEMUFile *f);
 void do_info_slirp(Monitor *mon);
 
 /* OS specific functions */
-void os_setup_signal_handling(void);
+void os_setup_early_signal_handling(void);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index f43456a..372f931 100644
--- a/vl.c
+++ b/vl.c
@@ -2451,7 +2451,7 @@ int main(int argc, char **argv, char **envp)
 qemu_cache_utils_init(envp);
 
 QLIST_INIT (vm_change_state_head);
-os_setup_signal_handling();
+os_setup_early_signal_handling();
 
 module_call_init(MODULE_INIT_MACHINE);
 machine = find_default_machine();
-- 
1.6.5.2




[Qemu-devel] [PATCH 09/16] Move find_datadir to OS specific files.

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

This moves the win32 and POSIX versions of find_datadir() to OS
specific files, and removes some #ifdef clutter from vl.c

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c |   64 +++
 os-win32.c |   23 ++
 sysemu.h   |1 +
 vl.c   |   98 ++-
 4 files changed, 92 insertions(+), 94 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 01dbec2..621ad06 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,7 @@
 #include signal.h
 #include sys/types.h
 #include sys/wait.h
+#include libgen.h
 
 /* Needed early for CONFIG_BSD etc. */
 #include config-host.h
@@ -66,3 +67,66 @@ void os_setup_signal_handling(void)
 act.sa_flags = SA_NOCLDSTOP;
 sigaction(SIGCHLD, act, NULL);
 }
+
+/* Find a likely location for support files using the location of the binary.
+   For installed binaries this will be $bindir/../share/qemu.  When
+   running from the build tree this will be $bindir/../pc-bios.  */
+#define SHARE_SUFFIX /share/qemu
+#define BUILD_SUFFIX /pc-bios
+char *os_find_datadir(const char *argv0)
+{
+char *dir;
+char *p = NULL;
+char *res;
+char buf[PATH_MAX];
+size_t max_len;
+
+#if defined(__linux__)
+{
+int len;
+len = readlink(/proc/self/exe, buf, sizeof(buf) - 1);
+if (len  0) {
+buf[len] = 0;
+p = buf;
+}
+}
+#elif defined(__FreeBSD__)
+{
+static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+size_t len = sizeof(buf) - 1;
+
+*buf = '\0';
+if (!sysctl(mib, sizeof(mib)/sizeof(*mib), buf, len, NULL, 0) 
+*buf) {
+buf[sizeof(buf) - 1] = '\0';
+p = buf;
+}
+}
+#endif
+/* If we don't have any way of figuring out the actual executable
+   location then try argv[0].  */
+if (!p) {
+p = realpath(argv0, buf);
+if (!p) {
+return NULL;
+}
+}
+dir = dirname(p);
+dir = dirname(dir);
+
+max_len = strlen(dir) +
+MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
+res = qemu_mallocz(max_len);
+snprintf(res, max_len, %s%s, dir, SHARE_SUFFIX);
+if (access(res, R_OK)) {
+snprintf(res, max_len, %s%s, dir, BUILD_SUFFIX);
+if (access(res, R_OK)) {
+qemu_free(res);
+res = NULL;
+}
+}
+
+return res;
+}
+#undef SHARE_SUFFIX
+#undef BUILD_SUFFIX
diff --git a/os-win32.c b/os-win32.c
index a936f7a..1758538 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -181,3 +181,26 @@ void os_setup_early_signal_handling(void)
 }
 }
 }
+
+/* Look for support files in the same directory as the executable.  */
+char *os_find_datadir(const char *argv0)
+{
+char *p;
+char buf[MAX_PATH];
+DWORD len;
+
+len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
+if (len == 0) {
+return NULL;
+}
+
+buf[len] = 0;
+p = buf + len - 1;
+while (p != buf  *p != '\\')
+p--;
+*p = 0;
+if (access(buf, R_OK) == 0) {
+return qemu_strdup(buf);
+}
+return NULL;
+}
diff --git a/sysemu.h b/sysemu.h
index 79ffd9f..72f3734 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -81,6 +81,7 @@ void do_info_slirp(Monitor *mon);
 
 /* OS specific functions */
 void os_setup_early_signal_handling(void);
+char *os_find_datadir(const char *argv0);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index fc5e8d8..7f22733 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,95 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifdef _WIN32
-/* Look for support files in the same directory as the executable.  */
-static char *find_datadir(const char *argv0)
-{
-char *p;
-char buf[MAX_PATH];
-DWORD len;
-
-len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
-if (len == 0) {
-return NULL;
-}
-
-buf[len] = 0;
-p = buf + len - 1;
-while (p != buf  *p != '\\')
-p--;
-*p = 0;
-if (access(buf, R_OK) == 0) {
-return qemu_strdup(buf);
-}
-return NULL;
-}
-#else /* !_WIN32 */
-
-/* Find a likely location for support files using the location of the binary.
-   For installed binaries this will be $bindir/../share/qemu.  When
-   running from the build tree this will be $bindir/../pc-bios.  */
-#define SHARE_SUFFIX /share/qemu
-#define BUILD_SUFFIX /pc-bios
-static char *find_datadir(const char *argv0)
-{
-char *dir;
-char *p = NULL;
-char *res;
-char buf[PATH_MAX];
-size_t max_len;
-
-#if defined(__linux__)
-{
-int len;
-len = readlink(/proc/self/exe, buf, sizeof(buf) - 1);
-if (len  0) {
-buf[len] = 0;
-p = buf;
-}
-}
-#elif defined(__FreeBSD__)
-{
-static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
-size_t len = sizeof(buf

[Qemu-devel] [PATCH 14/16] Make os_change_process_uid and os_change_root os-posix.c local

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

os_change_process_uid() and os_change_root() are now only called
from os-posix.c, so no need to keep win32 stubs for them.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |8 
 qemu-os-posix.h |2 --
 qemu-os-win32.h |2 --
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 8a9d102..7ac6f07 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -184,7 +184,7 @@ int os_parse_cmd_args(const QEMUOption *popt, const char 
*optarg)
 return ret;
 }
 
-void os_change_process_uid(void)
+static void change_process_uid(void)
 {
 if (user_pwd) {
 if (setgid(user_pwd-pw_gid)  0) {
@@ -202,7 +202,7 @@ void os_change_process_uid(void)
 }
 }
 
-void os_change_root(void)
+static void change_root(void)
 {
 if (chroot_dir) {
 if (chroot(chroot_dir)  0) {
@@ -291,8 +291,8 @@ void os_setup_post(void)
exit(1);
 }
 
-os_change_root();
-os_change_process_uid();
+change_root();
+change_process_uid();
 
 if (daemonize) {
 dup2(fd, 0);
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 9b07660..8be583d 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,8 +31,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_setup_signal_handling(void);
-void os_change_process_uid(void);
-void os_change_root(void);
 void os_daemonize(void);
 void os_setup_post(void);
 
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index ccb9691..facd3d6 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -43,8 +43,6 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque);
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {};
-static inline void os_change_process_uid(void) {};
-static inline void os_change_root(void) {};
 static inline void os_daemonize(void) {};
 static inline void os_setup_post(void) {};
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 11/16] Move runas handling from vl.c to OS specific files.

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move code to handle runas, ie. change of user id of QEMU process
to OS specific files and provide dummy stub for Win32.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |   28 
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   29 +
 4 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 66f2bf5..f8a092e 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,7 @@
 #include signal.h
 #include sys/types.h
 #include sys/wait.h
+#include pwd.h
 #include libgen.h
 
 /* Needed early for CONFIG_BSD etc. */
@@ -35,6 +36,8 @@
 #include sysemu.h
 #include net/slirp.h
 
+static struct passwd *user_pwd;
+
 void os_setup_early_signal_handling(void)
 {
 struct sigaction act;
@@ -159,8 +162,33 @@ int os_parse_cmd_args(const QEMUOption *popt, const char 
*optarg)
 exit(1);
 break;
 #endif
+case QEMU_OPTION_runas:
+user_pwd = getpwnam(optarg);
+if (!user_pwd) {
+fprintf(stderr, User \%s\ doesn't exist\n, optarg);
+exit(1);
+}
+break;
 default:
 ret = -1;
 }
 return ret;
 }
+
+void os_change_process_uid(void)
+{
+if (user_pwd) {
+if (setgid(user_pwd-pw_gid)  0) {
+fprintf(stderr, Failed to setgid(%d)\n, user_pwd-pw_gid);
+exit(1);
+}
+if (setuid(user_pwd-pw_uid)  0) {
+fprintf(stderr, Failed to setuid(%d)\n, user_pwd-pw_uid);
+exit(1);
+}
+if (setuid(0) != -1) {
+fprintf(stderr, Dropping privileges failed\n);
+exit(1);
+}
+}
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ff5adb1..6d8cf79 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,5 +31,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_setup_signal_handling(void);
+void os_change_process_uid(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 4343c6d..9df0eda 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -43,5 +43,6 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque);
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {};
+static inline void os_change_process_uid(void) {};
 
 #endif
diff --git a/vl.c b/vl.c
index 838e109..d42be8d 100644
--- a/vl.c
+++ b/vl.c
@@ -34,7 +34,6 @@
 
 #ifndef _WIN32
 #include libgen.h
-#include pwd.h
 #include sys/times.h
 #include sys/wait.h
 #include termios.h
@@ -2312,9 +2311,7 @@ int main(int argc, char **argv, char **envp)
 const char *incoming = NULL;
 #ifndef _WIN32
 int fd = 0;
-struct passwd *pwd = NULL;
 const char *chroot_dir = NULL;
-const char *run_as = NULL;
 #endif
 int show_vnc_port = 0;
 int defconfig = 1;
@@ -3062,9 +3059,6 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_chroot:
 chroot_dir = optarg;
 break;
-case QEMU_OPTION_runas:
-run_as = optarg;
-break;
 #endif
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
@@ -3554,14 +3548,6 @@ int main(int argc, char **argv, char **envp)
exit(1);
 }
 
-if (run_as) {
-pwd = getpwnam(run_as);
-if (!pwd) {
-fprintf(stderr, User \%s\ doesn't exist\n, run_as);
-exit(1);
-}
-}
-
 if (chroot_dir) {
 if (chroot(chroot_dir)  0) {
 fprintf(stderr, chroot failed\n);
@@ -3573,20 +3559,7 @@ int main(int argc, char **argv, char **envp)
 }
 }
 
-if (run_as) {
-if (setgid(pwd-pw_gid)  0) {
-fprintf(stderr, Failed to setgid(%d)\n, pwd-pw_gid);
-exit(1);
-}
-if (setuid(pwd-pw_uid)  0) {
-fprintf(stderr, Failed to setuid(%d)\n, pwd-pw_uid);
-exit(1);
-}
-if (setuid(0) != -1) {
-fprintf(stderr, Dropping privileges failed\n);
-exit(1);
-}
-}
+os_change_process_uid();
 
 if (daemonize) {
 dup2(fd, 0);
-- 
1.6.5.2




[Qemu-devel] [PATCH 12/16] Move chroot handling to OS specific files.

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move chroot handling to OS specific files.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |   19 +++
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   18 +-
 4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index f8a092e..a91e1f6 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -37,6 +37,7 @@
 #include net/slirp.h
 
 static struct passwd *user_pwd;
+static const char *chroot_dir;
 
 void os_setup_early_signal_handling(void)
 {
@@ -169,6 +170,9 @@ int os_parse_cmd_args(const QEMUOption *popt, const char 
*optarg)
 exit(1);
 }
 break;
+case QEMU_OPTION_chroot:
+chroot_dir = optarg;
+break;
 default:
 ret = -1;
 }
@@ -192,3 +196,18 @@ void os_change_process_uid(void)
 }
 }
 }
+
+void os_change_root(void)
+{
+if (chroot_dir) {
+if (chroot(chroot_dir)  0) {
+fprintf(stderr, chroot failed\n);
+exit(1);
+}
+if (chdir(/)) {
+perror(not able to chdir to /);
+exit(1);
+}
+}
+
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 6d8cf79..91c7b68 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -32,5 +32,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
+void os_change_root(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 9df0eda..245b188 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -44,5 +44,6 @@ void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {};
 static inline void os_change_process_uid(void) {};
+static inline void os_change_root(void) {};
 
 #endif
diff --git a/vl.c b/vl.c
index d42be8d..7173684 100644
--- a/vl.c
+++ b/vl.c
@@ -2311,7 +2311,6 @@ int main(int argc, char **argv, char **envp)
 const char *incoming = NULL;
 #ifndef _WIN32
 int fd = 0;
-const char *chroot_dir = NULL;
 #endif
 int show_vnc_port = 0;
 int defconfig = 1;
@@ -3055,11 +3054,6 @@ int main(int argc, char **argv, char **envp)
 default_cdrom = 0;
 default_sdcard = 0;
 break;
-#ifndef _WIN32
-case QEMU_OPTION_chroot:
-chroot_dir = optarg;
-break;
-#endif
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
 printf(Option %s not supported for this target\n, 
popt-name);
@@ -3548,17 +3542,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
 }
 
-if (chroot_dir) {
-if (chroot(chroot_dir)  0) {
-fprintf(stderr, chroot failed\n);
-exit(1);
-}
-if (chdir(/)) {
-perror(not able to chdir to /);
-exit(1);
-}
-}
-
+os_change_root();
 os_change_process_uid();
 
 if (daemonize) {
-- 
1.6.5.2




[Qemu-devel] [PATCH 10/16] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Introduce OS specific cmdline argument handling by calling
os_parse_cmd_args() at the end of switch() statement.

In addition move SMB argument to os-posix.c

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c |   34 ++
 os-win32.c |   22 ++
 sysemu.h   |9 +
 vl.c   |   15 ++-
 4 files changed, 67 insertions(+), 13 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 621ad06..66f2bf5 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -33,6 +33,7 @@
 /* Needed early for CONFIG_BSD etc. */
 #include config-host.h
 #include sysemu.h
+#include net/slirp.h
 
 void os_setup_early_signal_handling(void)
 {
@@ -130,3 +131,36 @@ char *os_find_datadir(const char *argv0)
 }
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
+
+/*
+ * Duplicate definition from vl.c to avoid messing up the entire build
+ */
+enum {
+#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
+opt_enum,
+#define DEFHEADING(text)
+#include qemu-options.h
+#undef DEF
+#undef DEFHEADING
+#undef GEN_DOCS
+};
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+int os_parse_cmd_args(const QEMUOption *popt, const char *optarg)
+{
+int ret = 0;
+switch (popt-index) {
+#ifdef CONFIG_SLIRP
+case QEMU_OPTION_smb:
+if (net_slirp_smb(optarg)  0)
+exit(1);
+break;
+#endif
+default:
+ret = -1;
+}
+return ret;
+}
diff --git a/os-win32.c b/os-win32.c
index 1758538..a311a90 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -204,3 +204,25 @@ char *os_find_datadir(const char *argv0)
 }
 return NULL;
 }
+
+/*
+ * Duplicate definition from vl.c to avoid messing up the entire build
+ */
+enum {
+#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
+opt_enum,
+#define DEFHEADING(text)
+#include qemu-options.h
+#undef DEF
+#undef DEFHEADING
+#undef GEN_DOCS
+};
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+int os_parse_cmd_args(const QEMUOption *popt, const char *optarg)
+{
+return -1;
+}
diff --git a/sysemu.h b/sysemu.h
index 72f3734..08ec323 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,9 +79,18 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
+/* This is needed for vl.c and the OS specific files */
+typedef struct QEMUOption {
+const char *name;
+int flags;
+int index;
+uint32_t arch_mask;
+} QEMUOption;
+
 /* OS specific functions */
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(const char *argv0);
+int os_parse_cmd_args(const QEMUOption *popt, const char *optarg);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index 7f22733..838e109 100644
--- a/vl.c
+++ b/vl.c
@@ -1909,13 +1909,6 @@ enum {
 #undef GEN_DOCS
 };
 
-typedef struct QEMUOption {
-const char *name;
-int flags;
-int index;
-uint32_t arch_mask;
-} QEMUOption;
-
 static const QEMUOption qemu_options[] = {
 { h, 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
@@ -2624,12 +2617,6 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_bootp:
 legacy_bootp_filename = optarg;
 break;
-#ifndef _WIN32
-case QEMU_OPTION_smb:
-if (net_slirp_smb(optarg)  0)
-exit(1);
-break;
-#endif
 case QEMU_OPTION_redir:
 if (net_slirp_redir(optarg)  0)
 exit(1);
@@ -3126,6 +3113,8 @@ int main(int argc, char **argv, char **envp)
 fclose(fp);
 break;
 }
+default:
+os_parse_cmd_args(popt, optarg);
 }
 }
 }
-- 
1.6.5.2




[Qemu-devel] [PATCH 13/16] Move daemonize handling to OS specific files

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move daemonize handling from vl.c to OS specific files. Provide dummy
stubs for Win32.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |  102 
 os-win32.c  |5 +++
 qemu-os-posix.h |2 +
 qemu-os-win32.h |2 +
 sysemu.h|1 +
 vl.c|  106 ++-
 6 files changed, 115 insertions(+), 103 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index a91e1f6..8a9d102 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -38,6 +38,8 @@
 
 static struct passwd *user_pwd;
 static const char *chroot_dir;
+static int daemonize;
+static int fds[2];
 
 void os_setup_early_signal_handling(void)
 {
@@ -173,6 +175,9 @@ int os_parse_cmd_args(const QEMUOption *popt, const char 
*optarg)
 case QEMU_OPTION_chroot:
 chroot_dir = optarg;
 break;
+case QEMU_OPTION_daemonize:
+daemonize = 1;
+break;
 default:
 ret = -1;
 }
@@ -211,3 +216,100 @@ void os_change_root(void)
 }
 
 }
+
+void os_daemonize(void)
+{
+if (daemonize) {
+   pid_t pid;
+
+   if (pipe(fds) == -1)
+   exit(1);
+
+   pid = fork();
+   if (pid  0) {
+   uint8_t status;
+   ssize_t len;
+
+   close(fds[1]);
+
+   again:
+len = read(fds[0], status, 1);
+if (len == -1  (errno == EINTR))
+goto again;
+
+if (len != 1)
+exit(1);
+else if (status == 1) {
+fprintf(stderr, Could not acquire pidfile: %s\n, 
strerror(errno));
+exit(1);
+} else
+exit(0);
+   } else if (pid  0)
+exit(1);
+
+   close(fds[0]);
+   qemu_set_cloexec(fds[1]);
+
+   setsid();
+
+   pid = fork();
+   if (pid  0)
+   exit(0);
+   else if (pid  0)
+   exit(1);
+
+   umask(027);
+
+signal(SIGTSTP, SIG_IGN);
+signal(SIGTTOU, SIG_IGN);
+signal(SIGTTIN, SIG_IGN);
+}
+}
+
+void os_setup_post(void)
+{
+int fd = 0;
+
+if (daemonize) {
+   uint8_t status = 0;
+   ssize_t len;
+
+again1:
+   len = write(fds[1], status, 1);
+   if (len == -1  (errno == EINTR))
+   goto again1;
+
+   if (len != 1)
+   exit(1);
+
+if (chdir(/)) {
+perror(not able to chdir to /);
+exit(1);
+}
+   TFR(fd = qemu_open(/dev/null, O_RDWR));
+   if (fd == -1)
+   exit(1);
+}
+
+os_change_root();
+os_change_process_uid();
+
+if (daemonize) {
+dup2(fd, 0);
+dup2(fd, 1);
+dup2(fd, 2);
+
+close(fd);
+}
+}
+
+void os_pidfile_error(void)
+{
+if (daemonize) {
+uint8_t status = 1;
+if (write(fds[1], status, 1) != 1) {
+perror(daemonize. Writing to pipe\n);
+}
+} else
+fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno));
+}
diff --git a/os-win32.c b/os-win32.c
index a311a90..86ff327 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -226,3 +226,8 @@ int os_parse_cmd_args(const QEMUOption *popt, const char 
*optarg)
 {
 return -1;
 }
+
+void os_pidfile_error(void)
+{
+fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno));
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 91c7b68..9b07660 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -33,5 +33,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
 void os_change_root(void);
+void os_daemonize(void);
+void os_setup_post(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 245b188..ccb9691 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {};
 static inline void os_change_process_uid(void) {};
 static inline void os_change_root(void) {};
+static inline void os_daemonize(void) {};
+static inline void os_setup_post(void) {};
 
 #endif
diff --git a/sysemu.h b/sysemu.h
index 08ec323..aa44a20 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -91,6 +91,7 @@ typedef struct QEMUOption {
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(const char *argv0);
 int os_parse_cmd_args(const QEMUOption *popt, const char *optarg);
+void os_pidfile_error(void);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index 7173684..bb8abbf 100644
--- a/vl.c
+++ b/vl.c
@@ -215,9 +215,6 @@ int no_shutdown = 0;
 int cursor_hide = 1;
 int graphic_rotate = 0;
 uint8_t irq0override = 1;
-#ifndef _WIN32
-int daemonize = 0;
-#endif
 const char *watchdog;
 const char *option_rom[MAX_OPTION_ROMS];
 int nb_option_roms;
@@ -2303,15 +2300,9 @@ int main(int argc, char **argv, char **envp)
 const char *loadvm = NULL;
 QEMUMachine *machine

[Qemu-devel] [PATCH 15/16] Move line-buffering setup to OS specific files.

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Move line-buffering setup to OS specific files.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c  |5 +
 qemu-os-posix.h |1 +
 qemu-os-win32.h |2 ++
 vl.c|5 +
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 7ac6f07..7530276 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -313,3 +313,8 @@ void os_pidfile_error(void)
 } else
 fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno));
 }
+
+void os_set_line_buffering(void)
+{
+setvbuf(stdout, NULL, _IOLBF, 0);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 8be583d..cb210ba 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,6 +30,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_set_line_buffering(void);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index facd3d6..1709cf6 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {};
 static inline void os_daemonize(void) {};
 static inline void os_setup_post(void) {};
+/* Win32 doesn't support line-buffering and requires size = 2 */
+static inline void os_set_line_buffering(void) {};
 
 #endif
diff --git a/vl.c b/vl.c
index bb8abbf..3dbc789 100644
--- a/vl.c
+++ b/vl.c
@@ -3216,10 +3216,7 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
-#ifndef _WIN32
-/* Win32 doesn't support line-buffering and requires size = 2 */
-setvbuf(stdout, NULL, _IOLBF, 0);
-#endif
+os_set_line_buffering();
 
 if (init_timer_alarm()  0) {
 fprintf(stderr, could not initialize alarm timer\n);
-- 
1.6.5.2




[Qemu-devel] Re: [SeaBIOS] SMBIOS strings

2010-06-02 Thread Jes Sorensen
On 06/01/10 22:26, Sebastian Herbszt wrote:
 Jes Sorensen wrote:
 Handle 0x0401, DMI type 4, 32 bytes
 Processor Information
 -   Socket Designation: CPU 1
 +   Socket Designation: CPU01
 
 smbios.c got
 snprintf((char*)start, 6, CPU%2x, cpu_number);
 
 It should print CPU 1 instead of CPU01 because the
 padding should be done with spaces not zeros. Maybe
 bvprintf() doesn't handle it correctly?

I looked at the man page for snprintf() and it isn't clear to me that it
is required to space pad when printing hex numbers.

Having looked at the other pieces, I think this is probably the only one
we might want to change. It should be pretty easy to just do something like:

if (cpu_number  0x10)
snprintf(CPU %x, cpu_number);
else
snprintf(CPU%2x, cpu_number);

Esthetically I think this would be prettier, but question is whether
it's something to worry about or not.

Cheers,
Jes




Re: [Qemu-devel] Re: [PATCHv2-RFC 0/2] virtio: put last seen used index into ring itself

2010-06-02 Thread Jes Sorensen
On 05/31/10 09:46, Rusty Russell wrote:
 On Thu, 27 May 2010 05:20:35 am Michael S. Tsirkin wrote:
 Here's a rewrite of the original patch with a new layout.
 I haven't tested it yet so no idea how this performs, but
 I think this addresses the cache bounce issue raised by Avi.
 Posting for early flames/comments.
 
 Sorry, not without some evidence that it'll actually reduce cacheline
 bouncing.  I *think* it will, but it's not obvious: the host may keep
 looking at avail_idx as we're updating last_seen.  Or does qemu always
 look at both together anyway?
 
 Can someone convince me this is a win?
 Rusty.

Hi Rusty,

I ran some tests using the vring index publish patch with virtio_blk.
The numbers are based on running IOZone on a ramdisk passed to the guest
via virtio. While I didn't see any throughput improvements, I saw a
20-30% reduction in the VMExit count for the full run. This was measured
grabbing the VMExit count prior and after the run and calculating the
difference.

I have the numbers in a PDF, so I will email it to you in private as I
don't like sending PDFs to the mailing list. However if anybody else
wants the numbers feel free to ping me off list and I'll forward them.

Cheers,
Jes




Re: [Qemu-devel] Re: [SeaBIOS] SMBIOS strings

2010-06-01 Thread Jes Sorensen
On 06/01/10 07:34, Markus Armbruster wrote:
 Sebastian Herbszt herb...@gmx.de writes:
 
 Gleb Natapov wrote:
 I don't care much as long as we will not have CPU :. It looks like 
 something
 that can change after BIOS upgrade, so it is hard to believe Windows
 will stop working because of this change.

 Maybe it could trigger the Windows activation process?
 
 Isn't that testable?

The problem there is that the number of possible combinations to test is
endless. I think older versions of windows are far more prone to such
problems than newer ones.

Cheers,
Jes



Re: [Qemu-devel] Re: [PATCH 00/14] Block-related fixes and cleanups

2010-06-01 Thread Jes Sorensen
On 05/31/10 11:19, Gerd Hoffmann wrote:
 On 05/28/10 15:38, Markus Armbruster wrote:
 I'm working on cleanly separating block device host and guest parts.
 I'd like to route all this work through Kevin's block tree.  This is
 just preliminaries.

 Markus Armbruster (14):
blockdev: Belatedly remove MAX_DRIVES
blockdev: Belatedly remove driveopts
usb: Remove unused usb_device_add() parameter is_hotplug
ide: Remove useless IDEDeviceInfo members unit, drive
ide: Remove redundant IDEState member conf
ide: Split ide_init1() off ide_init2()
ide: Change ide_init_drive() to require valid dinfo argument
ide: Split non-qdev code off ide_init2()
qdev: New qdev_prop_set_string()
qdev: Don't leak string property value on hot unplug
ide: Turn drive serial into a qdev property ide-drive.serial
ide: Fix info qtree for ide-drive.ver
scsi: Turn drive serial into a qdev property scsi-disk.serial
scsi: Fix info qtree for scsi-disk.ver
 
 Nice cleanups.
 
 Acked-by: Gerd Hoffmann kra...@redhat.com

Was just about to post the same message :)

Cheers,
Jes




[Qemu-devel] [Bug 588127] Re: qemu fails to recognize host features SSE4.1, SSE4.2

2010-06-01 Thread Jes Sorensen
Tried this on with two versions of QEMU (0.12.50 out of CVS) and qemu-
kvm 0.12.1:

QEMU emulator version 0.12.50, Copyright (c) 2003-2008 Fabrice Bellard
QEMU PC emulator version 0.12.1 (qemu-kvm-devel), Copyright (c) 2003-2008 
Fabrice Bellard

model name  : Intel(R) Xeon(R) CPU   E5520  @ 2.27GHz

In both cases I am able to specify the sse4.1 and sse4.2 flags without
problems.

Are you building QEMU with strange flags, or running binaries from a
vendor somewhere?

Cheers,
Jes

-- 
qemu fails to recognize host features SSE4.1, SSE4.2
https://bugs.launchpad.net/bugs/588127
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
Tested on qemu v0.11.0 and v0.12.3:

qemu-kvm -cpu core2duo,+sse4.1,+sse4.2
CPU feature sse4.1 not found
CPU feature sse4.2 not found

egrep model name|flags /proc/cpuinfo | sort -r | uniq
model name  : Intel(R) Xeon(R) CPU   X5570  @ 2.93GHz
flags   : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat 
pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm 
constant_tsc arch_perfmon pebs bts rep_good xtopology tsc_reliable nonstop_tsc 
pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 sse4_2 
popcnt lahf_lm tpr_shadow vnmi flexpriority ept vpid





[Qemu-devel] Re: [SeaBIOS] SMBIOS strings

2010-05-31 Thread Jes Sorensen
On 05/28/10 17:44, Gleb Natapov wrote:
 On Fri, May 28, 2010 at 05:24:47PM +0200, Jes Sorensen wrote:
 I guess the Socket Designation in particular might have been done for a
 reason?

 It was part of commit cf2affa6de. And was a result of moving to
 snprintf() instead of direct string manipulation. Before that
 string was created like that:
 memcpy((char *)start, CPU   \0  \0 , 7);
((char *)start)[4] = cpu_number + '0';
 Which start to produce strange cpu numbers for cpus greater then 9. I
 doubt we want to go back to that ;)

Hi Gleb,

I see. Well I guess we could do something slightly more compatible by
printing along the lines:

printf(CPU:);
if (nr  10)
printf( );
snprintf()

Not sure if it is worth it, but it should be doable without reverting to
memcpy().

Thoughts?

Cheers,
Jes



[Qemu-devel] Re: [SeaBIOS] SMBIOS strings

2010-05-31 Thread Jes Sorensen
On 05/29/10 14:49, Sebastian Herbszt wrote:
 Jes Sorensen wrote:
 We were looking at the dmidecode output from qemu-kvm pre-seabios and
 current qemu-kvm and noticed some of the strings have changed.

 The main problem with this is that certain OSes are quite sensitive to
 system changes and avoiding to change things unnecessarily would
 probably be a good thing.
 
 Which OSes do care? Windows only?

The problem with this kind of stuff is that we don't know what is
sensitive and what doesn't care. Most of the Open Source OSes should be
fine, but still Windows is a pretty big customer in the virtualization
guest space.

 Handle 0x0401, DMI type 4, 32 bytes
 Processor Information
 -   Socket Designation: CPU 1
 +   Socket Designation: CPU01
Type: Central Processor
Family: Other
 -   Manufacturer: QEMU
 -   ID: 63 06 00 00 FD FB 8B 07
 +   Manufacturer: Bochs
 +   ID: 23 06 00 00 FD FB 8B 07
Version: Not Specified
Voltage: Unknown
External Clock: Unknown

 I guess the Socket Designation in particular might have been done for a
 reason?

 Otherwise, if there are no objections, I'll look at adding some patches
 to make it more backwards compatible.
 
 Is the different ID displayed on the same VM configuration (esp. -cpu
 option) ?
 The value is gained by calling CPUID so it should not be different.
 
 Which pre-seabios qemu-kvm bios are you comparing to?

Hmmm good point, I'll go back and dig some more on this.

Cheers,
Jes



[Qemu-devel] Re: [PATCHv2-RFC 0/2] virtio: put last seen used index into ring itself

2010-05-31 Thread Jes Sorensen
On 05/30/10 13:22, Michael S. Tsirkin wrote:
 On Fri, May 28, 2010 at 11:56:54AM +0200, Jes Sorensen wrote:
 It looks pretty good to me, however one thing I have been thinking of
 while reading through it:

 Rather than storing a pointer within the ring struct, pointing into a
 position within the same struct. How about storing a byte offset instead
 and using a cast to get to the pointer position? That would avoid the
 pointer dereference, which is less effective cache wise and harder for
 the CPU to predict.

 Not sure whether it really matters performance wise, just a thought.
 
 I think this won't work: when PUBLUSH_USED_IDX is negotiated,
 the pointer is to within the ring.

Hmmm shame, it would be a nice optimization.

Maybe it's time to introduce the v2 ring format, rather than having
adding more kludges to the existing one?

Cheers,
Jes



[Qemu-devel] Re: [PATCH] block.h: Make BDRV_SECTOR_SIZE 64 bit safe

2010-05-28 Thread Jes Sorensen
On 05/28/10 10:32, Paolo Bonzini wrote:
 On 05/27/2010 05:44 PM, Jes Sorensen wrote:
   Candidate for stable too?
 It should be safe to apply, but I didn't find any current users where
 the mask was applied in a way where it was causing problems. Not sure if
 you want the noise, or apply it as better safe than sorry?
 
 The only use in fact is this:
 
 addr = qemu_get_be64(f);
 flags = addr  ~BDRV_SECTOR_MASK;
 
 which is safe since the ~~ cancels to give back 511 again.  So
 nevermind, just asking.  If there are no bugs related to it it seems
 just as safe not to apply it.

That is correct, which is why I don't think it is necessary for the
stable release. However I want to see the fix in upstream as the macro
is likely to get used for other things in the future and it's a hidden
bug waiting to happen.

Cheers,
Jes




[Qemu-devel] Re: [PATCHv2-RFC 0/2] virtio: put last seen used index into ring itself

2010-05-28 Thread Jes Sorensen
On 05/26/10 21:50, Michael S. Tsirkin wrote:
 Here's a rewrite of the original patch with a new layout.
 I haven't tested it yet so no idea how this performs, but
 I think this addresses the cache bounce issue raised by Avi.
 Posting for early flames/comments.
 
 Generally, the Host end of the virtio ring doesn't need to see where
 Guest is up to in consuming the ring.  However, to completely understand
 what's going on from the outside, this information must be exposed.
 For example, host can reduce the number of interrupts by detecting
 that the guest is currently handling previous buffers.
 
 We add a feature bit so the guest can tell the host that it's writing
 out the current value there, if it wants to use that.
 
 This differs from original approach in that the used index
 is put after avail index (they are typically written out together).
 To avoid cache bounces on descriptor access,
 and make future extensions easier, we put the ring itself at start of
 page, and move the control after it.

Hi Michael,

It looks pretty good to me, however one thing I have been thinking of
while reading through it:

Rather than storing a pointer within the ring struct, pointing into a
position within the same struct. How about storing a byte offset instead
and using a cast to get to the pointer position? That would avoid the
pointer dereference, which is less effective cache wise and harder for
the CPU to predict.

Not sure whether it really matters performance wise, just a thought.

Cheers,
Jes



[Qemu-devel] [PATCH] vhost_net.c: Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

The format statement expects unsigned long on x86_64, but receives
unsigned long long, so gcc exits with an error.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 hw/vhost_net.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/vhost_net.c b/hw/vhost_net.c
index 26dae79..eab310c 100644
--- a/hw/vhost_net.c
+++ b/hw/vhost_net.c
@@ -100,7 +100,7 @@ struct vhost_net *vhost_net_init(VLANClientState *backend, 
int devfd)
 }
 if (~net-dev.features  net-dev.backend_features) {
 fprintf(stderr, vhost lacks feature mask % PRIu64  for backend\n,
-~net-dev.features  net-dev.backend_features);
+(uint64_t)~net-dev.features  net-dev.backend_features);
 vhost_dev_cleanup(net-dev);
 goto fail;
 }
-- 
1.6.5.2




[Qemu-devel] [PATCH] vhost_net.c: v2 Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

The format statement expects unsigned long on x86_64, but receives
unsigned long long, so gcc exits with an error.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 hw/vhost_net.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/vhost_net.c b/hw/vhost_net.c
index 26dae79..606aa0c 100644
--- a/hw/vhost_net.c
+++ b/hw/vhost_net.c
@@ -100,7 +100,7 @@ struct vhost_net *vhost_net_init(VLANClientState *backend, 
int devfd)
 }
 if (~net-dev.features  net-dev.backend_features) {
 fprintf(stderr, vhost lacks feature mask % PRIu64  for backend\n,
-~net-dev.features  net-dev.backend_features);
+(uint64_t)(~net-dev.features  net-dev.backend_features));
 vhost_dev_cleanup(net-dev);
 goto fail;
 }
-- 
1.6.5.2




[Qemu-devel] Re: [PATCH] vhost_net.c: v2 Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

2010-05-27 Thread Jes Sorensen
On 05/27/10 12:44, Michael S. Tsirkin wrote:
 On Thu, May 27, 2010 at 12:22:29PM +0200, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com

 Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

 The format statement expects unsigned long on x86_64, but receives
 unsigned long long, so gcc exits with an error.

 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 
 I think this part of 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2
 should just be reverted. We have unsigned long, it should be printed
 woith %ll. Casting to uint64_t just so we can print with PRIu64 seems silly.

That is an option too. Problem is just that unsigned long is 32 bit on
32 bit systems and Windows (even for 64 bit) so if we need more flags we
need to be careful with it.

Cheers,
Jes



[Qemu-devel] Re: [PATCH] vhost_net.c: v2 Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

2010-05-27 Thread Jes Sorensen
On 05/27/10 12:53, Michael S. Tsirkin wrote:
 On Thu, May 27, 2010 at 12:55:49PM +0200, Jes Sorensen wrote:
 On 05/27/10 12:44, Michael S. Tsirkin wrote:
 I think this part of 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2
 should just be reverted. We have unsigned long, it should be printed
 woith %ll. Casting to uint64_t just so we can print with PRIu64 seems silly.

 That is an option too. Problem is just that unsigned long is 32 bit on
 32 bit systems and Windows (even for 64 bit) so if we need more flags we
 need to be careful with it.

 Cheers,
 Jes
 
 I don't understand, sorry.
 This field is unsigned long long, not unsigned long.
 %ll will print unsigned long long
 for any standard printf, whatever its length.

Ah ok, if the field is long long, then your patch should be just fine. I
hadn't checked that was the case.

Cheers,
Jes





[Qemu-devel] Re: [PATCH] vhost_net.c: v2 Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

2010-05-27 Thread Jes Sorensen
On 05/27/10 12:54, Michael S. Tsirkin wrote:
 On Thu, May 27, 2010 at 12:55:49PM +0200, Jes Sorensen wrote:
 On 05/27/10 12:44, Michael S. Tsirkin wrote:
 On Thu, May 27, 2010 at 12:22:29PM +0200, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com

 Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

 The format statement expects unsigned long on x86_64, but receives
 unsigned long long, so gcc exits with an error.

 Signed-off-by: Jes Sorensen jes.soren...@redhat.com

 I think this part of 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2
 should just be reverted. We have unsigned long, it should be printed
 woith %ll. Casting to uint64_t just so we can print with PRIu64 seems silly.

 That is an option too.
 
 More importantly does this fix the problem for you?

Yes it works fine.

Acked-by: Jes Sorensen jes.soren...@redhat.com




[Qemu-devel] [PATCH] vhost_net.c: v2 Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Fix build failure introduced by 0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2

The format statement expects unsigned long on x86_64, but receives
unsigned long long, so gcc exits with an error.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 hw/vhost_net.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/vhost_net.c b/hw/vhost_net.c
index 26dae79..606aa0c 100644
--- a/hw/vhost_net.c
+++ b/hw/vhost_net.c
@@ -100,7 +100,7 @@ struct vhost_net *vhost_net_init(VLANClientState *backend, 
int devfd)
 }
 if (~net-dev.features  net-dev.backend_features) {
 fprintf(stderr, vhost lacks feature mask % PRIu64  for backend\n,
-~net-dev.features  net-dev.backend_features);
+(uint64_t)(~net-dev.features  net-dev.backend_features));
 vhost_dev_cleanup(net-dev);
 goto fail;
 }
-- 
1.6.5.2




[Qemu-devel] [PATCH] block.h: Make BDRV_SECTOR_SIZE 64 bit safe

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

C defaults to int, so make definition of BDRV_SECTOR_SIZE 64 bit
safe as it and BDRV_SECTOR_MASK may be used against 64 bit addresses.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 block.h |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block.h b/block.h
index 24efeb6..5e05612 100644
--- a/block.h
+++ b/block.h
@@ -38,7 +38,7 @@ typedef struct QEMUSnapshotInfo {
 #define BDRV_O_CACHE_MASK  (BDRV_O_NOCACHE | BDRV_O_CACHE_WB)
 
 #define BDRV_SECTOR_BITS   9
-#define BDRV_SECTOR_SIZE   (1  BDRV_SECTOR_BITS)
+#define BDRV_SECTOR_SIZE   (1ULL  BDRV_SECTOR_BITS)
 #define BDRV_SECTOR_MASK   ~(BDRV_SECTOR_SIZE - 1)
 
 typedef enum {
-- 
1.6.5.2




[Qemu-devel] [PATCH 0/4] Cleanups for block code

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Hi,

Reading through some of the blk code, I noticed a lot of cases where
we mix and match between hard-coded values for the block size of 512
and using BDRV_SECTOR_SIZE. Trying to clean it up a bit and change the
512 constants to BDRV_SECTOR_SIZE as it is more explaning when reading
the code.

In addition it fixes up a case in bdrv_open where we did the division,
just to multiply back to the original value for no real reason.

Cheers,
Jes


Jes Sorensen (4):
  Cleanup: bdrv_open() no need to shift total_size just to shift back.
  Cleanup: Be consistent and use BDRV_SECTOR_SIZE instead of 512
  Cleanup: raw-posix.c: Be more consistent using BDRV_SECTOR_SIZE
instead of 512
  Cleanup: virtio-blk.c: Be more consistent using BDRV_SECTOR_SIZE
instead

 block.c   |   17 +
 block/raw-posix.c |   20 +++-
 hw/virtio-blk.c   |7 ---
 3 files changed, 24 insertions(+), 20 deletions(-)




[Qemu-devel] [PATCH 2/4] Cleanup: Be consistent and use BDRV_SECTOR_SIZE instead of 512

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Clean up block.c and use BDRV_SECTOR_SIZE rather than hard coded
numbers (512) when referring to sector size throughout the code.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 block.c |   13 +++--
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index a094454..88806fb 100644
--- a/block.c
+++ b/block.c
@@ -683,7 +683,7 @@ int bdrv_commit(BlockDriverState *bs)
 int64_t i, total_sectors;
 int n, j, ro, open_flags;
 int ret = 0, rw_ret = 0;
-unsigned char sector[512];
+unsigned char sector[BDRV_SECTOR_SIZE];
 char filename[1024];
 BlockDriverState *bs_rw, *bs_ro;
 
@@ -823,7 +823,8 @@ static int bdrv_check_byte_request(BlockDriverState *bs, 
int64_t offset,
 static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
   int nb_sectors)
 {
-return bdrv_check_byte_request(bs, sector_num * 512, nb_sectors * 512);
+return bdrv_check_byte_request(bs, sector_num * BDRV_SECTOR_SIZE,
+   nb_sectors * BDRV_SECTOR_SIZE);
 }
 
 /* return  0 if error. See bdrv_write() for the return codes */
@@ -1058,7 +1059,7 @@ struct partition {
 static int guess_disk_lchs(BlockDriverState *bs,
int *pcylinders, int *pheads, int *psectors)
 {
-uint8_t buf[512];
+uint8_t buf[BDRV_SECTOR_SIZE];
 int ret, i, heads, sectors, cylinders;
 struct partition *p;
 uint32_t nr_sects;
@@ -1561,7 +1562,7 @@ static QObject* bdrv_info_stats_bs(BlockDriverState *bs)
  } },
  bs-rd_bytes, bs-wr_bytes,
  bs-rd_ops, bs-wr_ops,
- bs-wr_highest_sector * 512);
+ bs-wr_highest_sector * (long)BDRV_SECTOR_SIZE);
 dict  = qobject_to_qdict(res);
 
 if (*bs-device_name) {
@@ -2265,7 +2266,7 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t 
sector_num,
 
 async_ret = NOT_DONE;
 iov.iov_base = (void *)buf;
-iov.iov_len = nb_sectors * 512;
+iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE;
 qemu_iovec_init_external(qiov, iov, 1);
 acb = bdrv_aio_readv(bs, sector_num, qiov, nb_sectors,
 bdrv_rw_em_cb, async_ret);
@@ -2296,7 +2297,7 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t 
sector_num,
 
 async_ret = NOT_DONE;
 iov.iov_base = (void *)buf;
-iov.iov_len = nb_sectors * 512;
+iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE;
 qemu_iovec_init_external(qiov, iov, 1);
 acb = bdrv_aio_writev(bs, sector_num, qiov, nb_sectors,
 bdrv_rw_em_cb, async_ret);
-- 
1.6.5.2




[Qemu-devel] [PATCH 1/4] Cleanup: bdrv_open() no need to shift total_size just to shift back.

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

In bdrv_open() there is no need to shift total_size  9 just to
multiply it by 512 again just a few lines later, since this is the
only place the variable is used.

Mask with BDRV_SECTOR_MASK to protect against case where we are
passed a corrupted image.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 block.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index cd70730..a094454 100644
--- a/block.c
+++ b/block.c
@@ -521,7 +521,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
int flags,
 bdrv_delete(bs1);
 return ret;
 }
-total_size = bdrv_getlength(bs1)  BDRV_SECTOR_BITS;
+total_size = bdrv_getlength(bs1)  BDRV_SECTOR_MASK;
 
 if (bs1-drv  bs1-drv-protocol_name)
 is_protocol = 1;
@@ -540,7 +540,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
int flags,
 bdrv_qcow2 = bdrv_find_format(qcow2);
 options = parse_option_parameters(, bdrv_qcow2-create_options, 
NULL);
 
-set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size * 512);
+set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size);
 set_option_parameter(options, BLOCK_OPT_BACKING_FILE, 
backing_filename);
 if (drv) {
 set_option_parameter(options, BLOCK_OPT_BACKING_FMT,
-- 
1.6.5.2




[Qemu-devel] [PATCH 4/4] Cleanup: virtio-blk.c: Be more consistent using BDRV_SECTOR_SIZE instead

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Clean up virtio-blk.c to be more consistent using BDRV_SECTOR_SIZE
instead of hard coded 512 values.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 hw/virtio-blk.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 5d7f1a2..80d51c4 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -277,7 +277,7 @@ static void virtio_blk_handle_write(BlockRequest *blkreq, 
int *num_writes,
 }
 
 blkreq[*num_writes].sector = req-out-sector;
-blkreq[*num_writes].nb_sectors = req-qiov.size / 512;
+blkreq[*num_writes].nb_sectors = req-qiov.size / BDRV_SECTOR_SIZE;
 blkreq[*num_writes].qiov = req-qiov;
 blkreq[*num_writes].cb = virtio_blk_rw_complete;
 blkreq[*num_writes].opaque = req;
@@ -296,7 +296,8 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
 }
 
 acb = bdrv_aio_readv(req-dev-bs, req-out-sector, req-qiov,
- req-qiov.size / 512, virtio_blk_rw_complete, req);
+ req-qiov.size / BDRV_SECTOR_SIZE,
+ virtio_blk_rw_complete, req);
 if (!acb) {
 virtio_blk_rw_complete(req, -EIO);
 }
@@ -505,7 +506,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf 
*conf)
 s-bs = conf-dinfo-bdrv;
 s-conf = conf;
 s-rq = NULL;
-s-sector_mask = (s-conf-logical_block_size / 512) - 1;
+s-sector_mask = (s-conf-logical_block_size / BDRV_SECTOR_SIZE) - 1;
 bdrv_guess_geometry(s-bs, cylinders, heads, secs);
 
 s-vq = virtio_add_queue(s-vdev, 128, virtio_blk_handle_output);
-- 
1.6.5.2




[Qemu-devel] [PATCH 3/4] Cleanup: raw-posix.c: Be more consistent using BDRV_SECTOR_SIZE instead of 512

2010-05-27 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Clean up raw-posix.c to be more consistent using BDRV_SECTOR_SIZE
instead of hard coded 512 values.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 block/raw-posix.c |   20 +++-
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 7541ed2..3f0701b 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -392,8 +392,9 @@ static int raw_read(BlockDriverState *bs, int64_t 
sector_num,
 {
 int ret;
 
-ret = raw_pread(bs, sector_num * 512, buf, nb_sectors * 512);
-if (ret == (nb_sectors * 512))
+ret = raw_pread(bs, sector_num * BDRV_SECTOR_SIZE, buf,
+nb_sectors * BDRV_SECTOR_SIZE);
+if (ret == (nb_sectors * BDRV_SECTOR_SIZE))
 ret = 0;
 return ret;
 }
@@ -480,8 +481,9 @@ static int raw_write(BlockDriverState *bs, int64_t 
sector_num,
  const uint8_t *buf, int nb_sectors)
 {
 int ret;
-ret = raw_pwrite(bs, sector_num * 512, buf, nb_sectors * 512);
-if (ret == (nb_sectors * 512))
+ret = raw_pwrite(bs, sector_num * BDRV_SECTOR_SIZE, buf,
+ nb_sectors * BDRV_SECTOR_SIZE);
+if (ret == (nb_sectors * BDRV_SECTOR_SIZE))
 ret = 0;
 return ret;
 }
@@ -494,7 +496,7 @@ static int qiov_is_aligned(QEMUIOVector *qiov)
 int i;
 
 for (i = 0; i  qiov-niov; i++) {
-if ((uintptr_t) qiov-iov[i].iov_base % 512) {
+if ((uintptr_t) qiov-iov[i].iov_base % BDRV_SECTOR_SIZE) {
 return 0;
 }
 }
@@ -703,7 +705,7 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options)
 /* Read out options */
 while (options  options-name) {
 if (!strcmp(options-name, BLOCK_OPT_SIZE)) {
-total_size = options-value.n / 512;
+total_size = options-value.n / BDRV_SECTOR_SIZE;
 }
 options++;
 }
@@ -713,7 +715,7 @@ static int raw_create(const char *filename, 
QEMUOptionParameter *options)
 if (fd  0) {
 result = -errno;
 } else {
-if (ftruncate(fd, total_size * 512) != 0) {
+if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
 result = -errno;
 }
 if (close(fd) != 0) {
@@ -976,7 +978,7 @@ static int hdev_create(const char *filename, 
QEMUOptionParameter *options)
 /* Read out options */
 while (options  options-name) {
 if (!strcmp(options-name, size)) {
-total_size = options-value.n / 512;
+total_size = options-value.n / BDRV_SECTOR_SIZE;
 }
 options++;
 }
@@ -989,7 +991,7 @@ static int hdev_create(const char *filename, 
QEMUOptionParameter *options)
 ret = -errno;
 else if (!S_ISBLK(stat_buf.st_mode)  !S_ISCHR(stat_buf.st_mode))
 ret = -ENODEV;
-else if (lseek(fd, 0, SEEK_END)  total_size * 512)
+else if (lseek(fd, 0, SEEK_END)  total_size * BDRV_SECTOR_SIZE)
 ret = -ENOSPC;
 
 close(fd);
-- 
1.6.5.2




[Qemu-devel] Re: [PATCH] block.h: Make BDRV_SECTOR_SIZE 64 bit safe

2010-05-27 Thread Jes Sorensen
On 05/27/10 17:38, Paolo Bonzini wrote:
 On 05/27/2010 04:27 PM, Kevin Wolf wrote:
 Am 27.05.2010 15:46, schrieb jes.soren...@redhat.com:
 From: Jes Sorensenjes.soren...@redhat.com

 C defaults to int, so make definition of BDRV_SECTOR_SIZE 64 bit
 safe as it and BDRV_SECTOR_MASK may be used against 64 bit addresses.

 Signed-off-by: Jes Sorensenjes.soren...@redhat.com

 Thanks, applied to the block branch.
 
 Candidate for stable too?

It should be safe to apply, but I didn't find any current users where
the mask was applied in a way where it was causing problems. Not sure if
you want the noise, or apply it as better safe than sorry?

Cheers,
Jes



Re: [Qemu-devel] [RFC] Bug Day - June 1st, 2010

2010-05-20 Thread Jes Sorensen
On 05/19/10 02:58, Natalia Portillo wrote:
 Hi,
 
 - We'll try to migrate as many confirmable bugs from the Source Forge 
 tracker to Launchpad.
 I think that part of the bug day should also include retesting OSes that 
 appear in OS Support List as having bug and confirming if the bug is still 
 present and if it's in Launchpad or not.

This would be a great task for people who would like to contribute, but
maybe don't feel they have the experience or knowledge to hack on the
code itself.

Jes



Re: [Qemu-devel] [RFC] Bug Day - June 1st, 2010

2010-05-20 Thread Jes Sorensen
On 05/19/10 15:34, Anthony Liguori wrote:
 On 05/19/2010 12:04 AM, Aurelien Jarno wrote:
 The idea is nice, but would it be possible to hold this on a week-end,
 I personally won't be able to attend such thing on a day week.

 Or maybe holding that on two days: friday and saturday so that people
 can participate at least one of the two days, depending if they do that
 from work or from home.
 
 The work week in Israel is Sunday - Thursday.
 
 It would have to be Sunday and Monday but honestly, I think both days
 tend to be bad for this sort of thing.
 
 I'd much rather do more frequent bug days and alternate between a
 weekday and a Saturday.

If we settle for the 2nd of June, maybe the people who are unavailable
on week days, could run a pre-bug day on Sunday the 30th. Maybe some of
us would be able to stop by the channel briefly on the Sunday even if we
plan to do the big bug day on the 2nd?

Cheers,
Jes



[Qemu-devel] [PATCH] QEMU: change default disk cache behavior

2010-05-20 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

We seem to get into the discussion of what is the correct default
setting disk images in QEMU. The libvirt team is reluctant to change
specified for newly created images without the default setting
matching it, and everybody seems to agree that the current setting of
WT is the worse possible option.

'nocache' seems to be the preferred option, but it doesn't work for
all cases, like images on ramfs, NFS etc.

Therefore, here is a patch that does two things:
 - default to nocache
 - in case of failure with nocache, retry with write-back

Jes Sorensen (1):
  QEMU: Change default disk caching to nocache

 vl.c |   25 +++--
 1 files changed, 19 insertions(+), 6 deletions(-)




[Qemu-devel] [PATCH] QEMU: Change default disk caching to nocache

2010-05-20 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Change default disk image caching to nocache (O_DIRECT). However in
case it fails (ramfs, NFS etc.). fall back and retry with write-back.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 vl.c |   25 +++--
 1 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/vl.c b/vl.c
index d77b47c..f3a7d63 100644
--- a/vl.c
+++ b/vl.c
@@ -787,7 +787,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
 int max_devs;
 int index;
 int ro = 0;
-int bdrv_flags = 0;
+int bdrv_flags = BDRV_O_NOCACHE;
 int on_read_error, on_write_error;
 const char *devaddr;
 DriveInfo *dinfo;
@@ -910,11 +910,11 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
 
 if ((buf = qemu_opt_get(opts, cache)) != NULL) {
 if (!strcmp(buf, off) || !strcmp(buf, none)) {
-bdrv_flags |= BDRV_O_NOCACHE;
+/* default */
 } else if (!strcmp(buf, writeback)) {
 bdrv_flags |= BDRV_O_CACHE_WB;
 } else if (!strcmp(buf, writethrough)) {
-/* this is the default */
+bdrv_flags = ~BDRV_O_CACHE_MASK;
 } else {
fprintf(stderr, qemu: invalid cache option\n);
return NULL;
@@ -1120,15 +1120,28 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
 bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
 
 if (bdrv_open(dinfo-bdrv, file, bdrv_flags, drv)  0) {
-fprintf(stderr, qemu: could not open disk image %s: %s\n,
-file, strerror(errno));
-return NULL;
+if (bdrv_flags  BDRV_O_NOCACHE) {
+fprintf(stderr, qemu: failed to open disk image %s as 
+nocache (O_DIRECT) retrying as write-back\n, file);
+bdrv_flags = BDRV_O_NOCACHE;
+bdrv_flags |= BDRV_O_CACHE_WB;
+if (bdrv_open(dinfo-bdrv, file, bdrv_flags, drv)  0)
+goto error_open;
+} else {
+goto error_open;
+}
 }
 
 if (bdrv_key_required(dinfo-bdrv))
 autostart = 0;
 *fatal_error = 0;
 return dinfo;
+
+error_open:
+fprintf(stderr, qemu: could not open disk image %s: %s\n,
+file, strerror(errno));
+return NULL;
+
 }
 
 static int drive_init_func(QemuOpts *opts, void *opaque)
-- 
1.6.5.2




Re: [Qemu-devel] [PATCH] QEMU: change default disk cache behavior

2010-05-20 Thread Jes Sorensen
On 05/20/10 14:30, Anthony Liguori wrote:
 On 05/20/2010 04:32 AM, jes.soren...@redhat.com wrote:
 Therefore, here is a patch that does two things:
   - default to nocache
   - in case of failure with nocache, retry with write-back

 
 This sort of change requires performance data in a variety of
 circumstances to justify.
 
 And I strongly suspect that such a blanket change would be wrong but
 that a more targeted change like making cache=none default for physical
 devices would satisfy mostly everyone.

Is there any other thing than physical devices attached to the -drive
parameter?

If so, I can take a look at making it more generic when I am back from
holiday next week.

Jes




Re: [Qemu-devel] [PATCH] QEMU: change default disk cache behavior

2010-05-20 Thread Jes Sorensen
On 05/20/10 15:40, Anthony Liguori wrote:
 On 05/20/2010 08:36 AM, Jes Sorensen wrote:
 And I strongly suspect that such a blanket change would be wrong but
 that a more targeted change like making cache=none default for physical
 devices would satisfy mostly everyone.
  
 Is there any other thing than physical devices attached to the -drive
 parameter?
 
 Image files which are the overwhelming more common use-case.

For image files we certainly want it too, at least for proper ones (ie.
raw). It could be that it causes problems for qcow2.

I'll try and look at it when I am back.

Cheers,
Jes




Re: [Qemu-devel] [PATCH] virtio-blk: Avoid zeroing every request structure

2010-05-18 Thread Jes Sorensen
On 05/14/10 23:52, Stefan Hajnoczi wrote:
 The VirtIOBlockRequest structure is about 40 KB in size.  This patch
 avoids zeroing every request by only initializing fields that are read.
 The other fields are either written to or may not be used at all.
 
 Oprofile shows about 10% of CPU samples in memset called by
 virtio_blk_alloc_request().  The workload is
 dd if=/dev/vda of=/dev/null iflag=direct bs=8k running concurrently 4
 times.  This patch makes memset disappear to the bottom of the profile.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Great catch!

I ran some benchmarks using a ramdisk passed to the guest as a virtio
device and with this patch I saw improvements ranging from 5-20%. I
believe the fluctuations are due to not being able to numa bind it due
to limited memory.

However a win all the way round!

Acked-by: Jes Sorensen jes.soren...@redhat.com

Jes



[Qemu-devel] Re: [PATCH 1/1] Add -version-simple argument, printing only version number.

2010-05-17 Thread Jes Sorensen
On 05/14/10 15:21, Anthony Liguori wrote:
 On 05/13/2010 03:32 AM, jes.soren...@redhat.com wrote:
 From: Jes Sorensenjes.soren...@redhat.com

 Add -version-simple argument for QEMU, printing just the version
 number, without any supporting text.
 
 I'm not a huge fan of the name.

It was the lesser evil I could come up with since -version was already
taken, but I am open to alternatives.

 But what information are we trying to convey?  Just major/minor number
 or would qemu-kvm also throw some info in there?
 
 Do version numbers even matter because 0.13 from qemu.git is going to be
 a hell of a lot different from 0.13 in RHEL6.x.
 
 What are the consumers of this information actually doing with it?

I think this has already been discussed, I was off on Friday so I'll
leave it to the other thread.

Cheers,
Jes



[Qemu-devel] [PATCH 1/1] Add -version-simple argument, printing only version number.

2010-05-13 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Add -version-simple argument for QEMU, printing just the version
number, without any supporting text.

This makes it simpler for other apps, such as libvirt, to parse the
version string from QEMU independant of how the naming string may
change.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 qemu-options.hx |8 
 vl.c|9 +
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 12f6b51..e4f3979 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -27,6 +27,14 @@ STEXI
 Display version information and exit
 ETEXI
 
+DEF(version-simple, 0, QEMU_OPTION_version_simple,
+-version-simple display version information and exit\n, QEMU_ARCH_ALL)
+STEXI
+...@item -version-simple
+...@findex -version-simple
+Display basic version number information and exit
+ETEXI
+
 DEF(M, HAS_ARG, QEMU_OPTION_M,
 -M machine  select emulated machine (-M ? for list)\n, QEMU_ARCH_ALL)
 STEXI
diff --git a/vl.c b/vl.c
index 85bcc84..5adca87 100644
--- a/vl.c
+++ b/vl.c
@@ -2015,6 +2015,11 @@ static void version(void)
 printf(QEMU emulator version  QEMU_VERSION QEMU_PKGVERSION , Copyright 
(c) 2003-2008 Fabrice Bellard\n);
 }
 
+static void version_simple(void)
+{
+printf(QEMU_VERSION QEMU_PKGVERSION \n);
+}
+
 static void help(int exitcode)
 {
 const char *options_help =
@@ -2960,6 +2965,10 @@ int main(int argc, char **argv, char **envp)
 version();
 exit(0);
 break;
+case QEMU_OPTION_version_simple:
+version_simple();
+exit(0);
+break;
 case QEMU_OPTION_m: {
 uint64_t value;
 char *ptr;
-- 
1.6.6.1




[Qemu-devel] Re: [PATCH] Revive -version 'QEMU PC Emulator...'

2010-05-13 Thread Jes Sorensen
On 05/12/10 22:48, Cole Robinson wrote:
 I agree libvirt's method is a crappy approach. Adding a proper -version
 argument is certainly the way forward, but doesn't help users with
 existing libvirt installations that want to use latest qemu. This is the
 type of issue that libvirt devs will be fielding for months. Ideally i'd
 like the order to be:
 
 1) Apply this patch
 2) Add a proper -version argument, maybe named -version_num
 3) libvirt patched to use new version argument (and robustify legacy
 version parsing)
 4) Some reasonable amount of time from now (6 months, a year?), edit the
 current -version string at will
 
 I'd be willing to do 2 and 3 if people agree.

Hi Cole,

I think rather than 1, it would be better to add a patch to libvirt to
catch both formats. I know Chris Lalancette already cooked up a patch
for this. Combined with the 2) patch I just posted, and 3) I think that
should take care of the problems.

Cheers,
Jes



[Qemu-devel] [PATCH] Add -version-simple argument to QEMU

2010-05-13 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Hi,

I ran into a problem with the version string in QEMU changing,
confusing libvirt to not accept the output from qemu -help. Rather
than trying to change QEMU or continue to adapt apps when this change,
I believe it's a better solution to add a -version-simple argument
that just spits out the version number and nothing more.

Cheers,
Jes


Jes Sorensen (1):
  Add -version-simple argument, printing only version number.

 qemu-options.hx |8 
 vl.c|9 +
 2 files changed, 17 insertions(+), 0 deletions(-)




[Qemu-devel] Re: [PATCH] Revive -version 'QEMU PC Emulator...'

2010-05-13 Thread Jes Sorensen
On 05/13/10 15:04, Cole Robinson wrote:
 On 05/13/2010 04:35 AM, Jes Sorensen wrote:
 On 05/12/10 22:48, Cole Robinson wrote:
 I think rather than 1, it would be better to add a patch to libvirt to
 catch both formats. I know Chris Lalancette already cooked up a patch
 for this. Combined with the 2) patch I just posted, and 3) I think that
 should take care of the problems.
 
 It doesn't solve the problem for existing libvirt installations. It's
 not uncommon for users to track just the latest kvm releases without
 upgrading libvirt: any future qemu or kvm release will break every
 version of libvirt that exists today. Given that unfortunate case, I
 still recommend reverting the 'PC' change at least for long enough for a
 few fixed libvirt releases to make it into the wild.

But that is no different from what we have today. Users who update their
qemu and see issues with libvirt can also be asked to update libvirt. I
have already had several cases where I needed to do that anyway.

I don't like reverting a change like this, just to schedule it to be
reapplied again later.

Cheers,
Jes




Re: [Qemu-devel] [PATCH 1/1] Add -version-simple argument, printing only version number.

2010-05-13 Thread Jes Sorensen
On 05/13/10 15:33, Daniel P. Berrange wrote:
 This omits the KVM version string which is something we also want to see.
 It would also be nice to avoid having to parse the -help output to determine
 ARGV supported too. I wonder if it would be a good idea to just produce a
 well structured equivalent to -help that provides the same data, but in 
 JSON format for sane parsing. That would let peple easily determine the
 supported ARGV as well as version number(s)

I just made it print the version numbers that were already part of the
regular string, but I see no problem adding a KVM version number to the
output as well.

As for the JSON stuff, then I'll volunteer you to write the patch for it
:) To be honest, I have no clue what JSON is!

Cheers,
Jes



[Qemu-devel] Re: [PATCH] Revive -version 'QEMU PC Emulator...'

2010-05-12 Thread Jes Sorensen
On 05/12/10 22:29, Cole Robinson wrote:
 Commit f75ca1ae205f24dae296c82d534c37746f87232f changed the version
 string from:
 
 QEMU PC Emulator version x.yy.z
 
 to
 
 QEMU Emulator version x.yy.z
 
 libvirt is overly sensitive to the format of this string, and barfs when
 trying to parse qemu -help output. While libvirt should certainly be more
 robust here, changing the output format of -version for cosmetic reasons
 doesn't seem like the best idea, so let's revert the change and add a
 comment explaining the issue.

Rather than this, I would prefer a -version argument that just returns
the current QEMU version string.

IMHO it's not a good approach to do static string matching.

Cheers,
Jes





Re: [Qemu-devel] KVM call agenda for May 11

2010-05-11 Thread Jes Sorensen
On 05/11/10 15:53, Luiz Capitulino wrote:
 On Tue, 11 May 2010 15:50:32 +0200
 Alexander Graf ag...@suse.de wrote:
 
 Luiz Capitulino wrote:
 On Mon, 10 May 2010 08:02:50 -0700
 Chris Wright chr...@redhat.com wrote:

   
 Please send in any agenda items you are interested in covering.
 

 - Exposing named errno in QMP errors
   

 - flush=on
 
  We're doing it by irc right now, no need for the call then.
 

Where?

Jes




[Qemu-devel] Re: [SeaBIOS] About cpu_set, CPU hotplug and related subjects

2010-04-28 Thread Jes Sorensen
On 04/22/10 03:12, Kevin O'Connor wrote:
 As I understand it, the hotplug support was only in the kvm copy of
 bochs bios.  It also limited the number of cpus one could use (I think
 16).
 
 The current smp support in SeaBIOS doesn't limit the number of cpus.
 
 So, there has been reluctance to just port the old kvm bios code
 forward.

I believe the number was limited to 15, due to limits in a certain
proprietary operating system.

The issue with the AML code in BOCHS vs the code in Seabios is a bit
tricky. The tables in BOCHS are a fair bit more complicated with the
hotplug code and therefore statically generated, whereas Seabios
generates them dynamically at boot time.

Generating the more complex tables dynamically would be preferred, but
it requires like half an AML compiler in Seabios, so it kinda stalled
there

Cheers,
Jes




[Qemu-devel] Re: [SeaBIOS] About cpu_set, CPU hotplug and related subjects

2010-04-28 Thread Jes Sorensen
On 04/28/10 12:30, Gleb Natapov wrote:
 On Wed, Apr 28, 2010 at 11:31:00AM +0200, Jes Sorensen wrote:
 On 04/22/10 03:12, Kevin O'Connor wrote:
 Generating the more complex tables dynamically would be preferred, but
 it requires like half an AML compiler in Seabios, so it kinda stalled
 there

 We can try to be smart and generate most of the code statically and only
 minimum that absolutely required dynamically. Haven't looked at how
 simple dynamic part can be made.

I looked at it briefly and ran away screaming :) I am sure it can be
done, bit it would require pretty good understanding of the AML encodings.

The CPU declarations are particularly tricky as they get pretty big and
complex and need to live in the DSDT, whereas a lot of other things we
can shift off to separate SSDT tables and only put the minimum that
needs to be generated dynamically in it's own table.

Cheers,
Jes




Re: [libvirt] [Qemu-devel] Re: Libvirt debug API

2010-04-23 Thread Jes Sorensen
On 04/22/10 20:47, Anthony Liguori wrote:
 On 04/12/2010 07:23 AM, Jamie Lokier wrote:
 Some simple but versatile hook ideas:

 -emulator-append-option   (no space splitting, one option,
 appended)
 -emulator-append-options  (space splitting multiple options)
 -emulator-prepend-option
 -emulator-prepend-options
 -emulator-setenv name=NAMEVALUE/emulator-setenv
 
 I'd strongly suggest not focusing on manipulating command line
 arguments.  I think in the not too distant future, few people will pass
 command line arguments as opposed to just using configuration files.
 
 We are very close to being able to cover 90% of current users via the
 config file.

There will always be a place for adding command line parameters for
debugging purposes. When you try to debug a problem, the first port of
call is to look at the command line arguments libvirt uses to launch
qemu and replicate those with addons. It's a nightmare today and you end
up losing networking and other things. Having an optional debug options
thing that one can set quickly from virt-manager would make it so much
easier to retry different settings fast while replicating the setup that
is normally run.

Having to manually edit xml files for making changes is just not a
viable solution.

Speaking of which, one problem with the current XML format is that it
relies on hard-coding the path to QEMU. Instead if should rely on the
system default and provide an optional tag for debugging purposes. That
would make it easier to migrate specifications from one OS to another,
without manually having to edit the QEMU tag.

Cheers,
Jes




[Qemu-devel] Linux Plumbers Conference 2010 - call for tracks

2010-04-23 Thread Jes Sorensen
Hi,

I am organizing a Virtualization track at LPC 2010 (Linux Plumbers
Conference 2010). Please see the official call for tracks below.

LPC is particular well suited for work in progress and subjects that
needs discussion and collaboration between communities, for example
between KVM/QEMU and the Linux Kernel community. We expect strong
participation of kernel developers at LPC, and likely also from the
desktop community (GNOME/KDE/Xorg).

If you have a virtualization related project proposal, please submit it
using the information below. Note this is focused on general Linux
Virtualization, it is not limited to a specific hypervisor.

Subjects could be in the area of (but not limited to):
 - Kernel - KVM/QEMU interaction
 - IO Performance improvements
 - NUMA awareness
 - Migration
 - Support for new hardware features, and/or provide guest access to
   these features.
 - Virtualization management, user interfaces, and desktop integration

If you have questions related to this track, feel free to ask
lpc-plann...@linuxplumbersconf.org or email me directly.

Please feel free to forward this message to other mailing lists or
people for whom you feel it would be relevant.

Best regards,
Jes


Linux Plumbers Conference 2010
Call for Tracks

This year, Linux Plumbers Conference will take place in Cambridge, MA
on November 3-5, 2010.  Unlike more traditional conferences, the
Plumbers conference is not structured around presentations of
completed work, or problems and solutions confined to a single
subsystem or layer of the Linux ecosystem.  Rather the Plumbers
Conference encourages BOFs type meetings and brainstorming sessions
where technical experts from different areas and leaders in the Linux
and Open Source world can get together and discuss how to make
progress towards the solution of interdisciplinary multifaceted
problems spanning multiple components of the Linux system.  In some
sense, the Plumbers Conference is really more of a workshop.

The program committee for the Linux Plumbers Conference is looking for
proposals for the tracks that will be run during the Plumbers
Conference.

To do that, we are looking for problem statements: things that could
be improved in Linux that cross multiple interfaces or other project
boundaries (if you can solve it yourself inside a single project,
please, don't let us stop you --- get hacking!).  We are looking for
problems that require collaboration and face-to-face communication
across multiple teams and open source projects.  These problems could
apply to anywhere Linux is used: Linux on the Desktop, Linux on Mobile
devices, Linux on servers, etc.

For example, if in order to get better performance, we need to get
better information about low-level devices from the kernel, and that
needs to be utilized by file system utilities, and the user needs to
be able to involved by exposing options at the UI level in control
panels and distribution installers --- the Plumbers conference might
be a great place to get everyone in the same room for half a day to
solve this particular problem.

Along with your problem statements or track ideas, please list the
projects which and/or key individuals who ideally should be present,
and who might be a good person or persons to run such a conference
track.

If you have any thoughts or contributions, you can either

   * discuss them on this Linux Weekly News page:
http://lwn.net/Articles/lpc2010-cfi/
   * add the proposed topic to the Topics wiki page:
http://wiki.linuxplumbersconf.org/2010:topics
   * send e-mail to: lpc-plann...@linuxplumbersconf.org

Many thanks for helping to make Linux an even better platform!

The 2010 LPC Committee

Note: The event will be co-located with the Linux Kernel Summit which
will be held earlier that week.

Please feel free to forward this announcements to any communities or
mailing lists where you think it would be appropriate.




Re: [Qemu-devel] Re: KVM call agenda for Mar 23

2010-03-25 Thread Jes Sorensen

On 03/25/10 10:39, Jan Kiszka wrote:

Zhang, Xiantao wrote:

For ia64 part, maybe we can keep the current qemu-kvm.git for the users. And it 
is not a must to push it into Qemu upstream.
Xiantao



Does it still build  work? Does someone test it at least infrequently?
Or are there users?

There were a few changes recently due to cleanups and/or switches to
upstream code. There will be more in the future. And at some point heavy
work will be needed when there are no more qemu-kvm* files. That could
be a point ia64 breaks forever unless someone jumps in.

BTW, I'm also carrying ia64 bits in kvm-kmod. I never compiled them
(except for the make headers_install which throws tons of warnings at
me), I'm just keeping them for now to enforce architecture separation in
case someone once wishes to add another arch to this wrapper.


I think the end result will be that an older version of qemu-kvm will be
around, and if someone decides to pick up on it, they will have to work
from that. At this point I only see some of the Japanese vendors
potentially being interested, but I think they have mostly been looking
at Xen/ia64. Then again, I have no idea what the state is for Xen/ia64
patches for QEMU, in theory a lot of it should be shared.

As long as the bits are sitting in the tree without disturbing other
parts, then I just think we should let them sit there.

Cheers,
Jes




Re: [Qemu-devel] Re: [libvirt] Supporting hypervisor specific APIs in libvirt

2010-03-23 Thread Jes Sorensen

On 03/22/10 22:53, Anthony Liguori wrote:

On 03/22/2010 04:33 PM, Gerd Hoffmann wrote:

libvirt is very unfriendly to qemu hackers. There is no easy way to
add command line switches. There is no easy way to get access to the
monitor. I can get it done by pointing emulator to a wrapper script
and mangle the qemu command line there. But this sucks big time. And
it doesn't integrate with libvirt at all.


It's not just developers. As we're doing deployments of qemu/kvm, we
keep running into the same problem. We realize that we need to use a
feature of qemu/kvm that isn't modelled by libvirt today. I've gone as
far as to temporarily pausing libvirtd, finding the pty fd from
/proc/pid, and hijacking the monitor session temporarily.


One problem I have found, and I am not sure how to fix this in this
context. Sometimes when hacking on qemu, I want to try out a new
qemu binary on an existing image, without replacing the system wide
one and may want to pass new command line flags for testing those, plus
have access to the monitor.

What I do now is to look at the command line arguments of a guest using
ps and try and mimic it, but due to the random magic ptys and other
stuff, it's practically impossible to replicate a libvirt spawned qemu
on the command line. I end up having a somewhat similar command line
with everything removed that I cannot replicate.

I find it a real problem that libvirt tries to wrap things to the point
that an ordinary human cannot read, modify it's configuration or do a
simple command line spawn to replicate it, but as I said, I am not sure
how to solve the problem.

Regards,
Jes




Re: [Qemu-devel] Re: [libvirt] Supporting hypervisor specific APIs in libvirt

2010-03-23 Thread Jes Sorensen

On 03/23/10 11:25, Gerd Hoffmann wrote:

On 03/23/10 09:54, Jes Sorensen wrote:

One problem I have found, and I am not sure how to fix this in this
context. Sometimes when hacking on qemu, I want to try out a new
qemu binary on an existing image, without replacing the system wide
one and may want to pass new command line flags for testing those, plus
have access to the monitor.


Works with the wrapper script trick mentioned above.

virsh edit $domain
grep for emulator
make it point to a wrapper script.

My setup:

[r...@xenb ~]# virsh dumpxml fedora | grep emulator
emulator/root/bin/qemu-wrapper/emulator
[r...@xenb ~]# cat /root/bin/qemu-wrapper


Ah right thanks! However, it's a hack to get around the real problem
with libvirt. Not to mention that the output from virsh dumpxml is
where you have to cover your eyes and try not getting sick while
editing :(

Having a normal config file in readable format where you could add
regular command line options manually would make life so much easier.

Cheers,
Jes




Re: [Qemu-devel] Re: KVM call agenda for Mar 23

2010-03-23 Thread Jes Sorensen

On 03/23/10 13:45, Anthony Liguori wrote:

I don't think we can pull in:

- extboot
- ia64
- in-kernel pit[1]
- associated command line options
- device passthrough

The question is, if we dropped those things, would people actually use
qemu.git instead of qemu-kvm.git. If the answer is no, what set of
things do we need in order for people to focus on qemu.git instead of
qemu-kvm.git.


I am not sure if anyone is still actively working on ia64. According to
the qemu-kvm.git logs, there hasn't been any real ia64 changes to the
code since my last commit in June of last year and then a couple of
minor configure bits.

IMHO we can just let it rot - not sure if Xiantao is still interested?

Cheers,
Jes




Re: [Qemu-devel] Summer of Code 2010

2010-03-10 Thread Jes Sorensen

On 03/09/10 16:56, Alexander Graf wrote:


On 09.03.2010, at 16:50, Natalia Portillo wrote:


Qemu towards what xnu expects --  that's what I called Mac's memory space.

Of course is not only memory, the SMU, TPM module, anything it will search for 
without hacking.

(If you need testing comment me I have every x86 versions that is outside of 
Apple and nVidia, and hardware access to all in-sell Macintosh models)


No worries - I'd rather need someone implementing an ICH-7 PCI bridge, LPC and 
AHCI controller :-).


Well it seems to me you have an excellent and very specific 3 stage
project there already? Getting AHCI support in QEMU would be *really*
useful, and it seems what you are asking for should be easy to propose
for the summer of code. It's got a clear end target :-)

Cheers,
Jes




[Qemu-devel] [PATCH] QEMU-KVM missing bits for E820 handling.

2010-03-09 Thread Jes Sorensen

Hi,

This is the last piece needed for QEMU-KVM to match the changes that
went into upstream QEMU.

Cheers,
Jes
Use qemu-cfg to provide the BIOS with an optional table of e820 entries.

The missing bits for qemu-kvm.git to match what qemu does.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 qemu-kvm-x86.c |7 +++
 1 file changed, 7 insertions(+)

Index: qemu-kvm/qemu-kvm-x86.c
===
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -37,6 +37,13 @@ int kvm_set_tss_addr(kvm_context_t kvm, 
 {
 #ifdef KVM_CAP_SET_TSS_ADDR
int r;
+/*
+ * Tell fw_cfg to notify the BIOS to reserve the range.
+ */
+if (e820_add_entry(addr, 0x4000, E820_RESERVED)  0) {
+perror(e820_add_entry() table is full);
+exit(1);
+}
 
r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
if (r  0) {


Re: [Qemu-devel] [PATCH] QEMU e820 reservation patch

2010-02-21 Thread Jes Sorensen

On 02/19/10 22:02, Anthony Liguori wrote:

Acked-by: Anthony Liguori aligu...@us.ibm.com

Would be nice to use git-send-email in the future as your attachments
are often rendered poorly by mail clients.


Just switching over from quilt to git, and still having issues with
git-send-email. It does some things nicely, other things are a pain in
the b**t with it, especially for single patch submissions.


I noticed that you use this for the TSS page with EPT but you don't use
this interface for the rest of memory. I'm curious what you think the
right long term split is? If QEMU is not managing the full e820 table,
can we reasonable add entries on our own?


I'd like to have QEMU handle more, I picked the TSS page because we
changed the location of that in the past and it was the one that
triggered my patch in the first place. Now we have the infrastructure,
it will be easier to add more.

Cheers,
Jes





[Qemu-devel] [PATCH] QEMU kill CR3_CACHE references

2010-02-18 Thread Jes Sorensen

Hi,

The CR3 caching was never implemented in QEMU and is obsoleted by
NPT/EPT. This patch removes the unused references to it from
target-i386/kvm.c.

Cheers,
Jes

commit 5ed16687929511d015dd3542c4359cabe170401a
Author: Jes Sorensen jes.soren...@redhat.com
Date:   Fri Feb 19 07:39:56 2010 +0100

Remove all references to KVM_CR3_CACHE as it was never implemented.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 0d08cd5..5d9aecc 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -158,9 +158,6 @@ struct kvm_para_features {
 #ifdef KVM_CAP_PV_MMU
 { KVM_CAP_PV_MMU, KVM_FEATURE_MMU_OP },
 #endif
-#ifdef KVM_CAP_CR3_CACHE
-{ KVM_CAP_CR3_CACHE, KVM_FEATURE_CR3_CACHE },
-#endif
 { -1, -1 }
 };
 


[Qemu-devel] [PATCH] Seabios e820 reservation portion v3

2010-02-16 Thread Jes Sorensen

On 02/16/10 01:43, Kevin O'Connor wrote:

On Mon, Feb 15, 2010 at 06:33:59PM +0100, Jes Sorensen wrote:

Hi,

This is the Seabios part to match my e820 reservation via fw_cfg patch.


This still has 'struct e820_entry' which is too similar to 'struct
e820entry' in memmap.h.  Otherwise, it looks good to me.


Hmmm didn't catch that one earlier, thanks for pointing it out. I have
renamed it to struct e820_reservation to make it different.

Hope this version does the trick then.

Cheers,
Jes

Read optional table of e820 entries from qemu_cfg

Read optional table of e820 entries through qemu_cfg, allowing QEMU to
provide the location of KVM's switch area etc. rather than rely on
hard coded values.

For now, fall back to the old hard coded values for the TSS and EPT
switch page for compatibility reasons. Compatibility code could
possibly be removed in the future.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 src/paravirt.c |   17 +
 src/paravirt.h |9 +
 src/post.c |   13 -
 3 files changed, 38 insertions(+), 1 deletion(-)

Index: seabios/src/paravirt.c
===
--- seabios.orig/src/paravirt.c
+++ seabios/src/paravirt.c
@@ -132,6 +132,23 @@ u16 qemu_cfg_smbios_entries(void)
 return cnt;
 }
 
+u32 qemu_cfg_e820_entries(void)
+{
+u32 cnt;
+
+if (!qemu_cfg_present)
+return 0;
+
+qemu_cfg_read_entry(cnt, QEMU_CFG_E820_TABLE, sizeof(cnt));
+return cnt;
+}
+
+void* qemu_cfg_e820_load_next(void *addr)
+{
+qemu_cfg_read(addr, sizeof(struct e820_reservation));
+return addr;
+}
+
 struct smbios_header {
 u16 length;
 u8 type;
Index: seabios/src/paravirt.h
===
--- seabios.orig/src/paravirt.h
+++ seabios/src/paravirt.h
@@ -36,6 +36,7 @@ static inline int kvm_para_available(voi
 #define QEMU_CFG_ACPI_TABLES   (QEMU_CFG_ARCH_LOCAL + 0)
 #define QEMU_CFG_SMBIOS_ENTRIES(QEMU_CFG_ARCH_LOCAL + 1)
 #define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 2)
+#define QEMU_CFG_E820_TABLE(QEMU_CFG_ARCH_LOCAL + 3)
 
 extern int qemu_cfg_present;
 
@@ -61,8 +62,16 @@ typedef struct QemuCfgFile {
 char name[56];
 } QemuCfgFile;
 
+struct e820_reservation {
+u64 address;
+u64 length;
+u32 type;
+};
+
 u16 qemu_cfg_first_file(QemuCfgFile *entry);
 u16 qemu_cfg_next_file(QemuCfgFile *entry);
 u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen);
+u32 qemu_cfg_e820_entries(void);
+void* qemu_cfg_e820_load_next(void *addr);
 
 #endif
Index: seabios/src/post.c
===
--- seabios.orig/src/post.c
+++ seabios/src/post.c
@@ -135,10 +135,21 @@ ram_probe(void)
  , E820_RESERVED);
 add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
-if (kvm_para_available())
+u32 count = qemu_cfg_e820_entries();
+if (count) {
+struct e820_reservation entry;
+int i;
+
+for (i = 0; i  count; i++) {
+qemu_cfg_e820_load_next(entry);
+add_e820(entry.address, entry.length, entry.type);
+}
+} else if (kvm_para_available()) {
+// Backwards compatibility - provide hard coded range.
 // 4 pages before the bios, 3 pages for vmx tss pages, the
 // other page for EPT real mode pagetable
 add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+}
 
 dprintf(1, Ram Size=0x%08x (0x%08x%08x high)\n
 , RamSize, (u32)(RamSizeOver4G  32), (u32)RamSizeOver4G);


[Qemu-devel] Re: [PATCH] QEMU e820 reservation patch

2010-02-16 Thread Jes Sorensen

On 02/15/10 19:54, Stefano Stabellini wrote:

On Mon, 15 Feb 2010, Jes Sorensen wrote:

Kevin and I have agreed on the approach for this one now. So here is
the latest version of the patch for QEMU, submitting e820 reservation
entries via fw_cfg.


I think the interface is fine and it is perfectly usable by Xen as well.


Hi Stefano,

Thanks for the heads up! Glad it is flexible enough for Xen as well.

Cheers,
Jes





[Qemu-devel] [PATCH] QEMU e820 reservation patch

2010-02-15 Thread Jes Sorensen

Hi,

Kevin and I have agreed on the approach for this one now. So here is
the latest version of the patch for QEMU, submitting e820 reservation
entries via fw_cfg.

Cheers,
Jes

Use qemu-cfg to provide the BIOS with an optional table of e820 entries.

Notify the BIOS of the location of the TSS+EPT range to by reserving
it via the e820 table.

This matches a corresponding patch for Seabios, however older versions
of Seabios will default to the hardcoded address range and stay
compatible with current QEMU.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 hw/pc.c   |   35 +++
 hw/pc.h   |   10 ++
 target-i386/kvm.c |8 
 3 files changed, 53 insertions(+)

Index: qemu/hw/pc.c
===
--- qemu.orig/hw/pc.c
+++ qemu/hw/pc.c
@@ -59,6 +59,7 @@
 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
 #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
+#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 
 #define MAX_IDE_BUS 2
 
@@ -67,6 +68,21 @@ static RTCState *rtc_state;
 static PITState *pit;
 static PCII440FXState *i440fx_state;
 
+#define E820_NR_ENTRIES16
+
+struct e820_entry {
+uint64_t address;
+uint64_t length;
+uint32_t type;
+};
+
+struct e820_table {
+uint32_t count;
+struct e820_entry entry[E820_NR_ENTRIES];
+};
+
+static struct e820_table e820_table;
+
 typedef struct isa_irq_state {
 qemu_irq *i8259;
 qemu_irq *ioapic;
@@ -435,6 +451,23 @@ static void bochs_bios_write(void *opaqu
 }
 }
 
+int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
+{
+int index = e820_table.count;
+struct e820_entry *entry;
+
+if (index = E820_NR_ENTRIES)
+return -EBUSY;
+entry = e820_table.entry[index];
+
+entry-address = address;
+entry-length = length;
+entry-type = type;
+
+e820_table.count++;
+return e820_table.count;
+}
+
 static void *bochs_bios_init(void)
 {
 void *fw_cfg;
@@ -466,6 +499,8 @@ static void *bochs_bios_init(void)
 if (smbios_table)
 fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
  smbios_table, smbios_len);
+fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)e820_table,
+ sizeof(struct e820_table));
 
 /* allocate memory for the NUMA channel: one (64bit) word for the number
  * of nodes, one word for each VCPU-node and one word for each node to
Index: qemu/hw/pc.h
===
--- qemu.orig/hw/pc.h
+++ qemu/hw/pc.h
@@ -150,4 +150,14 @@ void isa_cirrus_vga_init(void);
 void isa_ne2000_init(int base, int irq, NICInfo *nd);
 
 int cpu_is_bsp(CPUState *env);
+
+/* e820 types */
+#define E820_RAM1
+#define E820_RESERVED   2
+#define E820_ACPI   3
+#define E820_NVS4
+#define E820_UNUSABLE   5
+
+int e820_add_entry(uint64_t, uint64_t, uint32_t);
+
 #endif
Index: qemu/target-i386/kvm.c
===
--- qemu.orig/target-i386/kvm.c
+++ qemu/target-i386/kvm.c
@@ -24,6 +24,7 @@
 #include cpu.h
 #include gdbstub.h
 #include host-utils.h
+#include hw/pc.h
 
 #ifdef CONFIG_KVM_PARA
 #include linux/kvm_para.h
@@ -362,6 +363,13 @@ int kvm_arch_init(KVMState *s, int smp_c
  * as unavaible memory.  FIXME, need to ensure the e820 map deals with
  * this?
  */
+/*
+ * Tell fw_cfg to notify the BIOS to reserve the range.
+ */
+if (e820_add_entry(0xfffbc000, 0x4000, E820_RESERVED)  0) {
+perror(e820_add_entry() table is full);
+exit(1);
+}
 return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000);
 }
 


[Qemu-devel] [PATCH] Seabios e820 reservation portion

2010-02-15 Thread Jes Sorensen

Hi,

This is the Seabios part to match my e820 reservation via fw_cfg patch.

Cheers,
Jes

Read optional table of e820 entries from qemu_cfg

Read optional table of e820 entries through qemu_cfg, allowing QEMU to
provide the location of KVM's switch area etc. rather than rely on
hard coded values.

For now, fall back to the old hard coded values for the TSS and EPT
switch page for compatibility reasons. Compatibility code could
possibly be removed in the future.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 src/paravirt.c |   17 +
 src/paravirt.h |9 +
 src/post.c |   13 -
 3 files changed, 38 insertions(+), 1 deletion(-)

Index: seabios/src/paravirt.c
===
--- seabios.orig/src/paravirt.c
+++ seabios/src/paravirt.c
@@ -132,6 +132,23 @@ u16 qemu_cfg_smbios_entries(void)
 return cnt;
 }
 
+u32 qemu_cfg_e820_entries(void)
+{
+u32 cnt;
+
+if (!qemu_cfg_present)
+return 0;
+
+qemu_cfg_read_entry(cnt, QEMU_CFG_E820_TABLE, sizeof(cnt));
+return cnt;
+}
+
+void* qemu_cfg_e820_load_next(void *addr)
+{
+qemu_cfg_read(addr, sizeof(struct e820_entry));
+return addr;
+}
+
 struct smbios_header {
 u16 length;
 u8 type;
Index: seabios/src/paravirt.h
===
--- seabios.orig/src/paravirt.h
+++ seabios/src/paravirt.h
@@ -36,6 +36,7 @@ static inline int kvm_para_available(voi
 #define QEMU_CFG_ACPI_TABLES   (QEMU_CFG_ARCH_LOCAL + 0)
 #define QEMU_CFG_SMBIOS_ENTRIES(QEMU_CFG_ARCH_LOCAL + 1)
 #define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 2)
+#define QEMU_CFG_E820_TABLE(QEMU_CFG_ARCH_LOCAL + 3)
 
 extern int qemu_cfg_present;
 
@@ -61,8 +62,16 @@ typedef struct QemuCfgFile {
 char name[56];
 } QemuCfgFile;
 
+struct e820_entry {
+u64 address;
+u64 length;
+u32 type;
+};
+
 u16 qemu_cfg_first_file(QemuCfgFile *entry);
 u16 qemu_cfg_next_file(QemuCfgFile *entry);
 u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen);
+u32 qemu_cfg_e820_entries(void);
+void* qemu_cfg_e820_load_next(void *addr);
 
 #endif
Index: seabios/src/post.c
===
--- seabios.orig/src/post.c
+++ seabios/src/post.c
@@ -135,10 +135,21 @@ ram_probe(void)
  , E820_RESERVED);
 add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
-if (kvm_para_available())
+u32 count = qemu_cfg_e820_entries();
+if (count) {
+struct e820_entry entry;
+int i;
+
+for (i = 0; i  count; i++) {
+qemu_cfg_e820_load_next(entry);
+add_e820(entry.address, entry.length, entry.type);
+}
+} else if (kvm_para_available()) {
+// Backwards compatibility - provide hard coded range.
 // 4 pages before the bios, 3 pages for vmx tss pages, the
 // other page for EPT real mode pagetable
 add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+}
 
 dprintf(1, Ram Size=0x%08x (0x%08x%08x high)\n
 , RamSize, (u32)(RamSizeOver4G  32), (u32)RamSizeOver4G);


[Qemu-devel] Re: [PATCH] Seabios - read e820 table from qemu_cfg

2010-02-08 Thread Jes Sorensen

On 01/28/10 05:39, Kevin O'Connor wrote:

As a side note, it should probably do the e820 map check even for qemu
users (ie, not just kvm).


Hi Kevin,

Here is an updated version of the patch which does the e820 read
unconditionally of  the return from kvm_para_available() so it should
work for coreboot too.

I haven't touched the file descriptor issue as I find it's a different
discussion.

Let me know what you think.

Cheers,
Jes

PS: I tried to subscribe to the seabios list but I never got an ack for
it :(
Read optional table of e820 entries from qemu_cfg

Read optional table of e820 entries through qemu_cfg, allowing QEMU to
provide the location of KVM's switch area etc. rather than rely on
hard coded values.

For now, fall back to the old hard coded values for the TSS and EPT
switch page for compatibility reasons. Compatibility code could
possibly be removed in the future.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 src/paravirt.c |   17 +
 src/paravirt.h |9 +
 src/post.c |   13 -
 3 files changed, 38 insertions(+), 1 deletion(-)

Index: seabios/src/paravirt.c
===
--- seabios.orig/src/paravirt.c
+++ seabios/src/paravirt.c
@@ -132,6 +132,23 @@ u16 qemu_cfg_smbios_entries(void)
 return cnt;
 }
 
+u32 qemu_cfg_e820_entries(void)
+{
+u32 cnt;
+
+if (!qemu_cfg_present)
+return 0;
+
+qemu_cfg_read_entry(cnt, QEMU_CFG_E820_TABLE, sizeof(cnt));
+return cnt;
+}
+
+void* qemu_cfg_e820_load_next(void *addr)
+{
+qemu_cfg_read(addr, sizeof(struct e820_entry));
+return addr;
+}
+
 struct smbios_header {
 u16 length;
 u8 type;
Index: seabios/src/paravirt.h
===
--- seabios.orig/src/paravirt.h
+++ seabios/src/paravirt.h
@@ -36,6 +36,7 @@ static inline int kvm_para_available(voi
 #define QEMU_CFG_ACPI_TABLES   (QEMU_CFG_ARCH_LOCAL + 0)
 #define QEMU_CFG_SMBIOS_ENTRIES(QEMU_CFG_ARCH_LOCAL + 1)
 #define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 2)
+#define QEMU_CFG_E820_TABLE(QEMU_CFG_ARCH_LOCAL + 3)
 
 extern int qemu_cfg_present;
 
@@ -61,8 +62,16 @@ typedef struct QemuCfgFile {
 char name[56];
 } QemuCfgFile;
 
+struct e820_entry {
+u64 address;
+u64 length;
+u32 type;
+};
+
 u16 qemu_cfg_first_file(QemuCfgFile *entry);
 u16 qemu_cfg_next_file(QemuCfgFile *entry);
 u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen);
+u32 qemu_cfg_e820_entries(void);
+void* qemu_cfg_e820_load_next(void *addr);
 
 #endif
Index: seabios/src/post.c
===
--- seabios.orig/src/post.c
+++ seabios/src/post.c
@@ -135,10 +135,21 @@ ram_probe(void)
  , E820_RESERVED);
 add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
-if (kvm_para_available())
+u32 count = qemu_cfg_e820_entries();
+if (count) {
+struct e820_entry entry;
+int i;
+
+for (i = 0; i  count; i++) {
+qemu_cfg_e820_load_next(entry);
+add_e820(entry.address, entry.length, entry.type);
+}
+} else if (kvm_para_available()) {
+// Backwards compatibility - provide hard coded range.
 // 4 pages before the bios, 3 pages for vmx tss pages, the
 // other page for EPT real mode pagetable
 add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+}
 
 dprintf(1, Ram Size=0x%08x (0x%08x%08x high)\n
 , RamSize, (u32)(RamSizeOver4G  32), (u32)RamSizeOver4G);


Re: [Qemu-devel] The new qemu.org

2010-02-03 Thread Jes Sorensen

On 02/02/10 17:22, G 3 wrote:

The new site looks nice. When is the Mac OS X section under Compilation
from the sources going to be updated from the lame The Mac OS X
patches are not fully merged in QEMU, so you should look at the QEMU
mailing list archive to have all the necessary information.. This is
unacceptable.


Well as Anthony pointed out, this is a Wiki, so you should just go ahead
and update the page, in fact it is unacceptable that you haven't done so
already!

Someone who uses OSX needs to do it, you cannot expect someone who is
not developing on OSX to keep up-to-date with all the OSX details.

Jes




[Qemu-devel] Re: [PATCH] Seabios - read e820 table from qemu_cfg

2010-01-29 Thread Jes Sorensen

On 01/28/10 05:39, Kevin O'Connor wrote:

I think defining accessor functions for every piece of data passed
through qemu-cfg interface is going to get tiring.  I'd prefer to
extend the existing qemu-cfg file interface for new content.

For example, add a helper with something like:

int qemu_cfg_get_file(const char *name, void *dest, int maxsize);


Hi Kevin,

I think switching qemu_cfg to use a file name based interface would be
a nice feature, but I think it should be independent of this patch. I am
CC'ing Gleb on this as he did the original design I believe.


-if (kvm_para_available())
-// 4 pages before the bios, 3 pages for vmx tss pages, the
-// other page for EPT real mode pagetable
-add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+if (kvm_para_available()) {
+u32 count;
+
+count = qemu_cfg_e820_entries();
+if (count) {
+struct e820_entry entry;
+int i;
+
+for (i = 0; i  count; i++) {
+qemu_cfg_e820_load_next(entry);
+add_e820(entry.address, entry.length, entry.type);
+}


and then this becomes:

struct e820entry map[128];
int len = qemu_cfg_get_file(e820map,map, sizeof(map));
if (len= 0)
 for (i=0; ilen / sizeof(map[0]); i++)
 add_e820(map[i].start, map[i].size, map[i].type);

The advantage being that it should be possible to write one set of
helper functions in both qemu and seabios that can then be used to
pass arbitrary content.


The only issue here is that I designed the Seabios portion to not rely
on the size of the struct, to avoid having to statically reserve it like
in your example. Having the qemu_cfg_get_file() function return a
pointer to a file descriptor and then have a qemu_cfg_read() helper that
takes the descriptor as it's first argument would avoid this problem.


As a side note, it should probably do the e820 map check even for qemu
users (ie, not just kvm).


Ah I didn't realize Seabios would try to use the fw_cfg interface if it
wasn't running on top of QEMU. That would be good to do.

Cheers,
Jes




[Qemu-devel] Re: [PATCH] QEMU - provide e820 reserve through qemu_cfg

2010-01-26 Thread Jes Sorensen

On 01/26/10 07:46, Gleb Natapov wrote:

On Mon, Jan 25, 2010 at 06:13:35PM +0100, Jes Sorensen wrote:

I am fine with having QEMU build the e820 tables completely if there is
a consensus to take that path.


QEMU can't build the e820 map completely. There are things it doesn't
know. Like how much memory ACPI tables take and where they are located.


Good point!

I think the conclusion is to do a load-extra-tables kinda interface 
allowing QEMU to pass in a bunch of them, but leaving things like the

ACPI space for the BIOS to reserve.

Cheers,
Jes




[Qemu-devel] [PATCH] Seabios - read e820 table from qemu_cfg

2010-01-26 Thread Jes Sorensen

Hi,

Based on the feedback I received over the e820 reserve patch, I have
changed it to have QEMU pass in a list of entries that can cover more
than just the TSS/EPT range. This should provide the flexibility that
people were asking for.

The Seabios portion should allow for unlimited sized tables in theory,
whereas for QEMU I have set a fixed limit for now, but it can easily
be extended.

Please let me know what you think of this version!

Cheers,
Jes

Read optional table of e820 entries from qemu_cfg

Read optional table of e820 entries through qemu_cfg, allowing QEMU to
provide the location of KVM's switch area etc. rather than rely on
hard coded values.

For now, fall back to the old hard coded values for the TSS and EPT
switch page for compatibility reasons. Compatibility code could
possibly be removed in the future.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 src/paravirt.c |   17 +
 src/paravirt.h |9 +
 src/post.c |   23 +++
 3 files changed, 45 insertions(+), 4 deletions(-)

Index: seabios/src/paravirt.c
===
--- seabios.orig/src/paravirt.c
+++ seabios/src/paravirt.c
@@ -132,6 +132,23 @@ u16 qemu_cfg_smbios_entries(void)
 return cnt;
 }
 
+u32 qemu_cfg_e820_entries(void)
+{
+u32 cnt;
+
+if (!qemu_cfg_present)
+return 0;
+
+qemu_cfg_read_entry(cnt, QEMU_CFG_E820_TABLE, sizeof(cnt));
+return cnt;
+}
+
+void* qemu_cfg_e820_load_next(void *addr)
+{
+qemu_cfg_read(addr, sizeof(struct e820_entry));
+return addr;
+}
+
 struct smbios_header {
 u16 length;
 u8 type;
Index: seabios/src/paravirt.h
===
--- seabios.orig/src/paravirt.h
+++ seabios/src/paravirt.h
@@ -36,6 +36,7 @@ static inline int kvm_para_available(voi
 #define QEMU_CFG_ACPI_TABLES   (QEMU_CFG_ARCH_LOCAL + 0)
 #define QEMU_CFG_SMBIOS_ENTRIES(QEMU_CFG_ARCH_LOCAL + 1)
 #define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 2)
+#define QEMU_CFG_E820_TABLE(QEMU_CFG_ARCH_LOCAL + 3)
 
 extern int qemu_cfg_present;
 
@@ -61,8 +62,16 @@ typedef struct QemuCfgFile {
 char name[56];
 } QemuCfgFile;
 
+struct e820_entry {
+u64 address;
+u64 length;
+u32 type;
+};
+
 u16 qemu_cfg_first_file(QemuCfgFile *entry);
 u16 qemu_cfg_next_file(QemuCfgFile *entry);
 u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen);
+u32 qemu_cfg_e820_entries(void);
+void* qemu_cfg_e820_load_next(void *addr);
 
 #endif
Index: seabios/src/post.c
===
--- seabios.orig/src/post.c
+++ seabios/src/post.c
@@ -135,10 +135,25 @@ ram_probe(void)
  , E820_RESERVED);
 add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
-if (kvm_para_available())
-// 4 pages before the bios, 3 pages for vmx tss pages, the
-// other page for EPT real mode pagetable
-add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+if (kvm_para_available()) {
+u32 count;
+
+count = qemu_cfg_e820_entries();
+if (count) {
+struct e820_entry entry;
+int i;
+
+for (i = 0; i  count; i++) {
+qemu_cfg_e820_load_next(entry);
+add_e820(entry.address, entry.length, entry.type);
+}
+} else {
+// Backwards compatibility - provide hard coded range.
+// 4 pages before the bios, 3 pages for vmx tss pages, the
+// other page for EPT real mode pagetable
+add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+}
+}
 
 dprintf(1, Ram Size=0x%08x (0x%08x%08x high)\n
 , RamSize, (u32)(RamSizeOver4G  32), (u32)RamSizeOver4G);


[Qemu-devel] [PATCH] QEMU-KVM - provide e820 table via fw_cfg

2010-01-26 Thread Jes Sorensen

Hi,

This is the QEMU-KVM part of the patch. If we can agree on this
approach, I will do a version for upstream QEMU as well.

Cheers,
Jes

Use qemu-cfg to provide the BIOS with an optional table of e820 entries.

Notify the BIOS of the location of the TSS+EPT range to by reserving
it via the e820 table.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 hw/pc.c   |   35 +++
 hw/pc.h   |9 +
 qemu-kvm-x86.c|7 +++
 target-i386/kvm.c |7 +++
 4 files changed, 58 insertions(+)

Index: qemu-kvm/hw/pc.c
===
--- qemu-kvm.orig/hw/pc.c
+++ qemu-kvm/hw/pc.c
@@ -66,6 +66,7 @@
 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
 #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
+#define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 
 #define MAX_IDE_BUS 2
 
@@ -74,6 +75,21 @@ static RTCState *rtc_state;
 static PITState *pit;
 static PCII440FXState *i440fx_state;
 
+#define E820_NR_ENTRIES16
+
+struct e820_entry {
+uint64_t address;
+uint64_t length;
+uint32_t type;
+};
+
+struct e820_table {
+uint32_t count;
+struct e820_entry entry[E820_NR_ENTRIES];
+};
+
+static struct e820_table e820_table;
+
 qemu_irq *ioapic_irq_hack;
 
 typedef struct isa_irq_state {
@@ -444,6 +460,23 @@ static void bochs_bios_write(void *opaqu
 }
 }
 
+int e820_add_entry(uint64_t address, uint64_t length, uint32_t type)
+{
+int index = e820_table.count;
+struct e820_entry *entry;
+
+if (index = E820_NR_ENTRIES)
+return -EBUSY;
+entry = e820_table.entry[index];
+
+entry-address = address;
+entry-length = length;
+entry-type = type;
+
+e820_table.count++;
+return e820_table.count;
+}
+
 static void *bochs_bios_init(void)
 {
 void *fw_cfg;
@@ -475,6 +508,8 @@ static void *bochs_bios_init(void)
 if (smbios_table)
 fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
  smbios_table, smbios_len);
+fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_TABLE, (uint8_t *)e820_table,
+ sizeof(struct e820_table));
 
 /* allocate memory for the NUMA channel: one (64bit) word for the number
  * of nodes, one word for each VCPU-node and one word for each node to
Index: qemu-kvm/hw/pc.h
===
--- qemu-kvm.orig/hw/pc.h
+++ qemu-kvm/hw/pc.h
@@ -169,4 +169,13 @@ void extboot_init(BlockDriverState *bs, 
 
 int cpu_is_bsp(CPUState *env);
 
+/* e820 types */
+#define E820_RAM1
+#define E820_RESERVED   2
+#define E820_ACPI   3
+#define E820_NVS4
+#define E820_UNUSABLE   5
+
+int e820_add_entry(uint64_t, uint64_t, uint32_t);
+
 #endif
Index: qemu-kvm/qemu-kvm-x86.c
===
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -37,6 +37,13 @@ int kvm_set_tss_addr(kvm_context_t kvm, 
 {
 #ifdef KVM_CAP_SET_TSS_ADDR
int r;
+/*
+ * Tell fw_cfg to notify the BIOS to reserve the range.
+ */
+if (e820_add_entry(addr, 0x4000, E820_RESERVED)  0) {
+perror(e820_add_entry() table is full);
+exit(1);
+}
 
r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
if (r  0) {
Index: qemu-kvm/target-i386/kvm.c
===
--- qemu-kvm.orig/target-i386/kvm.c
+++ qemu-kvm/target-i386/kvm.c
@@ -298,6 +298,13 @@ int kvm_arch_init(KVMState *s, int smp_c
  * as unavaible memory.  FIXME, need to ensure the e820 map deals with
  * this?
  */
+/*
+ * Tell fw_cfg to notify the BIOS to reserve the range.
+ */
+if (e820_add_entry(0xfffbc000, 0x4000, E820_RESERVED)  0) {
+perror(e820_add_entry() table is full);
+exit(1);
+}
 return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000);
 }
 


[Qemu-devel] [PATCH] Seabios - read e820 reserve from qemu_cfg

2010-01-25 Thread Jes Sorensen

Hi,

Right now KVM/QEMU relies on hard coded values in Seabios for the
reserved area for the TSS pages and the EPT page.

I'd like to suggest we change this to pass the value from QEMU via
qemu-cfg making it possible to move it around dynamically in the future.

Attached is a patch to Seabios for this, which defaults to the current
hard coded value if no value is provided by qemu-cfg. We can remove
the backwards compatibility later.

I'll post the QEMU patches for upstream QEMU and QEMU-KVM in a minute.

Comments most welcome!

Cheers,
Jes

Read location and size of KVM switch area from qemu-cfg

Read location of KVM's switch area (VMX TSS pages and EPT) from QEMU
via qemu-cfg instead of relying on hard coded values.

For now, fall back to the old hard coded values for compatibility
reasons. Compatibility code can be removed in the future.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 src/paravirt.c |9 +
 src/paravirt.h |7 +++
 src/post.c |   14 ++
 3 files changed, 26 insertions(+), 4 deletions(-)

Index: seabios/src/paravirt.c
===
--- seabios.orig/src/paravirt.c
+++ seabios/src/paravirt.c
@@ -132,6 +132,15 @@ u16 qemu_cfg_smbios_entries(void)
 return cnt;
 }
 
+int qemu_cfg_read_e820_reserve(struct qemu_cfg_e820_reserve *reserve)
+{
+if (!qemu_cfg_present)
+return 0;
+
+qemu_cfg_read((void *)reserve, sizeof(*reserve));
+return reserve-length;
+}
+
 struct smbios_header {
 u16 length;
 u8 type;
Index: seabios/src/paravirt.h
===
--- seabios.orig/src/paravirt.h
+++ seabios/src/paravirt.h
@@ -36,6 +36,7 @@ static inline int kvm_para_available(voi
 #define QEMU_CFG_ACPI_TABLES   (QEMU_CFG_ARCH_LOCAL + 0)
 #define QEMU_CFG_SMBIOS_ENTRIES(QEMU_CFG_ARCH_LOCAL + 1)
 #define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 2)
+#define QEMU_CFG_E820_RESERVE  (QEMU_CFG_ARCH_LOCAL + 3)
 
 extern int qemu_cfg_present;
 
@@ -61,8 +62,14 @@ typedef struct QemuCfgFile {
 char name[56];
 } QemuCfgFile;
 
+struct qemu_cfg_e820_reserve {
+u32 addr;
+u32 length;
+};
+
 u16 qemu_cfg_first_file(QemuCfgFile *entry);
 u16 qemu_cfg_next_file(QemuCfgFile *entry);
 u32 qemu_cfg_read_file(QemuCfgFile *entry, void *dst, u32 maxlen);
+int qemu_cfg_read_e820_reserve(struct qemu_cfg_e820_reserve *reserve);
 
 #endif
Index: seabios/src/post.c
===
--- seabios.orig/src/post.c
+++ seabios/src/post.c
@@ -135,10 +135,16 @@ ram_probe(void)
  , E820_RESERVED);
 add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED);
 
-if (kvm_para_available())
-// 4 pages before the bios, 3 pages for vmx tss pages, the
-// other page for EPT real mode pagetable
-add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+if (kvm_para_available()) {
+struct qemu_cfg_e820_reserve e820_reserve;
+if (qemu_cfg_read_e820_reserve(e820_reserve))
+add_e820(e820_reserve.addr, e820_reserve.length, E820_RESERVED);
+else {
+// 4 pages before the bios, 3 pages for vmx tss pages, the
+// other page for EPT real mode pagetable
+add_e820(0xfffbc000, 4*4096, E820_RESERVED);
+}
+}
 
 dprintf(1, Ram Size=0x%08x (0x%08x%08x high)\n
 , RamSize, (u32)(RamSizeOver4G  32), (u32)RamSizeOver4G);


[Qemu-devel] [PATCH] QEMU-KVM - provide e820 reserve through qemu_cfg

2010-01-25 Thread Jes Sorensen

Hi,

This is the QEMU-KVM bits for providing the e820-reserve space through
qemu-cfg.

Cheers,
Jes

Use qemu-cfg to notify the BIOS of the location of the TSS range to
reserve in the e820 table, to avoid relying on hard coded values.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 hw/fw_cfg.h   |5 +
 hw/pc.c   |4 
 kvm.h |2 ++
 qemu-kvm-x86.c|6 ++
 target-i386/kvm.c |7 +++
 5 files changed, 24 insertions(+)

Index: qemu-kvm/hw/fw_cfg.h
===
--- qemu-kvm.orig/hw/fw_cfg.h
+++ qemu-kvm/hw/fw_cfg.h
@@ -67,4 +67,9 @@ FWCfgState *fw_cfg_init(uint32_t ctl_por
 
 #endif /* NO_QEMU_PROTOS */
 
+struct fw_cfg_e820_reserve {
+uint32_t addr;
+uint32_t length;
+};
+
 #endif
Index: qemu-kvm/hw/pc.c
===
--- qemu-kvm.orig/hw/pc.c
+++ qemu-kvm/hw/pc.c
@@ -66,6 +66,7 @@
 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
 #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
+#define FW_CFG_E820_RESERVE (FW_CFG_ARCH_LOCAL + 3)
 
 #define MAX_IDE_BUS 2
 
@@ -73,6 +74,7 @@ static fdctrl_t *floppy_controller;
 static RTCState *rtc_state;
 static PITState *pit;
 static PCII440FXState *i440fx_state;
+struct fw_cfg_e820_reserve e820_reserve;
 
 qemu_irq *ioapic_irq_hack;
 
@@ -475,6 +477,8 @@ static void *bochs_bios_init(void)
 if (smbios_table)
 fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
  smbios_table, smbios_len);
+fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_RESERVE, (uint8_t *)e820_reserve,
+ sizeof(struct fw_cfg_e820_reserve));
 
 /* allocate memory for the NUMA channel: one (64bit) word for the number
  * of nodes, one word for each VCPU-node and one word for each node to
Index: qemu-kvm/kvm.h
===
--- qemu-kvm.orig/kvm.h
+++ qemu-kvm/kvm.h
@@ -101,6 +101,8 @@ void kvm_arch_reset_vcpu(CPUState *env);
 struct kvm_guest_debug;
 struct kvm_debug_exit_arch;
 
+extern struct fw_cfg_e820_reserve e820_reserve;
+
 struct kvm_sw_breakpoint {
 target_ulong pc;
 target_ulong saved_insn;
Index: qemu-kvm/qemu-kvm-x86.c
===
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -23,6 +23,7 @@
 
 #include kvm.h
 #include hw/pc.h
+#include hw/fw_cfg.h
 
 #define MSR_IA32_TSC   0x10
 
@@ -37,6 +38,11 @@ int kvm_set_tss_addr(kvm_context_t kvm, 
 {
 #ifdef KVM_CAP_SET_TSS_ADDR
int r;
+/*
+ * Tell fw_cfg to notify the BIOS to reserve the range.
+ */
+e820_reserve.addr = addr;
+e820_reserve.length = 0x4000;
 
r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
if (r  0) {
Index: qemu-kvm/target-i386/kvm.c
===
--- qemu-kvm.orig/target-i386/kvm.c
+++ qemu-kvm/target-i386/kvm.c
@@ -25,6 +25,8 @@
 #include gdbstub.h
 #include host-utils.h
 
+extern struct fw_cfg_e820_reserve e820_reserve;
+
 #ifdef KVM_UPSTREAM
 //#define DEBUG_KVM
 
@@ -298,6 +300,11 @@ int kvm_arch_init(KVMState *s, int smp_c
  * as unavaible memory.  FIXME, need to ensure the e820 map deals with
  * this?
  */
+/*
+ * Tell fw_cfg to notify the BIOS to reserve the range.
+ */
+e820_reserve.addr = 0xfffbc000;
+e820_reserve.length = 0x4000;
 return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000);
 }
 


[Qemu-devel] [PATCH] QEMU - provide e820 reserve through qemu_cfg

2010-01-25 Thread Jes Sorensen

Hi,

This is the QEMU patch for providing the e820-reserve space through
qemu-cfg.

Cheers,
Jes


Use qemu-cfg to notify the BIOS of the location of the TSS range to
reserve in the e820 table, to avoid relying on hard coded values.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com

---
 hw/pc.c   |5 +
 kvm.h |7 +++
 target-i386/kvm.c |5 +
 3 files changed, 17 insertions(+)

Index: qemu/hw/pc.c
===
--- qemu.orig/hw/pc.c
+++ qemu/hw/pc.c
@@ -45,6 +45,7 @@
 #include loader.h
 #include elf.h
 #include multiboot.h
+#include kvm.h
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -59,6 +60,7 @@
 #define FW_CFG_ACPI_TABLES (FW_CFG_ARCH_LOCAL + 0)
 #define FW_CFG_SMBIOS_ENTRIES (FW_CFG_ARCH_LOCAL + 1)
 #define FW_CFG_IRQ0_OVERRIDE (FW_CFG_ARCH_LOCAL + 2)
+#define FW_CFG_E820_RESERVE (FW_CFG_ARCH_LOCAL + 3)
 
 #define MAX_IDE_BUS 2
 
@@ -66,6 +68,7 @@ static fdctrl_t *floppy_controller;
 static RTCState *rtc_state;
 static PITState *pit;
 static PCII440FXState *i440fx_state;
+struct fw_cfg_e820_reserve e820_reserve;
 
 typedef struct isa_irq_state {
 qemu_irq *i8259;
@@ -466,6 +469,8 @@ static void *bochs_bios_init(void)
 if (smbios_table)
 fw_cfg_add_bytes(fw_cfg, FW_CFG_SMBIOS_ENTRIES,
  smbios_table, smbios_len);
+fw_cfg_add_bytes(fw_cfg, FW_CFG_E820_RESERVE, (uint8_t *)e820_reserve,
+ sizeof(struct fw_cfg_e820_reserve));
 
 /* allocate memory for the NUMA channel: one (64bit) word for the number
  * of nodes, one word for each VCPU-node and one word for each node to
Index: qemu/kvm.h
===
--- qemu.orig/kvm.h
+++ qemu/kvm.h
@@ -96,6 +96,13 @@ void kvm_arch_reset_vcpu(CPUState *env);
 struct kvm_guest_debug;
 struct kvm_debug_exit_arch;
 
+struct fw_cfg_e820_reserve {
+uint32_t addr;
+uint32_t length;
+};
+
+extern struct fw_cfg_e820_reserve e820_reserve;
+
 struct kvm_sw_breakpoint {
 target_ulong pc;
 target_ulong saved_insn;
Index: qemu/target-i386/kvm.c
===
--- qemu.orig/target-i386/kvm.c
+++ qemu/target-i386/kvm.c
@@ -356,6 +356,11 @@ int kvm_arch_init(KVMState *s, int smp_c
  * as unavaible memory.  FIXME, need to ensure the e820 map deals with
  * this?
  */
+/*
+ * Tell fw_cfg to notify the BIOS to reserve the range.
+ */
+e820_reserve.addr = 0xfffbc000;
+e820_reserve.length = 0x4000;
 return kvm_vm_ioctl(s, KVM_SET_TSS_ADDR, 0xfffbd000);
 }
 


[Qemu-devel] Re: [PATCH] QEMU - provide e820 reserve through qemu_cfg

2010-01-25 Thread Jes Sorensen

On 01/25/10 17:58, Alexander Graf wrote:

Howdy. Congratulations to the new mail address - looks neat ;-).


:-)


Two comments:

1) I don't see how passing a single region is any help. I'd rather like to see 
a device tree like table structure
You'd get one variable for len of the table, one with the contents. So for a 
universal reserved region specifier you'd get:

u64 baseu64 len

Then have len=2 and put data in the table:

u64 base1u64 len1u64 base2u64 len2

That way we'd get 2 entries and the chance to enhance them later on. In fact, 
it might even make sense to pass the whole table in such a form. That way qemu 
generates all of the e820 tables and we can declare whatever we want. Just add 
a type field in the table.


I am fine with having QEMU build the e820 tables completely if there is
a consensus to take that path.


2) Please inline patches. They showed up as attachments here, making them 
really hard to comment on.


Sorry Thunderbug doesn't do that well, but they should be attached as
txt?

Cheers,
Jes





[Qemu-devel] Re: [PATCH] QEMU - provide e820 reserve through qemu_cfg

2010-01-25 Thread Jes Sorensen

On 01/25/10 18:28, Alexander Graf wrote:

That way we'd get 2 entries and the chance to enhance them later on.
In fact, it might even make sense to pass the whole table in such a
form. That way qemu generates all of the e820 tables and we can
declare whatever we want. Just add a type field in the table.


I am fine with having QEMU build the e820 tables completely if there is
a consensus to take that path.


I agree. We better get this right :-). I don't want to maintain 5
versions of an 380 fw_cfg interface.


Looking at the internals, some of the e820 entries are based on compile
time constants for the BIOS, so it will be hard to pass those from
QEMU, but we could do it in a way so we pass a number of additional
e820 entries. Ie. address, length, and type.

What do you think?

Cheers,
Jes




[Qemu-devel] Re: [PATCH] QEMU - provide e820 reserve through qemu_cfg

2010-01-25 Thread Jes Sorensen

On 01/25/10 21:14, Anthony Liguori wrote:

On 01/25/2010 02:04 PM, Alexander Graf wrote:

Yes, sounds good. Should be fairly extensible then. What about memory
holes? Do we need to take care of them?


It would be nice for QEMU to be able to add additional e820 regions that
don't necessarily fit the standard layout model.

For instance, I've thought a number of times about using a large
reserved region as a shared memory mechanism.

But we certainly need to allow the BIOS to define the regions it needs
to know about.


I think it should be easy to accommodate using the scheme I am
suggesting. It would require some basic testing for conflicts in the
BIOS, but otherwise it should pretty much allow you to specify any
region you want as a reserved block.

Only problem is that we don't really have a way to pass back info
saying 'you messed up trying to pinch an area that the BIOS wants
for itself'.

I'll take a look at it.

Cheers,
Jes




[Qemu-devel] Re: [PATCH] QEMU - provide e820 reserve through qemu_cfg

2010-01-25 Thread Jes Sorensen

On 01/25/10 22:08, Alexander Graf wrote:


On 25.01.2010, at 22:05, Jes Sorensen wrote:

Only problem is that we don't really have a way to pass back info
saying 'you messed up trying to pinch an area that the BIOS wants
for itself'.


Eh - the BIOS shouldn't even try to use regions that are declared as reserved 
using this interface.
I guess we're mostly talking about DMI and ACPI tables. They can be anywhere in 
RAM.


What I had in mind with the above was the situation where a user tries
to reserve a region that is hardcoded into the BIOS, such as the address
of the BIOS text/data etc.

I don't think it would be a real problem anyway, if some user wants to
play with it, they have to take the risk of shooting themself in the
foot :)

Cheers,
Jes





<    4   5   6   7   8   9