Re: [Qemu-devel] [PATCH 3/3] Fail if detecting an unknown option

2010-12-06 Thread Jes Sorensen
On 12/03/10 12:46, Stefan Hajnoczi wrote:
 On Thu, Dec 2, 2010 at 5:46 PM,  jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com

 This patch changes qemu-img to exit if an unknown option is detected,
 instead of trying to continue with a set of arguments which may be
 incorrect.

 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-img.c |   48 
  1 files changed, 48 insertions(+), 0 deletions(-)
 
 Do we get a silent exit if an unknown option is detected?  Normally
 programs print their help/usage when this happens.
 
 Stefan

Fixed in the next version :)

Cheers,
Jes




[Qemu-devel] Re: [PATCH 3/3] Fail if detecting an unknown option

2010-12-06 Thread Jes Sorensen
On 12/03/10 13:30, Kevin Wolf wrote:
 Am 02.12.2010 18:46, schrieb jes.soren...@redhat.com:
 diff --git a/qemu-img.c b/qemu-img.c
 index d0dc445..f2e1c94 100644
 --- a/qemu-img.c
 +++ b/qemu-img.c
 @@ -304,6 +304,12 @@ static int img_create(int argc, char **argv)
  flags = 0;
  for(;;) {
  c = getopt(argc, argv, F:b:f:he6o:);
 +/*
 + * Fail if we detect an unknown argument
 + */
 +if (c == '?') {
 +return 1;
 +}
  if (c == -1) {
  break;
  }
 
 Why not making it another case in the switch statement below instead of
 an additional if?

There is a perfectly logical explanation for that. Doing that would
require for me to have clue, which is a bit much to expect :)

That said, we should really do the same for the c == -1 case as well.

Fixed in next version.

Cheers,
Jes



[Qemu-devel] [PATCH v2 0/3] Cleanup qemu-img code

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

Hi,

These patches moves the handling of block help printing to shared
code, which allows the ? detection to happen early in the parsing,
instead of half way down img_create() and img_convert(). I would like
to see this happen as I would like to pull some of the code out of
img_create() and into block.c so it can be shared with qemu and
qemu-img.

The formatting patch is solely because the third patch wanted to
change code next to the badly formatted code, and I didn't want to
pollute the patch with the formatting fixed.

The third patch fixes qemu-img to exit on detection of unknown options
instead of continuing with a potentially wrong set of arguments.

New in v2: Add missing free_option_parameters() and handle the help()
case in the general switch() statements for the getopt() output.

Cheers,
Jes

Jes Sorensen (3):
  Consolidate printing of block driver options
  Fix formatting and missing braces in qemu-img.c
  Fail if detecting an unknown option

 qemu-img.c |  132 
 1 files changed, 97 insertions(+), 35 deletions(-)

-- 
1.7.3.2




[Qemu-devel] [PATCH 3/3] Fail if detecting an unknown option

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

This patch changes qemu-img to exit if an unknown option is detected,
instead of trying to continue with a set of arguments which may be
incorrect.

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

