Re: [Qemu-devel] [PATCH] add text about how to use qemu-nbd with qemu

2012-07-09 Thread Wayne Xia

  Paolo, what do you think write a short section in document for it, but
make no change to code?


于 2012-7-5 16:34, Paolo Bonzini 写道:

Il 05/07/2012 10:13, Michael Tokarev ha scritto:

Hi Paolo, should I make a patch to make persistent the default for
qemu-nbd?


Yes, why not. However, as mentioned above client mode should still be
non-persistent.

I don't think this makes sense or is good: now we'll need
to have an option to enable non-persistent mode, and have
to fix scripts which expects non-persistent mode by default
(does autotest uses it?).


Hmm, yeah, with daemon mode non-persistent is still better. I guess it
is just a bogus thing we have to live with, just like daemon mode itself.


 From the product perspective, keeping qemu-nbd option unchanged seems
better. I think changing the qemu block behavior needs extra efforts
and not so worthy. Actually I don't think this is a bug, the nbd-block
still works but just need some document to avoid making user debug it.
Maybe a document is the easiest way.


Instead, it is more productive and rigth (IMHO anyway) to
fix the qemu side to stop connecting two times for one
device.


That too.

Paolo







--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH] add text about how to use qemu-nbd with qemu

2012-07-06 Thread Wayne Xia

于 2012-7-5 16:34, Paolo Bonzini 写道:

Il 05/07/2012 10:13, Michael Tokarev ha scritto:

Hi Paolo, should I make a patch to make persistent the default for
qemu-nbd?


Yes, why not.  However, as mentioned above client mode should still be
non-persistent.

I don't think this makes sense or is good: now we'll need
to have an option to enable non-persistent mode, and have
to fix scripts which expects non-persistent mode by default
(does autotest uses it?).


Hmm, yeah, with daemon mode non-persistent is still better.  I guess it
is just a bogus thing we have to live with, just like daemon mode itself.


  From the product perspective, keeping qemu-nbd option unchanged seems
better. I think changing the qemu block behavior needs extra efforts
and not so worthy. Actually I don't think this is a bug, the nbd-block
still works but just need some document to avoid making user debug it.
Maybe a document is the easiest way.


Instead, it is more productive and rigth (IMHO anyway) to
fix the qemu side to stop connecting two times for one
device.


That too.

Paolo




--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH] add text about how to use qemu-nbd with qemu

2012-07-04 Thread Wayne Xia

于 2012-7-3 19:55, Paolo Bonzini 写道:

Il 03/07/2012 13:05, xiaw...@linux.vnet.ibm.com ha scritto:

+
+  Note: When qemu-nbd was used to export a disk that would be used by QEMU
+block device, -t or --persistent must be set for that QEMU nbd client would try
+connect more than one time. For eg:
+  qemu-nbd ./simple.img -p 10809 -t
+  qemu -hdb nbd:127.0.0.1:10809


We could actually make persistent the default unless we're using
qemu-nbd in client mode (i.e. exporting to /dev/nbd*), and drop the
option.  What do you think?

Paolo


Hi Paolo, should I make a patch to make persistent the default for
qemu-nbd?



--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH] add text about how to use qemu-nbd with qemu

2012-07-03 Thread Wayne Xia

于 2012-7-4 0:18, 陳韋任 (Wei-Ren Chen) 写道:

+
+  Note: When qemu-nbd was used to export a disk that would be used by QEMU
+block device, -t or --persistent must be set for that QEMU nbd client would try
+connect more than one time. For eg:

^^
   Not a native english speaker, but I never see such usage before.
Should be "For example"?


  Sorry it should be "i.e." or "for example", my bad spell custom.


Regards,
chenwj




--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH] add text about how to use qemu-nbd with qemu

2012-07-03 Thread Wayne Xia

于 2012-7-3 19:55, Paolo Bonzini 写道:

Il 03/07/2012 13:05, xiaw...@linux.vnet.ibm.com ha scritto:

+
+  Note: When qemu-nbd was used to export a disk that would be used by QEMU
+block device, -t or --persistent must be set for that QEMU nbd client would try
+connect more than one time. For eg:
+  qemu-nbd ./simple.img -p 10809 -t
+  qemu -hdb nbd:127.0.0.1:10809


We could actually make persistent the default unless we're using
qemu-nbd in client mode (i.e. exporting to /dev/nbd*), and drop the
option.  What do you think?


  I think there will be no harm to make persistent default, but mark
this change in document in case of breaking potential user case.(maybe
someone have used qemu and expect qemu-nbd exit in script).


Paolo




--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH] add text about how to use qemu-nbd with qemu

2012-07-03 Thread Wayne Xia

On 03.07.2012 15:05, xiaw...@linux.vnet.ibm.com wrote:

From: Wenchao Xia

   Qemu system emulator reports only fails that make people confused
about why, when it is invoked with nbd block device tring to connect
qemu-nbd server. In fact qemu will try connect server for several
times but server only accept one connect by default.
   I paid some times to find out why it fails. This patch add special
text to explain how to use it in such case.

Signed-off-by: Wenchao Xia
---
  qemu-nbd.texi |6 ++
  1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/qemu-nbd.texi b/qemu-nbd.texi
index 6955d90..014040a 100644
--- a/qemu-nbd.texi
+++ b/qemu-nbd.texi
@@ -44,6 +44,12 @@ Export QEMU disk image using NBD protocol.
display this help and exit
  @item -V, --version
output version information and exit
+
+  Note: When qemu-nbd was used to export a disk that would be used by QEMU
+block device, -t or --persistent must be set for that QEMU nbd client would try
+connect more than one time. For eg:
+  qemu-nbd ./simple.img -p 10809 -t
+  qemu -hdb nbd:127.0.0.1:10809


It is not accurate.

qemu connect to nbd server not "several" but exactly two times by default.
The first connection it does (it need not be a separate connection
actually, and this, I'd say, a bug in qemu) in order to guess the format

  I think so, actually I planned to patch qemu client side to make it
connect only once, but the disconnect logical lies in general block
layer and changing of that may break other block device logical I guess,
so I gave up of that approach.


of the internal structure inside - be it raw, or qcow, or anything else.
So, if you specify the format of the device explicitly, by using
format=raw, only single connection will be made.

  thanks, that helped me. A bit more question: is there a way to let
nbd client know the image format used by server? qemu-nbd exports
simple_qcow2.img, and qemu saw it as raw block device, is it possible to
get the information in qemu that server is using qcow2 image?



/mjt




--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH v2] Sort the help info shown in monitor at runtime

2011-10-11 Thread Wayne Xia

于 2011-10-11 17:09, Markus Armbruster 写道:

Wayne Xia  writes:


Introduced two queues to save sorted command list in it. As a result, command
help and help info would show a more friendly sorted command list.
For eg:
(qemu)help
acl_add
acl_policy
acl_remove
acl_reset
acl_show
balloon
block_passwd
...
the command list is sorted.

v2: write sorted command list back to original array.

Signed-off-by: Wayne Xia
---
  monitor.c |  113 ++--
  1 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index 31b212a..122f950 100644
--- a/monitor.c
+++ b/monitor.c
@@ -66,6 +66,7 @@
  #include "memory.h"
  #include "qmp-commands.h"
  #include "hmp.h"
+#include "qemu-queue.h"

  //#define DEBUG
  //#define DEBUG_COMPLETION
@@ -128,6 +129,18 @@ typedef struct mon_cmd_t {
  int flags;
  } mon_cmd_t;

+/* queue structure used for runtime sorting */
+struct HelpCmdElem {
+QTAILQ_ENTRY(HelpCmdElem) entry;
+mon_cmd_t cmd_copy;
+};
+
+typedef struct HelpCmdElem HelpCmdElem;
+
+QTAILQ_HEAD(HelpCmdQueue, HelpCmdElem);
+
+typedef struct HelpCmdQueue HelpCmdQueue;
+
  /* file descriptors passed via SCM_RIGHTS */
  typedef struct mon_fd_t mon_fd_t;
  struct mon_fd_t {
@@ -195,8 +208,8 @@ static inline int mon_print_count_get(const Monitor *mon) { 
return 0; }

  static QLIST_HEAD(mon_list, Monitor) mon_list;

-static const mon_cmd_t mon_cmds[];
-static const mon_cmd_t info_cmds[];
+static mon_cmd_t mon_cmds[];
+static mon_cmd_t info_cmds[];

  static const mon_cmd_t qmp_cmds[];
  static const mon_cmd_t qmp_query_cmds[];
@@ -2726,13 +2739,14 @@ int monitor_get_fd(Monitor *mon, const char *fdname)
  return -1;
  }

