Re: [Qemu-devel] qemu:virtio-9p: [RFC] [PATCH 01/02] Send iounit to client for read/write operations

2010-06-03 Thread Sripathi Kodi
On Tue,  1 Jun 2010 19:47:14 +0530
"M. Mohan Kumar"  wrote:

> Compute iounit based on the host filesystem block size and pass it to
> client with open/create response. Also return iounit as statfs's f_bsize
> for optimal block size transfers.
> 
> Signed-off-by: M. Mohan Kumar 
> ---
>  hw/virtio-9p.c |   56 
> ++--
>  hw/virtio-9p.h |3 +++
>  2 files changed, 45 insertions(+), 14 deletions(-)
> 
> diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
> index f087122..4357f1f 100644
> --- a/hw/virtio-9p.c
> +++ b/hw/virtio-9p.c
> @@ -1,4 +1,4 @@
> -/*
> + /*
>   * Virtio 9p backend
>   *
>   * Copyright IBM, Corp. 2010
> @@ -269,6 +269,11 @@ static int v9fs_do_fsync(V9fsState *s, int fd)
>  return s->ops->fsync(&s->ctx, fd);
>  }
> 
> +static int v9fs_do_statfs(V9fsState *s, V9fsString *path, struct statfs 
> *stbuf)
> +{
> +return s->ops->statfs(&s->ctx, path->data, stbuf);
> +}
> +
>  static void v9fs_string_init(V9fsString *str)
>  {
>  str->data = NULL;
> @@ -1035,11 +1040,10 @@ static void v9fs_fix_path(V9fsString *dst, V9fsString 
> *src, int len)
> 
>  static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
>  {
> -int32_t msize;
>  V9fsString version;
>  size_t offset = 7;
> 
> -pdu_unmarshal(pdu, offset, "ds", &msize, &version);
> +pdu_unmarshal(pdu, offset, "ds", &s->msize, &version);
> 
>  if (!strcmp(version.data, "9P2000.u")) {
>  s->proto_version = V9FS_PROTO_2000U;
> @@ -1049,7 +1053,7 @@ static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
>  v9fs_string_sprintf(&version, "unknown");
>  }
> 
> -offset += pdu_marshal(pdu, offset, "ds", msize, &version);
> +offset += pdu_marshal(pdu, offset, "ds", s->msize, &version);
>  complete_pdu(s, pdu, offset);
> 
>  v9fs_string_free(&version);
> @@ -1304,6 +1308,20 @@ out:
>  v9fs_walk_complete(s, vs, err);
>  }
> 
> +static int32_t get_iounit(V9fsState *s, V9fsString *name)
> +{
> +struct statfs stbuf;
> +int32_t iounit = 0;
> +
> +
> +if (!v9fs_do_statfs(s, name, &stbuf)) {
> +iounit = stbuf.f_bsize;
> +iounit *= (s->msize - P9_IOHDRSZ)/stbuf.f_bsize;

If (s->msize - P9_IOHDRSZ) is less than stbuf.f_bsize iounit becomes
zero. See below.

> +}
> +
> +return iounit;
> +}
> +
>  static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err)
>  {
>  if (vs->fidp->dir == NULL) {
> @@ -1321,12 +1339,15 @@ out:
> 
>  static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
>  {
> +int32_t iounit;
> +
>  if (vs->fidp->fd == -1) {
>  err = -errno;
>  goto out;
>  }
> 
> -vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
> +iounit = get_iounit(s, &vs->fidp->path);
> +vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, iounit);
>  err = vs->offset;
>  out:
>  complete_pdu(s, vs->pdu, err);
> @@ -1800,11 +1821,16 @@ out:
> 
>  static void v9fs_post_create(V9fsState *s, V9fsCreateState *vs, int err)
>  {
> +int32_t iounit;
> +
> +iounit = get_iounit(s, &vs->fidp->path);
> +
>  if (err == 0) {
>  v9fs_string_copy(&vs->fidp->path, &vs->fullname);
>  stat_to_qid(&vs->stbuf, &vs->qid);
> 
> -vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, 0);
> +vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid,
> +iounit);
> 
>  err = vs->offset;
>  }
> @@ -2295,23 +2321,25 @@ out:
>  qemu_free(vs);
>  }
> 
> -static int v9fs_do_statfs(V9fsState *s, V9fsString *path, struct statfs 
> *stbuf)
> -{
> -return s->ops->statfs(&s->ctx, path->data, stbuf);
> -}
> -
>  static void v9fs_statfs_post_statfs(V9fsState *s, V9fsStatfsState *vs, int 
> err)
>  {
> +int32_t bsize_factor;
> +
>  if (err) {
>  err = -errno;
>  goto out;
>  }
> 
> +bsize_factor = (s->msize - P9_IOHDRSZ)/vs->stbuf.f_bsize;
> +if (!bsize_factor) {
> +bsize_factor = 1;
> +}

Again, if (s->msize - P9_IOHDRSZ) is less than stbuf.f_bsize
bsize_factor becomes zero. The following divisions become divide by
zero!

Thanks,
Sripathi.

>  vs->v9statfs.f_type = vs->stbuf.f_type;
>  vs->v9statfs.f_bsize = vs->stbuf.f_bsize;
> -vs->v9statfs.f_blocks = vs->stbuf.f_blocks;
> -vs->v9statfs.f_bfree = vs->stbuf.f_bfree;
> -vs->v9statfs.f_bavail = vs->stbuf.f_bavail;
> +vs->v9statfs.f_bsize *= bsize_factor;
> +vs->v9statfs.f_blocks = vs->stbuf.f_blocks/bsize_factor;
> +vs->v9statfs.f_bfree = vs->stbuf.f_bfree/bsize_factor;
> +vs->v9statfs.f_bavail = vs->stbuf.f_bavail/bsize_factor;
>  vs->v9statfs.f_files = vs->stbuf.f_files;
>  vs->v9statfs.f_ffree = vs->stbuf.f_ffree;
>  vs->v9statfs.fsid_val = (unsigned int) vs->stbuf.f_fsid.__val[0] |
> diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
> index 6b3d4a4..9264163 100644
> --- a/hw/virtio-9p.h
> +++ b/hw/virtio-9p.h
> @

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

2010-06-03 Thread Jes Sorensen
On 06/03/10 22:58, Richard Henderson wrote:
> On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
>> +/*
>> + * Duplicate definition from vl.c to avoid messing up the entire build
>> + */
>> +enum {
>> +#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
>> +opt_enum,
>> +#define DEFHEADING(text)
>> +#include "qemu-options.h"
>> +#undef DEF
>> +#undef DEFHEADING
>> +#undef GEN_DOCS
>> +};
> 
> There's no header file you can put this in?  Or invent to put this in?
> Cause this is really kinda gross...
> 

The problem is that it requires qemu-options.h to be included, which
isn't included per default for all the files. If I put it into sysemu.h
at least it's going to require making every .c file build with those flags.

I agree it's gross, but I am not sure what would be a better solution.

>> +default:
>> +ret = -1;
>> +}
>> +return ret;
>> +}
> 
> Why have a return value at all...
> 
>> +default:
>> +os_parse_cmd_args(popt, optarg);
> 
> ... if you're going to ignore the results?

I was trying to make it forward looking, but yeah we can just kill that.

Cheers,
Jes



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

2010-06-03 Thread Jes Sorensen
On 06/03/10 23:02, Richard Henderson wrote:
> On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
>> +static inline void os_change_root(void) {};
> 
> You really like the ";", don't you.  ;-)

LOL now I get it.

Yes, ;'s are so pretty ;-)

I'll clean it up and send out a new version. Still not sure about the
enmu but the rest is straight forward to handle.

Cheers,
Jes





[Qemu-devel] Re: [PATCH 2/4] Add virtio disk identification support

2010-06-03 Thread john cooper
Anthony Liguori wrote:
> On 03/25/2010 12:33 AM, john cooper wrote:
>> Fix bug which truncated serial string to 8 bytes, nul terminate.
>>
>> Signed-off-by: john cooper
>> ---
>>
>> diff --git a/vl.c b/vl.c
>> index d69250c..b74cbba 100644
>> --- a/vl.c
>> +++ b/vl.c
>> @@ -1162,7 +1162,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
>>   dinfo->on_write_error = on_write_error;
>>   dinfo->opts = opts;
>>   if (serial)
>> -strncpy(dinfo->serial, serial, sizeof(serial));
>> +strncpy(dinfo->serial, serial, sizeof(dinfo->serial) - 1);
>>
> 
> You need to explicitly add a null terminator.  Far better to just never
> use strncpy().

As previous this is a case where dinfo->serial[] is defined
as BLOCK_SERIAL_STRLEN + 1 bytes as an internal convenience.
Above the context of the patch here is a:

dinfo = qemu_mallocz(sizeof(*dinfo));

which assures this will do as intended, namely copy all
potential BLOCK_SERIAL_STRLEN bytes and assure they are
nul terminated should the full length be present.

I didn't conjure up the existing logic but rather am 
trying to peacefully coexist with it.

-john

-- 
john.coo...@redhat.com



[Qemu-devel] Re: [PATCH 1/4] Add virtio disk identification support

2010-06-03 Thread john cooper
Anthony Liguori wrote:
> On 03/25/2010 12:32 AM, john cooper wrote:
>> Add virtio-blk device id (s/n) support via virtio request.
>> Remove artifacts of pci and ATA_IDENTIFY implementation
>> relative to prior versions.
>>
>> Signed-off-by: john cooper
>> ---
>>
>> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
>> index 9915840..358b0af 100644
>> --- a/hw/virtio-blk.c
>> +++ b/hw/virtio-blk.c
>> @@ -19,6 +19,8 @@
>>   # include
>>   #endif
>>
>> +#define min(a,b) ((a)<  (b) ? (a) : (b))
>>
> 
> We already have MIN().
> 
>> +
>>   typedef struct VirtIOBlock
>>   {
>>   VirtIODevice vdev;
>> @@ -28,6 +30,7 @@ typedef struct VirtIOBlock
>>   QEMUBH *bh;
>>   BlockConf *conf;
>>   unsigned short sector_mask;
>> +char sn[BLOCK_SERIAL_STRLEN];
>>   } VirtIOBlock;
>>
>>   static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
>> @@ -317,6 +320,12 @@ static void
>> virtio_blk_handle_request(VirtIOBlockReq *req,
>>   virtio_blk_handle_flush(req);
>>   } else if (req->out->type&  VIRTIO_BLK_T_SCSI_CMD) {
>>   virtio_blk_handle_scsi(req);
>> +} else if (req->out->type&  VIRTIO_BLK_T_GET_ID) {
>> +VirtIOBlock *s = req->dev;
>> +
>> +memcpy(req->elem.in_sg[0].iov_base, s->sn,
>> +   min(req->elem.in_sg[0].iov_len, sizeof(s->sn)));
>> +virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
>>   } else if (req->out->type&  VIRTIO_BLK_T_OUT) {
>>   qemu_iovec_init_external(&req->qiov,&req->elem.out_sg[1],
>>req->elem.out_num - 1);
>> @@ -496,6 +505,8 @@ VirtIODevice *virtio_blk_init(DeviceState *dev,
>> BlockConf *conf)
>>   bdrv_guess_geometry(s->bs,&cylinders,&heads,&secs);
>>   bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);
>>
>> +strncpy(s->sn, drive_get_serial(s->bs), sizeof (s->sn));
>> +
>>
> 
> Friends don't let friends use strncpy().
> 
> This actually will result in a non-NULL terminated string if
> drive_get_serial() returns a string larger than s->sn.  Use snprintf()
> instead.

That actually is the desired behavior here as a serial
string is of BLOCK_SERIAL_STRLEN bytes length maximum
and not assured to be nul terminated (legacy ATA convention).
snprintf() would cause us to lose the last string character
in the case the full BLOCK_SERIAL_STRLEN bytes were in use.

There are existing storage allocations of BLOCK_SERIAL_STRLEN + 1
in some cases but this appears as an internal convenience
and is not part of the serial string data.

-john

-- 
john.coo...@redhat.com



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

2010-06-03 Thread Jes Sorensen
On 06/03/10 22:50, Richard Henderson wrote:
> On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
>> --- a/sysemu.h
>> +++ b/sysemu.h
>> @@ -79,6 +79,9 @@ int qemu_loadvm_state(QEMUFile *f);
>>  /* SLIRP */
>>  void do_info_slirp(Monitor *mon);
>>  
>> +/* OS specific functions */
>> +void os_setup_signal_handling(void);
>> +
> 
> Can this go in your qemu-os-posix.h?

Seems reasonable, must be a leftover from earlier.

Cheers,
Jes



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

2010-06-03 Thread Jes Sorensen
On 06/03/10 22:52, Richard Henderson wrote:
> On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
>> --- a/qemu-os-win32.h
>> +++ b/qemu-os-win32.h
>> @@ -41,4 +41,7 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc 
>> *func, void *opaque);
>>  void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void 
>> *opaque);
>>  
>>  void os_host_main_loop_wait(int *timeout);
>> +
>> +static inline void os_setup_signal_handling(void) {};
> 
> Stray ;

Sorry, not sure what you mean here?

Jes



Re: [Qemu-devel] [PATCH 2/2] tcg-i386: Use segment registers to implement GUEST_BASE.

2010-06-03 Thread Alexander Graf

On 04.06.2010, at 02:35, Richard Henderson wrote:

> For 32-bit, using a segment override is smaller than the 4-byte
> immediate offset.  For 64-bit, segments can hold the entire 64-bit
> offset whereas the 4-byte immediate cannot.

Very nice idea indeed :). Have you found it to be faster? IIRC segment accesses 
are slower when seg_offs != 0. But then again the code is smaller, so it might 
weigh it up.