diff --git a/qemu-img.c b/qemu-img.c
index 2a54ae2..3e3ca36 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -309,6 +309,7 @@ static int img_create(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -477,6 +478,7 @@ static int img_check(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -555,6 +557,7 @@ static int img_commit(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -693,6 +696,7 @@ static int img_convert(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -1099,6 +1103,7 @@ static int img_info(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -1176,6 +1181,7 @@ static int img_snapshot(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 return 0;
@@ -1291,6 +1297,7 @@ static int img_rebase(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 return 0;
@@ -1505,6 +1512,7 @@ static int img_resize(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
-- 
1.7.3.2




[Qemu-devel] [PATCH 2/3] Fix formatting and missing braces in qemu-img.c

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

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 qemu-img.c |   77 +++
 1 files changed, 51 insertions(+), 26 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 7863835..2a54ae2 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -305,8 +305,9 @@ static int img_create(int argc, char **argv)
 flags = 0;
 for(;;) {
 c = getopt(argc, argv, F:b:f:he6o:);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -333,8 +334,9 @@ static int img_create(int argc, char **argv)
 }
 
 /* Get the filename */
-if (optind = argc)
+if (optind = argc) {
 help();
+}
 filename = argv[optind++];
 
 if (options  !strcmp(options, ?)) {
@@ -471,8 +473,9 @@ static int img_check(int argc, char **argv)
 fmt = NULL;
 for(;;) {
 c = getopt(argc, argv, f:h);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -482,8 +485,9 @@ static int img_check(int argc, char **argv)
 break;
 }
 }
-if (optind = argc)
+if (optind = argc) {
 help();
+}
 filename = argv[optind++];
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS);
@@ -547,8 +551,9 @@ static int img_commit(int argc, char **argv)
 fmt = NULL;
 for(;;) {
 c = getopt(argc, argv, f:h);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -558,8 +563,9 @@ static int img_commit(int argc, char **argv)
 break;
 }
 }
-if (optind = argc)
+if (optind = argc) {
 help();
+}
 filename = argv[optind++];
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
@@ -683,8 +689,9 @@ static int img_convert(int argc, char **argv)
 flags = 0;
 for(;;) {
 c = getopt(argc, argv, f:O:B:s:hce6o:);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -717,7 +724,9 @@ static int img_convert(int argc, char **argv)
 }
 
 bs_n = argc - optind - 1;
-if (bs_n  1) help();
+if (bs_n  1) {
+help();
+}
 
 out_filename = argv[argc - 1];
 
@@ -908,8 +917,9 @@ static int img_convert(int argc, char **argv)
 }
 assert (remainder == 0);
 
-if (n  cluster_sectors)
+if (n  cluster_sectors) {
 memset(buf + n * 512, 0, cluster_size - n * 512);
+}
 if (is_not_zero(buf, cluster_size)) {
 ret = bdrv_write_compressed(out_bs, sector_num, buf,
 cluster_sectors);
@@ -929,12 +939,14 @@ static int img_convert(int argc, char **argv)
 sector_num = 0; // total number of sectors converted so far
 for(;;) {
 nb_sectors = total_sectors - sector_num;
-if (nb_sectors = 0)
+if (nb_sectors = 0) {
 break;
-if (nb_sectors = (IO_BUF_SIZE / 512))
+}
+if (nb_sectors = (IO_BUF_SIZE / 512)) {
 n = (IO_BUF_SIZE / 512);
-else
+} else {
 n = nb_sectors;
+}
 
 while (sector_num - bs_offset = bs_sectors) {
 bs_i ++;
@@ -946,8 +958,9 @@ static int img_convert(int argc, char **argv)
sector_num, bs_i, bs_offset, bs_sectors); */
 }
 
-if (n  bs_offset + bs_sectors - sector_num)
+if (n  bs_offset + bs_sectors - sector_num) {
 n = bs_offset + bs_sectors - sector_num;
+}
 
 if (has_zero_init) {
 /* If the output image is being created as a copy on write 
image,
@@ -1082,8 +1095,9 @@ static int img_info(int argc, char **argv)
 fmt = NULL;
 for(;;) {
 c = getopt(argc, argv, f:h);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -1093,8 +1107,9 @@ static int img_info(int argc, char **argv)
 break;
 }
 }
-if (optind = argc)
+if (optind = argc) {
 help();
+}
 filename = argv[optind++];
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING);
@@ -1105,11 +1120,12 @@ static int img_info(int argc, char **argv)
 bdrv_get_geometry(bs, total_sectors);
 get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512);
 allocated_size = get_allocated_file_size(filename);
-if (allocated_size  0)
+if (allocated_size  0) {
 snprintf(dsize_buf, sizeof(dsize_buf), unavailable);
-

[Qemu-devel] [PATCH 1/3] Consolidate printing of block driver options

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

This consolidates the printing of block driver options in
print_block_option_help() which is called from both img_create() and
img_convert().

This allows for the ? detection to be done just after the parsing of
options and the filename, instead of half way down the codepath of
these functions.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 qemu-img.c |   47 ++-
 1 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index fa77ac0..7863835 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -188,6 +188,33 @@ static int read_password(char *buf, int buf_size)
 }
 #endif
 
+static int print_block_option_help(const char *filename, const char *fmt)
+{
+BlockDriver *drv, *proto_drv;
+QEMUOptionParameter *create_options = NULL;
+
+/* Find driver and parse its options */
+drv = bdrv_find_format(fmt);
+if (!drv) {
+error(Unknown file format '%s', fmt);
+return 1;
+}
+
+proto_drv = bdrv_find_protocol(filename);
+if (!proto_drv) {
+error(Unknown protocol '%s', filename);
+return 1;
+}
+
+create_options = append_option_parameters(create_options,
+  drv-create_options);
+create_options = append_option_parameters(create_options,
+  proto_drv-create_options);
+print_option_help(create_options);
+free_option_parameters(create_options);
+return 0;
+}
+
 static BlockDriverState *bdrv_new_open(const char *filename,
const char *fmt,
int flags)
@@ -310,6 +337,11 @@ static int img_create(int argc, char **argv)
 help();
 filename = argv[optind++];
 
+if (options  !strcmp(options, ?)) {
+ret = print_block_option_help(filename, fmt);
+goto out;
+}
+
 /* Find driver and parse its options */
 drv = bdrv_find_format(fmt);
 if (!drv) {
@@ -328,11 +360,6 @@ static int img_create(int argc, char **argv)
 create_options = append_option_parameters(create_options,
   proto_drv-create_options);
 
-if (options  !strcmp(options, ?)) {
-print_option_help(create_options);
-goto out;
-}
-
 /* Create parameter list with default values */
 param = parse_option_parameters(, create_options, param);
 set_option_parameter_int(param, BLOCK_OPT_SIZE, -1);
@@ -694,6 +721,11 @@ static int img_convert(int argc, char **argv)
 
 out_filename = argv[argc - 1];
 
+if (options  !strcmp(options, ?)) {
+ret = print_block_option_help(out_filename, out_fmt);
+goto out2;
+}
+
 if (bs_n  1  out_baseimg) {
 error(-B makes no sense when concatenating multiple input images);
 return 1;
@@ -749,10 +781,6 @@ static int img_convert(int argc, char **argv)
   drv-create_options);
 create_options = append_option_parameters(create_options,
   proto_drv-create_options);
-if (options  !strcmp(options, ?)) {
-print_option_help(create_options);
-goto out;
-}
 
 if (options) {
 param = parse_option_parameters(options, create_options, param);
@@ -984,6 +1012,7 @@ out:
 }
 }
 free(bs);
+out2:
 if (ret) {
 return 1;
 }
-- 
1.7.3.2




Re: [Qemu-devel] implementation of Vmul instruction in QEMU that seems to be illogical

2010-12-06 Thread Paul Brook
 Logically, implementation of Vmull.s32 and vmul.u32 is just similar to the
 8 and 16 bit cases. For example:
 case 4: gen_helper_neon_mull_s32(dest, a, b); break;
 case 5: gen_helper_neon_mull_u32(dest, a, b); break;
 I implemented in this way and tested. It is OK. So I can't understand why
 Vmull.s32 and vmul.u32 were implemented like this in QEMU 0.12.5. Please
 explain for me !

I think you're asking the wrong question. Instead ask yourself why should we 
add a new helper when we already know how to do 32x32-64 multiplies.

Paul



Re: [Qemu-devel] [PATCH 3/3] Fail if detecting an unknown option

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 6, 2010 at 8:17 AM,  jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com

 This patch changes qemu-img to exit if an unknown option is detected,
 instead of trying to continue with a set of arguments which may be
 incorrect.

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

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] [PATCH 1/6] [RFC] Emulation of GRLIB GPTimer as defined in GRLIB IP Core User's Manual.

2010-12-06 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau chout...@adacore.com
---
 hw/grlib_gptimer.c |  448 
 1 files changed, 448 insertions(+), 0 deletions(-)

diff --git a/hw/grlib_gptimer.c b/hw/grlib_gptimer.c
new file mode 100644
index 000..41edbe4
--- /dev/null
+++ b/hw/grlib_gptimer.c
@@ -0,0 +1,448 @@
+/*
+ * QEMU GRLIB GPTimer Emulator
+ *
+ * Copyright (c) 2010 AdaCore
+ *
+ * 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 sysbus.h
+#include qemu-timer.h
+
+#include grlib.h
+
+/* #define DEBUG_TIMER */
+
+#ifdef DEBUG_TIMER
+#define DPRINTF(fmt, ...)   \
+do { printf(GPTIMER:  fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+#define UNIT_REG_SIZE16 /* Size of memory mapped regs for the unit */
+#define GPTIMER_REG_SIZE 16 /* Size of memory mapped regs for a GPTimer */
+
+#define GPTIMER_MAX_TIMERS 8
+
+/* GPTimer Config register fields */
+#define GPTIMER_ENABLE  (1  0)
+#define GPTIMER_RESTART (1  1)
+#define GPTIMER_LOAD(1  2)
+#define GPTIMER_INT_ENABLE  (1  3)
+#define GPTIMER_INT_PENDING (1  4)
+#define GPTIMER_CHAIN   (1  5) /* Not supported */
+#define GPTIMER_DEBUG_HALT  (1  6) /* Not supported */
+
+/* Memory mapped register offsets */
+#define SCALER_OFFSET 0x00
+#define SCALER_RELOAD_OFFSET  0x04
+#define CONFIG_OFFSET 0x08
+#define COUNTER_OFFSET0x00
+#define COUNTER_RELOAD_OFFSET 0x04
+#define TIMER_BASE0x10
+
+typedef struct GPTimer GPTimer;
+typedef struct GPTimerUnit GPTimerUnit;
+
+struct GPTimer
+{
+QEMUBH *bh;
+struct ptimer_state *ptimer;
+
+qemu_irq irq;
+int  id;
+GPTimerUnit *unit;
+
+/* registers */
+uint32_t counter;
+uint32_t reload;
+uint32_t config;
+};
+
+struct GPTimerUnit
+{
+SysBusDevice  busdev;
+
+uint32_t nr_timers; /* Number of timers available */
+uint32_t freq_hz;   /* System frequency */
+uint32_t irq_line;  /* Base irq line */
+
+GPTimer *timers;
+
+/* registers */
+uint32_t scaler;
+uint32_t reload;
+uint32_t config;
+};
+
+DeviceState *grlib_gptimer_create(target_phys_addr_t  base,
+  uint32_tnr_timers,
+  uint32_tfreq,
+  qemu_irq   *cpu_irqs,
+  int base_irq)
+{
+DeviceState *dev;
+int i;
+
+dev = qdev_create(NULL, grlib,gptimer);
+qdev_prop_set_uint32(dev, nr-timers, nr_timers);
+qdev_prop_set_uint32(dev, frequency, freq);
+qdev_prop_set_uint32(dev, irq-line, base_irq);
+
+if (qdev_init(dev)) {
+return NULL;
+}
+
+sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
+
+for (i = 0; i  nr_timers; i++)
+sysbus_connect_irq(sysbus_from_qdev(dev), i, cpu_irqs[base_irq + i]);
+
+return dev;
+}
+
+static void grlib_gptimer_enable(GPTimer *timer)
+{
+assert(timer != NULL);
+
+DPRINTF(%s id:%d\n, __func__, timer-id);
+
+ptimer_stop(timer-ptimer);
+
+if (!(timer-config  GPTIMER_ENABLE)) {
+/* Timer disabled */
+DPRINTF(%s id:%d Timer disabled (config 0x%x)\n, __func__,
+timer-id, timer-config);
+return;
+}
+
+/* ptimer is triggered when the counter reach 0 but GPTimer is triggered at
+   underflow. Set count + 1 to simulate the GPTimer behavior. */
+
+DPRINTF(%s id:%d set count 0x%x and run\n,
+__func__,
+timer-id,
+timer-counter + 1);
+
+ptimer_set_count(timer-ptimer, timer-counter + 1);
+ptimer_run(timer-ptimer, 1);
+}
+
+static void grlib_gptimer_restart(GPTimer *timer)
+{
+assert(timer != NULL);
+
+DPRINTF(%s id:%d reload val: 0x%x\n, __func__, timer-id, timer-reload);
+
+timer-counter = 

[Qemu-devel] [PATCH 2/6] [RFC] Emulation of GRLIB IRQMP as defined in GRLIB IP Core User's Manual.

2010-12-06 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau chout...@adacore.com
---
 hw/grlib_irqmp.c |  416 ++
 1 files changed, 416 insertions(+), 0 deletions(-)

diff --git a/hw/grlib_irqmp.c b/hw/grlib_irqmp.c
new file mode 100644
index 000..69e1553
--- /dev/null
+++ b/hw/grlib_irqmp.c
@@ -0,0 +1,416 @@
+/*
+ * QEMU GRLIB IRQMP Emulator
+ *
+ * (Multiprocessor and extended interrupt not supported)
+ *
+ * Copyright (c) 2010 AdaCore
+ *
+ * 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 sysbus.h
+#include cpu.h
+
+#include grlib.h
+
+/* #define DEBUG_IRQ */
+
+#ifdef DEBUG_IRQ
+#define DPRINTF(fmt, ...)   \
+do { printf(IRQMP:  fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+#define IRQMP_MAX_CPU 16
+#define IRQMP_REG_SIZE 256  /* Size of memory mapped registers */
+
+/* Memory mapped register offsets */
+#define LEVEL_OFFSET 0x00
+#define PENDING_OFFSET   0x04
+#define FORCE0_OFFSET0x08
+#define CLEAR_OFFSET 0x0C
+#define MP_STATUS_OFFSET 0x10
+#define BROADCAST_OFFSET 0x14
+#define MASK_OFFSET  0x40
+#define FORCE_OFFSET 0x80
+#define EXTENDED_OFFSET  0xC0
+
+typedef struct IRQMP
+{
+SysBusDevice busdev;
+
+CPUSPARCState *env;
+} IRQMP;
+
+typedef struct IRQMPState
+{
+uint32_t level;
+uint32_t pending;
+uint32_t clear;
+uint32_t broadcast;
+
+uint32_t mask[IRQMP_MAX_CPU];
+uint32_t force[IRQMP_MAX_CPU];
+uint32_t extended[IRQMP_MAX_CPU];
+
+IRQMP*parent;
+} IRQMPState;
+
+IRQMPState grlib_irqmp_state;
+
+void grlib_irqmp_set_irq(void *opaque, int irq, int level);
+
+DeviceState *grlib_irqmp_create(target_phys_addr_t   base,
+CPUState*env,
+qemu_irq   **cpu_irqs,
+uint32_t nr_irqs)
+{
+DeviceState *dev;
+
+assert(cpu_irqs != NULL);
+
+dev = qdev_create(NULL, grlib,irqmp);
+qdev_prop_set_ptr(dev, cpustate, env);
+
+if (qdev_init(dev)) {
+return NULL;
+}
+
+sysbus_mmio_map(sysbus_from_qdev(dev), 0, base);
+
+*cpu_irqs = qemu_allocate_irqs(grlib_irqmp_set_irq,
+   grlib_irqmp_state,
+   nr_irqs);
+
+return dev;
+}
+
+static void grlib_irqmp_check_irqs(CPUState *env)
+{
+uint32_t pend   = 0;
+uint32_t level0 = 0;
+uint32_t level1 = 0;
+
+assert(env != NULL);
+
+/* IRQ for CPU 0 (no SMP support) */
+pend = (grlib_irqmp_state.pending | grlib_irqmp_state.force[0])
+ grlib_irqmp_state.mask[0];
+
+
+level0 = pend  ~grlib_irqmp_state.level;
+level1 = pend   grlib_irqmp_state.level;
+
+DPRINTF(pend:0x%04x force:0x%04x mask:0x%04x lvl1:0x%04x lvl0:0x%04x\n,
+grlib_irqmp_state.pending, grlib_irqmp_state.force[0],
+grlib_irqmp_state.mask[0], level1, level0);
+
+/* Trigger level1 interrupt first and level0 if there is no level1 */
+if (level1 != 0) {
+env-pil_in = level1;
+} else {
+env-pil_in = level0;
+}
+
+if (env-pil_in  (env-interrupt_index == 0 ||
+(env-interrupt_index  ~15) == TT_EXTINT)) {
+unsigned int i;
+
+for (i = 15; i  0; i--) {
+if (env-pil_in  (1  i)) {
+int old_interrupt = env-interrupt_index;
+
+env-interrupt_index = TT_EXTINT | i;
+if (old_interrupt != env-interrupt_index) {
+DPRINTF(Set CPU IRQ %d\n, i);
+cpu_interrupt(env, CPU_INTERRUPT_HARD);
+}
+break;
+}
+}
+} else if (!env-pil_in  (env-interrupt_index  ~15) == TT_EXTINT) {
+DPRINTF(Reset CPU IRQ %d\n, env-interrupt_index  15);
+env-interrupt_index = 0;
+cpu_reset_interrupt(env, 

[Qemu-devel] [PATCH 6/6] [RFC] SPARCV8 asr17 register support.

2010-12-06 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau chout...@adacore.com
---
 hw/leon3.c   |6 ++
 target-sparc/cpu.h   |1 +
 target-sparc/machine.c   |2 ++
 target-sparc/translate.c |   10 ++
 4 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/hw/leon3.c b/hw/leon3.c
index ba61081..9605ce8 100644
--- a/hw/leon3.c
+++ b/hw/leon3.c
@@ -187,6 +187,12 @@ static void main_cpu_reset(void *opaque)
values */
 leon3_state.inst_cache_conf = 0x1022;
 leon3_state.data_cache_conf = 0x1822;
+
+/* Asr17 for Leon3 mono-processor */
+env-asr17 = 0  28;  /* CPU id */
+env-asr17 = 1  8;   /* SPARC V8 multiply and divide available 
*/
+env-asr17 = env-nwindows -1; /* Number of implemented registers
+   windows */
 }
 
 static void leon3_generic_hw_init(ram_addr_t  ram_size,
diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index 6020ffd..36d49fc 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -341,6 +341,7 @@ typedef struct CPUSPARCState {
   from PSR) */
 #if !defined(TARGET_SPARC64) || defined(TARGET_ABI32)
 uint32_t wim;  /* window invalid mask */
+uint32_t asr17;/* asr17 */
 #endif
 target_ulong tbr;  /* trap base register */
 #if !defined(TARGET_SPARC64)
diff --git a/target-sparc/machine.c b/target-sparc/machine.c
index 752e431..c530bd3 100644
--- a/target-sparc/machine.c
+++ b/target-sparc/machine.c
@@ -42,6 +42,7 @@ void cpu_save(QEMUFile *f, void *opaque)
 qemu_put_be32s(f, env-pil_in);
 #ifndef TARGET_SPARC64
 qemu_put_be32s(f, env-wim);
+qemu_put_be32s(f, env-asr17);
 /* MMU */
 for (i = 0; i  32; i++)
 qemu_put_be32s(f, env-mmuregs[i]);
@@ -138,6 +139,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
 qemu_get_be32s(f, env-pil_in);
 #ifndef TARGET_SPARC64
 qemu_get_be32s(f, env-wim);
+qemu_get_be32s(f, env-asr17);
 /* MMU */
 for (i = 0; i  32; i++)
 qemu_get_be32s(f, env-mmuregs[i]);
diff --git a/target-sparc/translate.c b/target-sparc/translate.c
index 23f9519..65de614 100644
--- a/target-sparc/translate.c
+++ b/target-sparc/translate.c
@@ -58,6 +58,7 @@ static TCGv cpu_hintp, cpu_htba, cpu_hver, cpu_ssr, cpu_ver;
 static TCGv_i32 cpu_softint;
 #else
 static TCGv cpu_wim;
+static TCGv cpu_asr17;
 #endif
 /* local register indexes (only used inside old micro ops) */
 static TCGv cpu_tmp0;
@@ -2049,6 +2050,8 @@ static void disas_sparc_insn(DisasContext * dc)
 rs1 = GET_FIELD(insn, 13, 17);
 switch(rs1) {
 case 0: /* rdy */
+gen_movl_TN_reg(rd, cpu_y);
+break;
 #ifndef TARGET_SPARC64
 case 0x01 ... 0x0e: /* undefined in the SPARCv8
manual, rdy on the microSPARC
@@ -2058,6 +2061,11 @@ static void disas_sparc_insn(DisasContext * dc)
 case 0x10 ... 0x1f: /* implementation-dependent in the
SPARCv8 manual, rdy on the
microSPARC II */
+
+if (rs1 == 0x11) { /* Read %asr17 */
+gen_movl_TN_reg(rd, cpu_asr17);
+break;
+}
 #endif
 gen_movl_TN_reg(rd, cpu_y);
 break;
@@ -5019,6 +5027,8 @@ void gen_intermediate_code_init(CPUSPARCState *env)
 #else
 cpu_wim = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, wim),
  wim);
+cpu_asr17 = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, asr17),
+ asr17);
 #endif
 cpu_cond = tcg_global_mem_new(TCG_AREG0, offsetof(CPUState, cond),
   cond);
-- 
1.7.1




[Qemu-devel] [PATCH 0/6] [RFC] New SPARC machine: Leon3

2010-12-06 Thread Fabien Chouteau
Hi everyone,
I'm glad to submit my first patches to the Qemu-devel list.

This patch set introduces a new SPARC V8 machine: Leon3. It's an open-source
VHDL System-On-Chip, well known in space industry (more information on
http://www.gaisler.com).

Leon3 is made of multiple components available in the GrLib VHDL library.
Three devices are implemented: uart, timers and IRQ manager.
You can find code for these peripherals in the grlib_* files.

Modifications have been done to the SPARC cpu emulation code to handle
Leon3's specific behavior:
 - IRQ management
 - Cache control
 - Asr17 (implementation-dependent Ancillary State Registers)
 - Shutdown

Please feel free to comment.

Regards,

Fabien Chouteau (6):
  Emulation of GRLIB GPTimer as defined in GRLIB IP Core User's Manual.
  Emulation of GRLIB IRQMP as defined in GRLIB IP Core User's Manual.
  Emulation of GRLIB APB UART as defined in GRLIB IP Core User's
Manual.
  Header file for the GRLIB components.
  Emulation of Leon3.
  SPARCV8 asr17 register support.

 Makefile.target  |5 +-
 hw/grlib.h   |   27 +++
 hw/grlib_apbuart.c   |  231 
 hw/grlib_gptimer.c   |  448 ++
 hw/grlib_irqmp.c |  416 ++
 hw/leon3.c   |  316 
 target-sparc/cpu.h   |   11 ++
 target-sparc/helper.c|2 +-
 target-sparc/machine.c   |2 +
 target-sparc/op_helper.c |   30 +++-
 target-sparc/translate.c |   10 +
 11 files changed, 1494 insertions(+), 4 deletions(-)
 create mode 100644 hw/grlib.h
 create mode 100644 hw/grlib_apbuart.c
 create mode 100644 hw/grlib_gptimer.c
 create mode 100644 hw/grlib_irqmp.c
 create mode 100644 hw/leon3.c




[Qemu-devel] [PATCH 5/6] [RFC] Emulation of Leon3.

2010-12-06 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau chout...@adacore.com
---
 Makefile.target  |5 +-
 hw/leon3.c   |  310 ++
 target-sparc/cpu.h   |   10 ++
 target-sparc/helper.c|2 +-
 target-sparc/op_helper.c |   30 -
 5 files changed, 353 insertions(+), 4 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index 2800f47..f40e04f 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -290,7 +290,10 @@ obj-sparc-y += cirrus_vga.o
 else
 obj-sparc-y = sun4m.o lance.o tcx.o sun4m_iommu.o slavio_intctl.o
 obj-sparc-y += slavio_timer.o slavio_misc.o sparc32_dma.o
-obj-sparc-y += cs4231.o eccmemctl.o sbi.o sun4c_intctl.o
+obj-sparc-y += cs4231.o eccmemctl.o sbi.o sun4c_intctl.o leon3.o
+
+# GRLIB
+obj-sparc-y += grlib_gptimer.o grlib_irqmp.o grlib_apbuart.o
 endif
 
 obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o
diff --git a/hw/leon3.c b/hw/leon3.c
new file mode 100644
index 000..ba61081
--- /dev/null
+++ b/hw/leon3.c
@@ -0,0 +1,310 @@
+/*
+ * QEMU Leon3 System Emulator
+ *
+ * Copyright (c) 2010 AdaCore
+ *
+ * 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 hw.h
+#include qemu-timer.h
+#include qemu-char.h
+#include sysemu.h
+#include boards.h
+#include loader.h
+#include elf.h
+
+#include grlib.h
+
+/* #define DEBUG_LEON3 */
+
+#ifdef DEBUG_LEON3
+#define DPRINTF(fmt, ...)   \
+do { printf(Leon3:  fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...)
+#endif
+
+/* Default system clock.  */
+#define CPU_CLK (40 * 1000 * 1000)
+
+#define PROM_FILENAMEu-boot.bin
+
+#define MAX_PILS 16
+
+typedef struct Leon3State
+{
+uint32_t cache_control;
+uint32_t inst_cache_conf;
+uint32_t data_cache_conf;
+
+uint64_t entry; /* save kernel entry in case of reset */
+} Leon3State;
+
+Leon3State leon3_state;
+
+/* Cache control: emulate the behavior of cache control registers but without
+   any effect on the emulated CPU */
+
+#define CACHE_DISABLED 0x0
+#define CACHE_FROZEN   0x1
+#define CACHE_ENABLED  0x3
+
+/* Cache Control register fields */
+
+#define CACHE_CTRL_IF (1   4)  /* Instruction Cache Freeze on Interrupt */
+#define CACHE_CTRL_DF (1   5)  /* Data Cache Freeze on Interrupt */
+#define CACHE_CTRL_DP (1  14)  /* Data cache flush pending */
+#define CACHE_CTRL_IP (1  15)  /* Instruction cache flush pending */
+#define CACHE_CTRL_IB (1  16)  /* Instruction burst fetch */
+#define CACHE_CTRL_FI (1  21)  /* Flush Instruction cache (Write only) */
+#define CACHE_CTRL_FD (1  22)  /* Flush Data cache (Write only) */
+#define CACHE_CTRL_DS (1  23)  /* Data cache snoop enable */
+
+void leon3_cache_control_int(void)
+{
+uint32_t state = 0;
+
+if (leon3_state.cache_control  CACHE_CTRL_IF) {
+/* Instruction cache state */
+state = leon3_state.cache_control  0x3;
+if (state == CACHE_ENABLED) {
+state = CACHE_FROZEN;
+DPRINTF(Instruction cache: freeze\n);
+}
+
+leon3_state.cache_control = ~0x3;
+leon3_state.cache_control |= state;
+}
+
+if (leon3_state.cache_control  CACHE_CTRL_DF) {
+/* Data cache state */
+state = (leon3_state.cache_control  2)  0x3;
+if (state == CACHE_ENABLED) {
+state = CACHE_FROZEN;
+DPRINTF(Data cache: freeze\n);
+}
+
+leon3_state.cache_control = ~(0x3  2);
+leon3_state.cache_control |= (state  2);
+}
+}
+
+void leon3_cache_control_st(target_ulong addr, uint64_t val, int size)
+{
+DPRINTF(cc st addr:%lu, val:0x%x, size:%d\n, (long unsigned int)addr,
+(unsigned int)val, size);
+
+if (size != 4) {
+DPRINTF( CC 32bits only\n);
+return;
+}
+
+switch (addr) {
+case 0x00:  /* Cache control */
+
+/* These values must always be read as zeros */
+val 

[Qemu-devel] [PATCH 4/6] [RFC] Header file for the GRLIB components.

2010-12-06 Thread Fabien Chouteau

Signed-off-by: Fabien Chouteau chout...@adacore.com
---
 hw/grlib.h |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/hw/grlib.h b/hw/grlib.h
new file mode 100644
index 000..eab7974
--- /dev/null
+++ b/hw/grlib.h
@@ -0,0 +1,27 @@
+#ifndef _GRLIB_H_
+#define _GRLIB_H_
+
+#include qdev.h
+
+/* IRQMP */
+
+DeviceState *grlib_irqmp_create(target_phys_addr_t   base,
+CPUState*env,
+qemu_irq   **cpu_irqs,
+uint32_t nr_irqs);
+
+/* GPTimer */
+
+DeviceState *grlib_gptimer_create(target_phys_addr_t  base,
+  uint32_tnr_timers,
+  uint32_tfreq,
+  qemu_irq   *cpu_irqs,
+  int base_irq);
+
+/* APB UART */
+
+DeviceState *grlib_apbuart_create(target_phys_addr_t  base,
+  CharDriverState*serial,
+  qemu_irqirq);
+
+#endif /* ! _GRLIB_H_ */
-- 
1.7.1




Re: [Qemu-devel] [PATCH 1/3] Consolidate printing of block driver options

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 6, 2010 at 8:17 AM,  jes.soren...@redhat.com wrote:
 @@ -694,6 +721,11 @@ static int img_convert(int argc, char **argv)

     out_filename = argv[argc - 1];

 +    if (options  !strcmp(options, ?)) {
 +        ret = print_block_option_help(out_filename, out_fmt);
 +        goto out2;
 +    }
 +
     if (bs_n  1  out_baseimg) {
         error(-B makes no sense when concatenating multiple input images);
         return 1;

Why goto out2 and not just return like the bs  1  out_baseimg check?

Stefan



[Qemu-devel] Re: [PATCH 3/3] Fail if detecting an unknown option

2010-12-06 Thread Kevin Wolf
Am 06.12.2010 09:02, schrieb Jes Sorensen:
 On 12/03/10 13:30, Kevin Wolf wrote:
 Am 02.12.2010 18:46, schrieb jes.soren...@redhat.com:
 diff --git a/qemu-img.c b/qemu-img.c
 index d0dc445..f2e1c94 100644
 --- a/qemu-img.c
 +++ b/qemu-img.c
 @@ -304,6 +304,12 @@ static int img_create(int argc, char **argv)
  flags = 0;
  for(;;) {
  c = getopt(argc, argv, F:b:f:he6o:);
 +/*
 + * Fail if we detect an unknown argument
 + */
 +if (c == '?') {
 +return 1;
 +}
  if (c == -1) {
  break;
  }

 Why not making it another case in the switch statement below instead of
 an additional if?
 
 There is a perfectly logical explanation for that. Doing that would
 require for me to have clue, which is a bit much to expect :)
 
 That said, we should really do the same for the c == -1 case as well.

That's what I thought at first, too. But then the break relates to the
switch instead of the for, so it would have to become a goto to a new
label. Probably not a big improvement...

Kevin



Re: [Qemu-devel] [PATCH v8 7/7] virtio-console: Enable port throttling when chardev is slow to consume data

2010-12-06 Thread Paul Brook
 On (Thu) Dec 02 2010 [17:31:36], Paul Brook wrote:
 when there's a partial write, it tries to do a write again, which
 will fail with -EAGAIN.

Doesn't that cause the first partial chunk to be incorrectly
transmitted twice? You may only return EAGAIN if no data was
transmitted.
   
   Except for the fact that no caller of qemu_chr_write() resubmits (or
   even checks) partial writes.
  
  I don't buy this argument. The current implementation of qemu_chr_write
  never generates transient failures, so they don't need to.
 
 And applying this patch won't change the situation.

Sure it will. The whole point of the patch is to allow transient failures 
(i.e. avoid blocking) when writing to char backends.  You should expect to 
have to modify the device code to cope with this.

As with the DMA interface added a while ago, I believe it's important to get 
these APIs right.  Quick hacks to support limited use-cases just end up 
needing a complete rewrite (or even worse multiple concurrent 
APIs/implementations) once we actually start using them seriously.

I'm extremely reluctant to add a new layer of buffering that is not visible to 
ether the kernel or the device.  In practice we still need to be able to split 
oversize requests, so handling small split requests should be pretty much 
free.

 What I proposed in the earlier mail was to buffer only the data that has
 to be re-submitted in case the caller is capable of stopping further
 output till the char layer indicates it's free to start again.

That's case (b) below.

  Once data has been transmitted, we have three options:
  
  a) Block until the write completes. This makes the whole patch fairly
  pointless as host and guest block boundaries are unlikely to align.
 
 This is what currently happens and will remain so for callers of
 qemu_chr_write() which don't have a .write_unblocked() pointer assigned
 in the char dev struct.

Obviously if the device doesn't supply an unbocked() hook then the behavior is 
unchanged.  That's trivially uninteresting.  I'm talking about devices that do 
provide the unblocked() hook.

  b) Store the data on the side somewhere. Tell the device all data has
  been sent, and arrange for this data to be flushed before accepting any
  more data. This is bad because it allows the guest to allocate
  arbitrarily large[1] buffers on the host. i.e. a fairly easily
  exploitable DoS attack.
 
 With virtio-serial, this is what's in use.  The buffer is limited to the
 length of the vq (which is a compile-time constant) and there also is
 the virtio_serial_throttle_port() call that tells the guest to not send
 any more data to the host till the char layer indicates it's OK to send
 more data.

No.

Firstly you're assuming all users are virtio based. That may be all you care 
about, but is not acceptable if you want to get this code merged.

Secondly, the virtqueue only restricts the number of direct ring buffer 
entries. It does not restrict the quantity of data each ring entry points to.

As a side note, I notice that the virtio-serial-buf code is already allocating 
buffers and calling iov_to_buf on arbitrary sized requests. This is wrong for 
the same reason. Don't do it.

  c) Return a partial write to the guest. The guest already has to handle
  retries due to EAGAIN, and DMA capable devices already have to handle
  partial mappings, so this doesn't seem too onerous a requirement. This
  is not a new concept, it's the same as the unix write(2)/send(2)
  functions.
 
 This isn't possible with the current vq design.

You need to fix that then.  I'm fairly sure it must be possible as virtio-blk 
has to handle similar problems.

Paul



Re: [Qemu-devel] [PATCH v8 7/7] virtio-console: Enable port throttling when chardev is slow to consume data

2010-12-06 Thread Amit Shah
On (Mon) Dec 06 2010 [09:35:10], Paul Brook wrote:
  On (Thu) Dec 02 2010 [17:31:36], Paul Brook wrote:
  when there's a partial write, it tries to do a write again, which
  will fail with -EAGAIN.
 
 Doesn't that cause the first partial chunk to be incorrectly
 transmitted twice? You may only return EAGAIN if no data was
 transmitted.

Except for the fact that no caller of qemu_chr_write() resubmits (or
even checks) partial writes.
   
   I don't buy this argument. The current implementation of qemu_chr_write
   never generates transient failures, so they don't need to.
  
  And applying this patch won't change the situation.
 
 Sure it will. The whole point of the patch is to allow transient failures 
 (i.e. avoid blocking) when writing to char backends.  You should expect to 
 have to modify the device code to cope with this.

Looks like we're talking of two different cases.  I'm talking here of
current code that uses qemu chardevs and that it'll continue working
fine with this patchset (ie. changes required only to code that wants
-EAGAIN returns).

 As with the DMA interface added a while ago, I believe it's important to get 
 these APIs right.  Quick hacks to support limited use-cases just end up 
 needing a complete rewrite (or even worse multiple concurrent 
 APIs/implementations) once we actually start using them seriously.

Sure.  My proposal is for qemu_chr_write() to succeed all the time.  If
the backend can block, and the caller can handle it, it can get a
-EAGAIN (or WSAEWOULDBLOCK) return.  When the backend becomes writable,
the chardev can call the -writes_unblocked() callback for that caller.
Individual callers need not bother about re-submitting partial writes,
since the buffering can be done in common code in one place
(qemu-char.c).

My previous implementation for leaving out the buffering details to
individual users of qemu chardevs was OK'ed by you but not Anthony.

 I'm extremely reluctant to add a new layer of buffering that is not visible 
 to 
 ether the kernel or the device.  In practice we still need to be able to 
 split 
 oversize requests, so handling small split requests should be pretty much 
 free.

So do you propose to propagate this -EAGAIN error all the way to the
guest?  That won't work for older virtio guests (for virtio, host and
guest changes will be needed).

  What I proposed in the earlier mail was to buffer only the data that has
  to be re-submitted in case the caller is capable of stopping further
  output till the char layer indicates it's free to start again.
 
 That's case (b) below.
 
   Once data has been transmitted, we have three options:
   
   a) Block until the write completes. This makes the whole patch fairly
   pointless as host and guest block boundaries are unlikely to align.
  
  This is what currently happens and will remain so for callers of
  qemu_chr_write() which don't have a .write_unblocked() pointer assigned
  in the char dev struct.
 
 Obviously if the device doesn't supply an unbocked() hook then the behavior 
 is 
 unchanged.  That's trivially uninteresting.  I'm talking about devices that 
 do 
 provide the unblocked() hook.
 
   b) Store the data on the side somewhere. Tell the device all data has
   been sent, and arrange for this data to be flushed before accepting any
   more data. This is bad because it allows the guest to allocate
   arbitrarily large[1] buffers on the host. i.e. a fairly easily
   exploitable DoS attack.
  
  With virtio-serial, this is what's in use.  The buffer is limited to the
  length of the vq (which is a compile-time constant) and there also is
  the virtio_serial_throttle_port() call that tells the guest to not send
  any more data to the host till the char layer indicates it's OK to send
  more data.
 
 No.
 
 Firstly you're assuming all users are virtio based. That may be all you care 
 about, but is not acceptable if you want to get this code merged.

OK, but it's assumed that once a -EAGAIN is returned, the caller will
take appropriate actions to restrict the data sent.  Especially,
send_all has:

if (chr-write_blocked) {
/*
 * We don't handle this situation: the caller should not send
 * us data while we're blocked.
 *
 * We could buffer this data here but that'll only encourage
 * bad behaviour on part of the callers.
 *
 * Also, the data already in fd's buffers isn't easily
 * migratable.  If we want full migration support, all the
 * data landing here needs to be buffered and on migration,
 * anything that's unsent needs to be transferred to the
 * dest. machine (which again isn't a very good way of solving
 * the problem, as the src may become writable just during
 * migration and the reader could receive some data twice,
 * essentially corrupting the data).
 */
return -1;
}

 Secondly, the virtqueue only restricts 

[Qemu-devel] Re: [PATCH 3/3] Fail if detecting an unknown option

2010-12-06 Thread Jes Sorensen
On 12/06/10 10:37, Kevin Wolf wrote:
 Am 06.12.2010 09:02, schrieb Jes Sorensen:
 On 12/03/10 13:30, Kevin Wolf wrote:
 There is a perfectly logical explanation for that. Doing that would
 require for me to have clue, which is a bit much to expect :)

 That said, we should really do the same for the c == -1 case as well.
 
 That's what I thought at first, too. But then the break relates to the
 switch instead of the for, so it would have to become a goto to a new
 label. Probably not a big improvement...

Yeah, it hit me the moment I hit send, so ignore that comment.

Cheers,
Jes




Re: [Qemu-devel] [PATCH 1/3] Consolidate printing of block driver options

2010-12-06 Thread Jes Sorensen
On 12/06/10 10:32, Stefan Hajnoczi wrote:
 On Mon, Dec 6, 2010 at 8:17 AM,  jes.soren...@redhat.com wrote:
 @@ -694,6 +721,11 @@ static int img_convert(int argc, char **argv)

 out_filename = argv[argc - 1];

 +if (options  !strcmp(options, ?)) {
 +ret = print_block_option_help(out_filename, out_fmt);
 +goto out2;
 +}
 +
 if (bs_n  1  out_baseimg) {
 error(-B makes no sense when concatenating multiple input images);
 return 1;
 
 Why goto out2 and not just return like the bs  1  out_baseimg check?

It is cleaner, I'd rather convert the bs_n test to do it too.

Cheers,
Jes






Re: [Qemu-devel] [PATCH 1/3] Consolidate printing of block driver options

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 6, 2010 at 10:20 AM, Jes Sorensen jes.soren...@redhat.com wrote:
 On 12/06/10 10:32, Stefan Hajnoczi wrote:
 On Mon, Dec 6, 2010 at 8:17 AM,  jes.soren...@redhat.com wrote:
 @@ -694,6 +721,11 @@ static int img_convert(int argc, char **argv)

     out_filename = argv[argc - 1];

 +    if (options  !strcmp(options, ?)) {
 +        ret = print_block_option_help(out_filename, out_fmt);
 +        goto out2;
 +    }
 +
     if (bs_n  1  out_baseimg) {
         error(-B makes no sense when concatenating multiple input images);
         return 1;

 Why goto out2 and not just return like the bs  1  out_baseimg check?

 It is cleaner, I'd rather convert the bs_n test to do it too.

out2 tells me nothing and is just indirection for a return.  At this
point no resources have been acquired and it is simplest to bail out
early.

The segfault on out is fixed by setting up bs_n and bs[] together
instead of doing checks in between (that way we never have bs_n  0
and bs == NULL).  Or by adding a check for bs != NULL to the out
cleanup code.  Then it would be safe to use out.

Stefan



Re: [Qemu-devel] [PATCH 0/6] [RFC] New SPARC machine: Leon3

2010-12-06 Thread Artyom Tarasenko
On Mon, Dec 6, 2010 at 10:26 AM, Fabien Chouteau chout...@adacore.com wrote:
 Hi everyone,
 I'm glad to submit my first patches to the Qemu-devel list.

 This patch set introduces a new SPARC V8 machine: Leon3. It's an open-source
 VHDL System-On-Chip, well known in space industry (more information on
 http://www.gaisler.com).

Nice! Haven't looked into the code yet, but it's great to have someone
who cares for V8.
Do you also have a firmware which runs on these machines?

 Leon3 is made of multiple components available in the GrLib VHDL library.
 Three devices are implemented: uart, timers and IRQ manager.
 You can find code for these peripherals in the grlib_* files.

 Modifications have been done to the SPARC cpu emulation code to handle
 Leon3's specific behavior:
  - IRQ management
  - Cache control
  - Asr17 (implementation-dependent Ancillary State Registers)

Is it the only implementation-dependent asr in Leon3? Thought there were more.

  - Shutdown

 Please feel free to comment.

 Regards,

 Fabien Chouteau (6):
  Emulation of GRLIB GPTimer as defined in GRLIB IP Core User's Manual.
  Emulation of GRLIB IRQMP as defined in GRLIB IP Core User's Manual.
  Emulation of GRLIB APB UART as defined in GRLIB IP Core User's
    Manual.
  Header file for the GRLIB components.
  Emulation of Leon3.
  SPARCV8 asr17 register support.

  Makefile.target          |    5 +-
  hw/grlib.h               |   27 +++
  hw/grlib_apbuart.c       |  231 
  hw/grlib_gptimer.c       |  448 
 ++
  hw/grlib_irqmp.c         |  416 ++
  hw/leon3.c               |  316 
  target-sparc/cpu.h       |   11 ++
  target-sparc/helper.c    |    2 +-
  target-sparc/machine.c   |    2 +
  target-sparc/op_helper.c |   30 +++-
  target-sparc/translate.c |   10 +
  11 files changed, 1494 insertions(+), 4 deletions(-)
  create mode 100644 hw/grlib.h
  create mode 100644 hw/grlib_apbuart.c
  create mode 100644 hw/grlib_gptimer.c
  create mode 100644 hw/grlib_irqmp.c
  create mode 100644 hw/leon3.c



-- 
Regards,
Artyom Tarasenko

solaris/sparc under qemu blog: http://tyom.blogspot.com/



Re: [Qemu-devel] [PATCH 1/3] Consolidate printing of block driver options

2010-12-06 Thread Jes Sorensen
On 12/06/10 11:37, Stefan Hajnoczi wrote:
 On Mon, Dec 6, 2010 at 10:20 AM, Jes Sorensen jes.soren...@redhat.com wrote:
 On 12/06/10 10:32, Stefan Hajnoczi wrote:
 On Mon, Dec 6, 2010 at 8:17 AM,  jes.soren...@redhat.com wrote:
 Why goto out2 and not just return like the bs  1  out_baseimg check?

 It is cleaner, I'd rather convert the bs_n test to do it too.
 
 out2 tells me nothing and is just indirection for a return.  At this
 point no resources have been acquired and it is simplest to bail out
 early.

A consistent out path is more likely to catch issues if the code is
modified later. I am not a big fan of the random mix of return vs goto
out that we spray over the code or having help() call exit() for
that matter.

Cheers,
Jes



Re: [Qemu-devel] [PATCH 1/3] Consolidate printing of block driver options

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 6, 2010 at 10:47 AM, Jes Sorensen jes.soren...@redhat.com wrote:
 On 12/06/10 11:37, Stefan Hajnoczi wrote:
 On Mon, Dec 6, 2010 at 10:20 AM, Jes Sorensen jes.soren...@redhat.com 
 wrote:
 On 12/06/10 10:32, Stefan Hajnoczi wrote:
 On Mon, Dec 6, 2010 at 8:17 AM,  jes.soren...@redhat.com wrote:
 Why goto out2 and not just return like the bs  1  out_baseimg check?

 It is cleaner, I'd rather convert the bs_n test to do it too.

 out2 tells me nothing and is just indirection for a return.  At this
 point no resources have been acquired and it is simplest to bail out
 early.

 A consistent out path is more likely to catch issues if the code is
 modified later. I am not a big fan of the random mix of return vs goto
 out that we spray over the code or having help() call exit() for
 that matter.

img_convert() wasn't random before your patch: return statements
before the first resource allocation, gotos afterwards. :P

I see what you're saying though.  How about making out work in all
cases and consistently using goto out?

Stefan



Re: [Qemu-devel] [PATCH, RFT] monitor: implement x86 info tlb for PAE and long modes

2010-12-06 Thread Alexander Graf

On 05.12.2010, at 17:25, Blue Swirl wrote:

 'info tlb' didn't show correct information for PAE mode and
 x86_64 long mode.
 
 Implement the missing modes. Also print NX bit for PAE and long modes.
 Fix off-by-one error in 32 bit mode mask.
 
 Signed-off-by: Blue Swirl blauwir...@gmail.com
 ---
 
 I didn't find an OS that enabled PAE, please test and report.

Xen does. Just take a random recent xen kernel and run it with -kernel :).


Alex




[Qemu-devel] qemu bug report?

2010-12-06 Thread Witold Paluszynski
I am running qemu from a qcow virtual disk with Windows XP installed
trying various network options.  Qemu is running on a Ubuntu x86_64
machine to which I am connected remotely by ssh from a Sun Ray terminal
on a Solaris Sun SPARC machine.

Upon starting, qemu says on the terminal:
unknown keycodes `sun(type6_usb)_aliases(qwerty)', please report to 
qemu-devel@nongnu.org

But the emulation and the keyboard work (at least some simple keyboard
sequences such as Alt-F4 works).

Witold Paluszynski wit...@ict.pwr.wroc.pl



[Qemu-devel] Re: Block device resize detection

2010-12-06 Thread Alexander Graf
Hi Vandeir,


On 06.12.2010, at 11:49, Vandeir Eduardo wrote:

 Hi guys,
 
 I have a KVM guest machine, lets name it VMTEST,
 using an iSCSI LUN as a virtio device. Something like this:
 
 disk type='block' device='disk'
   driver name='qemu' type='raw' cache='none'/
   source 
 dev='/dev/disk/by-path/ip-w.x.y.z:3260-iscsi-iqn.2010-10.br.furb.inf:disk0-lun-4'/
  target dev='vda' bus='virtio'/
 /disk
 
 On iSCSI server, if I resize this LUN, this resize is detected
 on KVM host, but not on the VMTEST. The device resize is only
 detected if I restart VMTEST. Is there a way to make VMTEST detect
 the /dev/vda resize without restarting it?
 
 On VMTEST I already tried commands like partprobe /dev/vda, 
 hdparm -z /dev/vda and blockdev --rereadpt /dev/vda, but none of
 was capable to detect the block device (/dev/vda) resize.

The probing of an image is only done at initialization time of the block 
backend driver, which in your case is the bootup. The only chance you have of 
reevaluating it would be to hot-add another virtio device with the resized 
image.

Alternatively, you could also try to write a patch for reevaluation plumbing, 
so that the hba emulation layer can trigger reevaluation in the disk layer.


Alex




[Qemu-devel] Re: Block device resize detection

2010-12-06 Thread Vandeir Eduardo
Humm,

unfortunately I'm not a developer, only a sys admin, but this would
be a nice feature to avoid restarting vm guests.

I didn't want, but I think I will have to add another
software layer (LVM) inside the guest vm.
This way, when I need more space, I hot-add another device and
add it to the volume group of the guest vm.

Thanks.

On Mon, 6 Dec 2010, Alexander Graf wrote:

 Hi Vandeir,
 
 
 On 06.12.2010, at 11:49, Vandeir Eduardo wrote:
 
  Hi guys,
  
  I have a KVM guest machine, lets name it VMTEST,
  using an iSCSI LUN as a virtio device. Something like this:
  
  disk type='block' device='disk'
driver name='qemu' type='raw' cache='none'/
source 
  dev='/dev/disk/by-path/ip-w.x.y.z:3260-iscsi-iqn.2010-10.br.furb.inf:disk0-lun-4'/
   target dev='vda' bus='virtio'/
  /disk
  
  On iSCSI server, if I resize this LUN, this resize is detected
  on KVM host, but not on the VMTEST. The device resize is only
  detected if I restart VMTEST. Is there a way to make VMTEST detect
  the /dev/vda resize without restarting it?
  
  On VMTEST I already tried commands like partprobe /dev/vda, 
  hdparm -z /dev/vda and blockdev --rereadpt /dev/vda, but none of
  was capable to detect the block device (/dev/vda) resize.
 
 The probing of an image is only done at initialization time of the block 
 backend driver, which in your case is the bootup. The only chance you have of 
 reevaluating it would be to hot-add another virtio device with the resized 
 image.
 
 Alternatively, you could also try to write a patch for reevaluation plumbing, 
 so that the hba emulation layer can trigger reevaluation in the disk layer.
 
 
 Alex
 
 

__
Vandeir Eduardo
(CCNA, LPIC-2, MCSA 2003 Server)
Laboratório de Computação e Informática (LCI) - Campus III
Fundacao Universidade Regional de Blumenau (FURB)
Rua São Paulo, 2171 - Sala A009 - CEP: 89.030-000
Blumenau, SC, Brasil.
Fone: +55 47 3321-7342

Re: [Qemu-devel] [PATCH] ceph/rbd block driver for qemu-kvm (v8)

2010-12-06 Thread Kevin Wolf
Am 17.11.2010 22:42, schrieb Christian Brunner:
 Here is another update for the ceph storage driver. It includes changes
 for the annotations Stefan made last week and a bit more things Sage
 discovered while looking over the driver again.
 
 I really hope that this time we are not only close, but have reached
 a quality that everyone is satisfied with. - Of course suggestions for 
 further improvements are always welcome.
 
 Regards,
 Christian
 
 
 RBD is an block driver for the distributed file system Ceph
 (http://ceph.newdream.net/). This driver uses librados (which
 is part of the Ceph server) for direct access to the Ceph object
 store and is running entirely in userspace (Yehuda also
 wrote a driver for the linux kernel, that can be used to access
 rbd volumes as a block device).
 ---
  Makefile.objs |1 +
  block/rbd.c   | 1059 
 +
  block/rbd_types.h |   71 
  configure |   31 ++
  4 files changed, 1162 insertions(+), 0 deletions(-)
  create mode 100644 block/rbd.c
  create mode 100644 block/rbd_types.h

This lacks a Signed-off-by. Please merge Yehuda's fix for configure when
you resend the patch.

What's the easiest way to try it out? I tried to use vstart.sh and copy
the generated ceph.conf to /etc/ceph/ceph.conf so that qemu-img etc.
find the monitor address. However, that leads to a hang when I try rbd
list or ./qemu-img create -f rbd rbd:data/test.img 4G, so I seem to
be missing something.

The only thing I have achieved until now with my attempts of trying it
out (and trying wrong things, of course) is that I stumbled over the the
following segfault in librados:

Program received signal SIGSEGV, Segmentation fault.
Objecter::shutdown (this=0x0) at osdc/Objecter.cc:59
59assert(client_lock.is_locked());  // otherwise event
cancellation is unsafe
(gdb) bt
#0  Objecter::shutdown (this=0x0) at osdc/Objecter.cc:59
#1  0x77ca5ce4 in RadosClient::shutdown (this=0xa58a90) at
librados.cc:392
#2  0x77ca8ccc in rados_deinitialize () at librados.cc:1770
#3  0x0043150c in rbd_create (filename=value optimized out,
options=value optimized out) at block/rbd.c:304
#4  0x00405f10 in img_create (argc=5, argv=0x7fffde80) at
qemu-img.c:409
#5  0x003c9f01eb1d in __libc_start_main () from /lib64/libc.so.6
#6  0x00403999 in _start ()

Kevin



Re: [Qemu-devel] [PATCH, RFT] monitor: implement x86 info tlb for PAE and long modes

2010-12-06 Thread Ian Campbell
On Mon, 2010-12-06 at 12:12 +0100, Alexander Graf wrote:
 On 05.12.2010, at 17:25, Blue Swirl wrote:
 
  'info tlb' didn't show correct information for PAE mode and
  x86_64 long mode.
  
  Implement the missing modes. Also print NX bit for PAE and long modes.
  Fix off-by-one error in 32 bit mode mask.
  
  Signed-off-by: Blue Swirl blauwir...@gmail.com
  ---
  
  I didn't find an OS that enabled PAE, please test and report.
 
 Xen does. Just take a random recent xen kernel and run it with -kernel :).

In addition AFAIK recent 32 bit Fedora is PAE enabled by default (so is
RHEL6?). Debian also supplies a -686-bigmem kernel flavour which is
their name for PAE enabled.

Ian.

-- 
Ian Campbell
Current Noise: The Dillinger Escape Plan - Hollywood Squares

Turnaucka's Law:
The attention span of a computer is only as long as its
electrical cord.




[Qemu-devel] Re: Block device resize detection

2010-12-06 Thread Kevin Wolf
Am 06.12.2010 12:29, schrieb Alexander Graf:
 On 06.12.2010, at 11:49, Vandeir Eduardo wrote:

 I have a KVM guest machine, lets name it VMTEST,
 using an iSCSI LUN as a virtio device. Something like this:

 disk type='block' device='disk'
   driver name='qemu' type='raw' cache='none'/
   source 
 dev='/dev/disk/by-path/ip-w.x.y.z:3260-iscsi-iqn.2010-10.br.furb.inf:disk0-lun-4'/
  target dev='vda' bus='virtio'/
 /disk

 On iSCSI server, if I resize this LUN, this resize is detected
 on KVM host, but not on the VMTEST. The device resize is only
 detected if I restart VMTEST. Is there a way to make VMTEST detect
 the /dev/vda resize without restarting it?

 On VMTEST I already tried commands like partprobe /dev/vda, 
 hdparm -z /dev/vda and blockdev --rereadpt /dev/vda, but none of
 was capable to detect the block device (/dev/vda) resize.
 
 The probing of an image is only done at initialization time of the block 
 backend driver, which in your case is the bootup. The only chance you have of 
 reevaluating it would be to hot-add another virtio device with the resized 
 image.
 
 Alternatively, you could also try to write a patch for reevaluation plumbing, 
 so that the hba emulation layer can trigger reevaluation in the disk layer.

This is basically online disk resizing, which we have discussed in the
past and which I think we want to have for virtio-blk eventually, but
currently it's supported neither in the host qemu nor in the guest kernel.

Kevin



Re: [Qemu-devel] [PATCH v8 7/7] virtio-console: Enable port throttling when chardev is slow to consume data

2010-12-06 Thread Paul Brook
  As with the DMA interface added a while ago, I believe it's important to
  get these APIs right.  Quick hacks to support limited use-cases just end
  up needing a complete rewrite (or even worse multiple concurrent
  APIs/implementations) once we actually start using them seriously.
 
 Sure.  My proposal is for qemu_chr_write() to succeed all the time.  If
 the backend can block, and the caller can handle it, it can get a
 -EAGAIN (or WSAEWOULDBLOCK) return.  When the backend becomes writable,
 the chardev can call the -writes_unblocked() callback for that caller.
 Individual callers need not bother about re-submitting partial writes,
 since the buffering can be done in common code in one place
 (qemu-char.c).

That's only OK if you assume it's OK to buffer all but one byte of the 
transmit request.

  I'm extremely reluctant to add a new layer of buffering that is not
  visible to ether the kernel or the device.  In practice we still need to
  be able to split oversize requests, so handling small split requests
  should be pretty much free.
 
 So do you propose to propagate this -EAGAIN error all the way to the
 guest?  That won't work for older virtio guests (for virtio, host and
 guest changes will be needed).

Huh? That doesn't make any sense. The guest is already using an asyncronous 
submission mechanism.  
With a virtio device the status of a buffer becomes indeterminate once it has 
been placed into the queue. Only when it is removed from the queue do we know 
that it has completed.  The device may transfer all or part of that buffer at 
any time in between.
 
b) Store the data on the side somewhere. Tell the device all data has
been sent, and arrange for this data to be flushed before accepting
any more data. This is bad because it allows the guest to allocate
arbitrarily large[1] buffers on the host. i.e. a fairly easily
exploitable DoS attack.
   
   With virtio-serial, this is what's in use.  The buffer is limited to
   the length of the vq (which is a compile-time constant) and there also
   is the virtio_serial_throttle_port() call that tells the guest to not
   send any more data to the host till the char layer indicates it's OK
   to send more data.
  
  No.
  
  Firstly you're assuming all users are virtio based. That may be all you
  care about, but is not acceptable if you want to get this code merged.
 
 OK, but it's assumed that once a -EAGAIN is returned, the caller will
 take appropriate actions to restrict the data sent.  Especially,
 send_all has:
 
 if (chr-write_blocked) {
 /*
  * We don't handle this situation: the caller should not send
  * us data while we're blocked.
  *
  * We could buffer this data here but that'll only encourage
  * bad behaviour on part of the callers.

  */
 return -1;
 }

If you're being draconian about this then do it properly and make this an 
abort. Otherwise return -EAGAIN. Returning a random error seems like the worst 
of both worlds.  Your code results in spurious guest errors (or lost data) 
with real indication that this is actually a qemu device emulation bug.
 
  Secondly, the virtqueue only restricts the number of direct ring buffer
  entries. It does not restrict the quantity of data each ring entry points
  to.
 
 But that's entirely in guest memory, so it's limited to the amount of
 RAM that has been allocated to the guest.

Exactly. The guest can cause ram_size * nr_ports of additional host memory to 
be allocated.  Not acceptable. 

c) Return a partial write to the guest. The guest already has to
handle retries due to EAGAIN, and DMA capable devices already have
to handle partial mappings, so this doesn't seem too onerous a
requirement. This is not a new concept, it's the same as the unix
write(2)/send(2) functions.
   
   This isn't possible with the current vq design.
  
  You need to fix that then.  I'm fairly sure it must be possible as
  virtio-blk has to handle similar problems.
 
 This was one of the items that was debated during the lead-up to
 virtio-serial merge:  whether a write() call in the guest means data has
 been flushed out to the host chardev or if the guest has just passed it
 on to the host to take care of it.  We merged the latter approach.

Ensuring that data has actually reached the endpoint (v.s. being in a queue 
for transmission at the next available point) is a different problem, and 
probably one better solved by higher level protocols.


Char devices are fundamentally stream based devices with no frame boundaries 
(or alternatively a fixed frame size of 1 byte).

Your device only reports progress to the guest in virtqueue-entry sized 
chunks. However that places no real restrictions on how the data is passed to 
the host. You can choose to pass a single queue entry to the host in several 
smaller chunks, or even pass several queue entries to the host in a single 
request.

Paul



Re: [Qemu-devel] [PULL 00/16] Block patches

2010-12-06 Thread Anthony Liguori

On 11/30/2010 11:58 AM, Kevin Wolf wrote:

The following changes since commit f711df67d611e4762966a249742a5f7499e19f99:

   microblaze: target-ify target_ucontext (2010-11-23 10:04:30 +0100)

are available in the git repository at:
   git://repo.or.cz/qemu/kevin.git for-anthony
   


I see:

commit 393f398b69f9baadc3f29d822a0b5b74ca63b919
Author: Richard Henderson r...@twiddle.net
Date:   Mon Nov 22 14:57:58 2010 -0800

tcg-ia64: Fix warning in qemu_ld.

The usermode version of qemu_ld doesn't used mem_index,
leading to set-but-not-used warnings.

Signed-off-by: Richard Henderson r...@twiddle.net
Signed-off-by: Edgar E. Iglesias ed...@axis.com

As the head on that branch which doesn't seem right.

Regards,

Anthony Liguori


Avi Kivity (1):
   ide: convert bmdma address ioport to ioport_register()

Christoph Hellwig (1):
   raw-posix: raw_pwrite comment fixup

Hannes Reinecke (5):
   scsi: Increase the number of possible devices
   scsi: Return SAM status codes
   scsi: INQUIRY VPD fixes
   scsi: Move sense handling into the driver
   scsi-disk: Remove duplicate cdb parsing

Kevin Wolf (5):
   block: Remove unused s-hd in various drivers
   ide: Factor ide_dma_set_inactive out
   ide: Set bus master inactive on error
   ide: Ignore double DMA transfer starts/stops
   ide: Reset current_addr after stopping DMA

Marcelo Tosatti (1):
   block migration: do not submit multiple AIOs for same sector (v2)

Ryan Harper (1):
   Implement drive_del to decouple block removal from device removal

Stefan Hajnoczi (1):
   scsi-disk: Move active request asserts

Stefano Stabellini (1):
   qemu and qemu-xen: support empty write barriers in xen_disk

  block-migration.c |   14 ++
  block/qcow.c  |1 -
  block/qcow2.h |1 -
  block/raw-posix.c |2 +-
  block/vdi.c   |1 -
  block/vmdk.c  |1 -
  block/vpc.c   |2 -
  blockdev.c|   39 +++
  blockdev.h|3 +-
  hmp-commands.hx   |   18 +++
  hw/ide/cmd646.c   |8 +--
  hw/ide/core.c |   31 ++--
  hw/ide/internal.h |2 +
  hw/ide/pci.c  |  131 +++---
  hw/ide/pci.h  |7 +--
  hw/ide/piix.c |8 +--
  hw/ide/via.c  |8 +--
  hw/scsi-bus.c |   12 +
  hw/scsi-defs.h|   20 
  hw/scsi-disk.c|  137 +---
  hw/scsi-generic.c |   10 ++--
  hw/scsi.h |   11 +
  hw/xen_disk.c |   12 -
  23 files changed, 234 insertions(+), 245 deletions(-)


   





Re: [Qemu-devel] [PULL 00/16] Block patches

2010-12-06 Thread Kevin Wolf
Am 06.12.2010 14:32, schrieb Anthony Liguori:
 On 11/30/2010 11:58 AM, Kevin Wolf wrote:
 The following changes since commit f711df67d611e4762966a249742a5f7499e19f99:

microblaze: target-ify target_ucontext (2010-11-23 10:04:30 +0100)

 are available in the git repository at:
git://repo.or.cz/qemu/kevin.git for-anthony

 
 I see:
 
 commit 393f398b69f9baadc3f29d822a0b5b74ca63b919
 Author: Richard Henderson r...@twiddle.net
 Date:   Mon Nov 22 14:57:58 2010 -0800
 
  tcg-ia64: Fix warning in qemu_ld.
 
  The usermode version of qemu_ld doesn't used mem_index,
  leading to set-but-not-used warnings.
 
  Signed-off-by: Richard Henderson r...@twiddle.net
  Signed-off-by: Edgar E. Iglesias ed...@axis.com
 
 As the head on that branch which doesn't seem right.

You have pulled this already last week, so after a rebase on my side it
just points to some random commit in master. :-)

Kevin



[Qemu-devel] [PATCHv7 04/16] Add get_fw_dev_path callback to ISA bus in qdev.

2010-12-06 Thread Gleb Natapov
Use device ioports to create unique device path.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/isa-bus.c |   16 
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index c0ac7e9..c423c1b 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -31,11 +31,13 @@ static ISABus *isabus;
 target_phys_addr_t isa_mem_base = 0;
 
 static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent);
+static char *isabus_get_fw_dev_path(DeviceState *dev);
 
 static struct BusInfo isa_bus_info = {
 .name  = ISA,
 .size  = sizeof(ISABus),
 .print_dev = isabus_dev_print,
+.get_fw_dev_path = isabus_get_fw_dev_path,
 };
 
 ISABus *isa_bus_new(DeviceState *dev)
@@ -188,4 +190,18 @@ static void isabus_register_devices(void)
 sysbus_register_withprop(isabus_bridge_info);
 }
 
+static char *isabus_get_fw_dev_path(DeviceState *dev)
+{
+ISADevice *d = (ISADevice*)dev;
+char path[40];
+int off;
+
+off = snprintf(path, sizeof(path), %s, qdev_fw_name(dev));
+if (d-nioports) {
+snprintf(path + off, sizeof(path) - off, @%04x, d-ioports[0]);
+}
+
+return strdup(path);
+}
+
 device_init(isabus_register_devices)
-- 
1.7.2.3




[Qemu-devel] [PATCHv7 06/16] Add get_fw_dev_path callback to IDE bus.

2010-12-06 Thread Gleb Natapov

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/ide/qdev.c |   13 +
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 88ff657..01a181b 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -24,9 +24,12 @@
 
 /* - */
 
+static char *idebus_get_fw_dev_path(DeviceState *dev);
+
 static struct BusInfo ide_bus_info = {
 .name  = IDE,
 .size  = sizeof(IDEBus),
+.get_fw_dev_path = idebus_get_fw_dev_path,
 };
 
 void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id)
@@ -35,6 +38,16 @@ void ide_bus_new(IDEBus *idebus, DeviceState *dev, int 
bus_id)
 idebus-bus_id = bus_id;
 }
 
+static char *idebus_get_fw_dev_path(DeviceState *dev)
+{
+char path[30];
+
+snprintf(path, sizeof(path), %...@%d, qdev_fw_name(dev),
+ ((IDEBus*)dev-parent_bus)-bus_id);
+
+return strdup(path);
+}
+
 static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
 IDEDevice *dev = DO_UPCAST(IDEDevice, qdev, qdev);
-- 
1.7.2.3




[Qemu-devel] [PATCHv7 00/16] boot order specification

2010-12-06 Thread Gleb Natapov
I am using open firmware naming scheme to specify device path names.
Changes from last version: rebase to master, added pointers to OF specs,
   added bootindex parameter documentation.

Gleb Natapov (16):
  Introduce fw_name field to DeviceInfo structure.
  Introduce new BusInfo callback get_fw_dev_path.
  Keep track of ISA ports ISA device is using in qdev.
  Add get_fw_dev_path callback to ISA bus in qdev.
  Store IDE bus id in IDEBus structure for easy access.
  Add get_fw_dev_path callback to IDE bus.
  Add get_fw_dev_path callback for system bus.
  Add get_fw_dev_path callback for pci bus.
  Record which USBDevice USBPort belongs too.
  Add get_fw_dev_path callback for usb bus.
  Add get_fw_dev_path callback to scsi bus.
  Add bootindex parameter to net/block/fd device
  Change fw_cfg_add_file() to get full file path as a parameter.
  Add bootindex for option roms.
  Add notifier that will be called when machine is fully created.
  Pass boot device list to firmware.

 block_int.h   |4 +-
 hw/cs4231a.c  |1 +
 hw/e1000.c|4 ++
 hw/eepro100.c |3 +
 hw/fdc.c  |   12 ++
 hw/fw_cfg.c   |   30 --
 hw/fw_cfg.h   |4 +-
 hw/gus.c  |4 ++
 hw/ide/cmd646.c   |4 +-
 hw/ide/internal.h |3 +-
 hw/ide/isa.c  |5 ++-
 hw/ide/piix.c |4 +-
 hw/ide/qdev.c |   22 ++-
 hw/ide/via.c  |4 +-
 hw/isa-bus.c  |   42 +++
 hw/isa.h  |4 ++
 hw/lance.c|1 +
 hw/loader.c   |   32 ---
 hw/loader.h   |8 ++--
 hw/m48t59.c   |1 +
 hw/mc146818rtc.c  |1 +
 hw/multiboot.c|3 +-
 hw/ne2000-isa.c   |3 +
 hw/ne2000.c   |5 ++-
 hw/nseries.c  |4 +-
 hw/palm.c |6 +-
 hw/parallel.c |5 ++
 hw/pc.c   |7 ++-
 hw/pci.c  |  110 ---
 hw/pci_host.c |2 +
 hw/pckbd.c|3 +
 hw/pcnet-pci.c|2 +-
 hw/pcnet.c|4 ++
 hw/piix_pci.c |1 +
 hw/qdev.c |   32 +++
 hw/qdev.h |   14 ++
 hw/rtl8139.c  |4 ++
 hw/sb16.c |4 ++
 hw/scsi-bus.c |   23 +++
 hw/scsi-disk.c|2 +
 hw/serial.c   |1 +
 hw/sysbus.c   |   30 ++
 hw/sysbus.h   |4 ++
 hw/usb-bus.c  |   45 -
 hw/usb-hub.c  |3 +-
 hw/usb-musb.c |2 +-
 hw/usb-net.c  |3 +
 hw/usb-ohci.c |2 +-
 hw/usb-uhci.c |2 +-
 hw/usb.h  |3 +-
 hw/virtio-blk.c   |2 +
 hw/virtio-net.c   |2 +
 hw/virtio-pci.c   |1 +
 net.h |4 +-
 qemu-config.c |   17 
 sysemu.h  |   11 +-
 vl.c  |  114 -
 57 files changed, 593 insertions(+), 80 deletions(-)

-- 
1.7.2.3




[Qemu-devel] [PATCHv7 03/16] Keep track of ISA ports ISA device is using in qdev.

2010-12-06 Thread Gleb Natapov
Store all io ports used by device in ISADevice structure.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/cs4231a.c |1 +
 hw/fdc.c |3 +++
 hw/gus.c |4 
 hw/ide/isa.c |2 ++
 hw/isa-bus.c |   25 +
 hw/isa.h |4 
 hw/m48t59.c  |1 +
 hw/mc146818rtc.c |1 +
 hw/ne2000-isa.c  |3 +++
 hw/parallel.c|5 +
 hw/pckbd.c   |3 +++
 hw/sb16.c|4 
 hw/serial.c  |1 +
 13 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/hw/cs4231a.c b/hw/cs4231a.c
index 4d5ce5c..598f032 100644
--- a/hw/cs4231a.c
+++ b/hw/cs4231a.c
@@ -645,6 +645,7 @@ static int cs4231a_initfn (ISADevice *dev)
 isa_init_irq (dev, s-pic, s-irq);
 
 for (i = 0; i  4; i++) {
+isa_init_ioport(dev, i);
 register_ioport_write (s-port + i, 1, 1, cs_write, s);
 register_ioport_read (s-port + i, 1, 1, cs_read, s);
 }
diff --git a/hw/fdc.c b/hw/fdc.c
index a467c4b..5ab754b 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1983,6 +1983,9 @@ static int isabus_fdc_init1(ISADevice *dev)
   fdctrl_write_port, fdctrl);
 register_ioport_write(iobase + 0x07, 1, 1,
   fdctrl_write_port, fdctrl);
+isa_init_ioport_range(dev, iobase + 1, 5);
+isa_init_ioport(dev, iobase + 7);
+
 isa_init_irq(isa-busdev, fdctrl-irq, isairq);
 fdctrl-dma_chann = dma_chann;
 
diff --git a/hw/gus.c b/hw/gus.c
index e9016d8..ff9e7c7 100644
--- a/hw/gus.c
+++ b/hw/gus.c
@@ -264,20 +264,24 @@ static int gus_initfn (ISADevice *dev)
 
 register_ioport_write (s-port, 1, 1, gus_writeb, s);
 register_ioport_write (s-port, 1, 2, gus_writew, s);
+isa_init_ioport_range(dev, s-port, 2);
 
 register_ioport_read ((s-port + 0x100)  0xf00, 1, 1, gus_readb, s);
 register_ioport_read ((s-port + 0x100)  0xf00, 1, 2, gus_readw, s);
+isa_init_ioport_range(dev, (s-port + 0x100)  0xf00, 2);
 
 register_ioport_write (s-port + 6, 10, 1, gus_writeb, s);
 register_ioport_write (s-port + 6, 10, 2, gus_writew, s);
 register_ioport_read (s-port + 6, 10, 1, gus_readb, s);
 register_ioport_read (s-port + 6, 10, 2, gus_readw, s);
+isa_init_ioport_range(dev, s-port + 6, 10);
 
 
 register_ioport_write (s-port + 0x100, 8, 1, gus_writeb, s);
 register_ioport_write (s-port + 0x100, 8, 2, gus_writew, s);
 register_ioport_read (s-port + 0x100, 8, 1, gus_readb, s);
 register_ioport_read (s-port + 0x100, 8, 2, gus_readw, s);
+isa_init_ioport_range(dev, s-port + 0x100, 8);
 
 DMA_register_channel (s-emu.gusdma, GUS_read_DMA, s);
 s-emu.himemaddr = s-himem;
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 9856435..4206afd 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -70,6 +70,8 @@ static int isa_ide_initfn(ISADevice *dev)
 ide_bus_new(s-bus, s-dev.qdev);
 ide_init_ioport(s-bus, s-iobase, s-iobase2);
 isa_init_irq(dev, s-irq, s-isairq);
+isa_init_ioport_range(dev, s-iobase, 8);
+isa_init_ioport(dev, s-iobase2);
 ide_init2(s-bus, s-irq);
 vmstate_register(dev-qdev, 0, vmstate_ide_isa, s);
 return 0;
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 26036e0..c0ac7e9 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -92,6 +92,31 @@ void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq)
 dev-nirqs++;
 }
 
+static void isa_init_ioport_one(ISADevice *dev, uint16_t ioport)
+{
+assert(dev-nioports  ARRAY_SIZE(dev-ioports));
+dev-ioports[dev-nioports++] = ioport;
+}
+
+static int isa_cmp_ports(const void *p1, const void *p2)
+{
+return *(uint16_t*)p1 - *(uint16_t*)p2;
+}
+
+void isa_init_ioport_range(ISADevice *dev, uint16_t start, uint16_t length)
+{
+int i;
+for (i = start; i  start + length; i++) {
+isa_init_ioport_one(dev, i);
+}
+qsort(dev-ioports, dev-nioports, sizeof(dev-ioports[0]), isa_cmp_ports);
+}
+
+void isa_init_ioport(ISADevice *dev, uint16_t ioport)
+{
+isa_init_ioport_range(dev, ioport, 1);
+}
+
 static int isa_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
 ISADevice *dev = DO_UPCAST(ISADevice, qdev, qdev);
diff --git a/hw/isa.h b/hw/isa.h
index aaf0272..4794b76 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -14,6 +14,8 @@ struct ISADevice {
 DeviceState qdev;
 uint32_t isairq[2];
 int nirqs;
+uint16_t ioports[32];
+int nioports;
 };
 
 typedef int (*isa_qdev_initfn)(ISADevice *dev);
@@ -26,6 +28,8 @@ ISABus *isa_bus_new(DeviceState *dev);
 void isa_bus_irqs(qemu_irq *irqs);
 qemu_irq isa_reserve_irq(int isairq);
 void isa_init_irq(ISADevice *dev, qemu_irq *p, int isairq);
+void isa_init_ioport(ISADevice *dev, uint16_t ioport);
+void isa_init_ioport_range(ISADevice *dev, uint16_t start, uint16_t length);
 void isa_qdev_register(ISADeviceInfo *info);
 ISADevice *isa_create(const char *name);
 ISADevice *isa_create_simple(const char *name);
diff --git a/hw/m48t59.c b/hw/m48t59.c
index c7492a6..75a94e1 100644
--- 

[Qemu-devel] [PATCHv7 10/16] Add get_fw_dev_path callback for usb bus.

2010-12-06 Thread Gleb Natapov

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/usb-bus.c |   42 ++
 1 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 256b881..8b4583c 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -5,11 +5,13 @@
 #include monitor.h
 
 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
+static char *usbbus_get_fw_dev_path(DeviceState *dev);
 
 static struct BusInfo usb_bus_info = {
 .name  = USB,
 .size  = sizeof(USBBus),
 .print_dev = usb_bus_dev_print,
+.get_fw_dev_path = usbbus_get_fw_dev_path,
 };
 static int next_usb_bus = 0;
 static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses);
@@ -307,3 +309,43 @@ USBDevice *usbdevice_create(const char *cmdline)
 }
 return usb-usbdevice_init(params);
 }
+
+static int usbbus_get_fw_dev_path_helper(USBDevice *d, USBBus *bus, char *p,
+ int len)
+{
+int l = 0;
+USBPort *port;
+
+QTAILQ_FOREACH(port, bus-used, next) {
+if (port-dev == d) {
+if (port-pdev) {
+l = usbbus_get_fw_dev_path_helper(port-pdev, bus, p, len);
+}
+l += snprintf(p + l, len - l, %...@%x/, qdev_fw_name(d-qdev),
+  port-index);
+break;
+}
+}
+
+return l;
+}
+
+static char *usbbus_get_fw_dev_path(DeviceState *dev)
+{
+USBDevice *d = (USBDevice*)dev;
+USBBus *bus = usb_bus_from_device(d);
+char path[100];
+int l;
+
+assert(d-attached != 0);
+
+l = usbbus_get_fw_dev_path_helper(d, bus, path, sizeof(path));
+
+if (l == 0) {
+abort();
+}
+
+path[l-1] = '\0';
+
+return strdup(path);
+}
-- 
1.7.2.3




[Qemu-devel] [PATCHv7 01/16] Introduce fw_name field to DeviceInfo structure.

2010-12-06 Thread Gleb Natapov
Add fw_name to DeviceInfo to use in device path building. In
contrast to name fw_name should refer to functionality device
provides instead of particular device model like name does.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/fdc.c|1 +
 hw/ide/isa.c|1 +
 hw/ide/qdev.c   |1 +
 hw/isa-bus.c|1 +
 hw/lance.c  |1 +
 hw/piix_pci.c   |1 +
 hw/qdev.h   |6 ++
 hw/scsi-disk.c  |1 +
 hw/usb-hub.c|1 +
 hw/usb-net.c|1 +
 hw/virtio-pci.c |1 +
 11 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index c159dcb..a467c4b 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -2040,6 +2040,7 @@ static const VMStateDescription vmstate_isa_fdc ={
 static ISADeviceInfo isa_fdc_info = {
 .init = isabus_fdc_init1,
 .qdev.name  = isa-fdc,
+.qdev.fw_name  = fdc,
 .qdev.size  = sizeof(FDCtrlISABus),
 .qdev.no_user = 1,
 .qdev.vmsd  = vmstate_isa_fdc,
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 6b57e0d..9856435 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -98,6 +98,7 @@ ISADevice *isa_ide_init(int iobase, int iobase2, int isairq,
 
 static ISADeviceInfo isa_ide_info = {
 .qdev.name  = isa-ide,
+.qdev.fw_name  = ide,
 .qdev.size  = sizeof(ISAIDEState),
 .init   = isa_ide_initfn,
 .qdev.reset = isa_ide_reset,
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 0808760..6d27b60 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -134,6 +134,7 @@ static int ide_drive_initfn(IDEDevice *dev)
 
 static IDEDeviceInfo ide_drive_info = {
 .qdev.name  = ide-drive,
+.qdev.fw_name  = drive,
 .qdev.size  = sizeof(IDEDrive),
 .init   = ide_drive_initfn,
 .qdev.props = (Property[]) {
diff --git a/hw/isa-bus.c b/hw/isa-bus.c
index 4e306de..26036e0 100644
--- a/hw/isa-bus.c
+++ b/hw/isa-bus.c
@@ -153,6 +153,7 @@ static int isabus_bridge_init(SysBusDevice *dev)
 static SysBusDeviceInfo isabus_bridge_info = {
 .init = isabus_bridge_init,
 .qdev.name  = isabus-bridge,
+.qdev.fw_name  = isa,
 .qdev.size  = sizeof(SysBusDevice),
 .qdev.no_user = 1,
 };
diff --git a/hw/lance.c b/hw/lance.c
index dc12144..1a3bb1a 100644
--- a/hw/lance.c
+++ b/hw/lance.c
@@ -141,6 +141,7 @@ static void lance_reset(DeviceState *dev)
 static SysBusDeviceInfo lance_info = {
 .init   = lance_init,
 .qdev.name  = lance,
+.qdev.fw_name  = ethernet,
 .qdev.size  = sizeof(SysBusPCNetState),
 .qdev.reset = lance_reset,
 .qdev.vmsd  = vmstate_lance,
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index b5589b9..38f9d9e 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -365,6 +365,7 @@ static PCIDeviceInfo i440fx_info[] = {
 static SysBusDeviceInfo i440fx_pcihost_info = {
 .init = i440fx_pcihost_initfn,
 .qdev.name= i440FX-pcihost,
+.qdev.fw_name = pci,
 .qdev.size= sizeof(I440FXState),
 .qdev.no_user = 1,
 };
diff --git a/hw/qdev.h b/hw/qdev.h
index 3fac364..bc71110 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -141,6 +141,7 @@ typedef void (*qdev_resetfn)(DeviceState *dev);
 
 struct DeviceInfo {
 const char *name;
+const char *fw_name;
 const char *alias;
 const char *desc;
 size_t size;
@@ -306,6 +307,11 @@ void qdev_prop_set_defaults(DeviceState *dev, Property 
*props);
 void qdev_prop_register_global_list(GlobalProperty *props);
 void qdev_prop_set_globals(DeviceState *dev);
 
+static inline const char *qdev_fw_name(DeviceState *dev)
+{
+return dev-info-fw_name ? : dev-info-alias ? : dev-info-name;
+}
+
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 extern struct BusInfo system_bus_info;
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 6e49404..851046f 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1230,6 +1230,7 @@ static int scsi_disk_initfn(SCSIDevice *dev)
 
 static SCSIDeviceInfo scsi_disk_info = {
 .qdev.name= scsi-disk,
+.qdev.fw_name = disk,
 .qdev.desc= virtual scsi disk or cdrom,
 .qdev.size= sizeof(SCSIDiskState),
 .qdev.reset   = scsi_disk_reset,
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 2a1edfc..8e3a96b 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -545,6 +545,7 @@ static int usb_hub_initfn(USBDevice *dev)
 static struct USBDeviceInfo hub_info = {
 .product_desc   = QEMU USB Hub,
 .qdev.name  = usb-hub,
+.qdev.fw_name= hub,
 .qdev.size  = sizeof(USBHubState),
 .init   = usb_hub_initfn,
 .handle_packet  = usb_hub_handle_packet,
diff --git a/hw/usb-net.c b/hw/usb-net.c
index 58c672f..f6bed21 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1496,6 +1496,7 @@ static USBDevice *usb_net_init(const char *cmdline)
 static struct USBDeviceInfo net_info = {
 .product_desc   = QEMU USB Network Interface,
 .qdev.name  = usb-net,
+.qdev.fw_name= network,
 .qdev.size  = sizeof(USBNetState),
 .init   = usb_net_initfn,
 .handle_packet  = 

[Qemu-devel] [PATCHv7 09/16] Record which USBDevice USBPort belongs too.

2010-12-06 Thread Gleb Natapov
Ports on root hub will have NULL here. This is needed to reconstruct
path from device to its root hub to build device path.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/usb-bus.c  |3 ++-
 hw/usb-hub.c  |2 +-
 hw/usb-musb.c |2 +-
 hw/usb-ohci.c |2 +-
 hw/usb-uhci.c |2 +-
 hw/usb.h  |3 ++-
 6 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index b692503..256b881 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -110,11 +110,12 @@ USBDevice *usb_create_simple(USBBus *bus, const char 
*name)
 }
 
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
-   usb_attachfn attach)
+   USBDevice *pdev, usb_attachfn attach)
 {
 port-opaque = opaque;
 port-index = index;
 port-attach = attach;
+port-pdev = pdev;
 QTAILQ_INSERT_TAIL(bus-free, port, next);
 bus-nfree++;
 }
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 8e3a96b..8a3f829 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -535,7 +535,7 @@ static int usb_hub_initfn(USBDevice *dev)
 for (i = 0; i  s-nb_ports; i++) {
 port = s-ports[i];
 usb_register_port(usb_bus_from_device(dev),
-  port-port, s, i, usb_hub_attach);
+  port-port, s, i, s-dev, usb_hub_attach);
 port-wPortStatus = PORT_STAT_POWER;
 port-wPortChange = 0;
 }
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 7f15842..9efe7a6 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -343,7 +343,7 @@ struct MUSBState {
 }
 
 usb_bus_new(s-bus, NULL /* FIXME */);
-usb_register_port(s-bus, s-port, s, 0, musb_attach);
+usb_register_port(s-bus, s-port, s, 0, NULL, musb_attach);
 
 return s;
 }
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 8fb2f83..1247295 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1705,7 +1705,7 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState 
*dev,
 usb_bus_new(ohci-bus, dev);
 ohci-num_ports = num_ports;
 for (i = 0; i  num_ports; i++) {
-usb_register_port(ohci-bus, ohci-rhport[i].port, ohci, i, 
ohci_attach);
+usb_register_port(ohci-bus, ohci-rhport[i].port, ohci, i, NULL, 
ohci_attach);
 }
 
 ohci-async_td = 0;
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 1d83400..b9b822f 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1115,7 +1115,7 @@ static int usb_uhci_common_initfn(UHCIState *s)
 
 usb_bus_new(s-bus, s-dev.qdev);
 for(i = 0; i  NB_PORTS; i++) {
-usb_register_port(s-bus, s-ports[i].port, s, i, uhci_attach);
+usb_register_port(s-bus, s-ports[i].port, s, i, NULL, uhci_attach);
 }
 s-frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s);
 s-expire_time = qemu_get_clock(vm_clock) +
diff --git a/hw/usb.h b/hw/usb.h
index 00d2802..0b32d77 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -203,6 +203,7 @@ struct USBPort {
 USBDevice *dev;
 usb_attachfn attach;
 void *opaque;
+USBDevice *pdev;
 int index; /* internal port index, may be used with the opaque */
 QTAILQ_ENTRY(USBPort) next;
 };
@@ -312,7 +313,7 @@ USBDevice *usb_create(USBBus *bus, const char *name);
 USBDevice *usb_create_simple(USBBus *bus, const char *name);
 USBDevice *usbdevice_create(const char *cmdline);
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
-   usb_attachfn attach);
+   USBDevice *pdev, usb_attachfn attach);
 void usb_unregister_port(USBBus *bus, USBPort *port);
 int usb_device_attach(USBDevice *dev);
 int usb_device_detach(USBDevice *dev);
-- 
1.7.2.3




[Qemu-devel] [PATCHv7 11/16] Add get_fw_dev_path callback to scsi bus.

2010-12-06 Thread Gleb Natapov

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/scsi-bus.c |   23 +++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 93f0e9a..7febb86 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -5,9 +5,12 @@
 #include qdev.h
 #include blockdev.h
 
+static char *scsibus_get_fw_dev_path(DeviceState *dev);
+
 static struct BusInfo scsi_bus_info = {
 .name  = SCSI,
 .size  = sizeof(SCSIBus),
+.get_fw_dev_path = scsibus_get_fw_dev_path,
 .props = (Property[]) {
 DEFINE_PROP_UINT32(scsi-id, SCSIDevice, id, -1),
 DEFINE_PROP_END_OF_LIST(),
@@ -518,3 +521,23 @@ void scsi_req_complete(SCSIRequest *req)
req-tag,
req-status);
 }
+
+static char *scsibus_get_fw_dev_path(DeviceState *dev)
+{
+SCSIDevice *d = (SCSIDevice*)dev;
+SCSIBus *bus = scsi_bus_from_device(d);
+char path[100];
+int i;
+
+for (i = 0; i  bus-ndev; i++) {
+if (bus-devs[i] == d) {
+break;
+}
+}
+
+assert(i != bus-ndev);
+
+snprintf(path, sizeof(path), %...@%x, qdev_fw_name(dev), i);
+
+return strdup(path);
+}
-- 
1.7.2.3




[Qemu-devel] [PATCHv7 02/16] Introduce new BusInfo callback get_fw_dev_path.

2010-12-06 Thread Gleb Natapov
New get_fw_dev_path callback will be used for build device path usable
by firmware in contrast to qdev qemu internal device path.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/qdev.h |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/hw/qdev.h b/hw/qdev.h
index bc71110..f72fbde 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -49,6 +49,12 @@ struct DeviceState {
 
 typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
 typedef char *(*bus_get_dev_path)(DeviceState *dev);
+/*
+ * This callback is used to create Open Firmware device path in accordance with
+ * OF spec http://forthworks.com/standards/of1275.pdf. Indicidual bus bindings
+ * can be found here http://playground.sun.com/1275/bindings/.
+ */
+typedef char *(*bus_get_fw_dev_path)(DeviceState *dev);
 typedef int (qbus_resetfn)(BusState *bus);
 
 struct BusInfo {
@@ -56,6 +62,7 @@ struct BusInfo {
 size_t size;
 bus_dev_printfn print_dev;
 bus_get_dev_path get_dev_path;
+bus_get_fw_dev_path get_fw_dev_path;
 qbus_resetfn *reset;
 Property *props;
 };
-- 
1.7.2.3




[Qemu-devel] [PATCH v2 2/2] make kvmclock value idempotent for stopped machine

2010-12-06 Thread Glauber Costa
Although we never made such commitment clear (well, to the best
of my knowledge), some people expect that two savevm issued in sequence
in a stopped machine will yield the same results. This is not a crazy
requirement, since we don't expect a stopped machine to be updating its state,
for any device.

With kvmclock, this is not the case, since the .pre_save hook will issue an
ioctl to the host to acquire a timestamp, which is always changing.

This patch moves the value acquisition to vm state change handlers, conditional
on not being run. This could mean mean our get clock ioctl is issued more times,
but this should be fine since vm_stop is not a hot path.

When we do migrate, we'll transfer that value along.

Signed-off-by: Glauber Costa glom...@redhat.com
CC: Paolo Bonzini pbonz...@redhat.com

---
 qemu-kvm-x86.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 14a52ce..0e357ac 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -500,11 +500,11 @@ static int kvm_enable_tpr_access_reporting(CPUState *env)
 #ifdef KVM_CAP_ADJUST_CLOCK
 static struct kvm_clock_data kvmclock_data;
 
-static void kvmclock_pre_save(void *opaque)
+static void kvmclock_update_clock(void *opaque, int running, int reason)
 {
 struct kvm_clock_data *cl = opaque;
 
-if (!kvmclock_enabled)
+if ((!kvmclock_enabled) || running)
 return;
 
 kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, cl);
@@ -522,7 +522,6 @@ static const VMStateDescription vmstate_kvmclock= {
 .version_id = 1,
 .minimum_version_id = 1,
 .minimum_version_id_old = 1,
-.pre_save = kvmclock_pre_save,
 .post_load = kvmclock_post_load,
 .fields  = (VMStateField []) {
 VMSTATE_U64(clock, struct kvm_clock_data),
@@ -537,6 +536,7 @@ void kvmclock_register_savevm(void)
 #ifdef KVM_CAP_ADJUST_CLOCK
 if (kvmclock_enabled  kvm_check_extension(kvm_state, 
KVM_CAP_ADJUST_CLOCK)) {
 vmstate_register(NULL, 0, vmstate_kvmclock, kvmclock_data);
+qemu_add_vm_change_state_handler(kvmclock_update_clock, 
kvmclock_data);
 }
 #endif
 }
-- 
1.7.2.3




[Qemu-devel] [PATCHv7 05/16] Store IDE bus id in IDEBus structure for easy access.

2010-12-06 Thread Gleb Natapov

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/ide/cmd646.c   |4 ++--
 hw/ide/internal.h |3 ++-
 hw/ide/isa.c  |2 +-
 hw/ide/piix.c |4 ++--
 hw/ide/qdev.c |3 ++-
 hw/ide/via.c  |4 ++--
 6 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index dfe6091..ea5d2dc 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -253,8 +253,8 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev)
 pci_conf[PCI_INTERRUPT_PIN] = 0x01; // interrupt on pin 1
 
 irq = qemu_allocate_irqs(cmd646_set_irq, d, 2);
-ide_bus_new(d-bus[0], d-dev.qdev);
-ide_bus_new(d-bus[1], d-dev.qdev);
+ide_bus_new(d-bus[0], d-dev.qdev, 0);
+ide_bus_new(d-bus[1], d-dev.qdev, 1);
 ide_init2(d-bus[0], irq[0]);
 ide_init2(d-bus[1], irq[1]);
 
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 85f4a16..71af66f 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -449,6 +449,7 @@ struct IDEBus {
 IDEDevice *slave;
 BMDMAState *bmdma;
 IDEState ifs[2];
+int bus_id;
 uint8_t unit;
 uint8_t cmd;
 qemu_irq irq;
@@ -567,7 +568,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo 
*hd0,
 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
 
 /* hw/ide/qdev.c */
-void ide_bus_new(IDEBus *idebus, DeviceState *dev);
+void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id);
 IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
 
 #endif /* HW_IDE_INTERNAL_H */
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 4206afd..8c59c5a 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -67,7 +67,7 @@ static int isa_ide_initfn(ISADevice *dev)
 {
 ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
 
-ide_bus_new(s-bus, s-dev.qdev);
+ide_bus_new(s-bus, s-dev.qdev, 0);
 ide_init_ioport(s-bus, s-iobase, s-iobase2);
 isa_init_irq(dev, s-irq, s-isairq);
 isa_init_ioport_range(dev, s-iobase, 8);
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index e02b89a..1c0cb0c 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -125,8 +125,8 @@ static int pci_piix_ide_initfn(PCIIDEState *d)
 
 vmstate_register(d-dev.qdev, 0, vmstate_ide_pci, d);
 
-ide_bus_new(d-bus[0], d-dev.qdev);
-ide_bus_new(d-bus[1], d-dev.qdev);
+ide_bus_new(d-bus[0], d-dev.qdev, 0);
+ide_bus_new(d-bus[1], d-dev.qdev, 1);
 ide_init_ioport(d-bus[0], 0x1f0, 0x3f6);
 ide_init_ioport(d-bus[1], 0x170, 0x376);
 
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 6d27b60..88ff657 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -29,9 +29,10 @@ static struct BusInfo ide_bus_info = {
 .size  = sizeof(IDEBus),
 };
 
-void ide_bus_new(IDEBus *idebus, DeviceState *dev)
+void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id)
 {
 qbus_create_inplace(idebus-qbus, ide_bus_info, dev, NULL);
+idebus-bus_id = bus_id;
 }
 
 static int ide_qdev_init(DeviceState *qdev, DeviceInfo *base)
diff --git a/hw/ide/via.c b/hw/ide/via.c
index 66be0c4..78857e8 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -154,8 +154,8 @@ static int vt82c686b_ide_initfn(PCIDevice *dev)
 
 vmstate_register(dev-qdev, 0, vmstate_ide_pci, d);
 
-ide_bus_new(d-bus[0], d-dev.qdev);
-ide_bus_new(d-bus[1], d-dev.qdev);
+ide_bus_new(d-bus[0], d-dev.qdev, 0);
+ide_bus_new(d-bus[1], d-dev.qdev, 1);
 ide_init2(d-bus[0], isa_reserve_irq(14));
 ide_init2(d-bus[1], isa_reserve_irq(15));
 ide_init_ioport(d-bus[0], 0x1f0, 0x3f6);
-- 
1.7.2.3




[Qemu-devel] [PATCHv7 08/16] Add get_fw_dev_path callback for pci bus.

2010-12-06 Thread Gleb Natapov

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/pci.c |  108 -
 1 files changed, 85 insertions(+), 23 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 0c15b13..e7ea907 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -43,6 +43,7 @@
 
 static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 static char *pcibus_get_dev_path(DeviceState *dev);
+static char *pcibus_get_fw_dev_path(DeviceState *dev);
 static int pcibus_reset(BusState *qbus);
 
 struct BusInfo pci_bus_info = {
@@ -50,6 +51,7 @@ struct BusInfo pci_bus_info = {
 .size   = sizeof(PCIBus),
 .print_dev  = pcibus_dev_print,
 .get_dev_path = pcibus_get_dev_path,
+.get_fw_dev_path = pcibus_get_fw_dev_path,
 .reset  = pcibus_reset,
 .props  = (Property[]) {
 DEFINE_PROP_PCI_DEVFN(addr, PCIDevice, devfn, -1),
@@ -1117,45 +1119,63 @@ void pci_msi_notify(PCIDevice *dev, unsigned int vector)
 typedef struct {
 uint16_t class;
 const char *desc;
+const char *fw_name;
+uint16_t fw_ign_bits;
 } pci_class_desc;
 
 static const pci_class_desc pci_class_descriptions[] =
 {
-{ 0x0100, SCSI controller},
-{ 0x0101, IDE controller},
-{ 0x0102, Floppy controller},
-{ 0x0103, IPI controller},
-{ 0x0104, RAID controller},
+{ 0x0001, VGA controller, display},
+{ 0x0100, SCSI controller, scsi},
+{ 0x0101, IDE controller, ide},
+{ 0x0102, Floppy controller, fdc},
+{ 0x0103, IPI controller, ipi},
+{ 0x0104, RAID controller, raid},
 { 0x0106, SATA controller},
 { 0x0107, SAS controller},
 { 0x0180, Storage controller},
-{ 0x0200, Ethernet controller},
-{ 0x0201, Token Ring controller},
-{ 0x0202, FDDI controller},
-{ 0x0203, ATM controller},
+{ 0x0200, Ethernet controller, ethernet},
+{ 0x0201, Token Ring controller, token-ring},
+{ 0x0202, FDDI controller, fddi},
+{ 0x0203, ATM controller, atm},
 { 0x0280, Network controller},
-{ 0x0300, VGA controller},
+{ 0x0300, VGA controller, display, 0x00ff},
 { 0x0301, XGA controller},
 { 0x0302, 3D controller},
 { 0x0380, Display controller},
-{ 0x0400, Video controller},
-{ 0x0401, Audio controller},
+{ 0x0400, Video controller, video},
+{ 0x0401, Audio controller, sound},
 { 0x0402, Phone},
 { 0x0480, Multimedia controller},
-{ 0x0500, RAM controller},
-{ 0x0501, Flash controller},
+{ 0x0500, RAM controller, memory},
+{ 0x0501, Flash controller, flash},
 { 0x0580, Memory controller},
-{ 0x0600, Host bridge},
-{ 0x0601, ISA bridge},
-{ 0x0602, EISA bridge},
-{ 0x0603, MC bridge},
-{ 0x0604, PCI bridge},
-{ 0x0605, PCMCIA bridge},
-{ 0x0606, NUBUS bridge},
-{ 0x0607, CARDBUS bridge},
+{ 0x0600, Host bridge, host},
+{ 0x0601, ISA bridge, isa},
+{ 0x0602, EISA bridge, eisa},
+{ 0x0603, MC bridge, mca},
+{ 0x0604, PCI bridge, pci},
+{ 0x0605, PCMCIA bridge, pcmcia},
+{ 0x0606, NUBUS bridge, nubus},
+{ 0x0607, CARDBUS bridge, cardbus},
 { 0x0608, RACEWAY bridge},
 { 0x0680, Bridge},
-{ 0x0c03, USB controller},
+{ 0x0700, Serial port, serial},
+{ 0x0701, Parallel port, parallel},
+{ 0x0800, Interrupt controller, interrupt-controller},
+{ 0x0801, DMA controller, dma-controller},
+{ 0x0802, Timer, timer},
+{ 0x0803, RTC, rtc},
+{ 0x0900, Keyboard, keyboard},
+{ 0x0901, Pen, pen},
+{ 0x0902, Mouse, mouse},
+{ 0x0A00, Dock station, dock, 0x00ff},
+{ 0x0B00, i386 cpu, cpu, 0x00ff},
+{ 0x0c00, Fireware contorller, fireware},
+{ 0x0c01, Access bus controller, access-bus},
+{ 0x0c02, SSA controller, ssa},
+{ 0x0c03, USB controller, usb},
+{ 0x0c04, Fibre channel controller, fibre-channel},
 { 0, NULL}
 };
 
@@ -1960,6 +1980,48 @@ static void pcibus_dev_print(Monitor *mon, DeviceState 
*dev, int indent)
 }
 }
 
+static char *pci_dev_fw_name(DeviceState *dev, char *buf, int len)
+{
+PCIDevice *d = (PCIDevice *)dev;
+const char *name = NULL;
+const pci_class_desc *desc =  pci_class_descriptions;
+int class = pci_get_word(d-config + PCI_CLASS_DEVICE);
+
+while (desc-desc 
+  (class  ~desc-fw_ign_bits) !=
+  (desc-class  ~desc-fw_ign_bits)) {
+desc++;
+}
+
+if (desc-desc) {
+name = desc-fw_name;
+}
+
+if (name) {
+pstrcpy(buf, len, name);
+} else {
+snprintf(buf, len, pci%04x,%04x,
+ pci_get_word(d-config + PCI_VENDOR_ID),
+ pci_get_word(d-config + PCI_DEVICE_ID));
+}
+
+return buf;
+}
+
+static char *pcibus_get_fw_dev_path(DeviceState *dev)
+{
+PCIDevice *d = (PCIDevice *)dev;
+char path[50], name[33];
+int off;
+
+off = snprintf(path, sizeof(path), %...@%x,
+   pci_dev_fw_name(dev, name, sizeof name),
+   PCI_SLOT(d-devfn));
+if 

[Qemu-devel] [PATCHv7 16/16] Pass boot device list to firmware.

2010-12-06 Thread Gleb Natapov

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/fw_cfg.c |   14 ++
 sysemu.h|1 +
 vl.c|   48 
 3 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 7b9434f..20a816f 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -53,6 +53,7 @@ struct FWCfgState {
 FWCfgFiles *files;
 uint16_t cur_entry;
 uint32_t cur_offset;
+Notifier machine_ready;
 };
 
 static void fw_cfg_write(FWCfgState *s, uint8_t value)
@@ -315,6 +316,15 @@ int fw_cfg_add_file(FWCfgState *s,  const char *filename, 
uint8_t *data,
 return 1;
 }
 
+static void fw_cfg_machine_ready(struct Notifier* n)
+{
+uint32_t len;
+FWCfgState *s = container_of(n, FWCfgState, machine_ready);
+char *bootindex = get_boot_devices_list(len);
+
+fw_cfg_add_file(s, bootorder, (uint8_t*)bootindex, len);
+}
+
 FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port,
 target_phys_addr_t ctl_addr, target_phys_addr_t 
data_addr)
 {
@@ -343,6 +353,10 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t 
data_port,
 fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
 fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu);
 
+
+s-machine_ready.notify = fw_cfg_machine_ready;
+qemu_add_machine_init_done_notifier(s-machine_ready);
+
 return s;
 }
 
diff --git a/sysemu.h b/sysemu.h
index c42f33a..38a20a3 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -196,4 +196,5 @@ void register_devices(void);
 
 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
   const char *suffix);
+char *get_boot_devices_list(uint32_t *size);
 #endif
diff --git a/vl.c b/vl.c
index 0d20d26..c4d3fc0 100644
--- a/vl.c
+++ b/vl.c
@@ -736,6 +736,54 @@ void add_boot_device_path(int32_t bootindex, DeviceState 
*dev,
 QTAILQ_INSERT_TAIL(fw_boot_order, node, link);
 }
 
+/*
+ * This function returns null terminated string that consist of new line
+ * separated device pathes.
+ *
+ * memory pointed by size is assigned total length of the array in bytes
+ *
+ */
+char *get_boot_devices_list(uint32_t *size)
+{
+FWBootEntry *i;
+uint32_t total = 0;
+char *list = NULL;
+
+QTAILQ_FOREACH(i, fw_boot_order, link) {
+char *devpath = NULL, *bootpath;
+int len;
+
+if (i-dev) {
+devpath = qdev_get_fw_dev_path(i-dev);
+assert(devpath);
+}
+
+if (i-suffix  devpath) {
+bootpath = qemu_malloc(strlen(devpath) + strlen(i-suffix) + 1);
+sprintf(bootpath, %s%s, devpath, i-suffix);
+qemu_free(devpath);
+} else if (devpath) {
+bootpath = devpath;
+} else {
+bootpath = strdup(i-suffix);
+assert(bootpath);
+}
+
+if (total) {
+list[total-1] = '\n';
+}
+len = strlen(bootpath) + 1;
+list = qemu_realloc(list, total + len);
+memcpy(list[total], bootpath, len);
+total += len;
+qemu_free(bootpath);
+}
+
+*size = total;
+
+return list;
+}
+
 static void numa_add(const char *optarg)
 {
 char option[128];
-- 
1.7.2.3




[Qemu-devel] [PATCHv7 12/16] Add bootindex parameter to net/block/fd device

2010-12-06 Thread Gleb Natapov
If bootindex is specified on command line a string that describes device
in firmware readable way is added into sorted list. Later this list will
be passed into firmware to control boot order.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 block_int.h |4 +++-
 hw/e1000.c  |4 
 hw/eepro100.c   |3 +++
 hw/fdc.c|8 
 hw/ide/qdev.c   |5 +
 hw/ne2000.c |3 +++
 hw/pcnet.c  |4 
 hw/qdev.c   |   32 
 hw/qdev.h   |1 +
 hw/rtl8139.c|4 
 hw/scsi-disk.c  |1 +
 hw/usb-net.c|2 ++
 hw/virtio-blk.c |2 ++
 hw/virtio-net.c |2 ++
 net.h   |4 +++-
 sysemu.h|2 ++
 vl.c|   40 
 17 files changed, 119 insertions(+), 2 deletions(-)

diff --git a/block_int.h b/block_int.h
index 3c3adb5..0a0e47d 100644
--- a/block_int.h
+++ b/block_int.h
@@ -227,6 +227,7 @@ typedef struct BlockConf {
 uint16_t logical_block_size;
 uint16_t min_io_size;
 uint32_t opt_io_size;
+int32_t bootindex;
 } BlockConf;
 
 static inline unsigned int get_physical_block_exp(BlockConf *conf)
@@ -249,6 +250,7 @@ static inline unsigned int get_physical_block_exp(BlockConf 
*conf)
 DEFINE_PROP_UINT16(physical_block_size, _state,   \
_conf.physical_block_size, 512), \
 DEFINE_PROP_UINT16(min_io_size, _state, _conf.min_io_size, 0),  \
-DEFINE_PROP_UINT32(opt_io_size, _state, _conf.opt_io_size, 0)
+DEFINE_PROP_UINT32(opt_io_size, _state, _conf.opt_io_size, 0),\
+DEFINE_PROP_INT32(bootindex, _state, _conf.bootindex, -1) \
 
 #endif /* BLOCK_INT_H */
diff --git a/hw/e1000.c b/hw/e1000.c
index 57d08cf..e411b03 100644
--- a/hw/e1000.c
+++ b/hw/e1000.c
@@ -30,6 +30,7 @@
 #include net.h
 #include net/checksum.h
 #include loader.h
+#include sysemu.h
 
 #include e1000_hw.h
 
@@ -1154,6 +1155,9 @@ static int pci_e1000_init(PCIDevice *pci_dev)
   d-dev.qdev.info-name, d-dev.qdev.id, d);
 
 qemu_format_nic_info_str(d-nic-nc, macaddr);
+
+add_boot_device_path(d-conf.bootindex, pci_dev-qdev, /ethernet-...@0);
+
 return 0;
 }
 
diff --git a/hw/eepro100.c b/hw/eepro100.c
index f8a700a..a464e9b 100644
--- a/hw/eepro100.c
+++ b/hw/eepro100.c
@@ -46,6 +46,7 @@
 #include pci.h
 #include net.h
 #include eeprom93xx.h
+#include sysemu.h
 
 #define KiB 1024
 
@@ -1907,6 +1908,8 @@ static int e100_nic_init(PCIDevice *pci_dev)
 s-vmstate-name = s-nic-nc.model;
 vmstate_register(pci_dev-qdev, -1, s-vmstate, s);
 
+add_boot_device_path(s-conf.bootindex, pci_dev-qdev, /ethernet-...@0);
+
 return 0;
 }
 
diff --git a/hw/fdc.c b/hw/fdc.c
index 5ab754b..543aa68 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -35,6 +35,7 @@
 #include sysbus.h
 #include qdev-addr.h
 #include blockdev.h
+#include sysemu.h
 
 //
 /* debug Floppy devices */
@@ -523,6 +524,8 @@ typedef struct FDCtrlSysBus {
 typedef struct FDCtrlISABus {
 ISADevice busdev;
 struct FDCtrl state;
+int32_t bootindexA;
+int32_t bootindexB;
 } FDCtrlISABus;
 
 static uint32_t fdctrl_read (void *opaque, uint32_t reg)
@@ -1992,6 +1995,9 @@ static int isabus_fdc_init1(ISADevice *dev)
 qdev_set_legacy_instance_id(dev-qdev, iobase, 2);
 ret = fdctrl_init_common(fdctrl);
 
+add_boot_device_path(isa-bootindexA, dev-qdev, /flo...@0);
+add_boot_device_path(isa-bootindexB, dev-qdev, /flo...@1);
+
 return ret;
 }
 
@@ -2051,6 +2057,8 @@ static ISADeviceInfo isa_fdc_info = {
 .qdev.props = (Property[]) {
 DEFINE_PROP_DRIVE(driveA, FDCtrlISABus, state.drives[0].bs),
 DEFINE_PROP_DRIVE(driveB, FDCtrlISABus, state.drives[1].bs),
+DEFINE_PROP_INT32(bootindexA, FDCtrlISABus, bootindexA, -1),
+DEFINE_PROP_INT32(bootindexB, FDCtrlISABus, bootindexB, -1),
 DEFINE_PROP_END_OF_LIST(),
 },
 };
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 01a181b..69a00e2 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -21,6 +21,7 @@
 #include qemu-error.h
 #include hw/ide/internal.h
 #include blockdev.h
+#include sysemu.h
 
 /* - */
 
@@ -143,6 +144,10 @@ static int ide_drive_initfn(IDEDevice *dev)
 if (!dev-serial) {
 dev-serial = qemu_strdup(s-drive_serial_str);
 }
+
+add_boot_device_path(dev-conf.bootindex, dev-qdev,
+ dev-unit ? d...@1 : d...@0);
+
 return 0;
 }
 
diff --git a/hw/ne2000.c b/hw/ne2000.c
index 126e7cf..a030106 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -26,6 +26,7 @@
 #include net.h
 #include ne2000.h
 #include loader.h
+#include sysemu.h
 
 /* debug NE2000 card */
 //#define DEBUG_NE2000
@@ -746,6 +747,8 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
 }
 }
 
+add_boot_device_path(s-c.bootindex, pci_dev-qdev, /ethernet-...@0);
+
 return 0;
 }
 
diff 

[Qemu-devel] [PATCH v2 0/2] savevm odness related to kvmclock

2010-12-06 Thread Glauber Costa
Some users told me that savevm path is behaving oddly wrt kvmclock.
The first oddness is that a guarantee we never made (AFAIK) is being broken:
two consecutive savevm operations, with the machine stopped in between
produces different results, due to the call to KVM_GET_CLOCK ioctl.
I believe the assumption that if the vm does not run, its saveable
state won't change is fairly reasonable. Maybe we should formally
guarantee that?

Also, this patch deals with the fact that this happens even if
kvmclock is disabled in cpuid: its savevm section is registered
nevertheless. Here, I try to register it only if it's enabled at
machine start.

v2: improvements suggested by Paolo, and patch reordering.

Glauber Costa (2):
  Do not register kvmclock savevm section if kvmclock is disabled.
  make kvmclock value idempotent for stopped machine

 cpus.c|3 +++
 qemu-kvm-x86.c|   23 +++
 qemu-kvm.h|3 +++
 target-i386/kvm.c |7 +++
 4 files changed, 28 insertions(+), 8 deletions(-)

-- 
1.7.2.3




[Qemu-devel] [PATCHv7 14/16] Add bootindex for option roms.

2010-12-06 Thread Gleb Natapov
Extend -option-rom command to have additional parameter ,bootindex=.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/loader.c|   16 +++-
 hw/loader.h|8 
 hw/multiboot.c |3 ++-
 hw/ne2000.c|2 +-
 hw/nseries.c   |4 ++--
 hw/palm.c  |6 +++---
 hw/pc.c|7 ---
 hw/pci.c   |2 +-
 hw/pcnet-pci.c |2 +-
 qemu-config.c  |   17 +
 sysemu.h   |6 +-
 vl.c   |   11 +--
 12 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/hw/loader.c b/hw/loader.c
index 1e98326..eb198f6 100644
--- a/hw/loader.c
+++ b/hw/loader.c
@@ -107,7 +107,7 @@ int load_image_targphys(const char *filename,
 
 size = get_image_size(filename);
 if (size  0)
-rom_add_file_fixed(filename, addr);
+rom_add_file_fixed(filename, addr, -1);
 return size;
 }
 
@@ -557,10 +557,11 @@ static void rom_insert(Rom *rom)
 }
 
 int rom_add_file(const char *file, const char *fw_dir,
- target_phys_addr_t addr)
+ target_phys_addr_t addr, int32_t bootindex)
 {
 Rom *rom;
 int rc, fd = -1;
+char devpath[100];
 
 rom = qemu_mallocz(sizeof(*rom));
 rom-name = qemu_strdup(file);
@@ -605,7 +606,12 @@ int rom_add_file(const char *file, const char *fw_dir,
 snprintf(fw_file_name, sizeof(fw_file_name), %s/%s, rom-fw_dir,
  basename);
 fw_cfg_add_file(fw_cfg, fw_file_name, rom-data, rom-romsize);
+snprintf(devpath, sizeof(devpath), /r...@%s, fw_file_name);
+} else {
+snprintf(devpath, sizeof(devpath), /rom@ TARGET_FMT_plx, addr);
 }
+
+add_boot_device_path(bootindex, NULL, devpath);
 return 0;
 
 err:
@@ -635,12 +641,12 @@ int rom_add_blob(const char *name, const void *blob, 
size_t len,
 
 int rom_add_vga(const char *file)
 {
-return rom_add_file(file, vgaroms, 0);
+return rom_add_file(file, vgaroms, 0, -1);
 }
 
-int rom_add_option(const char *file)
+int rom_add_option(const char *file, int32_t bootindex)
 {
-return rom_add_file(file, genroms, 0);
+return rom_add_file(file, genroms, 0, bootindex);
 }
 
 static void rom_reset(void *unused)
diff --git a/hw/loader.h b/hw/loader.h
index 1f82fc5..fc6bdff 100644
--- a/hw/loader.h
+++ b/hw/loader.h
@@ -22,7 +22,7 @@ void pstrcpy_targphys(const char *name,
 
 
 int rom_add_file(const char *file, const char *fw_dir,
- target_phys_addr_t addr);
+ target_phys_addr_t addr, int32_t bootindex);
 int rom_add_blob(const char *name, const void *blob, size_t len,
  target_phys_addr_t addr);
 int rom_load_all(void);
@@ -31,8 +31,8 @@ int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t 
size);
 void *rom_ptr(target_phys_addr_t addr);
 void do_info_roms(Monitor *mon);
 
-#define rom_add_file_fixed(_f, _a)  \
-rom_add_file(_f, NULL, _a)
+#define rom_add_file_fixed(_f, _a, _i)  \
+rom_add_file(_f, NULL, _a, _i)
 #define rom_add_blob_fixed(_f, _b, _l, _a)  \
 rom_add_blob(_f, _b, _l, _a)
 
@@ -43,6 +43,6 @@ void do_info_roms(Monitor *mon);
 #define PC_ROM_SIZE(PC_ROM_MAX - PC_ROM_MIN_VGA)
 
 int rom_add_vga(const char *file);
-int rom_add_option(const char *file);
+int rom_add_option(const char *file, int32_t bootindex);
 
 #endif
diff --git a/hw/multiboot.c b/hw/multiboot.c
index e710bbb..7cc3055 100644
--- a/hw/multiboot.c
+++ b/hw/multiboot.c
@@ -331,7 +331,8 @@ int load_multiboot(void *fw_cfg,
 fw_cfg_add_bytes(fw_cfg, FW_CFG_INITRD_DATA, mb_bootinfo_data,
  sizeof(bootinfo));
 
-option_rom[nb_option_roms] = multiboot.bin;
+option_rom[nb_option_roms].name = multiboot.bin;
+option_rom[nb_option_roms].bootindex = 0;
 nb_option_roms++;
 
 return 1; /* yes, we are multiboot */
diff --git a/hw/ne2000.c b/hw/ne2000.c
index a030106..5966359 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -742,7 +742,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
 if (!pci_dev-qdev.hotplugged) {
 static int loaded = 0;
 if (!loaded) {
-rom_add_option(pxe-ne2k_pci.bin);
+rom_add_option(pxe-ne2k_pci.bin, -1);
 loaded = 1;
 }
 }
diff --git a/hw/nseries.c b/hw/nseries.c
index 04a028d..2f6f473 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -1326,7 +1326,7 @@ static void n8x0_init(ram_addr_t ram_size, const char 
*boot_device,
 qemu_register_reset(n8x0_boot_init, s);
 }
 
-if (option_rom[0]  (boot_device[0] == 'n' || !kernel_filename)) {
+if (option_rom[0].name  (boot_device[0] == 'n' || !kernel_filename)) {
 int rom_size;
 uint8_t nolo_tags[0x1];
 /* No, wait, better start at the ROM.  */
@@ -1341,7 +1341,7 @@ static void n8x0_init(ram_addr_t ram_size, const char 
*boot_device,
  *
  * The code above is for loading the `zImage' file from Nokia
  * images.  */
-rom_size = 

[Qemu-devel] Re: [PATCH v2 0/2] savevm odness related to kvmclock

2010-12-06 Thread Paolo Bonzini

On 12/06/2010 03:03 PM, Glauber Costa wrote:

Some users told me that savevm path is behaving oddly wrt kvmclock.
The first oddness is that a guarantee we never made (AFAIK) is being broken:
two consecutive savevm operations, with the machine stopped in between
produces different results, due to the call to KVM_GET_CLOCK ioctl.
I believe the assumption that if the vm does not run, its saveable
state won't change is fairly reasonable. Maybe we should formally
guarantee that?

Also, this patch deals with the fact that this happens even if
kvmclock is disabled in cpuid: its savevm section is registered
nevertheless. Here, I try to register it only if it's enabled at
machine start.

v2: improvements suggested by Paolo, and patch reordering.

Glauber Costa (2):
   Do not register kvmclock savevm section if kvmclock is disabled.
   make kvmclock value idempotent for stopped machine

  cpus.c|3 +++
  qemu-kvm-x86.c|   23 +++
  qemu-kvm.h|3 +++
  target-i386/kvm.c |7 +++
  4 files changed, 28 insertions(+), 8 deletions(-)


ACK

Paolo



[Qemu-devel] [PATCHv7 07/16] Add get_fw_dev_path callback for system bus.

2010-12-06 Thread Gleb Natapov
Prints out mmio or pio used to access child device.

Signed-off-by: Gleb Natapov g...@redhat.com
---
 hw/pci_host.c |2 ++
 hw/sysbus.c   |   30 ++
 hw/sysbus.h   |4 
 3 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/hw/pci_host.c b/hw/pci_host.c
index bc5b771..28d45bf 100644
--- a/hw/pci_host.c
+++ b/hw/pci_host.c
@@ -197,6 +197,7 @@ void pci_host_conf_register_ioport(pio_addr_t ioport, 
PCIHostState *s)
 {
 pci_host_init(s);
 register_ioport_simple(s-conf_noswap_handler, ioport, 4, 4);
+sysbus_init_ioports(s-busdev, ioport, 4);
 }
 
 int pci_host_data_register_mmio(PCIHostState *s, int swap)
@@ -215,4 +216,5 @@ void pci_host_data_register_ioport(pio_addr_t ioport, 
PCIHostState *s)
 register_ioport_simple(s-data_noswap_handler, ioport, 4, 1);
 register_ioport_simple(s-data_noswap_handler, ioport, 4, 2);
 register_ioport_simple(s-data_noswap_handler, ioport, 4, 4);
+sysbus_init_ioports(s-busdev, ioport, 4);
 }
diff --git a/hw/sysbus.c b/hw/sysbus.c
index d817721..1583bd8 100644
--- a/hw/sysbus.c
+++ b/hw/sysbus.c
@@ -22,11 +22,13 @@
 #include monitor.h
 
 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
+static char *sysbus_get_fw_dev_path(DeviceState *dev);
 
 struct BusInfo system_bus_info = {
 .name   = System,
 .size   = sizeof(BusState),
 .print_dev  = sysbus_dev_print,
+.get_fw_dev_path = sysbus_get_fw_dev_path,
 };
 
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq)
@@ -106,6 +108,16 @@ void sysbus_init_mmio_cb(SysBusDevice *dev, 
target_phys_addr_t size,
 dev-mmio[n].cb = cb;
 }
 
+void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size)
+{
+pio_addr_t i;
+
+for (i = 0; i  size; i++) {
+assert(dev-num_pio  QDEV_MAX_PIO);
+dev-pio[dev-num_pio++] = ioport++;
+}
+}
+
 static int sysbus_device_init(DeviceState *dev, DeviceInfo *base)
 {
 SysBusDeviceInfo *info = container_of(base, SysBusDeviceInfo, qdev);
@@ -171,3 +183,21 @@ static void sysbus_dev_print(Monitor *mon, DeviceState 
*dev, int indent)
indent, , s-mmio[i].addr, s-mmio[i].size);
 }
 }
+
+static char *sysbus_get_fw_dev_path(DeviceState *dev)
+{
+SysBusDevice *s = sysbus_from_qdev(dev);
+char path[40];
+int off;
+
+off = snprintf(path, sizeof(path), %s, qdev_fw_name(dev));
+
+if (s-num_mmio) {
+snprintf(path + off, sizeof(path) - off, @TARGET_FMT_plx,
+ s-mmio[0].addr);
+} else if (s-num_pio) {
+snprintf(path + off, sizeof(path) - off, @i%04x, s-pio[0]);
+}
+
+return strdup(path);
+}
diff --git a/hw/sysbus.h b/hw/sysbus.h
index 5980901..e9eb618 100644
--- a/hw/sysbus.h
+++ b/hw/sysbus.h
@@ -6,6 +6,7 @@
 #include qdev.h
 
 #define QDEV_MAX_MMIO 32
+#define QDEV_MAX_PIO 32
 #define QDEV_MAX_IRQ 256
 
 typedef struct SysBusDevice SysBusDevice;
@@ -23,6 +24,8 @@ struct SysBusDevice {
 mmio_mapfunc cb;
 ram_addr_t iofunc;
 } mmio[QDEV_MAX_MMIO];
+int num_pio;
+pio_addr_t pio[QDEV_MAX_PIO];
 };
 
 typedef int (*sysbus_initfn)(SysBusDevice *dev);
@@ -45,6 +48,7 @@ void sysbus_init_mmio_cb(SysBusDevice *dev, 
target_phys_addr_t size,
 mmio_mapfunc cb);
 void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
 void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
+void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t 
size);
 
 
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
-- 
1.7.2.3




[Qemu-devel] [PATCH v2 1/2] Do not register kvmclock savevm section if kvmclock is disabled.

2010-12-06 Thread Glauber Costa
Usually nobody usually thinks about that scenario (me included and specially),
but kvmclock can be actually disabled in the host.

It happens in two scenarios:
 1. host too old.
 2. we passed -kvmclock to our -cpu parameter.

In both cases, we should not register kvmclock savevm section. This patch
achives that by registering this section only if kvmclock is actually
currently enabled in cpuid.

The only caveat is that we have to register the savevm section a little bit
later, since we won't know the final kvmclock state before cpuid gets parsed.

Signed-off-by: Glauber Costa glom...@redhat.com
---
 cpus.c|3 +++
 qemu-kvm-x86.c|   19 +--
 qemu-kvm.h|3 +++
 target-i386/kvm.c |7 +++
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/cpus.c b/cpus.c
index a55c330..a24098e 100644
--- a/cpus.c
+++ b/cpus.c
@@ -97,6 +97,9 @@ void cpu_synchronize_all_post_init(void)
 for (cpu = first_cpu; cpu; cpu = cpu-next_cpu) {
 cpu_synchronize_post_init(cpu);
 }
+if (kvm_enabled()) {
+kvmclock_register_savevm();
+}
 }
 
 int cpu_is_stopped(CPUState *env)
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 20b7d6d..14a52ce 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -504,6 +504,9 @@ static void kvmclock_pre_save(void *opaque)
 {
 struct kvm_clock_data *cl = opaque;
 
+if (!kvmclock_enabled)
+return;
+
 kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, cl);
 }
 
@@ -528,6 +531,16 @@ static const VMStateDescription vmstate_kvmclock= {
 };
 #endif
 
+/* This has to happen after vcpu setup*/
+void kvmclock_register_savevm(void)
+{
+#ifdef KVM_CAP_ADJUST_CLOCK
+if (kvmclock_enabled  kvm_check_extension(kvm_state, 
KVM_CAP_ADJUST_CLOCK)) {
+vmstate_register(NULL, 0, vmstate_kvmclock, kvmclock_data);
+}
+#endif
+}
+
 int kvm_arch_qemu_create_context(void)
 {
 int r;
@@ -545,12 +558,6 @@ int kvm_arch_qemu_create_context(void)
 return -1;
 }
 
-#ifdef KVM_CAP_ADJUST_CLOCK
-if (kvm_check_extension(kvm_state, KVM_CAP_ADJUST_CLOCK)) {
-vmstate_register(NULL, 0, vmstate_kvmclock, kvmclock_data);
-}
-#endif
-
 r = kvm_set_boot_cpu_id(0);
 if (r  0  r != -ENOSYS) {
 return r;
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 0f3fb50..0a104ef 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -752,6 +752,9 @@ int handle_tpr_access(void *opaque, CPUState *env, uint64_t 
rip,
 #define qemu_kvm_cpu_stop(env) do {} while(0)
 #endif
 
+extern int kvmclock_enabled;
+void kvmclock_register_savevm(void);
+
 #ifdef CONFIG_KVM
 
 typedef struct KVMSlot {
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 95e5d02..5443765 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -293,6 +293,7 @@ void kvm_inject_x86_mce(CPUState *cenv, int bank, uint64_t 
status,
 }
 
 static int _kvm_arch_init_vcpu(CPUState *env);
+int kvmclock_enabled = 1;
 
 int kvm_arch_init_vcpu(CPUState *env)
 {
@@ -350,6 +351,12 @@ int kvm_arch_init_vcpu(CPUState *env)
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_FEATURES;
 c-eax = env-cpuid_kvm_features  get_para_features(env);
+
+if (!(c-eax  (1  KVM_FEATURE_CLOCKSOURCE))) {
+/* In theory cpuid is per-cpu, and this is a global variable,
+ * but we don't expect kvmclock enabled in some cpus only */
+kvmclock_enabled = 0;
+}
 #endif
 
 cpu_x86_cpuid(env, 0, 0, limit, unused, unused, unused);
-- 
1.7.2.3




Re: [Qemu-devel] [PULL 00/16] Block patches

2010-12-06 Thread Anthony Liguori

On 12/06/2010 07:41 AM, Kevin Wolf wrote:



I see:

commit 393f398b69f9baadc3f29d822a0b5b74ca63b919
Author: Richard Hendersonr...@twiddle.net
Date:   Mon Nov 22 14:57:58 2010 -0800

  tcg-ia64: Fix warning in qemu_ld.

  The usermode version of qemu_ld doesn't used mem_index,
  leading to set-but-not-used warnings.

  Signed-off-by: Richard Hendersonr...@twiddle.net
  Signed-off-by: Edgar E. Iglesiased...@axis.com

As the head on that branch which doesn't seem right.
 

You have pulled this already last week, so after a rebase on my side it
just points to some random commit in master. :-)
   


Yeah, I still have origin pointing to Savannah and it confused me.  
Sorry for the noise.


Regards,

Anthony Liguori


Kevin
   





[Qemu-devel] [PATCH v3 0/7] Cleanup qemu-img code

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

Hi,

These patches applies a number of cleanups to qemu-img.c as well as a
minor bug in qemu-malloc.c. 

The handling of block help printing is moved to shared code, which
allows the ? detection to happen early in the parsing, instead of
half way down img_create() and img_convert(). I would like to see this
happen as I would like to pull some of the code out of img_create()
and into block.c so it can be shared with qemu and qemu-img.

In addition there is a couple of patches to clean up the error
handling in qemu-img.c and make it more consistent.

The formatting patch is solely because the last patch wanted to
change code next to the badly formatted code, and I didn't want to
pollute the patch with the formatting fixed.

The seventh patch fixes qemu-img to exit on detection of unknown
options instead of continuing with a potentially wrong set of
arguments.

v3 applies a number of changes discussed on irc and email. This is the
grow to seven from three patches series.

Cheers,
Jes

Jes Sorensen (7):
  Add missing tracing to qemu_mallocz()
  Use qemu_mallocz() instead of calloc() in img_convert()
  img_convert(): Only try to free bs[] entries if bs is valid.
  Make error handling more consistent in img_create() and img_resize()
  Consolidate printing of block driver options
  Fix formatting and missing braces in qemu-img.c
  Fail if detecting an unknown option

 qemu-img.c|  162 +++-
 qemu-malloc.c |5 ++-
 2 files changed, 117 insertions(+), 50 deletions(-)

-- 
1.7.3.2




[Qemu-devel] [PATCH 1/7] Add missing tracing to qemu_mallocz()

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

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

diff --git a/qemu-malloc.c b/qemu-malloc.c
index 28fb05a..b9b3851 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -64,10 +64,13 @@ void *qemu_realloc(void *ptr, size_t size)
 
 void *qemu_mallocz(size_t size)
 {
+void *ptr;
 if (!size  !allow_zero_malloc()) {
 abort();
 }
-return qemu_oom_check(calloc(1, size ? size : 1));
+ptr = qemu_oom_check(calloc(1, size ? size : 1));
+trace_qemu_malloc(size, ptr);
+return ptr;
 }
 
 char *qemu_strdup(const char *str)
-- 
1.7.3.2




[Qemu-devel] [PATCH 2/7] Use qemu_mallocz() instead of calloc() in img_convert()

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

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

diff --git a/qemu-img.c b/qemu-img.c
index fa77ac0..eca99c4 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -699,11 +699,7 @@ static int img_convert(int argc, char **argv)
 return 1;
 }
 
-bs = calloc(bs_n, sizeof(BlockDriverState *));
-if (!bs) {
-error(Out of memory);
-return 1;
-}
+bs = qemu_mallocz(bs_n * sizeof(BlockDriverState *));
 
 total_sectors = 0;
 for (bs_i = 0; bs_i  bs_n; bs_i++) {
@@ -983,7 +979,7 @@ out:
 bdrv_delete(bs[bs_i]);
 }
 }
-free(bs);
+qemu_free(bs);
 if (ret) {
 return 1;
 }
-- 
1.7.3.2




[Qemu-devel] [PATCH 5/7] Consolidate printing of block driver options

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

This consolidates the printing of block driver options in
print_block_option_help() which is called from both img_create() and
img_convert().

This allows for the ? detection to be done just after the parsing of
options and the filename, instead of half way down the codepath of
these functions.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 qemu-img.c |   46 +-
 1 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 7f4939e..c7d0ca8 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -188,6 +188,33 @@ static int read_password(char *buf, int buf_size)
 }
 #endif
 
+static int print_block_option_help(const char *filename, const char *fmt)
+{
+BlockDriver *drv, *proto_drv;
+QEMUOptionParameter *create_options = NULL;
+
+/* Find driver and parse its options */
+drv = bdrv_find_format(fmt);
+if (!drv) {
+error(Unknown file format '%s', fmt);
+return 1;
+}
+
+proto_drv = bdrv_find_protocol(filename);
+if (!proto_drv) {
+error(Unknown protocol '%s', filename);
+return 1;
+}
+
+create_options = append_option_parameters(create_options,
+  drv-create_options);
+create_options = append_option_parameters(create_options,
+  proto_drv-create_options);
+print_option_help(create_options);
+free_option_parameters(create_options);
+return 0;
+}
+
 static BlockDriverState *bdrv_new_open(const char *filename,
const char *fmt,
int flags)
@@ -310,6 +337,11 @@ static int img_create(int argc, char **argv)
 help();
 filename = argv[optind++];
 
+if (options  !strcmp(options, ?)) {
+ret = print_block_option_help(filename, fmt);
+goto out;
+}
+
 /* Find driver and parse its options */
 drv = bdrv_find_format(fmt);
 if (!drv) {
@@ -330,11 +362,6 @@ static int img_create(int argc, char **argv)
 create_options = append_option_parameters(create_options,
   proto_drv-create_options);
 
-if (options  !strcmp(options, ?)) {
-print_option_help(create_options);
-goto out;
-}
-
 /* Create parameter list with default values */
 param = parse_option_parameters(, create_options, param);
 set_option_parameter_int(param, BLOCK_OPT_SIZE, -1);
@@ -696,6 +723,11 @@ static int img_convert(int argc, char **argv)
 
 out_filename = argv[argc - 1];
 
+if (options  !strcmp(options, ?)) {
+ret = print_block_option_help(out_filename, out_fmt);
+goto out;
+}
+
 if (bs_n  1  out_baseimg) {
 error(-B makes no sense when concatenating multiple input images);
 ret = -1;
@@ -748,10 +780,6 @@ static int img_convert(int argc, char **argv)
   drv-create_options);
 create_options = append_option_parameters(create_options,
   proto_drv-create_options);
-if (options  !strcmp(options, ?)) {
-print_option_help(create_options);
-goto out;
-}
 
 if (options) {
 param = parse_option_parameters(options, create_options, param);
-- 
1.7.3.2




[Qemu-devel] [PATCH 4/7] Make error handling more consistent in img_create() and img_resize()

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

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

diff --git a/qemu-img.c b/qemu-img.c
index aded72d..7f4939e 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -314,13 +314,15 @@ static int img_create(int argc, char **argv)
 drv = bdrv_find_format(fmt);
 if (!drv) {
 error(Unknown file format '%s', fmt);
-return 1;
+ret = -1;
+goto out;
 }
 
 proto_drv = bdrv_find_protocol(filename);
 if (!proto_drv) {
 error(Unknown protocol '%s', filename);
-return 1;
+ret = -1;
+goto out;
 }
 
 create_options = append_option_parameters(create_options,
@@ -1483,14 +1485,16 @@ static int img_resize(int argc, char **argv)
 param = parse_option_parameters(, resize_options, NULL);
 if (set_option_parameter(param, BLOCK_OPT_SIZE, size)) {
 /* Error message already printed when size parsing fails */
-exit(1);
+ret = -1;
+goto out;
 }
 n = get_option_parameter(param, BLOCK_OPT_SIZE)-value.n;
 free_option_parameters(param);
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
 if (!bs) {
-return 1;
+ret = -1;
+goto out;
 }
 
 if (relative) {
-- 
1.7.3.2




[Qemu-devel] [PATCH 6/7] Fix formatting and missing braces in qemu-img.c

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

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 qemu-img.c |   77 +++
 1 files changed, 51 insertions(+), 26 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index c7d0ca8..d812db0 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -305,8 +305,9 @@ static int img_create(int argc, char **argv)
 flags = 0;
 for(;;) {
 c = getopt(argc, argv, F:b:f:he6o:);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -333,8 +334,9 @@ static int img_create(int argc, char **argv)
 }
 
 /* Get the filename */
-if (optind = argc)
+if (optind = argc) {
 help();
+}
 filename = argv[optind++];
 
 if (options  !strcmp(options, ?)) {
@@ -473,8 +475,9 @@ static int img_check(int argc, char **argv)
 fmt = NULL;
 for(;;) {
 c = getopt(argc, argv, f:h);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -484,8 +487,9 @@ static int img_check(int argc, char **argv)
 break;
 }
 }
-if (optind = argc)
+if (optind = argc) {
 help();
+}
 filename = argv[optind++];
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS);
@@ -549,8 +553,9 @@ static int img_commit(int argc, char **argv)
 fmt = NULL;
 for(;;) {
 c = getopt(argc, argv, f:h);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -560,8 +565,9 @@ static int img_commit(int argc, char **argv)
 break;
 }
 }
-if (optind = argc)
+if (optind = argc) {
 help();
+}
 filename = argv[optind++];
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
@@ -685,8 +691,9 @@ static int img_convert(int argc, char **argv)
 flags = 0;
 for(;;) {
 c = getopt(argc, argv, f:O:B:s:hce6o:);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -719,7 +726,9 @@ static int img_convert(int argc, char **argv)
 }
 
 bs_n = argc - optind - 1;
-if (bs_n  1) help();
+if (bs_n  1) {
+help();
+}
 
 out_filename = argv[argc - 1];
 
@@ -907,8 +916,9 @@ static int img_convert(int argc, char **argv)
 }
 assert (remainder == 0);
 
-if (n  cluster_sectors)
+if (n  cluster_sectors) {
 memset(buf + n * 512, 0, cluster_size - n * 512);
+}
 if (is_not_zero(buf, cluster_size)) {
 ret = bdrv_write_compressed(out_bs, sector_num, buf,
 cluster_sectors);
@@ -928,12 +938,14 @@ static int img_convert(int argc, char **argv)
 sector_num = 0; // total number of sectors converted so far
 for(;;) {
 nb_sectors = total_sectors - sector_num;
-if (nb_sectors = 0)
+if (nb_sectors = 0) {
 break;
-if (nb_sectors = (IO_BUF_SIZE / 512))
+}
+if (nb_sectors = (IO_BUF_SIZE / 512)) {
 n = (IO_BUF_SIZE / 512);
-else
+} else {
 n = nb_sectors;
+}
 
 while (sector_num - bs_offset = bs_sectors) {
 bs_i ++;
@@ -945,8 +957,9 @@ static int img_convert(int argc, char **argv)
sector_num, bs_i, bs_offset, bs_sectors); */
 }
 
-if (n  bs_offset + bs_sectors - sector_num)
+if (n  bs_offset + bs_sectors - sector_num) {
 n = bs_offset + bs_sectors - sector_num;
+}
 
 if (has_zero_init) {
 /* If the output image is being created as a copy on write 
image,
@@ -1082,8 +1095,9 @@ static int img_info(int argc, char **argv)
 fmt = NULL;
 for(;;) {
 c = getopt(argc, argv, f:h);
-if (c == -1)
+if (c == -1) {
 break;
+}
 switch(c) {
 case 'h':
 help();
@@ -1093,8 +1107,9 @@ static int img_info(int argc, char **argv)
 break;
 }
 }
-if (optind = argc)
+if (optind = argc) {
 help();
+}
 filename = argv[optind++];
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_NO_BACKING);
@@ -1105,11 +1120,12 @@ static int img_info(int argc, char **argv)
 bdrv_get_geometry(bs, total_sectors);
 get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512);
 allocated_size = get_allocated_file_size(filename);
-if (allocated_size  0)
+if (allocated_size  0) {
 snprintf(dsize_buf, sizeof(dsize_buf), unavailable);
-

[Qemu-devel] [PATCH 3/7] img_convert(): Only try to free bs[] entries if bs is valid.

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

This allows for jumping to 'out:' consistently for error exit.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 qemu-img.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index eca99c4..aded72d 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -696,7 +696,8 @@ static int img_convert(int argc, char **argv)
 
 if (bs_n  1  out_baseimg) {
 error(-B makes no sense when concatenating multiple input images);
-return 1;
+ret = -1;
+goto out;
 }
 
 bs = qemu_mallocz(bs_n * sizeof(BlockDriverState *));
@@ -974,12 +975,14 @@ out:
 if (out_bs) {
 bdrv_delete(out_bs);
 }
-for (bs_i = 0; bs_i  bs_n; bs_i++) {
-if (bs[bs_i]) {
-bdrv_delete(bs[bs_i]);
+if (bs) {
+for (bs_i = 0; bs_i  bs_n; bs_i++) {
+if (bs[bs_i]) {
+bdrv_delete(bs[bs_i]);
+}
 }
+qemu_free(bs);
 }
-qemu_free(bs);
 if (ret) {
 return 1;
 }
-- 
1.7.3.2




[Qemu-devel] [PATCH 7/7] Fail if detecting an unknown option

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

This patch changes qemu-img to exit if an unknown option is detected,
instead of trying to continue with a set of arguments which may be
incorrect.

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

diff --git a/qemu-img.c b/qemu-img.c
index d812db0..f021a06 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -309,6 +309,7 @@ static int img_create(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -479,6 +480,7 @@ static int img_check(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -557,6 +559,7 @@ static int img_commit(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -695,6 +698,7 @@ static int img_convert(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -1099,6 +1103,7 @@ static int img_info(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
@@ -1176,6 +1181,7 @@ static int img_snapshot(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 return 0;
@@ -1291,6 +1297,7 @@ static int img_rebase(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 return 0;
@@ -1505,6 +1512,7 @@ static int img_resize(int argc, char **argv)
 break;
 }
 switch(c) {
+case '?':
 case 'h':
 help();
 break;
-- 
1.7.3.2




[Qemu-devel] [PULL 0/4]: Monitor queue

2010-12-06 Thread Luiz Capitulino
Anthony,

QMP fixes pull request.

The changes (since 2c90fe2b71df2534884bce96d90cbfcc93aeedb8) are available
in the following repository:

git://repo.or.cz/qemu/qmp-unstable.git for-anthony

Luiz Capitulino (3):
  QMP: Fix default response regression
  QMP: Drop dead code
  QMP: Simplify monitor_json_emitter()

Wen Congyang (1):
  correct migrate_set_speed's args_type

 monitor.c   |   84 --
 qmp-commands.hx |2 +-
 2 files changed, 38 insertions(+), 48 deletions(-)




[Qemu-devel] [PATCH 3/4] QMP: Simplify monitor_json_emitter()

2010-12-06 Thread Luiz Capitulino
Use the ternary operator instead of an if (also fixes bad indentation).

Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
---
 monitor.c |6 ++
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index 1e8b1fc..f1aebc1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -351,10 +351,8 @@ static void monitor_json_emitter(Monitor *mon, const 
QObject *data)
 {
 QString *json;
 
-if (mon-flags  MONITOR_USE_PRETTY)
-   json = qobject_to_json_pretty(data);
-else
-   json = qobject_to_json(data);
+json = mon-flags  MONITOR_USE_PRETTY ? qobject_to_json_pretty(data) :
+ qobject_to_json(data);
 assert(json != NULL);
 
 qstring_append_chr(json, '\n');
-- 
1.7.3.3.398.g0b0cd




[Qemu-devel] [PATCH 2/4] QMP: Drop dead code

2010-12-06 Thread Luiz Capitulino
The first if/else clause in handler_audit() makes no sense for two
reasons:

  1. this function is now called only by QMP code, so testing if
 it's a QMP call makes no sense anymore

  2. the else clause first asserts that there's no error in the
 monitor object, then it tries to free it!

Just drop it.

Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
---
 monitor.c |   74 -
 1 files changed, 34 insertions(+), 40 deletions(-)

diff --git a/monitor.c b/monitor.c
index 1296c40..1e8b1fc 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3891,49 +3891,43 @@ void monitor_set_error(Monitor *mon, QError *qerror)
 
 static void handler_audit(Monitor *mon, const mon_cmd_t *cmd, int ret)
 {
-if (monitor_ctrl_mode(mon)) {
-if (ret  !monitor_has_error(mon)) {
-/*
- * If it returns failure, it must have passed on error.
- *
- * Action: Report an internal error to the client if in QMP.
- */
-qerror_report(QERR_UNDEFINED_ERROR);
-MON_DEBUG(command '%s' returned failure but did not pass an 
error\n,
-  cmd-name);
-}
+if (ret  !monitor_has_error(mon)) {
+/*
+ * If it returns failure, it must have passed on error.
+ *
+ * Action: Report an internal error to the client if in QMP.
+ */
+qerror_report(QERR_UNDEFINED_ERROR);
+MON_DEBUG(command '%s' returned failure but did not pass an error\n,
+  cmd-name);
+}
 
 #ifdef CONFIG_DEBUG_MONITOR
-if (!ret  monitor_has_error(mon)) {
-/*
- * If it returns success, it must not have passed an error.
- *
- * Action: Report the passed error to the client.
- */
-MON_DEBUG(command '%s' returned success but passed an error\n,
-  cmd-name);
-}
-
-if (mon_print_count_get(mon)  0  strcmp(cmd-name, info) != 0) {
-/*
- * Handlers should not call Monitor print functions.
- *
- * Action: Ignore them in QMP.
- *
- * (XXX: we don't check any 'info' or 'query' command here
- * because the user print function _is_ called by do_info(), hence
- * we will trigger this check. This problem will go away when we
- * make 'query' commands real and kill do_info())
- */
-MON_DEBUG(command '%s' called print functions %d time(s)\n,
-  cmd-name, mon_print_count_get(mon));
-}
-#endif
-} else {
-assert(!monitor_has_error(mon));
-QDECREF(mon-error);
-mon-error = NULL;
+if (!ret  monitor_has_error(mon)) {
+/*
+ * If it returns success, it must not have passed an error.
+ *
+ * Action: Report the passed error to the client.
+ */
+MON_DEBUG(command '%s' returned success but passed an error\n,
+  cmd-name);
+}
+
+if (mon_print_count_get(mon)  0  strcmp(cmd-name, info) != 0) {
+/*
+ * Handlers should not call Monitor print functions.
+ *
+ * Action: Ignore them in QMP.
+ *
+ * (XXX: we don't check any 'info' or 'query' command here
+ * because the user print function _is_ called by do_info(), hence
+ * we will trigger this check. This problem will go away when we
+ * make 'query' commands real and kill do_info())
+ */
+MON_DEBUG(command '%s' called print functions %d time(s)\n,
+  cmd-name, mon_print_count_get(mon));
 }
+#endif
 }
 
 static void handle_user_command(Monitor *mon, const char *cmdline)
-- 
1.7.3.3.398.g0b0cd




[Qemu-devel] [PATCH 4/4] correct migrate_set_speed's args_type

2010-12-06 Thread Luiz Capitulino
From: Wen Congyang we...@cn.fujitsu.com

The args_type of migrate_set_speed in qmp-commands.hx is wrong.
When we set migrate speed by json, qemu will be core dumped.

This bug was caused by 07de3e60b05 and hence affects master only.

Signed-off-by: Wen Congyang we...@cn.fujitsu.com
Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
---
 qmp-commands.hx |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/qmp-commands.hx b/qmp-commands.hx
index e5f157f..3486223 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -495,7 +495,7 @@ EQMP
 
 {
 .name   = migrate_set_speed,
-.args_type  = value:f,
+.args_type  = value:o,
 .params = value,
 .help   = set maximum speed (in bytes) for migrations,
 .user_print = monitor_user_noop,
-- 
1.7.3.3.398.g0b0cd




[Qemu-devel] Re: [PATCH 1/7] Add missing tracing to qemu_mallocz()

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 06, 2010 at 03:25:34PM +0100, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-malloc.c |5 -
  1 files changed, 4 insertions(+), 1 deletions(-)

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] Re: [PATCH 2/7] Use qemu_mallocz() instead of calloc() in img_convert()

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 06, 2010 at 03:25:35PM +0100, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-img.c |8 ++--
  1 files changed, 2 insertions(+), 6 deletions(-)

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] Re: [PATCH 4/7] Make error handling more consistent in img_create() and img_resize()

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 06, 2010 at 03:25:37PM +0100, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-img.c |   12 
  1 files changed, 8 insertions(+), 4 deletions(-)

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] Re: [PATCH 5/7] Consolidate printing of block driver options

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 06, 2010 at 03:25:38PM +0100, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com
 
 This consolidates the printing of block driver options in
 print_block_option_help() which is called from both img_create() and
 img_convert().
 
 This allows for the ? detection to be done just after the parsing of
 options and the filename, instead of half way down the codepath of
 these functions.
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-img.c |   46 +-
  1 files changed, 37 insertions(+), 9 deletions(-)

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] Re: [PATCH 6/7] Fix formatting and missing braces in qemu-img.c

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 06, 2010 at 03:25:39PM +0100, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
  qemu-img.c |   77 +++
  1 files changed, 51 insertions(+), 26 deletions(-)

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] [PATCH 1/4] QMP: Fix default response regression

