Re: [Qemu-devel] [PATCH 3/3] megasas: LSI Megaraid SAS emulation

2011-07-03 Thread Michael S. Tsirkin
On Fri, Jul 01, 2011 at 11:16:03AM +0200, Alexander Graf wrote:
> 
> On 01.07.2011, at 09:42, Hannes Reinecke wrote:
> 
> > This patch adds an emulation for the LSI Megaraid SAS 8708EM2 HBA.
> > 
> > Signed-off-by: Hannes Reinecke 
> > ---
> > Makefile.objs   |1 +
> > default-configs/pci.mak |1 +
> > hw/megasas.c| 1923 
> > +++
> > hw/mfi.h| 1197 +
> > hw/pci_ids.h|3 +-
> > 5 files changed, 3124 insertions(+), 1 deletions(-)
> > create mode 100644 hw/megasas.c
> > create mode 100644 hw/mfi.h
> > 
> > diff --git a/Makefile.objs b/Makefile.objs
> > index cea15e4..6f5d113 100644
> > --- a/Makefile.objs
> > +++ b/Makefile.objs
> > @@ -258,6 +258,7 @@ hw-obj-$(CONFIG_AHCI) += ide/ich.o
> > 
> > # SCSI layer
> > hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
> > +hw-obj-$(CONFIG_MEGASAS_SCSI_PCI) += megasas.o
> > hw-obj-$(CONFIG_ESP) += esp.o
> > 
> > hw-obj-y += dma-helpers.o sysbus.o isa-bus.o
> > diff --git a/default-configs/pci.mak b/default-configs/pci.mak
> > index 22bd350..fabb56c 100644
> > --- a/default-configs/pci.mak
> > +++ b/default-configs/pci.mak
> > @@ -9,6 +9,7 @@ CONFIG_EEPRO100_PCI=y
> > CONFIG_PCNET_PCI=y
> > CONFIG_PCNET_COMMON=y
> > CONFIG_LSI_SCSI_PCI=y
> > +CONFIG_MEGASAS_SCSI_PCI=y
> > CONFIG_RTL8139_PCI=y
> > CONFIG_E1000_PCI=y
> > CONFIG_IDE_CORE=y
> > diff --git a/hw/megasas.c b/hw/megasas.c
> > new file mode 100644
> > index 000..75f9be3
> > --- /dev/null
> > +++ b/hw/megasas.c
> > @@ -0,0 +1,1923 @@
> > +/*
> > + * QEMU MegaRAID SAS 8708EM2 Host Bus Adapter emulation
> > + *
> > + * Copyright (c) 2009-2011 Hannes Reinecke, SUSE Labs
> > + *
> > + * This code is licenced under the LGPL.
> 
> Please take a look at the license header of other LGPL code and just copy it 
> :).
> 
> > + */
> > +
> > +#include 
> > +#include 
> 
> Are you sure you need to manually include those?
> 
> > +
> > +#include "hw.h"
> > +#include "pci.h"
> > +#include "dma.h"
> > +#include "iov.h"
> > +#include "scsi.h"
> > +#include "scsi-defs.h"
> > +#include "block_int.h"
> > +#ifdef __linux__
> > +# include 
> 
> Is this really necessary? Device code shouldn't be host dependent IMHO. I 
> also haven't found any user of this in the actual code, so it might be as 
> easy as merely removing the include :).
> 
> > +#endif
> > +
> > +#include "mfi.h"
> > +
> > +#define DEBUG_MEGASAS
> > +#undef DEBUG_MEGASAS_REG
> > +#undef DEBUG_MEGASAS_QUEUE
> > +#undef DEBUG_MEGASAS_MFI
> > +#undef DEBUG_MEGASAS_IO
> > +#undef DEBUG_MEGASAS_DCMD
> > +
> > +#ifdef DEBUG_MEGASAS
> > +#define DPRINTF(fmt, ...) \
> > +do { printf("megasas: " fmt , ## __VA_ARGS__); } while (0)
> > +#define BADF(fmt, ...) \
> > +do { fprintf(stderr, "megasas: error: " fmt , ## __VA_ARGS__); exit(1);} 
> > while (0)
> > +#ifdef DEBUG_MEGASAS_REG
> > +#define DPRINTF_REG DPRINTF
> > +#else
> > +#define DPRINTF_REG(fmt, ...) do {} while(0)
> > +#endif
> > +#ifdef DEBUG_MEGASAS_QUEUE
> > +#define DPRINTF_QUEUE DPRINTF
> > +#else
> > +#define DPRINTF_QUEUE(fmt, ...) do {} while(0)
> > +#endif
> > +#ifdef DEBUG_MEGASAS_MFI
> > +#define DPRINTF_MFI DPRINTF
> > +#else
> > +#define DPRINTF_MFI(fmt, ...) do {} while(0)
> > +#endif
> > +#ifdef DEBUG_MEGASAS_IO
> > +#define DPRINTF_IO DPRINTF
> > +#else
> > +#define DPRINTF_IO(fmt, ...) do {} while(0)
> > +#endif
> > +#ifdef DEBUG_MEGASAS_DCMD
> > +#define DPRINTF_DCMD DPRINTF
> > +#else
> > +#define DPRINTF_DCMD(fmt, ...) do {} while(0)
> > +#endif
> > +#else
> > +#define DPRINTF(fmt, ...) do {} while(0)
> > +#define DPRINTF_REG DPRINTF
> > +#define DPRINTF_QUEUE DPRINTF
> > +#define DPRINTF_MFI DPRINTF
> > +#define DPRINTF_IO DPRINTF
> > +#define DPRINTF_DCMD DPRINTF
> > +#define BADF(fmt, ...) \
> > +do { fprintf(stderr, "megasas: error: " fmt , ## __VA_ARGS__);} while (0)
> > +#endif
> > +
> > +/* Static definitions */
> > +#define MEGASAS_VERSION "1.20"
> > +#define MEGASAS_MAX_FRAMES 2048 /* Firmware limit at 65535 */
> > +#define MEGASAS_DEFAULT_FRAMES 1000 /* Windows requires this */
> > +#define MEGASAS_MAX_SGE 256 /* Firmware limit */
> > +#define MEGASAS_DEFAULT_SGE 80
> > +#define MEGASAS_MAX_SECTORS 0x  /* No real limit */
> > +#define MEGASAS_MAX_ARRAYS 128
> > +
> > +const char *mfi_frame_desc[] = {
> > +"MFI init", "LD Read", "LD Write", "LD SCSI", "PD SCSI",
> > +"MFI Doorbell", "MFI Abort", "MFI SMP", "MFI Stop"};
> > +
> > +struct megasas_cmd_t {
> > +int index;
> > +int context;
> > +int count;
> > +
> > +target_phys_addr_t pa;
> > +target_phys_addr_t pa_size;
> > +union mfi_frame *frame;
> > +SCSIRequest *req;
> > +struct iovec *iov;
> > +void *iov_buf;
> > +long iov_cnt;
> > +long iov_size;
> > +long iov_offset;
> 
> Why would anything be a long? It's either target_ulong or uintXX_t for device 
> code usually :).
> 
> > +SCSIDevice *sdev;
> > +struct megasas_state

Re: [Qemu-devel] [PATCHv2] Add compat eventfd header

2011-07-03 Thread Michael S. Tsirkin
On Fri, Jul 01, 2011 at 11:05:28PM +0300, Blue Swirl wrote:
> On Thu, Jun 30, 2011 at 6:57 PM, Michael S. Tsirkin  wrote:
> > Support build on rhel 5.X where we have syscall for eventfd but not
> > userspace wrapper.
> >
> > (cherry-picked from commit 9e3269181e9bc56feb43bcd4e8ce0b82cd543e65
> >  in qemu-kvm.git).
> >
> > Signed-off-by: Michael S. Tsirkin 
> > ---
> >
> > Changes from v1:
> >  checkpatch fix
> >  address comments by agraf
> >  verify we are on linux
> >
> >  compat/sys/eventfd.h |   20 
> >  configure            |    6 --
> >  2 files changed, 24 insertions(+), 2 deletions(-)
> >  create mode 100644 compat/sys/eventfd.h
> >
> > diff --git a/compat/sys/eventfd.h b/compat/sys/eventfd.h
> > new file mode 100644
> > index 000..1801a5f
> > --- /dev/null
> > +++ b/compat/sys/eventfd.h
> 
> Since we have linux-headers directory now, the directory should be
> compat-headers. I'd also add 'linux' directory below that to avoid
> collisions, so the full path would be
> compat-headers/linux/sys/eventfd.h.
> 

I'll make it compat-headers/sys/eventfd.h.

Actually this header is useful for non-linux as well:
CONFIG_EVENTFD is not defined there which in theory
makes it possible to include sys/eventfd.h
without ifdefs.

> > @@ -0,0 +1,20 @@
> > +#ifndef _COMPAT_SYS_EVENTFD
> > +#define _COMPAT_SYS_EVENTFD
> > +
> > +#ifdef CONFIG_EVENTFD
> > +
> > +#ifndef __linux__
> > +#error __linux__ is not defined: eventfd is only supported on linux
> > +#endif
> 
> With the linux directory, this check wouldn't be needed. It's not
> incorrect and we could add more specific checks later (for example if
> SYS_eventfd is not defined).

Yes, it's not incorrect because it is nested within CONFIG_EVENTFD.
If CONFIG_EVENTFD is set and SYS_eventfd is not defined then
there's a bug in the configure script.


> > +
> > +#include 
> > +#include 
> > +
> > +static inline int eventfd(int count, int flags)
> > +{
> > +    return syscall(SYS_eventfd, count, flags);
> > +}
> > +
> > +#endif
> > +
> > +#endif
> > diff --git a/configure b/configure
> > index 856b41e..6f7dd74 100755
> > --- a/configure
> > +++ b/configure
> > @@ -822,7 +822,6 @@ esac
> >
> >  [ -z "$guest_base" ] && guest_base="$host_guest_base"
> >
> > -
> >  default_target_list=""
> >
> >  # these targets are portable
> > @@ -891,6 +890,9 @@ sparc64-bsd-user \
> >  "
> >  fi
> >
> > +#compat headers
> > +QEMU_CFLAGS="$QEMU_CFLAGS -idirafter $source_path/compat"
> 
> Please use $source_path/compat-headers/$targetos/.

I think it's best to keep it simple. When we have many
compat headers we will see how to split them best.
If most of the code turns out to be common we will want to avoid
duplicating it.

> > +
> >  if test x"$show_help" = x"yes" ; then
> >  cat << EOF
> >
> > @@ -2122,7 +2124,7 @@ int main(void)
> >     return 0;
> >  }
> >  EOF
> > -if compile_prog "" "" ; then
> > +if compile_prog "-DCONFIG_EVENTFD" "" ; then
> >   eventfd=yes
> >  fi
> >
> > --
> > 1.7.5.53.gc233e
> >



[Qemu-devel] [PATCH] Fix unassigned memory access handling

2011-07-03 Thread Blue Swirl
cea5f9a28faa528b6b1b117c9ab2d8828f473fef exposed bugs in unassigned memory
access handling. Fix them by always passing CPUState to the handlers.

Reported-by: Hervé Poussineau 
Signed-off-by: Blue Swirl 
---
 exec-all.h|2 +-
 exec.c|   12 ++--
 target-alpha/cpu.h|5 +++--
 target-alpha/op_helper.c  |   10 --
 target-microblaze/cpu.h   |4 ++--
 target-microblaze/op_helper.c |   14 --
 target-mips/cpu.h |4 ++--
 target-mips/op_helper.c   |   10 --
 target-sparc/cpu.h|4 ++--
 target-sparc/op_helper.c  |   31 ---
 10 files changed, 60 insertions(+), 36 deletions(-)

diff --git a/exec-all.h b/exec-all.h
index 21a69d6..c24518e 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -327,7 +327,7 @@ static inline tb_page_addr_t
get_page_addr_code(CPUState *env1, target_ulong add
 pd = env1->tlb_table[mmu_idx][page_index].addr_code & ~TARGET_PAGE_MASK;
 if (pd > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) {
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SPARC)
-do_unassigned_access(addr, 0, 1, 0, 4);
+cpu_unassigned_access(env1, addr, 0, 1, 0, 4);
 #else
 cpu_abort(env1, "Trying to execute code outside RAM or ROM at
0x" TARGET_FMT_lx "\n", addr);
 #endif
diff --git a/exec.c b/exec.c
index 4c45299..4d9d92b 100644
--- a/exec.c
+++ b/exec.c
@@ -3236,7 +3236,7 @@ static uint32_t unassigned_mem_readb(void
*opaque, target_phys_addr_t addr)
 printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
 #endif
 #if defined(TARGET_ALPHA) || defined(TARGET_SPARC) ||
defined(TARGET_MICROBLAZE)
-do_unassigned_access(addr, 0, 0, 0, 1);
+cpu_unassigned_access(cpu_single_env, addr, 0, 0, 0, 1);
 #endif
 return 0;
 }
@@ -3247,7 +3247,7 @@ static uint32_t unassigned_mem_readw(void
*opaque, target_phys_addr_t addr)
 printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
 #endif
 #if defined(TARGET_ALPHA) || defined(TARGET_SPARC) ||
defined(TARGET_MICROBLAZE)
-do_unassigned_access(addr, 0, 0, 0, 2);
+cpu_unassigned_access(cpu_single_env, addr, 0, 0, 0, 2);
 #endif
 return 0;
 }
@@ -3258,7 +3258,7 @@ static uint32_t unassigned_mem_readl(void
*opaque, target_phys_addr_t addr)
 printf("Unassigned mem read " TARGET_FMT_plx "\n", addr);
 #endif
 #if defined(TARGET_ALPHA) || defined(TARGET_SPARC) ||
defined(TARGET_MICROBLAZE)
-do_unassigned_access(addr, 0, 0, 0, 4);
+cpu_unassigned_access(cpu_single_env, addr, 0, 0, 0, 4);
 #endif
 return 0;
 }
@@ -3269,7 +3269,7 @@ static void unassigned_mem_writeb(void *opaque,
target_phys_addr_t addr, uint32_
 printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
 #endif
 #if defined(TARGET_ALPHA) || defined(TARGET_SPARC) ||
defined(TARGET_MICROBLAZE)
-do_unassigned_access(addr, 1, 0, 0, 1);
+cpu_unassigned_access(cpu_single_env, addr, 1, 0, 0, 1);
 #endif
 }

@@ -3279,7 +3279,7 @@ static void unassigned_mem_writew(void *opaque,
target_phys_addr_t addr, uint32_
 printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
 #endif
 #if defined(TARGET_ALPHA) || defined(TARGET_SPARC) ||
defined(TARGET_MICROBLAZE)
-do_unassigned_access(addr, 1, 0, 0, 2);
+cpu_unassigned_access(cpu_single_env, addr, 1, 0, 0, 2);
 #endif
 }

@@ -3289,7 +3289,7 @@ static void unassigned_mem_writel(void *opaque,
target_phys_addr_t addr, uint32_
 printf("Unassigned mem write " TARGET_FMT_plx " = 0x%x\n", addr, val);
 #endif
 #if defined(TARGET_ALPHA) || defined(TARGET_SPARC) ||
defined(TARGET_MICROBLAZE)
-do_unassigned_access(addr, 1, 0, 0, 4);
+cpu_unassigned_access(cpu_single_env, addr, 1, 0, 0, 4);
 #endif
 }

diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index 411bd55..ccdcd1b 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -436,8 +436,9 @@ uint64_t cpu_alpha_load_fpcr (CPUState *env);
 void cpu_alpha_store_fpcr (CPUState *env, uint64_t val);
 #ifndef CONFIG_USER_ONLY
 void swap_shadow_regs(CPUState *env);
-extern QEMU_NORETURN void do_unassigned_access(target_phys_addr_t addr,
-   int, int, int, int);
+QEMU_NORETURN void cpu_unassigned_access(CPUState *env1,
+ target_phys_addr_t addr, int is_write,
+ int is_exec, int unused, int size);
 #endif

 /* Bits in TB->FLAGS that control how translation is processed.  */
diff --git a/target-alpha/op_helper.c b/target-alpha/op_helper.c
index 51d1bd7..90f3c75 100644
--- a/target-alpha/op_helper.c
+++ b/target-alpha/op_helper.c
@@ -1301,12 +1301,18 @@ static void QEMU_NORETURN
do_unaligned_access(target_ulong addr, int is_write,
 helper_excp(EXCP_UNALIGN, 0);
 }

-void QEMU_NORETURN do_unassigned_access(target_phys_addr_t addr, int is_write,
-int is_exec, int unused, int size)
+void Q

Re: [Qemu-devel] SPARC64 support on FreeBSD, has it improved as of yet?

2011-07-03 Thread Super Bisquit
On Fri, Jul 1, 2011 at 4:21 PM, Blue Swirl  wrote:

> On Fri, Jul 1, 2011 at 7:03 PM, Super Bisquit 
> wrote:
> >
> >
> > On Wed, Jun 29, 2011 at 9:46 PM, Super Bisquit 
> > wrote:
> >>
> >>
> >> On Wed, Jun 29, 2011 at 1:10 AM, Bob Breuer  wrote:
> >>>
> >>> Super Bisquit wrote:
> >>> >
> >>> ...
> >>> >
> >>> > It builds, doesn't run. More like it runs and hangs.
> >>> >
> >>> > $ qemu-system-sparc -cpu LEON3 -hda test.img -cdrom
> >>> > Downloads/debian-6.0.2.1-sparc-businesscard.iso -m 256 -boot d
> >>> >
> >>>
> >>> That command line won't work.  OpenBIOS doesn't support LEON, and the
> >>> last version of Debian for sparc32 was 4.0.
> >>>
> >>> Try instead: "qemu-system-sparc -cdrom debian-40r9-sparc-netinst.iso
> >>> -boot d"
> >>>
> >>> You can get a cd image from
> >>> http://cdimage.debian.org/cdimage/archive/4.0_r9/sparc/iso-cd/ but the
> >>> installer may not be able to load packages from the internet because
> the
> >>> packages have been moved to archive.debian.org.
> >>>
> >>> Bob
> >>
> >> No response either from sparc32 or powerpc.  I386 also didn't work.
> >> What gdb commands should be ran on the core and what qemu monitor
> commands
> >> should I run?
> >>
> >
> > Here. When someone else on the list has FreeBSD installed to a
> > SPARC64/UltraSPARC device and has installed qemu to it, then it will be
> easy
> > to see what I am referring to constantly.
>
> More Sparc (or BSD) hackers are very much welcome.
>

Is there a way of verbose logging qemu while it runs? Maybe comparing the
FreeBSD output to the OpenBSD output will help.
Also, I can send you a list of the installed binaries, libraries, scripts,
and config files. Qemu on qemu has worked for me. This means that anyone
with a machine that has the CPU and memory to support a sparc64 guest could
install FreeBSD as a virtual sparc64 client/vm.


Re: [Qemu-devel] SPARC64 support on FreeBSD, has it improved as of yet?

2011-07-03 Thread Blue Swirl
On Sun, Jul 3, 2011 at 1:18 PM, Super Bisquit  wrote:
>
>
> On Fri, Jul 1, 2011 at 4:21 PM, Blue Swirl  wrote:
>>
>> On Fri, Jul 1, 2011 at 7:03 PM, Super Bisquit 
>> wrote:
>> >
>> >
>> > On Wed, Jun 29, 2011 at 9:46 PM, Super Bisquit 
>> > wrote:
>> >>
>> >>
>> >> On Wed, Jun 29, 2011 at 1:10 AM, Bob Breuer  wrote:
>> >>>
>> >>> Super Bisquit wrote:
>> >>> >
>> >>> ...
>> >>> >
>> >>> > It builds, doesn't run. More like it runs and hangs.
>> >>> >
>> >>> > $ qemu-system-sparc -cpu LEON3 -hda test.img -cdrom
>> >>> > Downloads/debian-6.0.2.1-sparc-businesscard.iso -m 256 -boot d
>> >>> >
>> >>>
>> >>> That command line won't work.  OpenBIOS doesn't support LEON, and the
>> >>> last version of Debian for sparc32 was 4.0.
>> >>>
>> >>> Try instead: "qemu-system-sparc -cdrom debian-40r9-sparc-netinst.iso
>> >>> -boot d"
>> >>>
>> >>> You can get a cd image from
>> >>> http://cdimage.debian.org/cdimage/archive/4.0_r9/sparc/iso-cd/ but the
>> >>> installer may not be able to load packages from the internet because
>> >>> the
>> >>> packages have been moved to archive.debian.org.
>> >>>
>> >>> Bob
>> >>
>> >> No response either from sparc32 or powerpc.  I386 also didn't work.
>> >> What gdb commands should be ran on the core and what qemu monitor
>> >> commands
>> >> should I run?
>> >>
>> >
>> > Here. When someone else on the list has FreeBSD installed to a
>> > SPARC64/UltraSPARC device and has installed qemu to it, then it will be
>> > easy
>> > to see what I am referring to constantly.
>>
>> More Sparc (or BSD) hackers are very much welcome.
>
> Is there a way of verbose logging qemu while it runs? Maybe comparing the
> FreeBSD output to the OpenBSD output will help.

-d in_asm,op,out_asm. For user emulator, -strace may also be useful
though the output may be buggy.

Comparing should work, but perhaps it's easier if you compared
FreeBSD/i386 host output to FreeBSD/Sparc64 output for the same
binaries.

> Also, I can send you a list of the installed binaries, libraries, scripts,
> and config files. Qemu on qemu has worked for me. This means that anyone
> with a machine that has the CPU and memory to support a sparc64 guest could
> install FreeBSD as a virtual sparc64 client/vm.

Unfortunately Sparc64 guest support is not complete enough for
installation of any OS.



Re: [Qemu-devel] [PATCH] tcg: Reload local variables after return from longjmp

2011-07-03 Thread Paolo Bonzini

On 07/02/2011 11:43 AM, Jan Kiszka wrote:

  static const char *pch;
+static char *saved_key;
  static jmp_buf expr_env;

  #define MD_TLONG 0
@@ -4254,8 +4255,11 @@ static const mon_cmd_t *monitor_parse_command(Monitor 
*mon,
  }
  typestr++;
  }
-if (get_expr(mon,&val,&p))
+saved_key = key;
+if (get_expr(mon,&val,&p)) {
+key = saved_key;
  goto fail;
+}


Please make saved_key a volatile local instead.

Paolo



Re: [Qemu-devel] [PATCH 3/3] megasas: LSI Megaraid SAS emulation

2011-07-03 Thread Paolo Bonzini

On 07/02/2011 03:50 PM, Hannes Reinecke wrote:

(And no, I will not getting into another dog-fight with Paul B. here.
Virtio can do without bounce buffers. AHCI can. So I fail to see why
SCSI has to rely on bounce buffers.)


I agree, but I do see why a SCSI device might prefer to rely on bounce 
buffers for non-I/O commands.  This is why in my last RFC series for 
vmw_pvscsi I let the device choose whether to force a bounce buffer or 
get an external iovec from the HBA.


Paolo



Re: [Qemu-devel] standalone C program "Hello World" on qemu-system-mipsel

2011-07-03 Thread Leo Chen.
Hi,  Andreas

Thanks for your reply.

I tried the -bios *.elf:
qemu-system-mipsel -M mipssim -nographic -bios bin/test.elf
The result is the same with -kernel *.elf: C program can work, but the
serial port still not working.

And I also tried the normal way: -kernel *.bin
mips-linux-gnu-objcopy -O binary bin/test.elf bin/test.bin
qemu-system-mipsel -M mipssim -nographic -kernel bin/test.bin
and get this failure message:
 qemu: could not load kernel 'bin/test.bin'

I know the C programe is working by doing these:
step1:
add some useless code in my C entry:
void c_entry()
{
   init_serial();
   int a, b, c;  //useless code, for remote GDB trace
   a = 1;
   b = 2;
   c = a+b;
   print_uart0("Hello world!\n");
}
step2:
using mips-linux-gdb to connect the qemu like this:
   mips-linux-gnu-gdb
   target remote localhost:1234
Then, I trace the code step by step, and get the correct
result "c=3";

So, I think the problem is I am driving the serial port in
a wrong way. I know there're some linux kernels working
fine on qemu-system-mipsel, maybe I should read these
kernel codes to see how to get the 8250 serial port work.


2011/7/2 Andreas Färber :
> Hi,
>
> Am 02.07.2011 um 08:13 schrieb Leo Chen.:
>
>> qemu-system-mipsel -M mipssim -nographic -kernel bin/test.elf
>> or
>> qemu-system-mipsel -M malta -nographic -kernel bin/test.elf
>
> The use of -kernel for a random ELF executable looks strange, even if it
> happens to work on arm. Have you tried -bios instead?
>
> Andreas
>

Leo Chen



[Qemu-devel] [PATCH v7 00/12] Adding VMDK monolithic flat support

2011-07-03 Thread Fam Zheng
Changes from v6:
01/12: cancel CHECK_CID change, add extents order comment, remove 
duplicated count
04/12: remove unnecessary checks, call vmdk_free_extents on fail
05/12: cancel comment remove, memset-to-zero buf before reading descriptor
08/12: fix two false "return 0"
09/12: remove force flags, use bdrv_file_open to open extent

Fam Zheng (12):
  VMDK: introduce VmdkExtent
  VMDK: bugfix, align offset to cluster in get_whole_cluster
  VMDK: probe for monolithicFlat images
  VMDK: separate vmdk_open by format version
  VMDK: add field BDRVVmdkState.desc_offset
  VMDK: flush multiple extents
  VMDK: move 'static' cid_update flag to bs field
  VMDK: change get_cluster_offset return type
  VMDK: open/read/write for monolithicFlat image
  VMDK: create different subformats
  VMDK: fix coding style
  block: add bdrv_get_allocated_file_size() operation

 block.c   |   19 +
 block.h   |1 +
 block/raw-posix.c |   21 +
 block/raw-win32.c |   29 ++
 block/vmdk.c  | 1360 +
 block_int.h   |2 +
 qemu-img.c|   31 +--
 7 files changed, 1023 insertions(+), 440 deletions(-)




[Qemu-devel] [PATCH v7 06/12] VMDK: flush multiple extents

2011-07-03 Thread Fam Zheng
Flush all the file that referenced by the image.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |   12 +++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 32a9e2e..fbc8af5 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1071,7 +1071,17 @@ static void vmdk_close(BlockDriverState *bs)
 
 static int vmdk_flush(BlockDriverState *bs)
 {
-return bdrv_flush(bs->file);
+int i, ret, err;
+BDRVVmdkState *s = bs->opaque;
+
+ret = bdrv_flush(bs->file);
+for (i = 0; i < s->num_extents; i++) {
+err = bdrv_flush(s->extents[i].file);
+if (err < 0) {
+ret = err;
+}
+}
+return ret;
 }
 
 



[Qemu-devel] [PATCH v7 02/12] VMDK: bugfix, align offset to cluster in get_whole_cluster

2011-07-03 Thread Fam Zheng
In get_whole_cluster, the offset is not aligned to cluster when reading
from backing_hd. When the first write to child is not at the cluster
boundary, wrong address data from parent is copied to child.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 3b78583..03a4619 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -514,21 +514,23 @@ static int get_whole_cluster(BlockDriverState *bs,
 /* 128 sectors * 512 bytes each = grain size 64KB */
 uint8_t  whole_grain[extent->cluster_sectors * 512];
 
-// we will be here if it's first write on non-exist grain(cluster).
-// try to read from parent image, if exist
+/* we will be here if it's first write on non-exist grain(cluster).
+ * try to read from parent image, if exist */
 if (bs->backing_hd) {
 int ret;
 
 if (!vmdk_is_cid_valid(bs))
 return -1;
 
+/* floor offset to cluster */
+offset -= offset % (extent->cluster_sectors * 512);
 ret = bdrv_read(bs->backing_hd, offset >> 9, whole_grain,
 extent->cluster_sectors);
 if (ret < 0) {
 return -1;
 }
 
-//Write grain only into the active image
+/* Write grain only into the active image */
 ret = bdrv_write(extent->file, cluster_offset, whole_grain,
 extent->cluster_sectors);
 if (ret < 0) {



[Qemu-devel] [PATCH v7 04/12] VMDK: separate vmdk_open by format version

2011-07-03 Thread Fam Zheng
Separate vmdk_open by subformats to:
* vmdk_open_vmdk3
* vmdk_open_vmdk4

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |  178 -
 1 files changed, 112 insertions(+), 66 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 05a58db..0b4de38 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -457,67 +457,20 @@ static VmdkExtent *vmdk_add_extent(BlockDriverState *bs,
 return extent;
 }
 
-
-static int vmdk_open(BlockDriverState *bs, int flags)
+static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent)
 {
-BDRVVmdkState *s = bs->opaque;
-uint32_t magic;
-int i;
-uint32_t l1_size, l1_entry_sectors;
-VmdkExtent *extent = NULL;
-
-if (bdrv_pread(bs->file, 0, &magic, sizeof(magic)) != sizeof(magic))
-goto fail;
-
-magic = be32_to_cpu(magic);
-if (magic == VMDK3_MAGIC) {
-VMDK3Header header;
-if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header))
-!= sizeof(header)) {
-goto fail;
-}
-extent = vmdk_add_extent(bs, bs->file, false,
-  le32_to_cpu(header.disk_sectors),
-  le32_to_cpu(header.l1dir_offset) << 9, 0,
-  1 << 6, 1 << 9, le32_to_cpu(header.granularity));
-} else if (magic == VMDK4_MAGIC) {
-VMDK4Header header;
-if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header))
-!= sizeof(header)) {
-goto fail;
-}
-l1_entry_sectors = le32_to_cpu(header.num_gtes_per_gte)
-* le64_to_cpu(header.granularity);
-l1_size = (le64_to_cpu(header.capacity) + l1_entry_sectors - 1)
-/ l1_entry_sectors;
-extent = vmdk_add_extent(bs, bs->file, false,
-  le64_to_cpu(header.capacity),
-  le64_to_cpu(header.gd_offset) << 9,
-  le64_to_cpu(header.rgd_offset) << 9,
-  l1_size,
-  le32_to_cpu(header.num_gtes_per_gte),
-  le64_to_cpu(header.granularity));
-if (extent->l1_entry_sectors <= 0) {
-goto fail;
-}
-// try to open parent images, if exist
-if (vmdk_parent_open(bs) != 0)
-goto fail;
-// write the CID once after the image creation
-s->parent_cid = vmdk_read_cid(bs,1);
-} else {
-goto fail;
-}
+int ret;
+int l1_size, i;
 
 /* read the L1 table */
 l1_size = extent->l1_size * sizeof(uint32_t);
 extent->l1_table = qemu_malloc(l1_size);