> Only implemented for linux, with fallback to the immediate offset
> if the system call fails.
> 
> Signed-off-by: Richard Henderson 
> ---
> tcg/i386/tcg-target.c |  206 +++-
> 1 files changed, 150 insertions(+), 56 deletions(-)
> 
> diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
> index fab2a30..e34254f 100644
> --- a/tcg/i386/tcg-target.c
> +++ b/tcg/i386/tcg-target.c
> @@ -240,6 +240,8 @@ static inline int tcg_target_const_match(tcg_target_long 
> val,
> # define P_REXB_R 0
> # define P_REXB_RM0
> #endif
> +#define P_FS 0x4000
> +#define P_GS 0x8000
> 
> #define OPC_ARITH_EvIz(0x81)
> #define OPC_ARITH_EvIb(0x83)
> @@ -347,11 +349,29 @@ static const uint8_t tcg_cond_to_jcc[10] = {
> [TCG_COND_GTU] = JCC_JA,
> };
> 
> +static inline void tcg_out_seg_prefix(TCGContext *s, int opc)
> +{
> +switch (opc & (P_FS | P_GS)) {
> +case 0:
> +break;
> +case P_FS:
> +tcg_out8(s, 0x64);
> +break;
> +case P_GS:
> +tcg_out8(s, 0x65);
> +break;
> +default:
> +tcg_abort();
> +}
> +}
> +
> #if TCG_TARGET_REG_BITS == 64
> static void tcg_out_opc(TCGContext *s, int opc, int r, int rm, int x)
> {
> int rex;
> 
> +tcg_out_seg_prefix(s, opc);
> +
> if (opc & P_DATA16) {
> /* We should never be asking for both 16 and 64-bit operation.  */
> assert((opc & P_REXW) == 0);
> @@ -387,6 +407,8 @@ static void tcg_out_opc(TCGContext *s, int opc, int r, 
> int rm, int x)
> #else
> static void tcg_out_opc(TCGContext *s, int opc)
> {
> +tcg_out_seg_prefix(s, opc);
> +
> if (opc & P_DATA16) {
> tcg_out8(s, 0x66);
> }
> @@ -956,6 +978,48 @@ static void tcg_out_jmp(TCGContext *s, tcg_target_long 
> dest)
> tcg_out_branch(s, 0, dest);
> }
> 
> +#ifndef GUEST_BASE
> +#define GUEST_BASE 0
> +#endif
> +
> +#if defined(__x86_64__) && defined(__linux__)
> +# include 
> +# include 
> +
> +static int guest_base_flags;
> +static inline void setup_guest_base_seg(void)
> +{
> +if (syscall(__NR_arch_prctl, ARCH_SET_GS, GUEST_BASE) == 0) {
> +guest_base_flags = P_GS;

I'd like to see a comment here stating that FS is used for TLS.

> +}
> +}
> +#elif defined(__i386__) && defined(__linux__)
> +# include 
> +# include 
> +
> +static int guest_base_flags;
> +static inline void setup_guest_base_seg(void)
> +{
> +struct user_desc d;
> +
> +memset(&d, 0, sizeof(d));
> +d.entry_number = -1;/* let the kernel choose */
> +d.base_addr = GUEST_BASE;
> +d.limit = 0xf;  /* 4GB segment */
> +d.seg_32bit = 1;
> +d.limit_in_pages = 1;
> +d.useable = 1;
> +
> +if (syscall(__NR_set_thread_area, &d) == 0) {
> +asm volatile("movw %w0, %%fs" : : "r"(d.entry_number * 8 + 3));

Same here for %gs.

[snip]

> @@ -1945,6 +2031,14 @@ static void tcg_target_qemu_prologue(TCGContext *s)
> tcg_out_pop(s, tcg_target_callee_save_regs[i]);
> }
> tcg_out_opc(s, OPC_RET, 0, 0, 0);
> +
> +/* Try to set up %fs or %gs (whichever isn't already used for TLS)
> +   to point to GUEST_BASE.  The 1-byte segment override prefix is
> +   always smaller than the 4-byte offset we'd have to encode into
> +   the address, and is also able to handle the full 64-bit offset.  */

Ah, so that's where the comment hides. Uh. Better be safe than sorry and have 
it in both locations, no? :)

Alex




[Qemu-devel] [PATCH] virtio-9p: Return correct error from v9fs_remove

2010-06-03 Thread Sripathi Kodi
This patch got mangled last time. Resending.

virtio-9p: Return correct error from v9fs_remove

In v9fs_remove_post_remove() we currently ignore the error returned by
the previous call to remove() and return an error only if freeing the
fid fails. However, the client expects to see the error from remove().
Currently the client falsely thinks that the remove call has always
succeeded. For example, doing rmdir on a non-empty directory does
not return ENOTEMPTY.

With this patch we ignore the error from free_fid(). The client cannot
use this error value anyway.

Signed-off-by: Sripathi Kodi 
---

 hw/virtio-9p.c |   11 ++-
 1 files changed, 6 insertions(+), 5 deletions(-)


diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index e5d0112..999c0d5 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1943,14 +1943,15 @@ typedef struct V9fsRemoveState {
 static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs,
 int err)
 {
-/* For TREMOVE we need to clunk the fid even on failed remove */
-err = free_fid(s, vs->fidp->fid);
 if (err < 0) {
-goto out;
+err = -errno;
+} else {
+err = vs->offset;
 }
 
-err = vs->offset;
-out:
+/* For TREMOVE we need to clunk the fid even on failed remove */
+free_fid(s, vs->fidp->fid);
+
 complete_pdu(s, vs->pdu, err);
 qemu_free(vs);
 }



[Qemu-devel] [Bug 575887] Re: VNC heap corruption at 1400x1050 (with % 16 != 0)

2010-06-03 Thread sciencewhiz
Where can I find a list of supported QEMU resolutions?

-- 
VNC heap corruption at 1400x1050 (with % 16 != 0)
https://bugs.launchpad.net/bugs/575887
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Invalid

Bug description:
vnc_refresh_server_surface assumes that the display width
is a multiple of 16.  If it's not, then it accesses beyond the end of the row
by a few bytes.  On all but the last row, this is mostly harmless (it can
result in unnecessarily marking the end of the row dirty), but on the last row,
it copies over heap metadata.  This triggers a crash when changing resolutions 
or disconnecting and reconnecting a client.

I can trigger this reliably with a Windows 7 guest at 1400x1050 with -vga std.

The attached patch (rather ugly, with debugging code for good measure) 
partially fixes the issue.  There's still a black stripe on the right side of 
the screen, presumably because there are other bugs in vnc.c (or I messed up 
the patch).

I'm marking this as a security vulnerability because it allows the guest to 
overwrite host memory.

The same issue is tracked in Red Hat's bugzilla here:
https://bugzilla.redhat.com/show_bug.cgi?id=583850





[Qemu-devel] Re: [PATCHv3 1/2] virtio: support layout with avail ring before idx

2010-06-03 Thread Rusty Russell
On Wed, 2 Jun 2010 12:17:12 am Michael S. Tsirkin wrote:
> This adds an (unused) option to put available ring before control (avail
> index, flags), and adds padding between index and flags. This avoids
> cache line sharing between control and ring, and also makes it possible
> to extend avail control without incurring extra cache misses.
> 
> Signed-off-by: Michael S. Tsirkin 

No no no no.  254?  You're trying to Morton me![1]

How's this (untested):

diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h
--- a/include/linux/virtio_ring.h
+++ b/include/linux/virtio_ring.h
@@ -74,8 +74,8 @@ struct vring {
 /* The standard layout for the ring is a continuous chunk of memory which looks
  * like this.  We assume num is a power of 2.
  *
- * struct vring
- * {
+ * struct vring {
+ * *** The driver writes to this part.
  * // The actual descriptors (16 bytes each)
  * struct vring_desc desc[num];
  *
@@ -84,9 +84,11 @@ struct vring {
  * __u16 avail_idx;
  * __u16 available[num];
  *
- * // Padding to the next align boundary.
+ * // Padding so used_flags is on the next align boundary.
  * char pad[];
+ * __u16 last_used; // On a cacheline of its own.
  *
+ * *** The device writes to this part.
  * // A ring of used descriptor heads with free-running index.
  * __u16 used_flags;
  * __u16 used_idx;
@@ -110,6 +112,12 @@ static inline unsigned vring_size(unsign
+ sizeof(__u16) * 2 + sizeof(struct vring_used_elem) * num;
 }
 
+/* Last used index sits at the very end of the driver part of the struct */
+static inline __u16 *vring_last_used_idx(const struct vring *vr)
+{
+   return (__u16 *)vr->used - 1;
+}
+
 #ifdef __KERNEL__
 #include 
 struct virtio_device;

Cheers,
Rusty.
[1] Andrew Morton has this technique where he posts a solution so ugly it
forces others to fix it properly.  Ego-roping, basically.



[Qemu-devel] [Bug 588748] Re: QEMU fails to boot DR DOS Plus since 0.6.1

2010-06-03 Thread Roy Tam
> Can you add some debugging to see what IER is being set to?

With DEBUG_SERIAL defined, serial logs:
serial: event 2
serial: write addr=0x01 val=0x02
serial: read addr=0x01 val=0x02
serial: read addr=0x02 val=0x02
serial: write addr=0x01 val=0x00
serial: write addr=0x03 val=0x80
serial: write addr=0x00 val=0x0c
serial: write addr=0x01 val=0x00
serial: write addr=0x03 val=0x03
serial: write addr=0x04 val=0x0b
serial: read addr=0x05 val=0x60
serial: read addr=0x06 val=0xb0
serial: read addr=0x00 val=0x00
serial: write addr=0x01 val=0x0f
serial: read addr=0x02 val=0x02
serial: read addr=0x02 val=0x01
(stalls here)

-- 
QEMU fails to boot DR DOS Plus since 0.6.1
https://bugs.launchpad.net/bugs/588748
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: In Progress

Bug description:
The commit in r1049 (serial interrupt fix (Hampa Hug)) prevents booting Digital 
Research DOS Plus.





Re: [Qemu-devel] [PATCH -V4 3/7] virtio-9p: modify create/open2 and mkdir for new security model.

2010-06-03 Thread Venkateswararao Jujjuri (JV)
Aneesh Kumar K.V wrote:
> On Wed, May 26, 2010 at 04:21:42PM -0700, Venkateswararao Jujjuri (JV) wrote:
>> Add required infrastructure and modify create/open2 and mkdir per the new
>> security model.
>>
>> Signed-off-by: Venkateswararao Jujjuri 
>> ---
>>  hw/file-op-9p.h  |   23 +++-
>>  hw/virtio-9p-local.c |  149 
>> --
>>  hw/virtio-9p.c   |   42 ++
>>  3 files changed, 158 insertions(+), 56 deletions(-)
>>
>> diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
>> index 2934ff1..73d59b2 100644
>> --- a/hw/file-op-9p.h
>> +++ b/hw/file-op-9p.h
>> @@ -19,13 +19,32 @@
>>  #include 
>>  #include 
>>  #include 
>> +#define SM_LOCAL_MODE_BITS0600
>> +#define SM_LOCAL_DIR_MODE_BITS0700
>> +
>> +typedef enum
>> +{
>> +SM_PASSTHROUGH = 1, /* uid/gid set on fileserver files */
>> +SM_MAPPED,  /* uid/gid part of xattr */
>> +} SecModel;
>> +
>> +typedef struct FsCred
>> +{
>> +uid_t   fc_uid;
>> +gid_t   fc_gid;
>> +mode_t  fc_mode;
>> +dev_t   fc_rdev;
>> +} FsCred;
>>  
>>  typedef struct FsContext
>>  {
>>  char *fs_root;
>> +SecModel fs_sm;
>>  uid_t uid;
>>  } FsContext;
>>  
>> +extern void cred_init(FsCred *);
>> +
>>  typedef struct FileOperations
>>  {
>>  int (*lstat)(FsContext *, const char *, struct stat *);
>> @@ -43,7 +62,7 @@ typedef struct FileOperations
>>  int (*closedir)(FsContext *, DIR *);
>>  DIR *(*opendir)(FsContext *, const char *);
>>  int (*open)(FsContext *, const char *, int);
>> -int (*open2)(FsContext *, const char *, int, mode_t);
>> +int (*open2)(FsContext *, const char *, int, FsCred *);
>>  void (*rewinddir)(FsContext *, DIR *);
>>  off_t (*telldir)(FsContext *, DIR *);
>>  struct dirent *(*readdir)(FsContext *, DIR *);
>> @@ -51,7 +70,7 @@ typedef struct FileOperations
>>  ssize_t (*readv)(FsContext *, int, const struct iovec *, int);
>>  ssize_t (*writev)(FsContext *, int, const struct iovec *, int);
>>  off_t (*lseek)(FsContext *, int, off_t, int);
>> -int (*mkdir)(FsContext *, const char *, mode_t);
>> +int (*mkdir)(FsContext *, const char *, FsCred *);
>>  int (*fstat)(FsContext *, int, struct stat *);
>>  int (*rename)(FsContext *, const char *, const char *);
>>  int (*truncate)(FsContext *, const char *, off_t);
>> diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
>> index 78960ac..f6c2fe2 100644
>> --- a/hw/virtio-9p-local.c
>> +++ b/hw/virtio-9p-local.c
>> @@ -17,6 +17,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  
>>  static const char *rpath(FsContext *ctx, const char *path)
>>  {
>> @@ -31,47 +32,39 @@ static int local_lstat(FsContext *ctx, const char *path, 
>> struct stat *stbuf)
>>  return lstat(rpath(ctx, path), stbuf);
>>  }
>>  
>> -static int local_setuid(FsContext *ctx, uid_t uid)
>> +static int local_set_xattr(const char *path, FsCred *credp)
>>  {
>> -struct passwd *pw;
>> -gid_t groups[33];
>> -int ngroups;
>> -static uid_t cur_uid = -1;
>> -
>> -if (cur_uid == uid) {
>> -return 0;
>> -}
>> -
>> -if (setreuid(0, 0)) {
>> -return -1;
>> -}
>> -
>> -pw = getpwuid(uid);
>> -if (pw == NULL) {
>> -return -1;
>> +int err;
>> +if (credp->fc_uid != -1) {
>> +err = setxattr(path, "user.virtfs.uid", &credp->fc_uid, 
>> sizeof(uid_t),
>> +0);
>> +if (err) {
>> +return err;
>> +}
>>  }
>> -
>> -ngroups = 33;
>> -if (getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups) == -1) {
>> -return -1;
>> +if (credp->fc_gid != -1) {
>> +err = setxattr(path, "user.virtfs.gid", &credp->fc_gid, 
>> sizeof(gid_t),
>> +0);
>> +if (err) {
>> +return err;
>> +}
>>  }
>> -
>> -if (setgroups(ngroups, groups)) {
>> -return -1;
>> -}
>> -
>> -if (setregid(-1, pw->pw_gid)) {
>> -return -1;
>> +if (credp->fc_mode != -1) {
>> +err = setxattr(path, "user.virtfs.mode", &credp->fc_mode,
>> +sizeof(mode_t), 0);
>> +if (err) {
>> +return err;
>> +}
>>  }
>> -
>> -if (setreuid(-1, uid)) {
>> -return -1;
>> +if (credp->fc_rdev != -1) {
>> +err = setxattr(path, "user.virtfs.rdev", &credp->fc_rdev,
>> +sizeof(dev_t), 0);
>> +if (err) {
>> +return err;
>> +}
>>  }
>> -
>> -cur_uid = uid;
>> -
>> -return 0;
>> -}
>> + return 0;
>> + }
>>  
>>  static ssize_t local_readlink(FsContext *ctx, const char *path,
>>  char *buf, size_t bufsz)
>> @@ -168,9 +161,44 @@ static int local_mksock(FsContext *ctx2, const char 
>> *path)
>>  return 0;
>>  }
>>  
>> -static int local_mkdir(FsContext *ctx, const char *path, mode_t mode)
>> +static int local_mkdir(FsContext *fs_ctx, const char *path, FsCred *cr

[Qemu-devel] [PATCH 2/2] tcg-i386: Use segment registers to implement GUEST_BASE.

2010-06-03 Thread Richard Henderson
For 32-bit, using a segment override is smaller than the 4-byte
immediate offset.  For 64-bit, segments can hold the entire 64-bit
offset whereas the 4-byte immediate cannot.

Only implemented for linux, with fallback to the immediate offset
if the system call fails.

Signed-off-by: Richard Henderson 
---
 tcg/i386/tcg-target.c |  206 +++-
 1 files changed, 150 insertions(+), 56 deletions(-)

diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
index fab2a30..e34254f 100644
--- a/tcg/i386/tcg-target.c
+++ b/tcg/i386/tcg-target.c
@@ -240,6 +240,8 @@ static inline int tcg_target_const_match(tcg_target_long 
val,
 # define P_REXB_R  0
 # define P_REXB_RM 0
 #endif
+#define P_FS   0x4000
+#define P_GS   0x8000
 
 #define OPC_ARITH_EvIz (0x81)
 #define OPC_ARITH_EvIb (0x83)
@@ -347,11 +349,29 @@ static const uint8_t tcg_cond_to_jcc[10] = {
 [TCG_COND_GTU] = JCC_JA,
 };
 
+static inline void tcg_out_seg_prefix(TCGContext *s, int opc)
+{
+switch (opc & (P_FS | P_GS)) {
+case 0:
+break;
+case P_FS:
+tcg_out8(s, 0x64);
+break;
+case P_GS:
+tcg_out8(s, 0x65);
+break;
+default:
+tcg_abort();
+}
+}
+
 #if TCG_TARGET_REG_BITS == 64
 static void tcg_out_opc(TCGContext *s, int opc, int r, int rm, int x)
 {
 int rex;
 
+tcg_out_seg_prefix(s, opc);
+
 if (opc & P_DATA16) {
 /* We should never be asking for both 16 and 64-bit operation.  */
 assert((opc & P_REXW) == 0);
@@ -387,6 +407,8 @@ static void tcg_out_opc(TCGContext *s, int opc, int r, int 
rm, int x)
 #else
 static void tcg_out_opc(TCGContext *s, int opc)
 {
+tcg_out_seg_prefix(s, opc);
+
 if (opc & P_DATA16) {
 tcg_out8(s, 0x66);
 }
@@ -956,6 +978,48 @@ static void tcg_out_jmp(TCGContext *s, tcg_target_long 
dest)
 tcg_out_branch(s, 0, dest);
 }
 
+#ifndef GUEST_BASE
+#define GUEST_BASE 0
+#endif
+
+#if defined(__x86_64__) && defined(__linux__)
+# include 
+# include 
+
+static int guest_base_flags;
+static inline void setup_guest_base_seg(void)
+{
+if (syscall(__NR_arch_prctl, ARCH_SET_GS, GUEST_BASE) == 0) {
+guest_base_flags = P_GS;
+}
+}
+#elif defined(__i386__) && defined(__linux__)
+# include 
+# include 
+
+static int guest_base_flags;
+static inline void setup_guest_base_seg(void)
+{
+struct user_desc d;
+
+memset(&d, 0, sizeof(d));
+d.entry_number = -1;/* let the kernel choose */
+d.base_addr = GUEST_BASE;
+d.limit = 0xf;  /* 4GB segment */
+d.seg_32bit = 1;
+d.limit_in_pages = 1;
+d.useable = 1;
+
+if (syscall(__NR_set_thread_area, &d) == 0) {
+asm volatile("movw %w0, %%fs" : : "r"(d.entry_number * 8 + 3));
+guest_base_flags = P_FS;
+}
+}
+#else
+# define guest_base_flags   0
+static inline void setup_guest_base_seg(void) { }
+#endif
+
 #if defined(CONFIG_SOFTMMU)
 
 #include "../../softmmu_defs.h"
@@ -1056,37 +1120,41 @@ static inline void tcg_out_tlb_load(TCGContext *s, int 
addrlo_idx,
 #endif
 
 static void tcg_out_qemu_ld_direct(TCGContext *s, int datalo, int datahi,
-   int base, tcg_target_long ofs, int sizeop)
+   int base, tcg_target_long ofs, int sizeop,
+   int prefix)
 {
 #ifdef TARGET_WORDS_BIGENDIAN
 const int bswap = 1;
 #else
 const int bswap = 0;
 #endif
+int rexw = (TARGET_LONG_BITS == 64 ? P_REXW : 0);
+
 switch (sizeop) {
 case 0:
-tcg_out_modrm_offset(s, OPC_MOVZBL, datalo, base, ofs);
+tcg_out_modrm_offset(s, OPC_MOVZBL + prefix, datalo, base, ofs);
 break;
 case 0 | 4:
-tcg_out_modrm_offset(s, OPC_MOVSBL + P_REXW, datalo, base, ofs);
+tcg_out_modrm_offset(s, OPC_MOVSBL + prefix + rexw, datalo, base, ofs);
 break;
 case 1:
-tcg_out_modrm_offset(s, OPC_MOVZWL, datalo, base, ofs);
+tcg_out_modrm_offset(s, OPC_MOVZWL + prefix, datalo, base, ofs);
 if (bswap) {
 tcg_out_rolw_8(s, datalo);
 }
 break;
 case 1 | 4:
 if (bswap) {
-tcg_out_modrm_offset(s, OPC_MOVZWL, datalo, base, ofs);
+tcg_out_modrm_offset(s, OPC_MOVZWL + prefix, datalo, base, ofs);
 tcg_out_rolw_8(s, datalo);
-tcg_out_modrm(s, OPC_MOVSWL + P_REXW, datalo, datalo);
+tcg_out_modrm(s, OPC_MOVSWL + rexw, datalo, datalo);
 } else {
-tcg_out_modrm_offset(s, OPC_MOVSWL + P_REXW, datalo, base, ofs);
+tcg_out_modrm_offset(s, OPC_MOVSWL + prefix + rexw,
+ datalo, base, ofs);
 }
 break;
 case 2:
-tcg_out_ld(s, TCG_TYPE_I32, datalo, base, ofs);
+tcg_out_modrm_offset(s, OPC_MOVL_GvEv + prefix, datalo, base, ofs);
 if (bswap) {
 tcg_out_bswap32(s, datalo);
 }
@@

[Qemu-devel] [PATCH 0/2] tcg-i386: merge 64-bit, guest_base improvement

2010-06-03 Thread Richard Henderson
This patch series is dependent on the "tcg cleanups, part 4"
patch series.

The first patch merges the 64-bit code generator with the cleaned-up
32-bit code generator.  I think the result is going to be easier to
maintain than the two generators separately.  I've spot-checked the
code for 32-bit at -O2; I think the compiler has done a good job
compiling away the 64-bit parts.

The second patch uses the segmentation registers to implement GUEST_BASE.
This is only a mild space-savings for 32-bit (3 bytes per guest access),
but for 64-bit it can be very helpful.  Consider the new -R option for
reserving an address-space:

Reserved 0x8000 bytes of guest address space
host mmap_min_addr=0x1000
guest_base  0x7fff74be1000

The area the OS reserved for us often turns out to be in high memory.
Before this patch, we wind up emitting

  movq $large,%rax
  addq %addr,%rax

The reduction by using a segment register is 11 bytes (and 2 insns)
per guest access.



r~



Richard Henderson (2):
  tcg-i386: Merge 64-bit generation.
  tcg-i386: Use segment registers to implement GUEST_BASE.

 configure   |2 +
 tcg/i386/tcg-target.c   | 1276 ++---
 tcg/i386/tcg-target.h   |   61 ++-
 tcg/x86_64/tcg-target.c | 1445 ---
 tcg/x86_64/tcg-target.h |  101 
 5 files changed, 996 insertions(+), 1889 deletions(-)
 delete mode 100644 tcg/x86_64/tcg-target.c
 delete mode 100644 tcg/x86_64/tcg-target.h




Re: [Qemu-devel] Arm big endian?

2010-06-03 Thread Rob Landley
On Thursday 03 June 2010 02:52:03 Paul Brook wrote:
> > I'm trying to get arm big endian support to work.  I patched the 2.6.33
> > kernel to pretend that good old versatilepb can have a big endian CPU
> > plugged into it (attached), and then I built a kernel with the attached
> > .config, and qemu went "boing":
>
> That's about the result I'd expect. The fact that neither qemu nor linux
> claim to support big-endian mode for this hardware should be your first
> clue.

Understood.  I there a better emulation to try?

When you say "this hardware" do you mean the board, or do you mean big endian 
arm as a CPU?  Because there _is_ a qemu-armeb.  There isn't a qemu-system-
armeb that I'm aware of, but I thought it autodetected endianness at least for 
the CPU...)

If it's the board, I did that because versatilepb has essentially been the 
generic board emulation I've plugged all the other arm variants into.  There 
isn't a -M ip4xx that I'm aware of.  (I can try configuring a kernel with just 
serial console and see if I can get that to boot, and then add back net and 
disk and such one at a time, if that might be a reasonable approach...)

> > Does this look more like a kernel error, or a qemu error?
>
> Probably both.

If I could just get them to agree, I'd be happy.  I just want a setup that can 
run a big endian arm userspace under system emulation (with network, serial 
console, clock, and disk).  Emulating a feasible board would be a nice bonus, 
but not actually a goal.

> Paul

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds



[Qemu-devel] I would like to do the link exchange with you.

2010-06-03 Thread Cheapest Rooms
Title: Untitled Document





Hi,
  
  My name is Mark. I recently came across your website http://nongnu.org/ through  search engine and found it is informative for our website's visitors.
  I would like to exchange link with our websites  CheapestRoomsLondon.co.uk  and CheapRoomsLondon.co.uk.
  
  As you are probably aware, reciprocal linking benefits both of us by raising  the search engine rankings and generating more traffic to both of our websites.
  
  If you would like to do the link exchange with us, please place our link on  your website with the following details.
Title: CheapestRoomsLondon
  Description: Find cheapest rooms to rent in London
Link: http://www.cheapestroomslondon.co.uk/
Title :  CheapRoomsLondon
  Desc : Find rooms with cheap rent in London.
  Url : http://www.cheaproomslondon.co.uk/
  
  Then, please inform me by replying to this email with your details (title and  description).
   
  Look forward to hearing from you.
  
  Best regards,
  Mark Jain






Re: [Qemu-devel] [PATCH -V4 1/7] virtio-9p: Introduces an option to specify the security model.

2010-06-03 Thread Venkateswararao Jujjuri (JV)
Aneesh Kumar K.V wrote:
> On Wed, May 26, 2010 at 04:21:40PM -0700, Venkateswararao Jujjuri (JV) wrote:
>> The new option is:
>>
>> -fsdev fstype,id=myid,path=/share_path/,security_model=[mapped|passthrough]
>> -virtfs 
>> fstype,path=/share_path/,security_model=[mapped|passthrough],mnt_tag=tag
>>
>> In the case of mapped security model, files are created with QEMU user
>> credentials and the client-user's credentials are saved in extended 
>> attributes.
>> Whereas in the case of passthrough security model, files on the
>> filesystem are directly created with client-user's credentials.
>>
>> Signed-off-by: Venkateswararao Jujjuri 
>> ---
>>  fsdev/qemu-fsdev.c |   14 +-
>>  fsdev/qemu-fsdev.h |1 +
>>  hw/virtio-9p.c |   22 ++
>>  qemu-config.c  |   12 +---
>>  qemu-options.hx|   15 +++
>>  vl.c   |   18 +++---
>>  6 files changed, 67 insertions(+), 15 deletions(-)
>>
>> diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
>> index 813e1f7..7d7a153 100644
>> --- a/fsdev/qemu-fsdev.c
>> +++ b/fsdev/qemu-fsdev.c
>> @@ -34,7 +34,7 @@ int qemu_fsdev_add(QemuOpts *opts)
>>  return -1;
>>  }
>>  
>> - for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
>> +for (i = 0; i < ARRAY_SIZE(FsTypes); i++) {
>>  if (strcmp(FsTypes[i].name, qemu_opt_get(opts, "fstype")) == 0) {
>>  break;
>>  }
> 
> 
> Don't do whitespace fixup in the same patch.

Ok. 

> 
> 
>> @@ -46,10 +46,22 @@ int qemu_fsdev_add(QemuOpts *opts)
>>  return -1;
>>  }
>>  
>> +if (qemu_opt_get(opts, "path") == NULL) {
>> +fprintf(stderr, "fsdev: No path specified.\n");
>> +return -1;
>> +}
>> +
> 
> 
> How is this related to new option ? 

Not related. Will send out another patch.

> 
> 
>> +if (qemu_opt_get(opts, "security_model") == NULL) {
>> +fprintf(stderr, "fsdev: No security_model specified.\n");
>> +return -1;
>> +}
>> +
>>  fsle = qemu_malloc(sizeof(*fsle));
>>  
>>  fsle->fse.fsdev_id = qemu_strdup(qemu_opts_id(opts));
>>  fsle->fse.path = qemu_strdup(qemu_opt_get(opts, "path"));
>> +fsle->fse.security_model = qemu_strdup(qemu_opt_get(opts,
>> +"security_model"));
>>  fsle->fse.ops = FsTypes[i].ops;
>>  
>>  QTAILQ_INSERT_TAIL(&fstype_entries, fsle, next);
>> diff --git a/fsdev/qemu-fsdev.h b/fsdev/qemu-fsdev.h
>> index b50fbe0..6c27881 100644
>> --- a/fsdev/qemu-fsdev.h
>> +++ b/fsdev/qemu-fsdev.h
>> @@ -40,6 +40,7 @@ typedef struct FsTypeTable {
>>  typedef struct FsTypeEntry {
>>  char *fsdev_id;
>>  char *path;
>> +char *security_model;
>>  FileOperations *ops;
>>  } FsTypeEntry;
>>  
>> diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
>> index 687abc0..a57562a 100644
>> --- a/hw/virtio-9p.c
>> +++ b/hw/virtio-9p.c
>> @@ -2402,7 +2402,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, 
>> V9fsConf *conf)
>>  /* We don't have a fsdev identified by fsdev_id */
>>  fprintf(stderr, "Virtio-9p device couldn't find fsdev "
>>  "with the id %s\n", conf->fsdev_id);
>> -exit(1);
>> +return NULL;
>>  }
>>  
>>  if (!fse->path || !conf->tag) {
>> @@ -2410,15 +2410,29 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, 
>> V9fsConf *conf)
>>  fprintf(stderr, "fsdev with id %s needs path "
>>  "and Virtio-9p device needs mount_tag arguments\n",
>>  conf->fsdev_id);
>> -exit(1);
>> +return NULL;
>> +}
>> +
>> +if (!strcmp(fse->security_model, "passthrough")) {
>> +/* Files on the Fileserver set to client user credentials */
>> +} else if (!strcmp(fse->security_model, "mapped")) {
>> +/* Files on the fileserver are set to QEMU credentials.
>> + * Client user credentials are saved in extended attributes.
>> + */
> 
> 
> The above two if should be dropped add them when you have something to do in 
> the if () { }
> section.
> 
> 
>> +} else {
>> +/* user haven't specified a correct security option */
>> +fprintf(stderr, "one of the following must be specified as the"
>> +"security option:\n\t security_model=passthrough \n\t "
>> +"security_model=mapped\n");
>> +return NULL;
>>  }
> 
> We should only have this

Well, it is tricky. Given that we should not fix/change the code in the 
previous patches
in the same series, code becomes ugly without the above place holders.

Given that I can't change this part of the code in my next patch in the 
series.. I need to go like this:

if ( !strcmp(fse->security_model, "passthrough") && 
!strcmp(fse->security_model, "mapped"))
{
Error;
Return NULL;
}

Then in the next patch, 
Below this i need to add in the next patch.
if (!strcmp(fse->security_model, "passthrough"))
 blah
if (!strcmp(fse->security_model, "mapped"))
  blah

Which makes the code to chec

Re: [Qemu-devel] [Bug 589315] [NEW] qemu: Improve error reporting when migration can't connect

2010-06-03 Thread Yoshiaki Tamura
2010/6/4 Cole Robinson :
> Public bug reported:
>
> Tested with upstream qemu as of Jun 3 2010
>
> If the source qemu instance can't connect to the migration destination (say
> there is no listening QEMU instance, or port is blocked by a firewall), all we
> get is info migrate -> Migration status: failed. This is all we have to report
> back to libvirt users if their firewall is misconfigured, which is crappy.
>
> Ideally, if we can't connect, migration would fail immediately with a relevant
> message and strerror(). More info from 'info migrate' would be nice too, no
> idea how this will play with QMP though.
>
> As a slightly related issue, try entering
>
> migrate tcp:127.0.0.0:6000
>
> We get a 'migration failed' error, and then the monitor hangs!
>
> ** Affects: qemu
>     Importance: Undecided
>         Status: New
>
> --
> qemu: Improve error reporting when migration can't connect
> https://bugs.launchpad.net/bugs/589315
> You received this bug notification because you are a member of qemu-
> devel-ml, which is subscribed to QEMU.
>
> Status in QEMU: New
>
> Bug description:
> Tested with upstream qemu as of Jun 3 2010
>
> If the source qemu instance can't connect to the migration destination (say
> there is no listening QEMU instance, or port is blocked by a firewall), all we
> get is info migrate -> Migration status: failed. This is all we have to report
> back to libvirt users if their firewall is misconfigured, which is crappy.
>
> Ideally, if we can't connect, migration would fail immediately with a relevant
> message and strerror(). More info from 'info migrate' would be nice too, no
> idea how this will play with QMP though.
>
> As a slightly related issue, try entering
>
> migrate tcp:127.0.0.0:6000
>
> We get a 'migration failed' error, and then the monitor hangs!
>

Hi,

Does the following patch fix the problem?

Thanks,

Yoshi

[PATCH] migration-tcp: call migrate_fd_error() instead of close() and free().

This patch fixes the following error report.  When changing
migration-tcp.c to call migrate_fd_error() instead of close() and
free() by itself, monitor is resumed, and returns allocated mig_state
is set to current_migration in migration.c allows us to print "info
migrate".

Reported-by: Cole Robinson 
Signed-off-by: Yoshiaki Tamura 

--
qemu: Improve error reporting when migration can't connect
https://bugs.launchpad.net/bugs/589315
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
Tested with upstream qemu as of Jun 3 2010

If the source qemu instance can't connect to the migration destination (say
there is no listening QEMU instance, or port is blocked by a firewall), all we
get is info migrate -> Migration status: failed. This is all we have to report
back to libvirt users if their firewall is misconfigured, which is crappy.

Ideally, if we can't connect, migration would fail immediately with a relevant
message and strerror(). More info from 'info migrate' would be nice too, no
idea how this will play with QMP though.

As a slightly related issue, try entering

migrate tcp:127.0.0.0:6000

We get a 'migration failed' error, and then the monitor hangs!
--
---
 migration-tcp.c |4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/migration-tcp.c b/migration-tcp.c
index 95ce722..43af2e0 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -128,9 +128,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon,

 if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) {
 DPRINTF("connect failed\n");
-close(s->fd);
-qemu_free(s);
-return NULL;
+migrate_fd_error(s);
 } else if (ret >= 0)
 migrate_fd_connect(s);

-- 
1.7.0.31.g1df487



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

2010-06-03 Thread Richard Henderson
On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
> +/*
> + * Duplicate definition from vl.c to avoid messing up the entire build
> + */
> +enum {
> +#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
> +opt_enum,
> +#define DEFHEADING(text)
> +#include "qemu-options.h"
> +#undef DEF
> +#undef DEFHEADING
> +#undef GEN_DOCS
> +};

There's no header file you can put this in?  Or invent to put this in?
Cause this is really kinda gross...

> +
> +/*
> + * Parse OS specific command line options.
> + * return 0 if option handled, -1 otherwise
> + */
> +int os_parse_cmd_args(const QEMUOption *popt, const char *optarg)
> +{
> +int ret = 0;
> +switch (popt->index) {
> +#ifdef CONFIG_SLIRP
> +case QEMU_OPTION_smb:
> +if (net_slirp_smb(optarg) < 0)
> +exit(1);
> +break;
> +#endif
> +default:
> +ret = -1;
> +}
> +return ret;
> +}

Why have a return value at all...

> +default:
> +os_parse_cmd_args(popt, optarg);

... if you're going to ignore the results?


r~



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

2010-06-03 Thread Richard Henderson
On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
> +static inline void os_change_process_uid(void) {};

Stray ;


r~



[Qemu-devel] Fwd: [PATCH 1/4] Make configure find uuid functions in Mac OS X by looking into libSystem.B

2010-06-03 Thread C.W. Betts
Since this didn't seem to get to the mailing list, I'm forwarding it.

Begin forwarded message:

> From: "C.W. Betts" 
> Date: May 16, 2010 12:47:33 PM MDT
> To: qemu-devel@nongnu.org
> Cc: "C.W. Betts" 
> Subject: [PATCH 1/4] Make configure find uuid functions in Mac OS X by 
> looking into libSystem.B
> 
> ---
> configure |6 +-
> 1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/configure b/configure
> index 966cd7d..ecc3317 100755
> --- a/configure
> +++ b/configure
> @@ -1198,7 +1198,11 @@ fi
> ##
> # uuid_generate() probe, used for vdi block driver
> if test "$uuid" != "no" ; then
> -  uuid_libs="-luuid"
> +  if test "$darwin" == "yes"; then
> +uuid_libs=""
> +  else
> +uuid_libs="-luuid"
> +  fi
>   cat > $TMPC << EOF
> #include 
> int main(void)
> -- 
> 1.6.5.5
> 
> 



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

2010-06-03 Thread Richard Henderson
On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
> +static inline void os_change_root(void) {};

You really like the ";", don't you.  ;-)


r~



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

2010-06-03 Thread Richard Henderson
On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
> --- a/qemu-os-win32.h
> +++ b/qemu-os-win32.h
> @@ -41,4 +41,7 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc 
> *func, void *opaque);
>  void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
>  
>  void os_host_main_loop_wait(int *timeout);
> +
> +static inline void os_setup_signal_handling(void) {};

Stray ;


r~



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

2010-06-03 Thread Richard Henderson
On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
> --- a/sysemu.h
> +++ b/sysemu.h
> @@ -79,6 +79,9 @@ int qemu_loadvm_state(QEMUFile *f);
>  /* SLIRP */
>  void do_info_slirp(Monitor *mon);
>  
> +/* OS specific functions */
> +void os_setup_signal_handling(void);
> +

Can this go in your qemu-os-posix.h?


r~



[Qemu-devel] [PATCH 2/2] tcg: get rid of DEF2 in tcg-opc.h

2010-06-03 Thread Aurelien Jarno
Now that tcg-opc.h is only used in TCG code, get rid of DEF2 in
tcg-opc.h.

Signed-off-by: Aurelien Jarno 
---
 tcg/tcg-opc.h |  293 +
 tcg/tcg.c |4 +-
 tcg/tcg.h |2 +-
 3 files changed, 149 insertions(+), 150 deletions(-)

diff --git a/tcg/tcg-opc.h b/tcg/tcg-opc.h
index 5531da7..2a98fed 100644
--- a/tcg/tcg-opc.h
+++ b/tcg/tcg-opc.h
@@ -21,283 +21,284 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#ifndef DEF2
-#define DEF2(name, oargs, iargs, cargs, flags) DEF(name, oargs + iargs + cargs)
-#endif
+
+/*
+ * DEF(name, oargs, iargs, cargs, flags)
+ */
 
 /* predefined ops */
-DEF2(end, 0, 0, 0, 0) /* must be kept first */
-DEF2(nop, 0, 0, 0, 0)
-DEF2(nop1, 0, 0, 1, 0)
-DEF2(nop2, 0, 0, 2, 0)
-DEF2(nop3, 0, 0, 3, 0)
-DEF2(nopn, 0, 0, 1, 0) /* variable number of parameters */
+DEF(end, 0, 0, 0, 0) /* must be kept first */
+DEF(nop, 0, 0, 0, 0)
+DEF(nop1, 0, 0, 1, 0)
+DEF(nop2, 0, 0, 2, 0)
+DEF(nop3, 0, 0, 3, 0)
+DEF(nopn, 0, 0, 1, 0) /* variable number of parameters */
 
-DEF2(discard, 1, 0, 0, 0)
+DEF(discard, 1, 0, 0, 0)
 
-DEF2(set_label, 0, 0, 1, 0)
-DEF2(call, 0, 1, 2, TCG_OPF_SIDE_EFFECTS) /* variable number of parameters */
-DEF2(jmp, 0, 1, 0, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
-DEF2(br, 0, 0, 1, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
+DEF(set_label, 0, 0, 1, 0)
+DEF(call, 0, 1, 2, TCG_OPF_SIDE_EFFECTS) /* variable number of parameters */
+DEF(jmp, 0, 1, 0, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
+DEF(br, 0, 0, 1, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
 
-DEF2(mov_i32, 1, 1, 0, 0)
-DEF2(movi_i32, 1, 0, 1, 0)
-DEF2(setcond_i32, 1, 2, 1, 0)
+DEF(mov_i32, 1, 1, 0, 0)
+DEF(movi_i32, 1, 0, 1, 0)
+DEF(setcond_i32, 1, 2, 1, 0)
 /* load/store */
-DEF2(ld8u_i32, 1, 1, 1, 0)
-DEF2(ld8s_i32, 1, 1, 1, 0)
-DEF2(ld16u_i32, 1, 1, 1, 0)
-DEF2(ld16s_i32, 1, 1, 1, 0)
-DEF2(ld_i32, 1, 1, 1, 0)
-DEF2(st8_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
-DEF2(st16_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
-DEF2(st_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
+DEF(ld8u_i32, 1, 1, 1, 0)
+DEF(ld8s_i32, 1, 1, 1, 0)
+DEF(ld16u_i32, 1, 1, 1, 0)
+DEF(ld16s_i32, 1, 1, 1, 0)
+DEF(ld_i32, 1, 1, 1, 0)
+DEF(st8_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
+DEF(st16_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
+DEF(st_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
 /* arith */
-DEF2(add_i32, 1, 2, 0, 0)
-DEF2(sub_i32, 1, 2, 0, 0)
-DEF2(mul_i32, 1, 2, 0, 0)
+DEF(add_i32, 1, 2, 0, 0)
+DEF(sub_i32, 1, 2, 0, 0)
+DEF(mul_i32, 1, 2, 0, 0)
 #ifdef TCG_TARGET_HAS_div_i32
-DEF2(div_i32, 1, 2, 0, 0)
-DEF2(divu_i32, 1, 2, 0, 0)
-DEF2(rem_i32, 1, 2, 0, 0)
-DEF2(remu_i32, 1, 2, 0, 0)
+DEF(div_i32, 1, 2, 0, 0)
+DEF(divu_i32, 1, 2, 0, 0)
+DEF(rem_i32, 1, 2, 0, 0)
+DEF(remu_i32, 1, 2, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_div2_i32
-DEF2(div2_i32, 2, 3, 0, 0)
-DEF2(divu2_i32, 2, 3, 0, 0)
+DEF(div2_i32, 2, 3, 0, 0)
+DEF(divu2_i32, 2, 3, 0, 0)
 #endif
-DEF2(and_i32, 1, 2, 0, 0)
-DEF2(or_i32, 1, 2, 0, 0)
-DEF2(xor_i32, 1, 2, 0, 0)
+DEF(and_i32, 1, 2, 0, 0)
+DEF(or_i32, 1, 2, 0, 0)
+DEF(xor_i32, 1, 2, 0, 0)
 /* shifts/rotates */
-DEF2(shl_i32, 1, 2, 0, 0)
-DEF2(shr_i32, 1, 2, 0, 0)
-DEF2(sar_i32, 1, 2, 0, 0)
+DEF(shl_i32, 1, 2, 0, 0)
+DEF(shr_i32, 1, 2, 0, 0)
+DEF(sar_i32, 1, 2, 0, 0)
 #ifdef TCG_TARGET_HAS_rot_i32
-DEF2(rotl_i32, 1, 2, 0, 0)
-DEF2(rotr_i32, 1, 2, 0, 0)
+DEF(rotl_i32, 1, 2, 0, 0)
+DEF(rotr_i32, 1, 2, 0, 0)
 #endif
 
-DEF2(brcond_i32, 0, 2, 2, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
+DEF(brcond_i32, 0, 2, 2, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
 #if TCG_TARGET_REG_BITS == 32
-DEF2(add2_i32, 2, 4, 0, 0)
-DEF2(sub2_i32, 2, 4, 0, 0)
-DEF2(brcond2_i32, 0, 4, 2, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
-DEF2(mulu2_i32, 2, 2, 0, 0)
-DEF2(setcond2_i32, 1, 4, 1, 0)
+DEF(add2_i32, 2, 4, 0, 0)
+DEF(sub2_i32, 2, 4, 0, 0)
+DEF(brcond2_i32, 0, 4, 2, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
+DEF(mulu2_i32, 2, 2, 0, 0)
+DEF(setcond2_i32, 1, 4, 1, 0)
 #endif
 #ifdef TCG_TARGET_HAS_ext8s_i32
-DEF2(ext8s_i32, 1, 1, 0, 0)
+DEF(ext8s_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_ext16s_i32
-DEF2(ext16s_i32, 1, 1, 0, 0)
+DEF(ext16s_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_ext8u_i32
-DEF2(ext8u_i32, 1, 1, 0, 0)
+DEF(ext8u_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_ext16u_i32
-DEF2(ext16u_i32, 1, 1, 0, 0)
+DEF(ext16u_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_bswap16_i32
-DEF2(bswap16_i32, 1, 1, 0, 0)
+DEF(bswap16_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_bswap32_i32
-DEF2(bswap32_i32, 1, 1, 0, 0)
+DEF(bswap32_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_not_i32
-DEF2(not_i32, 1, 1, 0, 0)
+DEF(not_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_neg_i32
-DEF2(neg_i32, 1, 1, 0, 0)
+DEF(neg_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_andc_i32
-DEF2(andc_i32, 1, 2, 0, 0)
+DEF(andc_i32, 1, 2, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_orc_i32
-DEF2(orc_i32, 1, 2, 0, 0)
+DEF(orc_i32, 1, 2, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_eqv_i32
-DEF2(eqv_i32, 1, 2, 0, 0)
+DEF(eqv_i3

[Qemu-devel] [PATCH 1/2] tcg: get rid of copy_size in TCGOpDef

2010-06-03 Thread Aurelien Jarno
copy_size is a left-over from the dyngen era, remove it.

Signed-off-by: Aurelien Jarno 
---
 exec-all.h  |1 -
 exec.c  |2 +-
 tcg/tcg-opc.h   |2 +-
 tcg/tcg.c   |2 +-
 tcg/tcg.h   |3 +--
 translate-all.c |   16 
 6 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/exec-all.h b/exec-all.h
index 4565dd0..a775582 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -80,7 +80,6 @@ void gen_intermediate_code_pc(CPUState *env, struct 
TranslationBlock *tb);
 void gen_pc_load(CPUState *env, struct TranslationBlock *tb,
  unsigned long searched_pc, int pc_pos, void *puc);
 
-unsigned long code_gen_max_block_size(void);
 void cpu_gen_init(void);
 int cpu_gen_code(CPUState *env, struct TranslationBlock *tb,
  int *gen_code_size_ptr);
diff --git a/exec.c b/exec.c
index bb3dcad..aedfda4 100644
--- a/exec.c
+++ b/exec.c
@@ -557,7 +557,7 @@ static void code_gen_alloc(unsigned long tb_size)
 #endif /* !USE_STATIC_CODE_GEN_BUFFER */
 map_exec(code_gen_prologue, sizeof(code_gen_prologue));
 code_gen_buffer_max_size = code_gen_buffer_size - 
-code_gen_max_block_size();
+(TCG_MAX_OP_SIZE * OPC_MAX_SIZE);
 code_gen_max_blocks = code_gen_buffer_size / CODE_GEN_AVG_BLOCK_SIZE;
 tbs = qemu_malloc(code_gen_max_blocks * sizeof(TranslationBlock));
 }
diff --git a/tcg/tcg-opc.h b/tcg/tcg-opc.h
index 674c73a..5531da7 100644
--- a/tcg/tcg-opc.h
+++ b/tcg/tcg-opc.h
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #ifndef DEF2
-#define DEF2(name, oargs, iargs, cargs, flags) DEF(name, oargs + iargs + 
cargs, 0)
+#define DEF2(name, oargs, iargs, cargs, flags) DEF(name, oargs + iargs + cargs)
 #endif
 
 /* predefined ops */
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 880e7ce..b0b0363 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -67,7 +67,7 @@ static void patch_reloc(uint8_t *code_ptr, int type,
 tcg_target_long value, tcg_target_long addend);
 
 static TCGOpDef tcg_op_defs[] = {
-#define DEF(s, n, copy_size) { #s, 0, 0, n, n, 0, copy_size },
+#define DEF(s, n) { #s, 0, 0, n, n, 0 },
 #define DEF2(s, oargs, iargs, cargs, flags) { #s, oargs, iargs, cargs, iargs + 
oargs + cargs, flags, 0 },
 #include "tcg-opc.h"
 #undef DEF
diff --git a/tcg/tcg.h b/tcg/tcg.h
index 5853823..74d2e0b 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -48,7 +48,7 @@ typedef uint64_t TCGRegSet;
 #endif
 
 typedef enum TCGOpcode {
-#define DEF(s, n, copy_size) INDEX_op_ ## s,
+#define DEF(s, n) INDEX_op_ ## s,
 #include "tcg-opc.h"
 #undef DEF
 NB_OPS,
@@ -415,7 +415,6 @@ typedef struct TCGOpDef {
 const char *name;
 uint8_t nb_oargs, nb_iargs, nb_cargs, nb_args;
 uint8_t flags;
-uint16_t copy_size;
 TCGArgConstraint *args_ct;
 int *sorted_args;
 #if defined(CONFIG_DEBUG_TCG)
diff --git a/translate-all.c b/translate-all.c
index 91cbbc4..efcfb9a 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -41,22 +41,6 @@ target_ulong gen_opc_pc[OPC_BUF_SIZE];
 uint16_t gen_opc_icount[OPC_BUF_SIZE];
 uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
 
-/* XXX: suppress that */
-unsigned long code_gen_max_block_size(void)
-{
-static unsigned long max;
-
-if (max == 0) {
-max = TCG_MAX_OP_SIZE;
-#define DEF(s, n, copy_size) max = copy_size > max? copy_size : max;
-#include "tcg-opc.h"
-#undef DEF
-max *= OPC_MAX_SIZE;
-}
-
-return max;
-}
-
 void cpu_gen_init(void)
 {
 tcg_context_init(&tcg_ctx); 
-- 
1.7.1




[Qemu-devel] [PATCH 2/2] tcg: get rid of DEF2 in tcg-opc.h

2010-06-03 Thread y
From: Aurelien Jarno 

Now that tcg-opc.h is only used in TCG code, get rid of DEF2 in
tcg-opc.h.

Signed-off-by: Aurelien Jarno 
---
 tcg/tcg-opc.h |  293 +
 tcg/tcg.c |4 +-
 tcg/tcg.h |2 +-
 3 files changed, 149 insertions(+), 150 deletions(-)

diff --git a/tcg/tcg-opc.h b/tcg/tcg-opc.h
index 5531da7..2a98fed 100644
--- a/tcg/tcg-opc.h
+++ b/tcg/tcg-opc.h
@@ -21,283 +21,284 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#ifndef DEF2
-#define DEF2(name, oargs, iargs, cargs, flags) DEF(name, oargs + iargs + cargs)
-#endif
+
+/*
+ * DEF(name, oargs, iargs, cargs, flags)
+ */
 
 /* predefined ops */
-DEF2(end, 0, 0, 0, 0) /* must be kept first */
-DEF2(nop, 0, 0, 0, 0)
-DEF2(nop1, 0, 0, 1, 0)
-DEF2(nop2, 0, 0, 2, 0)
-DEF2(nop3, 0, 0, 3, 0)
-DEF2(nopn, 0, 0, 1, 0) /* variable number of parameters */
+DEF(end, 0, 0, 0, 0) /* must be kept first */
+DEF(nop, 0, 0, 0, 0)
+DEF(nop1, 0, 0, 1, 0)
+DEF(nop2, 0, 0, 2, 0)
+DEF(nop3, 0, 0, 3, 0)
+DEF(nopn, 0, 0, 1, 0) /* variable number of parameters */
 
-DEF2(discard, 1, 0, 0, 0)
+DEF(discard, 1, 0, 0, 0)
 
-DEF2(set_label, 0, 0, 1, 0)
-DEF2(call, 0, 1, 2, TCG_OPF_SIDE_EFFECTS) /* variable number of parameters */
-DEF2(jmp, 0, 1, 0, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
-DEF2(br, 0, 0, 1, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
+DEF(set_label, 0, 0, 1, 0)
+DEF(call, 0, 1, 2, TCG_OPF_SIDE_EFFECTS) /* variable number of parameters */
+DEF(jmp, 0, 1, 0, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
+DEF(br, 0, 0, 1, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
 
-DEF2(mov_i32, 1, 1, 0, 0)
-DEF2(movi_i32, 1, 0, 1, 0)
-DEF2(setcond_i32, 1, 2, 1, 0)
+DEF(mov_i32, 1, 1, 0, 0)
+DEF(movi_i32, 1, 0, 1, 0)
+DEF(setcond_i32, 1, 2, 1, 0)
 /* load/store */
-DEF2(ld8u_i32, 1, 1, 1, 0)
-DEF2(ld8s_i32, 1, 1, 1, 0)
-DEF2(ld16u_i32, 1, 1, 1, 0)
-DEF2(ld16s_i32, 1, 1, 1, 0)
-DEF2(ld_i32, 1, 1, 1, 0)
-DEF2(st8_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
-DEF2(st16_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
-DEF2(st_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
+DEF(ld8u_i32, 1, 1, 1, 0)
+DEF(ld8s_i32, 1, 1, 1, 0)
+DEF(ld16u_i32, 1, 1, 1, 0)
+DEF(ld16s_i32, 1, 1, 1, 0)
+DEF(ld_i32, 1, 1, 1, 0)
+DEF(st8_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
+DEF(st16_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
+DEF(st_i32, 0, 2, 1, TCG_OPF_SIDE_EFFECTS)
 /* arith */
-DEF2(add_i32, 1, 2, 0, 0)
-DEF2(sub_i32, 1, 2, 0, 0)
-DEF2(mul_i32, 1, 2, 0, 0)
+DEF(add_i32, 1, 2, 0, 0)
+DEF(sub_i32, 1, 2, 0, 0)
+DEF(mul_i32, 1, 2, 0, 0)
 #ifdef TCG_TARGET_HAS_div_i32
-DEF2(div_i32, 1, 2, 0, 0)
-DEF2(divu_i32, 1, 2, 0, 0)
-DEF2(rem_i32, 1, 2, 0, 0)
-DEF2(remu_i32, 1, 2, 0, 0)
+DEF(div_i32, 1, 2, 0, 0)
+DEF(divu_i32, 1, 2, 0, 0)
+DEF(rem_i32, 1, 2, 0, 0)
+DEF(remu_i32, 1, 2, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_div2_i32
-DEF2(div2_i32, 2, 3, 0, 0)
-DEF2(divu2_i32, 2, 3, 0, 0)
+DEF(div2_i32, 2, 3, 0, 0)
+DEF(divu2_i32, 2, 3, 0, 0)
 #endif
-DEF2(and_i32, 1, 2, 0, 0)
-DEF2(or_i32, 1, 2, 0, 0)
-DEF2(xor_i32, 1, 2, 0, 0)
+DEF(and_i32, 1, 2, 0, 0)
+DEF(or_i32, 1, 2, 0, 0)
+DEF(xor_i32, 1, 2, 0, 0)
 /* shifts/rotates */
-DEF2(shl_i32, 1, 2, 0, 0)
-DEF2(shr_i32, 1, 2, 0, 0)
-DEF2(sar_i32, 1, 2, 0, 0)
+DEF(shl_i32, 1, 2, 0, 0)
+DEF(shr_i32, 1, 2, 0, 0)
+DEF(sar_i32, 1, 2, 0, 0)
 #ifdef TCG_TARGET_HAS_rot_i32
-DEF2(rotl_i32, 1, 2, 0, 0)
-DEF2(rotr_i32, 1, 2, 0, 0)
+DEF(rotl_i32, 1, 2, 0, 0)
+DEF(rotr_i32, 1, 2, 0, 0)
 #endif
 
-DEF2(brcond_i32, 0, 2, 2, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
+DEF(brcond_i32, 0, 2, 2, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
 #if TCG_TARGET_REG_BITS == 32
-DEF2(add2_i32, 2, 4, 0, 0)
-DEF2(sub2_i32, 2, 4, 0, 0)
-DEF2(brcond2_i32, 0, 4, 2, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
-DEF2(mulu2_i32, 2, 2, 0, 0)
-DEF2(setcond2_i32, 1, 4, 1, 0)
+DEF(add2_i32, 2, 4, 0, 0)
+DEF(sub2_i32, 2, 4, 0, 0)
+DEF(brcond2_i32, 0, 4, 2, TCG_OPF_BB_END | TCG_OPF_SIDE_EFFECTS)
+DEF(mulu2_i32, 2, 2, 0, 0)
+DEF(setcond2_i32, 1, 4, 1, 0)
 #endif
 #ifdef TCG_TARGET_HAS_ext8s_i32
-DEF2(ext8s_i32, 1, 1, 0, 0)
+DEF(ext8s_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_ext16s_i32
-DEF2(ext16s_i32, 1, 1, 0, 0)
+DEF(ext16s_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_ext8u_i32
-DEF2(ext8u_i32, 1, 1, 0, 0)
+DEF(ext8u_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_ext16u_i32
-DEF2(ext16u_i32, 1, 1, 0, 0)
+DEF(ext16u_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_bswap16_i32
-DEF2(bswap16_i32, 1, 1, 0, 0)
+DEF(bswap16_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_bswap32_i32
-DEF2(bswap32_i32, 1, 1, 0, 0)
+DEF(bswap32_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_not_i32
-DEF2(not_i32, 1, 1, 0, 0)
+DEF(not_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_neg_i32
-DEF2(neg_i32, 1, 1, 0, 0)
+DEF(neg_i32, 1, 1, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_andc_i32
-DEF2(andc_i32, 1, 2, 0, 0)
+DEF(andc_i32, 1, 2, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_orc_i32
-DEF2(orc_i32, 1, 2, 0, 0)
+DEF(orc_i32, 1, 2, 0, 0)
 #endif
 #ifdef TCG_TARGET_HAS_eqv_i32
-DEF2(eqv_i32, 

[Qemu-devel] [PATCH 1/2] tcg: get rid of copy_size in TCGOpDef

2010-06-03 Thread y
From: Aurelien Jarno 

copy_size is a left-over from the dyngen era, remove it.

Signed-off-by: Aurelien Jarno 
---
 exec-all.h  |1 -
 exec.c  |2 +-
 tcg/tcg-opc.h   |2 +-
 tcg/tcg.c   |2 +-
 tcg/tcg.h   |3 +--
 translate-all.c |   16 
 6 files changed, 4 insertions(+), 22 deletions(-)

diff --git a/exec-all.h b/exec-all.h
index 4565dd0..a775582 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -80,7 +80,6 @@ void gen_intermediate_code_pc(CPUState *env, struct 
TranslationBlock *tb);
 void gen_pc_load(CPUState *env, struct TranslationBlock *tb,
  unsigned long searched_pc, int pc_pos, void *puc);
 
-unsigned long code_gen_max_block_size(void);
 void cpu_gen_init(void);
 int cpu_gen_code(CPUState *env, struct TranslationBlock *tb,
  int *gen_code_size_ptr);
diff --git a/exec.c b/exec.c
index bb3dcad..aedfda4 100644
--- a/exec.c
+++ b/exec.c
@@ -557,7 +557,7 @@ static void code_gen_alloc(unsigned long tb_size)
 #endif /* !USE_STATIC_CODE_GEN_BUFFER */
 map_exec(code_gen_prologue, sizeof(code_gen_prologue));
 code_gen_buffer_max_size = code_gen_buffer_size - 
-code_gen_max_block_size();
+(TCG_MAX_OP_SIZE * OPC_MAX_SIZE);
 code_gen_max_blocks = code_gen_buffer_size / CODE_GEN_AVG_BLOCK_SIZE;
 tbs = qemu_malloc(code_gen_max_blocks * sizeof(TranslationBlock));
 }
diff --git a/tcg/tcg-opc.h b/tcg/tcg-opc.h
index 674c73a..5531da7 100644
--- a/tcg/tcg-opc.h
+++ b/tcg/tcg-opc.h
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #ifndef DEF2
-#define DEF2(name, oargs, iargs, cargs, flags) DEF(name, oargs + iargs + 
cargs, 0)
+#define DEF2(name, oargs, iargs, cargs, flags) DEF(name, oargs + iargs + cargs)
 #endif
 
 /* predefined ops */
diff --git a/tcg/tcg.c b/tcg/tcg.c
index 880e7ce..b0b0363 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -67,7 +67,7 @@ static void patch_reloc(uint8_t *code_ptr, int type,
 tcg_target_long value, tcg_target_long addend);
 
 static TCGOpDef tcg_op_defs[] = {
-#define DEF(s, n, copy_size) { #s, 0, 0, n, n, 0, copy_size },
+#define DEF(s, n) { #s, 0, 0, n, n, 0 },
 #define DEF2(s, oargs, iargs, cargs, flags) { #s, oargs, iargs, cargs, iargs + 
oargs + cargs, flags, 0 },
 #include "tcg-opc.h"
 #undef DEF
diff --git a/tcg/tcg.h b/tcg/tcg.h
index 5853823..74d2e0b 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -48,7 +48,7 @@ typedef uint64_t TCGRegSet;
 #endif
 
 typedef enum TCGOpcode {
-#define DEF(s, n, copy_size) INDEX_op_ ## s,
+#define DEF(s, n) INDEX_op_ ## s,
 #include "tcg-opc.h"
 #undef DEF
 NB_OPS,
@@ -415,7 +415,6 @@ typedef struct TCGOpDef {
 const char *name;
 uint8_t nb_oargs, nb_iargs, nb_cargs, nb_args;
 uint8_t flags;
-uint16_t copy_size;
 TCGArgConstraint *args_ct;
 int *sorted_args;
 #if defined(CONFIG_DEBUG_TCG)
diff --git a/translate-all.c b/translate-all.c
index 91cbbc4..efcfb9a 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -41,22 +41,6 @@ target_ulong gen_opc_pc[OPC_BUF_SIZE];
 uint16_t gen_opc_icount[OPC_BUF_SIZE];
 uint8_t gen_opc_instr_start[OPC_BUF_SIZE];
 
-/* XXX: suppress that */
-unsigned long code_gen_max_block_size(void)
-{
-static unsigned long max;
-
-if (max == 0) {
-max = TCG_MAX_OP_SIZE;
-#define DEF(s, n, copy_size) max = copy_size > max? copy_size : max;
-#include "tcg-opc.h"
-#undef DEF
-max *= OPC_MAX_SIZE;
-}
-
-return max;
-}
-
 void cpu_gen_init(void)
 {
 tcg_context_init(&tcg_ctx); 
-- 
1.7.1




[Qemu-devel] [PATCH] Extra scan codes for missing keys (v2)

2010-06-03 Thread Brendan Sleight
 bmsleight, please post to the top-level
 and add a (v2) otherwise, it's easy for me to get confused
that i've already looked at a patch

Thanks

Hi All,

First - Qemu is fantastic and allows lots of wonderful things.

Second, when using qemu-system-ppc, I wanted to use sendkey to emulate
a colon. This patch enables shift-semicolon to emulate a ':'

Whilst I was adding semicolon, I used the following link to look up
some other missing keys :-
 http://terpconnect.umd.edu/~nsw/ench250/scancode.htm#Key2

Please cc my to any replies as I am not subscribed to the list.

Best Regards,
Brendan M. Sleight

diff --git a/monitor.c b/monitor.c
index ad50f12..e1ffa0e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1641,6 +1641,8 @@ static const KeyDef key_defs[] = {
    { 0x17, "i" },
    { 0x18, "o" },
    { 0x19, "p" },
+    { 0x1a, "sqr_brack_l" },
+    { 0x1b, "sqr_brack_r" },

    { 0x1c, "ret" },

@@ -1653,7 +1655,11 @@ static const KeyDef key_defs[] = {
    { 0x24, "j" },
    { 0x25, "k" },
    { 0x26, "l" },
+    { 0x27, "semicolon" },
+    { 0x28, "apostrophe" },
+    { 0x29, "grave_accent" },

+    { 0x2b, "backslash" },
    { 0x2c, "z" },
    { 0x2d, "x" },
    { 0x2e, "c" },



[Qemu-devel] Re: [PATCH 3/8] sparc64: fix 32bit load sign extension

2010-06-03 Thread Igor Kovalenko
On Thu, Jun 3, 2010 at 7:42 PM, Paolo Bonzini  wrote:
> On 06/03/2010 05:25 PM, Alexander Graf wrote:
>>
>> Am 03.06.2010 um 15:18 schrieb Paolo Bonzini :
>>
>>> On 06/01/2010 10:12 PM, Igor V. Kovalenko wrote:

 From: Igor V. Kovalenko

 - change return type of ldl_* to uint32_t to prevent unwanted sign
 extension
 visible in sparc64 load alternate address space methods
 - note this change makes ldl_* softmmu implementations match ldl_phys
 one
>>>
>>> This patch breaks -kernel/-initrd.
>>
>> Breaks it where and when?
>
> x86_64 TCG reboots after the "Probing EDD" step.

My local build appears to work, qemu-system-x86_64 loads my gentoo linux setup.
I use x86_64 host, gcc 4.4.3, qemu configured with ./configure
--prefix=/inst --target-list=sparc64-softmmu,x86_64-softmmu

-- 
Kind regards,
Igor V. Kovalenko



[Qemu-devel] [PATCH v3] savevm: Really verify if a drive supports snapshots

2010-06-03 Thread Miguel Di Ciurcio Filho
Both bdrv_can_snapshot() and bdrv_has_snapshot() does not work as advertized.

First issue: Their names implies different porpouses, but they do the same thing
and have exactly the same code. Maybe copied and pasted and forgotten?
bdrv_has_snapshot() is called in various places for actually checking if there
is snapshots or not.

Second issue: the way bdrv_can_snapshot() verifies if a block driver supports or
not snapshots does not catch all cases. E.g.: a raw image.

So when do_savevm() is called, first thing it does is to set a global
BlockDriverState to save the VM memory state calling get_bs_snapshots().

static BlockDriverState *get_bs_snapshots(void)
{
BlockDriverState *bs;
DriveInfo *dinfo;

if (bs_snapshots)
return bs_snapshots;
QTAILQ_FOREACH(dinfo, &drives, next) {
bs = dinfo->bdrv;
if (bdrv_can_snapshot(bs))
goto ok;
}
return NULL;
 ok:
bs_snapshots = bs;
return bs;
}

bdrv_can_snapshot() may return a BlockDriverState that does not support
snapshots and do_savevm() goes on.

Later on in do_savevm(), we find:

QTAILQ_FOREACH(dinfo, &drives, next) {
bs1 = dinfo->bdrv;
if (bdrv_has_snapshot(bs1)) {
/* Write VM state size only to the image that contains the state */
sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);
ret = bdrv_snapshot_create(bs1, sn);
if (ret < 0) {
monitor_printf(mon, "Error while creating snapshot on '%s'\n",
   bdrv_get_device_name(bs1));
}
}
}

bdrv_has_snapshot(bs1) is not checking if the device does support or has
snapshots as explained above. Only in bdrv_snapshot_create() the device is
actually checked for snapshot support.

So, in cases where the first device supports snapshots, and the second does not,
the snapshot on the first will happen anyways. I believe this is not a good
behavior. It should be an all or nothing process.

This patch addresses these issues by making bdrv_can_snapshot() actually do
what it must do and enforces better tests to avoid errors in the middle of
do_savevm(). bdrv_has_snapshot() is removed and replaced by bdrv_can_snapshot()
where appropriate.

bdrv_can_snapshot() was moved from savevm.c to block.c. It makes more sense to 
me.

The loadvm_state() function was updated too to enforce that when loading a VM at
least all writable devices must support snapshots too.

Signed-off-by: Miguel Di Ciurcio Filho 
---
 block.c  |   11 +++
 block.h  |1 +
 savevm.c |   58 --
 3 files changed, 48 insertions(+), 22 deletions(-)

diff --git a/block.c b/block.c
index cd70730..ace3cdb 100644
--- a/block.c
+++ b/block.c
@@ -1720,6 +1720,17 @@ void bdrv_debug_event(BlockDriverState *bs, 
BlkDebugEvent event)
 /**/
 /* handling of snapshots */
 
+int bdrv_can_snapshot(BlockDriverState *bs)
+{
+BlockDriver *drv = bs->drv;
+if (!drv || !drv->bdrv_snapshot_create || bdrv_is_removable(bs) ||
+bdrv_is_read_only(bs)) {
+return 0;
+}
+
+return 1;
+}
+
 int bdrv_snapshot_create(BlockDriverState *bs,
  QEMUSnapshotInfo *sn_info)
 {
diff --git a/block.h b/block.h
index 24efeb6..fbcd8af 100644
--- a/block.h
+++ b/block.h
@@ -173,6 +173,7 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo 
*bdi);
 const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
 void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size);
+int bdrv_can_snapshot(BlockDriverState *bs);
 int bdrv_snapshot_create(BlockDriverState *bs,
  QEMUSnapshotInfo *sn_info);
 int bdrv_snapshot_goto(BlockDriverState *bs,
diff --git a/savevm.c b/savevm.c
index dc20390..6549ca7 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1574,22 +1574,6 @@ out:
 return ret;
 }
 
-/* device can contain snapshots */
-static int bdrv_can_snapshot(BlockDriverState *bs)
-{
-return (bs &&
-!bdrv_is_removable(bs) &&
-!bdrv_is_read_only(bs));
-}
-
-/* device must be snapshots in order to have a reliable snapshot */
-static int bdrv_has_snapshot(BlockDriverState *bs)
-{
-return (bs &&
-!bdrv_is_removable(bs) &&
-!bdrv_is_read_only(bs));
-}
-
 static BlockDriverState *get_bs_snapshots(void)
 {
 BlockDriverState *bs;
@@ -1599,8 +1583,9 @@ static BlockDriverState *get_bs_snapshots(void)
 return bs_snapshots;
 QTAILQ_FOREACH(dinfo, &drives, next) {
 bs = dinfo->bdrv;
-if (bdrv_can_snapshot(bs))
+if (bdrv_can_snapshot(bs)) {
 goto ok;
+}
 }
 return NULL;
  ok:
@@ -1674,12 +1659,26 @@ void do_savevm(Monitor *mon, const QDict *qdict)
 #endif
 const char *name = qdict_get_try_str(qdict, "name");
 
+/* Verify if there is a device that doesn't su

[Qemu-devel] [Bug 267542] Re: MINIX 3 won't boot in qemu 0.9.1

2010-06-03 Thread Sylvain Nahas
Hi,
I have switched the status to "Fix Released". Was it the right thing to do?
Sylvain

-- 
MINIX 3 won't boot in qemu 0.9.1
https://bugs.launchpad.net/bugs/267542
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Fix Released

Bug description:
CD Image 3.1.2a was downloaded from http://www.minix3.org/download/

It booted with previous version of qemu but hangs at startup with 0.9.1.

Hardware acceleration is disabled.

Please ask if there is other information I can give you.





[Qemu-devel] [Bug 267542] Re: MINIX 3 won't boot in qemu 0.9.1

2010-06-03 Thread Sylvain Nahas
Hi,
I have retried with qemu 0.12.3 on the same binaries, and it works fine.
For me, this report can be closed.

Thanks,
Sylvain

** Changed in: qemu
   Status: Incomplete => Fix Released

-- 
MINIX 3 won't boot in qemu 0.9.1
https://bugs.launchpad.net/bugs/267542
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Fix Released

Bug description:
CD Image 3.1.2a was downloaded from http://www.minix3.org/download/

It booted with previous version of qemu but hangs at startup with 0.9.1.

Hardware acceleration is disabled.

Please ask if there is other information I can give you.





[Qemu-devel] [PATCH 0/3] Add virtio-blk support to persistent-storage rules

2010-06-03 Thread Ryan Harper
This patch series provides updates to udev to allow the creation symlinks for
virtio-blk devices, specifically disk/by-id and disk/by-path.  This is most
useful for virtio-blk devices that do not yet have any filesystem for which a
UUID can be extracted (disk/by-uuid).  These patches (save the path_id fix)
require an updated[1] qemu (on the host) and virtio-blk (in the guest)  to
generate the by-id path; however if the guest or host qemu isn't capable
then no action is taken.

1. http://lists.gnu.org/archive/html/qemu-devel/2010-03/msg01869.html

Signed-off-by: Ryan Harper 



[Qemu-devel] Re: [PATCH 2/4] Add virtio disk identification support

2010-06-03 Thread Anthony Liguori

On 03/25/2010 12:33 AM, john cooper wrote:

Fix bug which truncated serial string to 8 bytes, nul terminate.

Signed-off-by: john cooper
---

diff --git a/vl.c b/vl.c
index d69250c..b74cbba 100644
--- a/vl.c
+++ b/vl.c
@@ -1162,7 +1162,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
  dinfo->on_write_error = on_write_error;
  dinfo->opts = opts;
  if (serial)
-strncpy(dinfo->serial, serial, sizeof(serial));
+strncpy(dinfo->serial, serial, sizeof(dinfo->serial) - 1);
   


You need to explicitly add a null terminator.  Far better to just never 
use strncpy().


Regards,

Anthony Liguori


  QTAILQ_INSERT_TAIL(&drives, dinfo, next);

  switch(type) {

   





[Qemu-devel] Re: [PATCH 1/4] Add virtio disk identification support

2010-06-03 Thread Anthony Liguori

On 03/25/2010 12:32 AM, john cooper wrote:

Add virtio-blk device id (s/n) support via virtio request.
Remove artifacts of pci and ATA_IDENTIFY implementation
relative to prior versions.

Signed-off-by: john cooper
---

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 9915840..358b0af 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -19,6 +19,8 @@
  # include
  #endif

+#define min(a,b) ((a)<  (b) ? (a) : (b))
   


We already have MIN().


+
  typedef struct VirtIOBlock
  {
  VirtIODevice vdev;
@@ -28,6 +30,7 @@ typedef struct VirtIOBlock
  QEMUBH *bh;
  BlockConf *conf;
  unsigned short sector_mask;
+char sn[BLOCK_SERIAL_STRLEN];
  } VirtIOBlock;

  static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
@@ -317,6 +320,12 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
  virtio_blk_handle_flush(req);
  } else if (req->out->type&  VIRTIO_BLK_T_SCSI_CMD) {
  virtio_blk_handle_scsi(req);
+} else if (req->out->type&  VIRTIO_BLK_T_GET_ID) {
+VirtIOBlock *s = req->dev;
+
+memcpy(req->elem.in_sg[0].iov_base, s->sn,
+   min(req->elem.in_sg[0].iov_len, sizeof(s->sn)));
+virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
  } else if (req->out->type&  VIRTIO_BLK_T_OUT) {
  qemu_iovec_init_external(&req->qiov,&req->elem.out_sg[1],
   req->elem.out_num - 1);
@@ -496,6 +505,8 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf 
*conf)
  bdrv_guess_geometry(s->bs,&cylinders,&heads,&secs);
  bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);

+strncpy(s->sn, drive_get_serial(s->bs), sizeof (s->sn));
+
   


Friends don't let friends use strncpy().

This actually will result in a non-NULL terminated string if 
drive_get_serial() returns a string larger than s->sn.  Use snprintf() 
instead.


Regards,

Anthony Liguori


  s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);

  qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 7a7ece3..fff46da 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -59,6 +59,9 @@ struct virtio_blk_config
  /* Flush the volatile write cache */
  #define VIRTIO_BLK_T_FLUSH  4

+/* return the device ID string */
+#define VIRTIO_BLK_T_GET_ID 8
+
  /* Barrier before this op. */
  #define VIRTIO_BLK_T_BARRIER0x8000

   





[Qemu-devel] [Bug 589315] [NEW] qemu: Improve error reporting when migration can't connect

2010-06-03 Thread Cole Robinson
Public bug reported:

Tested with upstream qemu as of Jun 3 2010

If the source qemu instance can't connect to the migration destination (say
there is no listening QEMU instance, or port is blocked by a firewall), all we
get is info migrate -> Migration status: failed. This is all we have to report
back to libvirt users if their firewall is misconfigured, which is crappy.

Ideally, if we can't connect, migration would fail immediately with a relevant
message and strerror(). More info from 'info migrate' would be nice too, no
idea how this will play with QMP though.

As a slightly related issue, try entering

migrate tcp:127.0.0.0:6000

We get a 'migration failed' error, and then the monitor hangs!

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
qemu: Improve error reporting when migration can't connect
https://bugs.launchpad.net/bugs/589315
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
Tested with upstream qemu as of Jun 3 2010

If the source qemu instance can't connect to the migration destination (say
there is no listening QEMU instance, or port is blocked by a firewall), all we
get is info migrate -> Migration status: failed. This is all we have to report
back to libvirt users if their firewall is misconfigured, which is crappy.

Ideally, if we can't connect, migration would fail immediately with a relevant
message and strerror(). More info from 'info migrate' would be nice too, no
idea how this will play with QMP though.

As a slightly related issue, try entering

migrate tcp:127.0.0.0:6000

We get a 'migration failed' error, and then the monitor hangs!





Re: [Qemu-devel] [Bug 319014] Re: serial usb-device can't be passed-through to a guest

2010-06-03 Thread David S. Ahern


On 06/03/10 09:41, Nico Prenzel wrote:
> Hello Anthony,
> 
> which qemu-kvm version do you expect to work with serial usb devices?
> 
> After you've changed this ticket status and I've checked it again with 
> qemu-kvm version 0.12.4. The reported error message is gone away and the 
> device is present in the guest. The cdc_acm driver loads too without any 
> visible problems, but the device is still unusable.
> The device data led flash if it gets un/initialized by minicom.
> But if I try to make a test dial, nothing happens after I call a phone number.
> 
> To be more precise:
> -host dosn't have loaded the cdc_acm driver
> -guest loads the cdc_acm driver
> -a dial with minicom to the same phone number works on the host, if I load 
> the cdc_acm within the host
> 
> I would like to get this fixed, as I really want to use this usb-device
> as my dusty fax again.
> 

One option I resorted to is using Qemu's emulated USB serial device and
connecting it to the USB serial device host side. The stack then looks like:

  .-.
  | VM  |
  | |
  |/dev/ttyUSB0 |
  |-|
  | Qemu - serial device|
  '-'
 |
  .-.
  | Host: /dev/ttyUSB0  |
  '-'
|
  .-.
  |  USB serial port|<-- character stream -->
  '-'


A hack, but it works. :-)

David




[Qemu-devel] [Bug 581737] Re: Can't read e1000 NIC EEPROM on NetBSD guest

2010-06-03 Thread Ryan Harper
Please email the patch to qemu-devel@nongnu.org via git-send-email.
This will ensure the maintainers see the patch and the community has a
chance to review the patch.

-- 
Can't read e1000 NIC EEPROM on NetBSD guest
https://bugs.launchpad.net/bugs/581737
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Incomplete

Bug description:
QEMU Version: qemu-0.12.4
Host OS: NetBSD/i386 5.0.2
Guest OS: NetBSD/i386 5.1_RC1

On this environment, guest NetBSD tries to attach e1000 NIC using its own wm(4) 
driver but fails to read EEPROM as the following:
---
NetBSD 5.1_RC1 (GENERIC) #0: Sat Apr 24 23:26:09 UTC 2010

bui...@b7.netbsd.org:/home/builds/ab/netbsd-5-1-RC1/i386/201004250032Z-obj/home/builds/ab/
netbsd-5-1-RC1/src/sys/arch/i386/compile/GENERIC
total memory = 127 MB
avail memory = 113 MB
Bochs Bochs
 :
drm at vga1 not configured
wm0 at pci0 dev 3 function 0: Intel i82540EM 1000BASE-T Ethernet, rev. 3
wm0: interrupting at irq 11
wm0: unable to read Ethernet address
isa0 at pcib0
 :
---

You can reproduce this with NetBSD/i386 install CD image:
 ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-5.1_RC1/iso/i386cd-5.1_RC1.iso
 % qemu -cdrom i386cd-5.1_RC1.iso -boot d
 ---in QEMU window---
 [type ^C to quit installer]
 # dmesg | grep wm0
--

Per DBGOUT(EEPROM) messages, it show too large eecd_state.bitnum values, i.e. 
EEPROM state is not reset properly.
The set_eecd() function in e1000.c clears EEPROM internal state values on SK 
rising edge during CS==L.
But according to FM93C06 EEPROM (which is MicroWire compatible) data sheet,
EEPROM internal status should be cleared on CS rise edge regardless of SK input:
 "... a rising edge on this signal is required to reset the internal 
state-machine to accept a new cycle .."

Intel's em driver seems to explicitly raise and lower SK output after CS is 
negated in em_standby_eeprom()
so many other OSes that use Intel's driver don't have this problem with current 
e1000.c implementation,
but I can't find articles that say the MICROWIRE or EEPROM spec requires such 
sequence.

With the attached patch, NetBSD guest properly gets MAC address from e1000 NIC 
EEPROM.





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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

Move line-buffering setup to OS specific files.

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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

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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

In addition move SMB argument to os-posix.c

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

Move chroot handling to OS specific files.

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

Move main signal handler setup to os specific files.

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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

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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

Rename os_setup_signal_handling() to os_setup_early_signal_handling()

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

Move win32 early signal handling setup to os_setup_signal_handling()

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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

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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

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

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

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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

Hi,

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

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

Thanks,
Jes


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

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




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

2010-06-03 Thread Jes . Sorensen
From: Jes Sorensen 

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

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

diff --git a/vl.c b/vl.c
index 417554f..7c4298a 100644
--- a/vl.c
+++ b/vl.c
@@ -70,7 +70,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include  // must come after ip.h
-- 
1.6.5.2




[Qemu-devel] Re: [RFC PATCH v4 3/3] block: add sheepdog driver for distributed storage support

2010-06-03 Thread MORITA Kazutaka
At Wed, 02 Jun 2010 15:55:42 +0200,
Kevin Wolf wrote:
> 
> Am 28.05.2010 04:44, schrieb MORITA Kazutaka:
> > Sheepdog is a distributed storage system for QEMU. It provides highly
> > available block level storage volumes to VMs like Amazon EBS.  This
> > patch adds a qemu block driver for Sheepdog.
> > 
> > Sheepdog features are:
> > - No node in the cluster is special (no metadata node, no control
> >   node, etc)
> > - Linear scalability in performance and capacity
> > - No single point of failure
> > - Autonomous management (zero configuration)
> > - Useful volume management support such as snapshot and cloning
> > - Thin provisioning
> > - Autonomous load balancing
> > 
> > The more details are available at the project site:
> > http://www.osrg.net/sheepdog/
> > 
> > Signed-off-by: MORITA Kazutaka 
> > ---
> >  Makefile.objs|2 +-
> >  block/sheepdog.c | 1835 
> > ++
> >  2 files changed, 1836 insertions(+), 1 deletions(-)
> >  create mode 100644 block/sheepdog.c
> 
> One general thing: The code uses some mix of spaces and tabs for
> indentation, with the greatest part using tabs. According to
> CODING_STYLE it should consistently use four spaces instead.
> 

OK.  I'll fix the indentation according to CODYING_STYLE.


> > +
> > +typedef struct SheepdogInode {
> > +   char name[SD_MAX_VDI_LEN];
> > +   uint64_t ctime;
> > +   uint64_t snap_ctime;
> > +   uint64_t vm_clock_nsec;
> > +   uint64_t vdi_size;
> > +   uint64_t vm_state_size;
> > +   uint16_t copy_policy;
> > +   uint8_t  nr_copies;
> > +   uint8_t  block_size_shift;
> > +   uint32_t snap_id;
> > +   uint32_t vdi_id;
> > +   uint32_t parent_vdi_id;
> > +   uint32_t child_vdi_id[MAX_CHILDREN];
> > +   uint32_t data_vdi_id[MAX_DATA_OBJS];
> 
> Wow, this is a huge array. :-)
> 
> So Sheepdog has a fixed limit of 16 TB, right?
> 

MAX_DATA_OBJS is (1 << 20), and the size of a object is 4 MB.  So the
limit of the Sheepdog image size is 4 TB.

These values are hard-coded, and I guess they should be configurable.


> 
> > +} SheepdogInode;
> > +

> > +
> > +static void sd_aio_cancel(BlockDriverAIOCB *blockacb)
> > +{
> > +   SheepdogAIOCB *acb = (SheepdogAIOCB *)blockacb;
> > +
> > +   acb->canceled = 1;
> > +}
> 
> Does this provide the right semantics? You haven't really cancelled the
> request, but you pretend to. So you actually complete the request in the
> background and then throw the return code away.
> 
> I seem to remember that posix-aio-compat.c waits at this point for
> completion of the requests, calls the callbacks and only afterwards
> returns from aio_cancel when no more requests are in flight.
> 
> Or if you can really cancel requests, it would be the best option, of
> course.
> 

Sheepdog cannot cancel the requests which are already sent to the
servers.  So, as you say, we pretend to cancel the requests without
waiting for completion of them.  However, are there any situation
where pretending to cancel causes problems in practice?

To wait for completion of the requests here, we may need to create
another thread for processing I/O like posix-aio-compat.c.


> > +
> > +static int do_send_recv(int sockfd, struct iovec *iov, int len, int offset,
> > +   int write)
> 
> I've spent at least 15 minutes figuring out what this function does. I
> think I've got it now more or less, but I've come to the conclusion that
> this code needs more comments.
> 
> I'd suggest to add a header comment to all non-trivial functions and
> maybe somewhere on the top a general description of how things work.
> 
> As far as I understood now, there are basically two parts of request
> handling:
> 
> 1. The request is sent to the server. Its AIOCB is saved in a list in
> the BDRVSheepdogState. It doesn't pass a callback or anything for the
> completion.
> 
> 2. aio_read_response is registered as a fd handler to the sheepdog
> connection. When the server responds, it searches the right AIOCB in the
> list and the second part of request handling starts.
> 
> do_send_recv is the function that is used to do all communication with
> the server. The iov stuff looks like it's only used for some data, but
> seems this is not true - it's also used for the metadata of the protocol.
> 
> Did I understand it right so far?
> 

Yes, exactly.  I'll add comments to make codes more readable.


> > +{
> > +   struct msghdr msg;
> > +   int ret, diff;
> > +
> > +   memset(&msg, 0, sizeof(msg));
> > +   msg.msg_iov = iov;
> > +   msg.msg_iovlen = 1;
> > +
> > +   len += offset;
> > +
> > +   while (iov->iov_len < len) {
> > +   len -= iov->iov_len;
> > +
> > +   iov++;
> > +   msg.msg_iovlen++;
> > +   }
> 
> You're counting the number of elements in the iov here. qemu_iovec would
> already have these (and also len), wouldn't it make sense to use it as
> the abstraction? Though I'm not sure where these iovecs come from, so
> the answer might be no.
> 

We uses struct msghdr for 

[Qemu-devel] [Bug 319014] Re: serial usb-device can't be passed-through to a guest

2010-06-03 Thread Nico Prenzel
Hello Anthony,

which qemu-kvm version do you expect to work with serial usb devices?

After you've changed this ticket status and I've checked it again with qemu-kvm 
version 0.12.4. The reported error message is gone away and the device is 
present in the guest. The cdc_acm driver loads too without any visible 
problems, but the device is still unusable.
The device data led flash if it gets un/initialized by minicom.
But if I try to make a test dial, nothing happens after I call a phone number.

To be more precise:
-host dosn't have loaded the cdc_acm driver
-guest loads the cdc_acm driver
-a dial with minicom to the same phone number works on the host, if I load the 
cdc_acm within the host

I would like to get this fixed, as I really want to use this usb-device
as my dusty fax again.

-- 
serial usb-device can't be passed-through to a guest
https://bugs.launchpad.net/bugs/319014
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Fix Released
Status in CentOS: New

Bug description:
Hello,

I use Debian Lenny with qemu/kvm version 79. If I try to pass-through my "US 
Robotics 56K USB Modem Model 5637" to any guest, I get an 
perror("usb_linux_update_endp_table").
So, I've searched through the qemu-devel archives and found the following 
thread:
http://www.archivum.info/qemu-devel@nongnu.org/2008-10/msg00299.html
If I remove the "return 1;" as stated above my usb modem get's successfully 
passed-through to the guest and the modem works fine.
Is there any chance to get serial usb devices to work out of standard qemu/kvm, 
without the need to apply this line to every qemu/kvm version?

NicoP.





[Qemu-devel] [Bug 588735] Re: Quit command not working

2010-06-03 Thread Jan Smets
The host now has 8GB of memory, problem remains.


Try

 ./configure --target-list=x86_64-softmmu --enable-profiler --enable-
gprof --enable-io-thread --enable-debug-tcg --enable-debug


Without these options it magically works :)

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

Status in QEMU: Incomplete

Bug description:
Qemu strace



rt_sigreturn(0x1b)  = 56
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, 
child_tidptr=0x7f6fddecbad0) = ? ERESTARTNOINTR (To be restarted)
--- SIGPROF (Profiling timer expired) @ 0 (0) ---
rt_sigreturn(0x1b)  = 56


started with :

[r...@virtual-test ~]# 
/root/qemu-test/qemu-kvm/x86_64-softmmu/qemu-system-x86_64 -net 
tap,vlan=0,name=tap.0 -chardev 
socket,id=serial0,host=0.0.0.0,port=$CONSOLEPORT,telnet,server,nowait -serial 
chardev:serial0 -hda hda -hdb hdb -hdc hdc -hdd hdd -fda fd0 -fdb fd1 -chardev 
socket,id=monitor,host=0.0.0.0,port=$MONITORPORT,telnet,server,nowait -monitor 
chardev:monitor -net nic,macaddr=$MAC,vlan=0,model=e1000,name=e1000.0 -M pc -m 
4096

when removing -m 4096, the quit command works.

but I think its a combination of different args that causes the problem.





[Qemu-devel] [Bug 589231] [NEW] cirrus vga is very slow in qemu-kvm-0.12

2010-06-03 Thread Michael Tokarev
Public bug reported:

As has been reported multiple times (*), there were a regression in
qemu-kvm from 0.11 to 0.12, which causes significant slowdown in cirrus
vga emulation.  For windows guests, where "standard VGA" driver works
reasonable well, -vga std is a good workaround. But for e.g. linux
guests, where vesa driver is painfully slow by its own, that's not a
solution.

(*)
 debian qemu-kvm bug report #574988: http://bugs.debian.org/574988#17
 debian qemu bugreport (might be related): http://bugs.debian.org/575720
 kvm mailinglist thread: 
http://www.mail-archive.com/k...@vger.kernel.org/msg33459.html
 another kvm ml thread: 
http://www.mail-archive.com/k...@vger.kernel.org/msg32744.html

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: 0.12 cirrus qemu-kvm regression slow video

-- 
cirrus vga is very slow in qemu-kvm-0.12
https://bugs.launchpad.net/bugs/589231
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: New

Bug description:
As has been reported multiple times (*), there were a regression in qemu-kvm 
from 0.11 to 0.12, which causes significant slowdown in cirrus vga emulation.  
For windows guests, where "standard VGA" driver works reasonable well, -vga std 
is a good workaround. But for e.g. linux guests, where vesa driver is painfully 
slow by its own, that's not a solution.

(*)
 debian qemu-kvm bug report #574988: http://bugs.debian.org/574988#17
 debian qemu bugreport (might be related): http://bugs.debian.org/575720
 kvm mailinglist thread: 
http://www.mail-archive.com/k...@vger.kernel.org/msg33459.html
 another kvm ml thread: 
http://www.mail-archive.com/k...@vger.kernel.org/msg32744.html





[Qemu-devel] [PATCH] In v9fs_remove_post_remove() we currently ignore the error returned by

2010-06-03 Thread Sripathi Kodi
the previous call to remove() and return an error only if freeing the
fid fails. However, the client expects to see the error from remove().
Currently the client falsely thinks that the remove call has always
succeeded. For example, doing rmdir on a non-empty directory does
not return ENOTEMPTY.

With this patch we ignore the error from free_fid(). The client cannot
use this error value anyway.

Signed-off-by: Sripathi Kodi 
---

 hw/virtio-9p.c |   11 ++-
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index e5d0112..999c0d5 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1943,14 +1943,15 @@ typedef struct V9fsRemoveState {
 static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs,
 int err)
 {
-/* For TREMOVE we need to clunk the fid even on failed remove */
-err = free_fid(s, vs->fidp->fid);
 if (err < 0) {
-goto out;
+err = -errno;
+} else {
+err = vs->offset;
 }
 
-err = vs->offset;
-out:
+/* For TREMOVE we need to clunk the fid even on failed remove */
+free_fid(s, vs->fidp->fid);
+
 complete_pdu(s, vs->pdu, err);
 qemu_free(vs);
 }




[Qemu-devel] Re: [PATCH 3/8] sparc64: fix 32bit load sign extension

2010-06-03 Thread Paolo Bonzini

On 06/03/2010 05:25 PM, Alexander Graf wrote:


Am 03.06.2010 um 15:18 schrieb Paolo Bonzini :


On 06/01/2010 10:12 PM, Igor V. Kovalenko wrote:

From: Igor V. Kovalenko

- change return type of ldl_* to uint32_t to prevent unwanted sign
extension
visible in sparc64 load alternate address space methods
- note this change makes ldl_* softmmu implementations match ldl_phys
one


This patch breaks -kernel/-initrd.


Breaks it where and when?


x86_64 TCG reboots after the "Probing EDD" step.

Paolo



[Qemu-devel] [Bug 513273] Re: kvm with -vga std is broken since karmic

2010-06-03 Thread Michael Tokarev
um.  Can't you just take approach used in Debian, namely, to provide the
sources for the bios files and compile them at build time?  That is
somewhat ugly, but at least it works...

-- 
kvm with -vga std is broken since karmic
https://bugs.launchpad.net/bugs/513273
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Invalid
Status in “qemu-kvm” package in Ubuntu: Invalid
Status in “seabios” package in Ubuntu: Invalid
Status in “vgabios” package in Ubuntu: Fix Released
Status in “qemu-kvm” source package in Lucid: Invalid
Status in “seabios” source package in Lucid: Invalid
Status in “vgabios” source package in Lucid: Fix Released

Bug description:
Binary package hint: qemu-kvm

it works with -vga cirrus, with -vga std I got:

BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters
BUG: kvm_dirty_pages_log_enable_slot: invalid parameters
BUG: kvm_dirty_pages_log_disable_slot: invalid parameters


And driver do not work properly (I can not set screen resolution) ...
virtual machine almost works, only screen problem in winxp guest

ProblemType: Bug
Architecture: amd64
Date: Wed Jan 27 15:15:49 2010
DistroRelease: Ubuntu 10.04
KvmCmdLine: Error: command ['ps', '-C', 'kvm', '-F'] failed with exit code 1: 
UIDPID  PPID  CSZ   RSS PSR STIME TTY  TIME CMD
MachineType: Acer Aspire 9300
NonfreeKernelModules: nvidia
Package: qemu-kvm 0.12.2-0ubuntu1
PccardctlIdent:
 Socket 0:
   no product info available
PccardctlStatus:
 Socket 0:
   no card
ProcCmdLine: BOOT_IMAGE=/boot/vmlinuz-2.6.32-11-generic 

[Qemu-devel] Re: [RFC PATCH v4 3/3] block: add sheepdog driver for distributed storage support

2010-06-03 Thread MORITA Kazutaka
At Tue, 01 Jun 2010 09:58:04 -0500,
Thanks for your comments!

Chris Krumme wrote:
> 
> On 05/27/2010 09:44 PM, MORITA Kazutaka wrote:
> > Sheepdog is a distributed storage system for QEMU. It provides highly

> > +
> > +static int connect_to_sdog(const char *addr)
> > +{
> > +   char buf[64];
> > +   char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
> > +   char name[256], *p;
> > +   int fd, ret;
> > +   struct addrinfo hints, *res, *res0;
> > +   int port = 0;
> > +
> > +   if (!addr) {
> > +   addr = SD_DEFAULT_ADDR;
> > +   }
> > +
> > +   strcpy(name, addr);
> >
> 
> Can strlen(addr) be > sizeof(name)?
> 

Yes, we should check the length of addr. This would causes overflows.

> > +
> > +   p = name;
> > +   while (*p) {
> > +   if (*p == ':') {
> > +   *p++ = '\0';
> >
> 
> May also need to check for p > name + sizeof(name).
> 

p should be NULL-terminated, so the check is not required, I think.

> > +   break;
> > +   } else {
> > +   p++;
> > +   }
> > +   }
> > +
> > +   if (*p == '\0') {
> > +   error_report("cannot find a port number, %s\n", name);
> > +   return -1;
> > +   }
> > +   port = strtol(p, NULL, 10);
> >
> 
> Are negative numbers valid here?
> 

No. It is better to use strtoul.


> > +
> > +static int parse_vdiname(BDRVSheepdogState *s, const char *filename,
> > +char *vdi, int vdi_len, uint32_t *snapid)
> > +{
> > +   char *p, *q;
> > +   int nr_sep;
> > +
> > +   p = q = strdup(filename);
> > +
> > +   if (!p) {
> >
> 
> I think Qemu has a version of strdup that will not return NULL.
> 

Yes. We can use qemu_strdup here.


> > +
> > +/* TODO: error cleanups */
> > +static int sd_open(BlockDriverState *bs, const char *filename, int flags)
> > +{
> > +   int ret, fd;
> > +   uint32_t vid = 0;
> > +   BDRVSheepdogState *s = bs->opaque;
> > +   char vdi[256];
> > +   uint32_t snapid;
> > +   int for_snapshot = 0;
> > +   char *buf;
> > +
> > +   strstart(filename, "sheepdog:", (const char **)&filename);
> > +
> > +   buf = qemu_malloc(SD_INODE_SIZE);
> > +
> > +   memset(vdi, 0, sizeof(vdi));
> > +   if (parse_vdiname(s, filename, vdi, sizeof(vdi),&snapid)<  0) {
> > +   goto out;
> > +   }
> > +   s->fd = get_sheep_fd(s);
> > +   if (s->fd<  0) {
> >
> 
> buf is not freed, goto out maybe.
> 

Yes, we should goto out here.


> > +
> > +static int do_sd_create(const char *addr, char *filename, char *tag,
> > +   int64_t total_sectors, uint32_t base_vid,
> > +   uint32_t *vdi_id, int snapshot)
> > +{
> > +   SheepdogVdiReq hdr;
> > +   SheepdogVdiRsp *rsp = (SheepdogVdiRsp *)&hdr;
> > +   int fd, ret;
> > +   unsigned int wlen, rlen = 0;
> > +   char buf[SD_MAX_VDI_LEN];
> > +
> > +   fd = connect_to_sdog(addr);
> > +   if (fd<  0) {
> > +   return -1;
> > +   }
> > +
> > +   strncpy(buf, filename, SD_MAX_VDI_LEN);
> > +
> > +   memset(&hdr, 0, sizeof(hdr));
> > +   hdr.opcode = SD_OP_NEW_VDI;
> > +   hdr.base_vdi_id = base_vid;
> > +
> > +   wlen = SD_MAX_VDI_LEN;
> > +
> > +   hdr.flags = SD_FLAG_CMD_WRITE;
> > +   hdr.snapid = snapshot;
> > +
> > +   hdr.data_length = wlen;
> > +   hdr.vdi_size = total_sectors * 512;
> >
> 
> There is another patch on the list changing 512 to a define for sector size.
> 

OK. We'll define SECTOR_SIZE.


> > +
> > +   ret = do_req(fd, (SheepdogReq *)&hdr, buf,&wlen,&rlen);
> > +
> > +   close(fd);
> > +
> > +   if (ret) {
> > +   return -1;
> > +   }
> > +
> > +   if (rsp->result != SD_RES_SUCCESS) {
> > +   error_report("%s, %s\n", sd_strerror(rsp->result), filename);
> > +   return -1;
> > +   }
> > +
> > +   if (vdi_id) {
> > +   *vdi_id = rsp->vdi_id;
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> > +static int sd_create(const char *filename, QEMUOptionParameter *options)
> > +{
> > +   int ret;
> > +   uint32_t vid = 0;
> > +   int64_t total_sectors = 0;
> > +   char *backing_file = NULL;
> > +
> > +   strstart(filename, "sheepdog:", (const char **)&filename);
> > +
> > +   while (options&&  options->name) {
> > +   if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
> > +   total_sectors = options->value.n / 512;
> >
> Use define.
> > +   } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
> > +   backing_file = options->value.s;
> > +   }
> > +   options++;
> > +   }
> > +
> > +   if (backing_file) {
> > +   BlockDriverState bs;
> > +   char vdi[SD_MAX_VDI_LEN];
> > +   uint32_t snapid;
> > +
> > +   strstart(backing_file, "sheepdog:", (const char 
> > **)&backing_file);
> > +   memset(&bs, 0, sizeof(bs));
> > +
> > +   bs.opaque = qemu_malloc(sizeof(BDRVSheepdogState));
> >
> 
> bs seems to have a short life span, is opaque getting freed?
> 

No, we should free it.


> > +
> > +static int sd_snapshot_create(BlockDr

[Qemu-devel] Re: [PATCH 3/8] sparc64: fix 32bit load sign extension

2010-06-03 Thread Alexander Graf


Am 03.06.2010 um 15:18 schrieb Paolo Bonzini :


On 06/01/2010 10:12 PM, Igor V. Kovalenko wrote:

From: Igor V. Kovalenko

- change return type of ldl_* to uint32_t to prevent unwanted sign  
extension

  visible in sparc64 load alternate address space methods
- note this change makes ldl_* softmmu implementations match  
ldl_phys one


This patch breaks -kernel/-initrd.


Breaks it where and when?

Alex






[Qemu-devel] Re: [RFC PATCH v4 0/3] Sheepdog: distributed storage system for QEMU

2010-06-03 Thread MORITA Kazutaka
At Wed, 02 Jun 2010 12:49:02 +0200,
Kevin Wolf wrote:
> 
> Am 28.05.2010 04:44, schrieb MORITA Kazutaka:
> > Hi all,
> > 
> > This patch adds a block driver for Sheepdog distributed storage
> > system.  Please consider for inclusion.
> 
> Hint for next time: You should remove the RFC from the subject line if
> you think the patch is ready for inclusion. Otherwise I might miss this
> and think you only want comments on it.
> 

Thanks for the advice. I'll do so the next time.

> > MORITA Kazutaka (3):
> >   close all the block drivers before the qemu process exits
> >   block: call the snapshot handlers of the protocol drivers
> >   block: add sheepdog driver for distributed storage support
> 
> Thanks, I have applied the first two patches to the block branch, they
> look good to me. I'll send some comments for the third one (though it's
> only coding style until now).
> 

Thanks a lot.

Kazutaka



[Qemu-devel] [PATCH 2/2] virtio-9p: Implement server side of setattr for 9P2000.L protocol.

2010-06-03 Thread Sripathi Kodi
SYNOPSIS

  size[4] Tsetattr tag[2] attr[n]

  size[4] Rsetattr tag[2]

   DESCRIPTION

  The setattr command changes some of the file status information.
  attr resembles the iattr structure used in Linux kernel. It
  specifies which status parameter is to be changed and to what
  value. It is laid out as follows:

 valid[4]
specifies which status information is to be changed. Possible
values are:
ATTR_MODE(1 << 0)
ATTR_UID (1 << 1)
ATTR_GID (1 << 2)
ATTR_SIZE(1 << 3)
ATTR_ATIME   (1 << 4)
ATTR_MTIME   (1 << 5)

 mode[4]
File permission bits

 uid[4]
Owner id of file

 gid[4]
Group id of the file

 size[8]
File size

 atime_sec[8]
Time of last file access, seconds

 atime_nsec[8]
Time of last file access, nanoseconds

 mtime_sec[8]
Time of last file modification, seconds

 mtime_nsec[8]
Time of last file modification, nanoseconds



Explanation of the patches:
--

*) The kernel just copies relevent contents of iattr structure to p9_iattr_dotl
   structure and passes it down to the client. The only check it has is calling
   inode_change_ok()
*) The p9_iattr_dotl structure does not have ctime and ia_file parameters 
because
   I don't think these are needed in our case.
*) The server currently supports changing mode, time, ownership and size of the
   file.
*) 9P RFC says "Either all the changes in wstat request happen, or none of them
   does: if the request succeeds, all changes were made; if it fails, none 
were."
   I have not implemented this as I think this is not needed.

Signed-off-by: Sripathi Kodi 
---

 hw/virtio-9p.c |  137 
 hw/virtio-9p.h |   23 +
 2 files changed, 160 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 8c1cdfb..a51f5ac 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -662,6 +662,15 @@ static size_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, 
const char *fmt, ...)
 &statp->n_muid);
 break;
 }
+case 'I': {
+V9fsIattr *iattr = va_arg(ap, V9fsIattr *);
+offset += pdu_unmarshal(pdu, offset, "q",
+&iattr->valid, &iattr->mode,
+&iattr->uid, &iattr->gid, &iattr->size,
+&iattr->atime_sec, &iattr->atime_nsec,
+&iattr->mtime_sec, &iattr->mtime_nsec);
+break;
+}
 default:
 break;
 }
@@ -1208,6 +1217,133 @@ out:
 qemu_free(vs);
 }
 
+/* From Linux kernel code */
+#define ATTR_MODE(1 << 0)
+#define ATTR_UID (1 << 1)
+#define ATTR_GID (1 << 2)
+#define ATTR_SIZE(1 << 3)
+#define ATTR_ATIME   (1 << 4)
+#define ATTR_MTIME   (1 << 5)
+
+static void v9fs_setattr_post_truncate(V9fsState *s, V9fsSetattrState *vs,
+  int err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+err = vs->offset;
+
+out:
+complete_pdu(s, vs->pdu, err);
+qemu_free(vs);
+}
+
+static void v9fs_setattr_post_chown(V9fsState *s, V9fsSetattrState *vs, int 
err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+
+if (vs->v9iattr.valid & (ATTR_SIZE)) {
+err = v9fs_do_truncate(s, &vs->fidp->path, vs->v9iattr.size);
+}
+v9fs_setattr_post_truncate(s, vs, err);
+return;
+
+out:
+complete_pdu(s, vs->pdu, err);
+qemu_free(vs);
+}
+
+static void v9fs_setattr_post_utimensat(V9fsState *s, V9fsSetattrState *vs,
+   int err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+
+if (vs->v9iattr.valid & (ATTR_UID | ATTR_GID)) {
+if (! (vs->v9iattr.valid & ATTR_UID)) {
+vs->v9iattr.uid = -1;
+}
+if (! (vs->v9iattr.valid & ATTR_GID)) {
+vs->v9iattr.gid = -1;
+}
+err = v9fs_do_chown(s, &vs->fidp->path, vs->v9iattr.uid,
+vs->v9iattr.gid);
+}
+v9fs_setattr_post_chown(s, vs, err);
+return;
+
+out:
+complete_pdu(s, vs->pdu, err);
+qemu_free(vs);
+}
+
+static void v9fs_setattr_post_chmod(V9fsState *s, V9fsSetattrState *vs, int 
err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+
+if (vs->v9iattr.valid & (ATTR_ATIME | ATTR_MTIME)) {
+struct timespec times[2];
+if (vs->v9iattr.valid & ATTR_ATIME) {
+times[0].tv_sec = vs->v9iattr.atime_sec;
+times[0].tv_nsec = vs->v9iattr.atime_nsec;
+} else {
+times[0].tv_nsec = UTIME_OMIT;

[Qemu-devel] [PATCH 1/2] Make v9fs_do_utimensat accept timespec structures instead of v9stat.

2010-06-03 Thread Sripathi Kodi
One of Mohan's recent patches (Message-Id:
<1275286613-16757-1-git-send-email-mo...@in.ibm.com>) implements
v9fs_do_utimensat function. Currently v9fs_do_utimensat takes a V9fsStat
argument and builds timespec structures. It sets tv_nsec values to 0 by
default. Instead of this it should take struct timespec[2] and pass it
down to the system directly. This will make it more generic and useful
elsewhere.

Signed-off-by: Sripathi Kodi 
---

 hw/virtio-9p.c |   37 ++---
 1 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 1c7a428..8c1cdfb 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -239,25 +239,10 @@ static int v9fs_do_chown(V9fsState *s, V9fsString *path, 
uid_t uid, gid_t gid)
 return s->ops->chown(&s->ctx, path->data, &cred);
 }
 
-static int v9fs_do_utimensat(V9fsState *s, V9fsString *path, V9fsStat v9stat)
+static int v9fs_do_utimensat(V9fsState *s, V9fsString *path,
+   const struct timespec times[2])
 {
-struct timespec ts[2];
-
-if (v9stat.atime != -1) {
-ts[0].tv_sec = v9stat.atime;
-ts[0].tv_nsec = 0;
-} else {
-ts[0].tv_nsec = UTIME_OMIT;
-}
-
-if (v9stat.mtime != -1) {
-ts[1].tv_sec = v9stat.mtime;
-ts[1].tv_nsec = 0;
-} else {
-ts[1].tv_nsec = UTIME_OMIT;
-}
-
-return s->ops->utimensat(&s->ctx, path->data, ts);
+return s->ops->utimensat(&s->ctx, path->data, times);
 }
 
 static int v9fs_do_remove(V9fsState *s, V9fsString *path)
@@ -2345,7 +2330,21 @@ static void v9fs_wstat_post_chmod(V9fsState *s, 
V9fsWstatState *vs, int err)
 }
 
 if (vs->v9stat.mtime != -1 || vs->v9stat.atime != -1) {
-if (v9fs_do_utimensat(s, &vs->fidp->path, vs->v9stat)) {
+struct timespec times[2];
+if (vs->v9stat.atime != -1) {
+times[0].tv_sec = vs->v9stat.atime;
+times[0].tv_nsec = 0;
+} else {
+times[0].tv_nsec = UTIME_OMIT;
+}
+if (vs->v9stat.mtime != -1) {
+times[1].tv_sec = vs->v9stat.mtime;
+times[1].tv_nsec = 0;
+} else {
+times[1].tv_nsec = UTIME_OMIT;
+}
+
+if (v9fs_do_utimensat(s, &vs->fidp->path, times)) {
 err = -errno;
 }
 }




[Qemu-devel] [PATCH 0/2] virtio-9p: Setattr for 9P2000.L

2010-06-03 Thread Sripathi Kodi
The following series implements setattr support for 9P2000.L protocol.

---

Sripathi Kodi (2):
  virtio-9p: Implement server side of setattr for 9P2000.L protocol.
  Make v9fs_do_utimensat accept timespec structures instead of v9stat.


 hw/virtio-9p.c |  174 ++--
 hw/virtio-9p.h |   23 +++
 2 files changed, 178 insertions(+), 19 deletions(-)

-- 
-Sripathi



[Qemu-devel] Re: [PATCH v2 2/2] basic machine opts framework

2010-06-03 Thread Anthony Liguori

On 06/01/2010 12:56 PM, Glauber Costa wrote:

This patch adds initial support for the -machine option, that allows
command line specification of machine attributes (always relying on safe
defaults). Besides its value per-se, it is the saner way we found to
allow for enabling/disabling of kvm's in-kernel irqchip.

A machine with in-kernel-irqchip could be specified as:
-machine irqchip=apic-kvm
And one without it:
-machine irqchip=apic

To demonstrate how it'd work, this patch introduces a choice between
"pic" and "apic", pic being the old-style isa thing.
---
  hw/boards.h |   10 ++
  hw/pc.c |   45 +++--
  qemu-config.c   |   16 
  qemu-config.h   |1 +
  qemu-options.hx |9 +
  vl.c|   54 ++
  6 files changed, 129 insertions(+), 6 deletions(-)

diff --git a/hw/boards.h b/hw/boards.h
index d889341..187794e 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -12,6 +12,15 @@ typedef void QEMUMachineInitFunc(ram_addr_t ram_size,
   const char *initrd_filename,
   const char *cpu_model);

+typedef void (QEMUIrqchipFunc)(void *opaque);
+
+typedef struct QEMUIrqchip {
+const char *name;
+QEMUIrqchipFunc *init;
+int used;
+int is_default;
+} QEMUIrqchip;
+
  typedef struct QEMUMachine {
  const char *name;
  const char *alias;
@@ -21,6 +30,7 @@ typedef struct QEMUMachine {
  int max_cpus;
  int is_default;
  CompatProperty *compat_props;
+QEMUIrqchip *irqchip;
  struct QEMUMachine *next;
  } QEMUMachine;
   


We really need machine specific state.  I've sent a patch out to add this.


diff --git a/hw/pc.c b/hw/pc.c
index 408d6d6..b3de30a 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -1007,21 +1007,43 @@ int cpu_is_bsp(CPUState *env)
  return env->cpuid_apic_id == 0;
  }

+static void qemu_apic_init(void *opaque)
+{
+CPUState *env = opaque;
+if (!(env->cpuid_features&  CPUID_APIC)) {
+fprintf(stderr, "CPU lacks APIC cpuid flag\n");
+exit(1);
+}
+env->cpuid_apic_id = env->cpu_index;
+/* APIC reset callback resets cpu */
+apic_init(env);
+}
+
+static void qemu_pic_init(void *opaque)
+{
+CPUState *env = opaque;
+
+if (smp_cpus>  1) {
+fprintf(stderr, "PIC can't support smp systems\n");
+exit(1);
+}
+qemu_register_reset((QEMUResetHandler*)cpu_reset, env);
+}
+
  static CPUState *pc_new_cpu(const char *cpu_model)
  {
  CPUState *env;
+QEMUIrqchip *ic;

  env = cpu_init(cpu_model);
  if (!env) {
  fprintf(stderr, "Unable to find x86 CPU definition\n");
  exit(1);
  }
-if ((env->cpuid_features&  CPUID_APIC) || smp_cpus>  1) {
-env->cpuid_apic_id = env->cpu_index;
-/* APIC reset callback resets cpu */
-apic_init(env);
-} else {
-qemu_register_reset((QEMUResetHandler*)cpu_reset, env);
+
+for (ic = current_machine->irqchip; ic->name != NULL; ic++) {
+if (ic->used)
+ic->init(env);
  }
  return env;
  }
@@ -1370,6 +1392,17 @@ static QEMUMachine pc_machine = {
  .desc = "Standard PC",
  .init = pc_init_pci,
  .max_cpus = 255,
+.irqchip = (QEMUIrqchip[]){
+{
+.name = "apic",
+.init = qemu_apic_init,
+.is_default = 1,
+},{
+.name = "pic",
+.init = qemu_pic_init,
+},
+{ /* end of list */ },
+},
  .is_default = 1,
  };
   


I don't think it's really useful to specify the apic vs. pic like this.  
I think the current scheme of cpu flag is adequate.



diff --git a/qemu-config.c b/qemu-config.c
index cae92f7..e83b301 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -196,6 +196,21 @@ QemuOptsList qemu_rtc_opts = {
  },
  };

+QemuOptsList qemu_machine_opts = {
+.name = "M",
   


machine


+.head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
+.desc = {
+{
+.name = "mach",
+.type = QEMU_OPT_STRING,
+},{
   


driver, and it ought to be an implied option so that '-machine pc' works.


+.name = "irqchip",
+.type = QEMU_OPT_STRING,
+},
+{ /* end of list */ }
+},
+};
   


But let's actually make this an empty list, then do a #define that 
containers just the "machine" option.  Then we can setup a pc-specific 
qemu_machine_opts that contains the apic option.


Once we've found the machine based on the driver property, we can 
validate the machine-specific options in vl.c.

diff --git a/vl.c b/vl.c
index 7a8b20b..cabbd1e 100644
--- a/vl.c
+++ b/vl.c
@@ -3217,9 +3217,15 @@ static QEMUMachine *find_machine(const char *name)
  static QEMUMachine *find_default_machine(void)
  {
  QEMUMachine *m;
+QEMUIrqchip *ic;

  for(m = first_machine; m != NULL; m = m->next) {
  

[Qemu-devel] [PATCH] Make machine->init take QEMUMachine as an argument

2010-06-03 Thread Anthony Liguori
This let's machines use container_of() to get at machine specific state.

Signed-off-by: Anthony Liguori 

diff --git a/hw/axis_dev88.c b/hw/axis_dev88.c
index 7d59c96..7c34013 100644
--- a/hw/axis_dev88.c
+++ b/hw/axis_dev88.c
@@ -264,7 +264,7 @@ static uint64_t translate_kernel_address(void *opaque, 
uint64_t addr)
 }
 
 static
-void axisdev88_init (ram_addr_t ram_size,
+void axisdev88_init (QEMUMachine *machine, ram_addr_t ram_size,
  const char *boot_device,
  const char *kernel_filename, const char *kernel_cmdline,
  const char *initrd_filename, const char *cpu_model)
diff --git a/hw/etraxfs.c b/hw/etraxfs.c
index b88d00a..9ec463f 100644
--- a/hw/etraxfs.c
+++ b/hw/etraxfs.c
@@ -50,7 +50,7 @@ static uint64_t translate_kernel_address(void *opaque, 
uint64_t addr)
 }
 
 static
-void bareetraxfs_init (ram_addr_t ram_size,
+void bareetraxfs_init (QEMUMachine *machine, ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model)
diff --git a/hw/mainstone.c b/hw/mainstone.c
index c801a2c..6badf49 100644
--- a/hw/mainstone.c
+++ b/hw/mainstone.c
@@ -68,7 +68,7 @@ static struct arm_boot_info mainstone_binfo = {
 .ram_size = 0x0400,
 };
 
-static void mainstone_common_init(QEMUMachine *machine, ram_addr_t ram_size,
+static void mainstone_common_init(ram_addr_t ram_size,
 const char *kernel_filename,
 const char *kernel_cmdline, const char *initrd_filename,
 const char *cpu_model, enum mainstone_model_e model, int 
arm_id)
diff --git a/hw/mips_jazz.c b/hw/mips_jazz.c
index ead3a00..e784b1f 100644
--- a/hw/mips_jazz.c
+++ b/hw/mips_jazz.c
@@ -300,7 +300,7 @@ void mips_jazz_init (ram_addr_t ram_size,
 }
 
 static
-void mips_magnum_init (ram_addr_t ram_size,
+void mips_magnum_init (QEMUMachine *machine, ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model)
@@ -309,7 +309,7 @@ void mips_magnum_init (ram_addr_t ram_size,
 }
 
 static
-void mips_pica61_init (ram_addr_t ram_size,
+void mips_pica61_init (QEMUMachine *machine, ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model)
diff --git a/hw/mips_malta.c b/hw/mips_malta.c
index a8f9d15..48a6d9e 100644
--- a/hw/mips_malta.c
+++ b/hw/mips_malta.c
@@ -773,7 +773,7 @@ static void cpu_request_exit(void *opaque, int irq, int 
level)
 }
 
 static
-void mips_malta_init (ram_addr_t ram_size,
+void mips_malta_init (QEMUMachine *machine, ram_addr_t ram_size,
   const char *boot_device,
   const char *kernel_filename, const char *kernel_cmdline,
   const char *initrd_filename, const char *cpu_model)
diff --git a/hw/mips_mipssim.c b/hw/mips_mipssim.c
index a747de5..fd442ec 100644
--- a/hw/mips_mipssim.c
+++ b/hw/mips_mipssim.c
@@ -110,7 +110,7 @@ static void main_cpu_reset(void *opaque)
 }
 
 static void
-mips_mipssim_init (ram_addr_t ram_size,
+mips_mipssim_init (QEMUMachine *machine, ram_addr_t ram_size,
const char *boot_device,
const char *kernel_filename, const char *kernel_cmdline,
const char *initrd_filename, const char *cpu_model)
diff --git a/hw/mips_r4k.c b/hw/mips_r4k.c
index f1fcfcd..5ac1615 100644
--- a/hw/mips_r4k.c
+++ b/hw/mips_r4k.c
@@ -155,7 +155,7 @@ static void main_cpu_reset(void *opaque)
 
 static const int sector_len = 32 * 1024;
 static
-void mips_r4k_init (ram_addr_t ram_size,
+void mips_r4k_init (QEMUMachine *machine, ram_addr_t ram_size,
 const char *boot_device,
 const char *kernel_filename, const char *kernel_cmdline,
 const char *initrd_filename, const char *cpu_model)
diff --git a/hw/nseries.c b/hw/nseries.c
index ae092ca..fa23305 100644
--- a/hw/nseries.c
+++ b/hw/nseries.c
@@ -1264,7 +1264,7 @@ static int n810_atag_setup(struct arm_boot_info *info, 
void *p)
 return n8x0_atag_setup(p, 810);
 }
 
-static void n8x0_init(QEMUMachine *machine, ram_addr_t ram_size, const char 
*boot_device,
+static void n8x0_init(ram_addr_t ram_size, const char *boot_device,
 const char *kernel_filename,
 const char *kernel_cmdline, const char *initrd_filename,
 const char *cpu_model, struct arm_boot_info *binfo, int model)
diff --git a/hw/omap_sx1.c b/hw/omap_sx1.c
index bc765bf..946a010 100644
--- a/hw/omap_sx1.c
+++ b/hw/omap_sx1.c
@@ -114,7 +114,7 @@ static struct arm_boot_info sx1_binfo = {
 .board_id = 0x265,
 };
 

[Qemu-devel] Re: Unposted reserved_va patch

2010-06-03 Thread Richard Henderson
On 06/02/2010 09:54 PM, Paul Brook wrote:
> Hmm, maybe. My reasoning was that this is consistent with the current 
> behavior 
> of the ELF loader.  If you specify -G then the target application will be 
> splatted at that address, regardless of whether it's already used by the host.

Well, sort-of.  Before you removed PAGE_RESERVED we'd yield a
very cryptic error message about mmap failed and exit.


r~



[Qemu-devel] [Bug 581737] Re: Can't read e1000 NIC EEPROM on NetBSD guest

2010-06-03 Thread Izumi Tsutsui

** Patch added: "patch by git format-patch --signoff"
   http://launchpadlibrarian.net/49607393/qemu-git.patch

-- 
Can't read e1000 NIC EEPROM on NetBSD guest
https://bugs.launchpad.net/bugs/581737
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Incomplete

Bug description:
QEMU Version: qemu-0.12.4
Host OS: NetBSD/i386 5.0.2
Guest OS: NetBSD/i386 5.1_RC1

On this environment, guest NetBSD tries to attach e1000 NIC using its own wm(4) 
driver but fails to read EEPROM as the following:
---
NetBSD 5.1_RC1 (GENERIC) #0: Sat Apr 24 23:26:09 UTC 2010

bui...@b7.netbsd.org:/home/builds/ab/netbsd-5-1-RC1/i386/201004250032Z-obj/home/builds/ab/
netbsd-5-1-RC1/src/sys/arch/i386/compile/GENERIC
total memory = 127 MB
avail memory = 113 MB
Bochs Bochs
 :
drm at vga1 not configured
wm0 at pci0 dev 3 function 0: Intel i82540EM 1000BASE-T Ethernet, rev. 3
wm0: interrupting at irq 11
wm0: unable to read Ethernet address
isa0 at pcib0
 :
---

You can reproduce this with NetBSD/i386 install CD image:
 ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-5.1_RC1/iso/i386cd-5.1_RC1.iso
 % qemu -cdrom i386cd-5.1_RC1.iso -boot d
 ---in QEMU window---
 [type ^C to quit installer]
 # dmesg | grep wm0
--

Per DBGOUT(EEPROM) messages, it show too large eecd_state.bitnum values, i.e. 
EEPROM state is not reset properly.
The set_eecd() function in e1000.c clears EEPROM internal state values on SK 
rising edge during CS==L.
But according to FM93C06 EEPROM (which is MicroWire compatible) data sheet,
EEPROM internal status should be cleared on CS rise edge regardless of SK input:
 "... a rising edge on this signal is required to reset the internal 
state-machine to accept a new cycle .."

Intel's em driver seems to explicitly raise and lower SK output after CS is 
negated in em_standby_eeprom()
so many other OSes that use Intel's driver don't have this problem with current 
e1000.c implementation,
but I can't find articles that say the MICROWIRE or EEPROM spec requires such 
sequence.

With the attached patch, NetBSD guest properly gets MAC address from e1000 NIC 
EEPROM.





[Qemu-devel] [PATCH] make qemu_thread_create block all signals

2010-06-03 Thread Paolo Bonzini
All signals will thus be routed through the IO thread.

Signed-off-by: Paolo Bonzini 
---
 cpus.c|   38 +++---
 qemu-thread.c |7 +++
 2 files changed, 18 insertions(+), 27 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8341f6c..fcd0f09 100644
--- a/cpus.c
+++ b/cpus.c
@@ -318,8 +318,8 @@ static QemuCond qemu_system_cond;
 static QemuCond qemu_pause_cond;
 static QemuCond qemu_work_cond;
 
-static void tcg_block_io_signals(void);
-static void kvm_block_io_signals(CPUState *env);
+static void tcg_init_ipi(void);
+static void kvm_init_ipi(CPUState *env);
 static void unblock_io_signals(void);
 
 int qemu_init_main_loop(void)
@@ -464,7 +464,7 @@ static void *kvm_cpu_thread_fn(void *arg)
 if (kvm_enabled())
 kvm_init_vcpu(env);
 
-kvm_block_io_signals(env);
+kvm_init_ipi(env);
 
 /* signal CPU creation */
 env->created = 1;
@@ -487,7 +487,7 @@ static void *tcg_cpu_thread_fn(void *arg)
 {
 CPUState *env = arg;
 
-tcg_block_io_signals();
+tcg_init_ipi();
 qemu_thread_self(env->thread);
 
 /* signal CPU creation */
@@ -532,52 +532,36 @@ static void cpu_signal(int sig)
 exit_request = 1;
 }
 
-static void tcg_block_io_signals(void)
+static void tcg_init_ipi(void)
 {
 sigset_t set;
 struct sigaction sigact;
 
-sigemptyset(&set);
-sigaddset(&set, SIGUSR2);
-sigaddset(&set, SIGIO);
-sigaddset(&set, SIGALRM);
-sigaddset(&set, SIGCHLD);
-pthread_sigmask(SIG_BLOCK, &set, NULL);
+memset(&sigact, 0, sizeof(sigact));
+sigact.sa_handler = cpu_signal;
+sigaction(SIG_IPI, &sigact, NULL);
 
 sigemptyset(&set);
 sigaddset(&set, SIG_IPI);
 pthread_sigmask(SIG_UNBLOCK, &set, NULL);
-
-memset(&sigact, 0, sizeof(sigact));
-sigact.sa_handler = cpu_signal;
-sigaction(SIG_IPI, &sigact, NULL);
 }
 
 static void dummy_signal(int sig)
 {
 }
 
-static void kvm_block_io_signals(CPUState *env)
+static void kvm_init_ipi(CPUState *env)
 {
 int r;
 sigset_t set;
 struct sigaction sigact;
 
-sigemptyset(&set);
-sigaddset(&set, SIGUSR2);
-sigaddset(&set, SIGIO);
-sigaddset(&set, SIGALRM);
-sigaddset(&set, SIGCHLD);
-sigaddset(&set, SIG_IPI);
-pthread_sigmask(SIG_BLOCK, &set, NULL);
-
-pthread_sigmask(SIG_BLOCK, NULL, &set);
-sigdelset(&set, SIG_IPI);
-
 memset(&sigact, 0, sizeof(sigact));
 sigact.sa_handler = dummy_signal;
 sigaction(SIG_IPI, &sigact, NULL);
 
+pthread_sigmask(SIG_BLOCK, NULL, &set);
+sigdelset(&set, SIG_IPI);
 r = kvm_set_signal_mask(env, &set);
 if (r) {
 fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(r));
diff --git a/qemu-thread.c b/qemu-thread.c
index 3923db7..faf4061 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -137,9 +137,16 @@ void qemu_thread_create(QemuThread *thread,
 {
 int err;
 
+/* Leave signal handling to the iothread.  */
+sigset_t set, oldset;
+
+sigfillset(&set);
+pthread_sigmask(SIG_SETMASK, &set, &oldset);
 err = pthread_create(&thread->thread, NULL, start_routine, arg);
 if (err)
 error_exit(err, __func__);
+
+pthread_sigmask(SIG_SETMASK, &oldset, NULL);
 }
 
 void qemu_thread_signal(QemuThread *thread, int sig)
-- 
1.7.0.1




[Qemu-devel] Re: [PATCH 3/8] sparc64: fix 32bit load sign extension

2010-06-03 Thread Paolo Bonzini

On 06/01/2010 10:12 PM, Igor V. Kovalenko wrote:

From: Igor V. Kovalenko

- change return type of ldl_* to uint32_t to prevent unwanted sign extension
   visible in sparc64 load alternate address space methods
- note this change makes ldl_* softmmu implementations match ldl_phys one


This patch breaks -kernel/-initrd.

Paolo



[Qemu-devel] Re: [PATCH v2 1/2] early set current_machine

2010-06-03 Thread Anthony Liguori

On 06/01/2010 12:56 PM, Glauber Costa wrote:

this way, the machine_init function itself can know which machine is current
in use, not only the late init code.
   


While your touching it...

We only use current_machine in hw/device-hotplug.c.  I think it would be 
better to introduce an accessor function (get_current_machine()) and 
then make this global static.


Regards,

Anthony Liguori


Signed-off-by: Glauber Costa
---
  vl.c |5 +++--
  1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/vl.c b/vl.c
index 96838f8..7a8b20b 100644
--- a/vl.c
+++ b/vl.c
@@ -5824,6 +5824,9 @@ int main(int argc, char **argv, char **envp)
  if (machine->compat_props) {
  qdev_prop_register_compat(machine->compat_props);
  }
+
+current_machine = machine;
+
  machine->init(ram_size, boot_devices,
kernel_filename, kernel_cmdline, initrd_filename, 
cpu_model);

@@ -5841,8 +5844,6 @@ int main(int argc, char **argv, char **envp)
  }
  }

-current_machine = machine;
-
  /* init USB devices */
  if (usb_enabled) {
  if (foreach_device_config(DEV_USB, usb_parse)<  0)
   





[Qemu-devel] Re: [PATCH v2 2/2] basic machine opts framework

2010-06-03 Thread Anthony Liguori

On 06/03/2010 01:07 AM, Jan Kiszka wrote:

Glauber Costa wrote:
   

On Wed, Jun 02, 2010 at 09:15:10AM +0200, Jan Kiszka wrote:
 


+QemuOptsList qemu_machine_opts = {
+.name = "M",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
+.desc = {
+{
+.name = "mach",
+.type = QEMU_OPT_STRING,
+},{
+.name = "irqchip",
+.type = QEMU_OPT_STRING,
+},
 

Can't we make the concrete machine define what options it needs? Pushing
this into the generic code may soon end up in a bunch of very special
switches that are unused on most machines or even have no meaning for them.

Also, I would suggest to introduce the generic part first, and then add
first users like the x86 irqchip.
   

Yeah, in general, I do agree with you.

Me and anthony talked about it for a while some time ago, and more or less
concluded that it could be possible to avoid that, putting a little think
which options to add.

the "irqchip" option, if you note, is not x86-specific, in any case.
Any machine has an irqchip.
 

...but the majority has no choice among different models. This option
simply makes only sense for x86 now and in the foreseeable future.

   

The first idea was to use something like
"apic=in_kernel|userspace" which would be, that, very x86-centric.

So, since letting machines define their own options adds complexity,
my take would be to add those common options, and add infrastructure
for machine-specific options when we see something that makes it
unavoidable.

What do you think?

 

I have no general concerns if you document irqchip as a x86-only machine
option without effect on other machines and you promise to clean this up
once done with in-kernel irqchip support (which is clearly more
important). But the current design should not stay that way for a longer
period to avoid what I sketched above.
   


What I think we need to do is actually use an empty QemuOptsList for the 
-machine option, make sure that the driver is present, then re-validate 
the list with a QemuOptsList that's included in the machine state.


We should, of course, have a #define of MACHINE_COMMON_OPTS.  This would 
allow machine specific options (like irqchip).  I don't think irqchip is 
the best name really.  I think it should be apic=kernel|user.


Regards,

Anthony Liguori


Jan
   





[Qemu-devel] Re: [V9fs-developer] [PATCH] virtio-9p: getattr server implementation for 9P2000.L protocol.

2010-06-03 Thread Sripathi Kodi
On Wed, 02 Jun 2010 19:49:24 +0530
"Aneesh Kumar K. V"  wrote:

> On Fri, 28 May 2010 16:08:43 +0530, Sripathi Kodi  
> wrote:
> > From: M. Mohan Kumar 
> > 
> > SYNOPSIS
> > 
> >   size[4] Tgetattr tag[2] fid[4]
> > 
> >   size[4] Rgetattr tag[2] lstat[n]
> > 
> >DESCRIPTION
> > 
> >   The getattr transaction inquires about the file identified by fid.
> >   The reply will contain a machine-independent directory entry,
> >   laid out as follows:
> > 
> >  qid.type[1]
> > the type of the file (directory, etc.), represented as a bit
> > vector corresponding to the high 8 bits of the file's mode
> > word.
> > 
> >  qid.vers[4]
> > version number for given path
> > 
> >  qid.path[8]
> > the file server's unique identification for the file
> > 
> >  st_mode[4]
> > Permission and flags
> > 
> >  st_nlink[8]
> > Number of hard links
> > 
> >  st_uid[4]
> > User id of owner
> > 
> >  st_gid[4]
> > Group ID of owner
> > 
> >  st_rdev[8]
> > Device ID (if special file)
> > 
> >  st_size[8]
> > Size, in bytes
> > 
> >  st_blksize[8]
> > Block size for file system IO
> 
> 
> So it should be scaled by iounit right ? If we say 9p block size is iounit.

Yes, I think it should be iounit. Currently st_blksize being returned
in stat structure to the user space does not use this field that comes
from the server. It is being calculated as follows in
generic_fillattr():

stat->blksize = (1 << inode->i_blkbits);

So there may not be a need to put st_blksize on the protocol. Further,
inode->i_blkbits is copied from sb->s_blocksize_bits. For 9P this value
is obtained as:

sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
and
v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ;

Due to the above calculation sometimes stat() on a file can report
incorrect values. For example, if I mount 9P file system with
msize=5000 stat on a file shows me IO Block: 8192! However, we don't
consider this when we do actual file data transfer. We use 
clnt->msize - P9_IOHDRSZ.
Hence it looks to me like i_blkbits is only used to return stat data.

> 
> 
> > 
> >  st_blocks[8]
> > Number of file system blocks allocated
> 
> same here. 

Yes, this should be file size/iounit.

Thanks,
Sripathi.

> 
> > 
> >  st_atime_sec[8]
> > Time of last access, seconds
> > 
> >  st_atime_nsec[8]
> > Time of last access, nanoseconds
> > 
> >  st_mtime_sec[8]
> > Time of last modification, seconds
> > 
> >  st_mtime_nsec[8]
> > Time of last modification, nanoseconds
> > 
> >  st_ctime_sec[8]
> > Time of last status change, seconds
> > 
> >  st_ctime_nsec[8]
> > Time of last status change, nanoseconds
> > 
> > 
> > This patch implements the client side of getattr implementation for 
> > 9P2000.L.
> > It introduces a new structure p9_stat_dotl for getting Linux stat 
> > information
> > along with QID. The data layout is similar to stat structure in Linux user
> > space with the following major differences:
> > 
> > inode (st_ino) is not part of data. Instead qid is.
> > 
> > device (st_dev) is not part of data because this doesn't make sense on the
> > client.
> > 
> > All time variables are 64 bit wide on the wire. The kernel seems to use
> > 32 bit variables for these variables. However, some of the architectures
> > have used 64 bit variables and glibc exposes 64 bit variables to user
> > space on some architectures. Hence to be on the safer side we have made
> > these 64 bit in the protocol. Refer to the comments in
> > include/asm-generic/stat.h
> > 
> > 
> > Signed-off-by: M. Mohan Kumar 
> > Signed-off-by: Sripathi Kodi 
> > ---
> > 
> >  hw/virtio-9p-debug.c |   32 
> >  hw/virtio-9p.c   |   82 
> > ++
> >  hw/virtio-9p.h   |   28 +
> >  3 files changed, 142 insertions(+), 0 deletions(-)
> > 
> > diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
> > index a82b771..8bb817d 100644
> > --- a/hw/virtio-9p-debug.c
> > +++ b/hw/virtio-9p-debug.c
> > @@ -178,6 +178,30 @@ static void pprint_stat(V9fsPDU *pdu, int rx, size_t 
> > *offsetp, const char *name)
> >  fprintf(llogfile, "}");
> >  }
> > 
> > +static void pprint_stat_dotl(V9fsPDU *pdu, int rx, size_t *offsetp,
> > +  const char *name)
> > +{
> > +fprintf(llogfile, "%s={", name);
> > +pprint_qid(pdu, rx, offsetp, "qid");
> > +pprint_int32(pdu, rx, offsetp, ", st_mode");
> > +pprint_int64(pdu, rx, offsetp, ", st_nlink");
> > +pprint_int32(pdu, rx, offsetp, ", st_uid");
> > +pprint_int32(pdu, rx, offsetp, ", st_gid");
> > +pprint_int64(pdu, rx, offsetp, ",

[Qemu-devel] Re: [PATCH V3 2/3] qemu: Generic asynchronous threading framework to offload tasks

2010-06-03 Thread Paolo Bonzini

On 06/03/2010 01:41 PM, Corentin Chary wrote:

 +if (sigprocmask(SIG_SETMASK,&set,&oldset)) {
 +async_abort(errno, "sigprocmask");
 +}
 +
 +qemu_thread_create_attr(&thread,&attr, async_worker_thread, queue);
 +
 +if (sigprocmask(SIG_SETMASK,&oldset, NULL)) {
 +async_abort(errno, "sigprocmask restore");
 +}


I wonder if qemu_thread_create shouldn't block all signals by default. 
Then the cpu and iothreads can unblock whatever they want.


I'll send a patch shortly.

In any case, please use pthread_sigmask instead of sigprocmask.

Paolo



[Qemu-devel] [Bug 588748] Re: QEMU fails to boot DR DOS Plus since 0.6.1

2010-06-03 Thread Anthony Liguori
Can you add some debugging to see what IER is being set to?

Do you have any insight into why DR DOS Plus is failing?

-- 
QEMU fails to boot DR DOS Plus since 0.6.1
https://bugs.launchpad.net/bugs/588748
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: In Progress

Bug description:
The commit in r1049 (serial interrupt fix (Hampa Hug)) prevents booting Digital 
Research DOS Plus.





[Qemu-devel] Re: [PATCH V3 1/3] qemu: Add qemu-wrappers for pthread_attr_t

2010-06-03 Thread Paolo Bonzini

On 06/03/2010 10:56 AM, Gautham R Shenoy wrote:

Add qemu wrappers for pthread_attr_t handling.


The point of these wrappers AFAIU is not only to add error_exit, but 
also to be portable to Windows in the future.  Is it necessary to create 
the threads as detached?  If you set queue->min_threads to zero all 
threads should exit as soon as they finish their work (which is better 
than exiting immediately).


Paolo



[Qemu-devel] Re: [PATCH V3 2/3] qemu: Generic asynchronous threading framework to offload tasks

2010-06-03 Thread Corentin Chary
On Thu, Jun 3, 2010 at 10:56 AM, Gautham R Shenoy  wrote:
> From: Aneesh Kumar K.V 
>
> This patch creates a generic asynchronous-task-offloading infrastructure. It's
> extracted out of the threading framework that is being used by paio.
>
> The reason for extracting out this generic infrastructure of the
> posix-aio-compat.c is so that other subsystems, such as virtio-9p could make 
> use
> of it for offloading tasks that could block.
>
> [...@in.ibm.com: work_item_pool, async_work_init, async_work_release,
> async_cancel_work]
>
> Signed-off-by: Aneesh Kumar K.V 
> Signed-off-by: Gautham R Shenoy 
> ---
>  Makefile.objs |    3 +
>  async-work.c  |  136 
> +
>  async-work.h  |   85 
>  3 files changed, 223 insertions(+), 1 deletions(-)
>  create mode 100644 async-work.c
>  create mode 100644 async-work.h
>
> diff --git a/Makefile.objs b/Makefile.objs
> index ecdd53e..fd5ea4d 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -9,6 +9,8 @@ qobject-obj-y += qerror.o
>
>  block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
>  block-obj-y += nbd.o block.o aio.o aes.o osdep.o qemu-config.o
> +block-obj-y += qemu-thread.o
> +block-obj-y += async-work.o
>  block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
>  block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
>
> @@ -108,7 +110,6 @@ common-obj-y += iov.o
>  common-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
>  common-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
>  common-obj-$(CONFIG_COCOA) += cocoa.o
> -common-obj-$(CONFIG_IOTHREAD) += qemu-thread.o
>  common-obj-y += notify.o event_notifier.o
>  common-obj-y += qemu-timer.o
>
> diff --git a/async-work.c b/async-work.c
> new file mode 100644
> index 000..0675732
> --- /dev/null
> +++ b/async-work.c
> @@ -0,0 +1,136 @@
> +/*
> + * Async work support
> + *
> + * Copyright IBM, Corp. 2010
> + *
> + * Authors:
> + *  Aneesh Kumar K.V 
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2.  See
> + * the COPYING file in the top-level directory.
> + *
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "async-work.h"
> +#include "osdep.h"
> +
> +static void async_abort(int err, const char *what)
> +{
> +    fprintf(stderr, "%s failed: %s\n", what, strerror(err));
> +    abort();
> +}
> +
> +static void *async_worker_thread(void *data)
> +{
> +    struct async_queue *queue = data;
> +
> +    while (1) {
> +        struct work_item *work;
> +        int ret = 0;
> +        qemu_mutex_lock(&(queue->lock));
> +
> +        while (QTAILQ_EMPTY(&(queue->request_list)) &&
> +               (ret != ETIMEDOUT)) {
> +            ret = qemu_cond_timedwait(&(queue->cond),
> +                                        &(queue->lock), 10*10);
> +        }
> +
> +        if (QTAILQ_EMPTY(&(queue->request_list)))
> +            goto check_exit;
> +
> +        work = QTAILQ_FIRST(&(queue->request_list));
> +        QTAILQ_REMOVE(&(queue->request_list), work, node);
> +        queue->idle_threads--;
> +        qemu_mutex_unlock(&(queue->lock));
> +
> +        /* execute the work function */
> +        work->func(work);

Here the queue is empty, but there is a job running. In the VNC server
I need to be able to "join" jobs (before resize, deconnection, etc..).
What do you thing about adding something like qemu_async_join(queue,
work) (if work is null, join all job) ?

> +        async_work_release(queue, work);
> +
> +        qemu_mutex_lock(&(queue->lock));
> +        queue->idle_threads++;
> +
> +check_exit:
> +        if ((queue->idle_threads > 0) &&
> +            (queue->cur_threads > queue->min_threads)) {
> +            /* we retain minimum number of threads */
> +            break;
> +        }
> +        qemu_mutex_unlock(&(queue->lock));
> +    }
> +
> +    queue->idle_threads--;
> +    queue->cur_threads--;
> +    qemu_mutex_unlock(&(queue->lock));
> +
> +    return NULL;
> +}
> +
> +static void spawn_async_thread(struct async_queue *queue)
> +{
> +    QemuThreadAttr attr;
> +    QemuThread thread;
> +    sigset_t set, oldset;
> +
> +    queue->cur_threads++;
> +    queue->idle_threads++;
> +
> +    qemu_thread_attr_init(&attr);
> +
> +    /* create a detached thread so that we don't need to wait on it */
> +    qemu_thread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
> +
> +    /* block all signals */
> +    if (sigfillset(&set)) {
> +        async_abort(errno, "sigfillset");
> +    }
> +
> +    if (sigprocmask(SIG_SETMASK, &set, &oldset)) {
> +        async_abort(errno, "sigprocmask");
> +    }
> +
> +    qemu_thread_create_attr(&thread, &attr, async_worker_thread, queue);
> +
> +    if (sigprocmask(SIG_SETMASK, &oldset, NULL)) {
> +        async_abort(errno, "sigprocmask restore");
> +    }

Using PTHREAD_CREATE_DETACHED and signal stuff here doesn't looks
really portable. Can't we abstract that into qemu-thread (then, we
just need port qemu-

Re: [Qemu-devel] Re: [PATCH 3/3] vnc: threaded VNC server

2010-06-03 Thread Paolo Bonzini
> >> +void vnc_job_push(VncJob *job)
> >> +{
> >> +    vnc_lock_queue(queue);
> >> +    if (QLIST_EMPTY(&job->rectangles)) {
> >> +        qemu_free(job);
> >
> > No need to lock if you get into the "then" block.
> 
> I locked it because the main thread can try to push a job while a
> consumer is removing one, so I can't call QLIST_EMPTY() without
> locking the queue.

You're obviously right.

>>> +    qemu_mutex_unlock(&job->vs->output_mutex);
>>> +
>>> +    if (job->vs->csock != -1 && job->vs->abording != true) {
>>> +        vnc_flush(job->vs);
>>> +    }
>>> +
>>
>> You're accessing the abort flag outside the mutex here.  Also, you are not
>> using vnc_{,un}lock_output.
>
> I assumed that bool (int) where atomic .. but you're right I should lock that.

They are, however: 1) if you access them outside a mutex you have to think about
whether you need memory barriers and whether there are races; 2) since you 
already
own the mutex and you're just keeping it a bit longer, it costs basically 
nothing.
BTW, with the same reasoning you could avoid taking the mutex altogether in
vnc_abort_display_jobs (but I think it's better to keep it).

Also, I took a look at the code again and I noticed this:

>>> +if (job->vs->csock == -1) {
>>> +goto disconnected;
>>> +}

The "goto" is jumping over the unlocking of &job->vs->mutex.  You only want
a "break;" I think.

>>  static void vnc_disconnect_finish(VncState *vs)
>>  {
>> +    vnc_jobs_join(vs); /* Wait encoding jobs */
>> +    vnc_lock(vs);
>
> Possibly racy?  Maybe you have to set the aforementioned new flag
> queue->exit at the beginning of vnc_jobs_join, and refuse new jobs if it is
> set.
>
> vnc_disconnect_finish can only be called by the main thread, I don't
> see how this could be racy, any hint ?

I was thinking of someone queuing jobs between the end of vnc_jobs_join
and the time the vnc_lock is taken.  But indeed jobs cannot be queued
at this time because vnc_refresh can only be called from the same
thread.  So this is correct.

>> Also, if anything waits on the same vs in vnc_refresh while you own it in
>> vnc_disconnect_finish, as soon as you unlock they'll have a dangling
>> pointer.  (After you unlock the mutex the OS wakes the thread, but then
>> pthread_mutex_lock has to check again that no one got the lock in the
>> meanwhile; so QTAILQ_FOREACH_SAFE is not protecting you).  Probably it's
>> better to use a single lock on vd->clients instead of one lock per VncState.

Same here.  No race because everything happens in the main thread.

Paolo



Re: [Qemu-devel] [PATCH] Name the default PCI bus "pci.0" on all architectures

2010-06-03 Thread Andreas Färber

Am 02.06.2010 um 16:12 schrieb Daniel P. Berrange:


On Fri, May 28, 2010 at 08:39:53PM +0100, Paul Brook wrote:

The system emulators for each arch are using inconsistent
naming for the default PCI bus "pci" vs "pci.0". Since it
is conceivable we'll have multiple PCI buses in the future
standardize on "pci.0" for all architectures. This ensures
mgmt apps can rely on a name when assigning PCI devices an
address on the bus using eg '-device e1000,bus=pci.0,addr=3'


No. Bus names are local to the parent device.  None of the host  
bridges
support multiple bridges, so the ".0" suffix makes no sense.  The  
parent

device has no idea whether it owns the "default" pci bus or not.
If you have multiple PCI busses then you can identify them by the  
device

path.


The problem is that the ID names of default devices in machines are  
ABI

sensitive. Management apps need to know what the ID of these default
devices are. The x86 machines have already used 'pci.0' as their name
in the previous 0.12 release and libvirt is using this naming. We  
later
discovered many non-x86 archs have a name of just 'pci'. We need a  
single
consistent naming across all arches, hence this patch whcih  
standardizes

on 'pci.0'.


Iiuc sparc and ppc try to follow the IEEE1275 OpenFirmware naming  
conventions. Those should not blindly be patched to some random  
convention just to make them more x86-like. OpenFirmware uses  
p...@8000 on my ppc machine. In other places, e.g. disks, numbering  
appears to be done locally via @0, @1, etc. See `show-devs` for a  
complete listing.


As suggested by Paul there are device aliases, so that in `qemu-system- 
ppc -cdrom /dev/null` you can run `dev pci` followed by `pwd` to see  
the real device name.
Lacking a working `devalias`, see `dev /aliases .properties` for some  
more: screen, nvram, cd, cdrom, scca, sccb, adb-keyboard, adb-mouse


Andreas


The '.N' convention is used extensively in QEMU and is more
futureproof as & when QEMU supports multiple buses, without requiring
apps to use the more verbose device paths to ensure uniquness.

Daniel
--
|: Red Hat, Engineering, London-o-   http://people.redhat.com/berrange/ 
 :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org 
 :|
|: http://autobuild.org-o- http://search.cpan.org/~danberr/ 
 :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742  
7D3B 9505 :|







Re: [Qemu-devel] [PATCH 0/2] tcg cleanups, part 4

2010-06-03 Thread malc
On Wed, 2 Jun 2010, Richard Henderson wrote:

> The tcg_out_mov patch you've seen before, but now contains a
> TCG_TYPE_REG that should address the concerns you had with 
> the changes to the sparc port.  It's also been updated to HEAD
> to reflect the changes in tcg/i386.
> 
> The second patch is new.
> 

PPC parts are fine with me.

[..snip..]

-- 
mailto:av1...@comtv.ru



Re: [Qemu-devel] [PATCH v2 2/6] MIPS: Initial support of vt82686b south bridge used by fulong mini pc

2010-06-03 Thread Isaku Yamahata
Some comments below.
NOTE: I just checked pci related code and I'm not familiar
  with those chips.


On Wed, May 19, 2010 at 10:27:23PM +0800, Huacai Chen wrote:
> Signed-off-by: Huacai Chen 
> ---
>  Makefile.target |2 +-
>  hw/pc.h |7 +
>  hw/pci_ids.h|8 +
>  hw/vt82c686.c   |  786 
> +++
>  4 files changed, 802 insertions(+), 1 deletions(-)
>  create mode 100644 hw/vt82c686.c
> 
> diff --git a/Makefile.target b/Makefile.target
> index 247a2eb..9ed4a8d 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -221,7 +221,7 @@ obj-mips-y += dma.o vga.o i8259.o
>  obj-mips-y += g364fb.o jazz_led.o
>  obj-mips-y += gt64xxx.o pckbd.o mc146818rtc.o
>  obj-mips-y += piix4.o cirrus_vga.o
> -obj-mips-$(CONFIG_FULONG) += bonito.o
> +obj-mips-$(CONFIG_FULONG) += bonito.o vt82c686.o
>  
>  obj-microblaze-y = petalogix_s3adsp1800_mmu.o
>  
> diff --git a/hw/pc.h b/hw/pc.h
> index 654b7b3..7f0730b 100644
> --- a/hw/pc.h
> +++ b/hw/pc.h
> @@ -143,6 +143,13 @@ void i440fx_init_memory_mappings(PCII440FXState *d);
>  extern PCIDevice *piix4_dev;
>  int piix4_init(PCIBus *bus, int devfn);
>  
> +/* vt82c686.c */
> +int vt82c686b_init(PCIBus * bus, int devfn);
> +void vt82c686b_ac97_init(PCIBus *bus, int devfn);
> +void vt82c686b_mc97_init(PCIBus *bus, int devfn);
> +i2c_bus *vt82c686b_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
> +qemu_irq sci_irq);
> +

vt82c686.h?

>  /* vga.c */
>  enum vga_retrace_method {
>  VGA_RETRACE_DUMB,
> diff --git a/hw/pci_ids.h b/hw/pci_ids.h
> index fe7a121..39e9f1d 100644
> --- a/hw/pci_ids.h
> +++ b/hw/pci_ids.h
> @@ -78,6 +78,14 @@
>  
>  #define PCI_VENDOR_ID_XILINX 0x10ee
>  
> +#define PCI_VENDOR_ID_VIA0x1106
> +#define PCI_DEVICE_ID_VIA_ISA_BRIDGE 0x0686
> +#define PCI_DEVICE_ID_VIA_IDE0x0571
> +#define PCI_DEVICE_ID_VIA_UHCI   0x3038
> +#define PCI_DEVICE_ID_VIA_ACPI   0x3057
> +#define PCI_DEVICE_ID_VIA_AC97   0x3058
> +#define PCI_DEVICE_ID_VIA_MC97   0x3068
> +
>  #define PCI_VENDOR_ID_MARVELL0x11ab
>  
>  #define PCI_VENDOR_ID_ENSONIQ0x1274
> diff --git a/hw/vt82c686.c b/hw/vt82c686.c
> new file mode 100644
> index 000..1045467
> --- /dev/null
> +++ b/hw/vt82c686.c
> @@ -0,0 +1,786 @@
> +/*
> + * VT82C686B south bridge support
> + *
> + * Copyright (c) 2008 yajin (ya...@vm-kernel.org)
> + * Copyright (c) 2009 chenming (chenm...@rdc.faw.com.cn)
> + * Copyright (c) 2010 Huacai Chen (zltjiang...@gmail.com)
> + * This code is licensed under the GNU GPL v2.
> + */
> +
> +#include "hw.h"
> +#include "pc.h"
> +#include "i2c.h"
> +#include "smbus.h"
> +#include "pci.h"
> +#include "isa.h"
> +#include "sysbus.h"
> +#include "mips.h"
> +
> +typedef uint32_t pci_addr_t;
> +#include "pci_host.h"
> +//#define DEBUG_VT82C686B
> +
> +#ifdef DEBUG_VT82C686B
> +#define DPRINTF(fmt, ...) fprintf(stderr, "%s: " fmt, __FUNCTION__, 
> ##__VA_ARGS__)
> +#else
> +#define DPRINTF(fmt, ...)
> +#endif
> +
> +typedef struct SuperIOConfig
> +{
> +uint8_t config[0xff];
> +uint8_t index;
> +uint8_t data;
> +} SuperIOConfig;
> +
> +typedef struct VT82C686BState {
> +PCIDevice dev;
> +SuperIOConfig *superio_conf;
> +} VT82C686BState;
> +
> +uint32_t smb_data[16];
> +static void superio_ioport_writeb(void *opaque, uint32_t addr, uint32_t data)
> +{
> +int can_write;
> +SuperIOConfig *superio_conf = (SuperIOConfig *)opaque;
> +
> +DPRINTF("superio_ioport_writeb  address 0x%x  val 0x%x  \n", addr, data);
> +if (addr == 0x3f0) {
> +superio_conf->index = data & 0xff;
> +} else {
> +/* 0x3f1 */
> +switch (superio_conf->index) {
> +case 0x00 ... 0xdf:
> +case 0xe4:
> +case 0xe5:
> +case 0xe9 ... 0xed:
> +case 0xf3:
> +case 0xf5:
> +case 0xf7:
> +case 0xf9 ... 0xfb:
> +case 0xfd ... 0xff:
> +can_write = 0;
> +break;
> +default:
> +can_write = 1;
> +
> +if (can_write) {
> +switch (superio_conf->index) {
> +case 0xe7:
> +if ((data & 0xff) != 0xfe) {
> +DPRINTF("chage uart 1 base. unsupported yet \n");
> +}
> +break;
> +case 0xe8:
> +if ((data & 0xff) != 0xbe) {
> +DPRINTF("chage uart 2 base. unsupported yet \n");
> +}
> +break;
> +
> +default:
> +superio_conf->config[superio_conf->index] = data & 0xff;
> +}
> +}
> +}
> +superio_conf->config[superio_conf->index] = data & 0xff;
> +}
> +}
> +
> +static uint32_t superio_ioport_readb(void *opaque, uint32_t addr)
> +{
> +SuperIOConfig *superio_conf = (SuperIOConfig *)opaque;
> +
>

Re: [Qemu-devel] Re: [PATCH v2 2/2] basic machine opts framework

2010-06-03 Thread Paul Brook
> the "irqchip" option, if you note, is not x86-specific, in any case.
> Any machine has an irqchip. The first idea was to use something like
> "apic=in_kernel|userspace" which would be, that, very x86-centric.

How is this not x86-pc specific? All you're doing is creating two different 
machines, one with an APIC and one without.  In principle this is no different 
to what we have with pc v.s. isapc.

If you want machine properties (to avoid having to enumerate all the available 
machine variants) then these properties should be machine specific.

Incidentally, you patch appears to allow creation of a machine with a cpu that 
claims to have an APIC, but without an APIC present. Is that intentional?

Paul



[Qemu-devel] [PATCH V3 3/3] qemu: Convert AIO code to use the generic threading infrastructure.

2010-06-03 Thread Gautham R Shenoy
This patch makes the paio subsystem use the generic work offloading
infrastructure, there by decoupling asynchronous threading framework portion
out of posix-aio-compat.c

The patch has been tested with fstress.

Signed-off-by: Gautham R Shenoy 
---
 posix-aio-compat.c |  155 ++--
 1 files changed, 29 insertions(+), 126 deletions(-)

diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index b43c531..f2e7c6a 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -28,6 +28,7 @@
 #include "block_int.h"
 
 #include "block/raw-posix-aio.h"
+#include "async-work.h"
 
 
 struct qemu_paiocb {
@@ -50,6 +51,7 @@ struct qemu_paiocb {
 struct qemu_paiocb *next;
 
 int async_context_id;
+struct work_item *work;
 };
 
 typedef struct PosixAioState {
@@ -57,15 +59,8 @@ typedef struct PosixAioState {
 struct qemu_paiocb *first_aio;
 } PosixAioState;
 
-
-static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-static pthread_t thread_id;
-static pthread_attr_t attr;
 static int max_threads = 64;
-static int cur_threads = 0;
-static int idle_threads = 0;
-static QTAILQ_HEAD(, qemu_paiocb) request_list;
+static struct async_queue aio_request_list;
 
 #ifdef CONFIG_PREADV
 static int preadv_present = 1;
@@ -84,39 +79,6 @@ static void die(const char *what)
 die2(errno, what);
 }
 
-static void mutex_lock(pthread_mutex_t *mutex)
-{
-int ret = pthread_mutex_lock(mutex);
-if (ret) die2(ret, "pthread_mutex_lock");
-}
-
-static void mutex_unlock(pthread_mutex_t *mutex)
-{
-int ret = pthread_mutex_unlock(mutex);
-if (ret) die2(ret, "pthread_mutex_unlock");
-}
-
-static int cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
-   struct timespec *ts)
-{
-int ret = pthread_cond_timedwait(cond, mutex, ts);
-if (ret && ret != ETIMEDOUT) die2(ret, "pthread_cond_timedwait");
-return ret;
-}
-
-static void cond_signal(pthread_cond_t *cond)
-{
-int ret = pthread_cond_signal(cond);
-if (ret) die2(ret, "pthread_cond_signal");
-}
-
-static void thread_create(pthread_t *thread, pthread_attr_t *attr,
-  void *(*start_routine)(void*), void *arg)
-{
-int ret = pthread_create(thread, attr, start_routine, arg);
-if (ret) die2(ret, "pthread_create");
-}
-
 static ssize_t handle_aiocb_ioctl(struct qemu_paiocb *aiocb)
 {
int ret;
@@ -300,47 +262,27 @@ static ssize_t handle_aiocb_rw(struct qemu_paiocb *aiocb)
 return nbytes;
 }
 
-static void *aio_thread(void *unused)
+static void aio_thread(struct work_item *work)
 {
-pid_t pid;
 
-pid = getpid();
-
-while (1) {
-struct qemu_paiocb *aiocb;
-ssize_t ret = 0;
-qemu_timeval tv;
-struct timespec ts;
-
-qemu_gettimeofday(&tv);
-ts.tv_sec = tv.tv_sec + 10;
-ts.tv_nsec = 0;
-
-mutex_lock(&lock);
+pid_t pid;
 
-while (QTAILQ_EMPTY(&request_list) &&
-   !(ret == ETIMEDOUT)) {
-ret = cond_timedwait(&cond, &lock, &ts);
-}
+struct qemu_paiocb *aiocb = (struct qemu_paiocb *) work->private;
+ssize_t ret = 0;
 
-if (QTAILQ_EMPTY(&request_list))
-break;
+pid = getpid();
 
-aiocb = QTAILQ_FIRST(&request_list);
-QTAILQ_REMOVE(&request_list, aiocb, node);
-aiocb->active = 1;
-idle_threads--;
-mutex_unlock(&lock);
+aiocb->active = 1;
 
-switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) {
-case QEMU_AIO_READ:
-case QEMU_AIO_WRITE:
+switch (aiocb->aio_type & QEMU_AIO_TYPE_MASK) {
+case QEMU_AIO_READ:
+case QEMU_AIO_WRITE:
ret = handle_aiocb_rw(aiocb);
break;
-case QEMU_AIO_FLUSH:
-ret = handle_aiocb_flush(aiocb);
-break;
-case QEMU_AIO_IOCTL:
+case QEMU_AIO_FLUSH:
+ret = handle_aiocb_flush(aiocb);
+break;
+case QEMU_AIO_IOCTL:
ret = handle_aiocb_ioctl(aiocb);
break;
default:
@@ -349,57 +291,28 @@ static void *aio_thread(void *unused)
break;
}
 
-mutex_lock(&lock);
-aiocb->ret = ret;
-idle_threads++;
-mutex_unlock(&lock);
-
-if (kill(pid, aiocb->ev_signo)) die("kill failed");
-}
-
-idle_threads--;
-cur_threads--;
-mutex_unlock(&lock);
+aiocb->ret = ret;
 
-return NULL;
-}
-
-static void spawn_thread(void)
-{
-sigset_t set, oldset;
-
-cur_threads++;
-idle_threads++;
-
-/* block all signals */
-if (sigfillset(&set)) die("sigfillset");
-if (sigprocmask(SIG_SETMASK, &set, &oldset)) die("sigprocmask");
-
-thread_create(&thread_id, &attr, aio_thread, NULL);
-
-if (sigprocmask(SIG_SETMASK, &oldset, NULL)) die("sigprocmask restore");
+if (kill(pid, aiocb->ev_signo)) die("kill failed");
 }
 
 static void qem

[Qemu-devel] [PATCH V3 2/3] qemu: Generic asynchronous threading framework to offload tasks

2010-06-03 Thread Gautham R Shenoy
From: Aneesh Kumar K.V 

This patch creates a generic asynchronous-task-offloading infrastructure. It's
extracted out of the threading framework that is being used by paio.

The reason for extracting out this generic infrastructure of the
posix-aio-compat.c is so that other subsystems, such as virtio-9p could make use
of it for offloading tasks that could block.

[...@in.ibm.com: work_item_pool, async_work_init, async_work_release,
async_cancel_work]

Signed-off-by: Aneesh Kumar K.V 
Signed-off-by: Gautham R Shenoy 
---
 Makefile.objs |3 +
 async-work.c  |  136 +
 async-work.h  |   85 
 3 files changed, 223 insertions(+), 1 deletions(-)
 create mode 100644 async-work.c
 create mode 100644 async-work.h

diff --git a/Makefile.objs b/Makefile.objs
index ecdd53e..fd5ea4d 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -9,6 +9,8 @@ qobject-obj-y += qerror.o
 
 block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
 block-obj-y += nbd.o block.o aio.o aes.o osdep.o qemu-config.o
+block-obj-y += qemu-thread.o
+block-obj-y += async-work.o
 block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
@@ -108,7 +110,6 @@ common-obj-y += iov.o
 common-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
 common-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
-common-obj-$(CONFIG_IOTHREAD) += qemu-thread.o
 common-obj-y += notify.o event_notifier.o
 common-obj-y += qemu-timer.o
 
diff --git a/async-work.c b/async-work.c
new file mode 100644
index 000..0675732
--- /dev/null
+++ b/async-work.c
@@ -0,0 +1,136 @@
+/*
+ * Async work support
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Aneesh Kumar K.V 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "async-work.h"
+#include "osdep.h"
+
+static void async_abort(int err, const char *what)
+{
+fprintf(stderr, "%s failed: %s\n", what, strerror(err));
+abort();
+}
+
+static void *async_worker_thread(void *data)
+{
+struct async_queue *queue = data;
+
+while (1) {
+struct work_item *work;
+int ret = 0;
+qemu_mutex_lock(&(queue->lock));
+
+while (QTAILQ_EMPTY(&(queue->request_list)) &&
+   (ret != ETIMEDOUT)) {
+ret = qemu_cond_timedwait(&(queue->cond),
+&(queue->lock), 10*10);
+}
+
+if (QTAILQ_EMPTY(&(queue->request_list)))
+goto check_exit;
+
+work = QTAILQ_FIRST(&(queue->request_list));
+QTAILQ_REMOVE(&(queue->request_list), work, node);
+queue->idle_threads--;
+qemu_mutex_unlock(&(queue->lock));
+
+/* execute the work function */
+work->func(work);
+async_work_release(queue, work);
+
+qemu_mutex_lock(&(queue->lock));
+queue->idle_threads++;
+
+check_exit:
+if ((queue->idle_threads > 0) &&
+(queue->cur_threads > queue->min_threads)) {
+/* we retain minimum number of threads */
+break;
+}
+qemu_mutex_unlock(&(queue->lock));
+}
+
+queue->idle_threads--;
+queue->cur_threads--;
+qemu_mutex_unlock(&(queue->lock));
+
+return NULL;
+}
+
+static void spawn_async_thread(struct async_queue *queue)
+{
+QemuThreadAttr attr;
+QemuThread thread;
+sigset_t set, oldset;
+
+queue->cur_threads++;
+queue->idle_threads++;
+
+qemu_thread_attr_init(&attr);
+
+/* create a detached thread so that we don't need to wait on it */
+qemu_thread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+/* block all signals */
+if (sigfillset(&set)) {
+async_abort(errno, "sigfillset");
+}
+
+if (sigprocmask(SIG_SETMASK, &set, &oldset)) {
+async_abort(errno, "sigprocmask");
+}
+
+qemu_thread_create_attr(&thread, &attr, async_worker_thread, queue);
+
+if (sigprocmask(SIG_SETMASK, &oldset, NULL)) {
+async_abort(errno, "sigprocmask restore");
+}
+}
+
+void qemu_async_submit(struct async_queue *queue, struct work_item *work)
+{
+qemu_mutex_lock(&(queue->lock));
+if (queue->idle_threads == 0 && queue->cur_threads < queue->max_threads) {
+spawn_async_thread(queue);
+}
+QTAILQ_INSERT_TAIL(&(queue->request_list), work, node);
+qemu_mutex_unlock(&(queue->lock));
+qemu_cond_signal(&(queue->cond));
+}
+
+int qemu_async_cancel_work(struct async_queue *queue, struct work_item *work)
+{
+struct work_item *ret_work;
+int found = 0;
+
+qemu_mutex_lock(&(queue->lock));
+QTAILQ_FOREACH(ret_work, &(queue->request_list), node) {
+if (ret_work == work) {
+QTAILQ_REMOVE(&(queue->request_list), ret_work, node);
+found = 1;
+  

[Qemu-devel] [PATCH V3 1/3] qemu: Add qemu-wrappers for pthread_attr_t

2010-06-03 Thread Gautham R Shenoy
Add qemu wrappers for pthread_attr_t handling.


Signed-off-by: Gautham R Shenoy 
---
 qemu-thread.c |   34 ++
 qemu-thread.h |   11 +++
 2 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/qemu-thread.c b/qemu-thread.c
index 3923db7..524860c 100644
--- a/qemu-thread.c
+++ b/qemu-thread.c
@@ -142,6 +142,40 @@ void qemu_thread_create(QemuThread *thread,
 error_exit(err, __func__);
 }
 
+void qemu_thread_create_attr(QemuThread *thread, QemuThreadAttr *attr1,
+   void *(*start_routine)(void*),
+   void *arg)
+{
+int err;
+
+err = pthread_create(&thread->thread, &(attr1->attr), start_routine,
+arg);
+if (err)
+error_exit(err, __func__);
+}
+
+void qemu_thread_attr_init(QemuThreadAttr *attr1)
+{
+int err;
+
+err = pthread_attr_init(&(attr1->attr));
+
+if (err) {
+error_exit(err, __func__);
+}
+}
+
+void qemu_thread_attr_setdetachstate(QemuThreadAttr *attr1, int detachstate)
+{
+int err;
+
+err = pthread_attr_setdetachstate(&(attr1->attr), detachstate);
+
+if (err) {
+error_exit(err, __func__);
+}
+}
+
 void qemu_thread_signal(QemuThread *thread, int sig)
 {
 int err;
diff --git a/qemu-thread.h b/qemu-thread.h
index 5ef4a3a..361ef19 100644
--- a/qemu-thread.h
+++ b/qemu-thread.h
@@ -15,9 +15,14 @@ struct QemuThread {
 pthread_t thread;
 };
 
+struct QemuThreadAttr {
+pthread_attr_t attr;
+};
+
 typedef struct QemuMutex QemuMutex;
 typedef struct QemuCond QemuCond;
 typedef struct QemuThread QemuThread;
+typedef struct QemuThreadAttr QemuThreadAttr;
 
 void qemu_mutex_init(QemuMutex *mutex);
 void qemu_mutex_lock(QemuMutex *mutex);
@@ -34,7 +39,13 @@ int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, 
uint64_t msecs);
 void qemu_thread_create(QemuThread *thread,
void *(*start_routine)(void*),
void *arg);
+void qemu_thread_create_attr(QemuThread *thread, QemuThreadAttr *attr1,
+   void *(*start_routine)(void*),
+   void *arg);
 void qemu_thread_signal(QemuThread *thread, int sig);
 void qemu_thread_self(QemuThread *thread);
 int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2);
+
+void qemu_thread_attr_init(QemuThreadAttr *attr1);
+void qemu_thread_attr_setdetachstate(QemuThreadAttr *attr1, int detachstate);
 #endif




[Qemu-devel] [PATCH V3 0/3] qemu: Make AIO threading framework generic.

2010-06-03 Thread Gautham R Shenoy
Hi,

This is the v3 of the patch-series to have a generic asynchronous task
offloading framework within qemu.

V2 can be found here:
http://lists.gnu.org/archive/html/qemu-devel/2010-05/msg02227.html

Changes from V2:
=
- Made use of the qemu-thread.c wrappers in place of pthread_() calls.
- Added a couple fo qemu-thread wrappers for handling pthread_attr_t type.
- Audited the error handling in the generic asynchronous task offloading
  framework code.

Description
=
This patch series decouples the asynchrnous threading framework
implementation from posix-aio-compat.c to implement a generic asynchrnous
task offloading threading framework which can be used by other subsystems
within QEMU.

Currently within QEMU, the AIO subsystem (paio) creates a bunch of
asynchronous threads to offload any blocking operations so that
the vcpu threads and the IO thread can go back to servicing any
other guest requests.

This offloading framework can be used by subsystems such as virtio-9p,
Asynchronous encoding for vnc-server, so that the vcpu thread can offload
blocking operations on to the asynchronous threads and resume servicing
any other guest requests. The asynchronous threads, after
finishing the blocking operations can then transfer the control over
to the IO thread so that the latter can handle the post_blocking_operation().

The patch series passed fsstress test without any issues.

Could it be considered for inclusion ?

---

Aneesh Kumar K.V (1):
  qemu: Generic asynchronous threading framework to offload tasks

Gautham R Shenoy (2):
  qemu: Add qemu-wrappers for pthread_attr_t
  qemu: Convert AIO code to use the generic threading infrastructure.


 Makefile.objs  |3 +
 async-work.c   |  136 ++
 async-work.h   |   85 +
 posix-aio-compat.c |  155 ++--
 qemu-thread.c  |   34 +++
 qemu-thread.h  |   11 
 6 files changed, 297 insertions(+), 127 deletions(-)
 create mode 100644 async-work.c
 create mode 100644 async-work.h

-- 
Thanks and Regards
gautham.



[Qemu-devel] [PATCH v3 0/7] MIPS: Initial support for fulong (Loongson-2E based) mini pc

2010-06-03 Thread chen huacai
Changes from v2:
1, split the code of CPU definition and machine construction
2, remove useless memory r/w functions
3, add source of pmon
4, code style and other errors have been fixed

Changes from v1:
1, fulong support is limited to mips64el only (doesn't affect mips,
mips64 and mipsel)
2, qdev model is used for Bonito north bridge
3, code style and other errors have been fixed

This series of patches are for qemu master branch. They make qemu
initially support fulong (Loongson-2E based) mini pc, a new type of
MIPS machine.
Usage:
  1, Load PMON as bios, and then load OS in PMON shell
qemu-system-mips64el -M fulong2e -bios pmon_fulong2e.bin -hda /root/hda.img
  2, Load OS directly with -kernel parameter
qemu-system-mips64el -M fulong2e -kernel vmlinux -append
"root=/dev/hda1 console=ttyS0" -hda /root/hda.img

Patches include:
[PATCH 1/7] MIPS: Initial support of bonito north bridge used by fulong mini pc
[PATCH 2/7] MIPS: Initial support of vt82686b south bridge used by
fulong mini pc
[PATCH 3/7] MIPS: Initial support of VIA IDE controller used by fulong mini pc
[PATCH 4/7] MIPS: Initial support of VIA USB controller used by fulong mini pc
[PATCH 5/7] MIPS: Initial support of fulong mini pc (CPU definition)
[PATCH 6/7] MIPS: Initial support of fulong mini pc (machine construction)
[PATCH 7/7] MIPS: add PMON BIOS used by fulong mini pc

Signed-off-by: Huacai Chen 



Re: [Qemu-devel] [PATCH v2 1/6] MIPS: Initial support of bonito north bridge used by fulong mini pc

2010-06-03 Thread Isaku Yamahata
Maybe it is time to enhance pci_host.c to take a callback
to decode the address, so that you can use pci_host helper functions.
It would simplify this patch and eliminates code duplication.

Some comments below.

On Wed, May 19, 2010 at 10:26:32PM +0800, Huacai Chen wrote:
> Signed-off-by: Huacai Chen 
> ---
>  Makefile.target  |1 +
>  default-configs/mips64el-softmmu.mak |1 +
>  hw/bonito.c  |  950 
> ++
>  hw/mips.h|3 +
>  4 files changed, 955 insertions(+), 0 deletions(-)
>  create mode 100644 hw/bonito.c
> 
> diff --git a/Makefile.target b/Makefile.target
> index a22484e..247a2eb 100644
> --- a/Makefile.target
> +++ b/Makefile.target
> @@ -221,6 +221,7 @@ obj-mips-y += dma.o vga.o i8259.o
>  obj-mips-y += g364fb.o jazz_led.o
>  obj-mips-y += gt64xxx.o pckbd.o mc146818rtc.o
>  obj-mips-y += piix4.o cirrus_vga.o
> +obj-mips-$(CONFIG_FULONG) += bonito.o
>  
>  obj-microblaze-y = petalogix_s3adsp1800_mmu.o
>  
> diff --git a/default-configs/mips64el-softmmu.mak 
> b/default-configs/mips64el-softmmu.mak
> index 6fa54a3..b731c74 100644
> --- a/default-configs/mips64el-softmmu.mak
> +++ b/default-configs/mips64el-softmmu.mak
> @@ -27,3 +27,4 @@ CONFIG_DP8393X=y
>  CONFIG_DS1225Y=y
>  CONFIG_MIPSNET=y
>  CONFIG_PFLASH_CFI01=y
> +CONFIG_FULONG=y
> diff --git a/hw/bonito.c b/hw/bonito.c
> new file mode 100644
> index 000..246c12a
> --- /dev/null
> +++ b/hw/bonito.c
> @@ -0,0 +1,950 @@
> +/*
> + * bonito north bridge support
> + *
> + * Copyright (c) 2008 yajin (ya...@vm-kernel.org)
> + * Copyright (c) 2010 Huacai Chen (zltjiang...@gmail.com)
> + *
> + * This code is licensed under the GNU GPL v2.
> + */
> +
> +/*
> + * fulong 2e mini pc has a bonito north bridge.
> + */
> +
> +/* what is the meaning of devfn in qemu and IDSEL in bonito northbridge?
> + *
> + * devfn   pci_slot<<3  + funno
> + * one pci bus can have 32 devices and each device can have 8 functions.
> + *
> + * In bonito north bridge, pci slot = IDSEL bit - 12.
> + * For example, PCI_IDSEL_VIA686B = 17,
> + * pci slot = 17-12=5
> + *
> + * so
> + * VT686B_FUN0's devfn = (5<<3)+0
> + * VT686B_FUN1's devfn = (5<<3)+1
> + *
> + * qemu also uses pci address for north bridge to access pci config register.
> + * bus_no   [23:16]
> + * dev_no   [15:11]
> + * fun_no   [10:8]
> + * reg_no   [7:2]
> + *
> + * so function bonito_sbridge_pciaddr for the translation from
> + * north bridge address to pci address.
> + */
> +
> +#include 
> +
> +#include "hw.h"
> +#include "pci.h"
> +#include "pc.h"
> +#include "mips.h"
> +
> +typedef target_phys_addr_t pci_addr_t;

This isn't necessary anymore.
Perhaps you wrote this patch before the pci host clean ups.


> +#include "pci_host.h"
> +
> +//#define DEBUG_BONITO
> +
> +#ifdef DEBUG_BONITO
> +#define DPRINTF(fmt, ...) fprintf(stderr, "%s: " fmt, __FUNCTION__, 
> ##__VA_ARGS__)
> +#else
> +#define DPRINTF(fmt, ...)
> +#endif
> +
> +/* from linux soure code. include/asm-mips/mips-boards/bonito64.h*/
> +#define BONITO_BOOT_BASE0x1fc0
> +#define BONITO_BOOT_SIZE0x0010
> +#define BONITO_BOOT_TOP (BONITO_BOOT_BASE+BONITO_BOOT_SIZE-1)
> +#define BONITO_FLASH_BASE   0x1c00
> +#define BONITO_FLASH_SIZE   0x0300
> +#define BONITO_FLASH_TOP(BONITO_FLASH_BASE+BONITO_FLASH_SIZE-1)
> +#define BONITO_SOCKET_BASE  0x1f80
> +#define BONITO_SOCKET_SIZE  0x0040
> +#define BONITO_SOCKET_TOP   (BONITO_SOCKET_BASE+BONITO_SOCKET_SIZE-1)
> +#define BONITO_REG_BASE 0x1fe0
> +#define BONITO_REG_SIZE 0x0004
> +#define BONITO_REG_TOP  (BONITO_REG_BASE+BONITO_REG_SIZE-1)
> +#define BONITO_DEV_BASE 0x1ff0
> +#define BONITO_DEV_SIZE 0x0010
> +#define BONITO_DEV_TOP  (BONITO_DEV_BASE+BONITO_DEV_SIZE-1)
> +#define BONITO_PCILO_BASE   0x1000
> +#define BONITO_PCILO_BASE_VA0xb000
> +#define BONITO_PCILO_SIZE   0x0c00
> +#define BONITO_PCILO_TOP(BONITO_PCILO_BASE+BONITO_PCILO_SIZE-1)
> +#define BONITO_PCILO0_BASE  0x1000
> +#define BONITO_PCILO1_BASE  0x1400
> +#define BONITO_PCILO2_BASE  0x1800
> +#define BONITO_PCIHI_BASE   0x2000
> +#define BONITO_PCIHI_SIZE   0x2000
> +#define BONITO_PCIHI_TOP(BONITO_PCIHI_BASE+BONITO_PCIHI_SIZE-1)
> +#define BONITO_PCIIO_BASE   0x1fd0
> +#define BONITO_PCIIO_BASE_VA0xbfd0
> +#define BONITO_PCIIO_SIZE   0x0001
> +#define BONITO_PCIIO_TOP(BONITO_PCIIO_BASE+BONITO_PCIIO_SIZE-1)
> +#define BONITO_PCICFG_BASE  0x1fe8
> +#define BONITO_PCICFG_SIZE  0x0008
> +#define BONITO_PCICFG_TOP   (BONITO_PCICFG_BASE+BONITO_PCICFG_SIZE-1)
> +
> +
> +#define BONITO_PCICONFIGBASE0x00
> +#define BONITO_REGBASE  0x100
> +
> +#define BONITO_PCICONFIG_BASE   (BONITO_PCICONFIGBASE+BONITO_REG_BASE)
> +#define BONITO_PCICONFIG_SIZE   (0x100)
>

[Qemu-devel] [Bug 585113] Re: e1000 irq problems after live migration with qemu-kvm 0.12.4

2010-06-03 Thread Michael Tokarev
Please note that this bug affects 0.12 stable as well.  It'd be really
nice to know the commit which fixed the issue, in order to backport it
to -stable...

-- 
e1000 irq problems after live migration with qemu-kvm 0.12.4 
https://bugs.launchpad.net/bugs/585113
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Fix Committed

Bug description:
sorry for resubmitting. i accidently moved this bug to qemu-kvm at launchpad 
where it is stuck...

After live migrating ubuntu 9.10 server (2.6.31-14-server) and suse linux 10.1 
(2.6.16.13-4-smp)
it happens sometimes that the guest runs into irq problems. i mention these 2 
guest oss
since i have seen the error there. there are likely others around with the same 
problem.

on the host i run 2.6.33.3 (kernel+mod) and qemu-kvm 0.12.4.

i started a vm with:
/usr/bin/qemu-kvm-0.12.4  -net tap,vlan=141,script=no,downscript=no,ifname=tap0 
-net nic,vlan=141,model=e1000,macaddr=52:54:00:ff:00:72   -drive 
file=/dev/sdb,if=ide,boot=on,cache=none,aio=native  -m 1024 -cpu 
qemu64,model_id='Intel(R) Xeon(R) CPU   E5430  @ 2.66GHz'  -monitor 
tcp:0:4001,server,nowait -vnc :1 -name 'migration-test-9-10'  -boot 
order=dc,menu=on  -k de  -incoming tcp:172.21.55.22:5001  -pidfile 
/var/run/qemu/vm-155.pid  -mem-path /hugepages -mem-prealloc  -rtc 
base=utc,clock=host -usb -usbdevice tablet 

for testing i have a clean ubuntu 9.10 server 64-bit install and created a 
small script with fetches a dvd iso from a local server and checking md5sum in 
an endless loop.

the download performance is approx. 50MB/s on that vm.

to trigger the error i did several migrations of the vm throughout the last 
days. finally I ended up in the following oops in the guest:

[64442.298521] irq 10: nobody cared (try booting with the "irqpoll" option)
[64442.299175] Pid: 0, comm: swapper Not tainted 2.6.31-14-server #48-Ubuntu
[64442.299179] Call Trace:
[64442.299185][] __report_bad_irq+0x26/0xa0
[64442.299227]  [] note_interrupt+0x18c/0x1d0
[64442.299232]  [] handle_fasteoi_irq+0xd5/0x100
[64442.299244]  [] handle_irq+0x1d/0x30
[64442.299246]  [] do_IRQ+0x67/0xe0
[64442.299249]  [] ret_from_intr+0x0/0x11
[64442.299266]  [] ? handle_IRQ_event+0x24/0x160
[64442.299269]  [] ? handle_edge_irq+0xcf/0x170
[64442.299271]  [] ? handle_irq+0x1d/0x30
[64442.299273]  [] ? do_IRQ+0x67/0xe0
[64442.299275]  [] ? ret_from_intr+0x0/0x11
[64442.299290]  [] ? _spin_unlock_irqrestore+0x14/0x20
[64442.299302]  [] ? scsi_dispatch_cmd+0x16c/0x2d0
[64442.299307]  [] ? scsi_request_fn+0x3aa/0x500
[64442.299322]  [] ? __blk_run_queue+0x6c/0x150
[64442.299324]  [] ? blk_run_queue+0x2b/0x50
[64442.299327]  [] ? scsi_run_queue+0xcf/0x2a0
[64442.299336]  [] ? scsi_next_command+0x3d/0x60
[64442.299338]  [] ? scsi_end_request+0xab/0xb0
[64442.299340]  [] ? scsi_io_completion+0x9e/0x4d0
[64442.299348]  [] ? default_spin_lock_flags+0x9/0x10
[64442.299351]  [] ? scsi_finish_command+0xbd/0x130
[64442.299353]  [] ? scsi_softirq_done+0x145/0x170
[64442.299356]  [] ? blk_done_softirq+0x7d/0x90
[64442.299368]  [] ? __do_softirq+0xbd/0x200
[64442.299370]  [] ? call_softirq+0x1c/0x30
[64442.299372]  [] ? do_softirq+0x55/0x90
[64442.299374]  [] ? irq_exit+0x85/0x90
[64442.299376]  [] ? do_IRQ+0x70/0xe0
[64442.299379]  [] ? ret_from_intr+0x0/0x11
[64442.299380][] ? native_safe_halt+0x6/0x10
[64442.299390]  [] ? default_idle+0x4c/0xe0
[64442.299395]  [] ? atomic_notifier_call_chain+0x15/0x20
[64442.299398]  [] ? cpu_idle+0xb2/0x100
[64442.299406]  [] ? rest_init+0x66/0x70
[64442.299424]  [] ? start_kernel+0x352/0x35b
[64442.299427]  [] ? x86_64_start_reservations+0x125/0x129
[64442.299429]  [] ? x86_64_start_kernel+0xfa/0x109
[64442.299433] handlers:
[64442.299840] [] (e1000_intr+0x0/0x190 [e1000])
[64442.300046] Disabling IRQ #10

After this the guest is still allive, but download performance is down to 
approx. 500KB/s

This error is definetly not triggerable with option -no-kvm-irqchip. I have 
seen this error occasionally
since my first experiments with qemu-kvm-88 and also without hugetablefs.

Help appreciated.





Re: [Qemu-devel] [PATCH 0/4] Add virtio disk identification support

2010-06-03 Thread john cooper
john cooper wrote:
> I'm all for putting this issue to rest, but if we're
> going to live with an ioctl interface retrieving the
> id string, let's make it a little more friendly from
> the user's perspective.

The qemu side of the patch is ok as-is.  The guest-user
interface issue is contained in the driver.  While I
see the example ioctl patch has been incorporated into
the virtio_blk driver, there can be no data retrieved
through this interface as virtblk_get_id() will fail
without the qemu counterpart.  So we can clean up the
details without concern of existing usage.

The only difference (as above) is allowing the caller
to pass a buffer size to the driver and the driver
informing the caller of the total number of bytes
available:

#include 
#include 
#include 

#define IOCTL_CMD   'VBID'
#define BUFSZ   10

main()
{
int fd, rv;
char buf[255];

bzero(buf, sizeof (buf));
buf[0] = BUFSZ;
if ((fd = open("/dev/vda", O_RDONLY)) < 0)
perror("open");
else if ((rv = ioctl(fd, IOCTL_CMD, buf)) < 0)
perror("ioctl");
else
printf("[%s] %d of %d bytes\n", buf,
   BUFSZ < rv ? BUFSZ : rv, rv);
}


Signed-off-by: john cooper 
---

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 83fa09a..6237732 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -225,15 +225,29 @@ static int virtblk_ioctl(struct block_device *bdev, 
fmode_t mode,
struct gendisk *disk = bdev->bd_disk;
struct virtio_blk *vblk = disk->private_data;
 
+   /* user passes the address of a char[] for return of the id string
+* and has set char[0] to the array size.  copy id string to this
+* char[] and return the number of non-nul characters in the internal
+* id string.  The caller can then determine if all were received.
+*/
if (cmd == 0x56424944) { /* 'VBID' */
void __user *usr_data = (void __user *)data;
char id_str[VIRTIO_BLK_ID_BYTES];
-   int err;
-
-   err = virtblk_get_id(disk, id_str);
-   if (!err && copy_to_user(usr_data, id_str, VIRTIO_BLK_ID_BYTES))
-   err = -EFAULT;
-   return err;
+   unsigned char idlen;
+   int rv;
+
+   if (copy_from_user(&idlen, usr_data, sizeof (idlen)))
+   return -EFAULT;
+   if (VIRTIO_BLK_ID_BYTES < idlen)
+   idlen = VIRTIO_BLK_ID_BYTES;
+   if ((rv = virtblk_get_id(disk, id_str)))
+   return rv;
+   if (copy_to_user(usr_data, id_str, idlen))
+   return -EFAULT;
+   for (rv = 0; rv < VIRTIO_BLK_ID_BYTES; ++rv)
+   if (!id_str[rv])
+   break;
+   return rv;
}
/*
 * Only allow the generic SCSI ioctls if the host can support it.

-- 
john.coo...@redhat.com



Re: [Qemu-devel] Re: [PATCH 3/3] vnc: threaded VNC server

2010-06-03 Thread Corentin Chary
On Thu, Jun 3, 2010 at 9:55 AM, Paolo Bonzini  wrote:
> On 05/29/2010 09:38 AM, Corentin Chary wrote:
>>
>> Implement a threaded VNC server using the producer-consumer model.
>> The main thread will push encoding jobs (a list a rectangles to update)
>> in a queue, and the VNC worker thread will consume that queue and send
>> framebuffer updates to the output buffer.
>>
>> There is three levels of locking:
>> - jobs queue lock: for each operation on the queue (push, pop, isEmpty?)
>> - VncState global lock: mainly used for framebuffer updates to avoid
>>                         screen corruption if the framebuffer is updated
>>                        while the worker threaded is doing something.
>> - VncState::output lock: used to make sure the output buffer is not
>> corrupted
>>                         if two threads try to write on it at the same time
>>
>> While the VNC worker thread is working, the VncState global lock is hold
>> to avoid screen corruptions (this block vnc_refresh() for a short time)
>> but the
>> output lock is not hold because the thread work on its own output buffer.
>> When
>> the encoding job is done, the worker thread will hold the output lock and
>> copy
>> its output buffer in vs->output.
>
> This belong in a comment in the code, not in the commit message (or in
> both).

Right

>> +void vnc_job_push(VncJob *job)
>> +{
>> +    vnc_lock_queue(queue);
>> +    if (QLIST_EMPTY(&job->rectangles)) {
>> +        qemu_free(job);
>
> No need to lock if you get into the "then" block.

I locked it because the main thread can try to push a job while a
consumer is removing one, so I can't call QLIST_EMPTY() without
locking the queue.

>> +    } else {
>> +        QTAILQ_INSERT_TAIL(&queue->jobs, job, next);
>> +        qemu_cond_broadcast(&queue->cond);
>> +    }
>> +    vnc_unlock_queue(queue);
>> +}
>
> ...
>
>> +static int vnc_worker_thread_loop(VncJobQueue *queue)
>> +{
>> +    VncJob *job;
>> +    VncRectEntry *entry, *tmp;
>> +    VncState vs;
>> +    int n_rectangles;
>> +    int saved_offset;
>> +
>> +    vnc_lock_queue(queue);
>> +    if (QTAILQ_EMPTY(&queue->jobs)) {
>> +        qemu_cond_wait(&queue->cond,&queue->mutex);
>> +    }
>> +
>> +    /* If the queue is empty, it's an exit order */
>> +    if (QTAILQ_EMPTY(&queue->jobs)) {
>> +        vnc_unlock_queue(queue);
>> +        return -1;
>> +    }
>
> This is not safe.  It might work with a single consumer, but something like
> this is better:
>
>   vnc_lock_queue(queue);
>   while (!queue->exit && QTAILQ_EMPTY(&queue->jobs)) {
>        qemu_cond_wait(&queue->cond,&queue->mutex);
>   }
>   if (queue->exit) {
>       vnc_unlock_queue(queue);
>       return -1;
>   }

Right,

> (It occurred to me now that maybe you can reuse ->aborting.  Not sure
> though).
>
>> +    qemu_mutex_unlock(&job->vs->output_mutex);
>> +
>> +    if (job->vs->csock != -1 && job->vs->abording != true) {
>> +        vnc_flush(job->vs);
>> +    }
>> +
>
> You're accessing the abort flag outside the mutex here.  Also, you are not
> using vnc_{,un}lock_output.

I assumed that bool (int) where atomic .. but you're right I should lock that.

>> +    job = QTAILQ_FIRST(&queue->jobs);
>> +    vnc_unlock_queue(queue);
>
> ...
>
>> +static void vnc_abord_display_jobs(VncDisplay *vd)
>> +{
>> +    VncState *vs;
>> +
>> +    QTAILQ_FOREACH(vs, &vd->clients, next) {
>> +        vnc_lock_output(vs);
>> +        vs->abording = true;
>> +        vnc_unlock_output(vs);
>> +    }
>> +    QTAILQ_FOREACH(vs, &vd->clients, next) {
>> +        vnc_jobs_join(vs);
>> +    }
>> +    QTAILQ_FOREACH(vs, &vd->clients, next) {
>> +        vnc_lock_output(vs);
>> +        vs->abording = false;
>> +        vnc_unlock_output(vs);
>> +    }
>> +}
>
> It's "abort" not "abord". :-)

Ooops ...

> ...
>
>>  static void vnc_disconnect_finish(VncState *vs)
>>  {
>> +    vnc_jobs_join(vs); /* Wait encoding jobs */
>> +    vnc_lock(vs);
>
> Possibly racy?  Maybe you have to set the aforementioned new flag
> queue->exit at the beginning of vnc_jobs_join, and refuse new jobs if it is
> set.
>
> Also, if anything waits on the same vs in vnc_refresh while you own it in
> vnc_disconnect_finish, as soon as you unlock they'll have a dangling
> pointer.  (After you unlock the mutex the OS wakes the thread, but then
> pthread_mutex_lock has to check again that no one got the lock in the
> meanwhile; so QTAILQ_FOREACH_SAFE is not protecting you).  Probably it's
> better to use a single lock on vd->clients instead of one lock per VncState.

vnc_disconnect_finish can only be called by the main thread, I don't
see how this could be racy, any hint ?
I am missing something ?

>> +void vnc_client_write(void *opaque)
>> +{
>> +    VncState *vs = opaque;
>> +
>> +    vnc_lock_output(vs);
>> +    if (vs->output.offset) {
>> +        vnc_client_write_locked(opaque);
>> +    } else {
>> +        qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
>> +    }
>
> Why the if?  The "else" branch is already

Re: [Qemu-devel] [PATCH 13/13] blockdev: New -blockdev to define a host block device

2010-06-03 Thread Christoph Hellwig
On Wed, Jun 02, 2010 at 06:55:29PM +0200, Markus Armbruster wrote:
> Existing -drive defines both host and guest part.  To make it work
> with -device, we created if=none.  But all this does is peel off guest
> device selection.  The other guest properties such as geometry,
> removable vs. fixed media, and serial number are still in the wrong
> place.
> 
> Instead of overloading -drive even further, create a new, clean option
> to define a host block device.  -drive stays around unchanged for
> command line convenience and backwards compatibility.
> 
> This is just a first step.  Future work includes:

One thing we really needs is a protocol option.  The current colon
syntax means we can't support filenames with colons in them which
users keep requesting.  By making the protocol a separate option
we can sort this out.




[Qemu-devel] Re: [PATCH 3/3] vnc: threaded VNC server

2010-06-03 Thread Paolo Bonzini

On 05/29/2010 09:38 AM, Corentin Chary wrote:

Implement a threaded VNC server using the producer-consumer model.
The main thread will push encoding jobs (a list a rectangles to update)
in a queue, and the VNC worker thread will consume that queue and send
framebuffer updates to the output buffer.

There is three levels of locking:
- jobs queue lock: for each operation on the queue (push, pop, isEmpty?)
- VncState global lock: mainly used for framebuffer updates to avoid
 screen corruption if the framebuffer is updated
while the worker threaded is doing something.
- VncState::output lock: used to make sure the output buffer is not corrupted
 if two threads try to write on it at the same time

While the VNC worker thread is working, the VncState global lock is hold
to avoid screen corruptions (this block vnc_refresh() for a short time) but the
output lock is not hold because the thread work on its own output buffer. When
the encoding job is done, the worker thread will hold the output lock and copy
its output buffer in vs->output.


This belong in a comment in the code, not in the commit message (or in 
both).



+void vnc_job_push(VncJob *job)
+{
+vnc_lock_queue(queue);
+if (QLIST_EMPTY(&job->rectangles)) {
+qemu_free(job);


No need to lock if you get into the "then" block.


+} else {
+QTAILQ_INSERT_TAIL(&queue->jobs, job, next);
+qemu_cond_broadcast(&queue->cond);
+}
+vnc_unlock_queue(queue);
+}


...


+static int vnc_worker_thread_loop(VncJobQueue *queue)
+{
+VncJob *job;
+VncRectEntry *entry, *tmp;
+VncState vs;
+int n_rectangles;
+int saved_offset;
+
+vnc_lock_queue(queue);
+if (QTAILQ_EMPTY(&queue->jobs)) {
+qemu_cond_wait(&queue->cond,&queue->mutex);
+}
+
+/* If the queue is empty, it's an exit order */
+if (QTAILQ_EMPTY(&queue->jobs)) {
+vnc_unlock_queue(queue);
+return -1;
+}


This is not safe.  It might work with a single consumer, but something 
like this is better:


   vnc_lock_queue(queue);
   while (!queue->exit && QTAILQ_EMPTY(&queue->jobs)) {
qemu_cond_wait(&queue->cond,&queue->mutex);
   }
   if (queue->exit) {
   vnc_unlock_queue(queue);
   return -1;
   }

(It occurred to me now that maybe you can reuse ->aborting.  Not sure 
though).



+qemu_mutex_unlock(&job->vs->output_mutex);
+
+if (job->vs->csock != -1 && job->vs->abording != true) {
+vnc_flush(job->vs);
+}
+


You're accessing the abort flag outside the mutex here.  Also, you are 
not using vnc_{,un}lock_output.



+job = QTAILQ_FIRST(&queue->jobs);
+vnc_unlock_queue(queue);


...

> +static void vnc_abord_display_jobs(VncDisplay *vd)
> +{
> +VncState *vs;
> +
> +QTAILQ_FOREACH(vs, &vd->clients, next) {
> +vnc_lock_output(vs);
> +vs->abording = true;
> +vnc_unlock_output(vs);
> +}
> +QTAILQ_FOREACH(vs, &vd->clients, next) {
> +vnc_jobs_join(vs);
> +}
> +QTAILQ_FOREACH(vs, &vd->clients, next) {
> +vnc_lock_output(vs);
> +vs->abording = false;
> +vnc_unlock_output(vs);
> +}
> +}

It's "abort" not "abord". :-)

...


 static void vnc_disconnect_finish(VncState *vs)
 {
+vnc_jobs_join(vs); /* Wait encoding jobs */
+vnc_lock(vs);


Possibly racy?  Maybe you have to set the aforementioned new flag 
queue->exit at the beginning of vnc_jobs_join, and refuse new jobs if it 
is set.


Also, if anything waits on the same vs in vnc_refresh while you own it 
in vnc_disconnect_finish, as soon as you unlock they'll have a dangling 
pointer.  (After you unlock the mutex the OS wakes the thread, but then 
pthread_mutex_lock has to check again that no one got the lock in the 
meanwhile; so QTAILQ_FOREACH_SAFE is not protecting you).  Probably it's 
better to use a single lock on vd->clients instead of one lock per VncState.



+void vnc_client_write(void *opaque)
+{
+VncState *vs = opaque;
+
+vnc_lock_output(vs);
+if (vs->output.offset) {
+vnc_client_write_locked(opaque);
+} else {
+qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
+}


Why the if?  The "else" branch is already done by vnc_client_write_plain.

This may be a good time to port qemu-threads to Windows too.  IO thread 
has no hope to work under Windows at least without major hacks (because 
Windows has no asynchronous interrupts; the only way I can imagine to 
emulate them is a breakpoint) but threaded VNC should work.


Paolo



Re: [Qemu-devel] Arm big endian?

2010-06-03 Thread Paul Brook
> I'm trying to get arm big endian support to work.  I patched the 2.6.33
> kernel to pretend that good old versatilepb can have a big endian CPU
> plugged into it (attached), and then I built a kernel with the attached
> .config, and qemu went "boing":

That's about the result I'd expect. The fact that neither qemu nor linux claim 
to support big-endian mode for this hardware should be your first clue.

> Does this look more like a kernel error, or a qemu error?

Probably both.

Paul



  1   2   >