2010-12-06 Thread Luiz Capitulino
Commit 030db6e89d dropped do_info() usage from QMP and introduced
qmp_call_query_cmd(). However, the new function doesn't emit QMP's
default OK response when the handler doesn't return data.

Fix that by also calling monitor_protocol_emitter() when
ret_data == NULL, so that the default response is emitted.

Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
---
 monitor.c |6 ++
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index ec31eac..1296c40 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4464,10 +4464,8 @@ static void qmp_call_query_cmd(Monitor *mon, const 
mon_cmd_t *cmd)
 }
 } else {
 cmd-mhandler.info_new(mon, ret_data);
-if (ret_data) {
-monitor_protocol_emitter(mon, ret_data);
-qobject_decref(ret_data);
-}
+monitor_protocol_emitter(mon, ret_data);
+qobject_decref(ret_data);
 }
 }
 
-- 
1.7.3.3.398.g0b0cd




[Qemu-devel] [PATCH 1/2] Fix commandline handling for ARM semihosted executables

2010-12-06 Thread Peter Maydell
From: Wolfgang Schildbach ws...@dolby.com

Use the copy of the command line that loader_build_argptr() sets up in guest
memory as the command line to return from the ARM SYS_GET_CMDLINE semihosting
call. Previously we were using a pointer to memory which had already been
freed before the guest program started.