-if (bdrv_pread(bs->file,
-extent->l1_table_offset,
-extent->l1_table,
-l1_size)
-!= l1_size) {
-goto fail;
+ret = bdrv_pread(extent->file,
+extent->l1_table_offset,
+extent->l1_table,
+l1_size);
+if (ret < 0) {
+goto fail_l1;
 }
 for (i = 0; i < extent->l1_size; i++) {
 le32_to_cpus(&extent->l1_table[i]);
@@ -525,12 +478,12 @@ static int vmdk_open(BlockDriverState *bs, int flags)
 
 if (extent->l1_backup_table_offset) {
 extent->l1_backup_table = qemu_malloc(l1_size);
-if (bdrv_pread(bs->file,
-extent->l1_backup_table_offset,
-extent->l1_backup_table,
-l1_size)
-!= l1_size) {
-goto fail;
+ret = bdrv_pread(extent->file,
+extent->l1_backup_table_offset,
+extent->l1_backup_table,
+l1_size);
+if (ret < 0) {
+goto fail_l1b;
 }
 for (i = 0; i < extent->l1_size; i++) {
 le32_to_cpus(&extent->l1_backup_table[i]);
@@ -540,9 +493,102 @@ static int vmdk_open(BlockDriverState *bs, int flags)
 extent->l2_cache =
 qemu_malloc(extent->l2_size * L2_CACHE_SIZE * sizeof(uint32_t));
 return 0;
+ fail_l1b:
+qemu_free(extent->l1_backup_table);
+ fail_l1:
+qemu_free(extent->l1_table);
+return ret;
+}
+
+static int vmdk_open_vmdk3(BlockDriverState *bs, int flags)
+{
+int ret;
+uint32_t magic;
+VMDK3Header header;
+VmdkExtent *extent;
+
+ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header));
+if (ret < 0) {
+goto fail;
+}
+extent = vmdk_add_extent(bs,
+ bs->file, false,
+ le32_to_cpu(header.disk_sectors),
+ le32_to_cpu(header.l1dir_offset) << 9,
+ 0, 1 << 6, 1 << 9,
+ le32_to_cpu(header.granularity));
+ret = vmdk_init_tables(bs, extent);
+if (ret) {
+/* vmdk_init_tables cleans up on fail, so only free allocation of
+ * vmdk_add_extent here. */
+

[Qemu-devel] [PATCH v7 01/12] VMDK: introduce VmdkExtent

2011-07-03 Thread Fam Zheng
Introduced VmdkExtent array into BDRVVmdkState, enable holding multiple
image extents for multiple file image support.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |  348 +-
 1 files changed, 246 insertions(+), 102 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 922b23d..3b78583 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -60,7 +60,11 @@ typedef struct {
 
 #define L2_CACHE_SIZE 16
 
-typedef struct BDRVVmdkState {
+typedef struct VmdkExtent {
+BlockDriverState *file;
+bool flat;
+int64_t sectors;
+int64_t end_sector;
 int64_t l1_table_offset;
 int64_t l1_backup_table_offset;
 uint32_t *l1_table;
@@ -74,7 +78,13 @@ typedef struct BDRVVmdkState {
 uint32_t l2_cache_counts[L2_CACHE_SIZE];
 
 unsigned int cluster_sectors;
+} VmdkExtent;
+
+typedef struct BDRVVmdkState {
 uint32_t parent_cid;
+int num_extents;
+/* Extent array with num_extents entries, ascend ordered by address */
+VmdkExtent *extents;
 } BDRVVmdkState;
 
 typedef struct VmdkMetaData {
@@ -105,6 +115,19 @@ static int vmdk_probe(const uint8_t *buf, int buf_size, 
const char *filename)
 #define DESC_SIZE 20*SECTOR_SIZE   // 20 sectors of 512 bytes each
 #define HEADER_SIZE 512// first sector of 512 bytes
 
+static void vmdk_free_extents(BlockDriverState *bs)
+{
+int i;
+BDRVVmdkState *s = bs->opaque;
+
+for (i = 0; i < s->num_extents; i++) {
+qemu_free(s->extents[i].l1_table);
+qemu_free(s->extents[i].l2_cache);
+qemu_free(s->extents[i].l1_backup_table);
+}
+qemu_free(s->extents);
+}
+
 static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
 {
 char desc[DESC_SIZE];
@@ -358,11 +381,50 @@ static int vmdk_parent_open(BlockDriverState *bs)
 return 0;
 }
 
+/* Create and append extent to the extent array. Return the added VmdkExtent
+ * address. return NULL if allocation failed. */
+static VmdkExtent *vmdk_add_extent(BlockDriverState *bs,
+   BlockDriverState *file, bool flat, int64_t sectors,
+   int64_t l1_offset, int64_t l1_backup_offset,
+   uint32_t l1_size,
+   int l2_size, unsigned int cluster_sectors)
+{
+VmdkExtent *extent;
+BDRVVmdkState *s = bs->opaque;
+
+s->extents = qemu_realloc(s->extents,
+  (s->num_extents + 1) * sizeof(VmdkExtent));
+extent = &s->extents[s->num_extents];
+s->num_extents++;
+
+memset(extent, 0, sizeof(VmdkExtent));
+extent->file = file;
+extent->flat = flat;
+extent->sectors = sectors;
+extent->l1_table_offset = l1_offset;
+extent->l1_backup_table_offset = l1_backup_offset;
+extent->l1_size = l1_size;
+extent->l1_entry_sectors = l2_size * cluster_sectors;
+extent->l2_size = l2_size;
+extent->cluster_sectors = cluster_sectors;
+
+if (s->num_extents > 1) {
+extent->end_sector = (*(extent - 1)).end_sector + extent->sectors;
+} else {
+extent->end_sector = extent->sectors;
+}
+bs->total_sectors = extent->end_sector;
+return extent;
+}
+
+
 static int vmdk_open(BlockDriverState *bs, int flags)
 {
 BDRVVmdkState *s = bs->opaque;
 uint32_t magic;
-int l1_size, i;
+int i;
+uint32_t l1_size, l1_entry_sectors;
+VmdkExtent *extent = NULL;
 
 if (bdrv_pread(bs->file, 0, &magic, sizeof(magic)) != sizeof(magic))
 goto fail;
@@ -370,32 +432,34 @@ static int vmdk_open(BlockDriverState *bs, int flags)
 magic = be32_to_cpu(magic);
 if (magic == VMDK3_MAGIC) {
 VMDK3Header header;
-
-if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header)) != 
sizeof(header))
+if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header))
+!= sizeof(header)) {
 goto fail;
-s->cluster_sectors = le32_to_cpu(header.granularity);
-s->l2_size = 1 << 9;
-s->l1_size = 1 << 6;
-bs->total_sectors = le32_to_cpu(header.disk_sectors);
-s->l1_table_offset = le32_to_cpu(header.l1dir_offset) << 9;
-s->l1_backup_table_offset = 0;
-s->l1_entry_sectors = s->l2_size * s->cluster_sectors;
+}
+extent = vmdk_add_extent(bs, bs->file, false,
+  le32_to_cpu(header.disk_sectors),
+  le32_to_cpu(header.l1dir_offset) << 9, 0,
+  1 << 6, 1 << 9, le32_to_cpu(header.granularity));
 } else if (magic == VMDK4_MAGIC) {
 VMDK4Header header;
-
-if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header)) != 
sizeof(header))
+if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header))
+!= sizeof(header)) {
 goto fail;
-bs->total_sectors = le64_to_cpu(header.capacity);
-s->cluster_sectors = le64_to_cpu(header.granularity);
-  

[Qemu-devel] [PATCH v7 07/12] VMDK: move 'static' cid_update flag to bs field

2011-07-03 Thread Fam Zheng
Cid_update is the flag for updating CID on first write after opening the
image. This should be per image open rather than per program life cycle,
so change it from static var of vmdk_write to a field in BDRVVmdkState.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index fbc8af5..196419b 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -82,6 +82,7 @@ typedef struct VmdkExtent {
 
 typedef struct BDRVVmdkState {
 int desc_offset;
+bool cid_updated;
 uint32_t parent_cid;
 int num_extents;
 /* Extent array with num_extents entries, ascend ordered by address */
@@ -852,7 +853,6 @@ static int vmdk_write(BlockDriverState *bs, int64_t 
sector_num,
 int n;
 int64_t index_in_cluster;
 uint64_t cluster_offset;
-static int cid_update = 0;
 VmdkMetaData m_data;
 
 if (sector_num > bs->total_sectors) {
@@ -899,9 +899,9 @@ static int vmdk_write(BlockDriverState *bs, int64_t 
sector_num,
 buf += n * 512;
 
 // update CID on the first write every time the virtual disk is opened
-if (!cid_update) {
+if (!s->cid_updated) {
 vmdk_write_cid(bs, time(NULL));
-cid_update++;
+s->cid_updated = true;
 }
 }
 return 0;



[Qemu-devel] [PATCH v7 05/12] VMDK: add field BDRVVmdkState.desc_offset

2011-07-03 Thread Fam Zheng
There are several occurrence of magic number 0x200 as the descriptor
offset within mono sparse image file. This is not the case for images
with separate descriptor file. So a field is added to BDRVVmdkState to
hold the correct value.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |   27 ++-
 1 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 0b4de38..32a9e2e 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -81,6 +81,7 @@ typedef struct VmdkExtent {
 } VmdkExtent;
 
 typedef struct BDRVVmdkState {
+int desc_offset;
 uint32_t parent_cid;
 int num_extents;
 /* Extent array with num_extents entries, ascend ordered by address */
@@ -174,10 +175,11 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int 
parent)
 uint32_t cid;
 const char *p_name, *cid_str;
 size_t cid_str_size;
+BDRVVmdkState *s = bs->opaque;
 
-/* the descriptor offset = 0x200 */
-if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
 return 0;
+}
 
 if (parent) {
 cid_str = "parentCID";
@@ -199,10 +201,12 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t 
cid)
 {
 char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
 char *p_name, *tmp_str;
+BDRVVmdkState *s = bs->opaque;
 
-/* the descriptor offset = 0x200 */
-if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
-return -1;
+memset(desc, 0, sizeof(desc));
+if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
+return -EIO;
+}
 
 tmp_str = strstr(desc,"parentCID");
 pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str);
@@ -212,8 +216,9 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t 
cid)
 pstrcat(desc, sizeof(desc), tmp_desc);
 }
 
-if (bdrv_pwrite_sync(bs->file, 0x200, desc, DESC_SIZE) < 0)
-return -1;
+if (bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE) < 0) {
+return -EIO;
+}
 return 0;
 }
 
