Re: [Qemu-devel] [PATCH 2/2] tcg-i386: Use segment registers to implement GUEST_BASE.
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 r...@twiddle.net --- 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 sys/syscall.h +# include asm/prctl.h + +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 sys/syscall.h +# include asm/ldt.h + +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
Re: [Qemu-devel] [PATCH 08/16] Move main signal handler setup to os specificfiles.
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 05/16] Introduce os-posix.c and create os_setup_signal_handling()
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
[Qemu-devel] Re: [PATCH 1/4] Add virtio disk identification support
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 cooperjohn.coo...@redhat.com --- 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 @@ # includescsi/sg.h #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
[Qemu-devel] Re: [PATCH 2/4] Add virtio disk identification support
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 cooperjohn.coo...@redhat.com --- 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
Re: [Qemu-devel] [PATCH 12/16] Move chroot handling to OS specific files.
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
Re: [Qemu-devel] qemu:virtio-9p: [RFC] [PATCH 01/02] Send iounit to client for read/write operations
On Tue, 1 Jun 2010 19:47:14 +0530 M. Mohan Kumar mo...@in.ibm.com 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 mo...@in.ibm.com --- 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 @@ -72,6 +72,8 @@ enum p9_proto_version { #define P9_NOFID(u32)(~0) #define P9_MAXWELEM 16 +#define P9_IOHDRSZ 24 + typedef struct V9fsPDU V9fsPDU; struct V9fsPDU @@ -156,6 +158,7 @@ typedef struct V9fsState uint8_t
Re: [Qemu-devel] 9p: [RFC] [PATCH 02/02] Make use of iounit for read/write
On Tue, 1 Jun 2010 19:47:49 +0530 M. Mohan Kumar mo...@in.ibm.com wrote: Change the v9fs_file_readn function to limit the maximum transfer size based on the iounit instead of msize. Also remove the redundant check for limiting the transfer size in v9fs_file_write. This check is done by p9_client_write. Signed-off-by: M. Mohan Kumar mo...@in.ibm.com --- fs/9p/vfs_file.c | 10 ++ 1 files changed, 2 insertions(+), 8 deletions(-) diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 25b300e..b8c0891 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -160,7 +160,7 @@ v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, offset += n; count -= n; total += n; - } while (count 0 n == (fid-clnt-msize - P9_IOHDRSZ)); + } while (count 0 n == fid-iounit); If fid-iounit is zero this will go wrong. With the current version of your server side patch, fid-iounit can be zero, right? if (n 0) total = n; @@ -187,11 +187,7 @@ v9fs_file_read(struct file *filp, char __user *udata, size_t count, P9_DPRINTK(P9_DEBUG_VFS, count %zu offset %lld\n, count, *offset); fid = filp-private_data; - if (count (fid-clnt-msize - P9_IOHDRSZ)) - ret = v9fs_file_readn(filp, NULL, udata, count, *offset); - else - ret = p9_client_read(fid, NULL, udata, *offset, count); - + ret = v9fs_file_readn(filp, NULL, udata, count, *offset); if (ret 0) *offset += ret; @@ -225,8 +221,6 @@ v9fs_file_write(struct file *filp, const char __user * data, clnt = fid-clnt; rsize = fid-iounit; - if (!rsize || rsize clnt-msize-P9_IOHDRSZ) - rsize = clnt-msize - P9_IOHDRSZ; This will be needed if fid-iounit = 0 Thanks, Sripathi. do { if (count rsize) -- 1.6.6.1
[Qemu-devel] Qemu-mips
Hi, What part of the QEMU source code generates translation blocks for mips user emulation? Thanks,
[Qemu-devel] [Bug 589564] [NEW] Windows host tap (tap-win32) is not working on QEMU ver 0.12.X
Public bug reported: To reproduce the bug: 1) Install tap driver from openvpn (either v8/v9). Rename the tap connection to mytap and set the IP to 192.168.1.1 (or any ip) 2) use any QEMU 0.12.X and issue the following command c:\qemu qemu -net nic -net tap,ifname=mytap -cdrom ../linux.iso 3) Inside linux guest system, set the ip of the nic # ifconfig eth0 192.168.1.2 4) In the windows host try to ping the linux guest (or the other way around, after you disable the windows firewall) c:\qemu ping 192.168.1.2 Pinging 192.168.1.2 with 32 bytes of data: Reply from 192.168.1.1: Destination host unreachable. Those above steps is not working on QEMU 0.12.X. But confirmed working (ping successful) on: - QEMU 0.9.X - QEMU 0.10.X - QEMU 0.11.X I have tried with windows XP and windows 7 host system. I haven't tried the qemu latest from git repository, but looking at the net/tap- win32.c revision date, I guess the bug has been around for a while. Thanks. ** Affects: qemu Importance: Undecided Status: New -- Windows host tap (tap-win32) is not working on QEMU ver 0.12.X https://bugs.launchpad.net/bugs/589564 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: To reproduce the bug: 1) Install tap driver from openvpn (either v8/v9). Rename the tap connection to mytap and set the IP to 192.168.1.1 (or any ip) 2) use any QEMU 0.12.X and issue the following command c:\qemu qemu -net nic -net tap,ifname=mytap -cdrom ../linux.iso 3) Inside linux guest system, set the ip of the nic # ifconfig eth0 192.168.1.2 4) In the windows host try to ping the linux guest (or the other way around, after you disable the windows firewall) c:\qemu ping 192.168.1.2 Pinging 192.168.1.2 with 32 bytes of data: Reply from 192.168.1.1: Destination host unreachable. Those above steps is not working on QEMU 0.12.X. But confirmed working (ping successful) on: - QEMU 0.9.X - QEMU 0.10.X - QEMU 0.11.X I have tried with windows XP and windows 7 host system. I haven't tried the qemu latest from git repository, but looking at the net/tap-win32.c revision date, I guess the bug has been around for a while. Thanks.
Re: [Qemu-devel] [PATCH 08/16] Move main signal handler setup to os specificfiles.
Jes Sorensen jes.soren...@redhat.com writes: 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? There's a stray ';' after the function body's closing brace. Please drop it.
[Qemu-devel] Re: [PATCH 3/8] sparc64: fix 32bit load sign extension
On 06/03/2010 09:59 PM, Igor Kovalenko wrote: On Thu, Jun 3, 2010 at 7:42 PM, Paolo Bonzinipbonz...@redhat.com wrote: On 06/03/2010 05:25 PM, Alexander Graf wrote: Am 03.06.2010 um 15:18 schrieb Paolo Bonzinipbonz...@redhat.com: On 06/01/2010 10:12 PM, Igor V. Kovalenko wrote: From: Igor V. Kovalenkoigor.v.kovale...@gmail.com - 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 Normal boot works. Only -kernel/-initrd fails. Paolo
Re: [Qemu-devel] [PATCH 10/16] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c
jes.soren...@redhat.com writes: From: Jes Sorensen jes.soren...@redhat.com Introduce OS specific cmdline argument handling by calling os_parse_cmd_args() at the end of switch() statement. In addition move SMB argument to os-posix.c Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c | 34 ++ os-win32.c | 22 ++ sysemu.h |9 + vl.c | 15 ++- 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/os-posix.c b/os-posix.c index 621ad06..66f2bf5 100644 --- a/os-posix.c +++ b/os-posix.c @@ -33,6 +33,7 @@ /* Needed early for CONFIG_BSD etc. */ #include config-host.h #include sysemu.h +#include net/slirp.h void os_setup_early_signal_handling(void) { @@ -130,3 +131,36 @@ char *os_find_datadir(const char *argv0) } #undef SHARE_SUFFIX #undef BUILD_SUFFIX + +/* + * Duplicate definition from vl.c to avoid messing up the entire build + */ +enum { +#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ +opt_enum, +#define DEFHEADING(text) +#include qemu-options.h +#undef DEF +#undef DEFHEADING +#undef GEN_DOCS +}; + +/* + * Parse OS specific command line options. + * return 0 if option handled, -1 otherwise + */ +int os_parse_cmd_args(const QEMUOption *popt, const char *optarg) +{ +int ret = 0; +switch (popt-index) { +#ifdef CONFIG_SLIRP +case QEMU_OPTION_smb: +if (net_slirp_smb(optarg) 0) +exit(1); +break; +#endif Was #ifndef _WIN32 before. Impact? +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 +}; I agree with Richard: this is 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) +{ +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; + Ugh. /* 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); } } } Is this minor improvement of vl.c really worth the headaches elsewhere?
Re: [Qemu-devel] [PATCH 00/16] clean up vl.c code
jes.soren...@redhat.com writes: From: Jes Sorensen jes.soren...@redhat.com Hi, I have been working on a set of patches to clean up the vl.c code, by separating out OS specific code into OS specific files. Basically it introduces two header files: qemu-os-win32.h and qemu-os-posix.h as well as os-win32.c and os-posix.c. I have tried to be as careful as I can to not break non Linux support, but as I only have a Linux build environment handy, I would appreciate it if people with other OSes could check that I didn't break anything for them. In particular I would like to know if win32 still builds. I like moving stuff out of vl.c in general. Your moves of entire functions look like a win to me. I have doubts about spreading the option switch over three files, though.
Re: [Qemu-devel] [PATCH 10/16] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c
On 06/04/10 10:15, Markus Armbruster wrote: jes.soren...@redhat.com writes: + * 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 Was #ifndef _WIN32 before. Impact? It was moved to os-posix.c which is only built for non _WIN32, so it has the same effect, except it's not full of ugly #ifdef's +/* + * 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 +}; I agree with Richard: this is gross. The enum creation is gross by itself. Only way to get around not duplicating it is to create a new header file to hold just that? +/* 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; + Ugh. What do you mean? The real ugh! here is that it was created as a typedef. I can change the function to pass in just the index, but I don't know if we will have cases where the rest is needed. Is this minor improvement of vl.c really worth the headaches elsewhere? vl.c as it is today is gross and un-maintainable. This patch gets rid of a lot of the ugly #ifdefs and makes the code easier to read and maintain. Jes
[Qemu-devel] Re: [PATCH 08/13] qdev: Decouple qdev_prop_drive from DriveInfo
Gerd Hoffmann kra...@redhat.com writes: Hi, +static void free_drive(DeviceState *dev, Property *prop) +{ +BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop); + +if (*ptr) { +blockdev_detach(*ptr, dev); +} +} @@ -1043,26 +1043,26 @@ static void scsi_destroy(SCSIDevice *dev) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); scsi_disk_purge_requests(s); -drive_uninit(s-qdev.conf.dinfo); } Neat. Commit message should better explain that though. Point. I'll try to improve it.
Re: [Qemu-devel] [PATCH 00/16] clean up vl.c code
On 06/04/10 10:21, Markus Armbruster wrote: jes.soren...@redhat.com writes: 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. I like moving stuff out of vl.c in general. Your moves of entire functions look like a win to me. I have doubts about spreading the option switch over three files, though. The problem is right now there are too many OS specific options, but having the #ifdefs plastered all over to enable/disable them accordingly is just a nightmare and is prone to leave in inconsistent behavior for various OSes. See the set_proc_name() stuff for an example. Cheers, Jes
Re: [Qemu-devel] [PATCH 13/13] blockdev: New -blockdev to define a host block device
Christoph Hellwig h...@lst.de writes: 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. You're absolutely right. I'll look into it.
[Qemu-devel] Re: [V9fs-developer] [PATCH] virtio-9p: getattr server implementation for 9P2000.L protocol.
On Thu, 3 Jun 2010 18:29:02 +0530, Sripathi Kodi sripat...@in.ibm.com wrote: On Wed, 02 Jun 2010 19:49:24 +0530 Aneesh Kumar K. V aneesh.ku...@linux.vnet.ibm.com wrote: On Fri, 28 May 2010 16:08:43 +0530, Sripathi Kodi sripat...@in.ibm.com wrote: From: M. Mohan Kumar mo...@in.ibm.com 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: That is what linux kernel currently does. But from the protocol point of view and not looking at specific linux implementation i would suggest to put st_blksize on wire. -aneesh
[Qemu-devel] [PATCH v3 2/7] MIPS: Initial support of vt82686b south bridge used by fulong mini pc
Signed-off-by: Huacai Chen zltjiang...@gmail.com --- Makefile.target |2 +- hw/pci_ids.h|8 + hw/vt82c686.c | 579 +++ hw/vt82c686.h | 11 + 4 files changed, 599 insertions(+), 1 deletions(-) create mode 100644 hw/vt82c686.c create mode 100644 hw/vt82c686.h diff --git a/Makefile.target b/Makefile.target index ac36e2c..92ba282 100644 --- a/Makefile.target +++ b/Makefile.target @@ -221,7 +221,7 @@ obj-mips-y += vga.o i8259.o obj-mips-y += g364fb.o jazz_led.o obj-mips-y += gt64xxx.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/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..d7d9eaf --- /dev/null +++ b/hw/vt82c686.c @@ -0,0 +1,579 @@ +/* + * 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 vt82c686.h +#include i2c.h +#include smbus.h +#include pci.h +#include isa.h +#include sysbus.h +#include mips.h +#include apm.h +#include acpi.h +#include pm_smbus.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; + +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; + +DPRINTF(superio_ioport_readb address 0x%x \n, addr); +return (superio_conf-config[superio_conf-index]); +} + +static void vt82c686b_reset(void * opaque) +{ +PCIDevice *d = opaque; +uint8_t *pci_conf = d-config; +VT82C686BState *vt82c = DO_UPCAST(VT82C686BState, dev, d); + +pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x00c0); +pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | + PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); +pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); + +pci_conf[0x48] = 0x01; /* Miscellaneous Control 3 */ +pci_conf[0x4a] = 0x04; /* IDE interrupt Routing */ +pci_conf[0x4f] = 0x03; /* DMA/Master Mem Access Control 3 */ +pci_conf[0x50] = 0x2d; /* PnP DMA Request Control */ +pci_conf[0x59] = 0x04; +pci_conf[0x5a] = 0x04; /* KBC/RTC Control*/ +pci_conf[0x5f] = 0x04; +pci_conf[0x77] = 0x10; /* GPIO Control 1/2/3/4 */ + +vt82c-superio_conf-config[0xe0] = 0x3c; +
[Qemu-devel] [PATCH v3 4/7] MIPS: Initial support of VIA USB controller used by fulong mini pc
Signed-off-by: Huacai Chen zltjiang...@gmail.com --- hw/usb-uhci.c | 20 hw/usb-uhci.h |1 + 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index 624d55b..feb44e6 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -1152,6 +1152,16 @@ static int usb_uhci_piix4_initfn(PCIDevice *dev) return usb_uhci_common_initfn(s); } +static int usb_uhci_vt82c686b_initfn(PCIDevice *dev) +{ +UHCIState *s = DO_UPCAST(UHCIState, dev, dev); +uint8_t *pci_conf = s-dev.config; + +pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_VIA); +pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_VIA_UHCI); +return usb_uhci_common_initfn(s); +} + static PCIDeviceInfo uhci_info[] = { { .qdev.name= piix3-usb-uhci, @@ -1164,6 +1174,11 @@ static PCIDeviceInfo uhci_info[] = { .qdev.vmsd= vmstate_uhci, .init = usb_uhci_piix4_initfn, },{ +.qdev.name= vt82c686b-usb-uhci, +.qdev.size= sizeof(UHCIState), +.qdev.vmsd= vmstate_uhci, +.init = usb_uhci_vt82c686b_initfn, +},{ /* end of list */ } }; @@ -1183,3 +1198,8 @@ void usb_uhci_piix4_init(PCIBus *bus, int devfn) { pci_create_simple(bus, devfn, piix4-usb-uhci); } + +void usb_uhci_vt82c686b_init(PCIBus *bus, int devfn) +{ +pci_create_simple(bus, devfn, vt82c686b-usb-uhci); +} diff --git a/hw/usb-uhci.h b/hw/usb-uhci.h index 911948e..3e4d377 100644 --- a/hw/usb-uhci.h +++ b/hw/usb-uhci.h @@ -5,5 +5,6 @@ void usb_uhci_piix3_init(PCIBus *bus, int devfn); void usb_uhci_piix4_init(PCIBus *bus, int devfn); +void usb_uhci_vt82c686b_init(PCIBus *bus, int devfn); #endif -- 1.7.0.4
[Qemu-devel] [PATCH v3 5/7] MIPS: Initial support of fulong mini pc (CPU definition)
Signed-off-by: Huacai Chen zltjiang...@gmail.com --- target-mips/mips-defs.h |4 target-mips/translate_init.c | 35 +++ 2 files changed, 39 insertions(+), 0 deletions(-) diff --git a/target-mips/mips-defs.h b/target-mips/mips-defs.h index c57de02..38594da 100644 --- a/target-mips/mips-defs.h +++ b/target-mips/mips-defs.h @@ -40,6 +40,8 @@ #defineASE_SMARTMIPS 0x0004 /* Chip specific instructions. */ +#defineINSN_LOONGSON2E 0x2000 +#defineINSN_LOONGSON2F 0x4000 #defineINSN_VR54XX 0x8000 /* MIPS CPU defines. */ @@ -48,6 +50,8 @@ #defineCPU_MIPS3 (CPU_MIPS2 | ISA_MIPS3) #defineCPU_MIPS4 (CPU_MIPS3 | ISA_MIPS4) #defineCPU_VR54XX (CPU_MIPS4 | INSN_VR54XX) +#defineCPU_LOONGSON2E (CPU_MIPS3 | INSN_LOONGSON2E) +#defineCPU_LOONGSON2F (CPU_MIPS3 | INSN_LOONGSON2F) #defineCPU_MIPS5 (CPU_MIPS4 | ISA_MIPS5) diff --git a/target-mips/translate_init.c b/target-mips/translate_init.c index b79ed56..0d9899e 100644 --- a/target-mips/translate_init.c +++ b/target-mips/translate_init.c @@ -454,6 +454,41 @@ static const mips_def_t mips_defs[] = .insn_flags = CPU_MIPS64R2 | ASE_MIPS3D, .mmu_type = MMU_TYPE_R4000, }, +{ +.name = Loongson-2E, +.CP0_PRid = 0x6302, +/*64KB I-cache and d-cache. 4 way with 32 bit cache line size*/ +.CP0_Config0 = (0x117) | (0x116) | (0x111) | (0x18) | (0x15) | + (0x14) | (0x11), +/* Note: Config1 is only used internally, Loongson-2E has only Config0. */ +.CP0_Config1 = (1 CP0C1_FP) | (47 CP0C1_MMU), +.SYNCI_Step = 16, +.CCRes = 2, +.CP0_Status_rw_bitmask = 0x35D0, +.CP1_fcr0 = (0x5 FCR0_PRID) | (0x1 FCR0_REV), +.SEGBITS = 40, +.PABITS = 40, +.insn_flags = CPU_LOONGSON2E, +.mmu_type = MMU_TYPE_R4000, +}, +{ + .name = Loongson-2F, + .CP0_PRid = 0x6303, + /*64KB I-cache and d-cache. 4 way with 32 bit cache line size*/ + .CP0_Config0 = (0x117) | (0x116) | (0x111) | (0x18) | (0x15) | + (0x14) | (0x11), + /* Note: Config1 is only used internally, Loongson-2F has only Config0. */ + .CP0_Config1 = (1 CP0C1_FP) | (47 CP0C1_MMU), + .SYNCI_Step = 16, + .CCRes = 2, + .CP0_Status_rw_bitmask = 0xF5D0FF1F, /*bit5:7 not writeable*/ + .CP1_fcr0 = (0x5 FCR0_PRID) | (0x1 FCR0_REV), + .SEGBITS = 40, + .PABITS = 40, + .insn_flags = CPU_LOONGSON2F, + .mmu_type = MMU_TYPE_R4000, +}, + #endif }; -- 1.7.0.4
[Qemu-devel] [PATCH v3 6/7] MIPS: Initial support of fulong mini pc (machine construction)
Signed-off-by: Huacai Chen zltjiang...@gmail.com --- Makefile.target|2 +- hw/mips_fulong2e.c | 402 2 files changed, 403 insertions(+), 1 deletions(-) create mode 100644 hw/mips_fulong2e.c diff --git a/Makefile.target b/Makefile.target index 92ba282..f203c6b 100644 --- a/Makefile.target +++ b/Makefile.target @@ -221,7 +221,7 @@ obj-mips-y += vga.o i8259.o obj-mips-y += g364fb.o jazz_led.o obj-mips-y += gt64xxx.o mc146818rtc.o obj-mips-y += piix4.o cirrus_vga.o -obj-mips-$(CONFIG_FULONG) += bonito.o vt82c686.o +obj-mips-$(CONFIG_FULONG) += bonito.o vt82c686.o mips_fulong2e.o obj-microblaze-y = petalogix_s3adsp1800_mmu.o diff --git a/hw/mips_fulong2e.c b/hw/mips_fulong2e.c new file mode 100644 index 000..1b54236 --- /dev/null +++ b/hw/mips_fulong2e.c @@ -0,0 +1,402 @@ +/* + * QEMU fulong 2e mini pc 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. + */ + +/* + * Fulong 2e mini pc is based on ICT/ST Loongson 2e CPU (MIPS III like, 800MHz) + * http://www.linux-mips.org/wiki/Fulong + * + * Loongson 2e user manual: + * http://www.loongsondeveloper.com/doc/Loongson2EUserGuide.pdf + */ + +#include hw.h +#include pc.h +#include fdc.h +#include net.h +#include boards.h +#include smbus.h +#include block.h +#include flash.h +#include mips.h +#include mips_cpudevs.h +#include pci.h +#include usb-uhci.h +#include qemu-char.h +#include sysemu.h +#include audio/audio.h +#include qemu-log.h +#include loader.h +#include mips-bios.h +#include ide.h +#include elf.h +#include vt82c686.h +#include mc146818rtc.h + +#define DEBUG_FULONG2E_INIT + +#define ENVP_ADDR 0x80002000l +#define ENVP_NB_ENTRIES16 +#define ENVP_ENTRY_SIZE256 + +#define MAX_IDE_BUS 2 +#define FULONG_BIOSNAME pmon_fulong2e.bin + +/* PCI SLOT in fulong 2e */ +#define FULONG2E_VIA_SLOT5 +#define FULONG2E_ATI_SLOT6 +#define FULONG2E_RTL8139_SLOT7 + +static PITState *pit; + +static struct _loaderparams { +int ram_size; +const char *kernel_filename; +const char *kernel_cmdline; +const char *initrd_filename; +} loaderparams; + +static void prom_set(uint32_t* prom_buf, int index, const char *string, ...) +{ +va_list ap; +int32_t table_addr; + +if (index = ENVP_NB_ENTRIES) +return; + +if (string == NULL) { +prom_buf[index] = 0; +return; +} + +table_addr = sizeof(int32_t) * ENVP_NB_ENTRIES + index * ENVP_ENTRY_SIZE; +prom_buf[index] = tswap32(ENVP_ADDR + table_addr); + +va_start(ap, string); +vsnprintf((char *)prom_buf + table_addr, ENVP_ENTRY_SIZE, string, ap); +va_end(ap); +} + +static int64_t load_kernel (CPUState *env) +{ +int64_t kernel_entry, kernel_low, kernel_high; +int index = 0; +long initrd_size; +ram_addr_t initrd_offset; +uint32_t *prom_buf; +long prom_size; + +if (load_elf(loaderparams.kernel_filename, cpu_mips_kseg0_to_phys, NULL, + (uint64_t *)kernel_entry, (uint64_t *)kernel_low, + (uint64_t *)kernel_high, 0, ELF_MACHINE, 1) 0) { +fprintf(stderr, qemu: could not load kernel '%s'\n, +loaderparams.kernel_filename); +exit(1); +} + +/* load initrd */ +initrd_size = 0; +initrd_offset = 0; +if (loaderparams.initrd_filename) { +initrd_size = get_image_size (loaderparams.initrd_filename); +if (initrd_size 0) { +initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) TARGET_PAGE_MASK; +if (initrd_offset + initrd_size ram_size) { +fprintf(stderr, +qemu: memory too small for initial ram disk '%s'\n, +loaderparams.initrd_filename); +exit(1); +} +initrd_size = load_image_targphys(loaderparams.initrd_filename, + initrd_offset, ram_size - initrd_offset); +} +if (initrd_size == (target_ulong) -1) { +fprintf(stderr, qemu: could not load initial ram disk '%s'\n, +loaderparams.initrd_filename); +exit(1); +} +} + +/* Setup prom parameters. */ +prom_size = ENVP_NB_ENTRIES * (sizeof(int32_t) + ENVP_ENTRY_SIZE); +prom_buf = qemu_malloc(prom_size); + +prom_set(prom_buf, index++, loaderparams.kernel_filename); +if (initrd_size 0) { +prom_set(prom_buf, index++, rd_start=0x PRIx64 rd_size=%li %s, + cpu_mips_phys_to_kseg0(NULL, initrd_offset), initrd_size, + loaderparams.kernel_cmdline); +} else { +prom_set(prom_buf, index++, loaderparams.kernel_cmdline); +} + +/* Setup minimum environment variables */ +prom_set(prom_buf, index++, busclock=3300); +
[Qemu-devel] [PATCH v3 3/7] MIPS: Initial support of VIA IDE controller used by fulong mini pc
Signed-off-by: Huacai Chen zltjiang...@gmail.com --- Makefile.objs|1 + default-configs/mips64el-softmmu.mak |1 + hw/ide.h |1 + hw/ide/via.c | 176 ++ 4 files changed, 179 insertions(+), 0 deletions(-) create mode 100644 hw/ide/via.c diff --git a/Makefile.objs b/Makefile.objs index 9796dcb..ad9a825 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -200,6 +200,7 @@ hw-obj-$(CONFIG_IDE_ISA) += ide/isa.o hw-obj-$(CONFIG_IDE_PIIX) += ide/piix.o hw-obj-$(CONFIG_IDE_CMD646) += ide/cmd646.o hw-obj-$(CONFIG_IDE_MACIO) += ide/macio.o +hw-obj-$(CONFIG_IDE_VIA) += ide/via.o # SCSI layer hw-obj-y += lsi53c895a.o diff --git a/default-configs/mips64el-softmmu.mak b/default-configs/mips64el-softmmu.mak index d35d923..85b7838 100644 --- a/default-configs/mips64el-softmmu.mak +++ b/default-configs/mips64el-softmmu.mak @@ -21,6 +21,7 @@ CONFIG_IDE_QDEV=y CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y +CONFIG_IDE_VIA=y CONFIG_NE2000_ISA=y CONFIG_SOUND=y CONFIG_VIRTIO_PCI=y diff --git a/hw/ide.h b/hw/ide.h index 0e7d540..bb635b6 100644 --- a/hw/ide.h +++ b/hw/ide.h @@ -12,6 +12,7 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table, int secondary_ide_enabled); void pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); void pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); +void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); /* ide-macio.c */ int pmac_ide_init (DriveInfo **hd_table, qemu_irq irq, diff --git a/hw/ide/via.c b/hw/ide/via.c new file mode 100644 index 000..bc3b44e --- /dev/null +++ b/hw/ide/via.c @@ -0,0 +1,176 @@ +/* + * QEMU IDE Emulation: PCI VIA82C686B support. + * + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2006 Openedhand Ltd. + * Copyright (c) 2010 Huacai Chen zltjiang...@gmail.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include hw/hw.h +#include hw/pc.h +#include hw/pci.h +#include hw/isa.h +#include block.h +#include block_int.h +#include sysemu.h +#include dma.h + +#include hw/ide/pci.h + +static uint32_t bmdma_readb(void *opaque, uint32_t addr) +{ +BMDMAState *bm = opaque; +uint32_t val; + +switch (addr 3) { +case 0: +val = bm-cmd; +break; +case 2: +val = bm-status; +break; +default: +val = 0xff; +break; +} +#ifdef DEBUG_IDE +printf(bmdma: readb 0x%02x : 0x%02x\n, addr, val); +#endif +return val; +} + +static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val) +{ +BMDMAState *bm = opaque; +#ifdef DEBUG_IDE +printf(bmdma: writeb 0x%02x : 0x%02x\n, addr, val); +#endif +switch (addr 3) { +case 2: +bm-status = (val 0x60) | (bm-status 1) | (bm-status ~val 0x06); +break; +default:; +} +} + +static void bmdma_map(PCIDevice *pci_dev, int region_num, +pcibus_t addr, pcibus_t size, int type) +{ +PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, pci_dev); +int i; + +for(i = 0;i 2; i++) { +BMDMAState *bm = d-bmdma[i]; +d-bus[i].bmdma = bm; +bm-bus = d-bus+i; +qemu_add_vm_change_state_handler(ide_dma_restart_cb, bm); + +register_ioport_write(addr, 1, 1, bmdma_cmd_writeb, bm); + +register_ioport_write(addr + 1, 3, 1, bmdma_writeb, bm); +register_ioport_read(addr, 4, 1, bmdma_readb, bm); + +register_ioport_write(addr + 4, 4, 1, bmdma_addr_writeb, bm); +register_ioport_read(addr + 4, 4, 1, bmdma_addr_readb, bm); +register_ioport_write(addr + 4, 4, 2, bmdma_addr_writew, bm); +register_ioport_read(addr + 4, 4, 2, bmdma_addr_readw, bm); +register_ioport_write(addr + 4, 4, 4, bmdma_addr_writel, bm); +register_ioport_read(addr + 4, 4, 4, bmdma_addr_readl, bm); +addr
[Qemu-devel] [PATCH v3 1/7] MIPS: Initial support of bonito north bridge used by fulong mini pc
Signed-off-by: Huacai Chen zltjiang...@gmail.com --- Makefile.target |1 + default-configs/mips64el-softmmu.mak |1 + hw/bonito.c | 816 ++ hw/mips.h|3 + 4 files changed, 821 insertions(+), 0 deletions(-) create mode 100644 hw/bonito.c diff --git a/Makefile.target b/Makefile.target index d06c679..ac36e2c 100644 --- a/Makefile.target +++ b/Makefile.target @@ -221,6 +221,7 @@ obj-mips-y += vga.o i8259.o obj-mips-y += g364fb.o jazz_led.o obj-mips-y += gt64xxx.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 b372c1d..d35d923 100644 --- a/default-configs/mips64el-softmmu.mak +++ b/default-configs/mips64el-softmmu.mak @@ -29,3 +29,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..4f21042 --- /dev/null +++ b/hw/bonito.c @@ -0,0 +1,816 @@ +/* + * 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_slot3 + 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 = (53)+0 + * VT686B_FUN1's devfn = (53)+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 assert.h + +#include hw.h +#include pci.h +#include pc.h +#include mips.h +#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) + +#define BONITO_INTERNAL_REG_BASE (BONITO_REGBASE+BONITO_REG_BASE) +#define BONITO_INTERNAL_REG_SIZE (0x70) + +#define BONITO_SPCICONFIG_BASE (BONITO_PCICFG_BASE) +#define BONITO_SPCICONFIG_SIZE (BONITO_PCICFG_SIZE) + + + +/* 1. Bonito h/w Configuration */ +/* Power on register */ + +#define BONITO_BONPONCFG(0x00 2) /* 0x100 */ +#define BONITO_BONGENCFG_OFFSET 0x4 +#define BONITO_BONGENCFG(BONITO_BONGENCFG_OFFSET2) /*0x104 */ + +/* 2. IO IDE configuration */ +#define BONITO_IODEVCFG (0x08 2) /* 0x108 */ + +/* 3. IO IDE configuration */ +#define BONITO_SDCFG(0x0c 2) /* 0x10c */ + +/* 4. PCI address map
Re: [Qemu-devel] [PATCH v3 1/7] MIPS: Initial support of bonito north bridge used by fulong mini pc
On Fri, Jun 04, 2010 at 04:37:43PM +0800, Huacai Chen wrote: Signed-off-by: Huacai Chen zltjiang...@gmail.com --- Makefile.target |1 + default-configs/mips64el-softmmu.mak |1 + hw/bonito.c | 816 ++ hw/mips.h|3 + 4 files changed, 821 insertions(+), 0 deletions(-) create mode 100644 hw/bonito.c diff --git a/Makefile.target b/Makefile.target index d06c679..ac36e2c 100644 --- a/Makefile.target +++ b/Makefile.target @@ -221,6 +221,7 @@ obj-mips-y += vga.o i8259.o obj-mips-y += g364fb.o jazz_led.o obj-mips-y += gt64xxx.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 b372c1d..d35d923 100644 --- a/default-configs/mips64el-softmmu.mak +++ b/default-configs/mips64el-softmmu.mak @@ -29,3 +29,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..4f21042 --- /dev/null +++ b/hw/bonito.c @@ -0,0 +1,816 @@ +/* + * 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_slot3 + 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 = (53)+0 + * VT686B_FUN1's devfn = (53)+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 assert.h + +#include hw.h +#include pci.h +#include pc.h +#include mips.h +#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) + +#define BONITO_INTERNAL_REG_BASE (BONITO_REGBASE+BONITO_REG_BASE) +#define BONITO_INTERNAL_REG_SIZE (0x70) + +#define BONITO_SPCICONFIG_BASE (BONITO_PCICFG_BASE) +#define BONITO_SPCICONFIG_SIZE (BONITO_PCICFG_SIZE) + + + +/* 1. Bonito h/w Configuration */ +/* Power on register */ + +#define BONITO_BONPONCFG(0x00 2) /* 0x100 */ +#define BONITO_BONGENCFG_OFFSET 0x4 +#define BONITO_BONGENCFG(BONITO_BONGENCFG_OFFSET2) /*0x104 */ + +/* 2.
[Qemu-devel] [PATCH] target-arm: Handle 'smc' as an undefined instruction
Handle smc as undefined instruction instead of having it wrongly interpreted as some other instruction. Signed-off-by: Adam Lackorzynski a...@os.inf.tu-dresden.de --- target-arm/translate.c |6 +- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/target-arm/translate.c b/target-arm/translate.c index 0eccca5..afd6716 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -6344,7 +6344,11 @@ static void disas_arm_insn(CPUState * env, DisasContext *s) dead_tmp(tmp2); store_reg(s, rd, tmp); break; -case 7: /* bkpt */ +case 7: +/* SMC? */ +if ((insn 0xfff0) == 0xe1600070) + goto illegal_op; +/* bkpt */ gen_set_condexec(s); gen_set_pc_im(s-pc - 4); gen_exception(EXCP_BKPT); -- 1.7.1
Re: [Qemu-devel] [PATCH v3 2/7] MIPS: Initial support of vt82686b south bridge used by fulong mini pc
On Fri, Jun 04, 2010 at 04:38:30PM +0800, Huacai Chen wrote: Signed-off-by: Huacai Chen zltjiang...@gmail.com --- Makefile.target |2 +- hw/pci_ids.h|8 + hw/vt82c686.c | 579 +++ hw/vt82c686.h | 11 + 4 files changed, 599 insertions(+), 1 deletions(-) create mode 100644 hw/vt82c686.c create mode 100644 hw/vt82c686.h diff --git a/Makefile.target b/Makefile.target index ac36e2c..92ba282 100644 --- a/Makefile.target +++ b/Makefile.target @@ -221,7 +221,7 @@ obj-mips-y += vga.o i8259.o obj-mips-y += g364fb.o jazz_led.o obj-mips-y += gt64xxx.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/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..d7d9eaf --- /dev/null +++ b/hw/vt82c686.c @@ -0,0 +1,579 @@ +/* + * 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 vt82c686.h +#include i2c.h +#include smbus.h +#include pci.h +#include isa.h +#include sysbus.h +#include mips.h +#include apm.h +#include acpi.h +#include pm_smbus.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; + +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; + +DPRINTF(superio_ioport_readb address 0x%x \n, addr); +return (superio_conf-config[superio_conf-index]); +} + +static void vt82c686b_reset(void * opaque) +{ +PCIDevice *d = opaque; +uint8_t *pci_conf = d-config; +VT82C686BState *vt82c = DO_UPCAST(VT82C686BState, dev, d); + +pci_set_long(pci_conf + PCI_CAPABILITY_LIST, 0x00c0); +pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY | + PCI_COMMAND_MASTER | PCI_COMMAND_SPECIAL); +pci_set_word(pci_conf + PCI_STATUS, PCI_STATUS_DEVSEL_MEDIUM); + +pci_conf[0x48] = 0x01; /* Miscellaneous Control 3 */ +pci_conf[0x4a] = 0x04; /* IDE interrupt Routing */ +pci_conf[0x4f] = 0x03; /* DMA/Master Mem Access Control 3 */ +pci_conf[0x50] = 0x2d; /* PnP DMA
Re: [Qemu-devel] [PATCH v3 3/7] MIPS: Initial support of VIA IDE controller used by fulong mini pc
On Fri, Jun 04, 2010 at 04:39:01PM +0800, Huacai Chen wrote: Signed-off-by: Huacai Chen zltjiang...@gmail.com --- Makefile.objs|1 + default-configs/mips64el-softmmu.mak |1 + hw/ide.h |1 + hw/ide/via.c | 176 ++ 4 files changed, 179 insertions(+), 0 deletions(-) create mode 100644 hw/ide/via.c diff --git a/Makefile.objs b/Makefile.objs index 9796dcb..ad9a825 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -200,6 +200,7 @@ hw-obj-$(CONFIG_IDE_ISA) += ide/isa.o hw-obj-$(CONFIG_IDE_PIIX) += ide/piix.o hw-obj-$(CONFIG_IDE_CMD646) += ide/cmd646.o hw-obj-$(CONFIG_IDE_MACIO) += ide/macio.o +hw-obj-$(CONFIG_IDE_VIA) += ide/via.o # SCSI layer hw-obj-y += lsi53c895a.o diff --git a/default-configs/mips64el-softmmu.mak b/default-configs/mips64el-softmmu.mak index d35d923..85b7838 100644 --- a/default-configs/mips64el-softmmu.mak +++ b/default-configs/mips64el-softmmu.mak @@ -21,6 +21,7 @@ CONFIG_IDE_QDEV=y CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y +CONFIG_IDE_VIA=y CONFIG_NE2000_ISA=y CONFIG_SOUND=y CONFIG_VIRTIO_PCI=y diff --git a/hw/ide.h b/hw/ide.h index 0e7d540..bb635b6 100644 --- a/hw/ide.h +++ b/hw/ide.h @@ -12,6 +12,7 @@ void pci_cmd646_ide_init(PCIBus *bus, DriveInfo **hd_table, int secondary_ide_enabled); void pci_piix3_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); void pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); +void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn); /* ide-macio.c */ int pmac_ide_init (DriveInfo **hd_table, qemu_irq irq, diff --git a/hw/ide/via.c b/hw/ide/via.c new file mode 100644 index 000..bc3b44e --- /dev/null +++ b/hw/ide/via.c @@ -0,0 +1,176 @@ +/* + * QEMU IDE Emulation: PCI VIA82C686B support. + * + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2006 Openedhand Ltd. + * Copyright (c) 2010 Huacai Chen zltjiang...@gmail.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include hw/hw.h +#include hw/pc.h +#include hw/pci.h +#include hw/isa.h +#include block.h +#include block_int.h +#include sysemu.h +#include dma.h + +#include hw/ide/pci.h + +static uint32_t bmdma_readb(void *opaque, uint32_t addr) +{ +BMDMAState *bm = opaque; +uint32_t val; + +switch (addr 3) { +case 0: +val = bm-cmd; +break; +case 2: +val = bm-status; +break; +default: +val = 0xff; +break; +} +#ifdef DEBUG_IDE +printf(bmdma: readb 0x%02x : 0x%02x\n, addr, val); +#endif +return val; +} + +static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val) +{ +BMDMAState *bm = opaque; +#ifdef DEBUG_IDE +printf(bmdma: writeb 0x%02x : 0x%02x\n, addr, val); +#endif +switch (addr 3) { +case 2: +bm-status = (val 0x60) | (bm-status 1) | (bm-status ~val 0x06); +break; +default:; +} +} + +static void bmdma_map(PCIDevice *pci_dev, int region_num, +pcibus_t addr, pcibus_t size, int type) +{ +PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, pci_dev); +int i; + +for(i = 0;i 2; i++) { +BMDMAState *bm = d-bmdma[i]; +d-bus[i].bmdma = bm; +bm-bus = d-bus+i; +qemu_add_vm_change_state_handler(ide_dma_restart_cb, bm); + +register_ioport_write(addr, 1, 1, bmdma_cmd_writeb, bm); + +register_ioport_write(addr + 1, 3, 1, bmdma_writeb, bm); +register_ioport_read(addr, 4, 1, bmdma_readb, bm); + +register_ioport_write(addr + 4, 4, 1, bmdma_addr_writeb, bm); +register_ioport_read(addr + 4, 4, 1, bmdma_addr_readb, bm); +register_ioport_write(addr + 4, 4, 2, bmdma_addr_writew, bm); +
[Qemu-devel] [PATCH] Add exit notifiers.
Hook up any cleanup work which needs to be done here. Advantages over using atexit(3): (1) You get passed in a pointer to the notifier. If you embed that into your state struct you can use container_of() to get get your state info. (2) You can unregister, say when un-plugging a device. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- roms/seabios |2 +- sysemu.h |4 vl.c | 19 +++ 3 files changed, 24 insertions(+), 1 deletions(-) diff --git a/roms/seabios b/roms/seabios index 8f469b9..7d09d0e 16 --- a/roms/seabios +++ b/roms/seabios @@ -1 +1 @@ -Subproject commit 8f469b9676127ba6bb52609d89ec774e61db0ee1 +Subproject commit 7d09d0e3ba11310e973d4302c7fcc3fc2184e04c diff --git a/sysemu.h b/sysemu.h index fd9dd9d..140b7ff 100644 --- a/sysemu.h +++ b/sysemu.h @@ -6,6 +6,7 @@ #include qemu-option.h #include qemu-queue.h #include qemu-timer.h +#include notify.h #ifdef _WIN32 #include windows.h @@ -51,6 +52,9 @@ int qemu_powerdown_requested(void); extern qemu_irq qemu_system_powerdown; void qemu_system_reset(void); +void qemu_add_exit_notifier(Notifier *notify); +void qemu_remove_exit_notifier(Notifier *notify); + void do_savevm(Monitor *mon, const QDict *qdict); int load_vmstate(const char *name); void do_delvm(Monitor *mon, const QDict *qdict); diff --git a/vl.c b/vl.c index ac1a998..1577566 100644 --- a/vl.c +++ b/vl.c @@ -243,6 +243,9 @@ uint8_t qemu_uuid[16]; static QEMUBootSetHandler *boot_set_handler; static void *boot_set_opaque; +static NotifierList exit_notifiers = +NOTIFIER_LIST_INITIALIZER(exit_notifiers); + int kvm_allowed = 0; uint32_t xen_domid; enum xen_mode xen_mode = XEN_EMULATE; @@ -2127,6 +2130,21 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type) #ifndef _WIN32 +void qemu_add_exit_notifier(Notifier *notify) +{ +notifier_list_add(exit_notifiers, notify); +} + +void qemu_remove_exit_notifier(Notifier *notify) +{ +notifier_list_remove(exit_notifiers, notify); +} + +static void qemu_run_exit_notifiers(void) +{ +notifier_list_notify(exit_notifiers); +} + static void termsig_handler(int signal) { qemu_system_shutdown_request(); @@ -2583,6 +2601,7 @@ int main(int argc, char **argv, char **envp) int show_vnc_port = 0; int defconfig = 1; +atexit(qemu_run_exit_notifiers); error_set_progname(argv[0]); init_clocks(); -- 1.6.6.1
[Qemu-devel] Re: [PATCH] block: Fix serial number assignment
Am 02.06.2010 22:46, schrieb Luiz Capitulino: We should use 'dinfo-serial' length, 'serial' is a pointer, so the serial number length is currently limited to the pointer size. This fixes https://bugs.launchpad.net/qemu/+bug/584143 and is also valid for stable. Signed-off-by: Luiz Capitulino lcapitul...@redhat.com Thanks, applied to the block branch. Kevin
Re: [Qemu-devel] [PATCH] Add exit notifiers.
On Fri, Jun 4, 2010 at 10:35 AM, Gerd Hoffmann kra...@redhat.com wrote: Hook up any cleanup work which needs to be done here.  Advantages over using atexit(3):  (1) You get passed in a pointer to the notifier.  If you embed that    into your state struct you can use container_of() to get get your    state info.  (2) You can unregister, say when un-plugging a device. This looks useful to me. Just yesterday I added an atexit(3) case for some local hacking. diff --git a/roms/seabios b/roms/seabios index 8f469b9..7d09d0e 16 --- a/roms/seabios +++ b/roms/seabios @@ -1 +1 @@ -Subproject commit 8f469b9676127ba6bb52609d89ec774e61db0ee1 +Subproject commit 7d09d0e3ba11310e973d4302c7fcc3fc2184e04c This hunk seems unrelated to your commit. diff --git a/vl.c b/vl.c index ac1a998..1577566 100644 --- a/vl.c +++ b/vl.c @@ -2127,6 +2130,21 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)  #ifndef _WIN32 +void qemu_add_exit_notifier(Notifier *notify) Why #ifndef _WIN32? I think this patch will break _WIN32 builds. Stefan
[Qemu-devel] Re: [PATCH 3/8] sparc64: fix 32bit load sign extension
On 06/04/2010 09:53 AM, Paolo Bonzini wrote: On 06/03/2010 09:59 PM, Igor Kovalenko wrote: On Thu, Jun 3, 2010 at 7:42 PM, Paolo Bonzinipbonz...@redhat.com wrote: On 06/03/2010 05:25 PM, Alexander Graf wrote: Am 03.06.2010 um 15:18 schrieb Paolo Bonzinipbonz...@redhat.com: On 06/01/2010 10:12 PM, Igor V. Kovalenko wrote: From: Igor V. Kovalenkoigor.v.kovale...@gmail.com - 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 Normal boot works. Only -kernel/-initrd fails. Hmm, PEBKAC. Boot of Fedora and RHEL5 guests always fails, so it's not related to -kernel/-initrd. (Of course, without -kernel/-initrd it reboots into GRUB rather than looping quickly). I've placed a failing vmlinuz at http://people.redhat.com/people/vmlinuz-fail -- if it fails it should reboot continuously. The failure happens pretty soon after the kernel starts running. The sequence is: lock_kernel - __lock_kernel - preempt_disable - current_thread_info() IN: 0x80063064: push %rbp 0x80063065: mov%rsp,%rbp 0x80063068: mov%gs:0x10,%rax 0x80063071: mov-0x1fc8(%rax),%eax 0x80063077: test $0x8,%al 0x80063079: je 0x800630a2 %rax is 0x803f1fd8, but it page faults with %cr2=0x803f0010. The reason is that in the generated x86 assembly -0x1fc8 is erroneously zero extended: 0x4180347b: mov%rbp,%rbx 0x4180347e: mov$0xe038,%r12d 0x41803484: add%r12,%rbx so it gives the wrong address: (gdb) info reg rbp rbp0x803f1fd8 0x803f1fd8 (gdb) info reg r12 r120xe038 4294959160 (gdb) info reg rbx rbx0x803f0010 2151612432 From there it's obvious: general protection, double fault, general protection, triple fault. So it's a TCG bug that is expecting ldl_* to sign extend. I'll send a patch after I come back from lunch. Paolo
[Qemu-devel] [PATCH 0/3] qcow2: More error handling fixes
Three more cases of ignored or mutated error codes. Kevin Wolf (3): qcow2: Allow get_refcount to return errors qcow2: Allow alloc_clusters_noref to return errors qcow2: Return real error code in load_refcount_block block/qcow2-refcount.c | 70 +--- 1 files changed, 60 insertions(+), 10 deletions(-)
[Qemu-devel] [PATCH 1/3] qcow2: Allow get_refcount to return errors
get_refcount might need to load a refcount block from disk, so errors may happen. Return the error code instead of assuming a refcount of 1 and change the callers to respect error return values. Signed-off-by: Kevin Wolf kw...@redhat.com --- block/qcow2-refcount.c | 41 + 1 files changed, 37 insertions(+), 4 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 22b0b45..ca6b373 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -105,11 +105,17 @@ static int load_refcount_block(BlockDriverState *bs, return 0; } +/* + * Returns the refcount of the cluster given by its index. Any non-negative + * return value is the refcount of the cluster, negative values are -errno + * and indicate an error. + */ static int get_refcount(BlockDriverState *bs, int64_t cluster_index) { BDRVQcowState *s = bs-opaque; int refcount_table_index, block_index; int64_t refcount_block_offset; +int ret; refcount_table_index = cluster_index (s-cluster_bits - REFCOUNT_SHIFT); if (refcount_table_index = s-refcount_table_size) @@ -119,8 +125,10 @@ static int get_refcount(BlockDriverState *bs, int64_t cluster_index) return 0; if (refcount_block_offset != s-refcount_block_cache_offset) { /* better than nothing: return allocated if read error */ -if (load_refcount_block(bs, refcount_block_offset) 0) -return 1; +ret = load_refcount_block(bs, refcount_block_offset); +if (ret 0) { +return ret; +} } block_index = cluster_index ((1 (s-cluster_bits - REFCOUNT_SHIFT)) - 1); @@ -538,7 +546,13 @@ fail: return ret; } -/* addend must be 1 or -1 */ +/* + * Increases or decreases the refcount of a given cluster by one. + * addend must be 1 or -1. + * + * If the return value is non-negative, it is the new refcount of the cluster. + * If it is negative, it is -errno and indicates an error. + */ static int update_cluster_refcount(BlockDriverState *bs, int64_t cluster_index, int addend) @@ -779,6 +793,10 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, } else { refcount = get_refcount(bs, offset s-cluster_bits); } + +if (refcount 0) { +goto fail; +} } if (refcount == 1) { @@ -801,7 +819,9 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, } else { refcount = get_refcount(bs, l2_offset s-cluster_bits); } -if (refcount == 1) { +if (refcount 0) { +goto fail; +} else if (refcount == 1) { l2_offset |= QCOW_OFLAG_COPIED; } if (l2_offset != old_l2_offset) { @@ -934,6 +954,10 @@ static int check_refcounts_l2(BlockDriverState *bs, uint64_t entry = offset; offset = ~QCOW_OFLAG_COPIED; refcount = get_refcount(bs, offset s-cluster_bits); +if (refcount 0) { +fprintf(stderr, Can't get refcount for offset % +PRIx64 : %s\n, entry, strerror(-refcount)); +} if ((refcount == 1) != ((entry QCOW_OFLAG_COPIED) != 0)) { fprintf(stderr, ERROR OFLAG_COPIED: offset=% PRIx64 refcount=%d\n, entry, refcount); @@ -1011,6 +1035,10 @@ static int check_refcounts_l1(BlockDriverState *bs, if (check_copied) { refcount = get_refcount(bs, (l2_offset ~QCOW_OFLAG_COPIED) s-cluster_bits); +if (refcount 0) { +fprintf(stderr, Can't get refcount for l2_offset % +PRIx64 : %s\n, l2_offset, strerror(-refcount)); +} if ((refcount == 1) != ((l2_offset QCOW_OFLAG_COPIED) != 0)) { fprintf(stderr, ERROR OFLAG_COPIED: l2_offset=% PRIx64 refcount=%d\n, l2_offset, refcount); @@ -1118,6 +1146,11 @@ int qcow2_check_refcounts(BlockDriverState *bs) /* compare ref counts */ for(i = 0; i nb_clusters; i++) { refcount1 = get_refcount(bs, i); +if (refcount1 0) { +fprintf(stderr, Can't get refcount for cluster %d: %s\n, +i, strerror(-refcount1)); +} + refcount2 = refcount_table[i]; if (refcount1 != refcount2) { fprintf(stderr, ERROR cluster %d refcount=%d reference=%d\n, -- 1.6.6.1
[Qemu-devel] [PATCH 2/3] qcow2: Allow alloc_clusters_noref to return errors
Currently it would consider blocks for which get_refcount fails used. However, it's unlikely that get_refcount would succeed for the next cluster, so it's not really helpful. Return an error instead. Signed-off-by: Kevin Wolf kw...@redhat.com --- block/qcow2-refcount.c | 18 +++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index ca6b373..51948ae 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -228,7 +228,10 @@ static int64_t alloc_refcount_block(BlockDriverState *bs, int64_t cluster_index) } /* Allocate the refcount block itself and mark it as used */ -uint64_t new_block = alloc_clusters_noref(bs, s-cluster_size); +int64_t new_block = alloc_clusters_noref(bs, s-cluster_size); +if (new_block 0) { +return new_block; +} #ifdef DEBUG_ALLOC2 fprintf(stderr, qcow2: Allocate refcount block %d for % PRIx64 @@ -579,14 +582,19 @@ static int update_cluster_refcount(BlockDriverState *bs, static int64_t alloc_clusters_noref(BlockDriverState *bs, int64_t size) { BDRVQcowState *s = bs-opaque; -int i, nb_clusters; +int i, nb_clusters, refcount; nb_clusters = size_to_clusters(s, size); retry: for(i = 0; i nb_clusters; i++) { int64_t next_cluster_index = s-free_cluster_index++; -if (get_refcount(bs, next_cluster_index) != 0) +refcount = get_refcount(bs, next_cluster_index); + +if (refcount 0) { +return refcount; +} else if (refcount != 0) { goto retry; +} } #ifdef DEBUG_ALLOC2 printf(alloc_clusters: size=% PRId64 - % PRId64 \n, @@ -603,6 +611,10 @@ int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size) BLKDBG_EVENT(bs-file, BLKDBG_CLUSTER_ALLOC); offset = alloc_clusters_noref(bs, size); +if (offset 0) { +return offset; +} + ret = update_refcount(bs, offset, size, 1); if (ret 0) { return ret; -- 1.6.6.1
[Qemu-devel] [PATCH 3/3] qcow2: Return real error code in load_refcount_block
This fixes load_refcount_block which completely ignored the return value of write_refcount_block and always returned -EIO for bdrv_pwrite failure. Signed-off-by: Kevin Wolf kw...@redhat.com --- block/qcow2-refcount.c | 11 --- 1 files changed, 8 insertions(+), 3 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 51948ae..41e1da9 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -93,14 +93,19 @@ static int load_refcount_block(BlockDriverState *bs, int ret; if (cache_refcount_updates) { -write_refcount_block(bs); +ret = write_refcount_block(bs); +if (ret 0) { +return ret; +} } BLKDBG_EVENT(bs-file, BLKDBG_REFBLOCK_LOAD); ret = bdrv_pread(bs-file, refcount_block_offset, s-refcount_block_cache, s-cluster_size); -if (ret != s-cluster_size) -return -EIO; +if (ret 0) { +return ret; +} + s-refcount_block_cache_offset = refcount_block_offset; return 0; } -- 1.6.6.1
[Qemu-devel] Re: [PATCH 10/16] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c
+/* + * 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 +}; I agree with Richard: this is gross. The enum creation is gross by itself. Only way to get around not duplicating it is to create a new header file to hold just that? I don't think it's particularly gross. At least you don't have two files to keep in sync. You could rename qemu-options.h to qemu-options.def, and make a real header file with the typedef and the enum. Then include the header from vl.c and os-*.c. BTW from Fedora 11 and newer you can easily build QEMU with a cross compiler. (Running it is a bit harder). These packages should suffice: mingw32-w32api mingw32-cpp mingw32-termcap mingw32-runtime mingw32-binutils mingw32-filesystem mingw32-SDL mingw32-gcc mingw32-zlib and you need to configure it with --cross-prefix=i686-pc-mingw32- (trailing dash included!). Paolo
[Qemu-devel] Re: [PATCH 3/3] blockdev: Collect block device code in new blockdev.c
Am 02.06.2010 18:16, schrieb Markus Armbruster: Kevin Wolf kw...@redhat.com writes: Am 02.06.2010 13:31, schrieb Markus Armbruster: Anything that moves hundreds of lines out of vl.c can't be all bad. Signed-off-by: Markus Armbruster arm...@redhat.com New files need a license header, otherwise it looks ok. I have applied this patch (and the other ones, too) to the block branch anyway to avoid conflicts with other people basing their patches on that branch. However, it requires a v2 before I can propose this to be merged into master. vl.c has Copyright (c) 2003-2008 Fabrice Bellard. monitor.c has Copyright (c) 2003-2004 Fabrice Bellard. Would the following header do? /* * QEMU host block devices * * Copyright (c) 2003-2008 Fabrice Bellard * * This work is licensed under the terms of the GNU GPL, version 2 or * later. See the COPYING file in the top-level directory. */ Should be good enough, I think. vl.c and monitor.c are BSD licensed, though. Not sure if anyone minds if the license is changed to GPL. Probably not, just want to have it mentioned. Kevin
[Qemu-devel] Re: [PATCHv3 1/2] virtio: support layout with avail ring before idx
On Fri, Jun 04, 2010 at 12:04:57PM +0930, Rusty Russell wrote: 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 m...@redhat.com No no no no. 254? You're trying to Morton me![1] Hmm, I wonder what will we do if we want a 3rd field on a separate chacheline. But ok. How's this (untested): I think we also want to put flags there as well, they are used on interrupt path, together with last used index. 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 linux/irqreturn.h 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] Re: [RFC PATCH v4 3/3] block: add sheepdog driver for distributed storage support
Am 03.06.2010 18:23, schrieb MORITA Kazutaka: +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? I'm not sure how often it would happen in practice, but if the guest OS thinks the old value is on disk when in fact the new one is, this could lead to corruption. I think if it can happen, even without evidence that it actually does, it's already relevant enough. To wait for completion of the requests here, we may need to create another thread for processing I/O like posix-aio-compat.c. I don't think you need a thread to get the same behaviour, you just need to call the fd handlers like in the main loop. It would probably be the first driver doing this, though, and it's not an often used code path, so it might be a bad idea. Maybe it's reasonable to just complete the request with -EIO? This way the guest couldn't make any assumption about the data written. On the other hand, it could be unhappy about failed requests, but that's probably better than corruption. Kevin
[Qemu-devel] Re: [PATCHv3 1/2] virtio: support layout with avail ring before idx
On Fri, 4 Jun 2010 08:05:43 pm Michael S. Tsirkin wrote: On Fri, Jun 04, 2010 at 12:04:57PM +0930, Rusty Russell wrote: 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 m...@redhat.com No no no no. 254? You're trying to Morton me![1] Hmm, I wonder what will we do if we want a 3rd field on a separate chacheline. But ok. How's this (untested): I think we also want to put flags there as well, they are used on interrupt path, together with last used index. I'm uncomfortable with moving a field. We haven't done that before and I wonder what will break with old code. Should we instead just abandon the flags field and use last_used only? Or, more radically, put flags == last_used when the feature is on? Thoughts? Rusty.
[Qemu-devel] Re: [PATCHv3 1/2] virtio: support layout with avail ring before idx
On Fri, Jun 04, 2010 at 08:46:49PM +0930, Rusty Russell wrote: On Fri, 4 Jun 2010 08:05:43 pm Michael S. Tsirkin wrote: On Fri, Jun 04, 2010 at 12:04:57PM +0930, Rusty Russell wrote: 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 m...@redhat.com No no no no. 254? You're trying to Morton me![1] Hmm, I wonder what will we do if we want a 3rd field on a separate chacheline. But ok. How's this (untested): I think we also want to put flags there as well, they are used on interrupt path, together with last used index. I'm uncomfortable with moving a field. We haven't done that before and I wonder what will break with old code. With e.g. my patch, We only do this conditionally when bit is negotitated. Should we instead just abandon the flags field and use last_used only? Or, more radically, put flags == last_used when the feature is on? Thoughts? Rusty. Hmm, e.g. with TX and virtio net, we almost never want interrupts, whatever the index value. -- MST
Re: [Qemu-devel] [PATCH 00/16] clean up vl.c code
Jes Sorensen jes.soren...@redhat.com writes: On 06/04/10 10:21, Markus Armbruster wrote: jes.soren...@redhat.com writes: 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. I like moving stuff out of vl.c in general. Your moves of entire functions look like a win to me. I have doubts about spreading the option switch over three files, though. The problem is right now there are too many OS specific options, but having the #ifdefs plastered all over to enable/disable them accordingly is just a nightmare and is prone to leave in inconsistent behavior for various OSes. See the set_proc_name() stuff for an example. I doubt spreading option code over separate files will help consistency. I suspect the true root of the problem is having (too many) OS-specific options in the first place. What about parsing options the same everywhere, calling out to OS-specific functions to do the actual work? Let them fail with can't do this on this OS.
Re: [Qemu-devel] [PATCH 00/16] clean up vl.c code
On 06/04/10 13:54, Markus Armbruster wrote: Jes Sorensen jes.soren...@redhat.com writes: On 06/04/10 10:21, Markus Armbruster wrote: I like moving stuff out of vl.c in general. Your moves of entire functions look like a win to me. I have doubts about spreading the option switch over three files, though. The problem is right now there are too many OS specific options, but having the #ifdefs plastered all over to enable/disable them accordingly is just a nightmare and is prone to leave in inconsistent behavior for various OSes. See the set_proc_name() stuff for an example. I doubt spreading option code over separate files will help consistency. I suspect the true root of the problem is having (too many) OS-specific options in the first place. What about parsing options the same everywhere, calling out to OS-specific functions to do the actual work? Let them fail with can't do this on this OS. That is a possibility which I did consider, but it would end up in far more os specific functions for simple assignments etc. I modeled it the way I did similar to how we handle ioctl calls in the kernel. If there is strong feeling we should do it this way instead, I can change the code to do it this way instead. I am not married to the current approach, I just find it the lesser evil. Cheers, Jes
Re: [Qemu-devel] [PATCH 10/16] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c
Jes Sorensen jes.soren...@redhat.com writes: On 06/04/10 10:15, Markus Armbruster wrote: jes.soren...@redhat.com writes: + * 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 Was #ifndef _WIN32 before. Impact? It was moved to os-posix.c which is only built for non _WIN32, so it has the same effect, except it's not full of ugly #ifdef's I missed the fact that it is under #ifdef CONFIG_SLIRP in the current code. Sorry for the noise. +/* + * 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 +}; I agree with Richard: this is gross. The enum creation is gross by itself. Only way to get around not duplicating it is to create a new header file to hold just that? +/* 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; + Ugh. What do you mean? The real ugh! here is that it was created as a typedef. I can change the function to pass in just the index, but I don't know if we will have cases where the rest is needed. Moving stuff out of the vl.c grabbag is cool. Moving stuff into the sysemu.h grabbag is very uncool. Is this minor improvement of vl.c really worth the headaches elsewhere? vl.c as it is today is gross and un-maintainable. This patch gets rid of a lot of the ugly #ifdefs and makes the code easier to read and maintain. I'm not arguing against your patch, just trying to help making it even better.
[Qemu-devel] [PATCH] 9p: Make use of iounit for read/write
Change the v9fs_file_readn function to limit the maximum transfer size based on the iounit or msize. Also remove the redundant check for limiting the transfer size in v9fs_file_write. This check is done by p9_client_write. Signed-off-by: M. Mohan Kumar mo...@in.ibm.com --- fs/9p/vfs_file.c | 13 +++-- 1 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c index 25b300e..ae0147c 100644 --- a/fs/9p/vfs_file.c +++ b/fs/9p/vfs_file.c @@ -139,7 +139,7 @@ ssize_t v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, u64 offset) { - int n, total; + int n, total, size; struct p9_fid *fid = filp-private_data; P9_DPRINTK(P9_DEBUG_VFS, fid %d offset %llu count %d\n, fid-fid, @@ -147,6 +147,7 @@ v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, n = 0; total = 0; + size = fid-iounit ? fid-iounit : fid-clnt-msize - P9_IOHDRSZ; do { n = p9_client_read(fid, data, udata, offset, count); if (n = 0) @@ -160,7 +161,7 @@ v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count, offset += n; count -= n; total += n; - } while (count 0 n == (fid-clnt-msize - P9_IOHDRSZ)); + } while (count 0 n == size); if (n 0) total = n; @@ -183,11 +184,13 @@ v9fs_file_read(struct file *filp, char __user *udata, size_t count, { int ret; struct p9_fid *fid; + size_t size; P9_DPRINTK(P9_DEBUG_VFS, count %zu offset %lld\n, count, *offset); fid = filp-private_data; - if (count (fid-clnt-msize - P9_IOHDRSZ)) + size = fid-iounit ? fid-iounit : fid-clnt-msize - P9_IOHDRSZ; + if (count size) ret = v9fs_file_readn(filp, NULL, udata, count, *offset); else ret = p9_client_read(fid, NULL, udata, *offset, count); @@ -224,9 +227,7 @@ v9fs_file_write(struct file *filp, const char __user * data, fid = filp-private_data; clnt = fid-clnt; - rsize = fid-iounit; - if (!rsize || rsize clnt-msize-P9_IOHDRSZ) - rsize = clnt-msize - P9_IOHDRSZ; + rsize = fid-iounit ? fid-iounit : clnt-msize - P9_IOHDRSZ; do { if (count rsize) -- 1.6.6.1
Re: [Qemu-devel] [PATCH] Add exit notifiers.
--- a/roms/seabios +++ b/roms/seabios @@ -1 +1 @@ -Subproject commit 8f469b9676127ba6bb52609d89ec774e61db0ee1 +Subproject commit 7d09d0e3ba11310e973d4302c7fcc3fc2184e04c This hunk seems unrelated to your commit. Damn. Yea. These seem to creap in now and then, I think when rebasing to a new version with new seabios, then carelessly doing 'git commit -a'. +void qemu_add_exit_notifier(Notifier *notify) Why #ifndef _WIN32? I think this patch will break _WIN32 builds. Not intentionally. Sent fixed version. cheers, Gerd
Re: [Qemu-devel] [PATCH 10/16] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c
On 06/04/10 14:04, Markus Armbruster wrote: Jes Sorensen jes.soren...@redhat.com writes: On 06/04/10 10:15, Markus Armbruster wrote: What do you mean? The real ugh! here is that it was created as a typedef. I can change the function to pass in just the index, but I don't know if we will have cases where the rest is needed. Moving stuff out of the vl.c grabbag is cool. Moving stuff into the sysemu.h grabbag is very uncool. I agree, I have a new version of the patch coming up shortly. I just want to apply Paolo's idea of moving qemu-options.h around a bit. Is this minor improvement of vl.c really worth the headaches elsewhere? vl.c as it is today is gross and un-maintainable. This patch gets rid of a lot of the ugly #ifdefs and makes the code easier to read and maintain. I'm not arguing against your patch, just trying to help making it even better. I was gathering that, and your input is much appreciated. Cheers, Jes
[Qemu-devel] Re: [PATCH 3/3] blockdev: Collect block device code in new blockdev.c
Kevin Wolf kw...@redhat.com writes: Am 02.06.2010 18:16, schrieb Markus Armbruster: Kevin Wolf kw...@redhat.com writes: Am 02.06.2010 13:31, schrieb Markus Armbruster: Anything that moves hundreds of lines out of vl.c can't be all bad. Signed-off-by: Markus Armbruster arm...@redhat.com New files need a license header, otherwise it looks ok. I have applied this patch (and the other ones, too) to the block branch anyway to avoid conflicts with other people basing their patches on that branch. However, it requires a v2 before I can propose this to be merged into master. vl.c has Copyright (c) 2003-2008 Fabrice Bellard. monitor.c has Copyright (c) 2003-2004 Fabrice Bellard. Would the following header do? /* * QEMU host block devices * * Copyright (c) 2003-2008 Fabrice Bellard * * This work is licensed under the terms of the GNU GPL, version 2 or * later. See the COPYING file in the top-level directory. */ Should be good enough, I think. vl.c and monitor.c are BSD licensed, though. Not sure if anyone minds if the license is changed to GPL. Probably not, just want to have it mentioned. If this were not okay, I'd split blockdev.c, because I want my new code GPL'ed.
[Qemu-devel] [Bug 587993] Re: qemu-kvm 0.12.4+dfsg-1 from debian squeeze crashes BUG: unable to handle kernel NULL pointer (sym53c8xx)
** Description changed: I use eucalyptus software (1.6.2) on debian squeeze with kvm - 0.12.4+dfsg-1. Kernel 2.6.32-3-amd64. After a few days machines crash. - There are no logs in host system. Guest is the same kernel and OS as - host. The kvm process use 100% of cpu time. I can not even ping the - guest. Here is the log from virtual machine: + 0.12.4+dfsg-1 (the same happend with 0.11.1+dfsg-1 ). Kernel + 2.6.32-3-amd64. After a few days machines crash. There are no logs in + host system. Guest is the same kernel and OS as host. The kvm process + use 100% of cpu time. I can not even ping the guest. Here is the log + from virtual machine: [ 3577.81] sd 0:0:0:0: [sda] ABORT operation started [ 3582.816047] sd 0:0:0:0: ABORT operation timed-out. [ 3582.816781] sd 0:0:0:0: [sda] ABORT operation started [ 3587.816649] sd 0:0:0:0: ABORT operation timed-out. [ 3587.817379] sd 0:0:0:0: [sda] DEVICE RESET operation started [ 3592.816062] sd 0:0:0:0: DEVICE RESET operation timed-out. [ 3592.816882] sd 0:0:0:0: [sda] BUS RESET operation started [ 3592.820056] sym0: SCSI BUS reset detected. [ 3592.831538] sym0: SCSI BUS has been reset. [ 3592.831968] BUG: unable to handle kernel NULL pointer dereference at 0358 [ 3592.832003] IP: [a01147c4] sym_int_sir+0x62f/0x14e0 [sym53c8xx] - [ 3592.832003] PGD 5f73e067 PUD 5fa53067 PMD 0 - [ 3592.832003] Oops: [#1] SMP + [ 3592.832003] PGD 5f73e067 PUD 5fa53067 PMD 0 + [ 3592.832003] Oops: [#1] SMP [ 3592.832003] last sysfs file: /sys/devices/pci:00/:00:05.0/host0/target0:0:0/0:0:0:0/vendor - [ 3592.832003] CPU 0 + [ 3592.832003] CPU 0 [ 3592.832003] Modules linked in: dm_mod openafs(P) ext2 snd_pcsp snd_pcm snd_timer serio_raw i2c_piix4 snd virtio_balloon evdev i2c_core soundcore psmouse button processor snd_page_alloc ext3 jbd mbcache sd_mod crc_t10dif ata_generic libata ide_pci_generic sym53c8xx scsi_transport_spi thermal piix uhci_hcd ehci_hcd floppy thermal_sys scsi_mod virtio_pci virtio_ring virtio e1000 ide_core usbcore nls_base [last unloaded: scsi_wait_scan] [ 3592.832003] Pid: 193, comm: scsi_eh_0 Tainted: P 2.6.32-3-amd64 #1 Bochs [ 3592.832003] RIP: 0010:[a01147c4] [a01147c4] sym_int_sir+0x62f/0x14e0 [sym53c8xx] [ 3592.832003] RSP: 0018:880001803cb0 EFLAGS: 00010287 [ 3592.832003] RAX: 000a RBX: 000b RCX: 5f410090 [ 3592.832003] RDX: RSI: 88005c450800 RDI: c9a5e006 [ 3592.832003] RBP: 88005f41 R08: R09: [ 3592.832003] R10: 003a R11: 813b871e R12: 88005f410090 [ 3592.832003] R13: 0084 R14: R15: 0001 [ 3592.832003] FS: () GS:88000180() knlGS: [ 3592.832003] CS: 0010 DS: 0018 ES: 0018 CR0: 8005003b [ 3592.832003] CR2: 0358 CR3: 5e269000 CR4: 06f0 [ 3592.832003] DR0: DR1: DR2: [ 3592.832003] DR3: DR6: 0ff0 DR7: 0400 [ 3592.832003] Process scsi_eh_0 (pid: 193, threadinfo 88005f6fa000, task 88005f697880) [ 3592.832003] Stack: [ 3592.832003] 88005f3fd000 0130 [ 3592.832003] 0 88005f407710 c9a64710 ff10 81195301 [ 3592.832003] 0 0010 00010212 880001803d18 0018 [ 3592.832003] Call Trace: - [ 3592.832003] IRQ + [ 3592.832003] IRQ [ 3592.832003] [81195301] ? __memcpy_toio+0x9/0x19 [ 3592.832003] [a01164ed] ? sym_interrupt+0x46c/0x6a3 [sym53c8xx] [ 3592.832003] [8103fea0] ? update_curr+0xa6/0x147 [ 3592.832003] [a010fbde] ? sym53c8xx_intr+0x43/0x6a [sym53c8xx] [ 3592.832003] [81093bfc] ? handle_IRQ_event+0x58/0x126 [ 3592.832003] [810954e2] ? handle_fasteoi_irq+0x7d/0xb5 [ 3592.832003] [81013957] ? handle_irq+0x17/0x1d [ 3592.832003] [81012fb1] ? do_IRQ+0x57/0xb6 [ 3592.832003] [810114d3] ? ret_from_intr+0x0/0x11 [ 3592.832003] [81053903] ? __do_softirq+0x6e/0x19f [ 3592.832003] [8106fa87] ? tick_dev_program_event+0x2d/0x95 [ 3592.832003] [81011cac] ? call_softirq+0x1c/0x30 [ 3592.832003] [81013903] ? do_softirq+0x3f/0x7c [ 3592.832003] [810537e1] ? irq_exit+0x36/0x76 [ 3592.832003] [81025837] ? smp_apic_timer_interrupt+0x87/0x95 [ 3592.832003] [81011673] ? apic_timer_interrupt+0x13/0x20 - [ 3592.832003] EOI + [ 3592.832003] EOI [ 3592.832003] [8118e009] ? delay_tsc+0x0/0x73 [ 3592.832003] [a010f900] ? sym_eh_handler+0x22e/0x2e2 [sym53c8xx] [ 3592.832003] [a008e5de] ? scsi_try_bus_reset+0x50/0xd9 [scsi_mod] [ 3592.832003]
Re: [Qemu-devel] Re: [PATCH V3 1/3] qemu: Add qemu-wrappers for pthread_attr_t
On 06/03/2010 07:31 AM, Paolo Bonzini wrote: 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). This is historical because the code was largely inspired by glibc's implementation of posix-aio. It doesn't need to be detached and since Corentin wants to be able to join a worker, it makes sense to just avoid detaching and pay the overhead of making the threads joinable. Regards, Anthony Liguori Paolo
[Qemu-devel] [PATCH 3/5] vnc: add lossless option
The lossless option can be used to force lossless compression by disabling all lossy encodings like gradient or jpeg. Signed-off-by: Corentin Chary corenti...@iksaif.net --- qemu-options.hx |5 + vnc-encoding-tight.c |4 vnc.c|2 ++ vnc.h|2 ++ 4 files changed, 13 insertions(+), 0 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index a6928b7..81fd737 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -828,6 +828,11 @@ empty, with a @code{deny} policy. Thus no one will be allowed to use the VNC server until the ACLs have been loaded. This can be achieved using the @code{acl} monitor command. +...@item lossless + +Turn off all lossy compression methods (gradient, JPEG, ...). If this +option is set, VNC client will only receive lossless framebuffer updates. + @end table ETEXI diff --git a/vnc-encoding-tight.c b/vnc-encoding-tight.c index 495745e..51bb707 100644 --- a/vnc-encoding-tight.c +++ b/vnc-encoding-tight.c @@ -230,6 +230,10 @@ tight_detect_smooth_image(VncState *vs, int w, int h) int compression = vs-tight_compression; int quality = vs-tight_quality; +if (vs-vd-lossless) { +return 0; +} + if (ds_get_bytes_per_pixel(vs-ds) == 1 || vs-clientds.pf.bytes_per_pixel == 1 || w VNC_TIGHT_DETECT_MIN_WIDTH || h VNC_TIGHT_DETECT_MIN_HEIGHT) { diff --git a/vnc.c b/vnc.c index 9cf38d1..e3ef315 100644 --- a/vnc.c +++ b/vnc.c @@ -2482,6 +2482,8 @@ int vnc_display_open(DisplayState *ds, const char *display) #endif } else if (strncmp(options, acl, 3) == 0) { acl = 1; +} else if (strncmp(options, lossless, 8) == 0) { +vs-lossless = true; } } diff --git a/vnc.h b/vnc.h index 2a9024d..cca1946 100644 --- a/vnc.h +++ b/vnc.h @@ -33,6 +33,7 @@ #include monitor.h #include audio/audio.h #include zlib.h +#include stdbool.h #include keymaps.h @@ -111,6 +112,7 @@ struct VncDisplay char *display; char *password; int auth; +bool lossless; #ifdef CONFIG_VNC_TLS int subauth; /* Used by VeNCrypt */ VncDisplayTLS tls; -- 1.7.1
[Qemu-devel] [PATCH 0/5] vnc updates and ui move
Hi, This set starts by adding JPEG and gradient to tight, then move all ui code in the ui/ subdirectory. Thanks, Corentin Chary (5): vnc: tight: add JPEG and gradient subencoding with smooth image detection vnc: JPEG should be disabled if the client don't set tight quality vnc: add lossless option ui: move all ui components in ui/ vnc: rename vnc-encoding-* vnc-enc-* Makefile | 38 +- Makefile.objs | 22 +- Makefile.target |1 + cocoa.m | 1014 configure | 33 + curses.c | 365 -- curses_keys.h | 508 d3des.c | 424 --- d3des.h | 51 - keymaps.c | 210 keymaps.h | 77 -- qemu-options.hx |5 + sdl.c | 879 -- sdl_keysym.h | 277 - sdl_zoom.c| 95 -- sdl_zoom.h| 25 - sdl_zoom_template.h | 225 ui/cocoa.m| 1014 ui/curses.c | 365 ++ ui/curses_keys.h | 508 ui/d3des.c| 424 +++ ui/d3des.h| 51 + ui/keymaps.c | 210 ui/keymaps.h | 77 ++ ui/sdl.c | 879 ++ ui/sdl_keysym.h | 277 + ui/sdl_zoom.c | 95 ++ ui/sdl_zoom.h | 25 + ui/sdl_zoom_template.h| 225 ui/vnc-auth-sasl.c| 637 ++ ui/vnc-auth-sasl.h| 74 ++ ui/vnc-auth-vencrypt.c| 175 +++ ui/vnc-auth-vencrypt.h| 33 + ui/vnc-enc-hextile-template.h | 211 ui/vnc-enc-hextile.c | 116 ++ ui/vnc-enc-tight.c| 1522 ui/vnc-enc-tight.h| 181 +++ ui/vnc-enc-zlib.c | 152 +++ ui/vnc-tls.c | 445 +++ ui/vnc-tls.h | 76 ++ ui/vnc.c | 2631 + ui/vnc.h | 430 +++ ui/vnc_keysym.h | 324 + ui/x_keymap.c | 168 +++ ui/x_keymap.h | 32 + vnc-auth-sasl.c | 637 -- vnc-auth-sasl.h | 74 -- vnc-auth-vencrypt.c | 175 --- vnc-auth-vencrypt.h | 33 - vnc-encoding-hextile.c| 116 -- vnc-encoding-tight.c | 961 --- vnc-encoding-tight.h | 176 --- vnc-encoding-zlib.c | 152 --- vnc-tls.c | 445 --- vnc-tls.h | 76 -- vnc.c | 2629 vnc.h | 424 --- vnc_keysym.h | 324 - vnchextile.h | 211 x_keymap.c| 168 --- x_keymap.h| 32 - 61 files changed, 11413 insertions(+), 10826 deletions(-) delete mode 100644 cocoa.m delete mode 100644 curses.c delete mode 100644 curses_keys.h delete mode 100644 d3des.c delete mode 100644 d3des.h delete mode 100644 keymaps.c delete mode 100644 keymaps.h delete mode 100644 sdl.c delete mode 100644 sdl_keysym.h delete mode 100644 sdl_zoom.c delete mode 100644 sdl_zoom.h delete mode 100644 sdl_zoom_template.h create mode 100644 ui/cocoa.m create mode 100644 ui/curses.c create mode 100644 ui/curses_keys.h create mode 100644 ui/d3des.c create mode 100644 ui/d3des.h create mode 100644 ui/keymaps.c create mode 100644 ui/keymaps.h create mode 100644 ui/sdl.c create mode 100644 ui/sdl_keysym.h create mode 100644 ui/sdl_zoom.c create mode 100644 ui/sdl_zoom.h create mode 100644 ui/sdl_zoom_template.h create mode 100644 ui/vnc-auth-sasl.c create mode 100644 ui/vnc-auth-sasl.h create mode 100644 ui/vnc-auth-vencrypt.c create mode 100644 ui/vnc-auth-vencrypt.h create mode 100644 ui/vnc-enc-hextile-template.h create mode 100644 ui/vnc-enc-hextile.c create mode 100644 ui/vnc-enc-tight.c create mode 100644 ui/vnc-enc-tight.h create mode 100644 ui/vnc-enc-zlib.c create mode 100644 ui/vnc-tls.c create mode 100644 ui/vnc-tls.h create mode 100644 ui/vnc.c create mode 100644 ui/vnc.h create mode 100644 ui/vnc_keysym.h create mode 100644 ui/x_keymap.c create mode 100644 ui/x_keymap.h delete mode 100644 vnc-auth-sasl.c delete mode 100644 vnc-auth-sasl.h delete mode 100644 vnc-auth-vencrypt.c delete mode 100644 vnc-auth-vencrypt.h delete mode 100644 vnc-encoding-hextile.c delete mode 100644 vnc-encoding-tight.c delete mode 100644 vnc-encoding-tight.h delete mode 100644 vnc-encoding-zlib.c delete mode 100644 vnc-tls.c delete mode 100644 vnc-tls.h delete mode 100644 vnc.c delete mode 100644 vnc.h
[Qemu-devel] [PATCH 2/5] vnc: JPEG should be disabled if the client don't set tight quality
Disable JPEG compression by default and only enable it if the VNC client has sent the requested quality. Signed-off-by: Corentin Chary corenti...@iksaif.net --- vnc.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/vnc.c b/vnc.c index ed0e096..9cf38d1 100644 --- a/vnc.c +++ b/vnc.c @@ -1644,7 +1644,7 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings) vs-features = 0; vs-vnc_encoding = 0; vs-tight_compression = 9; -vs-tight_quality = 9; +vs-tight_quality = -1; /* Lossless by default */ vs-absolute = -1; /* -- 1.7.1
[Qemu-devel] [PATCH 1/5] vnc: tight: add JPEG and gradient subencoding with smooth image detection
Add gradient filter and JPEG compression with an heuristic to detect how lossy the comppression will be. This code has been adapted from libvncserver/tight.c. JPEG support can be enabled/disabled at compile time with --enable-vnc-jpeg and --disable-vnc-jpeg. Signed-off-by: Corentin Chary corenti...@iksaif.net --- Makefile.target |1 + configure| 33 +++ vnc-encoding-tight.c | 559 +- vnc-encoding-tight.h |5 + vnc.h|4 + 5 files changed, 601 insertions(+), 1 deletions(-) diff --git a/Makefile.target b/Makefile.target index d06c679..decdcfa 100644 --- a/Makefile.target +++ b/Makefile.target @@ -177,6 +177,7 @@ LIBS+=-lz QEMU_CFLAGS += $(VNC_TLS_CFLAGS) QEMU_CFLAGS += $(VNC_SASL_CFLAGS) +QEMU_CFLAGS += $(VNC_JPEG_CFLAGS) # xen backend driver support obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o diff --git a/configure b/configure index 653c8d2..679f2fc 100755 --- a/configure +++ b/configure @@ -263,6 +263,7 @@ uuid= vde= vnc_tls= vnc_sasl= +vnc_jpeg= xen= linux_aio= vhost_net= @@ -547,6 +548,10 @@ for opt do ;; --enable-vnc-sasl) vnc_sasl=yes ;; + --disable-vnc-jpeg) vnc_jpeg=no + ;; + --enable-vnc-jpeg) vnc_jpeg=yes + ;; --disable-slirp) slirp=no ;; --disable-uuid) uuid=no @@ -779,6 +784,8 @@ echo --disable-vnc-tlsdisable TLS encryption for VNC server echo --enable-vnc-tls enable TLS encryption for VNC server echo --disable-vnc-sasl disable SASL encryption for VNC server echo --enable-vnc-saslenable SASL encryption for VNC server +echo --disable-vnc-jpeg disable JPEG lossy compression for VNC server +echo --enable-vnc-jpegenable JPEG lossy compression for VNC server echo --disable-curses disable curses output echo --enable-curses enable curses output echo --disable-curl disable curl connectivity @@ -1191,6 +1198,27 @@ EOF fi ## +# VNC JPEG detection +if test $vnc_jpeg = yes ; then +cat $TMPC EOF +#include stdio.h +#include jpeglib.h +int main(void) { struct jpeg_compress_struct s; jpeg_create_compress(s); return 0; } +EOF +vnc_jpeg_cflags= +vnc_jpeg_libs=-ljpeg + if compile_prog $vnc_jpeg_cflags $vnc_jpeg_libs ; then +vnc_jpeg=yes +libs_softmmu=$vnc_jpeg_libs $libs_softmmu + else +if test $vnc_jpeg = yes ; then + feature_not_found vnc-jpeg +fi +vnc_jpeg=no + fi +fi + +## # fnmatch() probe, used for ACL routines fnmatch=no cat $TMPC EOF @@ -2019,6 +2047,7 @@ echo Block whitelist $block_drv_whitelist echo Mixer emulation $mixemu echo VNC TLS support $vnc_tls echo VNC SASL support $vnc_sasl +echo VNC JPEG support $vnc_jpeg if test -n $sparc_cpu; then echo Target Sparc Arch $sparc_cpu fi @@ -2158,6 +2187,10 @@ if test $vnc_sasl = yes ; then echo CONFIG_VNC_SASL=y $config_host_mak echo VNC_SASL_CFLAGS=$vnc_sasl_cflags $config_host_mak fi +if test $vnc_jpeg = yes ; then + echo CONFIG_VNC_JPEG=y $config_host_mak + echo VNC_JPEG_CFLAGS=$vnc_jpeg_cflags $config_host_mak +fi if test $fnmatch = yes ; then echo CONFIG_FNMATCH=y $config_host_mak fi diff --git a/vnc-encoding-tight.c b/vnc-encoding-tight.c index efb57e7..495745e 100644 --- a/vnc-encoding-tight.c +++ b/vnc-encoding-tight.c @@ -26,8 +26,16 @@ * THE SOFTWARE. */ + +#include qemu-common.h + +#ifdef CONFIG_VNC_JPEG +#include stdio.h +#include jpeglib.h +#endif #include stdbool.h +#include bswap.h #include qdict.h #include qint.h #include vnc.h @@ -58,6 +66,206 @@ static const struct { }; /* + * Code to guess if given rectangle is suitable for smooth image + * compression (by applying gradient filter or JPEG coder). + */ + +static uint +tight_detect_smooth_image24(VncState *vs, int w, int h) +{ +int off; +int x, y, d, dx; +uint c; +uint stats[256]; +int pixels = 0; +int pix, left[3]; +uint errors; +unsigned char *buf = vs-tight.buffer; + +/* + * If client is big-endian, color samples begin from the second + * byte (offset 1) of a 32-bit pixel value. + */ +off = !!(vs-clientds.flags QEMU_BIG_ENDIAN_FLAG); + +memset(stats, 0, sizeof (stats)); + +for (y = 0, x = 0; y h x w;) { +for (d = 0; d h - y d w - x - VNC_TIGHT_DETECT_SUBROW_WIDTH; + d++) { +for (c = 0; c 3; c++) { +left[c] = buf[((y+d)*w+x+d)*4+off+c] 0xFF; +} +for (dx = 1; dx = VNC_TIGHT_DETECT_SUBROW_WIDTH; dx++) { +for (c = 0; c 3; c++) { +pix = buf[((y+d)*w+x+d+dx)*4+off+c] 0xFF; +stats[abs(pix - left[c])]++; +left[c] = pix; +} +pixels++; +} +} +if (w h) { +x += h; +y = 0; +} else {
Re: [Qemu-devel] [PATCH V3 2/3] qemu: Generic asynchronous threading framework to offload tasks
On 06/03/2010 03:56 AM, Gautham R Shenoy wrote: From: Aneesh Kumar K.Vaneesh.ku...@linux.vnet.ibm.com 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.Vaneesh.ku...@linux.vnet.ibm.com Signed-off-by: Gautham R Shenoye...@in.ibm.com --- 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.Vaneesh.ku...@linux.vnet.ibm.com + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. Please preserve the original copyright of the copied code. + */ +#includestdio.h +#includeerrno.h +#includestring.h +#includestdlib.h +#includesignal.h qemu-common.h should have all of these. Generally, you should avoid including system headers because qemu headers take care of portability. +#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
[Qemu-devel] Re: [PATCH 3/5] vnc: add lossless option
On 04.06.2010, at 15:18, Corentin Chary wrote: The lossless option can be used to force lossless compression by disabling all lossy encodings like gradient or jpeg. I think this should be reverse. Be lossless by default, but have a lossy option. Alex
[Qemu-devel] [PATCH v2 1/2] qemu-thread: add qemu_mutex/cond_destroy and qemu_mutex_exit
Add some missing functions in qemu-thread. Currently qemu-thread is only used for io-thread but it will used by the vnc server soon and we need those functions instead of calling pthread directly. Signed-off-by: Corentin Chary corenti...@iksaif.net --- qemu-thread.c | 22 ++ qemu-thread.h |4 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/qemu-thread.c b/qemu-thread.c index 3923db7..afc9933 100644 --- a/qemu-thread.c +++ b/qemu-thread.c @@ -34,6 +34,15 @@ void qemu_mutex_init(QemuMutex *mutex) error_exit(err, __func__); } +void qemu_mutex_destroy(QemuMutex *mutex) +{ +int err; + +err = pthread_mutex_destroy(mutex-lock); +if (err) +error_exit(err, __func__); +} + void qemu_mutex_lock(QemuMutex *mutex) { int err; @@ -90,6 +99,15 @@ void qemu_cond_init(QemuCond *cond) error_exit(err, __func__); } +void qemu_cond_destroy(QemuCond *cond) +{ +int err; + +err = pthread_cond_destroy(cond-cond); +if (err) +error_exit(err, __func__); +} + void qemu_cond_signal(QemuCond *cond) { int err; @@ -161,3 +179,7 @@ int qemu_thread_equal(QemuThread *thread1, QemuThread *thread2) return pthread_equal(thread1-thread, thread2-thread); } +void qemu_thread_exit(void *retval) +{ +pthread_exit(retval); +} diff --git a/qemu-thread.h b/qemu-thread.h index 5ef4a3a..19bb30c 100644 --- a/qemu-thread.h +++ b/qemu-thread.h @@ -20,12 +20,14 @@ typedef struct QemuCond QemuCond; typedef struct QemuThread QemuThread; void qemu_mutex_init(QemuMutex *mutex); +void qemu_mutex_destroy(QemuMutex *mutex); void qemu_mutex_lock(QemuMutex *mutex); int qemu_mutex_trylock(QemuMutex *mutex); int qemu_mutex_timedlock(QemuMutex *mutex, uint64_t msecs); void qemu_mutex_unlock(QemuMutex *mutex); void qemu_cond_init(QemuCond *cond); +void qemu_cond_destroy(QemuCond *cond); void qemu_cond_signal(QemuCond *cond); void qemu_cond_broadcast(QemuCond *cond); void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex); @@ -37,4 +39,6 @@ void qemu_thread_create(QemuThread *thread, 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_exit(void *retval); + #endif -- 1.7.1
[Qemu-devel] Re: [PATCH 4/5] ui: move all ui components in ui/
On 04.06.2010, at 15:18, Corentin Chary wrote: Move sdl, vnc, curses and cocoa UI into ui/ to cleanup the root directory. Also remove some unnecessary explicit targets from Makefile. There's a magic command to tell git to indicate moves as moves. I guess that'd be a good idea here :) Alex
Re: [Qemu-devel] Re: [PATCH V3 1/3] qemu: Add qemu-wrappers for pthread_attr_t
On Fri, Jun 4, 2010 at 3:07 PM, Anthony Liguori anth...@codemonkey.ws wrote: On 06/03/2010 07:31 AM, Paolo Bonzini wrote: 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). This is historical because the code was largely inspired by glibc's implementation of posix-aio. Â It doesn't need to be detached and since Corentin wants to be able to join a worker, it makes sense to just avoid detaching and pay the overhead of making the threads joinable. Regards, Anthony Liguori Actually, I want to know if the queue is empty and if no job are currently being processed: all worker are idle or stopped. I don't really need pthread_join() for that, since worker can be idle (we don't want to always start and stop the thread :) ). -- Corentin Chary http://xf.iksaif.net
[Qemu-devel] [PATCH 02/17] Create qemu-os-win32.h and move WIN32 specific declarations there
From: Jes Sorensen jes.soren...@redhat.com Create qemu-os-win32.h for WIN32 specific declarations. Move polling handling declaration into this file from sysemu.h Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- qemu-os-win32.h | 43 +++ sysemu.h| 17 + 2 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 qemu-os-win32.h diff --git a/qemu-os-win32.h b/qemu-os-win32.h new file mode 100644 index 000..be108ad --- /dev/null +++ b/qemu-os-win32.h @@ -0,0 +1,43 @@ +/* + * win32 specific declarations + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2010 Jes Sorensen jes.soren...@redhat.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef QEMU_OS_WIN32_H +#define QEMU_OS_WIN32_H + +/* Polling handling */ + +/* return TRUE if no sleep should be done afterwards */ +typedef int PollingFunc(void *opaque); + +int qemu_add_polling_cb(PollingFunc *func, void *opaque); +void qemu_del_polling_cb(PollingFunc *func, void *opaque); + +/* Wait objects handling */ +typedef void WaitObjectFunc(void *opaque); + +int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); +void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); + +#endif diff --git a/sysemu.h b/sysemu.h index 879446a..13fc9a9 100644 --- a/sysemu.h +++ b/sysemu.h @@ -9,6 +9,7 @@ #ifdef _WIN32 #include windows.h +#include qemu-os-win32.h #endif /* vl.c */ @@ -71,22 +72,6 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f); void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f); int qemu_loadvm_state(QEMUFile *f); -#ifdef _WIN32 -/* Polling handling */ - -/* return TRUE if no sleep should be done afterwards */ -typedef int PollingFunc(void *opaque); - -int qemu_add_polling_cb(PollingFunc *func, void *opaque); -void qemu_del_polling_cb(PollingFunc *func, void *opaque); - -/* Wait objects handling */ -typedef void WaitObjectFunc(void *opaque); - -int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); -void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); -#endif - /* SLIRP */ void do_info_slirp(Monitor *mon); -- 1.6.5.2
[Qemu-devel] [PATCH 07/17] Rename os_setup_signal_handling() to os_setup_early_signal_handling()
From: Jes Sorensen jes.soren...@redhat.com Rename os_setup_signal_handling() to os_setup_early_signal_handling() Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c |2 +- os-win32.c |2 +- qemu-os-posix.h |2 +- qemu-os-win32.h |2 +- vl.c|2 +- 5 files changed, 5 insertions(+), 5 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/qemu-os-posix.h b/qemu-os-posix.h index ff5adb1..2f54d40 100644 --- a/qemu-os-posix.h +++ b/qemu-os-posix.h @@ -30,6 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout) { } -void os_setup_signal_handling(void); +void os_setup_early_signal_handling(void); #endif diff --git a/qemu-os-win32.h b/qemu-os-win32.h index 74c7b4d..65e3a9d 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -40,6 +40,6 @@ 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); -static inline void os_setup_signal_handling(void) {} +static inline void os_setup_early_signal_handling(void) {} void os_host_main_loop_wait(int *timeout); #endif 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 08/17] Move main signal handler setup to os specificfiles.
From: Jes Sorensen jes.soren...@redhat.com Move main signal handler setup to os specific files. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c | 27 +++ qemu-os-posix.h |1 + qemu-os-win32.h |3 +++ vl.c| 33 + 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/os-posix.c b/os-posix.c index 948f662..01dbec2 100644 --- a/os-posix.c +++ b/os-posix.c @@ -26,6 +26,8 @@ #include unistd.h #include fcntl.h #include signal.h +#include sys/types.h +#include sys/wait.h /* Needed early for CONFIG_BSD etc. */ #include config-host.h @@ -39,3 +41,28 @@ void os_setup_early_signal_handling(void) act.sa_handler = SIG_IGN; sigaction(SIGPIPE, act, NULL); } + +static void termsig_handler(int signal) +{ +qemu_system_shutdown_request(); +} + +static void sigchld_handler(int signal) +{ +waitpid(-1, NULL, WNOHANG); +} + +void os_setup_signal_handling(void) +{ +struct sigaction act; + +memset(act, 0, sizeof(act)); +act.sa_handler = termsig_handler; +sigaction(SIGINT, act, NULL); +sigaction(SIGHUP, act, NULL); +sigaction(SIGTERM, act, NULL); + +act.sa_handler = sigchld_handler; +act.sa_flags = SA_NOCLDSTOP; +sigaction(SIGCHLD, act, NULL); +} diff --git a/qemu-os-posix.h b/qemu-os-posix.h index 2f54d40..41a4360 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_early_signal_handling(void); +void os_setup_signal_handling(void); #endif diff --git a/qemu-os-win32.h b/qemu-os-win32.h index 65e3a9d..ee30ea9 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -42,4 +42,7 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); static inline void os_setup_early_signal_handling(void) {} 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 00/17] *** SUBJECT HERE ***
From: Jes Sorensen jes.soren...@redhat.com *** BLURB HERE *** Jes Sorensen (17): 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. Rename qemu-options.h to qemu-options.def 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 |8 +- os-posix.c | 329 os-win32.c | 221 qemu-os-posix.h | 40 + qemu-os-win32.h | 53 ++ sysemu.h| 26 +-- vl.c| 498 ++- 7 files changed, 676 insertions(+), 499 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 10/17] Rename qemu-options.h to qemu-options.def
From: Jes Sorensen jes.soren...@redhat.com Rename qemu-options.h to qemu-options.def as it is not a header file for general use and this leaves space for a proper qemu-options.h Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- Makefile.objs |4 ++-- vl.c |6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index 2d94677..124afe7 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -258,8 +258,8 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS) -vl.o: qemu-options.h +vl.o: qemu-options.def -qemu-options.h: $(SRC_PATH)/qemu-options.hx +qemu-options.def: $(SRC_PATH)/qemu-options.hx $(call quiet-command,sh $(SRC_PATH)/hxtool -h $ $@, GEN $(TARGET_DIR)$@) diff --git a/vl.c b/vl.c index 7f22733..8cd0f8f 100644 --- a/vl.c +++ b/vl.c @@ -1875,7 +1875,7 @@ static void help(int exitcode) #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ opt_help #define DEFHEADING(text) stringify(text) \n -#include qemu-options.h +#include qemu-options.def #undef DEF #undef DEFHEADING #undef GEN_DOCS @@ -1903,7 +1903,7 @@ enum { #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ opt_enum, #define DEFHEADING(text) -#include qemu-options.h +#include qemu-options.def #undef DEF #undef DEFHEADING #undef GEN_DOCS @@ -1921,7 +1921,7 @@ static const QEMUOption qemu_options[] = { #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \ { option, opt_arg, opt_enum, arch_mask }, #define DEFHEADING(text) -#include qemu-options.h +#include qemu-options.def #undef DEF #undef DEFHEADING #undef GEN_DOCS -- 1.6.5.2
[Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files
From: Jes Sorensen jes.soren...@redhat.com Move daemonize handling from vl.c to OS specific files. Provide dummy stubs for Win32. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c | 102 os-win32.c |5 +++ qemu-os-posix.h |2 + qemu-os-win32.h |2 + sysemu.h|1 + vl.c| 106 ++- 6 files changed, 115 insertions(+), 103 deletions(-) diff --git a/os-posix.c b/os-posix.c index 6417d16..1672e06 100644 --- a/os-posix.c +++ b/os-posix.c @@ -39,6 +39,8 @@ static struct passwd *user_pwd; static const char *chroot_dir; +static int daemonize; +static int fds[2]; void os_setup_early_signal_handling(void) { @@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg) case QEMU_OPTION_chroot: chroot_dir = optarg; break; +case QEMU_OPTION_daemonize: +daemonize = 1; +break; } return; } @@ -196,3 +201,100 @@ void os_change_root(void) } } + +void os_daemonize(void) +{ +if (daemonize) { + pid_t pid; + + if (pipe(fds) == -1) + exit(1); + + pid = fork(); + if (pid 0) { + uint8_t status; + ssize_t len; + + close(fds[1]); + + again: +len = read(fds[0], status, 1); +if (len == -1 (errno == EINTR)) +goto again; + +if (len != 1) +exit(1); +else if (status == 1) { +fprintf(stderr, Could not acquire pidfile: %s\n, strerror(errno)); +exit(1); +} else +exit(0); + } else if (pid 0) +exit(1); + + close(fds[0]); + qemu_set_cloexec(fds[1]); + + setsid(); + + pid = fork(); + if (pid 0) + exit(0); + else if (pid 0) + exit(1); + + umask(027); + +signal(SIGTSTP, SIG_IGN); +signal(SIGTTOU, SIG_IGN); +signal(SIGTTIN, SIG_IGN); +} +} + +void os_setup_post(void) +{ +int fd = 0; + +if (daemonize) { + uint8_t status = 0; + ssize_t len; + +again1: + len = write(fds[1], status, 1); + if (len == -1 (errno == EINTR)) + goto again1; + + if (len != 1) + exit(1); + +if (chdir(/)) { +perror(not able to chdir to /); +exit(1); +} + TFR(fd = qemu_open(/dev/null, O_RDWR)); + if (fd == -1) + exit(1); +} + +os_change_root(); +os_change_process_uid(); + +if (daemonize) { +dup2(fd, 0); +dup2(fd, 1); +dup2(fd, 2); + +close(fd); +} +} + +void os_pidfile_error(void) +{ +if (daemonize) { +uint8_t status = 1; +if (write(fds[1], status, 1) != 1) { +perror(daemonize. Writing to pipe\n); +} +} else +fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno)); +} diff --git a/os-win32.c b/os-win32.c index aefc535..d98fd77 100644 --- a/os-win32.c +++ b/os-win32.c @@ -214,3 +214,8 @@ void os_parse_cmd_args(int index, const char *optarg) { return; } + +void os_pidfile_error(void) +{ +fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno)); +} diff --git a/qemu-os-posix.h b/qemu-os-posix.h index ae9d5a8..96a1831 100644 --- a/qemu-os-posix.h +++ b/qemu-os-posix.h @@ -34,5 +34,7 @@ void os_setup_early_signal_handling(void); 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 3ce72cf..0e712d4 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -46,5 +46,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 d7aab40..a93572c 100644 --- a/sysemu.h +++ b/sysemu.h @@ -82,6 +82,7 @@ void do_info_slirp(Monitor *mon); /* OS specific functions */ char *os_find_datadir(const char *argv0); void os_parse_cmd_args(int index, const char *optarg); +void os_pidfile_error(void); typedef enum DisplayType { diff --git a/vl.c b/vl.c index fc0e23d..c22d16f 100644 --- a/vl.c +++ b/vl.c @@ -216,9 +216,6 @@ int no_shutdown = 0; int cursor_hide = 1; int graphic_rotate = 0; uint8_t irq0override = 1; -#ifndef _WIN32 -int daemonize = 0; -#endif const char *watchdog; const char *option_rom[MAX_OPTION_ROMS]; int nb_option_roms; @@ -2301,15 +2298,9 @@ int main(int argc, char **argv, char **envp) const char *loadvm = NULL; QEMUMachine *machine; const char *cpu_model; -#ifndef _WIN32 -int fds[2]; -#endif int
[Qemu-devel] [PATCH 15/17] Make os_change_process_uid and os_change_root os-posix.c local
From: Jes Sorensen jes.soren...@redhat.com os_change_process_uid() and os_change_root() are now only called from os-posix.c, so no need to keep win32 stubs for them. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c |8 qemu-os-posix.h |2 -- qemu-os-win32.h |2 -- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/os-posix.c b/os-posix.c index 1672e06..3a96c91 100644 --- a/os-posix.c +++ b/os-posix.c @@ -169,7 +169,7 @@ void os_parse_cmd_args(int index, const char *optarg) return; } -void os_change_process_uid(void) +static void change_process_uid(void) { if (user_pwd) { if (setgid(user_pwd-pw_gid) 0) { @@ -187,7 +187,7 @@ void os_change_process_uid(void) } } -void os_change_root(void) +static void change_root(void) { if (chroot_dir) { if (chroot(chroot_dir) 0) { @@ -276,8 +276,8 @@ void os_setup_post(void) exit(1); } -os_change_root(); -os_change_process_uid(); +change_root(); +change_process_uid(); if (daemonize) { dup2(fd, 0); diff --git a/qemu-os-posix.h b/qemu-os-posix.h index 96a1831..a791a36 100644 --- a/qemu-os-posix.h +++ b/qemu-os-posix.h @@ -32,8 +32,6 @@ static inline void os_host_main_loop_wait(int *timeout) void os_setup_early_signal_handling(void); 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 0e712d4..0a263c4 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -44,8 +44,6 @@ static inline void os_setup_early_signal_handling(void) {} 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 16/17] Move line-buffering setup to OS specific files.
From: Jes Sorensen jes.soren...@redhat.com Move line-buffering setup to OS specific files. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c |5 + qemu-os-posix.h |1 + qemu-os-win32.h |2 ++ vl.c|5 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/os-posix.c b/os-posix.c index 3a96c91..9bae8fe 100644 --- a/os-posix.c +++ b/os-posix.c @@ -298,3 +298,8 @@ void os_pidfile_error(void) } else fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno)); } + +void os_set_line_buffering(void) +{ +setvbuf(stdout, NULL, _IOLBF, 0); +} diff --git a/qemu-os-posix.h b/qemu-os-posix.h index a791a36..322fcbe 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_early_signal_handling(void); void os_setup_signal_handling(void); void os_daemonize(void); diff --git a/qemu-os-win32.h b/qemu-os-win32.h index 0a263c4..b65ddda 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -46,5 +46,7 @@ void os_host_main_loop_wait(int *timeout); static inline void os_setup_signal_handling(void) {} static inline void os_daemonize(void) {} static inline void os_setup_post(void) {} +/* Win32 doesn't support line-buffering and requires size = 2 */ +static inline void os_set_line_buffering(void) {} #endif diff --git a/vl.c b/vl.c index c22d16f..c3641d6 100644 --- a/vl.c +++ b/vl.c @@ -3214,10 +3214,7 @@ int main(int argc, char **argv, char **envp) exit(1); } -#ifndef _WIN32 -/* Win32 doesn't support line-buffering and requires size = 2 */ -setvbuf(stdout, NULL, _IOLBF, 0); -#endif +os_set_line_buffering(); if (init_timer_alarm() 0) { fprintf(stderr, could not initialize alarm timer\n); -- 1.6.5.2
[Qemu-devel] Re: [PATCH 2/5] vnc: JPEG should be disabled if the client don't set tight quality
On 04.06.2010, at 15:48, Corentin Chary wrote: The tight quality level is a slider on most clients. A user doesn't know when it starts being lossy. He also can only choose 0 as the lowest (iirc). And IIRC the X tightvnc client also always sent the quality level. Alex You can use -nojpeg for that. Most vnc clients have this options. Phew - I didn't even know of that option until now. I guess that's a bad sign? :) One way I thought of it was to start being lossy as of quality level 6 or so. That way people who accidently enable jpeg still know high quality means lossless. I'm not sure Anthony agrees on this though. Alex
[Qemu-devel] Re: [PATCH] Fix and simplify gui timer logic.
On 06/04/10 15:44, Gerd Hoffmann wrote: Kill nographic timer. Have a global gui_timer instead. Have the gui timer enabled unconditionally. We need a timer running anyway for mmio flush, so the whole have-gui-timer-only-when-needed logic is pretty pointless. It also simplifies displaylisteners coming and going at runtime, we don't need to care about the timer then as it runs anyway. Oops, scratch that. Doesn't apply cleanly on master due to dependencies on other local patches. /me goes preparing a patch series ... cheers, Gerd
[Qemu-devel] [PATCH 12/17] Move runas handling from vl.c to OS specific files.
From: Jes Sorensen jes.soren...@redhat.com Move code to handle runas, ie. change of user id of QEMU process to OS specific files and provide dummy stub for Win32. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c | 28 qemu-os-posix.h |1 + qemu-os-win32.h |1 + vl.c| 29 + 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/os-posix.c b/os-posix.c index 0deddf3..8b686a4 100644 --- a/os-posix.c +++ b/os-posix.c @@ -28,6 +28,7 @@ #include signal.h #include sys/types.h #include sys/wait.h +#include pwd.h #include libgen.h /* Needed early for CONFIG_BSD etc. */ @@ -36,6 +37,8 @@ #include net/slirp.h #include qemu-options.h +static struct passwd *user_pwd; + void os_setup_early_signal_handling(void) { struct sigaction act; @@ -146,6 +149,31 @@ void os_parse_cmd_args(int index, 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; } return; } + +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 41a4360..ecceb5e 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_early_signal_handling(void); 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 ee30ea9..eff0242 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -44,5 +44,6 @@ static inline void os_setup_early_signal_handling(void) {} 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 7c48024..5fa4c79 100644 --- a/vl.c +++ b/vl.c @@ -34,7 +34,6 @@ #ifndef _WIN32 #include libgen.h -#include pwd.h #include sys/times.h #include sys/wait.h #include termios.h @@ -2310,9 +2309,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; @@ -3060,9 +3057,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())) { @@ -3552,14 +3546,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); @@ -3571,20 +3557,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 05/17] Introduce os-posix.c and create os_setup_signal_handling()
From: Jes Sorensen jes.soren...@redhat.com Introcuce os-posix.c and move posix specific signal handling there. Add dummy stub for win32. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- Makefile.objs |1 + os-posix.c | 41 + qemu-os-posix.h |2 ++ qemu-os-win32.h |1 + vl.c|8 +--- 5 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 os-posix.c diff --git a/Makefile.objs b/Makefile.objs index 58fdb03..2d94677 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -145,6 +145,7 @@ hw-obj-$(CONFIG_NAND) += nand.o hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o hw-obj-$(CONFIG_WIN32) += os-win32.o +hw-obj-$(CONFIG_POSIX) += os-posix.o hw-obj-$(CONFIG_M48T59) += m48t59.o hw-obj-$(CONFIG_ESCC) += escc.o diff --git a/os-posix.c b/os-posix.c new file mode 100644 index 000..914a4d1 --- /dev/null +++ b/os-posix.c @@ -0,0 +1,41 @@ +/* + * os-posix.c + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2010 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include unistd.h +#include fcntl.h +#include signal.h + +/* Needed early for CONFIG_BSD etc. */ +#include config-host.h +#include sysemu.h + +void os_setup_signal_handling(void) +{ +struct sigaction act; +sigfillset(act.sa_mask); +act.sa_flags = 0; +act.sa_handler = SIG_IGN; +sigaction(SIGPIPE, act, NULL); +} diff --git a/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..74c7b4d 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -40,5 +40,6 @@ 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); +static inline void os_setup_signal_handling(void) {} void os_host_main_loop_wait(int *timeout); #endif 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
Re: [Qemu-devel] Re: [PATCH V3 1/3] qemu: Add qemu-wrappers for pthread_attr_t
On 06/04/2010 03:19 PM, Corentin Chary wrote: The point of these wrappers AFAIU is not only to add error_exit, but also to be portable to Windows in the future. This is historical because the code was largely inspired by glibc's implementation of posix-aio. It doesn't need to be detached and since Corentin wants to be able to join a worker, it makes sense to just avoid detaching and pay the overhead of making the threads joinable. Actually, I want to know if the queue is empty and if no job are currently being processed: all worker are idle or stopped. I don't really need pthread_join() for that, since worker can be idle (we don't want to always start and stop the thread :) ). Then it's also fine to have all qemu_threads detached (like in my patch to create all qemu_threads with blocked signals). I just want to avoid implementing pthreads one day for qemu-threads-win32.c. Paolo
[Qemu-devel] [PATCH 06/17] Move win32 early signal handling setup to os_setup_signal_handling()
From: Jes Sorensen jes.soren...@redhat.com Move win32 early signal handling setup to os_setup_signal_handling() Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-win32.c | 29 + vl.c | 30 -- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/os-win32.c b/os-win32.c index 1f7e28b..dfa90bc 100644 --- a/os-win32.c +++ b/os-win32.c @@ -152,3 +152,32 @@ void os_host_main_loop_wait(int *timeout) *timeout = 0; } + +static BOOL WINAPI qemu_ctrl_handler(DWORD type) +{ +exit(STATUS_CONTROL_C_EXIT); +return TRUE; +} + +void os_setup_signal_handling(void) +{ +/* Note: cpu_interrupt() is currently not SMP safe, so we force + QEMU to run on a single CPU */ +HANDLE h; +DWORD mask, smask; +int i; + +SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE); + +h = GetCurrentProcess(); +if (GetProcessAffinityMask(h, mask, smask)) { +for(i = 0; i 32; i++) { +if (mask (1 i)) +break; +} +if (i != 32) { +mask = 1 i; +SetProcessAffinityMask(h, mask); +} +} +} diff --git a/vl.c b/vl.c index 7a46fee..f43456a 100644 --- a/vl.c +++ b/vl.c @@ -1986,14 +1986,6 @@ static int balloon_parse(const char *arg) return -1; } -#ifdef _WIN32 -static BOOL WINAPI qemu_ctrl_handler(DWORD type) -{ -exit(STATUS_CONTROL_C_EXIT); -return TRUE; -} -#endif - #ifndef _WIN32 static void termsig_handler(int signal) @@ -2459,29 +2451,7 @@ int main(int argc, char **argv, char **envp) qemu_cache_utils_init(envp); QLIST_INIT (vm_change_state_head); -#ifndef _WIN32 os_setup_signal_handling(); -#else -SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE); -/* Note: cpu_interrupt() is currently not SMP safe, so we force - QEMU to run on a single CPU */ -{ -HANDLE h; -DWORD mask, smask; -int i; -h = GetCurrentProcess(); -if (GetProcessAffinityMask(h, mask, smask)) { -for(i = 0; i 32; i++) { -if (mask (1 i)) -break; -} -if (i != 32) { -mask = 1 i; -SetProcessAffinityMask(h, mask); -} -} -} -#endif module_call_init(MODULE_INIT_MACHINE); machine = find_default_machine(); -- 1.6.5.2
[Qemu-devel] [PATCH 17/17] Move set_proc_name() to OS specific files.
From: Jes Sorensen jes.soren...@redhat.com Move handling to change process name to POSIX specific files plus add a better error message to cover the case where the feature isn't supported. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c | 24 qemu-os-posix.h |1 + qemu-os-win32.h |1 + vl.c| 19 +-- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/os-posix.c b/os-posix.c index 9bae8fe..d89020d 100644 --- a/os-posix.c +++ b/os-posix.c @@ -37,6 +37,10 @@ #include net/slirp.h #include qemu-options.h +#ifdef CONFIG_LINUX +#include sys/prctl.h +#endif + static struct passwd *user_pwd; static const char *chroot_dir; static int daemonize; @@ -139,6 +143,26 @@ char *os_find_datadir(const char *argv0) #undef SHARE_SUFFIX #undef BUILD_SUFFIX +void os_set_proc_name(const char *s) +{ +#if defined(PR_SET_NAME) +char name[16]; +if (!s) +return; +name[sizeof(name) - 1] = 0; +strncpy(name, s, sizeof(name)); +/* Could rewrite argv[0] too, but that's a bit more complicated. + This simple way is enough for `top'. */ +if (prctl(PR_SET_NAME, name)) { +perror(unable to change process name); +exit(1); +} +#else +fprintf(stderr, Change of process name not supported by your OS\n); +exit(1); +#endif +} + /* * Parse OS specific command line options. * return 0 if option handled, -1 otherwise diff --git a/qemu-os-posix.h b/qemu-os-posix.h index 322fcbe..9387669 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_early_signal_handling(void); void os_setup_signal_handling(void); void os_daemonize(void); diff --git a/qemu-os-win32.h b/qemu-os-win32.h index b65ddda..7fa79f2 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -48,5 +48,6 @@ static inline void os_daemonize(void) {} static inline void os_setup_post(void) {} /* Win32 doesn't support line-buffering and requires size = 2 */ static inline void os_set_line_buffering(void) {} +static inline void os_set_proc_name(const char *dummy) {} #endif diff --git a/vl.c b/vl.c index c3641d6..ce501e2 100644 --- a/vl.c +++ b/vl.c @@ -59,7 +59,6 @@ #ifdef __linux__ #include pty.h #include malloc.h -#include sys/prctl.h #include linux/ppdev.h #include linux/parport.h @@ -284,22 +283,6 @@ static int default_driver_check(QemuOpts *opts, void *opaque) } /***/ - -static void set_proc_name(const char *s) -{ -#if defined(__linux__) defined(PR_SET_NAME) -char name[16]; -if (!s) -return; -name[sizeof(name) - 1] = 0; -strncpy(name, s, sizeof(name)); -/* Could rewrite argv[0] too, but that's a bit more complicated. - This simple way is enough for `top'. */ -prctl(PR_SET_NAME, name); -#endif -} - -/***/ /* real time host monotonic timer */ /* compute with 96 bit intermediate result: (a*b)/c */ @@ -2988,7 +2971,7 @@ int main(int argc, char **argv, char **envp) exit(1); } p += 8; - set_proc_name(p); + os_set_proc_name(p); } } break; -- 1.6.5.2
[Qemu-devel] [PATCH] [V4] 9p: readdir implementation for 9p2000.L
This patch implements the kernel part of readdir() implementation for 9p2000.L Change from V3: Instead of inode, server now sends qids for each dirent SYNOPSIS size[4] Treaddir tag[2] fid[4] offset[8] count[4] size[4] Rreaddir tag[2] count[4] data[count] DESCRIPTION The readdir request asks the server to read the directory specified by 'fid' at an offset specified by 'offset' and return as many dirent structures as possible that fit into count bytes. Each dirent structure is 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 offset[8] offset into the next dirent. type[1] type of this directory entry. name[256] name of this directory entry. This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L. This function sends P9_TREADDIR command to the server. In response the server sends a buffer filled with dirent structures. This is different from the existing v9fs_dir_readdir() call which receives stat structures from the server. This results in significant speedup of readdir() on large directories. For example, doing 'ls /dev/null' on a directory with 1 files on my laptop takes 1.088 seconds with the existing code, but only takes 0.339 seconds with the new readdir. Signed-off-by: Sripathi Kodi sripat...@in.ibm.com Reviewed-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com --- fs/9p/vfs_dir.c | 134 +-- include/net/9p/9p.h | 17 ++ include/net/9p/client.h | 18 ++ net/9p/client.c | 47 net/9p/protocol.c | 27 + 5 files changed, 227 insertions(+), 16 deletions(-) diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index d61e3b2..aa1852d 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf) } /** - * v9fs_dir_readdir - read a directory + * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir * @filp: opened file structure - * @dirent: directory structure ??? - * @filldir: function to populate directory structure ??? + * @buflen: Length in bytes of buffer to allocate * */ -static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) +static int v9fs_alloc_rdir_buf(struct file *filp, int buflen) { - int over; - struct p9_wstat st; - int err = 0; - struct p9_fid *fid; - int buflen; - int reclen = 0; struct p9_rdir *rdir; + struct p9_fid *fid; + int err = 0; - P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name); fid = filp-private_data; - - buflen = fid-clnt-msize - P9_IOHDRSZ; - - /* allocate rdir on demand */ if (!fid-rdir) { rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL); @@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) spin_unlock(filp-f_dentry-d_lock); kfree(rdir); } +exit: + return err; +} + +/** + * v9fs_dir_readdir - read a directory + * @filp: opened file structure + * @dirent: directory structure ??? + * @filldir: function to populate directory structure ??? + * + */ + +static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) +{ + int over; + struct p9_wstat st; + int err = 0; + struct p9_fid *fid; + int buflen; + int reclen = 0; + struct p9_rdir *rdir; + + P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name); + fid = filp-private_data; + + buflen = fid-clnt-msize - P9_IOHDRSZ; + + err = v9fs_alloc_rdir_buf(filp, buflen); + if (err) + goto exit; rdir = (struct p9_rdir *) fid-rdir; err = mutex_lock_interruptible(rdir-mutex); @@ -176,6 +196,88 @@ exit: return err; } +/** + * v9fs_dir_readdir_dotl - read a directory + * @filp: opened file structure + * @dirent: buffer to fill dirent structures + * @filldir: function to populate dirent structures + * + */ +static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent, + filldir_t filldir) +{ + int over; + int err = 0; + struct p9_fid *fid; + int buflen; + struct p9_rdir *rdir; + struct p9_dirent curdirent; + u64 oldoffset = 0; + + P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name); + fid = filp-private_data; + + buflen =
[Qemu-devel] [PATCH v2 2/2] vnc: threaded VNC server
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. The threaded VNC server can be enabled with ./configure --enable-vnc-thread. If you don't want it, just use ./configure --disable-vnc-thread and a syncrhonous queue of job will be used (which as exactly the same behavior as the old queue). If you disable the VNC thread, all thread related code will not be built and there will be no overhead. Signed-off-by: Corentin Chary corenti...@iksaif.net --- Makefile.objs |7 +- configure | 13 ++ ui/vnc-jobs-sync.c | 65 ++ ui/vnc-jobs.c | 351 ui/vnc.c | 169 ++ ui/vnc.h | 75 +++ 6 files changed, 657 insertions(+), 23 deletions(-) create mode 100644 ui/vnc-jobs-sync.c create mode 100644 ui/vnc-jobs.c diff --git a/Makefile.objs b/Makefile.objs index 22622a9..0c6334b 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -109,10 +109,15 @@ ui-obj-y += vnc-enc-tight.o ui-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o ui-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o ui-obj-$(CONFIG_COCOA) += cocoa.o +ifdef CONFIG_VNC_THREAD +ui-obj-y += vnc-jobs.o +else +ui-obj-y += vnc-jobs-sync.o +endif common-obj-y += $(addprefix ui/, $(ui-obj-y)) common-obj-y += iov.o acl.o -common-obj-$(CONFIG_IOTHREAD) += qemu-thread.o +common-obj-$(CONFIG_THREAD) += qemu-thread.o common-obj-y += notify.o event_notifier.o common-obj-y += qemu-timer.o diff --git a/configure b/configure index 679f2fc..6f2e3a7 100755 --- a/configure +++ b/configure @@ -264,6 +264,7 @@ vde= vnc_tls= vnc_sasl= vnc_jpeg= +vnc_thread= xen= linux_aio= vhost_net= @@ -552,6 +553,10 @@ for opt do ;; --enable-vnc-jpeg) vnc_jpeg=yes ;; + --disable-vnc-thread) vnc_thread=no + ;; + --enable-vnc-thread) vnc_thread=yes + ;; --disable-slirp) slirp=no ;; --disable-uuid) uuid=no @@ -786,6 +791,8 @@ echo --disable-vnc-sasl disable SASL encryption for VNC server echo --enable-vnc-saslenable SASL encryption for VNC server echo --disable-vnc-jpeg disable JPEG lossy compression for VNC server echo --enable-vnc-jpegenable JPEG lossy compression for VNC server +echo --disable-vnc-thread disable threaded VNC server +echo --enable-vnc-thread enable threaded VNC server echo --disable-curses disable curses output echo --enable-curses enable curses output echo --disable-curl disable curl connectivity @@ -2048,6 +2055,7 @@ echo Mixer emulation $mixemu echo VNC TLS support $vnc_tls echo VNC SASL support $vnc_sasl echo VNC JPEG support $vnc_jpeg +echo VNC thread$vnc_thread if test -n $sparc_cpu; then echo Target Sparc Arch $sparc_cpu fi @@ -2191,6 +2199,10 @@ if test $vnc_jpeg = yes ; then echo CONFIG_VNC_JPEG=y $config_host_mak echo VNC_JPEG_CFLAGS=$vnc_jpeg_cflags $config_host_mak fi +if test $vnc_thread = yes ; then + echo CONFIG_VNC_THREAD=y $config_host_mak + echo CONFIG_THREAD=y $config_host_mak +fi if test $fnmatch = yes ; then echo CONFIG_FNMATCH=y $config_host_mak fi @@ -2267,6 +2279,7 @@ if test $xen = yes ; then fi if test $io_thread = yes ; then echo CONFIG_IOTHREAD=y $config_host_mak + echo CONFIG_THREAD=y $config_host_mak fi if test $linux_aio = yes ; then echo CONFIG_LINUX_AIO=y $config_host_mak diff --git a/ui/vnc-jobs-sync.c b/ui/vnc-jobs-sync.c new file mode 100644 index 000..9f138f5 --- /dev/null +++ b/ui/vnc-jobs-sync.c @@ -0,0 +1,65 @@ +/* + * QEMU VNC display driver + * + * Copyright (C) 2006 Anthony Liguori anth...@codemonkey.ws + * Copyright (C) 2006 Fabrice Bellard + * Copyright (C) 2009 Red Hat, Inc + * Copyright (C) 2010 Corentin Chary corentin.ch...@gmail.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +
[Qemu-devel] [PATCH 09/17] Move find_datadir to OS specific files.
From: Jes Sorensen jes.soren...@redhat.com This moves the win32 and POSIX versions of find_datadir() to OS specific files, and removes some #ifdef clutter from vl.c Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c | 64 +++ os-win32.c | 23 ++ sysemu.h |3 ++ vl.c | 98 ++- 4 files changed, 94 insertions(+), 94 deletions(-) diff --git a/os-posix.c b/os-posix.c index 01dbec2..621ad06 100644 --- a/os-posix.c +++ b/os-posix.c @@ -28,6 +28,7 @@ #include signal.h #include sys/types.h #include sys/wait.h +#include libgen.h /* Needed early for CONFIG_BSD etc. */ #include config-host.h @@ -66,3 +67,66 @@ void os_setup_signal_handling(void) act.sa_flags = SA_NOCLDSTOP; sigaction(SIGCHLD, act, NULL); } + +/* Find a likely location for support files using the location of the binary. + For installed binaries this will be $bindir/../share/qemu. When + running from the build tree this will be $bindir/../pc-bios. */ +#define SHARE_SUFFIX /share/qemu +#define BUILD_SUFFIX /pc-bios +char *os_find_datadir(const char *argv0) +{ +char *dir; +char *p = NULL; +char *res; +char buf[PATH_MAX]; +size_t max_len; + +#if defined(__linux__) +{ +int len; +len = readlink(/proc/self/exe, buf, sizeof(buf) - 1); +if (len 0) { +buf[len] = 0; +p = buf; +} +} +#elif defined(__FreeBSD__) +{ +static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; +size_t len = sizeof(buf) - 1; + +*buf = '\0'; +if (!sysctl(mib, sizeof(mib)/sizeof(*mib), buf, len, NULL, 0) +*buf) { +buf[sizeof(buf) - 1] = '\0'; +p = buf; +} +} +#endif +/* If we don't have any way of figuring out the actual executable + location then try argv[0]. */ +if (!p) { +p = realpath(argv0, buf); +if (!p) { +return NULL; +} +} +dir = dirname(p); +dir = dirname(dir); + +max_len = strlen(dir) + +MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1; +res = qemu_mallocz(max_len); +snprintf(res, max_len, %s%s, dir, SHARE_SUFFIX); +if (access(res, R_OK)) { +snprintf(res, max_len, %s%s, dir, BUILD_SUFFIX); +if (access(res, R_OK)) { +qemu_free(res); +res = NULL; +} +} + +return res; +} +#undef SHARE_SUFFIX +#undef BUILD_SUFFIX diff --git a/os-win32.c b/os-win32.c index a936f7a..1758538 100644 --- a/os-win32.c +++ b/os-win32.c @@ -181,3 +181,26 @@ void os_setup_early_signal_handling(void) } } } + +/* Look for support files in the same directory as the executable. */ +char *os_find_datadir(const char *argv0) +{ +char *p; +char buf[MAX_PATH]; +DWORD len; + +len = GetModuleFileName(NULL, buf, sizeof(buf) - 1); +if (len == 0) { +return NULL; +} + +buf[len] = 0; +p = buf + len - 1; +while (p != buf *p != '\\') +p--; +*p = 0; +if (access(buf, R_OK) == 0) { +return qemu_strdup(buf); +} +return NULL; +} diff --git a/sysemu.h b/sysemu.h index 5e4feae..affcbea 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 */ +char *os_find_datadir(const char *argv0); + typedef enum DisplayType { DT_DEFAULT, 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}; -
[Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files.
From: Jes Sorensen jes.soren...@redhat.com Move host_main_loop_wait() to OS specific files. Create qemu-os-posix.h and provide empty inline for the POSIX case. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-win32.c | 43 +++ qemu-os-posix.h | 33 + qemu-os-win32.h |1 + sysemu.h|4 vl.c| 52 +--- 5 files changed, 82 insertions(+), 51 deletions(-) create mode 100644 qemu-os-posix.h diff --git a/os-win32.c b/os-win32.c index 5a464cc..1f7e28b 100644 --- a/os-win32.c +++ b/os-win32.c @@ -109,3 +109,46 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) if (found) w-num--; } + +void os_host_main_loop_wait(int *timeout) +{ +int ret, ret2, i; +PollingEntry *pe; + +/* XXX: need to suppress polling by better using win32 events */ +ret = 0; +for(pe = first_polling_entry; pe != NULL; pe = pe-next) { +ret |= pe-func(pe-opaque); +} +if (ret == 0) { +int err; +WaitObjects *w = wait_objects; + +ret = WaitForMultipleObjects(w-num, w-events, FALSE, *timeout); +if (WAIT_OBJECT_0 + 0 = ret ret = WAIT_OBJECT_0 + w-num - 1) { +if (w-func[ret - WAIT_OBJECT_0]) +w-func[ret - WAIT_OBJECT_0](w-opaque[ret - WAIT_OBJECT_0]); + +/* Check for additional signaled events */ +for(i = (ret - WAIT_OBJECT_0 + 1); i w-num; i++) { + +/* Check if event is signaled */ +ret2 = WaitForSingleObject(w-events[i], 0); +if(ret2 == WAIT_OBJECT_0) { +if (w-func[i]) +w-func[i](w-opaque[i]); +} else if (ret2 == WAIT_TIMEOUT) { +} else { +err = GetLastError(); +fprintf(stderr, WaitForSingleObject error %d %d\n, i, err); +} +} +} else if (ret == WAIT_TIMEOUT) { +} else { +err = GetLastError(); +fprintf(stderr, WaitForMultipleObjects error %d %d\n, ret, err); +} +} + +*timeout = 0; +} diff --git a/qemu-os-posix.h b/qemu-os-posix.h new file mode 100644 index 000..96d1036 --- /dev/null +++ b/qemu-os-posix.h @@ -0,0 +1,33 @@ +/* + * posix specific declarations + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2010 Jes Sorensen jes.soren...@redhat.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the Software), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef QEMU_OS_POSIX_H +#define QEMU_OS_POSIX_H + +static inline void os_host_main_loop_wait(int *timeout) +{ +} + +#endif diff --git a/qemu-os-win32.h b/qemu-os-win32.h index be108ad..4d1cac8 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -40,4 +40,5 @@ typedef void WaitObjectFunc(void *opaque); int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); +void os_host_main_loop_wait(int *timeout); #endif diff --git a/sysemu.h b/sysemu.h index 13fc9a9..5e4feae 100644 --- a/sysemu.h +++ b/sysemu.h @@ -12,6 +12,10 @@ #include qemu-os-win32.h #endif +#ifdef CONFIG_POSIX +#include qemu-os-posix.h +#endif + /* vl.c */ extern const char *bios_name; diff --git a/vl.c b/vl.c index afbb26c..c655582 100644 --- a/vl.c +++ b/vl.c @@ -1722,56 +1722,6 @@ void qemu_system_powerdown_request(void) qemu_notify_event(); } -#ifdef _WIN32 -static void host_main_loop_wait(int *timeout) -{ -int ret, ret2, i; -PollingEntry *pe; - - -/* XXX: need to suppress polling by better using win32 events */ -ret = 0; -for(pe = first_polling_entry; pe != NULL; pe = pe-next) { -ret |= pe-func(pe-opaque); -} -if (ret == 0) { -int err; -WaitObjects *w = wait_objects; - -ret =
[Qemu-devel] Re: [PATCH 00/17] *** SUBJECT HERE ***
On 06/04/10 15:24, jes.soren...@redhat.com wrote: From: Jes Sorensen jes.soren...@redhat.com *** BLURB HERE *** ARGH, someone needs to learn about temp files please ignore this one :(
[Qemu-devel] [PATCH 2/2] machine: pass all init options as a single QemuOpts
The current method of passing arguments to machine init functions is haphazard. We pass some arguments as via the init function. We pass a lot of other arguments as global variables some that are supported by a lot of boards and others that are only supported by one board. It's very difficult to introduce new parameters in the function signature because of the number of files that have to be touched. There is no central way to tie all of the machine options into the configuration file. This patch redefines the machine init signature to just take a QemuOpts. It also passes the machine as the first parameter to allow multiple boards to be defined with one init function. Signed-off-by: Anthony Liguori aligu...@us.ibm.com diff --git a/hw/an5206.c b/hw/an5206.c index f584d88..dfc4cce 100644 --- a/hw/an5206.c +++ b/hw/an5206.c @@ -29,11 +29,11 @@ void irq_info(Monitor *mon) /* Board init. */ -static void an5206_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) +static void an5206_init(QEMUMachine *machine, QemuOpts *opts) { +ram_addr_t ram_size = qemu_opt_get_number(opts, ram_size, 0); +const char *kernel_filename = qemu_opt_get(opts, kernel); +const char *cpu_model = qemu_opt_get(opts, cpu); CPUState *env; int kernel_size; uint64_t elf_entry; diff --git a/hw/axis_dev88.c b/hw/axis_dev88.c index 7d59c96..c0ce621 100644 --- a/hw/axis_dev88.c +++ b/hw/axis_dev88.c @@ -264,11 +264,12 @@ static uint64_t translate_kernel_address(void *opaque, uint64_t addr) } static -void axisdev88_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) +void axisdev88_init (QEMUMachine *machine, QemuOpts *opts) { +ram_addr_t ram_size = qemu_opt_get_number(opts, ram_size, 0); +const char *kernel_filename = qemu_opt_get(opts, kernel); +const char *kernel_cmdline = qemu_opt_get(opts, cmdline); +const char *cpu_model = qemu_opt_get(opts, cpu); CPUState *env; DeviceState *dev; SysBusDevice *s; diff --git a/hw/boards.h b/hw/boards.h index 6f0f0d7..59b0b4d 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -5,14 +5,11 @@ #include qdev.h -typedef void QEMUMachineInitFunc(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); - -typedef struct QEMUMachine { +typedef struct QEMUMachine QEMUMachine; + +typedef void QEMUMachineInitFunc(QEMUMachine *machine, QemuOpts *opts); + +struct QEMUMachine { const char *name; const char *alias; const char *desc; @@ -29,7 +26,7 @@ typedef struct QEMUMachine { int is_default; GlobalProperty *compat_props; struct QEMUMachine *next; -} QEMUMachine; +}; int qemu_register_machine(QEMUMachine *m); diff --git a/hw/dummy_m68k.c b/hw/dummy_m68k.c index 9c9e6ff..a249aa7 100644 --- a/hw/dummy_m68k.c +++ b/hw/dummy_m68k.c @@ -16,11 +16,11 @@ /* Board init. */ -static void dummy_m68k_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) +static void dummy_m68k_init(QEMUMachine *machine, QemuOpts *opts) { +ram_addr_t ram_size = qemu_opt_get_number(opts, ram_size, 0); +const char *kernel_filename = qemu_opt_get(opts, kernel); +const char *cpu_model = qemu_opt_get(opts, cpu); CPUState *env; int kernel_size; uint64_t elf_entry; diff --git a/hw/etraxfs.c b/hw/etraxfs.c index b88d00a..a9c5cf4 100644 --- a/hw/etraxfs.c +++ b/hw/etraxfs.c @@ -50,11 +50,12 @@ static uint64_t translate_kernel_address(void *opaque, uint64_t addr) } static -void bareetraxfs_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) +void bareetraxfs_init (QEMUMachine *machine, QemuOpts *opts) { +ram_addr_t ram_size = qemu_opt_get_number(opts, ram_size, 0); +const char *kernel_filename = qemu_opt_get(opts, kernel); +const char *kernel_cmdline = qemu_opt_get(opts, cmdline); +const char *cpu_model = qemu_opt_get(opts, cpu); DeviceState *dev; SysBusDevice *s; CPUState *env; diff --git a/hw/gumstix.c b/hw/gumstix.c index b64e04e..c85d690 100644 --- a/hw/gumstix.c +++ b/hw/gumstix.c @@ -41,10 +41,7 @@ static const int
[Qemu-devel] [PATCH 13/17] Move chroot handling to OS specific files.
From: Jes Sorensen jes.soren...@redhat.com Move chroot handling to OS specific files. Signed-off-by: Jes Sorensen jes.soren...@redhat.com --- os-posix.c | 19 +++ qemu-os-posix.h |1 + qemu-os-win32.h |1 + vl.c| 18 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/os-posix.c b/os-posix.c index 8b686a4..6417d16 100644 --- a/os-posix.c +++ b/os-posix.c @@ -38,6 +38,7 @@ #include qemu-options.h static struct passwd *user_pwd; +static const char *chroot_dir; void os_setup_early_signal_handling(void) { @@ -156,6 +157,9 @@ void os_parse_cmd_args(int index, const char *optarg) exit(1); } break; +case QEMU_OPTION_chroot: +chroot_dir = optarg; +break; } return; } @@ -177,3 +181,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 ecceb5e..ae9d5a8 100644 --- a/qemu-os-posix.h +++ b/qemu-os-posix.h @@ -33,5 +33,6 @@ static inline void os_host_main_loop_wait(int *timeout) void os_setup_early_signal_handling(void); 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 eff0242..3ce72cf 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -45,5 +45,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 5fa4c79..fc0e23d 100644 --- a/vl.c +++ b/vl.c @@ -2309,7 +2309,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; @@ -3053,11 +3052,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); @@ -3546,17 +3540,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] [V4] virtio-9p: readdir implementation for 9p2000.L
This patch implements the server part of readdir() implementation for 9p2000.L Change from V3: Instead of inode, server now sends qids for each dirent SYNOPSIS size[4] Treaddir tag[2] fid[4] offset[8] count[4] size[4] Rreaddir tag[2] count[4] data[count] DESCRIPTION The readdir request asks the server to read the directory specified by 'fid' at an offset specified by 'offset' and return as many dirent structures as possible that fit into count bytes. Each dirent structure is 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 offset[8] offset into the next dirent. type[1] type of this directory entry. name[256] name of this directory entry. Signed-off-by: Sripathi Kodi sripat...@in.ibm.com Reviewed-by: M. Mohan Kumar mo...@in.ibm.com Reviewed-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com --- hw/virtio-9p-debug.c | 13 + hw/virtio-9p.c | 119 ++ hw/virtio-9p.h |2 + 3 files changed, 134 insertions(+), 0 deletions(-) diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c index 2fb2673..a82b771 100644 --- a/hw/virtio-9p-debug.c +++ b/hw/virtio-9p-debug.c @@ -328,6 +328,19 @@ void pprint_pdu(V9fsPDU *pdu) } switch (pdu-id) { +case P9_TREADDIR: +fprintf(llogfile, TREADDIR: (); +pprint_int32(pdu, 0, offset, fid); +pprint_int64(pdu, 0, offset, , initial offset); +pprint_int32(pdu, 0, offset, , max count); +break; +case P9_RREADDIR: +fprintf(llogfile, RREADDIR: (); +pprint_int32(pdu, 1, offset, count); +#ifdef DEBUG_DATA +pprint_data(pdu, 1, offset, , data); +#endif +break; case P9_TVERSION: fprintf(llogfile, TVERSION: (); pprint_int32(pdu, 0, offset, msize); diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c index 2d1cbd5..9c7e256 100644 --- a/hw/virtio-9p.c +++ b/hw/virtio-9p.c @@ -1583,6 +1583,124 @@ out: qemu_free(vs); } +typedef struct V9fsReadDirState { +V9fsPDU *pdu; +V9fsFidState *fidp; +V9fsQID qid; +off_t saved_dir_pos; +struct dirent *dent; +int32_t count; +int32_t max_count; +size_t offset; +int64_t initial_offset; +V9fsString name; +} V9fsReadDirState; + +static void v9fs_readdir_post_seekdir(V9fsState *s, V9fsReadDirState *vs) +{ +vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count); +vs-offset += vs-count; +complete_pdu(s, vs-pdu, vs-offset); +qemu_free(vs); +return; +} + +/* Size of each dirent on the wire: size of qid (13) + size of offset (8) + * size of type (1) + size of name.size (2) + strlen(name.data) + */ +#define V9_READDIR_DATA_SZ (24 + strlen(vs-name.data)) + +static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs) +{ +int len; +size_t size; + +if (vs-dent) { +v9fs_string_init(vs-name); +v9fs_string_sprintf(vs-name, %s, vs-dent-d_name); + +if ((vs-count + V9_READDIR_DATA_SZ) vs-max_count) { +/* Ran out of buffer. Set dir back to old position and return */ +v9fs_do_seekdir(s, vs-fidp-dir, vs-saved_dir_pos); +v9fs_readdir_post_seekdir(s, vs); +return; +} + +/* Fill up just the path field of qid because the client uses + * only that. To fill the entire qid structure we will have + * to stat each dirent found, which is expensive + */ +size = MIN(sizeof(vs-dent-d_ino), sizeof(vs-qid.path)); +memcpy(vs-qid.path, vs-dent-d_ino, size); + +len = pdu_marshal(vs-pdu, vs-offset+4+vs-count, Qqbs, + vs-qid, vs-dent-d_off, + vs-dent-d_type, vs-name); +vs-count += len; +v9fs_string_free(vs-name); +vs-saved_dir_pos = vs-dent-d_off; +vs-dent = v9fs_do_readdir(s, vs-fidp-dir); +v9fs_readdir_post_readdir(s, vs); +return; +} + +vs-offset += pdu_marshal(vs-pdu, vs-offset, d, vs-count); +vs-offset += vs-count; +complete_pdu(s, vs-pdu, vs-offset); +qemu_free(vs); +return; +} + +static void v9fs_readdir_post_telldir(V9fsState *s, V9fsReadDirState *vs) +{ +vs-dent = v9fs_do_readdir(s, vs-fidp-dir); +v9fs_readdir_post_readdir(s, vs); +return; +} + +static void v9fs_readdir_post_setdir(V9fsState *s, V9fsReadDirState *vs) +{ +vs-saved_dir_pos = v9fs_do_telldir(s, vs-fidp-dir); +v9fs_readdir_post_telldir(s, vs); +return; +} + +static void v9fs_readdir(V9fsState *s, V9fsPDU *pdu) +{ +
[Qemu-devel] [PATCH] [V4] 9p: readdir implementation for 9p2000.L
This patch implements the kernel part of readdir() implementation for 9p2000.L Change from V3: Instead of inode, server now sends qids for each dirent SYNOPSIS size[4] Treaddir tag[2] fid[4] offset[8] count[4] size[4] Rreaddir tag[2] count[4] data[count] DESCRIPTION The readdir request asks the server to read the directory specified by 'fid' at an offset specified by 'offset' and return as many dirent structures as possible that fit into count bytes. Each dirent structure is 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 offset[8] offset into the next dirent. type[1] type of this directory entry. name[256] name of this directory entry. This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L. This function sends P9_TREADDIR command to the server. In response the server sends a buffer filled with dirent structures. This is different from the existing v9fs_dir_readdir() call which receives stat structures from the server. This results in significant speedup of readdir() on large directories. For example, doing 'ls /dev/null' on a directory with 1 files on my laptop takes 1.088 seconds with the existing code, but only takes 0.339 seconds with the new readdir. Signed-off-by: Sripathi Kodi sripat...@in.ibm.com Reviewed-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com --- fs/9p/vfs_dir.c | 134 +-- include/net/9p/9p.h | 17 ++ include/net/9p/client.h | 18 ++ net/9p/client.c | 47 net/9p/protocol.c | 27 + 5 files changed, 227 insertions(+), 16 deletions(-) diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c index d61e3b2..aa1852d 100644 --- a/fs/9p/vfs_dir.c +++ b/fs/9p/vfs_dir.c @@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf) } /** - * v9fs_dir_readdir - read a directory + * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir * @filp: opened file structure - * @dirent: directory structure ??? - * @filldir: function to populate directory structure ??? + * @buflen: Length in bytes of buffer to allocate * */ -static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) +static int v9fs_alloc_rdir_buf(struct file *filp, int buflen) { - int over; - struct p9_wstat st; - int err = 0; - struct p9_fid *fid; - int buflen; - int reclen = 0; struct p9_rdir *rdir; + struct p9_fid *fid; + int err = 0; - P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name); fid = filp-private_data; - - buflen = fid-clnt-msize - P9_IOHDRSZ; - - /* allocate rdir on demand */ if (!fid-rdir) { rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL); @@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) spin_unlock(filp-f_dentry-d_lock); kfree(rdir); } +exit: + return err; +} + +/** + * v9fs_dir_readdir - read a directory + * @filp: opened file structure + * @dirent: directory structure ??? + * @filldir: function to populate directory structure ??? + * + */ + +static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) +{ + int over; + struct p9_wstat st; + int err = 0; + struct p9_fid *fid; + int buflen; + int reclen = 0; + struct p9_rdir *rdir; + + P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name); + fid = filp-private_data; + + buflen = fid-clnt-msize - P9_IOHDRSZ; + + err = v9fs_alloc_rdir_buf(filp, buflen); + if (err) + goto exit; rdir = (struct p9_rdir *) fid-rdir; err = mutex_lock_interruptible(rdir-mutex); @@ -176,6 +196,88 @@ exit: return err; } +/** + * v9fs_dir_readdir_dotl - read a directory + * @filp: opened file structure + * @dirent: buffer to fill dirent structures + * @filldir: function to populate dirent structures + * + */ +static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent, + filldir_t filldir) +{ + int over; + int err = 0; + struct p9_fid *fid; + int buflen; + struct p9_rdir *rdir; + struct p9_dirent curdirent; + u64 oldoffset = 0; + + P9_DPRINTK(P9_DEBUG_VFS, name %s\n, filp-f_path.dentry-d_name.name); + fid = filp-private_data; + + buflen =
[Qemu-devel] Re: RFC: blockdev_add friends, brief rationale, QMP docs
Discussion with Christoph and Kevin uncovered yet another issue: protocols. I find it pretty confusing, but let me try to describe it anyway; Christoph and Kevin, please correct my errors. A host block device has a format. A format has a name. Below the format, it has a stack of protocols. A protocol has a name (with one exception), and may have protocol-specific arguments. The most basic (and most commonly used) protocol is for accessing a file. Its argument is a file name. It doesn't have a name. Which makes for ugly prose, so I'll call it file. Stacking protocols is somewhat exotic. Think of stacking blkdebug on top of another protocol, say nbd. Our abstraction for formats is struct BlockDriver. Our abstraction for protocols is also struct BlockDriver. Except for the special protocol file, but that's detail. Examples: -drive file=foo.qcow2,format=qcow2 Format qcow2, protocol file with argument filename foo.img -drive file=nbd:unix:/tmp/my_socket,format=raw Format raw, protocol nbd with arguments domain unix, filename /tmp/my_socket -drive blkdebug:/tmp/blkdebug.cfg:fat:floppy:rw:/tmp/dir Format not specified (system guesses one), protocol blkdebug with argument filename /tmp/blkdebug.cfg stacked onto protocol fat with arguments floppy true, dirname /tmp/dir You see that -drive has a separate option for format, but has protocols encoded in option file, in their own mini-language. Doesn't work for arbitrary filenames. Besides, mini-languages to encode options in strings are quite inappropriate for QMP. So we need something cleaner for QMP. Here's a sketch. Instead of - file: the disk image file to use (json-string, optional) - format: disk format (json-string, optional) - Possible values: raw, qcow2, ... have - format: disk format (json-string, optional) - Possible values: raw, qcow2, ... - protocol: json-array of json-object Each element object has a member name - Possible values: file, nbd, ... Additional members depend on the value of name. For name = file: - file: file name (json-string) For name = nbd: - domain: address family (json-string, optional) - Possible values: inet (default), unix - file: file name (json-string), only with domain = unix - host: host name (json-string), only with domain = inet - port: port (json-int), only with domain = inet ... You get the idea. Comments?
[Qemu-devel] [PATCH 1/2] machine: package all init arguments into a QemuOpts
This patch creates a QemuOpts structure and stores all of the machine init arguments in that structure. It introduces a temporary list of QemuOptDescs in vl.c such that the current common options can be validated. The long term vision is that that list becomes a #define and that each machine can optionally provide it's own QemuOptDescs list using the common options as a base. This enables per-machine options. Signed-off-by: Anthony Liguori aligu...@us.ibm.com diff --git a/qemu-config.c b/qemu-config.c index 5a4e61b..3679a9f 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -336,6 +336,14 @@ QemuOptsList qemu_cpudef_opts = { }, }; +QemuOptsList qemu_machine_opts = { +.name = machine, +.head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), +.desc = { +{ /* end of list */ } +}, +}; + static QemuOptsList *vm_config_groups[] = { qemu_drive_opts, qemu_chardev_opts, @@ -346,6 +354,7 @@ static QemuOptsList *vm_config_groups[] = { qemu_global_opts, qemu_mon_opts, qemu_cpudef_opts, +qemu_machine_opts, NULL, }; diff --git a/qemu-config.h b/qemu-config.h index dca69d4..6f52188 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -14,6 +14,7 @@ extern QemuOptsList qemu_rtc_opts; extern QemuOptsList qemu_global_opts; extern QemuOptsList qemu_mon_opts; extern QemuOptsList qemu_cpudef_opts; +extern QemuOptsList qemu_machine_opts; QemuOptsList *qemu_find_opts(const char *group); int qemu_set_option(const char *str); diff --git a/vl.c b/vl.c index 7121cd0..d362fc0 100644 --- a/vl.c +++ b/vl.c @@ -2550,6 +2550,35 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } +/* TEMP: until we have proper -machine support */ +static QemuOptDesc common_machine_opts[] = { +{ +.name = ram_size, +.type = QEMU_OPT_NUMBER, +}, +{ +.name = kernel, +.type = QEMU_OPT_STRING, +}, +{ +.name = cmdline, +.type = QEMU_OPT_STRING, +}, +{ +.name = initrd, +.type = QEMU_OPT_STRING, +}, +{ +.name = boot_device, +.type = QEMU_OPT_STRING, +}, +{ +.name = cpu_model, +.type = QEMU_OPT_STRING, +}, +{ /* end of list */ }, +}; + int main(int argc, char **argv, char **envp) { const char *gdbstub_dev = NULL; @@ -3718,8 +3747,42 @@ int main(int argc, char **argv, char **envp) } qemu_add_globals(); -machine-init(ram_size, boot_devices, - kernel_filename, kernel_cmdline, initrd_filename, cpu_model); +opts = qemu_opts_create(qemu_machine_opts, NULL, 0); +if (kernel_filename) { +qemu_opt_set(opts, kernel, kernel_filename); +if (kernel_cmdline) { +qemu_opt_set(opts, cmdline, kernel_cmdline); +} +if (initrd_filename) { +qemu_opt_set(opts, initrd, initrd_filename); +} +} + +qemu_opt_set(opts, boot_device, boot_devices); + +if (cpu_model) { +qemu_opt_set(opts, cpu_model, cpu_model); +} + +if (ram_size) { +char buffer[64]; +snprintf(buffer, sizeof(buffer), + % PRId64, ram_size); +qemu_opt_set(opts, ram_size, buffer); +} + +if (qemu_opts_validate(opts, common_machine_opts) 0) { +exit(1); +} + +machine-init(qemu_opt_get_number(opts, ram_size), + qemu_opt_get(opts, boot_device), + qemu_opt_get(opts, kernel), + qemu_opt_get(opts, cmdline), + qemu_opt_get(opts, initrd), + qemu_opt_get(opts, cpu_model)); + +qemu_opts_del(opts); cpu_synchronize_all_post_init(); -- 1.7.0.4
[Qemu-devel] [RFC] QMP: Introduce query-netdevices documentation
This introduces the protocol specification for querying information about network devices available on a VM and a new monitor command that show the same information. Signed-off-by: Miguel Di Ciurcio Filho miguel.fi...@gmail.com --- qemu-monitor.hx | 69 +++ 1 files changed, 69 insertions(+), 0 deletions(-) diff --git a/qemu-monitor.hx b/qemu-monitor.hx index f6a94f2..8600129 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -1674,6 +1674,75 @@ show the various VLANs and the associated devices ETEXI STEXI +...@item info netdevices +show information about network devices +ETEXI +SQMP +query-netdevices + + +Each device is represented by a json-object. The returned value is a json-array +of all devices. + +Each json-object contain the following: + +- device: device name (json-string) +- vlan: only present if the device is attached to a VLAN (json-int) +- info: json-object containing the following: + - model: type of the device (json-string) + - Possible values: tap, socket, xen, slirp, dump, + vde, ne2k_pci, i82551, i82557b, + i82559er, rtl8139, e1000, pcnet, + virtio, dp83932, lan9118, mcf_fec, + xilinx-ethlite, lance, stellaris, + smc91c111, ne2k_isa, mv88w8618, + mipsnet, fseth, dp83932, usb + - macaddr: MAC address, only present if the device is a NIC +(json-string) + - script: path to script used to configure the device, only present +if model is tap (json-string) + - downscript: path to script used to deconfigure the device, only +present if model is tap (json-string) + - fd: handle to the device, only present if model is vde +(json-int) + - ifname: name of the host device connected to the guest device, +only present if model is tap (json-string) + - host: IP address, only present if model is socket +(json-string) + - service: port number, only present if model is socket + - family: address familyi, only present if model is socket +(json-string) +- Possible values: ipv4 + +Example: + +- { execute: query-netdevices } +- { + return: [ + { +device: tap.0, +vlan: 0, +info: { + script: /etc/kvm/kvm-ifup, + downscript: /etc/qemu-ifdown, + ifname: tap0, + model: tap +}, + }, + { + device: e1000.0, + vlan: 0, + info: { + model: e1000, + macaddr: 52:54:00:12:34:56 + }, + } + ] + } + +EQMP + +STEXI @item info chardev show the character devices ETEXI -- 1.7.1
[Qemu-devel] Re: [PATCH 2/5] vnc: JPEG should be disabled if the client don't set tight quality
The tight quality level is a slider on most clients. A user doesn't know when it starts being lossy. He also can only choose 0 as the lowest (iirc). And IIRC the X tightvnc client also always sent the quality level. Alex You can use -nojpeg for that. Most vnc clients have this options. -- Corentin Chary http://xf.iksaif.net
[Qemu-devel] Re: [PATCH 4/5] ui: move all ui components in ui/
On Fri, Jun 4, 2010 at 3:18 PM, Alexander Graf ag...@suse.de wrote: On 04.06.2010, at 15:18, Corentin Chary wrote: Move sdl, vnc, curses and cocoa UI into ui/ to cleanup the root directory. Also remove some unnecessary explicit targets from Makefile. There's a magic command to tell git to indicate moves as moves. I guess that'd be a good idea here :) Alex Hum .. right. -- Corentin Chary http://xf.iksaif.net
[Qemu-devel] Re: [PATCH v2 2/2] vnc: threaded VNC server
On 04.06.2010, at 15:20, 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. Hrm, does it merge the queue? So imagine the following gets put in the queue [0,0] - [100,100] [100,0] - [200,10] [0,0] - [200,10] Would that code try and merge those three queue entries? Because by adding the queue, you basically get rid of the automatic merging we get from the lazy dirty bitmap fetching. Before we were processing each entry and checked the bitmap again, seeing a merged bitmap of previous actions. With this I assume you push to-be-updated regions into the queue and mark them as processed before they are? Or does the processed marking still happen in the worker? Wouldn't that be racy? Hrm. Alex
[Qemu-devel] Re: [PATCH v3] savevm: Really verify if a drive supports snapshots
Am 03.06.2010 21:52, schrieb 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 miguel.fi...@gmail.com Thanks, applied to the block branch. Kevin
[Qemu-devel] Re: [PATCH 2/5] vnc: JPEG should be disabled if the client don't set tight quality
Phew - I didn't even know of that option until now. I guess that's a bad sign? :) One way I thought of it was to start being lossy as of quality level 6 or so. That way people who accidently enable jpeg still know high quality means lossless. I'm not sure Anthony agrees on this though. Alex If client set a quality it means that we are allowed to send something lossy. If you don't want this behavior, you can add the lossless (or lossy) parameter :). -- Corentin Chary http://xf.iksaif.net
[Qemu-devel] Re: RFC: blockdev_add friends, brief rationale, QMP docs
Am 04.06.2010 16:16, schrieb Markus Armbruster: Discussion with Christoph and Kevin uncovered yet another issue: protocols. I find it pretty confusing, but let me try to describe it anyway; Christoph and Kevin, please correct my errors. A host block device has a format. A format has a name. Below the format, it has a stack of protocols. A protocol has a name (with one exception), and may have protocol-specific arguments. The most basic (and most commonly used) protocol is for accessing a file. Its argument is a file name. It doesn't have a name. Which makes for ugly prose, so I'll call it file. It does have a name, and surprisingly it's called file indeed (defined at block/raw-posix.c:744 for Linux). Stacking protocols is somewhat exotic. Think of stacking blkdebug on top of another protocol, say nbd. Considering that file is a protocol as well as nbd, it's any blkdebug use that uses protocol stacking and therefore not that exotic - even though not the most common case, of course. Our abstraction for formats is struct BlockDriver. Our abstraction for protocols is also struct BlockDriver. Except for the special protocol file, but that's detail. See above, file isn't really special. Examples: -drive file=foo.qcow2,format=qcow2 Format qcow2, protocol file with argument filename foo.img Actually the protocol is guessed here. For this, not all protocols are considered, it's only between file/host_device/host_cdrom/host_floppy (these are the protocols implementing bdrv_probe_device, and file as the default if no other protocol feels responsible) -drive file=nbd:unix:/tmp/my_socket,format=raw Format raw, protocol nbd with arguments domain unix, filename /tmp/my_socket -drive blkdebug:/tmp/blkdebug.cfg:fat:floppy:rw:/tmp/dir Format not specified (system guesses one), protocol blkdebug with argument filename /tmp/blkdebug.cfg stacked onto protocol fat with arguments floppy true, dirname /tmp/dir These look right to me. You see that -drive has a separate option for format, but has protocols encoded in option file, in their own mini-language. Doesn't work for arbitrary filenames. Besides, mini-languages to encode options in strings are quite inappropriate for QMP. So we need something cleaner for QMP. Here's a sketch. Instead of - file: the disk image file to use (json-string, optional) - format: disk format (json-string, optional) - Possible values: raw, qcow2, ... have - format: disk format (json-string, optional) - Possible values: raw, qcow2, ... - protocol: json-array of json-object Each element object has a member name - Possible values: file, nbd, ... Additional members depend on the value of name. For name = file: - file: file name (json-string) For name = nbd: - domain: address family (json-string, optional) - Possible values: inet (default), unix - file: file name (json-string), only with domain = unix - host: host name (json-string), only with domain = inet - port: port (json-int), only with domain = inet ... You get the idea. Comments? Makes sense. So blkdebug would define a field protocol (json-object) that it uses to initialize the underlying protocol and we would get the stacking this way? Kevin
[Qemu-devel] Re: [PATCH 1/2] [scsi-bus]: Add PR-OUT and PR-IN case for SCSIRequest xfer and xfer_mode setup
Am 31.05.2010 03:43, schrieb Nicholas A. Bellinger: From: Nicholas Bellinger n...@linux-iscsi.org This patch updates hw/scsi-bus.c to add PERSISTENT_RESERVE_OUT and PERSISTENT_RESERVE_IN case in scsi_req_length() to extra the incoming buffer length into SCSIRequest-cmd.xfer, and adds a second PERSISTENT_RESERVE_OUT case in scsi_req_xfer_mode() in order to properly set SCSI_XFER_TO_DEV for WRITE data. Tested with Linux KVM guests and Megasas 8708EM2 HBA emulation and TCM_Loop target ports. Signed-off-by: Nicholas A. Bellinger n...@linux-iscsi.org --- hw/scsi-bus.c |5 + 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index b8e4b71..75ec74e 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -325,6 +325,10 @@ static int scsi_req_length(SCSIRequest *req, uint8_t *cmd) case INQUIRY: req-cmd.xfer = cmd[4] | (cmd[3] 8); break; +case PERSISTENT_RESERVE_OUT: +case PERSISTENT_RESERVE_IN: +req-cmd.xfer = cmd[8] | (cmd[7] 8); Maybe I'm missing something, but isn't exactly the same value set in the switch block above? (for cmd[0] 5 == 2) Kevin
[Qemu-devel] Re: [PATCH 1/2] machine: package all init arguments into a QemuOpts
On 06/04/2010 09:11 AM, Anthony Liguori wrote: This patch creates a QemuOpts structure and stores all of the machine init arguments in that structure. It introduces a temporary list of QemuOptDescs in vl.c such that the current common options can be validated. The long term vision is that that list becomes a #define and that each machine can optionally provide it's own QemuOptDescs list using the common options as a base. This enables per-machine options. Signed-off-by: Anthony Liguorialigu...@us.ibm.com diff --git a/qemu-config.c b/qemu-config.c index 5a4e61b..3679a9f 100644 --- a/qemu-config.c +++ b/qemu-config.c @@ -336,6 +336,14 @@ QemuOptsList qemu_cpudef_opts = { }, }; +QemuOptsList qemu_machine_opts = { +.name = machine, +.head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), +.desc = { +{ /* end of list */ } +}, +}; + static QemuOptsList *vm_config_groups[] = { qemu_drive_opts, qemu_chardev_opts, @@ -346,6 +354,7 @@ static QemuOptsList *vm_config_groups[] = { qemu_global_opts, qemu_mon_opts, qemu_cpudef_opts, +qemu_machine_opts, NULL, }; diff --git a/qemu-config.h b/qemu-config.h index dca69d4..6f52188 100644 --- a/qemu-config.h +++ b/qemu-config.h @@ -14,6 +14,7 @@ extern QemuOptsList qemu_rtc_opts; extern QemuOptsList qemu_global_opts; extern QemuOptsList qemu_mon_opts; extern QemuOptsList qemu_cpudef_opts; +extern QemuOptsList qemu_machine_opts; QemuOptsList *qemu_find_opts(const char *group); int qemu_set_option(const char *str); diff --git a/vl.c b/vl.c index 7121cd0..d362fc0 100644 --- a/vl.c +++ b/vl.c @@ -2550,6 +2550,35 @@ static const QEMUOption *lookup_opt(int argc, char **argv, return popt; } +/* TEMP: until we have proper -machine support */ +static QemuOptDesc common_machine_opts[] = { +{ +.name = ram_size, +.type = QEMU_OPT_NUMBER, +}, +{ +.name = kernel, +.type = QEMU_OPT_STRING, +}, +{ +.name = cmdline, +.type = QEMU_OPT_STRING, +}, +{ +.name = initrd, +.type = QEMU_OPT_STRING, +}, +{ +.name = boot_device, +.type = QEMU_OPT_STRING, +}, +{ +.name = cpu_model, +.type = QEMU_OPT_STRING, +}, +{ /* end of list */ }, +}; + int main(int argc, char **argv, char **envp) { const char *gdbstub_dev = NULL; @@ -3718,8 +3747,42 @@ int main(int argc, char **argv, char **envp) } qemu_add_globals(); -machine-init(ram_size, boot_devices, - kernel_filename, kernel_cmdline, initrd_filename, cpu_model); +opts = qemu_opts_create(qemu_machine_opts, NULL, 0); +if (kernel_filename) { +qemu_opt_set(opts, kernel, kernel_filename); +if (kernel_cmdline) { +qemu_opt_set(opts, cmdline, kernel_cmdline); +} +if (initrd_filename) { +qemu_opt_set(opts, initrd, initrd_filename); +} +} + +qemu_opt_set(opts, boot_device, boot_devices); + +if (cpu_model) { +qemu_opt_set(opts, cpu_model, cpu_model); +} + +if (ram_size) { +char buffer[64]; +snprintf(buffer, sizeof(buffer), + % PRId64, ram_size); +qemu_opt_set(opts, ram_size, buffer); +} + +if (qemu_opts_validate(opts, common_machine_opts) 0) { +exit(1); +} + +machine-init(qemu_opt_get_number(opts, ram_size), + qemu_opt_get(opts, boot_device), + qemu_opt_get(opts, kernel), + qemu_opt_get(opts, cmdline), + qemu_opt_get(opts, initrd), + qemu_opt_get(opts, cpu_model)); This should be cpu. I've updated and will hold off on a v2 for additional comments. Regards, Anthony Liguori + +qemu_opts_del(opts); cpu_synchronize_all_post_init();
Re: [Qemu-devel] Re: [PATCH 1/4] Add virtio disk identification support
Am 03.06.2010 21:09, schrieb 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 cooperjohn.coo...@redhat.com --- 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 @@ # includescsi/sg.h #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. Isn't this what we have pstrcpy for? Kevin
[Qemu-devel] [Bug 589315] Re: qemu: Improve error reporting when migration can't connect
** Changed in: qemu Status: New = Confirmed -- 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: Confirmed 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!
[Qemu-devel] [PATCH 2/3] add unregister_displaychangelistener
Signed-off-by: Gerd Hoffmann kra...@redhat.com --- console.h |5 + 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/console.h b/console.h index 3a80dca..a0da498 100644 --- a/console.h +++ b/console.h @@ -227,6 +227,11 @@ static inline void register_displaychangelistener(DisplayState *ds, DisplayChang QLIST_INSERT_HEAD(ds-listeners, dcl, next); } +static inline void unregister_displaychangelistener(DisplayChangeListener *dcl) +{ +QLIST_REMOVE(dcl, next); +} + static inline void dpy_update(DisplayState *s, int x, int y, int w, int h) { struct DisplayChangeListener *dcl; -- 1.6.6.1
[Qemu-devel] [PATCH 3/3] Fix and simplify gui timer logic.
Kill nographic timer. Have a global gui_timer instead. Have the gui timer enabled unconditionally. We need a timer running anyway for mmio flush, so the whole have-gui-timer-only-when-needed logic is pretty pointless. It also simplifies displaylisteners coming and going at runtime, we don't need to care about the timer then as it runs anyway. Don't allocate the timer twice in case we have two display listeners. Signed-off-by: Gerd Hoffmann kra...@redhat.com --- console.h |1 - vl.c | 37 +++-- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/console.h b/console.h index a0da498..6dad8d0 100644 --- a/console.h +++ b/console.h @@ -173,7 +173,6 @@ struct DisplayAllocator { struct DisplayState { struct DisplaySurface *surface; void *opaque; -struct QEMUTimer *gui_timer; struct DisplayAllocator* allocator; QLIST_HEAD(, DisplayChangeListener) listeners; diff --git a/vl.c b/vl.c index 9ca4e2f..703a233 100644 --- a/vl.c +++ b/vl.c @@ -236,7 +236,7 @@ int nb_numa_nodes; uint64_t node_mem[MAX_NODES]; uint64_t node_cpumask[MAX_NODES]; -static QEMUTimer *nographic_timer; +static QEMUTimer *gui_timer; uint8_t qemu_uuid[16]; @@ -1633,22 +1633,17 @@ static void gui_update(void *opaque) DisplayChangeListener *dcl; qemu_flush_coalesced_mmio_buffer(); -dpy_refresh(ds); -QLIST_FOREACH(dcl, ds-listeners, next) { -if (dcl-gui_timer_interval -dcl-gui_timer_interval interval) -interval = dcl-gui_timer_interval; +if (ds != NULL !QLIST_EMPTY(ds-listeners)) { +dpy_refresh(ds); +QLIST_FOREACH(dcl, ds-listeners, next) { +if (dcl-gui_timer_interval +dcl-gui_timer_interval interval) +interval = dcl-gui_timer_interval; +} } -qemu_mod_timer(ds-gui_timer, interval + qemu_get_clock(rt_clock)); -} - -static void nographic_update(void *opaque) -{ -uint64_t interval = GUI_REFRESH_INTERVAL; -qemu_flush_coalesced_mmio_buffer(); -qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock)); +qemu_mod_timer(gui_timer, interval + qemu_get_clock(rt_clock)); } struct vm_change_state_entry { @@ -2577,7 +2572,6 @@ int main(int argc, char **argv, char **envp) const char *kernel_filename, *kernel_cmdline; char boot_devices[33] = cad; /* default to HD-floppy-CD-ROM */ DisplayState *ds; -DisplayChangeListener *dcl; int cyls, heads, secs, translation; QemuOpts *hda_opts = NULL, *opts; int optind; @@ -3807,17 +3801,8 @@ int main(int argc, char **argv, char **envp) } dpy_resize(ds); -QLIST_FOREACH(dcl, ds-listeners, next) { -if (dcl-dpy_refresh != NULL) { -ds-gui_timer = qemu_new_timer(rt_clock, gui_update, ds); -qemu_mod_timer(ds-gui_timer, qemu_get_clock(rt_clock)); -} -} - -if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) { -nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL); -qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock)); -} +gui_timer = qemu_new_timer(rt_clock, gui_update, ds); +qemu_mod_timer(gui_timer, qemu_get_clock(rt_clock)); text_consoles_set_display(ds); -- 1.6.6.1