This fixes https://bugs.launchpad.net/qemu/+bug/673613 .

Signed-off-by: Wolfgang Schildbach ws...@dolby.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 arm-semi.c |   79 +--
 1 files changed, 49 insertions(+), 30 deletions(-)

diff --git a/arm-semi.c b/arm-semi.c
index 0687b03..1d5179b 100644
--- a/arm-semi.c
+++ b/arm-semi.c
@@ -373,45 +373,64 @@ uint32_t do_arm_semihosting(CPUState *env)
 #ifdef CONFIG_USER_ONLY
 /* Build a commandline from the original argv.  */
 {
-char **arg = ts-info-host_argv;
-int len = ARG(1);
-/* lock the buffer on the ARM side */
-char *cmdline_buffer = (char*)lock_user(VERIFY_WRITE, ARG(0), len, 
0);
+char *arm_cmdline_buffer;
+const char *host_cmdline_buffer;
 
-if (!cmdline_buffer)
-/* FIXME - should this error code be -TARGET_EFAULT ? */
-return (uint32_t)-1;
+unsigned int i;
+unsigned int arm_cmdline_len = ARG(1);
+unsigned int host_cmdline_len =
+ts-info-arg_end-ts-info-arg_start;
+
+if (!arm_cmdline_len || host_cmdline_len  arm_cmdline_len) {
+return -1; /* not enough space to store command line */
+}
 
-s = cmdline_buffer;
-while (*arg  len  2) {
-int n = strlen(*arg);
+if (!host_cmdline_len) {
+/* We special-case the empty command line case (argc==0).
+   Just provide the terminating 0. */
+arm_cmdline_buffer = lock_user(VERIFY_WRITE, ARG(0), 1, 0);
+arm_cmdline_buffer[0] = 0;
+unlock_user(arm_cmdline_buffer, ARG(0), 1);
 
-if (s != cmdline_buffer) {
-*(s++) = ' ';
-len--;
-}
-if (n = len)
-n = len - 1;
-memcpy(s, *arg, n);
-s += n;
-len -= n;
-arg++;
+/* Adjust the commandline length argument. */
+SET_ARG(1, 0);
+return 0;
 }
-/* Null terminate the string.  */
-*s = 0;
-len = s - cmdline_buffer;
 
-/* Unlock the buffer on the ARM side.  */
-unlock_user(cmdline_buffer, ARG(0), len);
+/* lock the buffers on the ARM side */
+arm_cmdline_buffer =
+lock_user(VERIFY_WRITE, ARG(0), host_cmdline_len, 0);
+host_cmdline_buffer =
+lock_user(VERIFY_READ, ts-info-arg_start,
+   host_cmdline_len, 1);
 
-/* Adjust the commandline length argument.  */
-SET_ARG(1, len);
+if (arm_cmdline_buffer  host_cmdline_buffer)
+{
+/* the last argument is zero-terminated;
+   no need for additional termination */
+memcpy(arm_cmdline_buffer, host_cmdline_buffer,
+   host_cmdline_len);
 
-/* Return success if commandline fit into buffer.  */
-return *arg ? -1 : 0;
+/* separate arguments by white spaces */
+for (i = 0; i  host_cmdline_len-1; i++) {
+if (arm_cmdline_buffer[i] == 0) {
+arm_cmdline_buffer[i] = ' ';
+}
+}
+
+/* Adjust the commandline length argument. */
+SET_ARG(1, host_cmdline_len-1);
+}
+
+/* Unlock the buffers on the ARM side.  */
+unlock_user(arm_cmdline_buffer, ARG(0), host_cmdline_len);
+unlock_user((void*)host_cmdline_buffer, ts-info-arg_start, 0);
+
+/* Return success if we could return a commandline.  */
+return (arm_cmdline_buffer  host_cmdline_buffer) ? 0 : -1;
 }
 #else
-  return -1;
+return -1;
 #endif
 case SYS_HEAPINFO:
 {
-- 
1.6.3.3




[Qemu-devel] Re: [PATCH 3/7] img_convert(): Only try to free bs[] entries if bs is valid.

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 06, 2010 at 03:25:36PM +0100, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com
 
 This allows for jumping to 'out:' consistently for error exit.
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-img.c |   13 -
  1 files changed, 8 insertions(+), 5 deletions(-)

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] Re: [PATCH 7/7] Fail if detecting an unknown option

2010-12-06 Thread Stefan Hajnoczi
On Mon, Dec 06, 2010 at 03:25:40PM +0100, jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com
 
 This patch changes qemu-img to exit if an unknown option is detected,
 instead of trying to continue with a set of arguments which may be
 incorrect.
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-img.c |8 
  1 files changed, 8 insertions(+), 0 deletions(-)

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] [PATCH 0/2] ARM: fix commandline handling for semihosted executables