-static const mon_cmd_t mon_cmds[] = {
+/* mon_cmds and info_cmds would be sorted at runtime */
+static mon_cmd_t mon_cmds[] = {
  #include "hmp-commands.h"
  { NULL, NULL, },
  };

  /* Please update hmp-commands.hx when adding or changing commands */
-static const mon_cmd_t info_cmds[] = {
+static mon_cmd_t info_cmds[] = {
  {
  .name   = "version",
  .args_type  = "",
@@ -5068,6 +5082,94 @@ static void monitor_event(void *opaque, int event)
  }
  }

+static int cmdlist_sortto_queue(const mon_cmd_t *cmdlist,
+HelpCmdQueue **pqueue)
+{
+const mon_cmd_t *cmd = NULL;
+HelpCmdElem *elem = NULL;
+HelpCmdElem *newelem = NULL;
+HelpCmdElem *next = NULL;
+HelpCmdQueue *cmdqueue = NULL;
+int cmpret1, cmpret2;
+
+cmdqueue = g_malloc(sizeof(HelpCmdQueue));


Are you sure this can fail?


+if (cmdqueue == NULL) {
+return -1;
+}
+
+for (cmd = cmdlist; cmd->name != NULL; cmd++) {
+newelem = NULL;
+newelem = g_malloc(sizeof(HelpCmdElem));
+if (newelem == NULL) {
+return -1;
+}
+newelem->cmd_copy = *cmd;
+
+if (QTAILQ_EMPTY(cmdqueue)) {
+QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
+continue;
+}
+QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
+/* search for proper postion */
+cmpret1 = strcmp(cmd->name, elem->cmd_copy.name);
+if (next == NULL) {
+if (cmpret1>= 0) {
+QTAILQ_INSERT_TAIL(cmdqueue, newelem, entry);
+} else {
+QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
+}
+break;
+} else {
+cmpret2 = strcmp(cmd->name, next->cmd_copy.name);
+}
+if ((cmpret1>= 0)&&  (cmpret2<= 0)) {
+QTAILQ_INSERT_AFTER(cmdqueue, elem, newelem, entry);
+break;
+}
+}
+}
+*pqueue = cmdqueue;
+return 1;
+}
+
+static void queue_to_cmdlist(HelpCmdQueue **pqueue,
+mon_cmd_t *cmdlist)
+{
+HelpCmdElem *elem = NULL;
+HelpCmdElem *next = NULL;
+HelpCmdQueue *cmdqueue = *pqueue;
+mon_cmd_t *pcmdlist = cmdlist;
+
+QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
+*(pcmdlist++) = elem->cmd_copy;
+QTAILQ_REMOVE(cmdqueue, elem, entry);
+g_free(elem);
+}
+g_free(cmdqueue);
+*pqueue = NULL;
+}
+
+static void sortcmdlist(void)
+{
+HelpCmdQueue *mon_cmds_queue = NULL;
+HelpCmdQueue *info_cmds_queue = NULL;
+int ret;
+
+ret = cmdlist_sortto_queue(mon_cmds,&mon_cmds_queue);
+if (ret<  0) {
+printf("error in initilize mon cmd queue, return is %d.\n", ret);


"initialize"

Error messages go to stderr.  Best use error_report().


right.


+return;
+}
+queue_to_cmdlist(&mon_cmds_queue, mon_cmds);
+
+ret = cmdlist_sortto_queue(info_cmds,&info_cmds_queue);
+if (ret<  0) {
+printf("error in initilize info cmd queue, 

[Qemu-devel] [PATCH v3] Sort the help info shown in monitor at runtime

2011-10-11 Thread Wayne Xia
This patch would try sort the command list in monitor at runtime. As a result,
command help and help info would show a more friendly sorted command list.
For eg:
(qemu)help
acl_add
acl_policy
acl_remove
acl_reset
acl_show
balloon
block_passwd
...
the command list is sorted.

v3: using qsort function to sort the command list.

Signed-off-by: Wayne Xia 
---
 monitor.c |   30 ++
 1 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index 31b212a..a172167 100644
--- a/monitor.c
+++ b/monitor.c
@@ -195,8 +195,8 @@ static inline int mon_print_count_get(const Monitor *mon) { 
return 0; }
 
 static QLIST_HEAD(mon_list, Monitor) mon_list;
 
-static const mon_cmd_t mon_cmds[];
-static const mon_cmd_t info_cmds[];
+static mon_cmd_t mon_cmds[];
+static mon_cmd_t info_cmds[];
 
 static const mon_cmd_t qmp_cmds[];
 static const mon_cmd_t qmp_query_cmds[];
@@ -2726,13 +2726,14 @@ int monitor_get_fd(Monitor *mon, const char *fdname)
 return -1;
 }
 
-static const mon_cmd_t mon_cmds[] = {
+/* mon_cmds and info_cmds would be sorted at runtime */
+static mon_cmd_t mon_cmds[] = {
 #include "hmp-commands.h"
 { NULL, NULL, },
 };
 
 /* Please update hmp-commands.hx when adding or changing commands */
-static const mon_cmd_t info_cmds[] = {
+static mon_cmd_t info_cmds[] = {
 {
 .name   = "version",
 .args_type  = "",
@@ -5068,6 +5069,25 @@ static void monitor_event(void *opaque, int event)
 }
 }
 
+static int
+compare_mon_cmd(const void *a, const void *b)
+{
+return strcmp(((const mon_cmd_t *)a)->name,
+((const mon_cmd_t *)b)->name);
+}
+
+static void sortcmdlist(void)
+{
+int array_num;
+int elem_size = sizeof(mon_cmd_t);
+
+array_num = sizeof(mon_cmds)/elem_size-1;
+qsort((void *)mon_cmds, array_num, elem_size, compare_mon_cmd);
+
+array_num = sizeof(info_cmds)/elem_size-1;
+qsort((void *)info_cmds, array_num, elem_size, compare_mon_cmd);
+}
+
 
 /*
  * Local variables:
@@ -5110,6 +5130,8 @@ void monitor_init(CharDriverState *chr, int flags)
 QLIST_INSERT_HEAD(&mon_list, mon, entry);
 if (!default_mon || (flags & MONITOR_IS_DEFAULT))
 default_mon = mon;
+
+sortcmdlist();
 }
 
 static void bdrv_password_cb(Monitor *mon, const char *password, void *opaque)
-- 
1.7.6




Re: [Qemu-devel] [PATCH 0/1] Make the help info more friendly in monitor

2011-10-11 Thread Wayne Xia

于 2011-10-4 21:55, Luiz Capitulino 写道:

On Wed, 28 Sep 2011 10:16:19 +0100
Stefan Hajnoczi  wrote:


On Wed, Sep 28, 2011 at 10:00 AM, Wayne Xia  wrote:

During my test, I found it inconvenient when I type "help" or "help info",
because the information was shown without orderliness. This patch would just
show the help information in sorted order.

For eg:
(qemu)help
acl_add
acl_policy
acl_remove
acl_reset
acl_show
balloon
block_passwd
...
the command list is sorted.

Wayne Xia (1):
  Sort the help info shown in monitor

  monitor.c |   97 ++--
  1 files changed, 93 insertions(+), 4 deletions(-)


This is a nice idea.  We could keep hmp/qmp-commands.hx in sorted
order but that prevents us from keeping related commands together in
those files (and the generated documentation?).  So sorting at
run-time makes sense.


The info help command reads from hmp-commands.hx and the info_cmds array,
I would prefer to get those sorted.


thanks, sorting info_cmds array seems more reasonable for that related
things would be kept here in one place not another queue, would change
in next patch.


--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




[Qemu-devel] [PATCH v2] Sort the help info shown in monitor at runtime

2011-10-11 Thread Wayne Xia
Introduced two queues to save sorted command list in it. As a result, command
help and help info would show a more friendly sorted command list.
For eg:
(qemu)help
acl_add
acl_policy
acl_remove
acl_reset
acl_show
balloon
block_passwd
...
the command list is sorted.

v2: write sorted command list back to original array.

Signed-off-by: Wayne Xia 
---
 monitor.c |  113 ++--
 1 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index 31b212a..122f950 100644
--- a/monitor.c
+++ b/monitor.c
@@ -66,6 +66,7 @@
 #include "memory.h"
 #include "qmp-commands.h"
 #include "hmp.h"
+#include "qemu-queue.h"
 
 //#define DEBUG
 //#define DEBUG_COMPLETION
@@ -128,6 +129,18 @@ typedef struct mon_cmd_t {
 int flags;
 } mon_cmd_t;
 
+/* queue structure used for runtime sorting */
+struct HelpCmdElem {
+QTAILQ_ENTRY(HelpCmdElem) entry;
+mon_cmd_t cmd_copy;
+};
+
+typedef struct HelpCmdElem HelpCmdElem;
+
+QTAILQ_HEAD(HelpCmdQueue, HelpCmdElem);
+
+typedef struct HelpCmdQueue HelpCmdQueue;
+
 /* file descriptors passed via SCM_RIGHTS */
 typedef struct mon_fd_t mon_fd_t;
 struct mon_fd_t {
@@ -195,8 +208,8 @@ static inline int mon_print_count_get(const Monitor *mon) { 
return 0; }
 
 static QLIST_HEAD(mon_list, Monitor) mon_list;
 
-static const mon_cmd_t mon_cmds[];
-static const mon_cmd_t info_cmds[];
+static mon_cmd_t mon_cmds[];
+static mon_cmd_t info_cmds[];
 
 static const mon_cmd_t qmp_cmds[];
 static const mon_cmd_t qmp_query_cmds[];
@@ -2726,13 +2739,14 @@ int monitor_get_fd(Monitor *mon, const char *fdname)
 return -1;
 }
 
-static const mon_cmd_t mon_cmds[] = {
+/* mon_cmds and info_cmds would be sorted at runtime */
+static mon_cmd_t mon_cmds[] = {
 #include "hmp-commands.h"
 { NULL, NULL, },
 };
 
 /* Please update hmp-commands.hx when adding or changing commands */
-static const mon_cmd_t info_cmds[] = {
+static mon_cmd_t info_cmds[] = {
 {
 .name   = "version",
 .args_type  = "",
@@ -5068,6 +5082,94 @@ static void monitor_event(void *opaque, int event)
 }
 }
 
+static int cmdlist_sortto_queue(const mon_cmd_t *cmdlist,
+HelpCmdQueue **pqueue)
+{
+const mon_cmd_t *cmd = NULL;
+HelpCmdElem *elem = NULL;
+HelpCmdElem *newelem = NULL;
+HelpCmdElem *next = NULL;
+HelpCmdQueue *cmdqueue = NULL;
+int cmpret1, cmpret2;
+
+cmdqueue = g_malloc(sizeof(HelpCmdQueue));
+if (cmdqueue == NULL) {
+return -1;
+}
+
+for (cmd = cmdlist; cmd->name != NULL; cmd++) {
+newelem = NULL;
+newelem = g_malloc(sizeof(HelpCmdElem));
+if (newelem == NULL) {
+return -1;
+}
+newelem->cmd_copy = *cmd;
+
+if (QTAILQ_EMPTY(cmdqueue)) {
+QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
+continue;
+}
+QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
+/* search for proper postion */
+cmpret1 = strcmp(cmd->name, elem->cmd_copy.name);
+if (next == NULL) {
+if (cmpret1 >= 0) {
+QTAILQ_INSERT_TAIL(cmdqueue, newelem, entry);
+} else {
+QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
+}
+break;
+} else {
+cmpret2 = strcmp(cmd->name, next->cmd_copy.name);
+}
+if ((cmpret1 >= 0) && (cmpret2 <= 0)) {
+QTAILQ_INSERT_AFTER(cmdqueue, elem, newelem, entry);
+break;
+}
+}
+}
+*pqueue = cmdqueue;
+return 1;
+}
+
+static void queue_to_cmdlist(HelpCmdQueue **pqueue,
+mon_cmd_t *cmdlist)
+{
+HelpCmdElem *elem = NULL;
+HelpCmdElem *next = NULL;
+HelpCmdQueue *cmdqueue = *pqueue;
+mon_cmd_t *pcmdlist = cmdlist;
+
+QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
+*(pcmdlist++) = elem->cmd_copy;
+QTAILQ_REMOVE(cmdqueue, elem, entry);
+g_free(elem);
+}
+g_free(cmdqueue);
+*pqueue = NULL;
+}
+
+static void sortcmdlist(void)
+{
+HelpCmdQueue *mon_cmds_queue = NULL;
+HelpCmdQueue *info_cmds_queue = NULL;
+int ret;
+
+ret = cmdlist_sortto_queue(mon_cmds, &mon_cmds_queue);
+if (ret < 0) {
+printf("error in initilize mon cmd queue, return is %d.\n", ret);
+return;
+}
+queue_to_cmdlist(&mon_cmds_queue, mon_cmds);
+
+ret = cmdlist_sortto_queue(info_cmds, &info_cmds_queue);
+if (ret < 0) {
+printf("error in initilize info cmd queue, return is %d.\n", ret);
+return;
+}
+queue_to_cmdlist(&info_cmds_queue, info_cmds);
+}
+
 
 /*
  * Local variables:
@@ -5110,6 +5212,9 @@ void monitor_init(CharDriverS

Re: [Qemu-devel] [RFC] potential risk for macro QTAILQ_INSERT_BEFORE

2011-09-28 Thread Wayne Xia
于 2011-9-28 16:43, Jan Kiszka 写道:
> On 2011-09-28 05:38, Wayne Xia wrote:
>>  Hi, during my coding, I found macro a bit different from other
>> QTAIL macros.
>>
>> QTAILQ_INSERT_AFTER was defined as:
>> ---
>> #define QTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
>>  if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
>>  (elm)->field.tqe_next->field.tqe_prev = \
>>  &(elm)->field.tqe_next; \
>>  else\
>>  (head)->tqh_last =&(elm)->field.tqe_next;  \
>>  (listelm)->field.tqe_next = (elm);  \
>>  (elm)->field.tqe_prev =&(listelm)->field.tqe_next; \
>> } while (/*CONSTCOND*/0)
>> -
>>   QTAILQ_INSERT_BEFORE is defined as following:
>>
>> #define QTAILQ_INSERT_BEFORE(listelm, elm, field) do {
>>  (elm)->field.tqe_prev = (listelm)->field.tqe_prev;  \
>>  (elm)->field.tqe_next = (listelm);  \
>>  *(listelm)->field.tqe_prev = (elm); \
>>  (listelm)->field.tqe_prev =&(elm)->field.tqe_next; \
>> } while (/*CONSTCOND*/0)
>> --
>>
>>  It did not take care of "head" as QTAILQ_INSERT_AFTER did, so I am
>> wondering what would happen if I use QTAILQ_INSERT_BEFORE to insert one
>> element to a queue that have only one element in it, would it happen
>> that the queue head pointer is not updated and the real first element
>> is lost? Currently some codes in qemu have used this macro.
> 
> The code is fine: a QTAILQ head consists of a dummy entry element that
> looks for the first element as if a normal element would precede it. In
> contrast, there is no dummy "end element", the last one just points to
> NULL. Therefore we need to handle this separately.

Thanks Jan, made a test program showing the macro is OK, the dummy
element works like a magic.

> 
> Jan
> 


-- 
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




[Qemu-devel] [PATCH 1/1] Sort the help info shown in monitor

2011-09-28 Thread Wayne Xia
Introduced two queues to save sorted command list in it, and dump commands
from them. As a result, command help and help info would show a more friendly
sorted command list.

Signed-off-by: Wayne Xia 
---
 monitor.c |   97 ++--
 1 files changed, 93 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index 8ec2c5e..88938d6 100644
--- a/monitor.c
+++ b/monitor.c
@@ -63,6 +63,7 @@
 #endif
 #include "trace/control.h"
 #include "ui/qemu-spice.h"
+#include "qemu-queue.h"
 
 //#define DEBUG
 //#define DEBUG_COMPLETION
@@ -124,6 +125,17 @@ typedef struct mon_cmd_t {
 int flags;
 } mon_cmd_t;
 
+struct HelpCmdElem {
+QTAILQ_ENTRY(HelpCmdElem) entry;
+const mon_cmd_t *cmd;
+};
+
+typedef struct HelpCmdElem HelpCmdElem;
+
+QTAILQ_HEAD(HelpCmdQueue, HelpCmdElem);
+
+typedef struct HelpCmdQueue HelpCmdQueue;
+
 /* file descriptors passed via SCM_RIGHTS */
 typedef struct mon_fd_t mon_fd_t;
 struct mon_fd_t {
@@ -193,6 +205,8 @@ static QLIST_HEAD(mon_list, Monitor) mon_list;
 
 static const mon_cmd_t mon_cmds[];
 static const mon_cmd_t info_cmds[];
+static HelpCmdQueue *mon_cmds_queue;
+static HelpCmdQueue *info_cmds_queue;
 
 static const mon_cmd_t qmp_cmds[];
 static const mon_cmd_t qmp_query_cmds[];
@@ -560,12 +574,15 @@ static int compare_cmd(const char *name, const char *list)
 return 0;
 }
 
-static void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds,
+static void help_cmd_dump_queue(Monitor *mon, const HelpCmdQueue *queue,
   const char *prefix, const char *name)
 {
 const mon_cmd_t *cmd;
+HelpCmdElem *elem = NULL;
+HelpCmdElem *next = NULL;
 
-for(cmd = cmds; cmd->name != NULL; cmd++) {
+QTAILQ_FOREACH_SAFE(elem, queue, entry, next) {
+cmd = elem->cmd;
 if (!name || !strcmp(name, cmd->name))
 monitor_printf(mon, "%s%s %s -- %s\n", prefix, cmd->name,
cmd->params, cmd->help);
@@ -575,9 +592,9 @@ static void help_cmd_dump(Monitor *mon, const mon_cmd_t 
*cmds,
 static void help_cmd(Monitor *mon, const char *name)
 {
 if (name && !strcmp(name, "info")) {
-help_cmd_dump(mon, info_cmds, "info ", NULL);
+help_cmd_dump_queue(mon, info_cmds_queue, "info ", NULL);
 } else {
-help_cmd_dump(mon, mon_cmds, "", name);
+help_cmd_dump_queue(mon, mon_cmds_queue, "", name);
 if (name && !strcmp(name, "log")) {
 const CPULogItem *item;
 monitor_printf(mon, "Log items (comma separated):\n");
@@ -5275,6 +5292,76 @@ static void monitor_event(void *opaque, int event)
  * End:
  */
 
+static int cmdlist_sortto_queue(const mon_cmd_t *cmdlist,
+HelpCmdQueue **pqueue)
+{
+const mon_cmd_t *cmd = NULL;
+HelpCmdElem *elem = NULL;
+HelpCmdElem *newelem = NULL;
+HelpCmdElem *next = NULL;
+HelpCmdQueue *cmdqueue = NULL;
+int cmpret1, cmpret2;
+
+if (*pqueue != NULL) {
+/* queue already allocated.
+because the cmd contents would not change when reboot, so skip */
+return 0;
+}
+cmdqueue = g_malloc(sizeof(HelpCmdQueue));
+if (cmdqueue == NULL) {
+return -1;
+}
+QTAILQ_INIT(cmdqueue);
+
+for (cmd = cmdlist; cmd->name != NULL; cmd++) {
+newelem = NULL;
+newelem = g_malloc(sizeof(HelpCmdElem));
+if (newelem == NULL) {
+return -1;
+}
+newelem->cmd = cmd;
+
+if (QTAILQ_EMPTY(cmdqueue)) {
+QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
+continue;
+}
+QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
+/* search for proper postion */
+cmpret1 = strcmp(cmd->name, elem->cmd->name);
+if (next == NULL) {
+if (cmpret1 >= 0) {
+QTAILQ_INSERT_TAIL(cmdqueue, newelem, entry);
+} else {
+QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
+}
+break;
+} else {
+cmpret2 = strcmp(cmd->name, next->cmd->name);
+}
+if ((cmpret1 >= 0) && (cmpret2 <= 0)) {
+QTAILQ_INSERT_AFTER(cmdqueue, elem, newelem, entry);
+break;
+}
+}
+}
+*pqueue = cmdqueue;
+return 1;
+}
+
+static int cmd_queue_init(void)
+{
+int ret;
+ret = cmdlist_sortto_queue(mon_cmds, &mon_cmds_queue);
+if (ret < 0) {
+printf("error in initilize mon cmd queue, return is %d.\n", ret);
+}
+ret = cmdlist_sortto_queue(info_cmds, &info_cmds_queue);
+if (ret < 0) {
+printf("error in initilize info cmd queue, return is %d.\n", ret);
+}
+retur

[Qemu-devel] [PATCH 0/1] Make the help info more friendly in monitor

2011-09-28 Thread Wayne Xia
During my test, I found it inconvenient when I type "help" or "help info",
because the information was shown without orderliness. This patch would just
show the help information in sorted order.

For eg:
(qemu)help
acl_add
acl_policy
acl_remove
acl_reset
acl_show
balloon
block_passwd
...
the command list is sorted.

Wayne Xia (1):
  Sort the help info shown in monitor

 monitor.c |   97 ++--
 1 files changed, 93 insertions(+), 4 deletions(-)

-- 
1.7.6





[Qemu-devel] [RFC] potential risk for macro QTAILQ_INSERT_BEFORE

2011-09-27 Thread Wayne Xia
Hi, during my coding, I found macro a bit different from other
QTAIL macros.

QTAILQ_INSERT_AFTER was defined as:
---
#define QTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
(elm)->field.tqe_next->field.tqe_prev = \
&(elm)->field.tqe_next; \
else\
(head)->tqh_last = &(elm)->field.tqe_next;  \
(listelm)->field.tqe_next = (elm);  \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
-
 QTAILQ_INSERT_BEFORE is defined as following:

#define QTAILQ_INSERT_BEFORE(listelm, elm, field) do {
(elm)->field.tqe_prev = (listelm)->field.tqe_prev;  \
(elm)->field.tqe_next = (listelm);  \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (/*CONSTCOND*/0)
--

It did not take care of "head" as QTAILQ_INSERT_AFTER did, so I am
wondering what would happen if I use QTAILQ_INSERT_BEFORE to insert one
element to a queue that have only one element in it, would it happen
that the queue head pointer is not updated and the real first element
is lost? Currently some codes in qemu have used this macro.



-- 
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH v2] memory: simple memory tree printer

2011-09-26 Thread Wayne Xia
 TARGET_I386
+monitor_printf(mon, "I/O\n");
+mtree_print_mr(mon, address_space_io.root, 0, 0, ml_head);
+#endif
+g_free(ml_head2);
+g_free(ml_head);
+}
diff --git a/memory.h b/memory.h
index 06b83ae..09d8e29 100644
--- a/memory.h
+++ b/memory.h
@@ -500,6 +500,8 @@ void memory_region_transaction_begin(void);
   */
  void memory_region_transaction_commit(void);

+void mtree_info(Monitor *mon);
+
  #endif

  #endif
diff --git a/monitor.c b/monitor.c
index 8ec2c5e..f86fff6 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2978,6 +2978,13 @@ static const mon_cmd_t info_cmds[] = {
  },
  #endif
  {
+.name   = "mtree",
+.args_type  = "",
+.params = "",
+.help   = "show memory tree",
+.mhandler.info = mtree_info,
+},
+{
  .name   = "jit",
  .args_type  = "",
  .params = "",



--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH 7/7] migration: qemu_savevm_iterate has three return values

2011-09-22 Thread Wayne Xia
于 2011-9-20 21:24, Juan Quintela 写道:
> We were retrying when there was one error, entering a loop.
> 
> Signed-off-by: Juan Quintela
> ---
>   migration.c |6 +-
>   1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/migration.c b/migration.c
> index 7f8928a..0baed23 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -362,6 +362,7 @@ void migrate_fd_connect(FdMigrationState *s)
>   void migrate_fd_put_ready(void *opaque)
>   {
>   FdMigrationState *s = opaque;
> +int ret;
> 
>   if (s->state != MIG_STATE_ACTIVE) {
>   DPRINTF("put_ready returning because of non-active state\n");
> @@ -369,7 +370,10 @@ void migrate_fd_put_ready(void *opaque)
>   }
> 
>   DPRINTF("iterate\n");
> -if (qemu_savevm_state_iterate(s->mon, s->file) == 1) {
> +ret = qemu_savevm_state_iterate(s->mon, s->file);
> +if (ret == -1) {
> +migrate_fd_error(s);
> +} else if (ret == 1) {
>   int old_vm_running = vm_running;
> 
>   DPRINTF("done iterating\n");
Maybe macro could be used in the situation that more than 2 possible
types of value may return.


-- 
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH v6] showing a splash picture when start

2011-07-27 Thread Wayne Xia

Thanks, following is my comments.


On 07/10/2011 05:09 AM, Wayne Xia wrote:

Added options to let qemu transfer two configuration files to bios:
"bootsplash.bmp" and "etc/boot-menu-wait", which could be specified by
command
-boot splash=P,splash-time=T
P is jpg/bmp file name or an absolute path, T have a max value of
0x, unit
is ms. With these two options, if user invoke qemu with menu=on
option, then
a splash picture would be showed in a given time. For example:
qemu -boot menu=on,splash=/root/boot.bmp,splash-time=5000
would make boot.bmp shown as a brand with 5 seconds in the booting up
process.
This feature need the new seabios's support, which could be got from git.


Please include documentation in qemu-doc.texi including information on
what image formats are supported and what restrictions are present (for
instance 24-bit depth bitmaps with what resolution?).

Regards,

Anthony Liguori


added the information in qemu-options.hx.



Signed-off-by: Wayne Xia
---
hw/fw_cfg.c | 140
-
qemu-config.c | 27 +++
sysemu.h | 3 +
vl.c | 17 +++-
4 files changed, 185 insertions(+), 2 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 85c8c3c..434fc96 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
#include "isa.h"
#include "fw_cfg.h"
#include "sysbus.h"
+#include "qemu-error.h"

/* debug firmware config */
//#define DEBUG_FW_CFG
@@ -56,6 +57,143 @@ struct FWCfgState {
Notifier machine_ready;
};

+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int
*file_typep)
+{
+ FILE *fp = NULL;
+ int fop_ret;
+ int file_size;
+ int file_type = -1;
+ unsigned char buf[2] = {0, 0};
+ unsigned int filehead_value = 0;
+ int bmp_bpp;
+
+ fp = fopen(filename, "rb");
+ if (fp == NULL) {
+ error_report("failed to open file '%s'.", filename);
+ return fp;
+ }
+ /* check file size */
+ fseek(fp, 0L, SEEK_END);
+ file_size = ftell(fp);
+ if (file_size< 2) {
+ error_report("file size is less than 2 bytes '%s'.", filename);
+ fclose(fp);
+ fp = NULL;
+ return fp;
+ }
+ /* check magic ID */
+ fseek(fp, 0L, SEEK_SET);
+ fop_ret = fread(buf, 1, 2, fp);
+ filehead_value = (buf[0] + (buf[1]<< 8))& 0x;
+ if (filehead_value == 0xd8ff) {
+ file_type = JPG_FILE;
+ } else {
+ if (filehead_value == 0x4d42) {
+ file_type = BMP_FILE;
+ }
+ }
+ if (file_type< 0) {
+ error_report("'%s' not jpg/bmp file,head:0x%x.",
+ filename, filehead_value);
+ fclose(fp);
+ fp = NULL;
+ return fp;
+ }
+ /* check BMP bpp */
+ if (file_type == BMP_FILE) {
+ fseek(fp, 28, SEEK_SET);
+ fop_ret = fread(buf, 1, 2, fp);
+ bmp_bpp = (buf[0] + (buf[1]<< 8))& 0x;
+ if (bmp_bpp != 24) {
+ error_report("only 24bpp bmp file is supported.");
+ fclose(fp);
+ fp = NULL;
+ return fp;
+ }
+ }
+ /* return values */
+ *file_sizep = file_size;
+ *file_typep = file_type;
+ return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+ int boot_splash_time = -1;
+ const char *boot_splash_filename = NULL;
+ char *p;
+ char *filename;
+ FILE *fp;
+ int fop_ret;
+ int file_size;
+ int file_type = -1;
+ const char *temp;
+
+ /* get user configuration */
+ QemuOptsList *plist = qemu_find_opts("boot-opts");
+ QemuOpts *opts = QTAILQ_FIRST(&plist->head);
+ if (opts != NULL) {
+ temp = qemu_opt_get(opts, "splash");
+ if (temp != NULL) {
+ boot_splash_filename = temp;
+ }
+ temp = qemu_opt_get(opts, "splash-time");
+ if (temp != NULL) {
+ p = (char *)temp;
+ boot_splash_time = strtol(p, (char **)&p, 10);
+ }
+ }
+
+ /* insert splash time if user configurated */
+ if (boot_splash_time>= 0) {
+ /* validate the input */
+ if (boot_splash_time> 0x) {
+ error_report("splash time is big than 65535, force it to 65535.");
+ boot_splash_time = 0x;
+ }
+ /* use little endian format */
+ qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time& 0xff);
+ qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time>> 8)& 0xff);
+ fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+ }
+
+ /* insert splash file if user configurated */
+ if (boot_splash_filename != NULL) {
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+ if (filename == NULL) {
+ error_report("failed to find file '%s'.", boot_splash_filename);
+ return;
+ }
+ /* probing the file */
+ fp = probe_splashfile(filename,&file_size,&file_type);
+ if (fp == NULL) {
+ qemu_free(filename);
+ return;
+ }
+ /* loading file data */
+ if (boot_splash_filedata != NULL) {
+ qemu_free(boot_splash_filedata);
+ }
+ boot_splash_filedata = qemu_malloc(file_size);
+ boot_splash_filedata_size = file_size;
+ fseek(fp, 0L, SEEK_SET);
+ fop_ret = fread(boot_splash_filedata, 1, file_size, fp);
+ 

[Qemu-devel] [PATCH v7] showing a splash picture when start

2011-07-27 Thread Wayne Xia
From: wayne 

Added options to let qemu transfer two configuration files to bios:
"bootsplash.bmp" and "etc/boot-menu-wait", which could be specified by command
-boot splash=P,splash-time=T
P is jpg/bmp file name or an absolute path, T have a max value of 0x, unit
is ms. With these two options, if user invoke qemu with menu=on option, then
a splash picture would be showed in a given time. For example:
qemu -boot menu=on,splash=/root/boot.bmp,splash-time=5000
would make boot.bmp shown as a brand with 5 seconds in the booting up process.
This feature need the new seabios's support, which could be got from git.

Signed-off-by: Wayne Xia 
---
 hw/fw_cfg.c |  140 ++-
 qemu-config.c   |   27 +++
 qemu-options.hx |   16 ++-
 sysemu.h|3 +
 vl.c|   17 ++-
 5 files changed, 199 insertions(+), 4 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 34e7526..a29db90 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
 #include "isa.h"
 #include "fw_cfg.h"
 #include "sysbus.h"
+#include "qemu-error.h"
 
 /* debug firmware config */
 //#define DEBUG_FW_CFG
@@ -56,6 +57,143 @@ struct FWCfgState {
 Notifier machine_ready;
 };
 
+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+{
+FILE *fp = NULL;
+int fop_ret;
+int file_size;
+int file_type = -1;
+unsigned char buf[2] = {0, 0};
+unsigned int filehead_value = 0;
+int bmp_bpp;
+
+fp = fopen(filename, "rb");
+if (fp == NULL) {
+error_report("failed to open file '%s'.", filename);
+return fp;
+}
+/* check file size */
+fseek(fp, 0L, SEEK_END);
+file_size = ftell(fp);
+if (file_size < 2) {
+error_report("file size is less than 2 bytes '%s'.", filename);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check magic ID */
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+filehead_value = (buf[0] + (buf[1] << 8)) & 0x;
+if (filehead_value == 0xd8ff) {
+file_type = JPG_FILE;
+} else {
+if (filehead_value == 0x4d42) {
+file_type = BMP_FILE;
+}
+}
+if (file_type < 0) {
+error_report("'%s' not jpg/bmp file,head:0x%x.",
+ filename, filehead_value);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check BMP bpp */
+if (file_type == BMP_FILE) {
+fseek(fp, 28, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+bmp_bpp = (buf[0] + (buf[1] << 8)) & 0x;
+if (bmp_bpp != 24) {
+error_report("only 24bpp bmp file is supported.");
+fclose(fp);
+fp = NULL;
+return fp;
+}
+}
+/* return values */
+*file_sizep = file_size;
+*file_typep = file_type;
+return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+int boot_splash_time = -1;
+const char *boot_splash_filename = NULL;
+char *p;
+char *filename;
+FILE *fp;
+int fop_ret;
+int file_size;
+int file_type = -1;
+const char *temp;
+
+/* get user configuration */
+QemuOptsList *plist = qemu_find_opts("boot-opts");
+QemuOpts *opts = QTAILQ_FIRST(&plist->head);
+if (opts != NULL) {
+temp = qemu_opt_get(opts, "splash");
+if (temp != NULL) {
+boot_splash_filename = temp;
+}
+temp = qemu_opt_get(opts, "splash-time");
+if (temp != NULL) {
+p = (char *)temp;
+boot_splash_time = strtol(p, (char **)&p, 10);
+}
+}
+
+/* insert splash time if user configurated */
+if (boot_splash_time >= 0) {
+/* validate the input */
+if (boot_splash_time > 0x) {
+error_report("splash time is big than 65535, force it to 65535.");
+boot_splash_time = 0x;
+}
+/* use little endian format */
+qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
+qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
+fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+}
+
+/* insert splash file if user configurated */
+if (boot_splash_filename != NULL) {
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+if (filename == NULL) {
+error_report("failed to find file '%s'.", boot_splash_filename);
+return;
+}
+/* probing the file */
+fp = probe_splashfile(filename, &file_size, &file_type);
+

[Qemu-devel] [PATCH v7] showing a splash picture when start

2011-07-26 Thread Wayne Xia
From: wayne 

Added options to let qemu transfer two configuration files to bios:
"bootsplash.bmp" and "etc/boot-menu-wait", which could be specified by command
-boot splash=P,splash-time=T
P is jpg/bmp file name or an absolute path, T have a max value of 0x, unit
is ms. With these two options, if user invoke qemu with menu=on option, then
a splash picture would be showed in a given time. For example:
qemu -boot menu=on,splash=/root/boot.bmp,splash-time=5000
would make boot.bmp shown as a brand with 5 seconds in the booting up process.
This feature need the new seabios's support, which could be got from git.

Signed-off-by: Wayne Xia 
---
 hw/fw_cfg.c |  140 ++-
 qemu-config.c   |   27 +++
 qemu-options.hx |   16 ++-
 sysemu.h|3 +
 vl.c|   17 ++-
 5 files changed, 199 insertions(+), 4 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 34e7526..a29db90 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
 #include "isa.h"
 #include "fw_cfg.h"
 #include "sysbus.h"
+#include "qemu-error.h"
 
 /* debug firmware config */
 //#define DEBUG_FW_CFG
@@ -56,6 +57,143 @@ struct FWCfgState {
 Notifier machine_ready;
 };
 
+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+{
+FILE *fp = NULL;
+int fop_ret;
+int file_size;
+int file_type = -1;
+unsigned char buf[2] = {0, 0};
+unsigned int filehead_value = 0;
+int bmp_bpp;
+
+fp = fopen(filename, "rb");
+if (fp == NULL) {
+error_report("failed to open file '%s'.", filename);
+return fp;
+}
+/* check file size */
+fseek(fp, 0L, SEEK_END);
+file_size = ftell(fp);
+if (file_size < 2) {
+error_report("file size is less than 2 bytes '%s'.", filename);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check magic ID */
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+filehead_value = (buf[0] + (buf[1] << 8)) & 0x;
+if (filehead_value == 0xd8ff) {
+file_type = JPG_FILE;
+} else {
+if (filehead_value == 0x4d42) {
+file_type = BMP_FILE;
+}
+}
+if (file_type < 0) {
+error_report("'%s' not jpg/bmp file,head:0x%x.",
+ filename, filehead_value);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check BMP bpp */
+if (file_type == BMP_FILE) {
+fseek(fp, 28, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+bmp_bpp = (buf[0] + (buf[1] << 8)) & 0x;
+if (bmp_bpp != 24) {
+error_report("only 24bpp bmp file is supported.");
+fclose(fp);
+fp = NULL;
+return fp;
+}
+}
+/* return values */
+*file_sizep = file_size;
+*file_typep = file_type;
+return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+int boot_splash_time = -1;
+const char *boot_splash_filename = NULL;
+char *p;
+char *filename;
+FILE *fp;
+int fop_ret;
+int file_size;
+int file_type = -1;
+const char *temp;
+
+/* get user configuration */
+QemuOptsList *plist = qemu_find_opts("boot-opts");
+QemuOpts *opts = QTAILQ_FIRST(&plist->head);
+if (opts != NULL) {
+temp = qemu_opt_get(opts, "splash");
+if (temp != NULL) {
+boot_splash_filename = temp;
+}
+temp = qemu_opt_get(opts, "splash-time");
+if (temp != NULL) {
+p = (char *)temp;
+boot_splash_time = strtol(p, (char **)&p, 10);
+}
+}
+
+/* insert splash time if user configurated */
+if (boot_splash_time >= 0) {
+/* validate the input */
+if (boot_splash_time > 0x) {
+error_report("splash time is big than 65535, force it to 65535.");
+boot_splash_time = 0x;
+}
+/* use little endian format */
+qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
+qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
+fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+}
+
+/* insert splash file if user configurated */
+if (boot_splash_filename != NULL) {
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+if (filename == NULL) {
+error_report("failed to find file '%s'.", boot_splash_filename);
+return;
+}
+/* probing the file */
+fp = probe_splashfile(filename, &file_size, &file_type);
+

[Qemu-devel] [PATCH v6] showing a splash picture when start

2011-07-10 Thread Wayne Xia
Added options to let qemu transfer two configuration files to bios:
"bootsplash.bmp" and "etc/boot-menu-wait", which could be specified by command
-boot splash=P,splash-time=T
P is jpg/bmp file name or an absolute path, T have a max value of 0x, unit 
is ms. With these two options, if user invoke qemu with menu=on option, then 
a splash picture would be showed in a given time. For example:
qemu -boot menu=on,splash=/root/boot.bmp,splash-time=5000
would make boot.bmp shown as a brand with 5 seconds in the booting up process.
This feature need the new seabios's support, which could be got from git.

Signed-off-by: Wayne Xia 
---
 hw/fw_cfg.c   |  140 -
 qemu-config.c |   27 +++
 sysemu.h  |3 +
 vl.c  |   17 +++-
 4 files changed, 185 insertions(+), 2 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 85c8c3c..434fc96 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
 #include "isa.h"
 #include "fw_cfg.h"
 #include "sysbus.h"
+#include "qemu-error.h"
 
 /* debug firmware config */
 //#define DEBUG_FW_CFG
@@ -56,6 +57,143 @@ struct FWCfgState {
 Notifier machine_ready;
 };
 
+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+{
+FILE *fp = NULL;
+int fop_ret;
+int file_size;
+int file_type = -1;
+unsigned char buf[2] = {0, 0};
+unsigned int filehead_value = 0;
+int bmp_bpp;
+
+fp = fopen(filename, "rb");
+if (fp == NULL) {
+error_report("failed to open file '%s'.", filename);
+return fp;
+}
+/* check file size */
+fseek(fp, 0L, SEEK_END);
+file_size = ftell(fp);
+if (file_size < 2) {
+error_report("file size is less than 2 bytes '%s'.", filename);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check magic ID */
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+filehead_value = (buf[0] + (buf[1] << 8)) & 0x;
+if (filehead_value == 0xd8ff) {
+file_type = JPG_FILE;
+} else {
+if (filehead_value == 0x4d42) {
+file_type = BMP_FILE;
+}
+}
+if (file_type < 0) {
+error_report("'%s' not jpg/bmp file,head:0x%x.",
+ filename, filehead_value);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check BMP bpp */
+if (file_type == BMP_FILE) {
+fseek(fp, 28, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+bmp_bpp = (buf[0] + (buf[1] << 8)) & 0x;
+if (bmp_bpp != 24) {
+error_report("only 24bpp bmp file is supported.");
+fclose(fp);
+fp = NULL;
+return fp;
+}
+}
+/* return values */
+*file_sizep = file_size;
+*file_typep = file_type;
+return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+int boot_splash_time = -1;
+const char *boot_splash_filename = NULL;
+char *p;
+char *filename;
+FILE *fp;
+int fop_ret;
+int file_size;
+int file_type = -1;
+const char *temp;
+
+/* get user configuration */
+QemuOptsList *plist = qemu_find_opts("boot-opts");
+QemuOpts *opts = QTAILQ_FIRST(&plist->head);
+if (opts != NULL) {
+temp = qemu_opt_get(opts, "splash");
+if (temp != NULL) {
+boot_splash_filename = temp;
+}
+temp = qemu_opt_get(opts, "splash-time");
+if (temp != NULL) {
+p = (char *)temp;
+boot_splash_time = strtol(p, (char **)&p, 10);
+}
+}
+
+/* insert splash time if user configurated */
+if (boot_splash_time >= 0) {
+/* validate the input */
+if (boot_splash_time > 0x) {
+error_report("splash time is big than 65535, force it to 65535.");
+boot_splash_time = 0x;
+}
+/* use little endian format */
+qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time & 0xff);
+qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time >> 8) & 0xff);
+fw_cfg_add_file(s, "etc/boot-menu-wait", qemu_extra_params_fw, 2);
+}
+
+/* insert splash file if user configurated */
+if (boot_splash_filename != NULL) {
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+if (filename == NULL) {
+error_report("failed to find file '%s'.", boot_splash_filename);
+return;
+}
+/* probing the file */
+fp = probe_splashfile(filename, &file_size, &file_type);
+if (fp == NULL) {
+qemu_free(filename);
+

[Qemu-devel] [Discuss] is it good to add codes providing information to libvirt about the qemu's capabilities

2011-07-08 Thread Wayne Xia
   Currently libvirt seems to invoke qemu by "qemu -help" onetime, and
then analysis the output text to find whether one type of device the
qemu could support. For example, if "qemu -help" prints a text with
"-sdl" then libvirt thought the qemu could accept that.
But here comes a problem: the output text seems not to adjust its
output according to the qemu's compile configuration, so it is possible
libvirt invoke qemu with -sdl but get "qemu exit" response that "SDL
support is disabled". By default, the sdl is disabled, and the libvirt
thought it is on.
I wonder if it is a good idea to modify the help function in vl.c,
to let it adjust -help output according to the configuration, but this
would hide some option of "-help" invocation.



-- 
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH v5] showing a splash picture when start, seabios image for test

2011-07-04 Thread Wayne Xia

于 2011-7-5 2:31, Paul Brook 写道:

  jpeg decoder have its limitation, it only accept jpg file with
width=16*M, height=16*N.
  bmp decoder only accept 24bpp file, with a resolution that a video
mode could support. Recommended is 640x480(mostly used).


Doing image decoding in the bios seems particularly pointless.  Why don't you
just pass the bios raw image data?

If you really want to directly support fancier formats IMO it makes much more
sense to do that in qemu itself.  There we can use the same libraries as
everyone else (libjpeg, libpng, etc) rather than badly reimpleenting them
inside the bios.

Paul

  I think the BMP file with 24bpp is almost the raw image data that
need just a little format adjusting in bios according to the video mode
it found.
   Jpeg and LZMA decoder are the old small functions that sea-bios
support, so I think user could use that format as an option.

--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




Re: [Qemu-devel] [PATCH v5] showing a splash picture when start, seabios image for test

2011-07-04 Thread Wayne Xia

于 2011-7-5 2:31, Paul Brook 写道:

  jpeg decoder have its limitation, it only accept jpg file with
width=16*M, height=16*N.
  bmp decoder only accept 24bpp file, with a resolution that a video
mode could support. Recommended is 640x480(mostly used).


Doing image decoding in the bios seems particularly pointless.  Why don't you
just pass the bios raw image data?

If you really want to directly support fancier formats IMO it makes much more
sense to do that in qemu itself.  There we can use the same libraries as
everyone else (libjpeg, libpng, etc) rather than badly reimpleenting them
inside the bios.

  I think the BMP file with 24bpp is almost the raw image data that 
need just a little format adjusting in bios according to the video mode 
it found.
   Jpeg and LZMA decoder are the old small functions that sea-bios 
support, so I think user could use that format as an option.



Paul



--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




[Qemu-devel] [PATCH v4] showing a splash picture when start

2011-06-28 Thread Wayne Xia
Made an option to let qemu pass a picture to bios, let the bios show it as a
logo. By default it is off, enable it as following
-boot splash=P<,splash-time=T>
P is jpg/bmp file name or an absolute path, specifying it would enable log.
T have a max value of 0x, unit is ms, and its predefined value is 2500ms.

Signed-off-by: Wayne Xia 
---
 hw/fw_cfg.c   |  141 -
 qemu-config.c |   27 +++
 sysemu.h  |3 +
 vl.c  |   17 +++-
 4 files changed, 186 insertions(+), 2 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 85c8c3c..3ef5f29 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
 #include "isa.h"
 #include "fw_cfg.h"
 #include "sysbus.h"
+#include "qemu-error.h"
 
 /* debug firmware config */
 //#define DEBUG_FW_CFG
@@ -56,6 +57,144 @@ struct FWCfgState {
 Notifier machine_ready;
 };
 
+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+{
+FILE *fp = NULL;
+int fop_ret;
+int file_size;
+int file_type = -1;
+unsigned char buf[2] = {0, 0};
+unsigned int filehead_value = 0;
+int bmp_bpp;
+
+fp = fopen(filename, "rb");
+if (fp == NULL) {
+error_report("failed to open file '%s'.", filename);
+return fp;
+}
+/* check file size */
+fseek(fp, 0L, SEEK_END);
+file_size = ftell(fp);
+if (file_size < 2) {
+error_report("file size is less than 2 bytes '%s'.", filename);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check magic ID */
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+filehead_value = (buf[0] + (buf[1] << 8)) & 0x;
+if (filehead_value == 0xd8ff) {
+file_type = JPG_FILE;
+} else {
+if (filehead_value == 0x4d42) {
+file_type = BMP_FILE;
+}
+}
+if (file_type < 0) {
+error_report("'%s' not jpg/bmp file,head:0x%x.",
+ filename, filehead_value);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check BMP bpp */
+if (file_type == BMP_FILE) {
+fseek(fp, 28, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+bmp_bpp = (buf[0] + (buf[1] << 8)) & 0x;
+if (bmp_bpp != 24) {
+error_report("only 24bpp bmp file is supported.");
+fclose(fp);
+fp = NULL;
+return fp;
+}
+}
+/* return values */
+*file_sizep = file_size;
+*file_typep = file_type;
+return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+int boot_splash_time = 2500; /* predifined time */
+const char *boot_splash_filename = NULL; /*default is off */
+char *p;
+char *filename;
+FILE *fp;
+int fop_ret;
+int file_size;
+int file_type = -1;
+const char *temp;
+
+/* get user configuration */
+QemuOptsList *plist = qemu_find_opts("boot-opts");
+QemuOpts *opts = QTAILQ_FIRST(&plist->head);
+if (opts != NULL) {
+temp = qemu_opt_get(opts, "splash");
+if (temp != NULL) {
+boot_splash_filename = temp;
+}
+temp = qemu_opt_get(opts, "splash-time");
+if (temp != NULL) {
+p = (char *)temp;
+boot_splash_time = strtol(p, (char **)&p, 10);
+}
+}
+
+/* check user configuration */
+if (boot_splash_filename == NULL) {
+/* do nothing, directly return */
+return;
+}
+if (boot_splash_time > 0x) {
+error_report("splash time is big than 65535, force it to 65535.");
+boot_splash_time = 65535;
+}
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+if (filename == NULL) {
+error_report("failed to find file '%s'.", boot_splash_filename);
+return;
+}
+
+/* probing the file */
+fp = probe_splashfile(filename, &file_size, &file_type);
+if (fp == NULL) {
+qemu_free(filename);
+return;
+}
+
+/* loading file data */
+if (boot_splash_filedata != NULL) {
+qemu_free(boot_splash_filedata);
+}
+boot_splash_filedata = qemu_malloc(file_size);
+boot_splash_filedata_size = file_size;
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(boot_splash_filedata, 1, file_size, fp);
+fclose(fp);
+
+/* insert data */
+if (file_type == JPG_FILE) {
+fw_cfg_add_file(s, "bootsplash.jpg",
+boot_splash_filedata, boot_splash_filedata_size);
+} else {
+fw_cfg_add_file(s, "bootsplash.bmp",
+boot_splash_filedata, boot_splash_filedata_size);
+}
+/* use little endia

Re: [Qemu-devel] [PATCH v3] showing a splash picture when start

2011-06-27 Thread Wayne Xia

On 2011-06-27 08:53, Wayne Xia wrote:

Made an option to let qemu pass a picture to bios, let the bios show it as a
logo. By default it is off, enable it as following


That's better. :)


 -boot splash_time=N,splash_filename=P
N have a max value of 0x, unit is ms. P is the a file name or a absolute
path.
Currently a trial version of sea-bios could be used to test it.

Signed-off-by: Wayne Xia
---


...

I think making the splash time configurable would be better, maybe
we could pass the configuration like following:
-boot splash=P,
only if splash=P was specified, the splash shows. In this
situation, if splash_time was not specified, then show it with a
predefined period, such as 2.5 seconds.



index c63741c..6f93b10 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -469,6 +469,32 @@ static QemuOptsList qemu_machine_opts = {
  },
  };

+QemuOptsList qemu_bootsplash_opts = {
+.name = "bootsplash",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_bootsplash_opts.head),
+.desc = {
+/* the three names below are not used now */
+{
+.name = "order",
+.type = QEMU_OPT_STRING,
+}, {
+.name = "once",
+.type = QEMU_OPT_STRING,
+}, {
+.name = "menu",
+.type = QEMU_OPT_STRING,
+/* following are really used */
+}, {
+.name = "splash_time",
+.type = QEMU_OPT_STRING,
+}, {
+.name = "splash_filename",
+.type = QEMU_OPT_STRING,
+},
+{ /*End of list */ }
+},
+};
+


This is describing the "boot" option that also controls the splash.
Naming should reflect this.

yeah, agree with you.


Jan




--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803



[Qemu-devel] [PATCH v3] showing a splash picture when start

2011-06-26 Thread Wayne Xia
Made an option to let qemu pass a picture to bios, let the bios show it as a 
logo. By default it is off, enable it as following
-boot splash_time=N,splash_filename=P
N have a max value of 0x, unit is ms. P is the a file name or a absolute 
path.
Currently a trial version of sea-bios could be used to test it.

Signed-off-by: Wayne Xia 
---
 hw/fw_cfg.c   |  141 -
 qemu-config.c |   27 +++
 sysemu.h  |3 +
 vl.c  |   17 +++-
 4 files changed, 186 insertions(+), 2 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 85c8c3c..b22ff0a 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
 #include "isa.h"
 #include "fw_cfg.h"
 #include "sysbus.h"
+#include "qemu-error.h"
 
 /* debug firmware config */
 //#define DEBUG_FW_CFG
@@ -56,6 +57,144 @@ struct FWCfgState {
 Notifier machine_ready;
 };
 
+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+{
+FILE *fp = NULL;
+int fop_ret;
+int file_size;
+int file_type = -1;
+unsigned char buf[2] = {0, 0};
+unsigned int filehead_value = 0;
+int bmp_bpp;
+
+fp = fopen(filename, "rb");
+if (fp == NULL) {
+error_report("failed to open file '%s'.", filename);
+return fp;
+}
+/* check file size */
+fseek(fp, 0L, SEEK_END);
+file_size = ftell(fp);
+if (file_size < 2) {
+error_report("file size is less than 2 bytes '%s'.", filename);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check magic ID */
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+filehead_value = (buf[0] + (buf[1] << 8)) & 0x;
+if (filehead_value == 0xd8ff) {
+file_type = JPG_FILE;
+} else {
+if (filehead_value == 0x4d42) {
+file_type = BMP_FILE;
+}
+}
+if (file_type < 0) {
+error_report("'%s' not jpg/bmp file,head:0x%x.",
+ filename, filehead_value);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check BMP bpp */
+if (file_type == BMP_FILE) {
+fseek(fp, 28, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+bmp_bpp = (buf[0] + (buf[1] << 8)) & 0x;
+if (bmp_bpp != 24) {
+error_report("only 24bpp bmp file is supported.");
+fclose(fp);
+fp = NULL;
+return fp;
+}
+}
+/* return values */
+*file_sizep = file_size;
+*file_typep = file_type;
+return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+int boot_splash_time = 0; /* default is off */
+const char *boot_splash_filename = "bootsplash.bmp";
+char *p;
+char *filename;
+FILE *fp;
+int fop_ret;
+int file_size;
+int file_type = -1;
+const char *temp;
+
+/* get user configuration */
+QemuOptsList *plist = qemu_find_opts("bootsplash");
+QemuOpts *opts = QTAILQ_FIRST(&plist->head);
+if (opts != NULL) {
+temp = qemu_opt_get(opts, "splash_time");
+if (temp != NULL) {
+p = (char *)temp;
+boot_splash_time = strtol(p, (char **)&p, 10);
+}
+temp = qemu_opt_get(opts, "splash_filename");
+if (temp != NULL) {
+boot_splash_filename = temp;
+}
+}
+
+/* check user configuration */
+if (boot_splash_time <= 0) {
+/* do nothing, directly return */
+return;
+}
+if (boot_splash_time > 0x) {
+error_report("splash time is big than 65535, force it to 65535.");
+boot_splash_time = 65535;
+}
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+if (filename == NULL) {
+error_report("failed to find file '%s'.", boot_splash_filename);
+return;
+}
+
+/* probing the file */
+fp = probe_splashfile(filename, &file_size, &file_type);
+if (fp == NULL) {
+qemu_free(filename);
+return;
+}
+
+/* loading file data */
+if (boot_splash_filedata != NULL) {
+qemu_free(boot_splash_filedata);
+}
+boot_splash_filedata = qemu_malloc(file_size);
+boot_splash_filedata_size = file_size;
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(boot_splash_filedata, 1, file_size, fp);
+fclose(fp);
+
+/* insert data */
+if (file_type == JPG_FILE) {
+fw_cfg_add_file(s, "bootsplash.jpg",
+boot_splash_filedata, boot_splash_filedata_size);
+} else {
+fw_cfg_add_file(s, "bootsplash.bmp",
+boot_splash_filedata, boot_splash_filedata_size);
+}
+/* use littl

Re: [Qemu-devel] [PATCH 12/12] Remove temp_buf, rename CPU_TEMP_BUF_NLONGS

2011-06-26 Thread Wayne Xia
G_AREG0, TCG_REG_I0);
diff --git a/tcg/tcg.h b/tcg/tcg.h
index a2dd8b8..39c59ff 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -92,6 +92,9 @@ typedef struct TCGPool {

  #define TCG_MAX_TEMPS 512

+/* buffer for temporaries */
+#define TCG_TEMP_BUF_NLONGS 128
+
  /* when the size of the arguments of a called function is smaller than
 this value, they are statically allocated in the TB stack frame */
  #define TCG_STATIC_CALL_ARGS_SIZE 128



--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803



Re: [Qemu-devel] [PATCH v2 0/3] kvm:showing a splash picture when start

2011-06-23 Thread Wayne Xia

 2011-6-23 20:29, Jan Kiszka :

On 2011-06-23 14:05, Daniel P. Berrange wrote:

On Thu, Jun 23, 2011 at 01:24:01PM +0200, Jan Kiszka wrote:

On 2011-06-23 13:20, Wayne Xia wrote:

2011-6-23 18:03, Jan Kiszka

On 2011-06-23 11:18, Wayne Xia wrote:

Hi,
  these 3 patch simply enable qemu-kvm to show a logo picture when it


You are posting on qemu-devel (which is correct for this topic), so your
patches must target that tree. Patch 1 eg. does not and needs rebasing.


thanks for the tip.

s start up, following is how to configurate it:
  invoke it with params:
  -boot (splash_time=,) (splash_filename=,)


Simply 'splash' for specifying the file should suffice.


  the splash_time is in the unit of ms, and its max value is 65535.
this feature is by default on with 5000ms showing up.


Strong NAK for making this default. We have a nice sub-second BIOS time
in QEMU, and that must not be destroyed by eye candy. 5 s is also way
too long even when you want splash.


Maybe 5 is a bit too long, this patch is for test so made it a bit
longer to be observed by VNC, I think 2.5s would be fit.


Maybe it could be something like that if the user specifies a splash
file - which indicates that there should be some splash delay as well.
Default without any splash parameter must remain 0, ie. disabled.


I don't think you want to change default timeouts based on whether
a splash screen is present. Consider that if you have enabled PXE boot
on one of the guest NICs, then there is already a few second delay
while the BIOS PXEs, during which it QEMU would be showing the splash
screen. You don't then want to add a further 2.5s or 5s delay ontop
of that already imposed by the BIOS PXE process. Just let the splash
screen be displayed for however long the BIOS process takes, without
any extra artifical delays, even if this is a mere fraction of a
second in some cases.


I don't want the splash to show up at all by default, even just for a
fraction of a second. Already loading that image costs time
(specifically as it's squeezed into fwcfg), and that would be unacceptable.

My point is that, if the user specifies "-boot
splash=my-nice-splace.bmp", there is likely the wish to see the result
more than a few 100 ms. Again, that's the case where the user asked for
a slowdown anyway.


   Completely understand that in most cases the Qemu-kvm should boot up
as soon as it can. Making this default now is just to provide a
convenient way to test it temporarily, I did that to make it easily
tested in the GUI--Virtual Machine Manager which would not accept
additional parameters to enable the splash screen. Sorry for having not
explained it clearly.
   I agree that if the user specifies it, then this logo would be
shown.


Jan




--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803



Re: [Qemu-devel] [PATCH v2 0/3] kvm:showing a splash picture when start

2011-06-23 Thread Wayne Xia
2011-6-23 18:03, Jan Kiszka
> On 2011-06-23 11:18, Wayne Xia wrote:
>> Hi,
>>  these 3 patch simply enable qemu-kvm to show a logo picture when it
> 
> You are posting on qemu-devel (which is correct for this topic), so your
> patches must target that tree. Patch 1 eg. does not and needs rebasing.
> 
thanks for the tip.
>> s start up, following is how to configurate it:
>>  invoke it with params:
>>  -boot (splash_time=,) (splash_filename=,)
> 
> Simply 'splash' for specifying the file should suffice.
> 
>>  the splash_time is in the unit of ms, and its max value is 65535.
>> this feature is by default on with 5000ms showing up.
> 
> Strong NAK for making this default. We have a nice sub-second BIOS time
> in QEMU, and that must not be destroyed by eye candy. 5 s is also way
> too long even when you want splash.
> 
Maybe 5 is a bit too long, this patch is for test so made it a bit
longer to be observed by VNC, I think 2.5s would be fit.

>>  Patch 1 contains the source modification for qemu-kvm, Patch 2 and
>> 3 are binary patches that added a default logo picture file, alternated
>> the bios.bin to make the sea-bios showing it. Patch 3 is just used to
>> provide a convenient way to test the Patch, waiting for newer version
>> of seabios that provide the support officially.
>>  Any comments would be very nice.
> 
> - commit logs a missing in the individual patches
I think patch 3/3 may be in the junk mail box.
> - the BIOS is updated via submodule reference, and that only to SeaBIOS
> releases (IOW,
>you can only provide a test image so far, no patch)
> - a default logo should not mention KVM but QEMU (splash is not limited
> to KVM mode)
we can switch it for a more official picture for different release.

> Jan
> 


-- 
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




[Qemu-devel] [PATCH v2 3/3] kvm:showing a splash picture when start, bios change

2011-06-23 Thread Wayne Xia

Signed-off-by: Wayne Xia 
---
 pc-bios/bios.bin |  Bin 131072 -> 131072 bytes
 1 files changed, 0 insertions(+), 0 deletions(-)

diff --git a/pc-bios/bios.bin b/pc-bios/bios.bin
index 
bdb48314dfb79c6db84846278a696da3cb68d4ff..7691173dc18d41272c60cf0bc7fc7016d5843b26
 100644
GIT binary patch
delta 27182
zcmb8Y33yD`8$W)}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
z0Gp;Hf(0`uI5_Y&dyZjF1e}xU^bN3C4b03q!yKi)OxjTpaTQixs9+5qoL?-t@N?@3FRo(6vc$Ywz(?nEnh*-KK*k=YZrA&rXd;~iVeT+
z

[Qemu-devel] [PATCH v2 1/3] kvm:showing a splash picture when start, code change

2011-06-23 Thread Wayne Xia

Signed-off-by: Wayne Xia 
---
 Makefile  |3 +-
 hw/fw_cfg.c   |  131 -
 qemu-config.c |   27 
 sysemu.h  |3 +
 vl.c  |   17 +++-
 5 files changed, 178 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 65edcf4..8cdd687 100644
--- a/Makefile
+++ b/Makefile
@@ -188,7 +188,8 @@ bamboo.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \
 mpc8544ds.dtb \
 multiboot.bin linuxboot.bin \
 s390-zipl.rom \
-spapr-rtas.bin slof.bin
+spapr-rtas.bin slof.bin \
+bootsplash.bmp
 BLOBS += extboot.bin
 BLOBS += vapic.bin
 else
diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 85c8c3c..a1188e5 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
 #include "isa.h"
 #include "fw_cfg.h"
 #include "sysbus.h"
+#include "qemu-error.h"
 
 /* debug firmware config */
 //#define DEBUG_FW_CFG
@@ -56,6 +57,134 @@ struct FWCfgState {
 Notifier machine_ready;
 };
 
+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+{
+FILE *fp = NULL;
+int fop_ret;
+int file_size;
+int file_type = -1;
+unsigned char buf[2] = {0, 0};
+unsigned int filehead_value = 0;
+int bmp_bpp;
+
+fp = fopen(filename, "rb");
+if (fp == NULL) {
+error_report("failed to open file '%s'.", filename);
+return fp;
+}
+/* check file size */
+fseek(fp, 0L, SEEK_END);
+file_size = ftell(fp);
+if (file_size < 2) {
+error_report("file size is less than 2 bytes '%s'.", filename);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check magic ID */
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+filehead_value = (buf[0] + (buf[1] << 8)) & 0x;
+if (filehead_value == 0xd8ff) {
+file_type = JPG_FILE;
+} else {
+if (filehead_value == 0x4d42) {
+file_type = BMP_FILE;
+}
+}
+if (file_type < 0) {
+error_report("'%s' not jpg/bmp file,head:0x%x.",
+ filename, filehead_value);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check BMP bpp */
+if (file_type == BMP_FILE) {
+fseek(fp, 28, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+bmp_bpp = (buf[0] + (buf[1] << 8)) & 0x;
+if (bmp_bpp != 24) {
+error_report("only 24bpp bmp file is supported.");
+fclose(fp);
+fp = NULL;
+return fp;
+}
+}
+/* return values */
+*file_sizep = file_size;
+*file_typep = file_type;
+return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+int boot_splash_time = 5000;
+const char *boot_splash_filename = "bootsplash.bmp";
+char *p;
+char *filename;
+FILE *fp;
+int fop_ret;
+int file_size;
+int file_type = -1;
+
+/* get user configuration */
+QemuOptsList *plist = qemu_find_opts("bootsplash");
+const char *temp = qemu_opt_get(QTAILQ_FIRST(&plist->head), "splash_time");
+if (temp != NULL) {
+p = (char *)temp;
+boot_splash_time = strtol(p, (char **)&p, 10);
+}
+if (boot_splash_time <= 0) {
+error_report("splash time is minor than 0, abort insert data.");
+return;
+}
+if (boot_splash_time > 0x) {
+error_report("splash time is big than 65535, force it to 65535.");
+boot_splash_time = 65535;
+}
+temp = qemu_opt_get(QTAILQ_FIRST(&plist->head), "splash_filename");
+if (temp != NULL) {
+boot_splash_filename = temp;
+}
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+if (filename == NULL) {
+error_report("failed to find file '%s'.", boot_splash_filename);
+return;
+}
+/* probing the file */
+fp = probe_splashfile(filename, &file_size, &file_type);
+if (fp == NULL) {
+qemu_free(filename);
+return;
+}
+/* loading file data */
+if (boot_splash_filedata != NULL) {
+qemu_free(boot_splash_filedata);
+}
+boot_splash_filedata = qemu_malloc(file_size);
+boot_splash_filedata_size = file_size;
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(boot_splash_filedata, 1, file_size, fp);
+fclose(fp);
+/* insert data */
+if (file_type == JPG_FILE) {
+fw_cfg_add_file(s, "bootsplash.jpg",
+boot_splash_filedata, boot_splash_filedata_size);
+} else {
+fw_cfg_add_file(s, "bootsplash.bmp",
+boot_splash_filedata, boot_splash_filedata_size);
+}
+/* use little endian format */
+qemu_extra_params_fw[

[Qemu-devel] [PATCH v2 0/3] kvm:showing a splash picture when start

2011-06-23 Thread Wayne Xia
Hi,
these 3 patch simply enable qemu-kvm to show a logo picture when it
s start up, following is how to configurate it:
invoke it with params:
-boot (splash_time=,) (splash_filename=,)
the splash_time is in the unit of ms, and its max value is 65535.
this feature is by default on with 5000ms showing up.
Patch 1 contains the source modification for qemu-kvm, Patch 2 and
3 are binary patches that added a default logo picture file, alternated
the bios.bin to make the sea-bios showing it. Patch 3 is just used to
provide a convenient way to test the Patch, waiting for newer version
of seabios that provide the support officially.
Any comments would be very nice.

-- 
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803