@@ -401,10 +406,11 @@ static int vmdk_parent_open(BlockDriverState *bs)
 {
 char *p_name;
 char desc[DESC_SIZE];
+BDRVVmdkState *s = bs->opaque;
 
-/* the descriptor offset = 0x200 */
-if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
 return -1;
+}
 
 if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) {
 char *end_name;
@@ -505,8 +511,10 @@ static int vmdk_open_vmdk3(BlockDriverState *bs, int flags)
 int ret;
 uint32_t magic;
 VMDK3Header header;
+BDRVVmdkState *s = bs->opaque;
 VmdkExtent *extent;
 
+s->desc_offset = 0x200;
 ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header));
 if (ret < 0) {
 goto fail;
@@ -538,6 +546,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, int flags)
 BDRVVmdkState *s = bs->opaque;
 VmdkExtent *extent;
 
+s->desc_offset = 0x200;
 ret = bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header));
 if (ret < 0) {
 goto fail;



[Qemu-devel] [PATCH v7 03/12] VMDK: probe for monolithicFlat images

2011-07-03 Thread Fam Zheng
Probe as the same behavior as VMware does.
Recognize image as monolithicFlat descriptor file when the file is text
and the first effective line (not '#' leaded comment or space line) is
either 'version=1' or 'version=2'. No space or upper case charactors
accepted.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |   44 ++--
 1 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 03a4619..05a58db 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -103,10 +103,50 @@ static int vmdk_probe(const uint8_t *buf, int buf_size, 
const char *filename)
 return 0;
 magic = be32_to_cpu(*(uint32_t *)buf);
 if (magic == VMDK3_MAGIC ||
-magic == VMDK4_MAGIC)
+magic == VMDK4_MAGIC) {
 return 100;
-else
+} else {
+const char *p = (const char *)buf;
+const char *end = p + buf_size;
+while (p < end) {
+if (*p == '#') {
+/* skip comment line */
+while (p < end && *p != '\n') {
+p++;
+}
+p++;
+continue;
+}
+if (*p == ' ') {
+while (p < end && *p == ' ') {
+p++;
+}
+/* skip '\r' if windows line endings used. */
+if (p < end && *p == '\r') {
+p++;
+}
+/* only accept blank lines before 'version=' line */
+if (p == end || *p != '\n') {
+return 0;
+}
+p++;
+continue;
+}
+if (end - p >= strlen("version=X\n")) {
+if (strncmp("version=1\n", p, strlen("version=1\n")) == 0 ||
+strncmp("version=2\n", p, strlen("version=2\n")) == 0) {
+return 100;
+}
+}
+if (end - p >= strlen("version=X\r\n")) {
+if (strncmp("version=1\r\n", p, strlen("version=1\r\n")) == 0 
||
+strncmp("version=2\r\n", p, strlen("version=2\r\n")) == 0) 
{
+return 100;
+}
+}
+}
 return 0;
+}
 }
 
 #define CHECK_CID 1