2010-12-06 Thread Peter Maydell
This patchset fixes the commandline handling for ARM semihosted executables
run under linux-user mode, and cleans up the resulting unused variable in
the linux-user image_info struct. The code is all by Wolfgang but he is
having difficulty sending properly formatted patches to the list so I am
retransmitting them (with my Reviewed-by: signoff).

Wolfgang Schildbach (2):
  Fix commandline handling for ARM semihosted executables
  Remove dead code for ARM semihosting commandline handling

 arm-semi.c |   79 +--
 bsd-user/bsdload.c |2 -
 bsd-user/qemu.h|1 -
 linux-user/linuxload.c |2 -
 linux-user/qemu.h  |1 -
 5 files changed, 49 insertions(+), 36 deletions(-)




Re: [Qemu-devel] [PATCH 0/6] [RFC] New SPARC machine: Leon3

2010-12-06 Thread Fabien Chouteau

On 12/06/2010 11:44 AM, Artyom Tarasenko wrote:

On Mon, Dec 6, 2010 at 10:26 AM, Fabien Chouteauchout...@adacore.com  wrote:

Hi everyone,
I'm glad to submit my first patches to the Qemu-devel list.

This patch set introduces a new SPARC V8 machine: Leon3. It's an open-source
VHDL System-On-Chip, well known in space industry (more information on
http://www.gaisler.com).

Nice! Haven't looked into the code yet, but it's great to have someone
who cares for V8.


And if this patch is accepted, we will try to submit more machines like 
erc32 and leon2.



Do you also have a firmware which runs on these machines?



I can give you a binary running some basic tests.


Leon3 is made of multiple components available in the GrLib VHDL library.
Three devices are implemented: uart, timers and IRQ manager.
You can find code for these peripherals in the grlib_* files.

Modifications have been done to the SPARC cpu emulation code to handle
Leon3's specific behavior:
  - IRQ management
  - Cache control
  - Asr17 (implementation-dependent Ancillary State Registers)

Is it the only implementation-dependent asr in Leon3? Thought there were more.



Yes, there's also asr19 for power-down, asr16 for FPU control and others 
for hardware breakpoints.
These are not required for this first implementation, but If there's a 
need for more ASRs, we may have to find a generic implementation to 
handle those registers.


Regards,

--
Fabien Chouteau




Re: [Qemu-devel] Re: [PATCH 2/3] virtio-pci: Use ioeventfd for virtqueue notify

2010-12-06 Thread Avi Kivity

On 12/01/2010 11:34 PM, Stefan Hajnoczi wrote:

  The guest CPU utilization numbers include an efficiency metric: %vcpu
  per MB/sec.  Here we see significant improvements too.  Guests that
  previously couldn't get more CPU work done now have regained some
  breathing space.

  Thanks for those numbers.  The guest improvements were expected, but the
  host numbers surprised me.  Do you have an explanation as to why total host
  load should decrease?

The first vcpu does virtqueue kick - it holds the guest driver
vblk-lock across kick.  Before this kick completes a second vcpu
tries to acquire vblk-lock, finds it is contended, and spins.  So
we're burning CPU due to the long vblk-lock hold times.

With virtio-ioeventfd those kick times are reduced an there is less
contention on vblk-lock.


Makes sense.

--
error compiling committee.c: too many arguments to function




[Qemu-devel] Re: [PATCH 4/7] Make error handling more consistent in img_create() and img_resize()

2010-12-06 Thread Kevin Wolf
Am 06.12.2010 15:25, schrieb jes.soren...@redhat.com:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-img.c |   12 
  1 files changed, 8 insertions(+), 4 deletions(-)
 
 diff --git a/qemu-img.c b/qemu-img.c
 index aded72d..7f4939e 100644
 --- a/qemu-img.c
 +++ b/qemu-img.c
 @@ -314,13 +314,15 @@ static int img_create(int argc, char **argv)
  drv = bdrv_find_format(fmt);
  if (!drv) {
  error(Unknown file format '%s', fmt);
 -return 1;
 +ret = -1;
 +goto out;
  }
  
  proto_drv = bdrv_find_protocol(filename);
  if (!proto_drv) {
  error(Unknown protocol '%s', filename);
 -return 1;
 +ret = -1;
 +goto out;
  }
  
  create_options = append_option_parameters(create_options,
 @@ -1483,14 +1485,16 @@ static int img_resize(int argc, char **argv)
  param = parse_option_parameters(, resize_options, NULL);
  if (set_option_parameter(param, BLOCK_OPT_SIZE, size)) {
  /* Error message already printed when size parsing fails */
 -exit(1);
 +ret = -1;
 +goto out;

bs isn't initialized here, so the bdrv_delete(bs) after out: will crash.

  }
  n = get_option_parameter(param, BLOCK_OPT_SIZE)-value.n;
  free_option_parameters(param);
  
  bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
  if (!bs) {
 -return 1;
 +ret = -1;
 +goto out;
  }

Same here.

Heh, wanted to try it out to be sure, but the compiler notices that, so
it doesn't even build:

cc1: warnings being treated as errors
qemu-img.c: In function 'img_resize':
qemu-img.c:1497: error: 'bs' may be used uninitialized in this function

Kevin



[Qemu-devel] [PATCH 2/2] Remove dead code for ARM semihosting commandline handling

2010-12-06 Thread Peter Maydell
From: Wolfgang Schildbach ws...@dolby.com

There are some bits in the code which were used to store the commandline for
the semihosting call. These bits are now write-only and can be removed.

Signed-off-by: Wolfgang Schildbach ws...@dolby.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 bsd-user/bsdload.c |2 --
 bsd-user/qemu.h|1 -
 linux-user/linuxload.c |2 --
 linux-user/qemu.h  |1 -
 4 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c
index 14a93bf..6d9bb6f 100644
--- a/bsd-user/bsdload.c
+++ b/bsd-user/bsdload.c
@@ -176,8 +176,6 @@ int loader_exec(const char * filename, char ** argv, char 
** envp,
 
 retval = prepare_binprm(bprm);
 
-infop-host_argv = argv;
-
 if(retval=0) {
 if (bprm.buf[0] == 0x7f
  bprm.buf[1] == 'E'
diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
index 9763616..e343894 100644
--- a/bsd-user/qemu.h
+++ b/bsd-user/qemu.h
@@ -50,7 +50,6 @@ struct image_info {
 abi_ulong entry;
 abi_ulong code_offset;
 abi_ulong data_offset;
-char  **host_argv;
 int   personality;
 };
 
diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 9ee27c3..ac8c486 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -174,8 +174,6 @@ int loader_exec(const char * filename, char ** argv, char 
** envp,
 
 retval = prepare_binprm(bprm);
 
-infop-host_argv = argv;
-
 if(retval=0) {
 if (bprm-buf[0] == 0x7f
  bprm-buf[1] == 'E'
diff --git a/linux-user/qemu.h b/linux-user/qemu.h
index e66a02b..32de241 100644
--- a/linux-user/qemu.h
+++ b/linux-user/qemu.h
@@ -50,7 +50,6 @@ struct image_info {
 abi_ulong   saved_auxv;
 abi_ulong   arg_start;
 abi_ulong   arg_end;
-char**host_argv;
int personality;
 };
 
-- 
1.6.3.3




[Qemu-devel] Re: [PATCH v3 0/7] Cleanup qemu-img code

2010-12-06 Thread Kevin Wolf
Am 06.12.2010 15:25, schrieb jes.soren...@redhat.com:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Hi,
 
 These patches applies a number of cleanups to qemu-img.c as well as a
 minor bug in qemu-malloc.c. 
 
 The handling of block help printing is moved to shared code, which
 allows the ? detection to happen early in the parsing, instead of
 half way down img_create() and img_convert(). I would like to see this
 happen as I would like to pull some of the code out of img_create()
 and into block.c so it can be shared with qemu and qemu-img.
 
 In addition there is a couple of patches to clean up the error
 handling in qemu-img.c and make it more consistent.
 
 The formatting patch is solely because the last patch wanted to
 change code next to the badly formatted code, and I didn't want to
 pollute the patch with the formatting fixed.
 
 The seventh patch fixes qemu-img to exit on detection of unknown
 options instead of continuing with a potentially wrong set of
 arguments.
 
 v3 applies a number of changes discussed on irc and email. This is the
 grow to seven from three patches series.
 
 Cheers,
 Jes
 
 Jes Sorensen (7):
   Add missing tracing to qemu_mallocz()
   Use qemu_mallocz() instead of calloc() in img_convert()
   img_convert(): Only try to free bs[] entries if bs is valid.
   Make error handling more consistent in img_create() and img_resize()
   Consolidate printing of block driver options
   Fix formatting and missing braces in qemu-img.c
   Fail if detecting an unknown option
 
  qemu-img.c|  162 +++-
  qemu-malloc.c |5 ++-
  2 files changed, 117 insertions(+), 50 deletions(-)

Thanks, applied all except patch 4, which breaks the build. Please
resend a new version of patch 4 as a single patch without the rest of
the series.

Kevin



[Qemu-devel] Re: [PATCH 4/7] Make error handling more consistent in img_create() and img_resize()

2010-12-06 Thread Jes Sorensen
On 12/06/10 16:25, Kevin Wolf wrote:
  }
  n = get_option_parameter(param, BLOCK_OPT_SIZE)-value.n;
  free_option_parameters(param);
  
  bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
  if (!bs) {
 -return 1;
 +ret = -1;
 +goto out;
  }
 
 Same here.
 
 Heh, wanted to try it out to be sure, but the compiler notices that, so
 it doesn't even build:

Gr I am an idiot!

Sorry about the noise, I was sure I had tested that last change. Fix
coming up in a few minutes.

Cheers,
Jes




[Qemu-devel] [PATCH 4/7] Make error handling more consistent in img_create() and img_resize()

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

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 qemu-img.c |   14 +-
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index aded72d..2deac67 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -314,13 +314,15 @@ static int img_create(int argc, char **argv)
 drv = bdrv_find_format(fmt);
 if (!drv) {
 error(Unknown file format '%s', fmt);
-return 1;
+ret = -1;
+goto out;
 }
 
 proto_drv = bdrv_find_protocol(filename);
 if (!proto_drv) {
 error(Unknown protocol '%s', filename);
-return 1;
+ret = -1;
+goto out;
 }
 
 create_options = append_option_parameters(create_options,
@@ -1432,7 +1434,7 @@ static int img_resize(int argc, char **argv)
 int c, ret, relative;
 const char *filename, *fmt, *size;
 int64_t n, total_size;
-BlockDriverState *bs;
+BlockDriverState *bs = NULL;
 QEMUOptionParameter *param;
 QEMUOptionParameter resize_options[] = {
 {
@@ -1483,14 +1485,16 @@ static int img_resize(int argc, char **argv)
 param = parse_option_parameters(, resize_options, NULL);
 if (set_option_parameter(param, BLOCK_OPT_SIZE, size)) {
 /* Error message already printed when size parsing fails */
-exit(1);
+ret = -1;
+goto out;
 }
 n = get_option_parameter(param, BLOCK_OPT_SIZE)-value.n;
 free_option_parameters(param);
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
 if (!bs) {
-return 1;
+ret = -1;
+goto out;
 }
 
 if (relative) {
-- 
1.7.3.2




[Qemu-devel] Re: [PATCH 4/7] Make error handling more consistent in img_create() and img_resize()

2010-12-06 Thread Kevin Wolf
Am 06.12.2010 16:45, schrieb jes.soren...@redhat.com:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com
 ---
  qemu-img.c |   14 +-
  1 files changed, 9 insertions(+), 5 deletions(-)

 @@ -1432,7 +1434,7 @@ static int img_resize(int argc, char **argv)
  int c, ret, relative;
  const char *filename, *fmt, *size;
  int64_t n, total_size;
 -BlockDriverState *bs;
 +BlockDriverState *bs = NULL;
  QEMUOptionParameter *param;
  QEMUOptionParameter resize_options[] = {
  {
 @@ -1483,14 +1485,16 @@ static int img_resize(int argc, char **argv)
  param = parse_option_parameters(, resize_options, NULL);
  if (set_option_parameter(param, BLOCK_OPT_SIZE, size)) {
  /* Error message already printed when size parsing fails */
 -exit(1);
 +ret = -1;
 +goto out;
  }
  n = get_option_parameter(param, BLOCK_OPT_SIZE)-value.n;
  free_option_parameters(param);
  
  bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
  if (!bs) {
 -return 1;
 +ret = -1;
 +goto out;
  }
  
  if (relative) {

bdrv_delete doesn't check for NULL, so this still isn't enough. Try
something like qemu-img resize -f vmdx foo +0 and you'll get a segfault.

Kevin



[Qemu-devel] Re: [PATCH 4/7] Make error handling more consistent in img_create() and img_resize()

2010-12-06 Thread Jes Sorensen
On 12/06/10 16:57, Kevin Wolf wrote:
 bdrv_delete doesn't check for NULL, so this still isn't enough. Try
 something like qemu-img resize -f vmdx foo +0 and you'll get a segfault.

G :(

It's a bummer things are so inconsistent throughout QEMU, most of the
free() functions can handle it.

Updated patch in a minute - sorry.

Thanks,
Jes



[Qemu-devel] [PATCH v6 1/5] docs: Add QED image format specification

2010-12-06 Thread Stefan Hajnoczi
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 docs/specs/qed_spec.txt |  130 +++
 1 files changed, 130 insertions(+), 0 deletions(-)
 create mode 100644 docs/specs/qed_spec.txt

diff --git a/docs/specs/qed_spec.txt b/docs/specs/qed_spec.txt
new file mode 100644
index 000..1d5fa87
--- /dev/null
+++ b/docs/specs/qed_spec.txt
@@ -0,0 +1,130 @@
+=Specification=
+
+The file format looks like this:
+
+ +--+--+--+-+
+ | cluster0 | cluster1 | cluster2 | ... |
+ +--+--+--+-+
+
+The first cluster begins with the '''header'''.  The header contains 
information about where regular clusters start; this allows the header to be 
extensible and store extra information about the image file.  A regular cluster 
may be a '''data cluster''', an '''L2''', or an '''L1 table'''.  L1 and L2 
tables are composed of one or more contiguous clusters.
+
+Normally the file size will be a multiple of the cluster size.  If the file 
size is not a multiple, extra information after the last cluster may not be 
preserved if data is written.  Legitimate extra information should use space 
between the header and the first regular cluster.
+
+All fields are little-endian.
+
+==Header==
+ Header {
+ uint32_t magic;   /* QED\0 */
+ 
+ uint32_t cluster_size;/* in bytes */
+ uint32_t table_size;  /* for L1 and L2 tables, in clusters */
+ uint32_t header_size; /* in clusters */
+ 
+ uint64_t features;/* format feature bits */
+ uint64_t compat_features; /* compat feature bits */
+ uint64_t autoclear_features;  /* self-resetting feature bits */
+
+ uint64_t l1_table_offset; /* in bytes */
+ uint64_t image_size;  /* total logical image size, in bytes */
+ 
+ /* if (features  QED_F_BACKING_FILE) */
+ uint32_t backing_filename_offset; /* in bytes from start of header */
+ uint32_t backing_filename_size;   /* in bytes */
+ }
+
+Field descriptions:
+* ''cluster_size'' must be a power of 2 in range [2^12, 2^26].
+* ''table_size'' must be a power of 2 in range [1, 16].
+* ''header_size'' is the number of clusters used by the header and any 
additional information stored before regular clusters.
+* ''features'', ''compat_features'', and ''autoclear_features'' are file 
format extension bitmaps.  They work as follows:
+** An image with unknown ''features'' bits enabled must not be opened.  File 
format changes that are not backwards-compatible must use ''features'' bits.
+** An image with unknown ''compat_features'' bits enabled can be opened 
safely.  The unknown features are simply ignored and represent 
backwards-compatible changes to the file format.
+** An image with unknown ''autoclear_features'' bits enable can be opened 
safely after clearing the unknown bits.  This allows for backwards-compatible 
changes to the file format which degrade gracefully and can be re-enabled again 
by a new program later.
+* ''l1_table_offset'' is the offset of the first byte of the L1 table in the 
image file and must be a multiple of ''cluster_size''.
+* ''image_size'' is the block device size seen by the guest and must be a 
multiple of 512 bytes.
+* ''backing_filename_offset'' and ''backing_filename_size'' describe a string 
in (byte offset, byte size) form.  It is not NUL-terminated and has no 
alignment constraints.  The string must be stored within the first 
''header_size'' clusters.  The backing filename may be an absolute path or 
relative to the image file.
+
+Feature bits:
+* QED_F_BACKING_FILE = 0x01.  The image uses a backing file.
+* QED_F_NEED_CHECK = 0x02.  The image needs a consistency check before use.
+* QED_F_BACKING_FORMAT_NO_PROBE = 0x04.  The backing file is a raw disk image 
and no file format autodetection should be attempted.  This should be used to 
ensure that raw backing files are never detected as an image format if they 
happen to contain magic constants.
+
+There are currently no defined ''compat_features'' or ''autoclear_features'' 
bits.
+
+Fields predicated on a feature bit are only used when that feature is set.  
The fields always take up header space, regardless of whether or not the 
feature bit is set.
+
+==Tables==
+
+Tables provide the translation from logical offsets in the block device to 
cluster offsets in the file.
+
+ #define TABLE_NOFFSETS (table_size * cluster_size / sizeof(uint64_t))
+  
+ Table {
+ uint64_t offsets[TABLE_NOFFSETS];
+ }
+
+The tables are organized as follows:
+
++--+
+| L1 table |
++--+
+   ,--'  |  '--.
+  +--+   |+--+
+  | L2 table |  ...   | L2 table |
+  +--++--+
+  ,--'  |  '--.
+ +--+   |+--+
+ |   Data   |  ...   |   Data   |
+ +--++--+
+
+A 

[Qemu-devel] [PATCH v6 5/5] qed: Consistency check support

2010-12-06 Thread Stefan Hajnoczi
This patch adds support for the qemu-img check command.  It also
introduces a dirty bit in the qed header to mark modified images as
needing a check.  This bit is cleared when the image file is closed
cleanly.

If an image file is opened and it has the dirty bit set, a consistency
check will run and try to fix corrupted table offsets.  These
corruptions may occur if there is power loss while an allocating write
is performed.  Once the image is fixed it opens as normal again.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 block/qed-check.c |  210 +
 block/qed.c   |  125 +++-
 block/qed.h   |4 +
 3 files changed, 336 insertions(+), 3 deletions(-)
 create mode 100644 block/qed-check.c

diff --git a/block/qed-check.c b/block/qed-check.c
new file mode 100644
index 000..4600932
--- /dev/null
+++ b/block/qed-check.c
@@ -0,0 +1,210 @@
+/*
+ * QEMU Enhanced Disk Format Consistency Check
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Stefan Hajnoczi   stefa...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include qed.h
+
+typedef struct {
+BDRVQEDState *s;
+BdrvCheckResult *result;
+bool fix;   /* whether to fix invalid offsets */
+
+size_t nclusters;
+uint32_t *used_clusters;/* referenced cluster bitmap */
+
+QEDRequest request;
+} QEDCheck;
+
+static bool qed_test_bit(uint32_t *bitmap, uint64_t n) {
+return !!(bitmap[n / 32]  (1  (n % 32)));
+}
+
+static void qed_set_bit(uint32_t *bitmap, uint64_t n) {
+bitmap[n / 32] |= 1  (n % 32);
+}
+
+/**
+ * Set bitmap bits for clusters
+ *
+ * @check:  Check structure
+ * @offset: Starting offset in bytes
+ * @n:  Number of clusters
+ */
+static bool qed_set_used_clusters(QEDCheck *check, uint64_t offset,
+  unsigned int n)
+{
+uint64_t cluster = qed_bytes_to_clusters(check-s, offset);
+unsigned int corruptions = 0;
+
+while (n-- != 0) {
+/* Clusters should only be referenced once */
+if (qed_test_bit(check-used_clusters, cluster)) {
+corruptions++;
+}
+
+qed_set_bit(check-used_clusters, cluster);
+cluster++;
+}
+
+check-result-corruptions += corruptions;
+return corruptions == 0;
+}
+
+/**
+ * Check an L2 table
+ *
+ * @ret:Number of invalid cluster offsets
+ */
+static unsigned int qed_check_l2_table(QEDCheck *check, QEDTable *table)
+{
+BDRVQEDState *s = check-s;
+unsigned int i, num_invalid = 0;
+
+for (i = 0; i  s-table_nelems; i++) {
+uint64_t offset = table-offsets[i];
+
+if (!offset) {
+continue;
+}
+
+/* Detect invalid cluster offset */
+if (!qed_check_cluster_offset(s, offset)) {
+if (check-fix) {
+table-offsets[i] = 0;
+} else {
+check-result-corruptions++;
+}
+
+num_invalid++;
+continue;
+}
+
+qed_set_used_clusters(check, offset, 1);
+}
+
+return num_invalid;
+}
+
+/**
+ * Descend tables and check each cluster is referenced once only
+ */
+static int qed_check_l1_table(QEDCheck *check, QEDTable *table)
+{
+BDRVQEDState *s = check-s;
+unsigned int i, num_invalid_l1 = 0;
+int ret, last_error = 0;
+
+/* Mark L1 table clusters used */
+qed_set_used_clusters(check, s-header.l1_table_offset,
+  s-header.table_size);
+
+for (i = 0; i  s-table_nelems; i++) {
+unsigned int num_invalid_l2;
+uint64_t offset = table-offsets[i];
+
+if (!offset) {
+continue;
+}
+
+/* Detect invalid L2 offset */
+if (!qed_check_table_offset(s, offset)) {
+/* Clear invalid offset */
+if (check-fix) {
+table-offsets[i] = 0;
+} else {
+check-result-corruptions++;
+}
+
+num_invalid_l1++;
+continue;
+}
+
+if (!qed_set_used_clusters(check, offset, s-header.table_size)) {
+continue; /* skip an invalid table */
+}
+
+ret = qed_read_l2_table_sync(s, check-request, offset);
+if (ret) {
+check-result-check_errors++;
+last_error = ret;
+continue;
+}
+
+num_invalid_l2 = qed_check_l2_table(check,
+check-request.l2_table-table);
+
+/* Write out fixed L2 table */
+if (num_invalid_l2  0  check-fix) {
+ret = qed_write_l2_table_sync(s, check-request, 0,
+  s-table_nelems, false);
+if (ret) {
+check-result-check_errors++;
+  

[Qemu-devel] [PATCH v6 0/5] qed: Add QEMU Enhanced Disk format

2010-12-06 Thread Stefan Hajnoczi
For a changelog against v5, see below.

QEMU Enhanced Disk format is a disk image format that forgoes features
found in qcow2 in favor of better levels of performance and data
integrity.  Due to its simpler on-disk layout, it is possible to safely
perform metadata updates more efficiently.

Installations, suspend-to-disk, and other allocation-heavy I/O workloads
will see increased performance due to fewer I/Os and syncs.  Workloads
that do not cause new clusters to be allocated will perform similar to
raw images due to in-memory metadata caching.

The format supports sparse disk images.  It does not rely on the host
filesystem holes feature, making it a good choice for sparse disk images
that need to be transferred over channels where holes are not supported.

Backing files are supported so only deltas against a base image can be
stored.  The base image may be smaller than the image file.

The file format is extensible so that additional features can be added
later with graceful compatibility handling.  A specification for the file
format is included in this patchset.

Internal snapshots are not supported.  This eliminates the need for
additional metadata to track copy-on-write clusters.

Compression and encryption are not supported.  They add complexity and can be
implemented at other layers in the stack (i.e. inside the guest or on the
host).  Encryption has been identified as a potential future extension and the
file format allows for this.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
The code is available from git:

http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/qed-v6

I have preserved distinct commits against v5 for easier reviewing here:

http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/qed-v6-presquash

v6:
 * Calculate correct offset before tracing
 * Fix 80 character lines
 * Replace qed_acb_build_qiov() with qemu_iovec_copy()
 * Remove table locking mechanism (v2) and use allocating write queue again
 * Trace qed_write_table_cb() flush state

v5:
 * Describe reserved offset bits in QED format spec
 * Backing filename must be stored within header clusters
 * Backing file clarifications in QED format spec
 * List autoclear_features in QED header struct in QED format spec
 * Return -EINVAL when header magic check fails
 * Allow bdrv_flush() to return errors

v4:
 * Use bdrv_*() instead of POSIX APIs to create an image file
 * Lift the non-zero image size restriction
 * Fix qed.c/qed.h style comments from Kevin

v3:
 * Flush before L2 update when a backing file is used
 * Use QED_F_BACKING_FORMAT_NO_PROBE instead of backing_fmt header field
 * Allow non-cluster sized images
 * Implement autoclear feature bits
 * Implement backing image smaller size - reads from backing image should zero 
beyond EOF
 * Preserve errno in qed_find_cluster_cb() - don't dumb down to 
QED_CLUSTER_ERROR
 * Use ffs() instead of get_bits_from_size()
 * Remove l2_cache argument to qed_unref_l2_cache_entry
 * Eliminate L2TableAllocFunc function pointer
 * Split qed_aio_write in-place and allocating code path to make code clearer
 * Document how L2 cache is used
 * Document qed_find_cluster()
 * Update QED specification
 * Fix COPYING.LIB LGPL license file references
 * Add copyright header to qed-check.c
 * Avoid the bytes_to_str()/cvtstr()/sztostr() dependency until Jes' strtosz() 
goes in

v2:
 * Add QED format specification to documentation
 * Use __builtin_ctzl() for get_bits_from_size()
 * Fine-grained table locking to allow concurrent allocating write requests
 * Fix qemu_free() instead of qemu_vfree() in qed_unref_l2_cache_entry()
 * Comment clean-ups

 Makefile.objs   |2 +
 block/qed-check.c   |  210 
 block/qed-cluster.c |  154 ++
 block/qed-gencb.c   |   32 ++
 block/qed-l2-cache.c|  173 ++
 block/qed-table.c   |  319 +++
 block/qed.c | 1349 +++
 block/qed.h |  301 +++
 block_int.h |1 +
 docs/specs/qed_spec.txt |  130 +
 trace-events|   21 +
 11 files changed, 2692 insertions(+), 0 deletions(-)




[Qemu-devel] [PATCH v5 4/7] Make error handling more consistent in img_create() and img_resize()

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

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 qemu-img.c |   18 --
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index aded72d..6b2b18b 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -314,13 +314,15 @@ static int img_create(int argc, char **argv)
 drv = bdrv_find_format(fmt);
 if (!drv) {
 error(Unknown file format '%s', fmt);
-return 1;
+ret = -1;
+goto out;
 }
 
 proto_drv = bdrv_find_protocol(filename);
 if (!proto_drv) {
 error(Unknown protocol '%s', filename);
-return 1;
+ret = -1;
+goto out;
 }
 
 create_options = append_option_parameters(create_options,
@@ -1432,7 +1434,7 @@ static int img_resize(int argc, char **argv)
 int c, ret, relative;
 const char *filename, *fmt, *size;
 int64_t n, total_size;
-BlockDriverState *bs;
+BlockDriverState *bs = NULL;
 QEMUOptionParameter *param;
 QEMUOptionParameter resize_options[] = {
 {
@@ -1483,14 +1485,16 @@ static int img_resize(int argc, char **argv)
 param = parse_option_parameters(, resize_options, NULL);
 if (set_option_parameter(param, BLOCK_OPT_SIZE, size)) {
 /* Error message already printed when size parsing fails */
-exit(1);
+ret = -1;
+goto out;
 }
 n = get_option_parameter(param, BLOCK_OPT_SIZE)-value.n;
 free_option_parameters(param);
 
 bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR);
 if (!bs) {
-return 1;
+ret = -1;
+goto out;
 }
 
 if (relative) {
@@ -1520,7 +1524,9 @@ static int img_resize(int argc, char **argv)
 break;
 }
 out:
-bdrv_delete(bs);
+if (bs) {
+bdrv_delete(bs);
+}
 if (ret) {
 return 1;
 }
-- 
1.7.3.2




[Qemu-devel] [PATCH v6 2/5] qed: Add QEMU Enhanced Disk image format

2010-12-06 Thread Stefan Hajnoczi
This patch introduces the qed on-disk layout and implements image
creation.  Later patches add read/write and other functionality.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 Makefile.objs |1 +
 block/qed.c   |  554 +
 block/qed.h   |  148 +++
 block_int.h   |1 +
 4 files changed, 704 insertions(+), 0 deletions(-)
 create mode 100644 block/qed.c
 create mode 100644 block/qed.h

diff --git a/Makefile.objs b/Makefile.objs
index 04625eb..f89ce19 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -20,6 +20,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
 block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o 
vvfat.o
 block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o
+block-nested-y += qed.o
 block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
 block-nested-$(CONFIG_WIN32) += raw-win32.o
 block-nested-$(CONFIG_POSIX) += raw-posix.o
diff --git a/block/qed.c b/block/qed.c
new file mode 100644
index 000..1436ac4
--- /dev/null
+++ b/block/qed.c
@@ -0,0 +1,554 @@
+/*
+ * QEMU Enhanced Disk Format
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Stefan Hajnoczi   stefa...@linux.vnet.ibm.com
+ *  Anthony Liguori   aligu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include qed.h
+
+static int bdrv_qed_probe(const uint8_t *buf, int buf_size,
+  const char *filename)
+{
+const QEDHeader *header = (const QEDHeader *)buf;
+
+if (buf_size  sizeof(*header)) {
+return 0;
+}
+if (le32_to_cpu(header-magic) != QED_MAGIC) {
+return 0;
+}
+return 100;
+}
+
+/**
+ * Check whether an image format is raw
+ *
+ * @fmt:Backing file format, may be NULL
+ */
+static bool qed_fmt_is_raw(const char *fmt)
+{
+return fmt  strcmp(fmt, raw) == 0;
+}
+
+static void qed_header_le_to_cpu(const QEDHeader *le, QEDHeader *cpu)
+{
+cpu-magic = le32_to_cpu(le-magic);
+cpu-cluster_size = le32_to_cpu(le-cluster_size);
+cpu-table_size = le32_to_cpu(le-table_size);
+cpu-header_size = le32_to_cpu(le-header_size);
+cpu-features = le64_to_cpu(le-features);
+cpu-compat_features = le64_to_cpu(le-compat_features);
+cpu-autoclear_features = le64_to_cpu(le-autoclear_features);
+cpu-l1_table_offset = le64_to_cpu(le-l1_table_offset);
+cpu-image_size = le64_to_cpu(le-image_size);
+cpu-backing_filename_offset = le32_to_cpu(le-backing_filename_offset);
+cpu-backing_filename_size = le32_to_cpu(le-backing_filename_size);
+}
+
+static void qed_header_cpu_to_le(const QEDHeader *cpu, QEDHeader *le)
+{
+le-magic = cpu_to_le32(cpu-magic);
+le-cluster_size = cpu_to_le32(cpu-cluster_size);
+le-table_size = cpu_to_le32(cpu-table_size);
+le-header_size = cpu_to_le32(cpu-header_size);
+le-features = cpu_to_le64(cpu-features);
+le-compat_features = cpu_to_le64(cpu-compat_features);
+le-autoclear_features = cpu_to_le64(cpu-autoclear_features);
+le-l1_table_offset = cpu_to_le64(cpu-l1_table_offset);
+le-image_size = cpu_to_le64(cpu-image_size);
+le-backing_filename_offset = cpu_to_le32(cpu-backing_filename_offset);
+le-backing_filename_size = cpu_to_le32(cpu-backing_filename_size);
+}
+
+static int qed_write_header_sync(BDRVQEDState *s)
+{
+QEDHeader le;
+int ret;
+
+qed_header_cpu_to_le(s-header, le);
+ret = bdrv_pwrite(s-bs-file, 0, le, sizeof(le));
+if (ret != sizeof(le)) {
+return ret;
+}
+return 0;
+}
+
+static uint64_t qed_max_image_size(uint32_t cluster_size, uint32_t table_size)
+{
+uint64_t table_entries;
+uint64_t l2_size;
+
+table_entries = (table_size * cluster_size) / sizeof(uint64_t);
+l2_size = table_entries * cluster_size;
+
+return l2_size * table_entries;
+}
+
+static bool qed_is_cluster_size_valid(uint32_t cluster_size)
+{
+if (cluster_size  QED_MIN_CLUSTER_SIZE ||
+cluster_size  QED_MAX_CLUSTER_SIZE) {
+return false;
+}
+if (cluster_size  (cluster_size - 1)) {
+return false; /* not power of 2 */
+}
+return true;
+}
+
+static bool qed_is_table_size_valid(uint32_t table_size)
+{
+if (table_size  QED_MIN_TABLE_SIZE ||
+table_size  QED_MAX_TABLE_SIZE) {
+return false;
+}
+if (table_size  (table_size - 1)) {
+return false; /* not power of 2 */
+}
+return true;
+}
+
+static bool qed_is_image_size_valid(uint64_t image_size, uint32_t cluster_size,
+uint32_t table_size)
+{
+if (image_size % BDRV_SECTOR_SIZE != 0) {
+return false; /* not multiple of sector size */
+}
+if (image_size  qed_max_image_size(cluster_size, table_size)) {
+return false; /* image is too large */
+}
+return true;
+}
+
+/**
+ * Read a 

[Qemu-devel] [PATCH v6 4/5] qed: Read/write support

2010-12-06 Thread Stefan Hajnoczi
This patch implements the read/write state machine.  Operations are
fully asynchronous and multiple operations may be active at any time.

Allocating writes lock tables to ensure metadata updates do not
interfere with each other.  If two allocating writes need to update the
same L2 table they will run sequentially.  If two allocating writes need
to update different L2 tables they will run in parallel.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 Makefile.objs |1 +
 block/qed.c   |  628 -
 block/qed.h   |   26 +++
 trace-events  |   10 +
 4 files changed, 663 insertions(+), 2 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 55a046f..5b683e0 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -21,6 +21,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o 
vvfat.o
 block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o
 block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
+block-nested-y += qed-check.o
 block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
 block-nested-$(CONFIG_WIN32) += raw-win32.o
 block-nested-$(CONFIG_POSIX) += raw-posix.o
diff --git a/block/qed.c b/block/qed.c
index cd1bead..8e65d18 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -12,8 +12,26 @@
  *
  */
 
+#include trace.h
 #include qed.h
 
+static void qed_aio_cancel(BlockDriverAIOCB *blockacb)
+{
+QEDAIOCB *acb = (QEDAIOCB *)blockacb;
+bool finished = false;
+
+/* Wait for the request to finish */
+acb-finished = finished;
+while (!finished) {
+qemu_aio_wait();
+}
+}
+
+static AIOPool qed_aio_pool = {
+.aiocb_size = sizeof(QEDAIOCB),
+.cancel = qed_aio_cancel,
+};
+
 static int bdrv_qed_probe(const uint8_t *buf, int buf_size,
   const char *filename)
 {
@@ -155,6 +173,24 @@ static int qed_read_string(BlockDriverState *file, 
uint64_t offset, size_t n,
 return 0;
 }
 
+/**
+ * Allocate new clusters
+ *
+ * @s:  QED state
+ * @n:  Number of contiguous clusters to allocate
+ * @ret:Offset of first allocated cluster
+ *
+ * This function only produces the offset where the new clusters should be
+ * written.  It updates BDRVQEDState but does not make any changes to the image
+ * file.
+ */
+static uint64_t qed_alloc_clusters(BDRVQEDState *s, unsigned int n)
+{
+uint64_t offset = s-file_size;
+s-file_size += n * s-header.cluster_size;
+return offset;
+}
+
 QEDTable *qed_alloc_table(BDRVQEDState *s)
 {
 /* Honor O_DIRECT memory alignment requirements */
@@ -162,6 +198,23 @@ QEDTable *qed_alloc_table(BDRVQEDState *s)
s-header.cluster_size * s-header.table_size);
 }
 
+/**
+ * Allocate a new zeroed L2 table
+ */
+static CachedL2Table *qed_new_l2_table(BDRVQEDState *s)
+{
+CachedL2Table *l2_table = qed_alloc_l2_cache_entry(s-l2_cache);
+
+l2_table-table = qed_alloc_table(s);
+l2_table-offset = qed_alloc_clusters(s, s-header.table_size);
+
+memset(l2_table-table-offsets, 0,
+   s-header.cluster_size * s-header.table_size);
+return l2_table;
+}
+
+static void qed_aio_next_io(void *opaque, int ret);
+
 static int bdrv_qed_open(BlockDriverState *bs, int flags)
 {
 BDRVQEDState *s = bs-opaque;
@@ -170,6 +223,7 @@ static int bdrv_qed_open(BlockDriverState *bs, int flags)
 int ret;
 
 s-bs = bs;
+QSIMPLEQ_INIT(s-allocating_write_reqs);
 
 ret = bdrv_pread(bs-file, 0, le_header, sizeof(le_header));
 if (ret  0) {
@@ -431,13 +485,583 @@ static int bdrv_qed_make_empty(BlockDriverState *bs)
 return -ENOTSUP;
 }
 
+static BDRVQEDState *acb_to_s(QEDAIOCB *acb)
+{
+return acb-common.bs-opaque;
+}
+
+/**
+ * Read from the backing file or zero-fill if no backing file
+ *
+ * @s:  QED state
+ * @pos:Byte position in device
+ * @qiov:   Destination I/O vector
+ * @cb: Completion function
+ * @opaque: User data for completion function
+ *
+ * This function reads qiov-size bytes starting at pos from the backing file.
+ * If there is no backing file then zeroes are read.
+ */
+static void qed_read_backing_file(BDRVQEDState *s, uint64_t pos,
+  QEMUIOVector *qiov,
+  BlockDriverCompletionFunc *cb, void *opaque)
+{
+BlockDriverAIOCB *aiocb;
+uint64_t backing_length = 0;
+size_t size;
+
+/* If there is a backing file, get its length.  Treat the absence of a
+ * backing file like a zero length backing file.
+ */
+if (s-bs-backing_hd) {
+int64_t l = bdrv_getlength(s-bs-backing_hd);
+if (l  0) {
+cb(opaque, l);
+return;
+}
+backing_length = l;
+}
+
+/* Zero all sectors if reading beyond the end of the backing file */
+if (pos = backing_length ||

[Qemu-devel] [PATCH v6 3/5] qed: Table, L2 cache, and cluster functions

2010-12-06 Thread Stefan Hajnoczi
This patch adds code to look up data cluster offsets in the image via
the L1/L2 tables.  The L2 tables are writethrough cached in memory for
performance (each read/write requires a lookup so it is essential to
cache the tables).

With cluster lookup code in place it is possible to implement
bdrv_is_allocated() to query the number of contiguous
allocated/unallocated clusters.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 Makefile.objs|2 +-
 block/qed-cluster.c  |  154 
 block/qed-gencb.c|   32 +
 block/qed-l2-cache.c |  173 +++
 block/qed-table.c|  319 ++
 block/qed.c  |   54 +-
 block/qed.h  |  123 +++
 trace-events |   11 ++
 8 files changed, 866 insertions(+), 2 deletions(-)
 create mode 100644 block/qed-cluster.c
 create mode 100644 block/qed-gencb.c
 create mode 100644 block/qed-l2-cache.c
 create mode 100644 block/qed-table.c

diff --git a/Makefile.objs b/Makefile.objs
index f89ce19..55a046f 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -20,7 +20,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
 block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o 
vvfat.o
 block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o
-block-nested-y += qed.o
+block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
 block-nested-$(CONFIG_WIN32) += raw-win32.o
 block-nested-$(CONFIG_POSIX) += raw-posix.o
diff --git a/block/qed-cluster.c b/block/qed-cluster.c
new file mode 100644
index 000..0ec864b
--- /dev/null
+++ b/block/qed-cluster.c
@@ -0,0 +1,154 @@
+/*
+ * QEMU Enhanced Disk Format Cluster functions
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Stefan Hajnoczi   stefa...@linux.vnet.ibm.com
+ *  Anthony Liguori   aligu...@us.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include qed.h
+
+/**
+ * Count the number of contiguous data clusters
+ *
+ * @s:  QED state
+ * @table:  L2 table
+ * @index:  First cluster index
+ * @n:  Maximum number of clusters
+ * @offset: Set to first cluster offset
+ *
+ * This function scans tables for contiguous allocated or free clusters.
+ */
+static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s,
+  QEDTable *table,
+  unsigned int index,
+  unsigned int n,
+  uint64_t *offset)
+{
+unsigned int end = MIN(index + n, s-table_nelems);
+uint64_t last = table-offsets[index];
+unsigned int i;
+
+*offset = last;
+
+for (i = index + 1; i  end; i++) {
+if (last == 0) {
+/* Counting free clusters */
+if (table-offsets[i] != 0) {
+break;
+}
+} else {
+/* Counting allocated clusters */
+if (table-offsets[i] != last + s-header.cluster_size) {
+break;
+}
+last = table-offsets[i];
+}
+}
+return i - index;
+}
+
+typedef struct {
+BDRVQEDState *s;
+uint64_t pos;
+size_t len;
+
+QEDRequest *request;
+
+/* User callback */
+QEDFindClusterFunc *cb;
+void *opaque;
+} QEDFindClusterCB;
+
+static void qed_find_cluster_cb(void *opaque, int ret)
+{
+QEDFindClusterCB *find_cluster_cb = opaque;
+BDRVQEDState *s = find_cluster_cb-s;
+QEDRequest *request = find_cluster_cb-request;
+uint64_t offset = 0;
+size_t len = 0;
+unsigned int index;
+unsigned int n;
+
+if (ret) {
+goto out;
+}
+
+index = qed_l2_index(s, find_cluster_cb-pos);
+n = qed_bytes_to_clusters(s,
+  qed_offset_into_cluster(s, find_cluster_cb-pos) 
+
+  find_cluster_cb-len);
+n = qed_count_contiguous_clusters(s, request-l2_table-table,
+  index, n, offset);
+
+ret = offset ? QED_CLUSTER_FOUND : QED_CLUSTER_L2;
+len = MIN(find_cluster_cb-len, n * s-header.cluster_size -
+  qed_offset_into_cluster(s, find_cluster_cb-pos));
+
+if (offset  !qed_check_cluster_offset(s, offset)) {
+ret = -EINVAL;
+}
+
+out:
+find_cluster_cb-cb(find_cluster_cb-opaque, ret, offset, len);
+qemu_free(find_cluster_cb);
+}
+
+/**
+ * Find the offset of a data cluster
+ *
+ * @s:  QED state
+ * @request:L2 cache entry
+ * @pos:Byte position in device
+ * @len:Number of bytes
+ * @cb: Completion function
+ * @opaque: User data for completion function
+ *
+ * This 

Re: [Qemu-devel] [PATCH 01/14] ./block/iscsi/init.c

2010-12-06 Thread Kevin Wolf
Am 03.12.2010 22:23, schrieb ronnie sahlberg:
 Thankyou.
 
 On Sat, Dec 4, 2010 at 7:32 AM, Stefan Hajnoczi stefa...@gmail.com wrote:

 You want the library to be GPL, not LGPL?
 
 I have changed it to LGPLv3 for next submission.

Please use LGPL 2.1 or later. IIRC, qemu has some parts that are GPL 2
only, and LGPL 3 isn't compatible with that.

Kevin



[Qemu-devel] Re: [PATCH v5 4/7] Make error handling more consistent in img_create() and img_resize()

2010-12-06 Thread Kevin Wolf
Am 06.12.2010 17:08, schrieb jes.soren...@redhat.com:
 From: Jes Sorensen jes.soren...@redhat.com
 
 Signed-off-by: Jes Sorensen jes.soren...@redhat.com

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [PATCH 1/8] ARM: Fix decoding of VFP forms of VCVT between float and int/fixed

2010-12-06 Thread Nathan Froyd
On Thu, Nov 11, 2010 at 06:23:55PM +, Peter Maydell wrote:
 Correct the decoding of source and destination registers
 for the VFP forms of the VCVT instructions which convert
 between floating point and integer or fixed-point.
 
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org

Reviewed-by: Nathan Froyd froy...@codesourcery.com

I don't know how good QEMU's framework is, but it'd be nice to have your
testing code checked into the tree, in case anybody decides to do major
surgery on the ARM backend.

-Nathan



Re: [Qemu-devel] [PATCH 1/8] ARM: Fix decoding of VFP forms of VCVT between float and int/fixed

2010-12-06 Thread Peter Maydell
On 6 December 2010 16:30, Nathan Froyd froy...@codesourcery.com wrote:
 On Thu, Nov 11, 2010 at 06:23:55PM +, Peter Maydell wrote:
 Correct the decoding of source and destination registers
 for the VFP forms of the VCVT instructions which convert
 between floating point and integer or fixed-point.

 Signed-off-by: Peter Maydell peter.mayd...@linaro.org

 Reviewed-by: Nathan Froyd froy...@codesourcery.com

Thanks. I'll resend this set with the softfloat-related comments addressed
for the two patches that affects (and the remaining unchanged patches
with your Reviewed-by: tag on them).

 I don't know how good QEMU's framework is, but it'd be nice to have your
 testing code checked into the tree, in case anybody decides to do major
 surgery on the ARM backend.

I'm not sure how well it would fit into being committed to qemu (yet):
it works as a program where you run half of it on real ARM hardware
and the other half under qemu (or valgrind) and it compares register
results after executing instructions by looking at the sigcontext struct
in a signal handler. Plus there's a perl script to generate random
instruction set sequences to feed the test program. It could be made
more automated and independent of having a reference bit of hardware
but I haven't got round to that yet. (Also since it has utility outside of
just testing qemu I'm not sure if it really belongs in the qemu repo.)

-- PMM



Re: [Qemu-devel] [PATCH 1/8] ARM: Fix decoding of VFP forms of VCVT between float and int/fixed

2010-12-06 Thread Nathan Froyd
On Mon, Dec 06, 2010 at 04:48:25PM +, Peter Maydell wrote:
 I'm not sure how well it would fit into being committed to qemu (yet):
 it works as a program where you run half of it on real ARM hardware
 and the other half under qemu (or valgrind) and it compares register
 results after executing instructions by looking at the sigcontext struct
 in a signal handler. Plus there's a perl script to generate random
 instruction set sequences to feed the test program. It could be made
 more automated and independent of having a reference bit of hardware
 but I haven't got round to that yet. (Also since it has utility outside of
 just testing qemu I'm not sure if it really belongs in the qemu repo.)

That does sound a little heavyweight.  Scripting gdb is also a possibility.

FWIW--and this is not particularly conducive to random insn
sequences--the approach taken when doing the AltiVec bits was to have
code that looked like:

  for each insn:
 for a suitable set of inputs:
setup interesting registers (status control registers etc.)
load inputs into registers
execute
record interesting post conditions in file.out

You'd get an output file from real hardware and an output file from the
simulator and then compare them, fixing differences as you go.  The
actual code included bits to compare the files as well as doing the
generation.

The output files can be somewhat large, but I'm sure clever engineering
could be applied to make them smaller.

Of course, the *real* problems are in undefined-behavior land. :)

-Nathan



[Qemu-devel] [PATCH 04/10] softfloat: Add float*_is_any_nan() functions

2010-12-06 Thread Peter Maydell
Add float*_is_any_nan() functions which return true if the argument
is a NaN of any kind (quiet or signalling).

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
 fpu/softfloat.h |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/fpu/softfloat.h b/fpu/softfloat.h
index 9528825..9bece80 100644
--- a/fpu/softfloat.h
+++ b/fpu/softfloat.h
@@ -314,6 +314,11 @@ INLINE int float32_is_zero(float32 a)
 return (float32_val(a)  0x7fff) == 0;
 }
 
+INLINE int float32_is_any_nan(float32 a)
+{
+return ((float32_val(a)  ~(1  31))  0x7f80UL);
+}
+
 #define float32_zero make_float32(0)
 #define float32_one make_float32(0x3f80)
 #define float32_ln2 make_float32(0x3f317218)
@@ -386,6 +391,11 @@ INLINE int float64_is_zero(float64 a)
 return (float64_val(a)  0x7fffLL) == 0;
 }
 
+INLINE int float64_is_any_nan(float64 a)
+{
+return ((float64_val(a)  ~(1ULL  63))  0x7ff0ULL);
+}
+
 #define float64_zero make_float64(0)
 #define float64_one make_float64(0x3ff0LL)
 #define float64_ln2 make_float64(0x3fe62e42fefa39efLL)
-- 
1.6.3.3




[Qemu-devel] [PATCH V2 00/10] ARM: fix VCVT instructions

2010-12-06 Thread Peter Maydell
This patch series corrects a number of errors in the decoding and
implementation of various forms of the ARM VCVT instruction. The
resulting qemu has been tested by execution of 100,000 random
variants of these instruction patterns with register values
cross-checked against the results given by Cortex-A8 hardware.

Thanks to Johan Bengtsson for posting the initial VCVT related
patch which prompted me to do some more testing in this area.

This is V2 of this patchset which addresses Nathan Froyd's
suggestion that we should be doing all the bit-twiddling
in softfloat rather than in the ARM specific files. The
old patch 4/8 is now 4/10 and 5/10, and the old 5/8 is
now 6/10 and 7/10; all other patches are unchanged.

In patch 4/10 I've left the '_any_' in the function name to
avoid a clash/dependency on the proposed 'rename _is_nan to
_is_quiet_nan' patch.


Peter Maydell (10):
  ARM: Fix decoding of VFP forms of VCVT between float and int/fixed
  ARM: Fix decoding of Neon forms of VCVT between float and fixed point
  ARM: Fix sense of to_integer bit in Neon VCVT float/int conversion
  softfloat: Add float*_is_any_nan() functions
  ARM: Return correct result for float-to-integer conversion of NaN
  softfloat: Add float*_maybe_silence_nan() functions
  ARM: Return correct result for single-double conversion of NaN
  ARM: Ignore top 16 bits when doing VCVT from 16 bit fixed point
  softfloat: Add float/double to 16 bit integer conversion functions
  ARM: Implement VCVT to 16 bit integer using new softfloat routines

 fpu/softfloat-specialize.h |   38 
 fpu/softfloat.c|  136 
 fpu/softfloat.h|   16 +
 target-arm/helper.c|   43 +-
 target-arm/translate.c |   35 +++
 5 files changed, 251 insertions(+), 17 deletions(-)




[Qemu-devel] [PATCH 02/10] ARM: Fix decoding of Neon forms of VCVT between float and fixed point

2010-12-06 Thread Peter Maydell
Fix errors in the decoding of the Neon forms of fixed-point VCVT:
 * fixed-point VCVT is op 14 and 15, not 15 and 16
 * the fbits immediate field was being misinterpreted
 * the sense of the to_fixed bit was inverted

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Reviewed-by: Nathan Froyd froy...@codesourcery.com
---
 target-arm/translate.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 0c8439a..696abf6 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -4850,11 +4850,15 @@ static int disas_neon_data_insn(CPUState * env, 
DisasContext *s, uint32_t insn)
 }
 neon_store_reg64(cpu_V0, rd + pass);
 }
-} else if (op == 15 || op == 16) {
+} else if (op = 14) {
 /* VCVT fixed-point.  */
+/* We have already masked out the must-be-1 top bit of imm6,
+ * hence this 32-shift where the ARM ARM has 64-imm6.
+ */
+shift = 32 - shift;
 for (pass = 0; pass  (q ? 4 : 2); pass++) {
 tcg_gen_ld_f32(cpu_F0s, cpu_env, neon_reg_offset(rm, 
pass));
-if (op  1) {
+if (!(op  1)) {
 if (u)
 gen_vfp_ulto(0, shift);
 else
-- 
1.6.3.3




  1   2   >