[Qemu-devel] [PATCH v7 09/12] VMDK: open/read/write for monolithicFlat image

2011-07-03 Thread Fam Zheng
Parse vmdk decriptor file and open mono flat image.
Read/write the flat extent.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |  172 +-
 1 files changed, 159 insertions(+), 13 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 5bb6392..9ea00ce 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -65,6 +65,7 @@ typedef struct VmdkExtent {
 bool flat;
 int64_t sectors;
 int64_t end_sector;
+int64_t flat_start_offset;
 int64_t l1_table_offset;
 int64_t l1_backup_table_offset;
 uint32_t *l1_table;
@@ -406,9 +407,10 @@ fail:
 static int vmdk_parent_open(BlockDriverState *bs)
 {
 char *p_name;
-char desc[DESC_SIZE];
+char desc[DESC_SIZE + 1];
 BDRVVmdkState *s = bs->opaque;
 
+desc[DESC_SIZE] = '\0';
 if (bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE) != DESC_SIZE) {
 return -1;
 }
@@ -583,6 +585,145 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, int 
flags)
 return ret;
 }
 
+/* find an option value out of descriptor file */
+static int vmdk_parse_description(const char *desc, const char *opt_name,
+char *buf, int buf_size)
+{
+char *opt_pos, *opt_end;
+const char *end = desc + strlen(desc);
+
+opt_pos = strstr(desc, opt_name);
+if (!opt_pos) {
+return -1;
+}
+/* Skip "=\"" following opt_name */
+opt_pos += strlen(opt_name) + 2;
+if (opt_pos >= end) {
+return -1;
+}
+opt_end = opt_pos;
+while (opt_end < end && *opt_end != '"') {
+opt_end++;
+}
+if (opt_end == end || buf_size < opt_end - opt_pos + 1) {
+return -1;
+}
+pstrcpy(buf, opt_end - opt_pos + 1, opt_pos);
+return 0;
+}
+
+static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
+const char *desc_file_path)
+{
+int ret;
+char access[11];
+char type[11];
+char fname[512];
+const char *p = desc;
+int64_t sectors = 0;
+int64_t flat_offset;
+
+while (*p) {
+/* parse extent line:
+ * RW [size in sectors] FLAT "file-name.vmdk" OFFSET
+ * or
+ * RW [size in sectors] SPARSE "file-name.vmdk"
+ */
+flat_offset = -1;
+ret = sscanf(p, "%10s %lld %10s %512s",
+access, §ors, type, fname);
+if (ret != 4) {
+goto next_line;
+}
+if (!strcmp(type, "FLAT")) {
+ret = sscanf(p, "%10s %lld %10s %511s %lld",
+access, §ors, type, fname, &flat_offset);
+if (ret != 5 || flat_offset < 0) {
+return -EINVAL;
+}
+}
+
+/* trim the quotation marks around */
+if (fname[0] == '"') {
+memmove(fname, fname + 1, strlen(fname));
+if (strlen(fname) <= 1 || fname[strlen(fname) - 1] != '"') {
+return -EINVAL;
+}
+fname[strlen(fname) - 1] = '\0';
+}
+if (sectors <= 0 ||
+(strcmp(type, "FLAT") && strcmp(type, "SPARSE")) ||
+(strcmp(access, "RW"))) {
+goto next_line;
+}
+
+/* save to extents array */
+if (!strcmp(type, "FLAT")) {
+/* FLAT extent */
+char extent_path[PATH_MAX];
+BlockDriverState *extent_file;
+VmdkExtent *extent;
+
+path_combine(extent_path, sizeof(extent_path),
+desc_file_path, fname);
+ret = bdrv_file_open(&extent_file, extent_path, bs->open_flags);
+if (ret) {
+return ret;
+}
+extent = vmdk_add_extent(bs, extent_file, true, sectors,
+0, 0, 0, 0, sectors);
+extent->flat_start_offset = flat_offset;
+} else {
+/* SPARSE extent, not supported for now */
+fprintf(stderr,
+"VMDK: Not supported extent type \"%s\""".\n", type);
+return -ENOTSUP;
+}
+next_line:
+/* move to next line */
+while (*p && *p != '\n') {
+p++;
+}
+p++;
+}
+return 0;
+}
+
+static int vmdk_open_desc_file(BlockDriverState *bs, int flags)
+{
+int ret;
+char buf[2048];
+char ct[128];
+BDRVVmdkState *s = bs->opaque;
+
+ret = bdrv_pread(bs->file, 0, buf, sizeof(buf));
+if (ret < 0) {
+return ret;
+}
+buf[2047] = '\0';
+if (vmdk_parse_description(buf, "createType", ct, sizeof(ct))) {
+return -EINVAL;
+}
+if (strcmp(ct, "monolithicFlat")) {
+fprintf(stderr,
+"VMDK: Not supported image type \"%s\""".\n", ct);
+return -ENOTSUP;
+}
+s->desc_offset = 0;
+ret = vmdk_parse_extents(buf, bs, bs->file->filename);
+if (ret) {
+return ret;
+}
+
+/* try to open parent images, if exist */
+if (vmdk_parent_open(bs)) {
+qemu_free(s->extents);
+return -EINVAL;
+}
+s

[Qemu-devel] [PATCH v7 08/12] VMDK: change get_cluster_offset return type

2011-07-03 Thread Fam Zheng
The return type of get_cluster_offset was an offset that use 0 to denote
'not allocated', this will be no longer true for flat extents, as we see
flat extent file as a single huge cluster whose offset is 0 and length
is the whole file length.
So now we use int return value, 0 means success and otherwise offset
invalid.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |   79 ++---
 1 files changed, 42 insertions(+), 37 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 196419b..5bb6392 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -664,26 +664,31 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData 
*m_data)
 return 0;
 }
 
-static uint64_t get_cluster_offset(BlockDriverState *bs,
+static int get_cluster_offset(BlockDriverState *bs,
 VmdkExtent *extent,
 VmdkMetaData *m_data,
-uint64_t offset, int allocate)
+uint64_t offset,
+int allocate,
+uint64_t *cluster_offset)
 {
 unsigned int l1_index, l2_offset, l2_index;
 int min_index, i, j;
 uint32_t min_count, *l2_table, tmp = 0;
-uint64_t cluster_offset;
 
 if (m_data)
 m_data->valid = 0;
+if (extent->flat) {
+*cluster_offset = 0;
+return 0;
+}
 
 l1_index = (offset >> 9) / extent->l1_entry_sectors;
 if (l1_index >= extent->l1_size) {
-return 0;
+return -1;
 }
 l2_offset = extent->l1_table[l1_index];
 if (!l2_offset) {
-return 0;
+return -1;
 }
 for (i = 0; i < L2_CACHE_SIZE; i++) {
 if (l2_offset == extent->l2_cache_offsets[i]) {
@@ -713,28 +718,29 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
 l2_table,
 extent->l2_size * sizeof(uint32_t)
 ) != extent->l2_size * sizeof(uint32_t)) {
-return 0;
+return -1;
 }
 
 extent->l2_cache_offsets[min_index] = l2_offset;
 extent->l2_cache_counts[min_index] = 1;
  found:
 l2_index = ((offset >> 9) / extent->cluster_sectors) % extent->l2_size;
-cluster_offset = le32_to_cpu(l2_table[l2_index]);
+*cluster_offset = le32_to_cpu(l2_table[l2_index]);
 
-if (!cluster_offset) {
-if (!allocate)
-return 0;
+if (!*cluster_offset) {
+if (!allocate) {
+return -1;
+}
 
 // Avoid the L2 tables update for the images that have snapshots.
-cluster_offset = bdrv_getlength(extent->file);
+*cluster_offset = bdrv_getlength(extent->file);
 bdrv_truncate(
 extent->file,
-cluster_offset + (extent->cluster_sectors << 9)
+*cluster_offset + (extent->cluster_sectors << 9)
 );
 
-cluster_offset >>= 9;
-tmp = cpu_to_le32(cluster_offset);
+*cluster_offset >>= 9;
+tmp = cpu_to_le32(*cluster_offset);
 l2_table[l2_index] = tmp;
 
 /* First of all we write grain itself, to avoid race condition
@@ -743,8 +749,8 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
  * or inappropriate VM shutdown.
  */
 if (get_whole_cluster(
-bs, extent, cluster_offset, offset, allocate) == -1)
-return 0;
+bs, extent, *cluster_offset, offset, allocate) == -1)
+return -1;
 
 if (m_data) {
 m_data->offset = tmp;
@@ -754,8 +760,8 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
 m_data->valid = 1;
 }
 }
-cluster_offset <<= 9;
-return cluster_offset;
+*cluster_offset <<= 9;
+return 0;
 }
 
 static VmdkExtent *find_extent(BDRVVmdkState *s,
@@ -779,7 +785,6 @@ static int vmdk_is_allocated(BlockDriverState *bs, int64_t 
sector_num,
  int nb_sectors, int *pnum)
 {
 BDRVVmdkState *s = bs->opaque;
-
 int64_t index_in_cluster, n, ret;
 uint64_t offset;
 VmdkExtent *extent;
@@ -788,15 +793,13 @@ static int vmdk_is_allocated(BlockDriverState *bs, 
int64_t sector_num,
 if (!extent) {
 return 0;
 }
-if (extent->flat) {
-n = extent->end_sector - sector_num;
-ret = 1;
-} else {
-offset = get_cluster_offset(bs, extent, NULL, sector_num * 512, 0);
-index_in_cluster = sector_num % extent->cluster_sectors;
-n = extent->cluster_sectors - index_in_cluster;
-ret = offset ? 1 : 0;
-}
+ret = get_cluster_offset(bs, extent, NULL,
+sector_num * 512, 0, &offset);
+/* get_cluster_offset returning 0 means success */
+ret = !ret;
+
+index_in_cluster = sector_num % extent->cluster_sectors;
+n = extent->cluster_sectors - index_in_cluster;
 if (n > nb_sectors)
 n = nb_sectors;
 *pnum = n;
@@ -817,14 +820

[Qemu-devel] [PATCH v7 11/12] VMDK: fix coding style

2011-07-03 Thread Fam Zheng
Conform coding style in vmdk.c to pass scripts/checkpatch.pl checks.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |   79 +++--
 1 files changed, 48 insertions(+), 31 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index cb529c6..61dc84d 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -102,8 +102,9 @@ static int vmdk_probe(const uint8_t *buf, int buf_size, 
const char *filename)
 {
 uint32_t magic;
 
-if (buf_size < 4)
+if (buf_size < 4) {
 return 0;
+}
 magic = be32_to_cpu(*(uint32_t *)buf);
 if (magic == VMDK3_MAGIC ||
 magic == VMDK4_MAGIC) {
@@ -191,9 +192,10 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int 
parent)
 cid_str_size = sizeof("CID");
 }
 
-if ((p_name = strstr(desc,cid_str)) != NULL) {
+p_name = strstr(desc, cid_str);
+if (p_name != NULL) {
 p_name += cid_str_size;
-sscanf(p_name,"%x",&cid);
+sscanf(p_name, "%x", &cid);
 }
 
 return cid;
@@ -210,9 +212,10 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t 
cid)
 return -EIO;
 }
 
-tmp_str = strstr(desc,"parentCID");
+tmp_str = strstr(desc, "parentCID");
 pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str);
-if ((p_name = strstr(desc,"CID")) != NULL) {
+p_name = strstr(desc, "CID");
+if (p_name != NULL) {
 p_name += sizeof("CID");
 snprintf(p_name, sizeof(desc) - (p_name - desc), "%x\n", cid);
 pstrcat(desc, sizeof(desc), tmp_desc);
@@ -232,13 +235,14 @@ static int vmdk_is_cid_valid(BlockDriverState *bs)
 uint32_t cur_pcid;
 
 if (p_bs) {
-cur_pcid = vmdk_read_cid(p_bs,0);
-if (s->parent_cid != cur_pcid)
-// CID not valid
+cur_pcid = vmdk_read_cid(p_bs, 0);
+if (s->parent_cid != cur_pcid) {
+/* CID not valid */
 return 0;
+}
 }
 #endif
-// CID valid
+/* CID valid */
 return 1;
 }
 
@@ -253,14 +257,18 @@ static int vmdk_parent_open(BlockDriverState *bs)
 return -1;
 }
 
-if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) {
+p_name = strstr(desc, "parentFileNameHint");
+if (p_name != NULL) {
 char *end_name;
 
 p_name += sizeof("parentFileNameHint") + 1;
-if ((end_name = strchr(p_name,'\"')) == NULL)
+end_name = strchr(p_name, '\"');
+if (end_name == NULL) {
 return -1;
-if ((end_name - p_name) > sizeof (bs->backing_file) - 1)
+}
+if ((end_name - p_name) > sizeof(bs->backing_file) - 1) {
 return -1;
+}
 
 pstrcpy(bs->backing_file, end_name - p_name + 1, p_name);
 }
@@ -594,8 +602,9 @@ static int get_whole_cluster(BlockDriverState *bs,
 if (bs->backing_hd) {
 int ret;
 
-if (!vmdk_is_cid_valid(bs))
+if (!vmdk_is_cid_valid(bs)) {
 return -1;
+}
 
 /* floor offset to cluster */
 offset -= offset % (extent->cluster_sectors * 512);
@@ -654,8 +663,9 @@ static int get_cluster_offset(BlockDriverState *bs,
 int min_index, i, j;
 uint32_t min_count, *l2_table, tmp = 0;
 
-if (m_data)
+if (m_data) {
 m_data->valid = 0;
+}
 if (extent->flat) {
 *cluster_offset = extent->flat_start_offset;
 return 0;
@@ -711,7 +721,7 @@ static int get_cluster_offset(BlockDriverState *bs,
 return -1;
 }
 
-// Avoid the L2 tables update for the images that have snapshots.
+/* Avoid the L2 tables update for the images that have snapshots. */
 *cluster_offset = bdrv_getlength(extent->file);
 bdrv_truncate(
 extent->file,
@@ -728,8 +738,9 @@ static int get_cluster_offset(BlockDriverState *bs,
  * or inappropriate VM shutdown.
  */
 if (get_whole_cluster(
-bs, extent, *cluster_offset, offset, allocate) == -1)
+bs, extent, *cluster_offset, offset, allocate) == -1) {
 return -1;
+}
 
 if (m_data) {
 m_data->offset = tmp;
@@ -779,8 +790,9 @@ static int vmdk_is_allocated(BlockDriverState *bs, int64_t 
sector_num,
 
 index_in_cluster = sector_num % extent->cluster_sectors;
 n = extent->cluster_sectors - index_in_cluster;
-if (n > nb_sectors)
+if (n > nb_sectors) {
 n = nb_sectors;
+}
 *pnum = n;
 return ret;
 }
@@ -804,16 +816,19 @@ static int vmdk_read(BlockDriverState *bs, int64_t 
sector_num,
 sector_num << 9, 0, &cluster_offset);
 index_in_cluster = sector_num % extent->cluster_sectors;
 n = extent->cluster_sectors - index_in_cluster;
-if (n > nb_sectors)
+if (n > nb_sectors) {
 n = nb_sectors;
+}
 if (ret) {
 /* if not allocated, try to read from parent image, if exist */
 if (bs->backing_hd) {
-  

[Qemu-devel] [PATCH v7 10/12] VMDK: create different subformats

2011-07-03 Thread Fam Zheng
Add create option 'format', with enums:
monolithicSparse
monolithicFlat
twoGbMaxExtentSparse
twoGbMaxExtentFlat
Each creates a subformat image file. The default is monolithiSparse.

Signed-off-by: Fam Zheng 
---
 block/vmdk.c |  561 ++
 block_int.h  |1 +
 2 files changed, 330 insertions(+), 232 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 9ea00ce..cb529c6 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -155,8 +155,8 @@ static int vmdk_probe(const uint8_t *buf, int buf_size, 
const char *filename)
 #define CHECK_CID 1
 
 #define SECTOR_SIZE 512
-#define DESC_SIZE 20*SECTOR_SIZE   // 20 sectors of 512 bytes each
-#define HEADER_SIZE 512// first sector of 512 bytes
+#define DESC_SIZE (20 * SECTOR_SIZE)/* 20 sectors of 512 bytes each */
+#define HEADER_SIZE 512 /* first sector of 512 bytes */
 
 static void vmdk_free_extents(BlockDriverState *bs)
 {
@@ -242,168 +242,6 @@ static int vmdk_is_cid_valid(BlockDriverState *bs)
 return 1;
 }
 
-static int vmdk_snapshot_create(const char *filename, const char *backing_file)
-{
-int snp_fd, p_fd;
-int ret;
-uint32_t p_cid;
-char *p_name, *gd_buf, *rgd_buf;
-const char *real_filename, *temp_str;
-VMDK4Header header;
-uint32_t gde_entries, gd_size;
-int64_t gd_offset, rgd_offset, capacity, gt_size;
-char p_desc[DESC_SIZE], s_desc[DESC_SIZE], hdr[HEADER_SIZE];
-static const char desc_template[] =
-"# Disk DescriptorFile\n"
-"version=1\n"
-"CID=%x\n"
-"parentCID=%x\n"
-"createType=\"monolithicSparse\"\n"
-"parentFileNameHint=\"%s\"\n"
-"\n"
-"# Extent description\n"
-"RW %u SPARSE \"%s\"\n"
-"\n"
-"# The Disk Data Base \n"
-"#DDB\n"
-"\n";
-
-snp_fd = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY | 
O_LARGEFILE, 0644);
-if (snp_fd < 0)
-return -errno;
-p_fd = open(backing_file, O_RDONLY | O_BINARY | O_LARGEFILE);
-if (p_fd < 0) {
-close(snp_fd);
-return -errno;
-}
-
-/* read the header */
-if (lseek(p_fd, 0x0, SEEK_SET) == -1) {
-ret = -errno;
-goto fail;
-}
-if (read(p_fd, hdr, HEADER_SIZE) != HEADER_SIZE) {
-ret = -errno;
-goto fail;
-}
-
-/* write the header */
-if (lseek(snp_fd, 0x0, SEEK_SET) == -1) {
-ret = -errno;
-goto fail;
-}
-if (write(snp_fd, hdr, HEADER_SIZE) == -1) {
-ret = -errno;
-goto fail;
-}
-
-memset(&header, 0, sizeof(header));
-memcpy(&header,&hdr[4], sizeof(header)); // skip the VMDK4_MAGIC
-
-if (ftruncate(snp_fd, header.grain_offset << 9)) {
-ret = -errno;
-goto fail;
-}
-/* the descriptor offset = 0x200 */
-if (lseek(p_fd, 0x200, SEEK_SET) == -1) {
-ret = -errno;
-goto fail;
-}
-if (read(p_fd, p_desc, DESC_SIZE) != DESC_SIZE) {
-ret = -errno;
-goto fail;
-}
-
-if ((p_name = strstr(p_desc,"CID")) != NULL) {
-p_name += sizeof("CID");
-sscanf(p_name,"%x",&p_cid);
-}
-
-real_filename = filename;
-if ((temp_str = strrchr(real_filename, '\\')) != NULL)
-real_filename = temp_str + 1;
-if ((temp_str = strrchr(real_filename, '/')) != NULL)
-real_filename = temp_str + 1;
-if ((temp_str = strrchr(real_filename, ':')) != NULL)
-real_filename = temp_str + 1;
-
-snprintf(s_desc, sizeof(s_desc), desc_template, p_cid, p_cid, backing_file,
- (uint32_t)header.capacity, real_filename);
-
-/* write the descriptor */
-if (lseek(snp_fd, 0x200, SEEK_SET) == -1) {
-ret = -errno;
-goto fail;
-}
-if (write(snp_fd, s_desc, strlen(s_desc)) == -1) {
-ret = -errno;
-goto fail;
-}
-
-gd_offset = header.gd_offset * SECTOR_SIZE; // offset of GD table
-rgd_offset = header.rgd_offset * SECTOR_SIZE;   // offset of RGD table
-capacity = header.capacity * SECTOR_SIZE;   // Extent size
-/*
- * Each GDE span 32M disk, means:
- * 512 GTE per GT, each GTE points to grain
- */
-gt_size = (int64_t)header.num_gtes_per_gte * header.granularity * 
SECTOR_SIZE;
-if (!gt_size) {
-ret = -EINVAL;
-goto fail;
-}
-gde_entries = (uint32_t)(capacity / gt_size);  // number of gde/rgde
-gd_size = gde_entries * sizeof(uint32_t);
-
-/* write RGD */
-rgd_buf = qemu_malloc(gd_size);
-if (lseek(p_fd, rgd_offset, SEEK_SET) == -1) {
-ret = -errno;
-goto fail_rgd;
-}
-if (read(p_fd, rgd_buf, gd_size) != gd_size) {
-ret = -errno;
-goto fail_rgd;
-}
-if (lseek(snp_fd, rgd_offset, SEEK_SET) == -1) {
-ret = -errno;
-goto fail_rgd;
-}
-if (write(snp_fd, rgd_buf, gd_size) == -1) {
-ret = -errno;
-goto fail_rgd;
-}
-
-/* write GD */
-gd_buf =

[Qemu-devel] [PATCH v7 12/12] block: add bdrv_get_allocated_file_size() operation

2011-07-03 Thread Fam Zheng
qemu-img.c wants to count allocated file size of image. Previously it
counts a single bs->file by 'stat' or Window API. As VMDK introduces
multiple file support, the operation becomes format specific with
platform specific meanwhile.

The functions are moved to block/raw-{posix,win32}.c and qemu-img.c calls
bdrv_get_allocated_file_size to count the bs. And also added VMDK code
to count his own extents.

Signed-off-by: Fam Zheng 
---
 block.c   |   19 +++
 block.h   |1 +
 block/raw-posix.c |   21 +
 block/raw-win32.c |   29 +
 block/vmdk.c  |   24 
 block_int.h   |1 +
 qemu-img.c|   31 +--
 7 files changed, 96 insertions(+), 30 deletions(-)

diff --git a/block.c b/block.c
index 24a25d5..9549b9e 100644
--- a/block.c
+++ b/block.c
@@ -1147,6 +1147,25 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
 }
 
 /**
+ * Length of a allocated file in bytes. Sparse files are counted by actual
+ * allocated space. Return < 0 if error or unknown.
+ */
+int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
+{
+BlockDriver *drv = bs->drv;
+if (!drv) {
+return -ENOMEDIUM;
+}
+if (drv->bdrv_get_allocated_file_size) {
+return drv->bdrv_get_allocated_file_size(bs);
+}
+if (bs->file) {
+return bdrv_get_allocated_file_size(bs->file);
+}
+return -ENOTSUP;
+}
+
+/**
  * Length of a file in bytes. Return < 0 if error or unknown.
  */
 int64_t bdrv_getlength(BlockDriverState *bs)
diff --git a/block.h b/block.h
index 859d1d9..59cc410 100644
--- a/block.h
+++ b/block.h
@@ -89,6 +89,7 @@ int bdrv_write_sync(BlockDriverState *bs, int64_t sector_num,
 const uint8_t *buf, int nb_sectors);
 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
 int64_t bdrv_getlength(BlockDriverState *bs);
+int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
 void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int 
*psecs);
 int bdrv_commit(BlockDriverState *bs);
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 4cd7d7a..911cc0d 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -791,6 +791,17 @@ static int64_t raw_getlength(BlockDriverState *bs)
 }
 #endif
 
+static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
+{
+struct stat st;
+BDRVRawState *s = bs->opaque;
+
+if (fstat(s->fd, &st) < 0) {
+return -errno;
+}
+return (int64_t)st.st_blocks * 512;
+}
+
 static int raw_create(const char *filename, QEMUOptionParameter *options)
 {
 int fd;
@@ -886,6 +897,8 @@ static BlockDriver bdrv_file = {
 
 .bdrv_truncate = raw_truncate,
 .bdrv_getlength = raw_getlength,
+.bdrv_get_allocated_file_size
+= raw_get_allocated_file_size,
 
 .create_options = raw_create_options,
 };
@@ -1154,6 +1167,8 @@ static BlockDriver bdrv_host_device = {
 .bdrv_read  = raw_read,
 .bdrv_write = raw_write,
 .bdrv_getlength= raw_getlength,
+.bdrv_get_allocated_file_size
+= raw_get_allocated_file_size,
 
 /* generic scsi device */
 #ifdef __linux__
@@ -1269,6 +1284,8 @@ static BlockDriver bdrv_host_floppy = {
 .bdrv_read  = raw_read,
 .bdrv_write = raw_write,
 .bdrv_getlength= raw_getlength,
+.bdrv_get_allocated_file_size
+= raw_get_allocated_file_size,
 
 /* removable device support */
 .bdrv_is_inserted   = floppy_is_inserted,
@@ -1366,6 +1383,8 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_read  = raw_read,
 .bdrv_write = raw_write,
 .bdrv_getlength = raw_getlength,
+.bdrv_get_allocated_file_size
+= raw_get_allocated_file_size,
 
 /* removable device support */
 .bdrv_is_inserted   = cdrom_is_inserted,
@@ -1489,6 +1508,8 @@ static BlockDriver bdrv_host_cdrom = {
 .bdrv_read  = raw_read,
 .bdrv_write = raw_write,
 .bdrv_getlength = raw_getlength,
+.bdrv_get_allocated_file_size
+= raw_get_allocated_file_size,
 
 /* removable device support */
 .bdrv_is_inserted   = cdrom_is_inserted,
diff --git a/block/raw-win32.c b/block/raw-win32.c
index 56bd719..91067e7 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -213,6 +213,31 @@ static int64_t raw_getlength(BlockDriverState *bs)
 return l.QuadPart;
 }
 
+static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
+{
+typedef DWORD (WINAPI * get_compressed_t)(const char *filename,
+  DWORD * high);
+get_compressed_t get_compressed;
+struct _stati64 st;
+const char *filename = bs->filename;
+/* WinNT support GetCompressedFileSize to determine allocate size */
+get_compresse

[Qemu-devel] [PATCH] esp: cancel current request only if some request is in flight

2011-07-03 Thread Hervé Poussineau
Some device may be selected, but it doesn't mean that a request is pending.
This fixes a possible crash of Qemu.

Signed-off-by: Hervé Poussineau 
---
 hw/esp.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/esp.c b/hw/esp.c
index 8e95672..aa50800 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -219,7 +219,7 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf)
 s->ti_rptr = 0;
 s->ti_wptr = 0;
 
-if (s->current_dev) {
+if (s->current_req) {
 /* Started a new command before the old one finished.  Cancel it.  */
 scsi_req_cancel(s->current_req);
 s->async_len = 0;
-- 
1.7.5.4




Re: [Qemu-devel] [PATCH] Fix unassigned memory access handling

2011-07-03 Thread Richard Henderson
On 07/03/2011 02:42 AM, Blue Swirl wrote:
>  }
> 
> -void QEMU_NORETURN do_unassigned_access(target_phys_addr_t addr, int 
> is_write,
> -int is_exec, int unused, int size)
> +void QEMU_NORETURN cpu_unassigned_access(CPUState *env1,
> + target_phys_addr_t addr, int 
> is_write,
> + int is_exec, int unused, int size)
>  {
> +CPUState *saved_env;
> +
> +saved_env = env;
> +env = env1;
>  env->trap_arg0 = addr;
>  env->trap_arg1 = is_write;
>  dynamic_excp(EXCP_MCHK, 0);
> +env = saved_env;
>  }

For Alpha and MIPS, these functions always throw an exception exiting
the cpu loop.  There's no point in saving the old value of ENV.

It's Sparc and Microblaze that only sometimes throw the exception.


r~



[Qemu-devel] buildbot failure in qemu on default_x86_64_debian_5_0

2011-07-03 Thread qemu
The Buildbot has detected a new failure on builder default_x86_64_debian_5_0 
while building qemu.
Full details are available at:
 
http://buildbot.b1-systems.de/qemu/builders/default_x86_64_debian_5_0/builds/144

Buildbot URL: http://buildbot.b1-systems.de/qemu/

Buildslave for this Build: b1_qemu_1

Build Reason: The Nightly scheduler named 'nightly_default' triggered this build
Build Source Stamp: [branch master] HEAD
Blamelist: 

BUILD FAILED: failed compile

sincerely,
 -The Buildbot



[Qemu-devel] Wiki spam

2011-07-03 Thread Sune Marcher

Hi folks,

sorry if this is the wrong place to post - couldn't find any other 
contact information. Just wanted to let you know that multiple pages of 
the wiki have had spam links added recently, so whoever is in charge 
might want to give the wiki a good scrubbing :)




[Qemu-devel] buildbot failure in qemu on disable_kvm_x86_64_debian_5_0

2011-07-03 Thread qemu
The Buildbot has detected a new failure on builder 
disable_kvm_x86_64_debian_5_0 while building qemu.
Full details are available at:
 
http://buildbot.b1-systems.de/qemu/builders/disable_kvm_x86_64_debian_5_0/builds/148

Buildbot URL: http://buildbot.b1-systems.de/qemu/

Buildslave for this Build: b1_qemu_1

Build Reason: The Nightly scheduler named 'nightly_disable_kvm' triggered this 
build
Build Source Stamp: [branch master] HEAD
Blamelist: 

BUILD FAILED: failed compile

sincerely,
 -The Buildbot



Re: [Qemu-devel] buildbot failure in qemu on disable_kvm_x86_64_debian_5_0

2011-07-03 Thread Alexander Graf

On 04.07.2011, at 02:04, q...@buildbot.b1-systems.de wrote:

> The Buildbot has detected a new failure on builder 
> disable_kvm_x86_64_debian_5_0 while building qemu.
> Full details are available at:
> http://buildbot.b1-systems.de/qemu/builders/disable_kvm_x86_64_debian_5_0/builds/148
> 
> Buildbot URL: http://buildbot.b1-systems.de/qemu/
> 
> Buildslave for this Build: b1_qemu_1
> 
> Build Reason: The Nightly scheduler named 'nightly_disable_kvm' triggered 
> this build
> Build Source Stamp: [branch master] HEAD
> Blamelist: 
> 
> BUILD FAILED: failed compile

In file included from /usr/include/png.h:438,
 from ui/vnc-enc-tight.c:40:
/usr/include/pngconf.h:326: error: expected '=', ',', ';', 'asm' or 
'__attribute__' before '.' token
/usr/include/pngconf.h:327: error: expected '=', ',', ';', 'asm' or 
'__attribute__' before 'include'
make: *** [ui/vnc-enc-tight.o] Error 1

program finished with exit code 2


Not sure what exactly is missing, but the last change in that code was from 
Stefan Weil (2fb0c09f4ff036f68474277ed4edc036f6529de8).

Alex




[Qemu-devel] [Bug 786209] Re: Information leak in IDE core

2011-07-03 Thread Qiao Liyong
hi Nelson :

what 's the flag 'DRQ_STAT' mean for   HD_STATUS ?

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/786209

Title:
  Information leak in IDE core

Status in QEMU:
  New

Bug description:
  When the DRQ_STAT bit is set, the IDE core permits both data reads and
  data writes, regardless of whether the current transfer was initiated
  as a read or write.

  Furthermore, the IO buffer is allocated via a qemu_memalign but not
  initialized or cleared at device creation.

  This potentially leaks uninitialized host memory into the guest, if,
  before doing anything else to an IDE device, the guest begins a write
  transaction (e.g. WIN_WRITE), but then *reads* from the IO port
  instead of writing to it. The IDE core will happily return the
  uninitialized contents of the buffer to the guest, potentially leaking
  offsets that could be used as part of an attack to get around ASLR.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/786209/+subscriptions



[Qemu-devel] buildbot failure in qemu on trivial-patches_x86_64_debian_5_0

2011-07-03 Thread qemu
The Buildbot has detected a new failure on builder 
trivial-patches_x86_64_debian_5_0 while building qemu.
Full details are available at:
 
http://buildbot.b1-systems.de/qemu/builders/trivial-patches_x86_64_debian_5_0/builds/23

Buildbot URL: http://buildbot.b1-systems.de/qemu/

Buildslave for this Build: b1_qemu_1

Build Reason: The Nightly scheduler named 'nightly_trivial-patches' triggered 
this build
Build Source Stamp: [branch trivial-patches] HEAD
Blamelist: 

BUILD FAILED: failed compile

sincerely,
 -The Buildbot



[Qemu-devel] Votre site Web pour 999 DT seulement !

2011-07-03 Thread web agency

PROMOTION SITE WEB

Du 21 juin au 8 juillet 2011



Nous proposons aux entreprises/associations une solution Internet clé en
main à 999 Dinars. Grande ou petite, votre entreprise/association ne peut
plus se passer d’un site internet si elle désire grandir et se faire
connaitre du plus grand nombre. Nous réalisons pour vous un site web
moderne et efficace, entièrement et facilement gérable par vous-même au
meilleur rapport qualité prix.

L'offre comprend:



• 10 pages web.

• Back Office sécurisé : gestion du contenu du site.

• Formulaire de contact

• Une conception graphique moderne

• Module de news

• inscription newsletter

• Moteur de recherche interne

• Galerie photo

• liens vers les réseaux sociaux (facebook, twitter...)

• Module de sondage

• Statistiques de fréquentation

• Images et textes fournis par vos soins 








Commander maintenant :
http://ptf.tweensa.com/link.php?M=4129515&N=111&L=37&F=T






Re: [Qemu-devel] buildbot failure in qemu on disable_kvm_x86_64_debian_5_0

2011-07-03 Thread Stefan Hajnoczi
On Mon, Jul 4, 2011 at 12:47 AM, Alexander Graf  wrote:
>
> On 04.07.2011, at 02:04, q...@buildbot.b1-systems.de wrote:
>
>> The Buildbot has detected a new failure on builder 
>> disable_kvm_x86_64_debian_5_0 while building qemu.
>> Full details are available at:
>> http://buildbot.b1-systems.de/qemu/builders/disable_kvm_x86_64_debian_5_0/builds/148
>>
>> Buildbot URL: http://buildbot.b1-systems.de/qemu/
>>
>> Buildslave for this Build: b1_qemu_1
>>
>> Build Reason: The Nightly scheduler named 'nightly_disable_kvm' triggered 
>> this build
>> Build Source Stamp: [branch master] HEAD
>> Blamelist:
>>
>> BUILD FAILED: failed compile
>
> In file included from /usr/include/png.h:438,
>                 from ui/vnc-enc-tight.c:40:
> /usr/include/pngconf.h:326: error: expected '=', ',', ';', 'asm' or 
> '__attribute__' before '.' token
> /usr/include/pngconf.h:327: error: expected '=', ',', ';', 'asm' or 
> '__attribute__' before 'include'
> make: *** [ui/vnc-enc-tight.o] Error 1
>
> program finished with exit code 2
>
>
> Not sure what exactly is missing, but the last change in that code was from 
> Stefan Weil (2fb0c09f4ff036f68474277ed4edc036f6529de8).

Daniel,
Would it be possible to post the contents of /usr/include/pngconf.h
from b1_qemu_1?  I checked my local copy and I don't understand these
compiler errors.  Perhaps you have a different version of the file.

Thanks,
Stefan



[Qemu-devel] buildbot failure in qemu on xen_x86_64_debian_5_0

2011-07-03 Thread qemu
The Buildbot has detected a new failure on builder xen_x86_64_debian_5_0 while 
building qemu.
Full details are available at:
 http://buildbot.b1-systems.de/qemu/builders/xen_x86_64_debian_5_0/builds/23

Buildbot URL: http://buildbot.b1-systems.de/qemu/

Buildslave for this Build: b1_qemu_1

Build Reason: The Nightly scheduler named 'nightly_xen' triggered this build
Build Source Stamp: [branch xen-next] HEAD
Blamelist: 

BUILD FAILED: failed compile

sincerely,
 -The Buildbot



Re: [Qemu-devel] Wiki spam

2011-07-03 Thread Stefan Hajnoczi
On Mon, Jul 4, 2011 at 12:09 AM, Sune Marcher  wrote:
> sorry if this is the wrong place to post - couldn't find any other contact
> information. Just wanted to let you know that multiple pages of the wiki
> have had spam links added recently, so whoever is in charge might want to
> give the wiki a good scrubbing :)

Thanks.  I have a regular wiki account so I checked the Recent Changes
page and undid the spam changes that I saw:

http://wiki.qemu.org/Special:RecentChanges

Stefan



Re: [Qemu-devel] buildbot failure in qemu on disable_kvm_x86_64_debian_5_0

2011-07-03 Thread Daniel Gollub
On Monday, July 04, 2011 06:23:41 am Stefan Hajnoczi wrote:
> >> BUILD FAILED: failed compile
> > 
> > In file included from /usr/include/png.h:438,
> > from ui/vnc-enc-tight.c:40:
> > /usr/include/pngconf.h:326: error: expected '=', ',', ';', 'asm' or
> > '__attribute__' before '.' token /usr/include/pngconf.h:327: error:
> > expected '=', ',', ';', 'asm' or '__attribute__' before 'include' make:
> > *** [ui/vnc-enc-tight.o] Error 1
> > 
> > program finished with exit code 2
> > 
> > 
> > Not sure what exactly is missing, but the last change in that code was
> > from Stefan Weil (2fb0c09f4ff036f68474277ed4edc036f6529de8).
> 
> Daniel,
> Would it be possible to post the contents of /usr/include/pngconf.h
> from b1_qemu_1?  I checked my local copy and I don't understand these
> compiler errors.  Perhaps you have a different version of the file.

Good catch. 

I readded my Debian 5 x86_64 buildslave to the qemu continous build yesterday. 
Thats the reason of this "regression", which very likely isn't one ...

All the other build failures from last night have the same root cause i guess. 
Because the run for the first time on b1_qemu_1 since a while ...

Stefan, which distro is your slave currently running on?
I guess we should sync up the buildbot factories so we run the same distro. Or 
create a new buildbot factory for Debian Lenny and more recent Distro ...


With regards to pngconf.h:

http://people.b1-systems.de/~gollub/pngconf.h

b1_qemu_1 is still runing Debian 5 (Lenny):
libpng12-dev   1.2.27-2+lenny

Best Regards,
Daniel

-- 
Daniel Gollub
Linux Consultant & Developer
Tel.: +49-160 47 73 970 
Mail: gol...@b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537


signature.asc
Description: This is a digitally signed message part.


Re: [Qemu-devel] buildbot failure in qemu on disable_kvm_x86_64_debian_5_0

2011-07-03 Thread Stefan Weil

Am 04.07.2011 06:23, schrieb Stefan Hajnoczi:

On Mon, Jul 4, 2011 at 12:47 AM, Alexander Graf  wrote:


On 04.07.2011, at 02:04, q...@buildbot.b1-systems.de wrote:

The Buildbot has detected a new failure on builder 
disable_kvm_x86_64_debian_5_0 while building qemu.

Full details are available at:
http://buildbot.b1-systems.de/qemu/builders/disable_kvm_x86_64_debian_5_0/builds/148

Buildbot URL: http://buildbot.b1-systems.de/qemu/

Buildslave for this Build: b1_qemu_1

Build Reason: The Nightly scheduler named 'nightly_disable_kvm' 
triggered this build

Build Source Stamp: [branch master] HEAD
Blamelist:

BUILD FAILED: failed compile


In file included from /usr/include/png.h:438,
from ui/vnc-enc-tight.c:40:
/usr/include/pngconf.h:326: error: expected '=', ',', ';', 'asm' or 
'__attribute__' before '.' token
/usr/include/pngconf.h:327: error: expected '=', ',', ';', 'asm' or 
'__attribute__' before 'include'

make: *** [ui/vnc-enc-tight.o] Error 1

program finished with exit code 2


Not sure what exactly is missing, but the last change in that code 
was from Stefan Weil (2fb0c09f4ff036f68474277ed4edc036f6529de8).


Daniel,
Would it be possible to post the contents of /usr/include/pngconf.h
from b1_qemu_1? I checked my local copy and I don't understand these
compiler errors. Perhaps you have a different version of the file.

Thanks,
Stefan


The compiler errors come again from the setjmp check in pngconf.h:

   __pngconf.h__ in libpng already includes setjmp.h;
   __dont__ include it again.;

The buildbot runs Debian Lenny which includes an old version of libpng.
That version does not use PNG_SKIP_SETJMP_CHECK to skip the setjmp check.
Defining PNG_SETJMP_NOT_SUPPORTED might help with this
version, but I still have to test that.

Updating the buildbot to Debian Squeeze would also work.

Cheers,
Stefan




Re: [Qemu-devel] 80-column rule and breaking output statements

2011-07-03 Thread Amit Shah
On (Sat) 02 Jul 2011 [09:38:30], Stefan Hajnoczi wrote:

...

> I don't see split lines as an issue because I never grep for an entire
> line.  Pick a small, unique, fixed part of the message and you'll find
> it.
> 
> "Small" in order to avoid any formatting or split line issues.

Unless you pick your Small string that was split across multiple lines.

> "Unique" in order to cut down the number of grep results.
> "Fixed" in order to avoid format string expansions as Blue Swirl mentioned.

Amit



Re: [Qemu-devel] [PATCH 3/3] megasas: LSI Megaraid SAS emulation

2011-07-03 Thread Hannes Reinecke

On 07/03/2011 04:36 PM, Paolo Bonzini wrote:

On 07/02/2011 03:50 PM, Hannes Reinecke wrote:

(And no, I will not getting into another dog-fight with Paul B. here.
Virtio can do without bounce buffers. AHCI can. So I fail to see why
SCSI has to rely on bounce buffers.)


I agree, but I do see why a SCSI device might prefer to rely on
bounce buffers for non-I/O commands. This is why in my last RFC
series for vmw_pvscsi I let the device choose whether to force a
bounce buffer or get an external iovec from the HBA.


Yes, sure, for non-I/O commands it's perfectly okay.
Most of which will be emulated anyway.
It's bounce buffers for I/O which kills performance.

But I seem to have missed your last RFC (I'm not reading qemu-devel 
on a regular basis ...).

Care to send me a pointer to it?

Cheers,

Hannes
--
Dr. Hannes Reinecke   zSeries & Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)



Re: [Qemu-devel] buildbot failure in qemu on disable_kvm_x86_64_debian_5_0

2011-07-03 Thread Stefan Hajnoczi
On Mon, Jul 4, 2011 at 6:41 AM, Daniel Gollub  wrote:
> On Monday, July 04, 2011 06:23:41 am Stefan Hajnoczi wrote:
>> >> BUILD FAILED: failed compile
>> >
>> > In file included from /usr/include/png.h:438,
>> >                 from ui/vnc-enc-tight.c:40:
>> > /usr/include/pngconf.h:326: error: expected '=', ',', ';', 'asm' or
>> > '__attribute__' before '.' token /usr/include/pngconf.h:327: error:
>> > expected '=', ',', ';', 'asm' or '__attribute__' before 'include' make:
>> > *** [ui/vnc-enc-tight.o] Error 1
>> >
>> > program finished with exit code 2
>> >
>> >
>> > Not sure what exactly is missing, but the last change in that code was
>> > from Stefan Weil (2fb0c09f4ff036f68474277ed4edc036f6529de8).
>>
>> Daniel,
>> Would it be possible to post the contents of /usr/include/pngconf.h
>> from b1_qemu_1?  I checked my local copy and I don't understand these
>> compiler errors.  Perhaps you have a different version of the file.
>
> Good catch.
>
> I readded my Debian 5 x86_64 buildslave to the qemu continous build yesterday.
> Thats the reason of this "regression", which very likely isn't one ...
>
> All the other build failures from last night have the same root cause i guess.
> Because the run for the first time on b1_qemu_1 since a while ...
>
> Stefan, which distro is your slave currently running on?

yuzuki is running Debian squeeze x86_64.

Stefan



Re: [Qemu-devel] [PATCH 3/3] megasas: LSI Megaraid SAS emulation

2011-07-03 Thread Paolo Bonzini

On 07/04/2011 08:13 AM, Hannes Reinecke wrote:

On 07/03/2011 04:36 PM, Paolo Bonzini wrote:

On 07/02/2011 03:50 PM, Hannes Reinecke wrote:

(And no, I will not getting into another dog-fight with Paul B. here.
Virtio can do without bounce buffers. AHCI can. So I fail to see why
SCSI has to rely on bounce buffers.)


I agree, but I do see why a SCSI device might prefer to rely on
bounce buffers for non-I/O commands. This is why in my last RFC
series for vmw_pvscsi I let the device choose whether to force a
bounce buffer or get an external iovec from the HBA.


Yes, sure, for non-I/O commands it's perfectly okay.
Most of which will be emulated anyway.
It's bounce buffers for I/O which kills performance.

But I seem to have missed your last RFC (I'm not reading qemu-devel on a
regular basis ...).
Care to send me a pointer to it?


Sure, http://lists.gnu.org/archive/html/qemu-devel/2011-06/msg00668.html

Paolo