[Qemu-devel] Block live migration's use of type hint

2010-06-28 Thread Markus Armbruster
Block live migration appears to migrate only block devices with type
hint BDRV_TYPE_HD.  Others are silently skipped:

static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
{
Monitor *mon = opaque;
BlkMigDevState *bmds;
int64_t sectors;

if (bs-type == BDRV_TYPE_HD) {
[...]
}
}

The logic comes from commit c163b5ca, but its commit message doesn't
mention it.  Liran, please advise.  What are we trying to accomplish
here?

Whatever it is, I suspect checking the type hint isn't the appropriate
way to get it.



[Qemu-devel] [PATCH] Another fix to VMware depth computation

2010-06-28 Thread Tian, Kevin
(patch made upon 0.12.4 release; tested on 0.12 branch; build test on master)

 console.h   |   13 -
 hw/vmware_vga.c |   10 ++
 qemu-common.h   |1 -
 vl.c|8 
 4 files changed, 2 insertions(+), 30 deletions(-)

=
Another fix to VMware depth computation

VMware SVGA presents to the guest with the depth of the host surface it 
renders
to, and rejects to work if the two sides are mismatched. One problem is that
current VMware VGA may calculate a wrong host depth, and then memcpy from 
virtual
framebuffer to host surface may trigger segmentation fault. For example, 
when
launching Qemu in a VNC connection, VMware SVGA thinks depth as '32', 
however the
actual depth of VNC is '16'. The fault also happens when the host depth is 
not
32 bit.

4b5db3749c5fdba93e1ac0e8748c9a9a1064319f tempts to fix a similar issue, by
changing from hard-coded 24bit depth to instead query the surface allocator
(e.g. sdl). However it doesn't really work, because the point where query
is invoked is earlier than the point where sdl is initialized. At query 
time,
qemu uses a default surface allocator which, again, provides another 
hard-coded
depth value - 32bit. So it happens to make VMware SVGA working on some 
hosts,
but still fails in others.

To solve this issue, this commit introduces a postcall interface to display
surface, which is walked after surface allocators are actually initialized.
At that point it's then safe to query host depth and present to the guest.

Signed-off-by Kevin Tian kevin.t...@intel.com

diff --git a/console.h b/console.h
index dfc8ae4..05fbf17 100644
--- a/console.h
+++ b/console.h
@@ -122,6 +122,12 @@ struct DisplayAllocator {
 void (*free_displaysurface)(DisplaySurface *surface);
 };
 
+struct DisplayPostCallback {
+void (*postcall) (void *);
+void *parm;
+struct DisplayPostCallback *next;
+};
+
 struct DisplayState {
 struct DisplaySurface *surface;
 void *opaque;
@@ -129,6 +135,7 @@ struct DisplayState {
 
 struct DisplayAllocator* allocator;
 struct DisplayChangeListener* listeners;
+struct DisplayPostCallback* postcalls;
 
 void (*mouse_set)(int x, int y, int on);
 void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
@@ -185,6 +192,12 @@ static inline void 
register_displaychangelistener(DisplayState *ds, DisplayChang
 ds-listeners = dcl;
 }
 
+static inline void register_displaypostcallback(DisplayState *ds, 
DisplayPostCallback *dpc)
+{
+dpc-next = ds-postcalls;
+ds-postcalls = dpc;
+}
+
 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
 {
 struct DisplayChangeListener *dcl = s-listeners;
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index 01bb85b..d73cca6 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -927,8 +927,9 @@ static void vmsvga_update_display(void *opaque)
 }
 }
 
-static void vmsvga_reset(struct vmsvga_state_s *s)
+static void vmsvga_reset(void *parm)
 {
+struct vmsvga_state_s *s = (struct vmsvga_state_s *)parm;
 s-index = 0;
 s-enable = 0;
 s-config = 0;
@@ -1133,6 +1134,8 @@ static const VMStateDescription vmstate_vmware_vga = {
 
 static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size)
 {
+DisplayPostCallback *dpc;
+
 s-scratch_size = SVGA_SCRATCH_SIZE;
 s-scratch = qemu_malloc(s-scratch_size * 4);
 
@@ -1160,7 +1163,10 @@ static void vmsvga_init(struct vmsvga_state_s *s, int 
vga_ram_size)
 
 rom_add_vga(VGABIOS_FILENAME);
 
-vmsvga_reset(s);
+dpc = qemu_mallocz(sizeof(DisplayPostCallback));
+dpc-postcall = vmsvga_reset;
+dpc-parm = s;
+register_displaypostcallback(s-vga.ds, dpc);
 }
 
 static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num,
diff --git a/qemu-common.h b/qemu-common.h
index a23afbc..19f107a 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -198,6 +198,7 @@ typedef struct DisplayState DisplayState;
 typedef struct DisplayChangeListener DisplayChangeListener;
 typedef struct DisplaySurface DisplaySurface;
 typedef struct DisplayAllocator DisplayAllocator;
+typedef struct DisplayPostCallback DisplayPostCallback;
 typedef struct PixelFormat PixelFormat;
 typedef struct TextConsole TextConsole;
 typedef TextConsole QEMUConsole;
diff --git a/vl.c b/vl.c
index 39182ea..9a3e9fd 100644
--- a/vl.c
+++ b/vl.c
@@ -4863,6 +4863,7 @@ int main(int argc, char **argv, char **envp)
 char boot_devices[33] = cad; /* default to HD-floppy-CD-ROM */
 DisplayState *ds;
 DisplayChangeListener *dcl;
+DisplayPostCallback *dpc;
 int cyls, heads, secs, translation;
 QemuOpts *hda_opts = NULL, *opts;
 int optind;
@@ -6053,6 +6053,13 @@ int main(int argc, char **argv, char **envp)
 }
 dpy_resize(ds);
 
+dpc = ds-postcalls;
+while (dpc != NULL) {
+if (dpc-postcall != NULL)
+

Re: [Qemu-devel] [PATCH 4/7] provide opaque CPUState to files that are compiled once

2010-06-28 Thread Paolo Bonzini

On 06/27/2010 09:17 PM, Blue Swirl wrote:

I'm not comfortable with this part. Accidental use of the global
register variable can cause subtle bugs. I'd rather rename 'env' to
something more obvious and less likely to collide, like
'global_reg_env' and always poison that. Then we could replace 'env1'
etc with just 'env'.


This is not very different from before thanks to the reordering of 
includes done in this patch.


All target-*/exec.h files now start with

#include config.h
#include dyngen-exec.h
#include cpu.h
#include exec-all.h

// sometimes a few #defines

register struct CPUAlphaState *env asm(AREG0);

And so they cannot use the global env unless NEED_CPU_H is defined.  If 
anything, it's clearer than before because the structure of the initial 
#includes is the same for all targets.


It's true that a NEED_GLOBAL_ENV would provide even better safety, but 
that's something for a separate patch series.  It's particularly easy to 
do after replacing CPUTargetState with CPUState, so that it can be 
moved into exec-all.h, but this series is already big enough IMO.  Let's 
do cleanups one thing at a time please.


Paolo



[Qemu-devel] Re: Block live migration's use of type hint

2010-06-28 Thread Liran Schour

Markus Armbruster arm...@redhat.com wrote on 28/06/2010 10:26:47:

 From: Markus Armbruster arm...@redhat.com
 To: qemu-devel@nongnu.org
 Cc: Liran Schour/Haifa/i...@ibmil
 Date: 28/06/2010 10:26
 Subject: Block live migration's use of type hint

 Block live migration appears to migrate only block devices with type
 hint BDRV_TYPE_HD.  Others are silently skipped:

 static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
 {
 Monitor *mon = opaque;
 BlkMigDevState *bmds;
 int64_t sectors;

 if (bs-type == BDRV_TYPE_HD) {
 [...]
 }
 }

 The logic comes from commit c163b5ca, but its commit message doesn't
 mention it.  Liran, please advise.  What are we trying to accomplish
 here?

 Whatever it is, I suspect checking the type hint isn't the appropriate
 way to get it.

my intention was to migrate only writeable devices. Maybe there are more
accurate ways to do that.

- Liran




Re: [Qemu-devel] VxWorks kernel for qemu emulating PowerPC?

2010-06-28 Thread hadi motamedi


 It is possible to boot a VxWorks image using the x86 system emulation.
 You would have to create a floppy image and pass that in for

Thank you very much for your reply. Can you please let me know how can I
obtain more details on the implementation scenario of your proposed
procedure?


[Qemu-devel] Re: qemu-kvm guest network stalls

2010-06-28 Thread William King
Is this the wrong list to get help tracking down why the network stalls
under heavy load?

I have been on irc talking with multiple people, some believe the
problem is located in xming so it's 100% linux-bridge/ebtables, but I
have no way to confirm this.

I have been able to reproduce the network stall with two completely
different pieces of hardware. One is an AMD dual core, the other an
Intel i7, each have different network hardware, etc. Same issue.

On 06/26/2010 01:36 PM, William King wrote:
 I have an ubuntu lucid host and an ubuntu lucid guest. Under heavy
 network load the guest network stalls and is only able to come back
 after running sudo /etc/init.d/networking restart on the guest.
 
 Here are some (hopefully) helpful details.
 Host---
 
 # uname -a
 Linux virtserv 2.6.32-22-server #36-Ubuntu SMP Thu Jun 3 20:38:33 UTC
 2010 x86_64 GNU/Linux
 
 # ifconfig -v
 br0   Link encap:Ethernet  HWaddr 00:e0:4d:20:1f:86
   inet addr:192.168.100.145  Bcast:192.168.100.255
 Mask:255.255.255.0
   inet6 addr: fe80::2e0:4dff:fe20:1f86/64 Scope:Link
   UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
   RX packets:1254011 errors:0 dropped:0 overruns:0 frame:0
   TX packets:1070096 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:0
   RX bytes:439139185 (439.1 MB)  TX bytes:836663432 (836.6 MB)
 
 eth0  Link encap:Ethernet  HWaddr 00:e0:4d:20:1f:86
   inet6 addr: fe80::2e0:4dff:fe20:1f86/64 Scope:Link
   UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
   RX packets:124712767 errors:0 dropped:0 overruns:0 frame:0
   TX packets:91086029 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:1000
   RX bytes:162562714983 (162.5 GB)  TX bytes:36005498601 (36.0 GB)
   Interrupt:29 Base address:0x8000
 
 loLink encap:Local Loopback
   inet addr:127.0.0.1  Mask:255.0.0.0
   inet6 addr: ::1/128 Scope:Host
   UP LOOPBACK RUNNING  MTU:16436  Metric:1
   RX packets:83577 errors:0 dropped:0 overruns:0 frame:0
   TX packets:83577 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:0
   RX bytes:15722576 (15.7 MB)  TX bytes:15722576 (15.7 MB)
 
 virbr0Link encap:Ethernet  HWaddr 5a:f3:dc:99:84:ee
   inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
   inet6 addr: fe80::58f3:dcff:fe99:84ee/64 Scope:Link
   UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
   RX packets:0 errors:0 dropped:0 overruns:0 frame:0
   TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:0
   RX bytes:0 (0.0 B)  TX bytes:468 (468.0 B)
 
 vnet0 Link encap:Ethernet  HWaddr ca:8b:d8:66:e6:f5
   inet6 addr: fe80::c88b:d8ff:fe66:e6f5/64 Scope:Link
   UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
   RX packets:81138964 errors:0 dropped:0 overruns:0 frame:0
   TX packets:111911797 errors:0 dropped:0 overruns:100 carrier:0
   collisions:0 txqueuelen:500
   RX bytes:31177137669 (31.1 GB)  TX bytes:147190153358 (147.1 GB)
 
 # dpkg -l |grep qemu
 ii  kvm
 1:84+dfsg-0ubuntu16+0.12.4+noroms+0ubuntu3~ppa1 dummy transitional
 pacakge from kvm to qemu-kvm
 ii  qemu-common
 0.12.4+noroms-0ubuntu3~ppa1 qemu common
 functionality (bios, documentation, etc)
 ii  qemu-kvm
 0.12.4+noroms-0ubuntu3~ppa1 Full virtualization on
 i386 and amd64 hardware
 
 
 I installed the 0.12.4 qemu-kvm package that was built for lucid and
 uploaded here:
 https://edge.launchpad.net/~ubuntu-virt/+archive/ppa/+packages
 
 # cat /etc/network/interfaces
 # This file describes the network interfaces available on your system
 # and how to activate them. For more information, see interfaces(5).
 
 # The loopback network interface
 auto lo
 iface lo inet loopback
 
 # The primary network interface
 auto eth0
 iface eth0 inet dhcp
 
 auto br0
 iface br0 inet dhcp
 bridge_ports eth0
 bridge_stp off
 bridge_fd 0
 bridge_maxwait 0
 
 
 
 --Guest---
 uname -a
 Linux torrents 2.6.32-22-server #36-Ubuntu SMP Thu Jun 3 20:38:33 UTC
 2010 x86_64 GNU/Linux
 
 # ifconfig -v
 eth0  Link encap:Ethernet  HWaddr 52:54:00:1e:6e:b4
   inet addr:192.168.100.203  Bcast:192.168.100.255
 Mask:255.255.255.0
   inet6 addr: fe80::5054:ff:fe1e:6eb4/64 Scope:Link
   UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
   RX packets:39410626 errors:0 dropped:0 overruns:0 frame:0
   TX packets:28376412 errors:0 dropped:0 overruns:0 carrier:0
   collisions:0 txqueuelen:1000
   RX bytes:52260862769 (52.2 GB)  TX bytes:10005355703 (10.0 GB)
 
 loLink encap:Local Loopback
   inet 

Re: [Qemu-devel] [PATCH 0/7] poison TARGET_xxx for compile once object and header file cleanups

2010-06-28 Thread Paolo Bonzini

On 06/27/2010 09:32 PM, Blue Swirl wrote:

 From just clean up or type safety point of view, this is good stuff.
But from architectural point of view, we should make it more difficult
to use CPUState in device code, not easier. This may still be fine as
a temporary measure, before all CPUState references have been removed.


I don't see it at all as a temporary measure.  In theory, only devices 
compiled per-target would need access to CPUState, that's true. 
However, there are conflicting goals which make an opaque CPUState 
preferrable.


First, converting devices such as APIC to qdev requires knowledge of 
CPUState in qdev, unless you want to keep DEFINE_PROP_PTR (whose removal 
is much more interesting) or sweep it under the void* blanket.  PICs are 
likely to have CPUState members, e.g. hw/pxa2xx_pic.c (and BTW indirect 
access via functions to these fields is making emulation a little bit 
slower).


Also, for things compiled in libhw that are not part of device code, 
requiring knowledge of CPUState is absolutely not problematic and the 
only alternative loses type-safety and so it is inferior.


Paolo



Re: [Qemu-devel] Re: qemu-kvm guest network stalls

2010-06-28 Thread Stefan Hajnoczi
On Mon, Jun 28, 2010 at 9:08 AM, William King quentus...@gmail.com wrote:
 Is this the wrong list to get help tracking down why the network stalls
 under heavy load?

This list is the right one.  There is at least one known network stall bug:

http://sourceforge.net/tracker/?func=detailatid=893831aid=2506814group_id=180599
http://www.mail-archive.com/k...@vger.kernel.org/msg06774.html

I sounds like you have the same issue?

Stefan



Re: [Qemu-devel] Re: qemu-kvm guest network stalls

2010-06-28 Thread William King
Thanks for the reply Stefan.

That looks to be exactly the same bug I'm dealing with here. The one
difference is that I can reproduce it easily on test hardware. So I have
two separate boxes that can go down(and run test code) without
interfering with anything in production.

My test setup has a local torrent server, and 5 other machines on the
network seeding a very large(10GB) random data file that I created. When
the guest tries to download this file from the other servers this
aggravates the issue. To the point that I could cause it to fail within
minutes, repeatedly. I created this test after someone on irc said that
the issue could have something to do with udp traffic rather than tcp
traffic.

I am running latest ubuntu 10.04 on the hosts and the guests, and I can
wipe(and reinstall) the hosts quickly and easily.

On 06/28/2010 01:28 AM, Stefan Hajnoczi wrote:
 On Mon, Jun 28, 2010 at 9:08 AM, William King quentus...@gmail.com wrote:
 Is this the wrong list to get help tracking down why the network stalls
 under heavy load?
 
 This list is the right one.  There is at least one known network stall bug:
 
 http://sourceforge.net/tracker/?func=detailatid=893831aid=2506814group_id=180599
 http://www.mail-archive.com/k...@vger.kernel.org/msg06774.html
 
 I sounds like you have the same issue?
 
 Stefan



Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-28 Thread Jes Sorensen
On 06/25/10 19:34, Frank Arnold wrote:
 We are doing KVM testing, so it is Linux.
 
 What I did is putting lines like this somewhere into vl.c and
 os-posix.c:
 fprintf(stderr, os: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize);
 fprintf(stderr, vl: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize);
 
 Resulting in the following output on stderr:
 os: QEMU_OPTION_daemonize: 85
 vl: QEMU_OPTION_daemonize: 86
 
 No compile time errors. The preprocessing of qemu-options.h is done
 separately for both files. This results in a missing option definition
 for os-posix.c and discrepancy in the option enumeration.

Ok this is truly odd! Let me try and see if I can reproduce it here.

Cheers,
Jes





[Qemu-devel] Re: [PATCH 04/12] blockdev: New drive_of_blockdev()

2010-06-28 Thread Paolo Bonzini

On 06/26/2010 04:46 PM, Markus Armbruster wrote:

drive_get_by_blockdev()?  blockdev_to_drive()?


I like drive_find_by_blockdev or drive_get_by_blockdev, in any case I'll 
make sure my own cpu_get_by_id is named in the same style that you choose.


Paolo



[Qemu-devel] console on stdio?

2010-06-28 Thread Pascal J. Bourguignon

What option should I give to get the guest host on the host stdio?
I want to launch qemu from a terminal and have access to the console
there.

I tried -serial stdio and -monitor stdio but this gives:

chardev: opening backend stdio failed
qemu: could not open serial device 'stdio': Invalid argument

-- 
__Pascal Bourguignon__ http://www.informatimago.com/




Re: [Qemu-devel] Re: [PATCH 08/12] block: Catch attempt to attach multiple devices to a blockdev

2010-06-28 Thread Christoph Hellwig
On Mon, Jun 28, 2010 at 10:24:49AM +0200, Kevin Wolf wrote:
 How would breaking compatibility help us? For the user a USB MSD is only
 one device, so requiring two -device parameters sounds wrong.

But it is separate devices.  At least the standards compliant usb
storage devices just are a bride of scsi commands over usb and fit into
the SAM device model, which makes a difference between initiator, target
and LUN.  So having a different device for the specific target vs the
initiator port makes a difference. (and yes, we're still totally missing
support for multiple luns, which would require another level of
devices).  Trying to hide this is not all that useful - not anymore
useful than hiding it on a normal scsi host controller anyway.




Re: [Qemu-devel] Re: [PATCH 08/12] block: Catch attempt to attach multiple devices to a blockdev

2010-06-28 Thread Kevin Wolf
Am 28.06.2010 12:16, schrieb Christoph Hellwig:
 On Mon, Jun 28, 2010 at 10:24:49AM +0200, Kevin Wolf wrote:
 How would breaking compatibility help us? For the user a USB MSD is only
 one device, so requiring two -device parameters sounds wrong.
 
 But it is separate devices.  At least the standards compliant usb
 storage devices just are a bride of scsi commands over usb and fit into
 the SAM device model, which makes a difference between initiator, target
 and LUN.  So having a different device for the specific target vs the
 initiator port makes a difference. (and yes, we're still totally missing
 support for multiple luns, which would require another level of
 devices).  Trying to hide this is not all that useful - not anymore
 useful than hiding it on a normal scsi host controller anyway.

Maybe we need something like composed devices? So when the user asks for
a USB stick, he actually gets all devices that this stick internally
uses? Otherwise it becomes really hard to use -device directly.

I guess the same applies for mainboards, CPUs and probably some more
things, though I don't really know how these are (planned to be) done in
qdev.

Kevin



Re: [Qemu-devel] Re: block: format vs. protocol, and how they stack

2010-06-28 Thread Christoph Hellwig
On Mon, Jun 21, 2010 at 06:21:09PM +0200, Markus Armbruster wrote:
 You describe the special case where format and protocol make some sense:
 you have a block driver that can transport bits in arbitrary formats,
 and a block driver that interprets bits without caring for transport.
 
 In the general case, we have things like vvfat that make people wonder
 whether it's a format or a protocol.  You can't stack it onto a
 transport, so it can't be a format!  You can't stack a format on it, so
 it can't be a protocol!

Instead of starting to get hung up on the protocol name let's go back to
the basic problem.  We have two types of Block drivers in qemu, which
are fundamentally different:

 - leaf drivers which use some sort of native I/O method and present
   an image.  The typical cases for this are file/host_device/nbd/http/
   ceph/sheepdog which just transport arbitrary content over some transport.
   Another category makes up the content of the image on the fly.  This
   is generally an extreme hack as it's very hard to keep any kind of
   coherency if the underlying content changes, but we've unfortunately
   enough done it anyway for vvfat.  I don't think I would accept any
   addition driver of this type.
 - non-leaf drivers which stack on top of another qemu block driver.

I think the difference is important enough for a user to care.  It's
basically two different questions for the users:

 - what image format do I want
 - and where do I store that image

Even vvfat kinda fits into that model.  The users wants to store the
image as a life view of a directory hierachy on the host.  Because
of the limitation of that model the choice of image format ontop of
that storage solution is limited to raw.



[Qemu-devel] Re: Block live migration's use of type hint

2010-06-28 Thread Markus Armbruster
Liran Schour lir...@il.ibm.com writes:

 Markus Armbruster arm...@redhat.com wrote on 28/06/2010 10:26:47:

 From: Markus Armbruster arm...@redhat.com
 To: qemu-devel@nongnu.org
 Cc: Liran Schour/Haifa/i...@ibmil
 Date: 28/06/2010 10:26
 Subject: Block live migration's use of type hint

 Block live migration appears to migrate only block devices with type
 hint BDRV_TYPE_HD.  Others are silently skipped:

 static void init_blk_migration_it(void *opaque, BlockDriverState *bs)
 {
 Monitor *mon = opaque;
 BlkMigDevState *bmds;
 int64_t sectors;

 if (bs-type == BDRV_TYPE_HD) {
 [...]
 }
 }

 The logic comes from commit c163b5ca, but its commit message doesn't
 mention it.  Liran, please advise.  What are we trying to accomplish
 here?

 Whatever it is, I suspect checking the type hint isn't the appropriate
 way to get it.

 my intention was to migrate only writeable devices. Maybe there are more
 accurate ways to do that.

Okay, that looks like a job for bdrv_is_read_only().

Thanks for your quick reply!



Re: [Qemu-devel] Guest OS hangs on usb_add

2010-06-28 Thread Gianni Tedesco
On Fri, 2010-06-25 at 18:23 +0100, TJ wrote:
 On 06/25/10 12:32, Gianni Tedesco wrote:
  A device MAY provide extended descriptors in 2 ways mentioned in the
  spec, but ISTR finding at least one device in the wild with standard
  descriptors extended which were not so much used by the host but by
  application software. So not sure about your patch, a quirks blacklist
  based on idDevice/idProduct might be the better fix here.
 
 Makes sense. I should add vend/prod id check.
 
  However the more serious problem is spinning on zero length descriptor
  when truncated descriptors are not valid and zero length (in fact  2)
  is totally unacceptable. Following patch checks for truncation.
 
 Gianni, Please check my later patch submitted last night. I basically did the
 same thing you did, but with few differences:
 
 - if descriptor size is  2, goto fail
 - if the descriptor is USB_DT_CONFIG, we can skip through all the sub
 descriptors using wTotalLength field.
 - otherwise, simply skip it

Good point, just seen you patch and it looks good.

 One thing to also watch out for is the string descriptors. I might be wrong, 
 but
 it appears (from reading the doc) that string descriptors (at least for the
 device descriptor) can be interspersed with the config descriptors, in which
 case (config_descr_len  USB_DT_CONFIG_SIZE) without checking descriptor type
 might unwittingly lead to failure.

Yeah definitely, descriptors can be in pretty much any old order so the
code should not rely on any of that.

FWIW, I am signing off on your approach :)

Gianni Tedesco




[Qemu-devel] [PATCH][Tracing] Fix for make parallelization.

2010-06-28 Thread Prerna Saxena
[PATCH] Restore parallel building
This is based on :
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing

Signed-off-by: Prerna Saxena pre...@linux.vnet.ibm.com
---
 Makefile |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index e64e397..de9b175 100644
--- a/Makefile
+++ b/Makefile
@@ -138,7 +138,9 @@ trace.h: $(SRC_PATH)/trace-events
 trace.c: $(SRC_PATH)/trace-events
$(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -c  
$  $@,  GEN   $@)
 
-trace.o: trace.c
+trace.o: trace.c trace.h
+
+simpletrace.o: simpletrace.c trace.h
 
 ##
 
-- 
1.6.2.5



-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India




[Qemu-devel] Re: [PATCH][Tracing] Fix for make parallelization.

2010-06-28 Thread Stefan Hajnoczi
On Mon, Jun 28, 2010 at 06:02:37PM +0530, Prerna Saxena wrote:
 [PATCH] Restore parallel building
 This is based on :
 http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing
 
 Signed-off-by: Prerna Saxena pre...@linux.vnet.ibm.com

Dependencies are not quite right yet:

$ make distclean
$ ./configure --trace-backend=simple
$ make V=1 trace.o
sh /home/stefanha/qemu/tracetool --simple -c  /home/stefanha/qemu/trace-events 
 trace.c
sh /home/stefanha/qemu/tracetool --simple -h  /home/stefanha/qemu/trace-events 
 trace.h
gcc -I/home/stefanha/qemu/slirp -Werror -m64 -fstack-protector-all 
-Wold-style-definition -Wold-style-declaration -I. -I/home/stefanha/qemu 
-D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels 
-Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing   -MMD -MP -MT 
trace.o -MF ./trace.d -O2 -g  -c -o trace.o trace.c
In file included from trace.h:6,
 from trace.c:2:
qemu-common.h:5:25: error: config-host.h: No such file or directory
In file included from trace.h:6,
 from trace.c:2:
qemu-common.h:61: error: redefinition of ‘struct iovec’
make: *** [trace.o] Error 1

I have applied it for now, however, because the implicit dependencies issue 
affects all of QEMU and was not caused by tracing code:

http://repo.or.cz/w/qemu/stefanha.git/commitdiff/e47a997579086dd585534da610e76f23f9c04b87

Stefan



[Qemu-devel] Re: [PATCH 0/8] Fix various IO-thread breakages

2010-06-28 Thread Marcelo Tosatti
On Fri, Jun 25, 2010 at 04:56:48PM +0200, Jan Kiszka wrote:
 This series unbreaks -smp 1 and guest debugging in CONFIG_IOTHREAD
 mode. I still find the SMP scheduling in cpu_exec_all suboptimal, but
 at least it works now.
 
 Dependencies are:
 http://thread.gmane.org/gmane.comp.emulators.kvm.devel/52718 (kvm queue)
 http://thread.gmane.org/gmane.comp.emulators.qemu/75087
 
 The full series can be found at
 
   git://git.kiszka.org/qemu.git queues/iothread
 
 Jan Kiszka (8):
   Introduce proper compiler barrier
   Fix cpu_unlink_tb race
   Init qemu_system_cond
   Fix cpu_exit for tcp_cpu_exec
   Fix qemu_wait_io_event processing in io-thread mode
   Drop redundant global cur_cpu variable
   Rename tcg_cpu_exec and tcg_has_work
   Rework debug exception processing for gdb use
 
  cpu-exec.c |   15 +++--
  cpus.c |   58 +--
  cpus.h |2 +-
  kvm-all.c  |2 -
  qemu-barrier.h |3 ++
  vl.c   |2 +-
  6 files changed, 48 insertions(+), 34 deletions(-)

Reviewed-by: Marcelo Tosatti mtosa...@redhat.com

I'll be sending the uq/master queue shortly (but this can go in
separately).



Re: [Qemu-devel] [PATCH][RESEND] qdev-properties: Fix (u)intXX parsers

2010-06-28 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 scanf calls must not use PRI constants, they have probably the wrong size and
 corrupt memory. We could replace them by SCN ones, but strtol is simpler than
 scanf here anyway. While at it, also fix the parsers to reject garbage after
 the number (4096xyz was accepted before).

 Signed-off-by: Kevin Wolf kw...@redhat.com

Ping...  this secures an open deathtrap, please apply.



Re: [Qemu-devel] Re: [PATCH][Tracing] Fix for make parallelization.

2010-06-28 Thread Stefan Hajnoczi
On Mon, Jun 28, 2010 at 2:46 PM, Stefan Hajnoczi
stefa...@linux.vnet.ibm.com wrote:
 On Mon, Jun 28, 2010 at 06:02:37PM +0530, Prerna Saxena wrote:
 [PATCH] Restore parallel building
 This is based on :
 http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/tracing

 Signed-off-by: Prerna Saxena pre...@linux.vnet.ibm.com

 Dependencies are not quite right yet:

 $ make distclean
 $ ./configure --trace-backend=simple
 $ make V=1 trace.o
 sh /home/stefanha/qemu/tracetool --simple -c  
 /home/stefanha/qemu/trace-events  trace.c
 sh /home/stefanha/qemu/tracetool --simple -h  
 /home/stefanha/qemu/trace-events  trace.h
 gcc -I/home/stefanha/qemu/slirp -Werror -m64 -fstack-protector-all 
 -Wold-style-definition -Wold-style-declaration -I. -I/home/stefanha/qemu 
 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
 -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wendif-labels 
 -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing   -MMD -MP -MT 
 trace.o -MF ./trace.d -O2 -g  -c -o trace.o trace.c
 In file included from trace.h:6,
                 from trace.c:2:
 qemu-common.h:5:25: error: config-host.h: No such file or directory
 In file included from trace.h:6,
                 from trace.c:2:
 qemu-common.h:61: error: redefinition of ‘struct iovec’
 make: *** [trace.o] Error 1

 I have applied it for now, however, because the implicit dependencies issue 
 affects all of QEMU and was not caused by tracing code:

Can someone explain how the build system uses dependency rules?  From
what I can tell the dependencies are generated during compilation.  In
rules.mak:

# Flags for dependency generation
QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d

%.o: %.c
$(call quiet-command,$(CC) $(QEMU_CFLAGS) $(QEMU_DGFLAGS)
$(CFLAGS) -c -o $@ $,  CC$(TARGET_DIR)$@)

I would have expected one pass to build dependencies, then the
dependency rules are sourced into make, then the code is built.  Isn't
it too late to generate dependencies when compiling the object file?

It looks like GENERATED_HEADERS is used to add explicit dependencies
on config-host.h and config-target.h.  trace.o should depend on
$(GENERATED_HEADERS).

Stefan



Re: [Qemu-devel] [PATCH 4/7] provide opaque CPUState to files that are compiled once

2010-06-28 Thread Blue Swirl
On Mon, Jun 28, 2010 at 8:04 AM, Paolo Bonzini pbonz...@redhat.com wrote:
 On 06/27/2010 09:17 PM, Blue Swirl wrote:

 I'm not comfortable with this part. Accidental use of the global
 register variable can cause subtle bugs. I'd rather rename 'env' to
 something more obvious and less likely to collide, like
 'global_reg_env' and always poison that. Then we could replace 'env1'
 etc with just 'env'.

 This is not very different from before thanks to the reordering of includes
 done in this patch.

 All target-*/exec.h files now start with

 #include config.h
 #include dyngen-exec.h
 #include cpu.h
 #include exec-all.h

 // sometimes a few #defines

 register struct CPUAlphaState *env asm(AREG0);

 And so they cannot use the global env unless NEED_CPU_H is defined.  If
 anything, it's clearer than before because the structure of the initial
 #includes is the same for all targets.

 It's true that a NEED_GLOBAL_ENV would provide even better safety, but
 that's something for a separate patch series.  It's particularly easy to do
 after replacing CPUTargetState with CPUState, so that it can be moved into
 exec-all.h, but this series is already big enough IMO.  Let's do cleanups
 one thing at a time please.

Fine, but then let's not unpoison env with this patch set, please.



Re: [Qemu-devel] [PATCH v4 11/23] monitor: Add completion support for option lists

2010-06-28 Thread Luiz Capitulino
On Wed, 23 Jun 2010 12:28:27 +0200
Jan Kiszka jan.kis...@siemens.com wrote:

 Markus Armbruster wrote:
  Jan Kiszka jan.kis...@web.de writes:
  
  From: Jan Kiszka jan.kis...@siemens.com
 
  This enables command line completion inside option strings. A list of
  expected key names and their completion type can be appended to the 'O'
  inside parentheses ('O(key:type,...)'). The first use case is block
  device completion for the 'drive' option of 'device_add'.
 
  Signed-off-by: Jan Kiszka jan.kis...@siemens.com
  ---
   monitor.c   |   68 
  ++-
   qemu-monitor.hx |2 +-
   2 files changed, 58 insertions(+), 12 deletions(-)
 
  diff --git a/monitor.c b/monitor.c
  index c1006b4..3e0d862 100644
  --- a/monitor.c
  +++ b/monitor.c
  @@ -68,6 +68,9 @@
* 'O'  option string of the form NAME=VALUE,...
*  parsed according to QemuOptsList given by its name
*  Example: 'device:O' uses qemu_device_opts.
  + *  Command completion for specific keys can be requested via
  + *  appending '(NAME:TYPE,...)' with 'F', 'B' as type.
  + *  Example: 'device:O(bus:Q)' to expand 'bus=...' as qtree 
  path.
*  Restriction: only lists with empty desc are supported
*  TODO lift the restriction
* 'i'  32 bit integer
  
  Ugh.
  
  Replacement of args_type by a proper data structure is long overdue.  We
  keep piling features into that poor, hapless string.
  
  Information on how to complete QemuOptsList options arguably belongs
  into the option description, i.e. QemuOptDesc.
 
 For sure, that would be better. I just wonder how much of it should be
 stuffed into this series. I guess I will drop this part for now, just
 focusing on what device_show makes direct use of. Same for separate args
 for HMP and QMP.

IIRC, the separate args idea use case was to allow commands like device_del
to have an ID argument and a path argument, right? If so, I think it doesn't
matter anymore as we have agreed on having a device argument which would
accept both, even under QMP, right Markus?

By the way, if you send patches 09/23, 10/23, 15/23, (maybe) 16/23, 21/23
and 22/23 in a different series, I could try pushing them in my next
pull request.



Re: [Qemu-devel] Guest OS hangs on usb_add

2010-06-28 Thread TJ
On 06/28/10 08:32, Gianni Tedesco wrote:
 
 FWIW, I am signing off on your approach :)
 
 Gianni Tedesco
 

Thank you Gianni :) I am gonna add simple vend/prod id check to my 0x18 hack and
resubmit final version.

-TJ



[Qemu-devel] [PATCH] Don't reset bs-is_temporary in bdrv_open_common

2010-06-28 Thread Ryan Harper
To fix https://bugs.launchpad.net/qemu/+bug/597402 where qemu fails to
call unlink() on temporary snapshots due to bs-is_temporary getting clobbered
in bdrv_open_common() after being set in bdrv_open() which calls the former.

We don't need to initialize bs-is_temporary in bdrv_open_common().

Signed-off-by: Ryan Harper ry...@us.ibm.com
---
 block.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/block.c b/block.c
index e71a771..a55882e 100644
--- a/block.c
+++ b/block.c
@@ -393,7 +393,6 @@ static int bdrv_open_common(BlockDriverState *bs, const 
char *filename,
 
 bs-file = NULL;
 bs-total_sectors = 0;
-bs-is_temporary = 0;
 bs-encrypted = 0;
 bs-valid_key = 0;
 bs-open_flags = flags;
-- 
1.6.3.3


-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
ry...@us.ibm.com



[Qemu-devel] [PATCH] Include sys/mman.h before qemu-options.h

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

The result of parsing qemu-options.def depends on whehter or not
MAP_POPULATE is defined, so make sure to include sys/mman.h before
including qemu-options.h.

Reported by Frank Arnold.

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

diff --git a/os-posix.c b/os-posix.c
index 804e20c..00133a0 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,8 @@
 #include signal.h
 #include sys/types.h
 #include sys/wait.h
+/*needed for MAP_POPULATE before including qemu-options.h */
+#include sys/mman.h
 #include pwd.h
 #include libgen.h
 
-- 
1.7.0.1




Re: [Qemu-devel] [PATCH v4 11/23] monitor: Add completion support for option lists

2010-06-28 Thread Jan Kiszka
Luiz Capitulino wrote:
 On Wed, 23 Jun 2010 12:28:27 +0200
 Jan Kiszka jan.kis...@siemens.com wrote:
 
 Markus Armbruster wrote:
 Jan Kiszka jan.kis...@web.de writes:

 From: Jan Kiszka jan.kis...@siemens.com

 This enables command line completion inside option strings. A list of
 expected key names and their completion type can be appended to the 'O'
 inside parentheses ('O(key:type,...)'). The first use case is block
 device completion for the 'drive' option of 'device_add'.

 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---
  monitor.c   |   68 
 ++-
  qemu-monitor.hx |2 +-
  2 files changed, 58 insertions(+), 12 deletions(-)

 diff --git a/monitor.c b/monitor.c
 index c1006b4..3e0d862 100644
 --- a/monitor.c
 +++ b/monitor.c
 @@ -68,6 +68,9 @@
   * 'O'  option string of the form NAME=VALUE,...
   *  parsed according to QemuOptsList given by its name
   *  Example: 'device:O' uses qemu_device_opts.
 + *  Command completion for specific keys can be requested via
 + *  appending '(NAME:TYPE,...)' with 'F', 'B' as type.
 + *  Example: 'device:O(bus:Q)' to expand 'bus=...' as qtree 
 path.
   *  Restriction: only lists with empty desc are supported
   *  TODO lift the restriction
   * 'i'  32 bit integer
 Ugh.

 Replacement of args_type by a proper data structure is long overdue.  We
 keep piling features into that poor, hapless string.

 Information on how to complete QemuOptsList options arguably belongs
 into the option description, i.e. QemuOptDesc.
 For sure, that would be better. I just wonder how much of it should be
 stuffed into this series. I guess I will drop this part for now, just
 focusing on what device_show makes direct use of. Same for separate args
 for HMP and QMP.
 
 IIRC, the separate args idea use case was to allow commands like device_del
 to have an ID argument and a path argument, right? If so, I think it doesn't
 matter anymore as we have agreed on having a device argument which would
 accept both, even under QMP, right Markus?

To my understanding: As a leading element in qdev path, at least to
address a device, maybe also to abbreviate only the beginning of a full
path (that's currently to major remaining open issue).

 
 By the way, if you send patches 09/23, 10/23, 15/23, (maybe) 16/23, 21/23
 and 22/23 in a different series, I could try pushing them in my next
 pull request.

Do they need rebasing? If not, feel free to pick them up as you like. My
series requires a v5 round anyway once discussion on path construction
finally came to an end.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



[Qemu-devel] [PATCH v2] Guest OS hangs on usb_add

2010-06-28 Thread TJ
This is a small patch to sligtly intelligentify usb device and
config descriptor parsing and to handle bug with certain usb
device (URC MX-950) reporting device desriptor length as 0x18
instead of 18 with added vendor_id/product_id check
---
 hw/usb.h|5 +
 usb-linux.c |   37 ++---
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/hw/usb.h b/hw/usb.h
index 00d2802..5c3528f 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -117,6 +117,11 @@
 #define USB_DT_INTERFACE   0x04
 #define USB_DT_ENDPOINT0x05

+#define USB_DT_DEVICE_LEN  18
+#define USB_DT_CONFIG_LEN  9
+#define USB_DT_INTERFACE_LEN   9
+#define USB_DT_ENDPOINT_LEN7
+
 #define USB_ENDPOINT_XFER_CONTROL  0
 #define USB_ENDPOINT_XFER_ISOC 1
 #define USB_ENDPOINT_XFER_BULK 2
diff --git a/usb-linux.c b/usb-linux.c
index 88273ff..2ac6562 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -288,7 +288,7 @@ static void async_cancel(USBPacket *unused, void *opaque)

 static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
 {
-int dev_descr_len, config_descr_len;
+int dev_descr_len, config_descr_total_len;
 int interface, nb_interfaces;
 int ret, i;

@@ -297,32 +297,39 @@ static int usb_host_claim_interfaces(USBHostDevice *dev,
int configuration)

 DPRINTF(husb: claiming interfaces. config %d\n, configuration);

-i = 0;
 dev_descr_len = dev-descr[0];
-if (dev_descr_len  dev-descr_len) {
+if (dev_descr_len == 0x18  dev-descr[ 8] == 0x47  dev-descr[ 9] == 
0x46
+   dev-descr[10] == 0x00  dev-descr[11] == 
0x30)
+dev_descr_len = USB_DT_DEVICE_LEN; /* for buggy MX-950 remote reporting
len in hex */
+
+if (dev_descr_len  dev-descr_len || dev_descr_len  USB_DT_DEVICE_LEN ||
dev-descr[1] != USB_DT_DEVICE) {
+fprintf(stderr, husb: invalid device descriptor\n);
 goto fail;
 }

-i += dev_descr_len;
-while (i  dev-descr_len) {
+for (i = dev_descr_len; i  dev-descr_len; ) {
 DPRINTF(husb: i is %d, descr_len is %d, dl %d, dt %d\n,
 i, dev-descr_len,
dev-descr[i], dev-descr[i+1]);

-if (dev-descr[i+1] != USB_DT_CONFIG) {
-i += dev-descr[i];
-continue;
+if (dev-descr[i]  2) {
+fprintf(stderr, husb: invalid descriptor\n);
+goto fail;
 }
-config_descr_len = dev-descr[i];
+if (dev-descr[i+1] == USB_DT_CONFIG) {
+config_descr_total_len = dev-descr[i+2] + (dev-descr[i+3]  8);

-printf(husb: config #%d need %d\n, dev-descr[i + 5], configuration);
+printf(husb: config #%d need %d\n, dev-descr[i + 5], 
configuration);

-if (configuration  0 || configuration == dev-descr[i + 5]) {
-configuration = dev-descr[i + 5];
-break;
-}
+if (configuration  0 || configuration == dev-descr[i + 5]) {
+configuration = dev-descr[i + 5];
+break;
+}

-i += config_descr_len;
+i += config_descr_total_len;
+}
+else
+i += dev-descr[i];
 }

 if (i = dev-descr_len) {



Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-28 Thread Jes Sorensen
On 06/25/10 19:34, Frank Arnold wrote:
 We are doing KVM testing, so it is Linux.
 
 What I did is putting lines like this somewhere into vl.c and
 os-posix.c:
 fprintf(stderr, os: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize);
 fprintf(stderr, vl: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize);
 
 Resulting in the following output on stderr:
 os: QEMU_OPTION_daemonize: 85
 vl: QEMU_OPTION_daemonize: 86
 
 No compile time errors. The preprocessing of qemu-options.h is done
 separately for both files. This results in a missing option definition
 for os-posix.c and discrepancy in the option enumeration.

Hi Frank,

I figured out what was causing it. qemu-options.def has an
#ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
being included. Pretty much every other #ifdef in qemu-options.def are
based on CONFIG_foo settings or things like _WIN32 which do not change
depending on header file inclusion.

I think the easiest fix is to just add sys/mmap.h to the include list in
os-posix.c, so I just posted a patch for that. Though, in principle we
really shouldn't base qemu-options.def settings on defines pulled in
from system header files.

Cheers,
Jes



Re: [Qemu-devel] [PATCH 0/7] poison TARGET_xxx for compile once object and header file cleanups

2010-06-28 Thread Blue Swirl
On Mon, Jun 28, 2010 at 8:20 AM, Paolo Bonzini pbonz...@redhat.com wrote:
 On 06/27/2010 09:32 PM, Blue Swirl wrote:

  From just clean up or type safety point of view, this is good stuff.
 But from architectural point of view, we should make it more difficult
 to use CPUState in device code, not easier. This may still be fine as
 a temporary measure, before all CPUState references have been removed.

 I don't see it at all as a temporary measure.  In theory, only devices
 compiled per-target would need access to CPUState, that's true.

There is no need for any device to have access to CPUState fields. All
such accesses are either poor design or a shortcut taken for
performance. The only device where the design calls for CPUState
access is vmmouse and even there we could avoid the direct access. In
all other cases, only board physical address size and CPU endianness
matters but these should be fixed at some point by a better bus
design.

 However,
 there are conflicting goals which make an opaque CPUState preferrable.

 First, converting devices such as APIC to qdev requires knowledge of
 CPUState in qdev, unless you want to keep DEFINE_PROP_PTR (whose removal is
 much more interesting) or sweep it under the void* blanket.  PICs are likely
 to have CPUState members, e.g. hw/pxa2xx_pic.c (and BTW indirect access via
 functions to these fields is making emulation a little bit slower).

One way to clean up PICs would be to use qemu_irq to signal CPU
interrupts, but there are probably others.


 Also, for things compiled in libhw that are not part of device code,
 requiring knowledge of CPUState is absolutely not problematic and the only
 alternative loses type-safety and so it is inferior.

Completely untrue. Devices (whether part of libhw etc. or not) have no
need (from architectural point of view) to access CPUState contents.
It's clearly problematic. It's also possible to get type safety
without CPUState references in the devices.

Anyway, as I mentioned earlier, I think it's OK to apply the series
(after the problems are fixed), because of the short term gains in
cleanups and type safety. But the goal must be to make all devices
independent of the CPU model. If we never reach that goal (for
example, because of the performance issues), I guess you would not be
sad.



[Qemu-devel] [PATCH] rename qemu_socket.h to qemu-socket.h for consistency

2010-06-28 Thread Chih-Min Chao

Signed-off-by: Chih-Min Chao cmc...@gmail.com
---
 aio.c|2 +-
 gdbstub.c|2 +-
 hw/lance.c   |2 +-
 hw/pcnet.c   |2 +-
 hw/virtio-9p.c   |2 +-
 migration-exec.c |2 +-
 migration-fd.c   |4 +-
 migration-tcp.c  |2 +-
 migration-unix.c |2 +-
 migration.c  |2 +-
 nbd.c|2 +-
 net.c|2 +-
 net/slirp.c  |2 +-
 net/socket.c |2 +-
 osdep.c  |2 +-
 qemu-char.c  |2 +-
 qemu-socket.h|   61 ++
 qemu-sockets.c   |2 +-
 qemu_socket.h|   61 --
 savevm.c |2 +-
 vl.c |2 +-
 vnc-tls.c|2 +-
 vnc.c|2 +-
 23 files changed, 83 insertions(+), 83 deletions(-)
 create mode 100644 qemu-socket.h
 delete mode 100644 qemu_socket.h

diff --git a/aio.c b/aio.c
index 2f08655..9d260d3 100644
--- a/aio.c
+++ b/aio.c
@@ -14,7 +14,7 @@
 #include qemu-common.h
 #include block.h
 #include qemu-queue.h
-#include qemu_socket.h
+#include qemu-socket.h
 
 typedef struct AioHandler AioHandler;
 
diff --git a/gdbstub.c b/gdbstub.c
index c1852c2..7eda76b 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -37,7 +37,7 @@
 
 #define MAX_PACKET_LENGTH 4096
 
-#include qemu_socket.h
+#include qemu-socket.h
 #include kvm.h
 
 
diff --git a/hw/lance.c b/hw/lance.c
index b6b04dd..a8ed73d 100644
--- a/hw/lance.c
+++ b/hw/lance.c
@@ -38,7 +38,7 @@
 #include sysbus.h
 #include net.h
 #include qemu-timer.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include sun4m.h
 
 #include pcnet.h
diff --git a/hw/pcnet.c b/hw/pcnet.c
index 5e63eb5..791b5db 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -39,7 +39,7 @@
 #include net.h
 #include loader.h
 #include qemu-timer.h
-#include qemu_socket.h
+#include qemu-socket.h
 
 #include pcnet.h
 
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index f8c85c3..683452b 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -13,7 +13,7 @@
 
 #include virtio.h
 #include pc.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include virtio-9p.h
 #include fsdev/qemu-fsdev.h
 #include virtio-9p-debug.h
diff --git a/migration-exec.c b/migration-exec.c
index 14718dd..2504f7a 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -14,7 +14,7 @@
  */
 
 #include qemu-common.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include migration.h
 #include qemu-char.h
 #include sysemu.h
diff --git a/migration-fd.c b/migration-fd.c
index 6d14505..564adf9 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -12,14 +12,14 @@
  */
 
 #include qemu-common.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include migration.h
 #include monitor.h
 #include qemu-char.h
 #include sysemu.h
 #include buffered_file.h
 #include block.h
-#include qemu_socket.h
+#include qemu-socket.h
 
 //#define DEBUG_MIGRATION_FD
 
diff --git a/migration-tcp.c b/migration-tcp.c
index 78b56dc..aefefa9 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -12,7 +12,7 @@
  */
 
 #include qemu-common.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include migration.h
 #include qemu-char.h
 #include sysemu.h
diff --git a/migration-unix.c b/migration-unix.c
index 57232c0..52471fa 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -12,7 +12,7 @@
  */
 
 #include qemu-common.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include migration.h
 #include qemu-char.h
 #include sysemu.h
diff --git a/migration.c b/migration.c
index b49964c..0ddc175 100644
--- a/migration.c
+++ b/migration.c
@@ -17,7 +17,7 @@
 #include buffered_file.h
 #include sysemu.h
 #include block.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include block-migration.h
 #include qemu-objects.h
 
diff --git a/nbd.c b/nbd.c
index a9f295f..df5eb95 100644
--- a/nbd.c
+++ b/nbd.c
@@ -29,7 +29,7 @@
 #include ctype.h
 #include inttypes.h
 
-#include qemu_socket.h
+#include qemu-socket.h
 
 //#define DEBUG_NBD
 
diff --git a/net.c b/net.c
index 0703698..7d4404e 100644
--- a/net.c
+++ b/net.c
@@ -34,7 +34,7 @@
 #include monitor.h
 #include sysemu.h
 #include qemu-common.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include hw/qdev.h
 
 static QTAILQ_HEAD(, VLANState) vlans;
diff --git a/net/slirp.c b/net/slirp.c
index b41c60a..7bb7312 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -31,7 +31,7 @@
 #include net.h
 #include monitor.h
 #include sysemu.h
-#include qemu_socket.h
+#include qemu-socket.h
 #include slirp/libslirp.h
 
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
diff --git a/net/socket.c b/net/socket.c
index 1c4e153..422c58a 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -30,7 +30,7 @@
 #include qemu-common.h
 #include qemu-error.h
 #include qemu-option.h
-#include qemu_socket.h
+#include qemu-socket.h
 
 typedef struct NetSocketState {
 VLANClientState nc;
diff --git a/osdep.c b/osdep.c
index dbf872a..25e6c07 100644
--- a/osdep.c
+++ b/osdep.c
@@ -51,7 +51,7 @@
 
 

Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-28 Thread Blue Swirl
On Mon, Jun 28, 2010 at 2:50 PM, Jes Sorensen jes.soren...@redhat.com wrote:
 On 06/25/10 19:34, Frank Arnold wrote:
 We are doing KVM testing, so it is Linux.

 What I did is putting lines like this somewhere into vl.c and
 os-posix.c:
 fprintf(stderr, os: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize);
 fprintf(stderr, vl: QEMU_OPTION_daemonize: %i, QEMU_OPTION_daemonize);

 Resulting in the following output on stderr:
 os: QEMU_OPTION_daemonize: 85
 vl: QEMU_OPTION_daemonize: 86

 No compile time errors. The preprocessing of qemu-options.h is done
 separately for both files. This results in a missing option definition
 for os-posix.c and discrepancy in the option enumeration.

 Hi Frank,

 I figured out what was causing it. qemu-options.def has an
 #ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
 being included. Pretty much every other #ifdef in qemu-options.def are
 based on CONFIG_foo settings or things like _WIN32 which do not change
 depending on header file inclusion.

 I think the easiest fix is to just add sys/mmap.h to the include list in
 os-posix.c, so I just posted a patch for that. Though, in principle we
 really shouldn't base qemu-options.def settings on defines pulled in
 from system header files.

I think more flags should be added to arch_mask field, like
QEMU_ARCH_LINUX, QEMU_ARCH_POSIX and QEMU_ARCH_WIN32. Then the #ifdefs
should be removed. Prealloc command line flag stuff should be
conditional to CONFIG_LINUX only, there should be another check for
MAP_POPULATE where mem_preallocate is set.

Alternatively, we could have more arch_mask flags like QEMU_MAP_POPULATE.



[Qemu-devel] [PATCH 1/3] target-arm: fix addsub/subadd implementation

2010-06-28 Thread Chih-Min Chao

Signed-off-by: Chih-Min Chao cmc...@gmail.com
---
 target-arm/op_addsub.h |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/target-arm/op_addsub.h b/target-arm/op_addsub.h
index 29f77ba..c02c92a 100644
--- a/target-arm/op_addsub.h
+++ b/target-arm/op_addsub.h
@@ -73,8 +73,8 @@ uint32_t HELPER(glue(PFX,subaddx))(uint32_t a, uint32_t b 
GE_ARG)
 uint32_t res = 0;
 DECLARE_GE;
 
-ADD16(a, b, 0);
-SUB16(a  16, b  16, 1);
+ADD16(a, b  16, 0);
+SUB16(a  16, b, 1);
 SET_GE;
 return res;
 }
@@ -84,8 +84,8 @@ uint32_t HELPER(glue(PFX,addsubx))(uint32_t a, uint32_t b 
GE_ARG)
 uint32_t res = 0;
 DECLARE_GE;
 
-SUB16(a, b, 0);
-ADD16(a  16, b  16, 1);
+SUB16(a, b  16, 0);
+ADD16(a  16, b, 1);
 SET_GE;
 return res;
 }
-- 
1.7.0.4




[Qemu-devel] [PATCH 0/0] fix ARM parallel instructions implementation bug

2010-06-28 Thread Chih-Min Chao
 The three patches focuse on Bugs 595906  Bug 591320. The first is related to
 Bug 595906 and the other solve Bug 591320.

 The series are also attached in the threads, listed below
 https://bugs.launchpad.net/qemu/+bug/595906
 https://bugs.launchpad.net/qemu/+bug/591320

 [PATCH 1/3] target-arm: fix addsub/subadd implementation
 [PATCH 2/3] target-arm : fix thumb2 parallel add/sub opcode decoding
 [PATCH 3/3] target-arm : fix parallel saturated subtraction implementation



[Qemu-devel] [PATCH 3/3] target-arm : fix parallel saturated subtraction implementation

2010-06-28 Thread Chih-Min Chao

Signed-off-by: Chih-Min Chao cmc...@gmail.com
---
 target-arm/helper.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-arm/helper.c b/target-arm/helper.c
index 63e5dc7..2dd64d9 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -2047,7 +2047,7 @@ static inline uint16_t add16_usat(uint16_t a, uint16_t b)
 
 static inline uint16_t sub16_usat(uint16_t a, uint16_t b)
 {
-if (a  b)
+if (a  b)
 return a - b;
 else
 return 0;
@@ -2064,7 +2064,7 @@ static inline uint8_t add8_usat(uint8_t a, uint8_t b)
 
 static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
 {
-if (a  b)
+if (a  b)
 return a - b;
 else
 return 0;
-- 
1.7.0.4




[Qemu-devel] [PATCH 2/3] target-arm : fix thumb2 parallel add/sub opcode decoding ref : DDI0406B_arm_architecture_reference_manual_errata_markup_4_0.pdf section A6.3.1[34]

2010-06-28 Thread Chih-Min Chao

Signed-off-by: Chih-Min Chao cmc...@gmail.com
---
 target-arm/translate.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index a28e2ff..6fcdd7e 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -561,7 +561,7 @@ static void gen_arm_parallel_addsub(int op1, int op2, TCGv 
a, TCGv b)
 
 /* For unknown reasons Arm and Thumb-2 use arbitrarily different encodings.  */
 #define PAS_OP(pfx) \
-switch (op2) {  \
+switch (op1) {  \
 case 0: gen_pas_helper(glue(pfx,add8)); break; \
 case 1: gen_pas_helper(glue(pfx,add16)); break; \
 case 2: gen_pas_helper(glue(pfx,addsubx)); break; \
@@ -573,7 +573,7 @@ static void gen_thumb2_parallel_addsub(int op1, int op2, 
TCGv a, TCGv b)
 {
 TCGv_ptr tmp;
 
-switch (op1) {
+switch (op2) {
 #define gen_pas_helper(name) glue(gen_helper_,name)(a, a, b, tmp)
 case 0:
 tmp = tcg_temp_new_ptr();
-- 
1.7.0.4




[Qemu-devel] [PATCH 7/7] kvm: Fix cpu_is_bsp() compilation warning

2010-06-28 Thread Marcelo Tosatti
From: Sheng Yang sh...@linux.intel.com

Signed-off-by: Sheng Yang sh...@linux.intel.com
Signed-off-by: Avi Kivity a...@redhat.com
---
 target-i386/kvm.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 576d3b5..a33d2fa 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -25,6 +25,7 @@
 #include gdbstub.h
 #include host-utils.h
 #include hw/pc.h
+#include hw/apic.h
 #include ioport.h
 
 #ifdef CONFIG_KVM_PARA
-- 
1.6.6.1




[Qemu-devel] [PATCH 0/7] [PULL] qemu-kvm.git uq/master queue

2010-06-28 Thread Marcelo Tosatti
The following changes since commit 4972d592113c627d4b6ea1be5c94a85b56099afd:
  Stefan Weil (1):
win32: Add missing function ffs

are available in the git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

Andre Przywara (1):
  fix CPUID vendor override

Jan Kiszka (1):
  kvm: Switch kvm_update_guest_debug to run_on_cpu

Marcelo Tosatti (1):
  kvm: init mp_state

Sheng Yang (4):
  kvm: Extend kvm_arch_get_supported_cpuid() to support index
  Enable XSAVE related CPUID
  kvm: Enable XSAVE live migration support
  kvm: Fix cpu_is_bsp() compilation warning

 kvm-all.c |   33 +++---
 kvm.h |4 +-
 target-i386/cpu.h |7 ++-
 target-i386/cpuid.c   |   23 +++-
 target-i386/kvm.c |  165 ++---
 target-i386/machine.c |   20 ++
 6 files changed, 228 insertions(+), 24 deletions(-)



[Qemu-devel] [PATCH 4/7] Enable XSAVE related CPUID

2010-06-28 Thread Marcelo Tosatti
From: Sheng Yang sh...@linux.intel.com

We can support it in KVM now. The 0xd leaf is queried from KVM.

Signed-off-by: Sheng Yang sh...@linux.intel.com
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
---
 target-i386/cpuid.c |   21 +
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index fe0e6b2..83057bd 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -1087,6 +1087,27 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *ecx = 0;
 *edx = 0;
 break;
+case 0xD:
+/* Processor Extended State */
+if (!(env-cpuid_ext_features  CPUID_EXT_XSAVE)) {
+*eax = 0;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
+}
+if (kvm_enabled()) {
+*eax = kvm_arch_get_supported_cpuid(env, 0xd, count, R_EAX);
+*ebx = kvm_arch_get_supported_cpuid(env, 0xd, count, R_EBX);
+*ecx = kvm_arch_get_supported_cpuid(env, 0xd, count, R_ECX);
+*edx = kvm_arch_get_supported_cpuid(env, 0xd, count, R_EDX);
+} else {
+*eax = 0;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+}
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.6.6.1




[Qemu-devel] [PATCH 3/7] kvm: Extend kvm_arch_get_supported_cpuid() to support index

2010-06-28 Thread Marcelo Tosatti
From: Sheng Yang sh...@linux.intel.com

Would use it later for XSAVE related CPUID.

Signed-off-by: Sheng Yang sh...@linux.intel.com
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
---
 kvm.h |2 +-
 target-i386/kvm.c |   19 +++
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/kvm.h b/kvm.h
index a30529c..500e7e4 100644
--- a/kvm.h
+++ b/kvm.h
@@ -144,7 +144,7 @@ bool kvm_arch_stop_on_emulation_error(CPUState *env);
 int kvm_check_extension(KVMState *s, unsigned int extension);
 
 uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
-  int reg);
+  uint32_t index, int reg);
 void kvm_cpu_synchronize_state(CPUState *env);
 void kvm_cpu_synchronize_post_reset(CPUState *env);
 void kvm_cpu_synchronize_post_init(CPUState *env);
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 5453239..2b14ff5 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -71,7 +71,8 @@ static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max)
 return cpuid;
 }
 
-uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int 
reg)
+uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
+  uint32_t index, int reg)
 {
 struct kvm_cpuid2 *cpuid;
 int i, max;
@@ -88,7 +89,8 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t 
function, int reg)
 }
 
 for (i = 0; i  cpuid-nent; ++i) {
-if (cpuid-entries[i].function == function) {
+if (cpuid-entries[i].function == function 
+cpuid-entries[i].index == index) {
 switch (reg) {
 case R_EAX:
 ret = cpuid-entries[i].eax;
@@ -110,7 +112,7 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, 
uint32_t function, int reg)
 /* On Intel, kvm returns cpuid according to the Intel spec,
  * so add missing bits according to the AMD spec:
  */
-cpuid_1_edx = kvm_arch_get_supported_cpuid(env, 1, R_EDX);
+cpuid_1_edx = kvm_arch_get_supported_cpuid(env, 1, 0, 
R_EDX);
 ret |= cpuid_1_edx  0x183f7ff;
 break;
 }
@@ -126,7 +128,8 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, 
uint32_t function, int reg)
 
 #else
 
-uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int 
reg)
+uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
+  uint32_t index, int reg)
 {
 return -1U;
 }
@@ -178,16 +181,16 @@ int kvm_arch_init_vcpu(CPUState *env)
 
 env-mp_state = KVM_MP_STATE_RUNNABLE;
 
-env-cpuid_features = kvm_arch_get_supported_cpuid(env, 1, R_EDX);
+env-cpuid_features = kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX);
 
 i = env-cpuid_ext_features  CPUID_EXT_HYPERVISOR;
-env-cpuid_ext_features = kvm_arch_get_supported_cpuid(env, 1, R_ECX);
+env-cpuid_ext_features = kvm_arch_get_supported_cpuid(env, 1, 0, R_ECX);
 env-cpuid_ext_features |= i;
 
 env-cpuid_ext2_features = kvm_arch_get_supported_cpuid(env, 0x8001,
- R_EDX);
+ 0, R_EDX);
 env-cpuid_ext3_features = kvm_arch_get_supported_cpuid(env, 0x8001,
- R_ECX);
+ 0, R_ECX);
 
 cpuid_i = 0;
 
-- 
1.6.6.1




Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-28 Thread Blue Swirl
On Mon, Jun 28, 2010 at 4:03 PM, Jes Sorensen jes.soren...@redhat.com wrote:
 On 06/28/10 17:42, Blue Swirl wrote:
 On Mon, Jun 28, 2010 at 2:50 PM, Jes Sorensen jes.soren...@redhat.com 
 wrote:
 I figured out what was causing it. qemu-options.def has an
 #ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
 being included. Pretty much every other #ifdef in qemu-options.def are
 based on CONFIG_foo settings or things like _WIN32 which do not change
 depending on header file inclusion.

 I think the easiest fix is to just add sys/mmap.h to the include list in
 os-posix.c, so I just posted a patch for that. Though, in principle we
 really shouldn't base qemu-options.def settings on defines pulled in
 from system header files.

 I think more flags should be added to arch_mask field, like
 QEMU_ARCH_LINUX, QEMU_ARCH_POSIX and QEMU_ARCH_WIN32. Then the #ifdefs
 should be removed. Prealloc command line flag stuff should be
 conditional to CONFIG_LINUX only, there should be another check for
 MAP_POPULATE where mem_preallocate is set.

 Alternatively, we could have more arch_mask flags like QEMU_MAP_POPULATE.

 Yeah, the problem with tying it to CONFIG_LINUX is that older version of
 Linux may not support it. Looking through the list, MAP_POPULATE is
 really an oddball in there though, so maybe it would be cleaner to catch
 it via configure and then use CONFIG_MAP_POPULATE or something like that?

There'd be 1:1 relation between MAP_POPULATE and CONFIG_MAP_POPULATE,
so maybe not.



[Qemu-devel] [PATCH 2/7] fix CPUID vendor override

2010-06-28 Thread Marcelo Tosatti
From: Andre Przywara andre.przyw...@amd.com

the meaning of vendor_override is actually the opposite of how it
is currently used :-(
Fix it to allow KVM to export the non-native CPUID vendor if
explicitly requested by the user.

The intended behavior is:
With TCG:
  - always inject the configured vendor (either hard-coded, in config
files or via ,vendor= commandline)
With KVM:
  - by default inject the host's vendor
  - if the user specifies ,vendor= on the commandline, use this
instead of the host's vendor
  - all pre-configured vendors (hard-coded, config file) are ignored

Signed-off-by: Andre Przywara andre.przyw...@amd.com
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
---
 target-i386/cpuid.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 6a0f7ca..fe0e6b2 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -982,7 +982,7 @@ static void get_cpuid_vendor(CPUX86State *env, uint32_t 
*ebx,
  * this if you want to use KVM's sysenter/syscall emulation
  * in compatibility mode and when doing cross vendor migration
  */
-if (kvm_enabled()  env-cpuid_vendor_override) {
+if (kvm_enabled()  ! env-cpuid_vendor_override) {
 host_cpuid(0, 0, NULL, ebx, ecx, edx);
 }
 }
-- 
1.6.6.1




Re: [Qemu-devel] [PATCH v4 11/23] monitor: Add completion support for option lists

2010-06-28 Thread Luiz Capitulino
On Mon, 28 Jun 2010 16:40:58 +0200
Jan Kiszka jan.kis...@siemens.com wrote:

 Luiz Capitulino wrote:
  On Wed, 23 Jun 2010 12:28:27 +0200
  Jan Kiszka jan.kis...@siemens.com wrote:
  
  Markus Armbruster wrote:
  Jan Kiszka jan.kis...@web.de writes:
 
  From: Jan Kiszka jan.kis...@siemens.com
 
  This enables command line completion inside option strings. A list of
  expected key names and their completion type can be appended to the 'O'
  inside parentheses ('O(key:type,...)'). The first use case is block
  device completion for the 'drive' option of 'device_add'.
 
  Signed-off-by: Jan Kiszka jan.kis...@siemens.com
  ---
   monitor.c   |   68 
  ++-
   qemu-monitor.hx |2 +-
   2 files changed, 58 insertions(+), 12 deletions(-)
 
  diff --git a/monitor.c b/monitor.c
  index c1006b4..3e0d862 100644
  --- a/monitor.c
  +++ b/monitor.c
  @@ -68,6 +68,9 @@
* 'O'  option string of the form NAME=VALUE,...
*  parsed according to QemuOptsList given by its name
*  Example: 'device:O' uses qemu_device_opts.
  + *  Command completion for specific keys can be requested 
  via
  + *  appending '(NAME:TYPE,...)' with 'F', 'B' as type.
  + *  Example: 'device:O(bus:Q)' to expand 'bus=...' as qtree 
  path.
*  Restriction: only lists with empty desc are supported
*  TODO lift the restriction
* 'i'  32 bit integer
  Ugh.
 
  Replacement of args_type by a proper data structure is long overdue.  We
  keep piling features into that poor, hapless string.
 
  Information on how to complete QemuOptsList options arguably belongs
  into the option description, i.e. QemuOptDesc.
  For sure, that would be better. I just wonder how much of it should be
  stuffed into this series. I guess I will drop this part for now, just
  focusing on what device_show makes direct use of. Same for separate args
  for HMP and QMP.
  
  IIRC, the separate args idea use case was to allow commands like device_del
  to have an ID argument and a path argument, right? If so, I think it doesn't
  matter anymore as we have agreed on having a device argument which would
  accept both, even under QMP, right Markus?
 
 To my understanding: As a leading element in qdev path, at least to
 address a device, maybe also to abbreviate only the beginning of a full
 path (that's currently to major remaining open issue).

I'm ok with it if it's unambiguous.

  By the way, if you send patches 09/23, 10/23, 15/23, (maybe) 16/23, 21/23
  and 22/23 in a different series, I could try pushing them in my next
  pull request.
 
 Do they need rebasing? If not, feel free to pick them up as you like. My
 series requires a v5 round anyway once discussion on path construction
 finally came to an end.

Done for them all, except 16/23 which mentions device_show in the changelog.

I should send a pull request until this Wednesday.



[Qemu-devel] [PATCH] monitor: Allow to exclude commands from QMP

2010-06-28 Thread Jan Kiszka
Luiz Capitulino wrote:
 On Mon, 28 Jun 2010 16:40:58 +0200
 Jan Kiszka jan.kis...@siemens.com wrote:
 
 Luiz Capitulino wrote:
 On Wed, 23 Jun 2010 12:28:27 +0200
 Jan Kiszka jan.kis...@siemens.com wrote:

 Markus Armbruster wrote:
 Jan Kiszka jan.kis...@web.de writes:

 From: Jan Kiszka jan.kis...@siemens.com

 This enables command line completion inside option strings. A list of
 expected key names and their completion type can be appended to the 'O'
 inside parentheses ('O(key:type,...)'). The first use case is block
 device completion for the 'drive' option of 'device_add'.

 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---
  monitor.c   |   68 
 ++-
  qemu-monitor.hx |2 +-
  2 files changed, 58 insertions(+), 12 deletions(-)

 diff --git a/monitor.c b/monitor.c
 index c1006b4..3e0d862 100644
 --- a/monitor.c
 +++ b/monitor.c
 @@ -68,6 +68,9 @@
   * 'O'  option string of the form NAME=VALUE,...
   *  parsed according to QemuOptsList given by its name
   *  Example: 'device:O' uses qemu_device_opts.
 + *  Command completion for specific keys can be requested 
 via
 + *  appending '(NAME:TYPE,...)' with 'F', 'B' as type.
 + *  Example: 'device:O(bus:Q)' to expand 'bus=...' as qtree 
 path.
   *  Restriction: only lists with empty desc are supported
   *  TODO lift the restriction
   * 'i'  32 bit integer
 Ugh.

 Replacement of args_type by a proper data structure is long overdue.  We
 keep piling features into that poor, hapless string.

 Information on how to complete QemuOptsList options arguably belongs
 into the option description, i.e. QemuOptDesc.
 For sure, that would be better. I just wonder how much of it should be
 stuffed into this series. I guess I will drop this part for now, just
 focusing on what device_show makes direct use of. Same for separate args
 for HMP and QMP.
 IIRC, the separate args idea use case was to allow commands like device_del
 to have an ID argument and a path argument, right? If so, I think it doesn't
 matter anymore as we have agreed on having a device argument which would
 accept both, even under QMP, right Markus?
 To my understanding: As a leading element in qdev path, at least to
 address a device, maybe also to abbreviate only the beginning of a full
 path (that's currently to major remaining open issue).
 
 I'm ok with it if it's unambiguous.
 
 By the way, if you send patches 09/23, 10/23, 15/23, (maybe) 16/23, 21/23
 and 22/23 in a different series, I could try pushing them in my next
 pull request.
 Do they need rebasing? If not, feel free to pick them up as you like. My
 series requires a v5 round anyway once discussion on path construction
 finally came to an end.
 
 Done for them all, except 16/23 which mentions device_show in the changelog.

If that's the only issue of 16/23, feel free to pick up the cleaned
version below.

 
 I should send a pull request until this Wednesday.

Great, thanks.

Jan

--

Ported commands that are marked 'user_only' will not be considered for
QMP monitor sessions. This allows to implement new commands that do not
(yet) provide a sufficiently stable interface for QMP use.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
---

For Luiz' queue, depends on monitor: Establish cmd flags and convert
the async tag as posted earlier.

 monitor.c |   18 +++---
 monitor.h |1 +
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/monitor.c b/monitor.c
index 281a6f2..99c07d2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -330,6 +330,11 @@ static inline bool monitor_handler_is_async(const 
mon_cmd_t *cmd)
 return cmd-flags  MONITOR_CMD_ASYNC;
 }
 
+static inline bool monitor_cmd_user_only(const mon_cmd_t *cmd)
+{
+return (cmd-flags  MONITOR_CMD_USER_ONLY);
+}
+
 static inline int monitor_has_error(const Monitor *mon)
 {
 return mon-error != NULL;
@@ -612,6 +617,11 @@ static int do_info(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 goto help;
 }
 
+if (monitor_ctrl_mode(mon)  monitor_cmd_user_only(cmd)) {
+qerror_report(QERR_COMMAND_NOT_FOUND, item);
+return -1;
+}
+
 if (monitor_handler_is_async(cmd)) {
 if (monitor_ctrl_mode(mon)) {
 qmp_async_info_handler(mon, cmd);
@@ -709,13 +719,14 @@ static void do_info_commands(Monitor *mon, QObject 
**ret_data)
 cmd_list = qlist_new();
 
 for (cmd = mon_cmds; cmd-name != NULL; cmd++) {
-if (monitor_handler_ported(cmd)  !compare_cmd(cmd-name, info)) {
+if (monitor_handler_ported(cmd)  !monitor_cmd_user_only(cmd) 
+!compare_cmd(cmd-name, info)) {
 qlist_append_obj(cmd_list, get_cmd_dict(cmd-name));
 }
 }
 
 for (cmd = info_cmds; cmd-name != NULL; cmd++) {
-if (monitor_handler_ported(cmd)) {
+if (monitor_handler_ported(cmd)  

[Qemu-devel] [PATCH 6/7] kvm: init mp_state

2010-06-28 Thread Marcelo Tosatti
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
Signed-off-by: Avi Kivity a...@redhat.com
---
 target-i386/kvm.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 436c0c4..576d3b5 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -282,6 +282,12 @@ void kvm_arch_reset_vcpu(CPUState *env)
 env-interrupt_injected = -1;
 env-nmi_injected = 0;
 env-nmi_pending = 0;
+if (kvm_irqchip_in_kernel()) {
+env-mp_state = cpu_is_bsp(env) ? KVM_MP_STATE_RUNNABLE :
+  KVM_MP_STATE_UNINITIALIZED;
+} else {
+env-mp_state = KVM_MP_STATE_RUNNABLE;
+}
 }
 
 static int kvm_has_msr_star(CPUState *env)
-- 
1.6.6.1




[Qemu-devel] [PATCH 1/7] kvm: Switch kvm_update_guest_debug to run_on_cpu

2010-06-28 Thread Marcelo Tosatti
From: Jan Kiszka jan.kis...@siemens.com

Guest debugging under KVM is currently broken once io-threads are
enabled. Easily fixable by switching the fake on_vcpu to the real
run_on_cpu implementation.

Signed-off-by: Jan Kiszka jan.kis...@siemens.com
Signed-off-by: Avi Kivity a...@redhat.com
---
 kvm-all.c |   12 +---
 1 files changed, 1 insertions(+), 11 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index c238f54..5684e51 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1033,16 +1033,6 @@ void kvm_setup_guest_memory(void *start, size_t size)
 }
 
 #ifdef KVM_CAP_SET_GUEST_DEBUG
-static void on_vcpu(CPUState *env, void (*func)(void *data), void *data)
-{
-#ifdef CONFIG_IOTHREAD
-if (env != cpu_single_env) {
-abort();
-}
-#endif
-func(data);
-}
-
 struct kvm_sw_breakpoint *kvm_find_sw_breakpoint(CPUState *env,
  target_ulong pc)
 {
@@ -1086,7 +1076,7 @@ int kvm_update_guest_debug(CPUState *env, unsigned long 
reinject_trap)
 kvm_arch_update_guest_debug(env, data.dbg);
 data.env = env;
 
-on_vcpu(env, kvm_invoke_set_guest_debug, data);
+run_on_cpu(env, kvm_invoke_set_guest_debug, data);
 return data.err;
 }
 
-- 
1.6.6.1




[Qemu-devel] [PATCH 5/7] kvm: Enable XSAVE live migration support

2010-06-28 Thread Marcelo Tosatti
From: Sheng Yang sh...@linux.intel.com

Signed-off-by: Sheng Yang sh...@linux.intel.com
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com
---
 kvm-all.c |   21 +++
 kvm.h |2 +
 target-i386/cpu.h |7 ++-
 target-i386/kvm.c |  139 -
 target-i386/machine.c |   20 +++
 5 files changed, 186 insertions(+), 3 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 5684e51..9380302 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -71,6 +71,7 @@ struct KVMState
 #endif
 int irqchip_in_kernel;
 int pit_in_kernel;
+int xsave, xcrs;
 };
 
 static KVMState *kvm_state;
@@ -686,6 +687,16 @@ int kvm_init(int smp_cpus)
 s-debugregs = kvm_check_extension(s, KVM_CAP_DEBUGREGS);
 #endif
 
+s-xsave = 0;
+#ifdef KVM_CAP_XSAVE
+s-xsave = kvm_check_extension(s, KVM_CAP_XSAVE);
+#endif
+
+s-xcrs = 0;
+#ifdef KVM_CAP_XCRS
+s-xcrs = kvm_check_extension(s, KVM_CAP_XCRS);
+#endif
+
 ret = kvm_arch_init(s, smp_cpus);
 if (ret  0)
 goto err;
@@ -1014,6 +1025,16 @@ int kvm_has_debugregs(void)
 return kvm_state-debugregs;
 }
 
+int kvm_has_xsave(void)
+{
+return kvm_state-xsave;
+}
+
+int kvm_has_xcrs(void)
+{
+return kvm_state-xcrs;
+}
+
 void kvm_setup_guest_memory(void *start, size_t size)
 {
 if (!kvm_has_sync_mmu()) {
diff --git a/kvm.h b/kvm.h
index 500e7e4..93f8187 100644
--- a/kvm.h
+++ b/kvm.h
@@ -40,6 +40,8 @@ int kvm_has_sync_mmu(void);
 int kvm_has_vcpu_events(void);
 int kvm_has_robust_singlestep(void);
 int kvm_has_debugregs(void);
+int kvm_has_xsave(void);
+int kvm_has_xcrs(void);
 
 #ifdef NEED_CPU_H
 int kvm_init_vcpu(CPUState *env);
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 8dafa0d..4de486e 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -718,6 +718,11 @@ typedef struct CPUX86State {
 uint16_t fpus_vmstate;
 uint16_t fptag_vmstate;
 uint16_t fpregs_format_vmstate;
+
+uint64_t xstate_bv;
+XMMReg ymmh_regs[CPU_NB_REGS];
+
+uint64_t xcr0;
 } CPUX86State;
 
 CPUX86State *cpu_x86_init(const char *cpu_model);
@@ -899,7 +904,7 @@ uint64_t cpu_get_tsc(CPUX86State *env);
 #define cpu_list_id x86_cpu_list
 #define cpudef_setup   x86_cpudef_setup
 
-#define CPU_SAVE_VERSION 11
+#define CPU_SAVE_VERSION 12
 
 /* MMU modes definitions */
 #define MMU_MODE0_SUFFIX _kernel
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 2b14ff5..436c0c4 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -497,6 +497,68 @@ static int kvm_put_fpu(CPUState *env)
 return kvm_vcpu_ioctl(env, KVM_SET_FPU, fpu);
 }
 
+#ifdef KVM_CAP_XSAVE
+#define XSAVE_CWD_RIP 2
+#define XSAVE_CWD_RDP 4
+#define XSAVE_MXCSR   6
+#define XSAVE_ST_SPACE8
+#define XSAVE_XMM_SPACE   40
+#define XSAVE_XSTATE_BV   128
+#define XSAVE_YMMH_SPACE  144
+#endif
+
+static int kvm_put_xsave(CPUState *env)
+{
+#ifdef KVM_CAP_XSAVE
+int i;
+struct kvm_xsave* xsave;
+uint16_t cwd, swd, twd, fop;
+
+if (!kvm_has_xsave())
+return kvm_put_fpu(env);
+
+xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
+memset(xsave, 0, sizeof(struct kvm_xsave));
+cwd = swd = twd = fop = 0;
+swd = env-fpus  ~(7  11);
+swd |= (env-fpstt  7)  11;
+cwd = env-fpuc;
+for (i = 0; i  8; ++i)
+twd |= (!env-fptags[i])  i;
+xsave-region[0] = (uint32_t)(swd  16) + cwd;
+xsave-region[1] = (uint32_t)(fop  16) + twd;
+memcpy(xsave-region[XSAVE_ST_SPACE], env-fpregs,
+sizeof env-fpregs);
+memcpy(xsave-region[XSAVE_XMM_SPACE], env-xmm_regs,
+sizeof env-xmm_regs);
+xsave-region[XSAVE_MXCSR] = env-mxcsr;
+*(uint64_t *)xsave-region[XSAVE_XSTATE_BV] = env-xstate_bv;
+memcpy(xsave-region[XSAVE_YMMH_SPACE], env-ymmh_regs,
+sizeof env-ymmh_regs);
+return kvm_vcpu_ioctl(env, KVM_SET_XSAVE, xsave);
+#else
+return kvm_put_fpu(env);
+#endif
+}
+
+static int kvm_put_xcrs(CPUState *env)
+{
+#ifdef KVM_CAP_XCRS
+struct kvm_xcrs xcrs;
+
+if (!kvm_has_xcrs())
+return 0;
+
+xcrs.nr_xcrs = 1;
+xcrs.flags = 0;
+xcrs.xcrs[0].xcr = 0;
+xcrs.xcrs[0].value = env-xcr0;
+return kvm_vcpu_ioctl(env, KVM_SET_XCRS, xcrs);
+#else
+return 0;
+#endif
+}
+
 static int kvm_put_sregs(CPUState *env)
 {
 struct kvm_sregs sregs;
@@ -614,6 +676,69 @@ static int kvm_get_fpu(CPUState *env)
 return 0;
 }
 
+static int kvm_get_xsave(CPUState *env)
+{
+#ifdef KVM_CAP_XSAVE
+struct kvm_xsave* xsave;
+int ret, i;
+uint16_t cwd, swd, twd, fop;
+
+if (!kvm_has_xsave())
+return kvm_get_fpu(env);
+
+xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
+ret = kvm_vcpu_ioctl(env, KVM_GET_XSAVE, xsave);
+if (ret  0)
+return ret;
+
+cwd = (uint16_t)xsave-region[0];
+swd = (uint16_t)(xsave-region[0]  16);
+twd = (uint16_t)xsave-region[1];
+fop = (uint16_t)(xsave-region[1]  16);
+env-fpstt = (swd  

[Qemu-devel] Re: [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-28 Thread Paolo Bonzini

On 06/28/2010 06:03 PM, Jes Sorensen wrote:

On 06/28/10 17:42, Blue Swirl wrote:

On Mon, Jun 28, 2010 at 2:50 PM, Jes Sorensenjes.soren...@redhat.com  wrote:

I figured out what was causing it. qemu-options.def has an
#ifdef MAP_POPULATE in it, which isn't being set without sys/mmap.h
being included. Pretty much every other #ifdef in qemu-options.def are
based on CONFIG_foo settings or things like _WIN32 which do not change
depending on header file inclusion.

I think the easiest fix is to just add sys/mmap.h to the include list in
os-posix.c, so I just posted a patch for that. Though, in principle we
really shouldn't base qemu-options.def settings on defines pulled in
from system header files.


I think more flags should be added to arch_mask field, like
QEMU_ARCH_LINUX, QEMU_ARCH_POSIX and QEMU_ARCH_WIN32. Then the #ifdefs
should be removed. Prealloc command line flag stuff should be
conditional to CONFIG_LINUX only, there should be another check for
MAP_POPULATE where mem_preallocate is set.

Alternatively, we could have more arch_mask flags like QEMU_MAP_POPULATE.


Yeah, the problem with tying it to CONFIG_LINUX is that older version of
Linux may not support it. Looking through the list, MAP_POPULATE is
really an oddball in there though, so maybe it would be cleaner to catch
it via configure and then use CONFIG_MAP_POPULATE or something like that?


Or create a header file system.h that pulls all we need from the system, 
and remove (almost) all ... includes from elsewhere.


Paolo



Re: [Qemu-devel] [PATCH 0/7] poison TARGET_xxx for compile once object and header file cleanups

2010-06-28 Thread Paolo Bonzini

I don't see it at all as a temporary measure.  In theory, only devices
compiled per-target would need access to CPUState, that's true.


There is no need for any device to have access to CPUState fields.


That's why this patch defines CPUState as opaque (i.e. incomplete). 
Granted, an opaque CPUState plus a bunch of accessors is not any better 
than a fully-visible CPUState, if the accessors are very much tied to 
that particular CPUState type.  (But then, we also agree it is also a 
tiny little bit better than void*).



First, converting devices such as APIC to qdev requires knowledge of
CPUState in qdev, unless you want to keep DEFINE_PROP_PTR (whose removal is
much more interesting) or sweep it under the void* blanket.  PICs are likely
to have CPUState members, e.g. hw/pxa2xx_pic.c (and BTW indirect access via
functions to these fields is making emulation a little bit slower).


One way to clean up PICs would be to use qemu_irq to signal CPU
interrupts, but there are probably others.


In the end the devices will be wired to a particular CPU and these 
wires will likely be more complex than a 1-bit IRQ, so qemu_irq only 
makes limited sense as it is now.


What you have to pass may be simply a 32-bit value as in hw/etraxfs_pic, 
or a more complicated payload as in apic_bus_deliver, but anyway at some 
point you'll be coupling either:


- the device to the CPU, as it happens now.  As above, the CPU may be 
accessed via void* and functions, or via fields directly, but in any 
case the coupling is there.


- the CPU to the device.  If you used qemu_irq that would be the most 
likely outcome: the CPU knows about some DeviceState, and it downcasts 
it to an expected device type in the IRQ handler.  Again, you only have 
an illusion of decoupling and, given the lengthy discussion about IRQ 
payloads on qemu-devel only a few weeks ago, I'm not optimist it's going 
to go away.



Also, for things compiled in libhw that are not part of device code,
requiring knowledge of CPUState is absolutely not problematic and the only
alternative loses type-safety and so it is inferior.


Completely untrue. Devices (whether part of libhw etc. or not) have no
need (from architectural point of view) to access CPUState contents.
It's clearly problematic. It's also possible to get type safety
without CPUState references in the devices.


I explicitly said things compiled in libhw that are not part of device 
code, most of which you added.


Anyway, thanks for the review and the (partial) ack.  I'll rework the 
patch series and resend.


Paolo



Re: [Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-28 Thread Jes Sorensen
On 06/28/10 18:20, Blue Swirl wrote:
 On Mon, Jun 28, 2010 at 4:03 PM, Jes Sorensen jes.soren...@redhat.com wrote:
 Yeah, the problem with tying it to CONFIG_LINUX is that older version of
 Linux may not support it. Looking through the list, MAP_POPULATE is
 really an oddball in there though, so maybe it would be cleaner to catch
 it via configure and then use CONFIG_MAP_POPULATE or something like that?
 
 There'd be 1:1 relation between MAP_POPULATE and CONFIG_MAP_POPULATE,
 so maybe not.

That is correct, but CONFIG_MAP_POPULATE would be in config.h so it
would not get missed out in cases where someone includes qemu-options.h
without including sys/mmap.h first. But it is a corner case, so my patch
should be fine.

Cheers,
Jes



[Qemu-devel] [PATCH 0/4] introduce NEED_GLOBAL_ENV

2010-06-28 Thread Paolo Bonzini
Let's start the cleanups from the feature required by Blue Swirl.
I also include here a baby step towards removing eminently TCG-related
stuff from cpu.h.

After this series, only a bunch of files will include exec-all.h,
instead of getting it indirectly from cpu.h.

Note that (as sworn in the previous submission) exec.h is only included
by files that need the global register variable (i.e. cpu-exec.c and
target-*/op_helper.c), and this is the same subset that gets
NEED_GLOBAL_ENV in this patchset.

i386 and sparc have functions declared in cpu.h that are in op_helper.c.
I checked that these do not need the global variable, but it would be
nice to cleanup those too.

Paolo Bonzini (4):
  remove unused stuff from */exec.h
  move cpu_pc_from_tb to target-*/exec.h
  remove exec-all.h inclusion from cpu.h
  require #define NEED_GLOBAL_ENV for files that need the global
register variable

 cpu-exec.c|2 ++
 exec-all.h|4 
 gdbstub.c |1 +
 hw/xen_domainbuild.c  |1 +
 kvm-stub.c|1 +
 monitor.c |1 +
 target-alpha/cpu.h|6 --
 target-alpha/exec.h   |9 +
 target-alpha/op_helper.c  |1 +
 target-arm/cpu.h  |6 --
 target-arm/exec.h |8 ++--
 target-arm/op_helper.c|1 +
 target-cris/cpu.h |6 --
 target-cris/exec.h|   11 ++-
 target-cris/op_helper.c   |1 +
 target-i386/cpu.h |7 ---
 target-i386/exec.h|   17 ++---
 target-i386/op_helper.c   |3 ++-
 target-m68k/cpu.h |6 --
 target-m68k/exec.h|8 ++--
 target-m68k/op_helper.c   |2 ++
 target-microblaze/cpu.h   |6 --
 target-microblaze/exec.h  |   10 ++
 target-microblaze/op_helper.c |1 +
 target-mips/cpu.h |8 
 target-mips/exec.h|   17 +++--
 target-mips/op_helper.c   |7 +++
 target-ppc/cpu.h  |6 --
 target-ppc/exec.h |7 +--
 target-ppc/op_helper.c|2 ++
 target-s390x/cpu.h|6 --
 target-s390x/exec.h   |8 ++--
 target-s390x/op_helper.c  |1 +
 target-sh4/cpu.h  |7 ---
 target-sh4/exec.h |8 ++--
 target-sh4/op_helper.c|2 ++
 target-sparc/cpu.h|7 ---
 target-sparc/exec.h   |8 ++--
 target-sparc/op_helper.c  |1 +
 39 files changed, 96 insertions(+), 118 deletions(-)




[Qemu-devel] [PATCH 4/4] require #define NEED_GLOBAL_ENV for files that need the global register variable

2010-06-28 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpu-exec.c|2 ++
 exec-all.h|4 
 target-alpha/exec.h   |2 --
 target-alpha/op_helper.c  |1 +
 target-arm/exec.h |2 --
 target-arm/op_helper.c|1 +
 target-cris/exec.h|2 --
 target-cris/op_helper.c   |1 +
 target-i386/exec.h|2 --
 target-i386/op_helper.c   |1 +
 target-m68k/exec.h|2 --
 target-m68k/op_helper.c   |2 ++
 target-microblaze/exec.h  |2 --
 target-microblaze/op_helper.c |1 +
 target-mips/exec.h|2 --
 target-mips/op_helper.c   |2 ++
 target-ppc/exec.h |2 --
 target-ppc/op_helper.c|2 ++
 target-s390x/exec.h   |2 --
 target-s390x/op_helper.c  |1 +
 target-sh4/exec.h |2 --
 target-sh4/op_helper.c|2 ++
 target-sparc/exec.h   |2 --
 target-sparc/op_helper.c  |1 +
 24 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/cpu-exec.c b/cpu-exec.c
index 026980a..5d5170f 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -16,7 +16,9 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see http://www.gnu.org/licenses/.
  */
+
 #include config.h
+#define NEED_GLOBAL_ENV
 #include exec.h
 #include disas.h
 #include tcg.h
diff --git a/exec-all.h b/exec-all.h
index a775582..ebe88ad 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -353,4 +353,8 @@ extern int singlestep;
 /* cpu-exec.c */
 extern volatile sig_atomic_t exit_request;
 
+#ifdef NEED_GLOBAL_ENV
+register CPUState *env asm(AREG0);
+#endif
+
 #endif
diff --git a/target-alpha/exec.h b/target-alpha/exec.h
index a8a38d2..1950f83 100644
--- a/target-alpha/exec.h
+++ b/target-alpha/exec.h
@@ -26,8 +26,6 @@
 
 #define TARGET_LONG_BITS 64
 
-register struct CPUAlphaState *env asm(AREG0);
-
 #define FP_STATUS (env-fp_status)
 
 #include cpu.h
diff --git a/target-alpha/op_helper.c b/target-alpha/op_helper.c
index ff5ae26..9870d97 100644
--- a/target-alpha/op_helper.c
+++ b/target-alpha/op_helper.c
@@ -17,6 +17,7 @@
  * License along with this library; if not, see http://www.gnu.org/licenses/.
  */
 
+#define NEED_GLOBAL_ENV
 #include exec.h
 #include host-utils.h
 #include softfloat.h
diff --git a/target-arm/exec.h b/target-arm/exec.h
index e4c35a3..eda5632 100644
--- a/target-arm/exec.h
+++ b/target-arm/exec.h
@@ -19,8 +19,6 @@
 #include config.h
 #include dyngen-exec.h
 
-register struct CPUARMState *env asm(AREG0);
-
 #define M0   env-iwmmxt.val
 
 #include cpu.h
diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c
index 9b1a014..235cffc 100644
--- a/target-arm/op_helper.c
+++ b/target-arm/op_helper.c
@@ -16,6 +16,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see http://www.gnu.org/licenses/.
  */
+#define NEED_GLOBAL_ENV
 #include exec.h
 #include helpers.h
 
diff --git a/target-cris/exec.h b/target-cris/exec.h
index 93ce768..360f45a 100644
--- a/target-cris/exec.h
+++ b/target-cris/exec.h
@@ -19,8 +19,6 @@
  */
 #include dyngen-exec.h
 
-register struct CPUCRISState *env asm(AREG0);
-
 #include cpu.h
 #include exec-all.h
 
diff --git a/target-cris/op_helper.c b/target-cris/op_helper.c
index a60da94..8bb3876 100644
--- a/target-cris/op_helper.c
+++ b/target-cris/op_helper.c
@@ -18,6 +18,7 @@
  * License along with this library; if not, see http://www.gnu.org/licenses/.
  */
 
+#define NEED_GLOBAL_ENV
 #include exec.h
 #include mmu.h
 #include helper.h
diff --git a/target-i386/exec.h b/target-i386/exec.h
index 04a566f..63f2363 100644
--- a/target-i386/exec.h
+++ b/target-i386/exec.h
@@ -28,8 +28,6 @@
 
 #include cpu-defs.h
 
-register struct CPUX86State *env asm(AREG0);
-
 #include qemu-common.h
 #include qemu-log.h
 
diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index 00fc671..05b6340 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -17,6 +17,7 @@
  * License along with this library; if not, see http://www.gnu.org/licenses/.
  */
 
+#define NEED_GLOBAL_ENV
 #include exec.h
 #include exec-all.h
 #include host-utils.h
diff --git a/target-m68k/exec.h b/target-m68k/exec.h
index f31e06e..ac1cf12 100644
--- a/target-m68k/exec.h
+++ b/target-m68k/exec.h
@@ -19,8 +19,6 @@
  */
 #include dyngen-exec.h
 
-register struct CPUM68KState *env asm(AREG0);
-
 #include cpu.h
 #include exec-all.h
 
diff --git a/target-m68k/op_helper.c b/target-m68k/op_helper.c
index 0711107..df4489f 100644
--- a/target-m68k/op_helper.c
+++ b/target-m68k/op_helper.c
@@ -16,6 +16,8 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see http://www.gnu.org/licenses/.
  */
+
+#define NEED_GLOBAL_ENV
 #include exec.h
 #include helpers.h
 
diff --git a/target-microblaze/exec.h b/target-microblaze/exec.h

[Qemu-devel] [PATCH 2/4] move cpu_pc_from_tb to target-*/exec.h

2010-06-28 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 target-alpha/cpu.h   |5 -
 target-alpha/exec.h  |5 +
 target-arm/cpu.h |5 -
 target-arm/exec.h|6 ++
 target-cris/cpu.h|5 -
 target-cris/exec.h   |6 ++
 target-i386/cpu.h|5 -
 target-i386/exec.h   |6 ++
 target-m68k/cpu.h|5 -
 target-m68k/exec.h   |6 ++
 target-microblaze/cpu.h  |5 -
 target-microblaze/exec.h |6 ++
 target-mips/cpu.h|7 ---
 target-mips/exec.h   |7 +++
 target-ppc/cpu.h |5 -
 target-ppc/exec.h|5 +
 target-s390x/cpu.h   |5 -
 target-s390x/exec.h  |6 ++
 target-sh4/cpu.h |6 --
 target-sh4/exec.h|6 ++
 target-sparc/cpu.h   |6 --
 target-sparc/exec.h  |6 ++
 22 files changed, 65 insertions(+), 59 deletions(-)

diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index 314d6ac..c96 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -512,11 +512,6 @@ void pal_init (CPUState *env);
 void call_pal (CPUState *env);
 #endif
 
-static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
-{
-env-pc = tb-pc;
-}
-
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
 target_ulong *cs_base, int *flags)
 {
diff --git a/target-alpha/exec.h b/target-alpha/exec.h
index 0fb459d..a8a38d2 100644
--- a/target-alpha/exec.h
+++ b/target-alpha/exec.h
@@ -53,4 +53,9 @@ static inline int cpu_halted(CPUState *env)
 return EXCP_HALTED;
 }
 
+static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
+{
+env-pc = tb-pc;
+}
+
 #endif /* !defined (__ALPHA_EXEC_H__) */
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index f3d138d..ddf764e 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -437,11 +437,6 @@ static inline void cpu_clone_regs(CPUState *env, 
target_ulong newsp)
 #include cpu-all.h
 #include exec-all.h
 
-static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
-{
-env-regs[15] = tb-pc;
-}
-
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
 target_ulong *cs_base, int *flags)
 {
diff --git a/target-arm/exec.h b/target-arm/exec.h
index 0225c3f..e4c35a3 100644
--- a/target-arm/exec.h
+++ b/target-arm/exec.h
@@ -50,3 +50,9 @@ static inline int cpu_halted(CPUState *env) {
 #endif
 
 void raise_exception(int);
+
+static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
+{
+env-regs[15] = tb-pc;
+}
+
diff --git a/target-cris/cpu.h b/target-cris/cpu.h
index a62d57c..f86c52a 100644
--- a/target-cris/cpu.h
+++ b/target-cris/cpu.h
@@ -252,11 +252,6 @@ static inline void cpu_set_tls(CPUCRISState *env, 
target_ulong newtls)
 #include cpu-all.h
 #include exec-all.h
 
-static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
-{
-env-pc = tb-pc;
-}
-
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
 target_ulong *cs_base, int *flags)
 {
diff --git a/target-cris/exec.h b/target-cris/exec.h
index 55776ba..93ce768 100644
--- a/target-cris/exec.h
+++ b/target-cris/exec.h
@@ -45,3 +45,9 @@ static inline int cpu_halted(CPUState *env) {
}
return EXCP_HALTED;
 }
+
+static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
+{
+env-pc = tb-pc;
+}
+
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 8dafa0d..e320c80 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -936,11 +936,6 @@ static inline void cpu_clone_regs(CPUState *env, 
target_ulong newsp)
 #include hw/apic.h
 #endif
 
-static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
-{
-env-eip = tb-pc - tb-cs_base;
-}
-
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
 target_ulong *cs_base, int *flags)
 {
diff --git a/target-i386/exec.h b/target-i386/exec.h
index cb34605..04a566f 100644
--- a/target-i386/exec.h
+++ b/target-i386/exec.h
@@ -318,3 +318,9 @@ static inline void cpu_load_efer(CPUState *env, uint64_t 
val)
 if (env-efer  MSR_EFER_SVME)
 env-hflags |= HF_SVME_MASK;
 }
+
+static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
+{
+env-eip = tb-pc - tb-cs_base;
+}
+
diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h
index b2f37ec..0f84514 100644
--- a/target-m68k/cpu.h
+++ b/target-m68k/cpu.h
@@ -244,11 +244,6 @@ static inline void cpu_clone_regs(CPUState *env, 
target_ulong newsp)
 #include cpu-all.h
 #include exec-all.h
 
-static inline void cpu_pc_from_tb(CPUState *env, TranslationBlock *tb)
-{
-env-pc = tb-pc;
-}
-
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
 target_ulong *cs_base, int *flags)
 {
diff 

[Qemu-devel] [PATCH 3/4] remove exec-all.h inclusion from cpu.h

2010-06-28 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 gdbstub.c   |1 +
 hw/xen_domainbuild.c|1 +
 kvm-stub.c  |1 +
 monitor.c   |1 +
 target-alpha/cpu.h  |1 -
 target-arm/cpu.h|1 -
 target-cris/cpu.h   |1 -
 target-i386/cpu.h   |2 --
 target-m68k/cpu.h   |1 -
 target-microblaze/cpu.h |1 -
 target-mips/cpu.h   |1 -
 target-ppc/cpu.h|1 -
 target-s390x/cpu.h  |1 -
 target-sh4/cpu.h|1 -
 target-sparc/cpu.h  |1 -
 15 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/gdbstub.c b/gdbstub.c
index c1852c2..2b03ef2 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -37,6 +37,7 @@
 
 #define MAX_PACKET_LENGTH 4096
 
+#include exec-all.h
 #include qemu_socket.h
 #include kvm.h
 
diff --git a/hw/xen_domainbuild.c b/hw/xen_domainbuild.c
index 2f59856..7f1fd66 100644
--- a/hw/xen_domainbuild.c
+++ b/hw/xen_domainbuild.c
@@ -3,6 +3,7 @@
 #include xen_domainbuild.h
 #include sysemu.h
 #include qemu-timer.h
+#include qemu-log.h
 
 #include xenguest.h
 
diff --git a/kvm-stub.c b/kvm-stub.c
index 7be5f5d..3378bd3 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -13,6 +13,7 @@
 #include qemu-common.h
 #include sysemu.h
 #include hw/hw.h
+#include exec-all.h
 #include gdbstub.h
 #include kvm.h
 
diff --git a/monitor.c b/monitor.c
index 170b269..8657c86 100644
--- a/monitor.c
+++ b/monitor.c
@@ -55,6 +55,7 @@
 #include json-streamer.h
 #include json-parser.h
 #include osdep.h
+#include exec-all.h
 
 //#define DEBUG
 //#define DEBUG_COMPLETION
diff --git a/target-alpha/cpu.h b/target-alpha/cpu.h
index c96..686fb4a 100644
--- a/target-alpha/cpu.h
+++ b/target-alpha/cpu.h
@@ -413,7 +413,6 @@ static inline int cpu_mmu_index (CPUState *env)
 }
 
 #include cpu-all.h
-#include exec-all.h
 
 enum {
 FEATURE_ASN= 0x0001,
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index ddf764e..39c4a0e 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -435,7 +435,6 @@ static inline void cpu_clone_regs(CPUState *env, 
target_ulong newsp)
 #endif
 
 #include cpu-all.h
-#include exec-all.h
 
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
 target_ulong *cs_base, int *flags)
diff --git a/target-cris/cpu.h b/target-cris/cpu.h
index f86c52a..fce0804 100644
--- a/target-cris/cpu.h
+++ b/target-cris/cpu.h
@@ -250,7 +250,6 @@ static inline void cpu_set_tls(CPUCRISState *env, 
target_ulong newtls)
 #define SFR_RW_MM_TLB_HI   env-pregs[PR_SRS]][6
 
 #include cpu-all.h
-#include exec-all.h
 
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
 target_ulong *cs_base, int *flags)
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index e320c80..e0a039e 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -928,8 +928,6 @@ static inline void cpu_clone_regs(CPUState *env, 
target_ulong newsp)
 #endif
 
 #include cpu-all.h
-#include exec-all.h
-
 #include svm.h
 
 #if !defined(CONFIG_USER_ONLY)
diff --git a/target-m68k/cpu.h b/target-m68k/cpu.h
index 0f84514..33c41b2 100644
--- a/target-m68k/cpu.h
+++ b/target-m68k/cpu.h
@@ -242,7 +242,6 @@ static inline void cpu_clone_regs(CPUState *env, 
target_ulong newsp)
 #endif
 
 #include cpu-all.h
-#include exec-all.h
 
 static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,
 target_ulong *cs_base, int *flags)
diff --git a/target-microblaze/cpu.h b/target-microblaze/cpu.h
index a2677cf..360ac0a 100644
--- a/target-microblaze/cpu.h
+++ b/target-microblaze/cpu.h
@@ -305,7 +305,6 @@ static inline int cpu_interrupts_enabled(CPUState *env)
 }
 
 #include cpu-all.h
-#include exec-all.h
 
 static inline target_ulong cpu_get_pc(CPUState *env)
 {
diff --git a/target-mips/cpu.h b/target-mips/cpu.h
index 1aaca77..81051aa 100644
--- a/target-mips/cpu.h
+++ b/target-mips/cpu.h
@@ -526,7 +526,6 @@ static inline void cpu_clone_regs(CPUState *env, 
target_ulong newsp)
 }
 
 #include cpu-all.h
-#include exec-all.h
 
 /* Memory access type :
  * may be needed for precise access rights control and precise exceptions.
diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index ca0eb1e..9c8d774 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -849,7 +849,6 @@ static inline void cpu_clone_regs(CPUState *env, 
target_ulong newsp)
 #endif
 
 #include cpu-all.h
-#include exec-all.h
 
 /*/
 /* CRF definitions */
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 49d3128..8d73fad 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -116,7 +116,6 @@ extern CPUState *s390_cpu_addr2state(uint16_t cpu_addr);
 #define cpu_gen_code cpu_s390x_gen_code
 
 #include cpu-all.h
-#include exec-all.h
 
 #define EXCP_OPEX 1 /* operation exception (sigill) */
 #define EXCP_SVC 2 /* supervisor call (syscall) */
diff 

[Qemu-devel] [PATCH 1/4] remove unused stuff from */exec.h

2010-06-28 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 target-alpha/exec.h  |2 --
 target-cris/exec.h   |3 ---
 target-i386/exec.h   |9 -
 target-i386/op_helper.c  |2 +-
 target-microblaze/exec.h |2 --
 target-mips/exec.h   |8 
 target-mips/op_helper.c  |5 +
 7 files changed, 6 insertions(+), 25 deletions(-)

diff --git a/target-alpha/exec.h b/target-alpha/exec.h
index 66526e2..0fb459d 100644
--- a/target-alpha/exec.h
+++ b/target-alpha/exec.h
@@ -28,8 +28,6 @@
 
 register struct CPUAlphaState *env asm(AREG0);
 
-#define PARAM(n) ((uint64_t)PARAM##n)
-#define SPARAM(n) ((int32_t)PARAM##n)
 #define FP_STATUS (env-fp_status)
 
 #include cpu.h
diff --git a/target-cris/exec.h b/target-cris/exec.h
index 728aa80..55776ba 100644
--- a/target-cris/exec.h
+++ b/target-cris/exec.h
@@ -28,9 +28,6 @@ register struct CPUCRISState *env asm(AREG0);
 #include softmmu_exec.h
 #endif
 
-void cpu_cris_flush_flags(CPUCRISState *env, int cc_op);
-void helper_movec(CPUCRISState *env, int reg, uint32_t val);
-
 static inline int cpu_has_work(CPUState *env)
 {
 return (env-interrupt_request  (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI));
diff --git a/target-i386/exec.h b/target-i386/exec.h
index 4ff3c57..cb34605 100644
--- a/target-i386/exec.h
+++ b/target-i386/exec.h
@@ -33,23 +33,14 @@ register struct CPUX86State *env asm(AREG0);
 #include qemu-common.h
 #include qemu-log.h
 
-#undef EAX
 #define EAX (env-regs[R_EAX])
-#undef ECX
 #define ECX (env-regs[R_ECX])
-#undef EDX
 #define EDX (env-regs[R_EDX])
-#undef EBX
 #define EBX (env-regs[R_EBX])
-#undef ESP
 #define ESP (env-regs[R_ESP])
-#undef EBP
 #define EBP (env-regs[R_EBP])
-#undef ESI
 #define ESI (env-regs[R_ESI])
-#undef EDI
 #define EDI (env-regs[R_EDI])
-#undef EIP
 #define EIP (env-eip)
 #define DF  (env-df)
 
diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index c1256f4..00fc671 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -16,7 +16,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see http://www.gnu.org/licenses/.
  */
-#define CPU_NO_GLOBAL_REGS
+
 #include exec.h
 #include exec-all.h
 #include host-utils.h
diff --git a/target-microblaze/exec.h b/target-microblaze/exec.h
index 646701c..db1c99e 100644
--- a/target-microblaze/exec.h
+++ b/target-microblaze/exec.h
@@ -27,8 +27,6 @@ register struct CPUMBState *env asm(AREG0);
 #include softmmu_exec.h
 #endif
 
-void cpu_mb_flush_flags(CPUMBState *env, int cc_op);
-
 static inline int cpu_has_work(CPUState *env)
 {
 return (env-interrupt_request  (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI));
diff --git a/target-mips/exec.h b/target-mips/exec.h
index 01e9c4d..a07761d 100644
--- a/target-mips/exec.h
+++ b/target-mips/exec.h
@@ -17,14 +17,6 @@ register struct CPUMIPSState *env asm(AREG0);
 #include softmmu_exec.h
 #endif /* !defined(CONFIG_USER_ONLY) */
 
-void dump_fpu(CPUState *env);
-void fpu_dump_state(CPUState *env, FILE *f,
-int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
-int flags);
-
-void cpu_mips_clock_init (CPUState *env);
-void cpu_mips_tlb_flush (CPUState *env, int flush_global);
-
 static inline int cpu_has_work(CPUState *env)
 {
 return (env-interrupt_request 
diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
index d09d6ed..344e0bd 100644
--- a/target-mips/op_helper.c
+++ b/target-mips/op_helper.c
@@ -22,6 +22,11 @@
 #include host-utils.h
 
 #include helper.h
+
+#ifndef CONFIG_USER_ONLY
+static inline void cpu_mips_tlb_flush (CPUState *env, int flush_global);
+#endif
+
 /*/
 /* Exceptions processing helpers */
 
-- 
1.7.0.1





[Qemu-devel] Re: [PATCH 1/4] remove unused stuff from */exec.h

2010-06-28 Thread Blue Swirl
On Mon, Jun 28, 2010 at 5:17 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  target-alpha/exec.h      |    2 --
  target-cris/exec.h       |    3 ---
  target-i386/exec.h       |    9 -
  target-i386/op_helper.c  |    2 +-
  target-microblaze/exec.h |    2 --
  target-mips/exec.h       |    8 
  target-mips/op_helper.c  |    5 +
  7 files changed, 6 insertions(+), 25 deletions(-)

 diff --git a/target-alpha/exec.h b/target-alpha/exec.h
 index 66526e2..0fb459d 100644
 --- a/target-alpha/exec.h
 +++ b/target-alpha/exec.h
 @@ -28,8 +28,6 @@

  register struct CPUAlphaState *env asm(AREG0);

 -#define PARAM(n) ((uint64_t)PARAM##n)
 -#define SPARAM(n) ((int32_t)PARAM##n)
  #define FP_STATUS (env-fp_status)

  #include cpu.h
 diff --git a/target-cris/exec.h b/target-cris/exec.h
 index 728aa80..55776ba 100644
 --- a/target-cris/exec.h
 +++ b/target-cris/exec.h
 @@ -28,9 +28,6 @@ register struct CPUCRISState *env asm(AREG0);
  #include softmmu_exec.h
  #endif

 -void cpu_cris_flush_flags(CPUCRISState *env, int cc_op);
 -void helper_movec(CPUCRISState *env, int reg, uint32_t val);
 -
  static inline int cpu_has_work(CPUState *env)
  {
     return (env-interrupt_request  (CPU_INTERRUPT_HARD | 
 CPU_INTERRUPT_NMI));
 diff --git a/target-i386/exec.h b/target-i386/exec.h
 index 4ff3c57..cb34605 100644
 --- a/target-i386/exec.h
 +++ b/target-i386/exec.h
 @@ -33,23 +33,14 @@ register struct CPUX86State *env asm(AREG0);
  #include qemu-common.h
  #include qemu-log.h

 -#undef EAX
  #define EAX (env-regs[R_EAX])
 -#undef ECX
  #define ECX (env-regs[R_ECX])
 -#undef EDX
  #define EDX (env-regs[R_EDX])
 -#undef EBX
  #define EBX (env-regs[R_EBX])
 -#undef ESP
  #define ESP (env-regs[R_ESP])
 -#undef EBP
  #define EBP (env-regs[R_EBP])
 -#undef ESI
  #define ESI (env-regs[R_ESI])
 -#undef EDI
  #define EDI (env-regs[R_EDI])
 -#undef EIP
  #define EIP (env-eip)
  #define DF  (env-df)

IIRC these #undefs were added because some system includes on some
hosts also defined them. I think they should be replaced by open coded
versions (rather than using the QEMU_ prefix). Or just leave the
#undefs in place.


 diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
 index c1256f4..00fc671 100644
 --- a/target-i386/op_helper.c
 +++ b/target-i386/op_helper.c
 @@ -16,7 +16,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see 
 http://www.gnu.org/licenses/.
  */
 -#define CPU_NO_GLOBAL_REGS
 +
  #include exec.h
  #include exec-all.h
  #include host-utils.h
 diff --git a/target-microblaze/exec.h b/target-microblaze/exec.h
 index 646701c..db1c99e 100644
 --- a/target-microblaze/exec.h
 +++ b/target-microblaze/exec.h
 @@ -27,8 +27,6 @@ register struct CPUMBState *env asm(AREG0);
  #include softmmu_exec.h
  #endif

 -void cpu_mb_flush_flags(CPUMBState *env, int cc_op);
 -
  static inline int cpu_has_work(CPUState *env)
  {
     return (env-interrupt_request  (CPU_INTERRUPT_HARD | 
 CPU_INTERRUPT_NMI));
 diff --git a/target-mips/exec.h b/target-mips/exec.h
 index 01e9c4d..a07761d 100644
 --- a/target-mips/exec.h
 +++ b/target-mips/exec.h
 @@ -17,14 +17,6 @@ register struct CPUMIPSState *env asm(AREG0);
  #include softmmu_exec.h
  #endif /* !defined(CONFIG_USER_ONLY) */

 -void dump_fpu(CPUState *env);
 -void fpu_dump_state(CPUState *env, FILE *f,
 -                    int (*fpu_fprintf)(FILE *f, const char *fmt, ...),
 -                    int flags);
 -
 -void cpu_mips_clock_init (CPUState *env);
 -void cpu_mips_tlb_flush (CPUState *env, int flush_global);
 -
  static inline int cpu_has_work(CPUState *env)
  {
     return (env-interrupt_request 
 diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
 index d09d6ed..344e0bd 100644
 --- a/target-mips/op_helper.c
 +++ b/target-mips/op_helper.c
 @@ -22,6 +22,11 @@
  #include host-utils.h

  #include helper.h
 +
 +#ifndef CONFIG_USER_ONLY
 +static inline void cpu_mips_tlb_flush (CPUState *env, int flush_global);
 +#endif
 +

Does 'inline' make sense with a function prototype?

Please also make the implementation of cpu_mips_tlb_flush() 'static'.

Otherwise, very nice cleanup. PARAM stuff dates from pre-TCG times.



[Qemu-devel] Re: [PATCH 0/4] introduce NEED_GLOBAL_ENV

2010-06-28 Thread Blue Swirl
On Mon, Jun 28, 2010 at 5:17 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 Let's start the cleanups from the feature required by Blue Swirl.
 I also include here a baby step towards removing eminently TCG-related
 stuff from cpu.h.

 After this series, only a bunch of files will include exec-all.h,
 instead of getting it indirectly from cpu.h.

 Note that (as sworn in the previous submission) exec.h is only included
 by files that need the global register variable (i.e. cpu-exec.c and
 target-*/op_helper.c), and this is the same subset that gets
 NEED_GLOBAL_ENV in this patchset.

 i386 and sparc have functions declared in cpu.h that are in op_helper.c.
 I checked that these do not need the global variable, but it would be
 nice to cleanup those too.

Maybe some of those could be moved to helper.c?

 Paolo Bonzini (4):
  remove unused stuff from */exec.h
  move cpu_pc_from_tb to target-*/exec.h
  remove exec-all.h inclusion from cpu.h
  require #define NEED_GLOBAL_ENV for files that need the global
    register variable

Good stuff. I had some comments to 1/4.



[Qemu-devel] KVM Call agenda for June 29

2010-06-28 Thread Juan Quintela

Please send in any agenda items you are interested in covering.

If we have a lack of agenda items I'll cancel the week's call.

After last week debacle, I will wait until 10 mins before call to cancel
it.

thanks, Juan.



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

2010-06-28 Thread Juan Quintela
Huacai Chen zltjiang...@gmail.com wrote:
 Signed-off-by: Huacai Chen zltjiang...@gmail.com

 +static void superio_ioport_writeb(void *opaque, uint32_t addr, uint32_t data)
 +{
 +int can_write;
 +SuperIOConfig *superio_conf = (SuperIOConfig *)opaque;

Useless cast from void *.

 +static uint32_t superio_ioport_readb(void *opaque, uint32_t addr)
 +{
 +SuperIOConfig *superio_conf = (SuperIOConfig *)opaque;

the same.

 +static void vt82c686b_save(QEMUFile * f, void *opaque)
 +{
 +PCIDevice *d = opaque;
 +pci_device_save(d, f);
 +}
 +
 +static int vt82c686b_load(QEMUFile * f, void *opaque, int version_id)
 +{
 +PCIDevice *d = opaque;
 +if (version_id != 1)
 +return -EINVAL;
 +return pci_device_load(d, f);
 +}

You use vmstate in the rest of devices, why use old style here?

 +typedef struct VT686AC97State {
 +PCIDevice dev;
 +int unused;

not needed really.

 +} VT686AC97State;
 +
 +typedef struct VT686MC97State {
 +PCIDevice dev;
 +int unused;

also not needed.

 +} VT686MC97State;
 +
 +#define RTC_EN(1  10)
 +#define PWRBTN_EN (1  8)
 +#define GBL_EN(1  5)
 +#define TMROF_EN  (1  0)
 +#define SCI_EN(1  0)

not used in the rest of the code.  Suspicions to be the same bit that
previous one.

 +
 +s = (VT686AC97State *)pci_register_device(bus,
 + vt82c686b_AC97, 
 sizeof(VT686AC97State),
 + devfn, NULL, NULL);

use DO_UPCAST like rest of driver instead of cast.

 +void vt82c686b_mc97_init(PCIBus *bus, int devfn)
 +{
 +VT686MC97State *s;
 +uint8_t *pci_conf;
 +
 +s = (VT686MC97State *)pci_register_device(bus,
 + vt82c686b_MC97, 
 sizeof(VT686MC97State),
 + devfn, NULL, NULL);

Same than previous comment.

 +/* set super io config */
 +vt686-superio_conf = qemu_mallocz(sizeof(SuperIOConfig));

Why do you use a pointer instead of changing it to a embeded estruct
inside struct VT82C686BState?

Later, Juan.



[Qemu-devel] Re: [PATCH v5 4/6] MIPS: Initial support of VIA USB controller used by fulong mini pc

2010-06-28 Thread Juan Quintela
Huacai Chen zltjiang...@gmail.com wrote:
 Signed-off-by: Huacai Chen zltjiang...@gmail.com
 ---
  hw/usb-uhci.c |   29 +
  hw/usb-uhci.h |1 +
  2 files changed, 30 insertions(+), 0 deletions(-)

 diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
 index 624d55b..accfe2e 100644
 --- a/hw/usb-uhci.c
 +++ b/hw/usb-uhci.c
 @@ -1149,6 +1149,25 @@ static int usb_uhci_piix4_initfn(PCIDevice *dev)
  
  pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
  pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_2);
 +pci_set_byte(pci_conf + PCI_LATENCY_TIMER, 0x16);
 +
 +/* USB misc control 1/2 */
 +pci_set_long(pci_conf + 0x40,0x1000);
 +/* PM capability */
 +pci_set_long(pci_conf + 0x80,0x00020001);
 +/* USB legacy support  */
 +pci_set_long(pci_conf + 0xc0,0x2000);

This looks fishy.  You are adding fields to uhci_piix4 when adding via
usb controller?  If this fields are needed for piix4 (I don't know) they
should be split in its own patch, no?



Re: [Qemu-devel] [PATCH 0/7] [PULL] qemu-kvm.git uq/master queue

2010-06-28 Thread Anthony Liguori

On 06/28/2010 11:14 AM, Marcelo Tosatti wrote:

The following changes since commit 4972d592113c627d4b6ea1be5c94a85b56099afd:
   Stefan Weil (1):
 win32: Add missing function ffs

are available in the git repository at:

   git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git uq/master

Andre Przywara (1):
   fix CPUID vendor override

Jan Kiszka (1):
   kvm: Switch kvm_update_guest_debug to run_on_cpu

Marcelo Tosatti (1):
   kvm: init mp_state

Sheng Yang (4):
   kvm: Extend kvm_arch_get_supported_cpuid() to support index
   Enable XSAVE related CPUID
   kvm: Enable XSAVE live migration support
   kvm: Fix cpu_is_bsp() compilation warning
   


Pulled.  Thanks.

Regards,

Anthony Liguori


  kvm-all.c |   33 +++---
  kvm.h |4 +-
  target-i386/cpu.h |7 ++-
  target-i386/cpuid.c   |   23 +++-
  target-i386/kvm.c |  165 ++---
  target-i386/machine.c |   20 ++
  6 files changed, 228 insertions(+), 24 deletions(-)


   





Re: [Qemu-devel] [PATCH 4/4] require #define NEED_GLOBAL_ENV for files that need the global register variable

2010-06-28 Thread Paul Brook
 diff --git a/exec-all.h b/exec-all.h
 index a775582..ebe88ad 100644
 --- a/exec-all.h
 +++ b/exec-all.h
 @@ -353,4 +353,8 @@ extern int singlestep;
  /* cpu-exec.c */
  extern volatile sig_atomic_t exit_request;
 
 +#ifdef NEED_GLOBAL_ENV
 +register CPUState *env asm(AREG0);
 +#endif

Wouldn't it be better to just put this in dyngen-exec.h ?
AFAICT there's a direct correlation between NEED_GLOBAL_ENV and #include 
exec.h.

Paul



[Qemu-devel] Re: Unusual physical address when using 64-bit BAR

2010-06-28 Thread Cam Macdonell
On Sun, Jun 27, 2010 at 2:39 AM, Avi Kivity a...@redhat.com wrote:
 On 06/25/2010 12:51 AM, Cam Macdonell wrote:

 On Tue, Jun 15, 2010 at 5:04 AM, Avi Kivitya...@redhat.com  wrote:


 On 06/11/2010 08:31 PM, Cam Macdonell wrote:


 On Mon, Apr 19, 2010 at 10:41 AM, Cam Macdonellc...@cs.ualberta.ca
  wrote:



 Hi,

 I'm trying to use a 64-bit BAR for my shared memory device.  In simply
 changing the memory type in pci_register_bar() to
 PCI_BASE_ADDRESS_MEM_TYPE_64 I get an unusual physical address for
 that BAR (and my driver crashes in pci_ioremap).

 from lspci:

 00:04.0 RAM memory: Qumranet, Inc. Device 1110
        Subsystem: Qumranet, Inc. Device 1100
        Flags: fast devsel, IRQ 10
        Memory at f102 (32-bit, non-prefetchable) [size=1K]
        Memory at f1021000 (32-bit, non-prefetchable) [size=4K]
        Memory at c200 (64-bit, non-prefetchable) [size=1024M]
        Capabilities:access denied
 00: f4 1a 10 11 03 00 10 00 00 00 00 05 00 00 00 00
 10: 00 00 02 f1 00 10 02 f1 04 00 00 00 00 c2 00 00
 20: 00 00 00 00 00 00 00 00 00 00 00 00 f4 1a 00 11
 30: 00 00 00 00 40 00 00 00 00 00 00 00 0b 01 00 00

 with DEBUG_MEMREG, I see

 kvm_unregister_memory_area:666 Unregistering memory region
 c200 (4000)
 kvm_destroy_phys_mem:649 slot 7 start c200 len 0 flags 0
 IVSHMEM: addr = 3221225472 size = 1073741824
 kvm_register_phys_mem:605 memory: gpa: c200c000, size: 4000,
 uaddr: 7f6dd7ffe000, slot: 7, flags: 0
 kvm_unregister_memory_area:666 Unregistering memory region
 c200c000 (4000)
 kvm_destroy_phys_mem:649 slot 7 start c200c000 len 0 flags 0
 IVSHMEM: addr = 0 size = 1073741824
 kvm_register_phys_mem:605 memory: gpa: c200, size: 4000,
 uaddr: 7f6dd7ffe000, slot: 7, flags: 0
 kvm_unregister_memory_area:666 Unregistering memory region
 c200 (4000)
 kvm_destroy_phys_mem:649 slot 7 start c200 len 0 flags 0
 IVSHMEM: addr = 0 size = 1073741824
 kvm_register_phys_mem:605 memory: gpa: , size:
 4000, uaddr: 7f6dd7ffe000, slot: 7, flags: 0
 kvm_unregister_memory_area:666 Unregistering memory region
  (4000)
 kvm_destroy_phys_mem:649 slot 7 start  len 0 flags 0
 IVSHMEM: addr = 0 size = 1073741824
 kvm_register_phys_mem:605 memory: gpa: c200, size: 4000,
 uaddr: 7f6dd7ffe000, slot: 7, flags: 0

 (the IVSHMEM lines are my debug statements)

 address sizes   : 40 bits physical, 48 bits virtual  (guest)
 address sizes   : 38 bits physical, 48 bits virtual  (host)




 Hi, I happened to run into this problem again when trying to use a
 64-bit BAR.  I did a bit more digging and the test that is failing is
 called from arch/x86/mm/ioremap.c in the guest and here it is.

 static inline int phys_addr_valid(resource_size_t addr)
 {
 #ifdef CONFIG_PHYS_ADDR_T_64BIT
        return !(addr    boot_cpu_data.x86_phys_bits);
 #else
        return 1;
 #endif
 }

 the value of addr (in this case the 48-bit virtual address
 c200) is shifted to the right shift by
 boot_cpu_data.x86_phys_bits (which is 40 bits, the physical address
 size), so a non-zero value is returned which causes the test to fail
 and generates the invalid physical address error in the guest.

 Any help is appreciated as to whether this is a Qemu or guest kernel
 issue.



 The guest kernel should never have generated an address that is bigger
 than
 cpu_phys_bits in the first place.  What's the value for cpu_phys_bits in
 the
 guest? (/proc/cpuinfo, 'address sizes :' line).


 Sorry I missed your reply until now.  The guest address sizes are as
 follows:

 address sizes   : 40 bits physical, 48 bits virtual


 So the address c200 is illegal.

 Is this really the address the guest programmed, or is qemu
 misinterpreting
 it?


 Well, what's the answer?

You're going to have to give me a hint on how to determine that.

lspci in the guest shows the following

Memory at c200 (64-bit, non-prefetchable) [size=1024M]

does that demonstrate a guest generated address?

Cam


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





[Qemu-devel] [PATCH 07/20] virtio-9p: Do not reset atime

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: M. Mohan Kumar mo...@in.ibm.com

Current code resets file's atime to 0 when there is a change in mtime.
This results in resetting the atime to 1970-01-01 05:30:00. For
example, truncate -s 0 filename results in changing the mtime to the
truncate time, but resets the atime to 1970-01-01 05:30:00. utime
system call does not have any provision to set only mtime or atime. So
change v9fs_wstat_post_chmod function to use utimensat function to change
the atime and mtime fields. If tv_nsec field is set to the special value
UTIME_OMIT, corresponding file time stamp is not updated.

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/file-op-9p.h  |2 +-
 hw/virtio-9p-local.c |8 
 hw/virtio-9p.c   |   28 
 3 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
index dd82ac7..120c803 100644
--- a/hw/file-op-9p.h
+++ b/hw/file-op-9p.h
@@ -52,7 +52,7 @@ typedef struct FileOperations
 int (*chmod)(FsContext *, const char *, FsCred *);
 int (*chown)(FsContext *, const char *, FsCred *);
 int (*mknod)(FsContext *, const char *, FsCred *);
-int (*utime)(FsContext *, const char *, const struct utimbuf *);
+int (*utimensat)(FsContext *, const char *, const struct timespec *);
 int (*remove)(FsContext *, const char *);
 int (*symlink)(FsContext *, const char *, const char *, FsCred *);
 int (*link)(FsContext *, const char *, const char *);
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 8ae5b07..b29f513 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -453,10 +453,10 @@ static int local_chown(FsContext *fs_ctx, const char 
*path, FsCred *credp)
 return -1;
 }
 
-static int local_utime(FsContext *ctx, const char *path,
-const struct utimbuf *buf)
+static int local_utimensat(FsContext *s, const char *path,
+  const struct timespec *buf)
 {
-return utime(rpath(ctx, path), buf);
+return utimensat(AT_FDCWD, rpath(s, path), buf, AT_SYMLINK_NOFOLLOW);
 }
 
 static int local_remove(FsContext *ctx, const char *path)
@@ -498,7 +498,7 @@ FileOperations local_ops = {
 .truncate = local_truncate,
 .rename = local_rename,
 .chown = local_chown,
-.utime = local_utime,
+.utimensat = local_utimensat,
 .remove = local_remove,
 .fsync = local_fsync,
 .statfs = local_statfs,
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 3a1a524..099514a 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -237,10 +237,25 @@ static int v9fs_do_chown(V9fsState *s, V9fsString *path, 
uid_t uid, gid_t gid)
 return s-ops-chown(s-ctx, path-data, cred);
 }
 
-static int v9fs_do_utime(V9fsState *s, V9fsString *path,
-const struct utimbuf *buf)
+static int v9fs_do_utimensat(V9fsState *s, V9fsString *path, V9fsStat v9stat)
 {
-return s-ops-utime(s-ctx, path-data, buf);
+struct timespec ts[2];
+
+if (v9stat.atime != -1) {
+ts[0].tv_sec = v9stat.atime;
+ts[0].tv_nsec = 0;
+} else {
+ts[0].tv_nsec = UTIME_OMIT;
+}
+
+if (v9stat.mtime != -1) {
+ts[1].tv_sec = v9stat.mtime;
+ts[1].tv_nsec = 0;
+} else {
+ts[1].tv_nsec = UTIME_OMIT;
+}
+
+return s-ops-utimensat(s-ctx, path-data, ts);
 }
 
 static int v9fs_do_remove(V9fsState *s, V9fsString *path)
@@ -2296,11 +2311,8 @@ static void v9fs_wstat_post_chmod(V9fsState *s, 
V9fsWstatState *vs, int err)
 goto out;
 }
 
-if (vs-v9stat.mtime != -1) {
-struct utimbuf tb;
-tb.actime = 0;
-tb.modtime = vs-v9stat.mtime;
-if (v9fs_do_utime(s, vs-fidp-path, tb)) {
+if (vs-v9stat.mtime != -1 || vs-v9stat.atime != -1) {
+if (v9fs_do_utimensat(s, vs-fidp-path, vs-v9stat)) {
 err = -errno;
 }
 }
-- 
1.6.5.2




[Qemu-devel] [PATCH 04/20] [V4] virtio-9p: readdir implementation for 9p2000.L

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: Sripathi Kodi sripat...@in.ibm.com

This patch implements the server part of readdir() implementation for
9p2000.L

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
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-debug.c |   13 +
 hw/virtio-9p.c   |  122 ++
 hw/virtio-9p.h   |2 +
 3 files changed, 137 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index e4ab4bc..030b3e6 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 0540a74..2918194 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1577,6 +1577,127 @@ 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);
+/* Fill the other fields with dummy values */
+vs-qid.type = 0;
+vs-qid.version = 0;
+
+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;
+}
+

[Qemu-devel] [PATCH 02/20] qemu: virtio-9p: Implement statfs support in server

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: M. Mohan Kumar mo...@in.ibm.com

Implement statfs support in qemu server based on Sripathi's
initial statfs patch.

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/file-op-9p.h  |1 +
 hw/virtio-9p-local.c |6 
 hw/virtio-9p.c   |   63 ++
 hw/virtio-9p.h   |   24 +++
 4 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
index a741c93..dd82ac7 100644
--- a/hw/file-op-9p.h
+++ b/hw/file-op-9p.h
@@ -74,6 +74,7 @@ typedef struct FileOperations
 int (*rename)(FsContext *, const char *, const char *);
 int (*truncate)(FsContext *, const char *, off_t);
 int (*fsync)(FsContext *, int);
+int (*statfs)(FsContext *s, const char *path, struct statfs *stbuf);
 void *opaque;
 } FileOperations;
 #endif
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 04f7f6f..8ae5b07 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -469,6 +469,11 @@ static int local_fsync(FsContext *ctx, int fd)
 return fsync(fd);
 }
 
+static int local_statfs(FsContext *s, const char *path, struct statfs *stbuf)
+{
+   return statfs(rpath(s, path), stbuf);
+}
+
 FileOperations local_ops = {
 .lstat = local_lstat,
 .readlink = local_readlink,
@@ -496,4 +501,5 @@ FileOperations local_ops = {
 .utime = local_utime,
 .remove = local_remove,
 .fsync = local_fsync,
+.statfs = local_statfs,
 };
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index e41c51e..20560e5 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -2145,9 +2145,72 @@ 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)
+{
+if (err) {
+err = -errno;
+goto out;
+}
+
+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_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] |
+   (unsigned long long)vs-stbuf.f_fsid.__val[1]  32;
+vs-v9statfs.f_namelen = vs-stbuf.f_namelen;
+
+vs-offset += pdu_marshal(vs-pdu, vs-offset, ddqqd,
+ vs-v9statfs.f_type, vs-v9statfs.f_bsize, vs-v9statfs.f_blocks,
+ vs-v9statfs.f_bfree, vs-v9statfs.f_bavail, vs-v9statfs.f_files,
+ vs-v9statfs.f_ffree, vs-v9statfs.fsid_val,
+ vs-v9statfs.f_namelen);
+
+out:
+complete_pdu(s, vs-pdu, vs-offset);
+qemu_free(vs);
+}
+
+static void v9fs_statfs(V9fsState *s, V9fsPDU *pdu)
+{
+V9fsStatfsState *vs;
+ssize_t err = 0;
+
+vs = qemu_malloc(sizeof(*vs));
+vs-pdu = pdu;
+vs-offset = 7;
+
+memset(vs-v9statfs, 0, sizeof(vs-v9statfs));
+
+pdu_unmarshal(vs-pdu, vs-offset, d, vs-fid);
+
+vs-fidp = lookup_fid(s, vs-fid);
+if (vs-fidp == NULL) {
+err = -ENOENT;
+goto out;
+}
+
+err = v9fs_do_statfs(s, vs-fidp-path, vs-stbuf);
+v9fs_statfs_post_statfs(s, vs, err);
+return;
+
+out:
+complete_pdu(s, vs-pdu, err);
+qemu_free(vs);
+}
+
 typedef void (pdu_handler_t)(V9fsState *s, V9fsPDU *pdu);
 
 static pdu_handler_t *pdu_handlers[] = {
+[P9_TSTATFS] = v9fs_statfs,
 [P9_TVERSION] = v9fs_version,
 [P9_TATTACH] = v9fs_attach,
 [P9_TSTAT] = v9fs_stat,
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 9286f59..992c765 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -13,6 +13,8 @@
 #define VIRTIO_9P_MOUNT_TAG 0
 
 enum {
+P9_TSTATFS = 8,
+P9_RSTATFS,
 P9_TVERSION = 100,
 P9_RVERSION,
 P9_TAUTH = 102,
@@ -252,6 +254,28 @@ struct virtio_9p_config
 uint8_t tag[0];
 } __attribute__((packed));
 
+typedef struct V9fsStatfs
+{
+uint32_t f_type;
+uint32_t f_bsize;
+uint64_t f_blocks;
+uint64_t f_bfree;
+uint64_t f_bavail;
+uint64_t f_files;
+uint64_t f_ffree;
+uint64_t fsid_val;
+uint32_t f_namelen;
+} V9fsStatfs;
+
+typedef struct V9fsStatfsState {
+V9fsPDU *pdu;
+size_t offset;
+int32_t fid;
+V9fsStatfs v9statfs;
+V9fsFidState *fidp;
+struct statfs stbuf;
+} V9fsStatfsState;
+
 extern size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
 size_t offset, size_t size, int pack);
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 18/20] virtio-9p: Implement TXATTRWALK

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

TXATTRWALK: Descend a ATTR namespace

 size[4] TXATTRWALK tag[2] fid[4] newfid[4] name[s]
 size[4] RXATTRWALK tag[2] size[8]

txattrwalk gets a fid pointing to xattr. This fid can later be
used to get read the xattr value. If name is NULL the fid returned
can be used to get the list of extended attribute associated to
the file system object.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/file-op-9p.h  |3 +
 hw/virtio-9p-debug.c |   10 +++
 hw/virtio-9p-local.c |   14 
 hw/virtio-9p.c   |  191 +-
 hw/virtio-9p.h   |   14 
 5 files changed, 230 insertions(+), 2 deletions(-)

diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
index 120c803..8f466b4 100644
--- a/hw/file-op-9p.h
+++ b/hw/file-op-9p.h
@@ -75,6 +75,9 @@ typedef struct FileOperations
 int (*truncate)(FsContext *, const char *, off_t);
 int (*fsync)(FsContext *, int);
 int (*statfs)(FsContext *s, const char *path, struct statfs *stbuf);
+ssize_t (*lgetxattr)(FsContext *, const char *, const char *, void *,
+size_t);
+ssize_t (*llistxattr)(FsContext *, const char *, void *, size_t);
 void *opaque;
 } FileOperations;
 #endif
diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index 18e355c..47d565a 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -577,6 +577,16 @@ void pprint_pdu(V9fsPDU *pdu)
 case P9_RWSTAT:
 fprintf(llogfile, RWSTAT: ();
 break;
+case P9_TXATTRWALK:
+fprintf(llogfile, TXATTRWALK: ();
+pprint_int32(pdu, 0, offset, fid);
+pprint_int32(pdu, 0, offset, , newfid);
+pprint_str(pdu, 0, offset, , xattr name);
+break;
+case P9_RXATTRWALK:
+fprintf(llogfile, RXATTRWALK: ();
+pprint_int64(pdu, 1, offset, xattrsize);
+break;
 default:
 fprintf(llogfile, unknown(%d): (, pdu-id);
 break;
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 1f72f2e..5a3f5b8 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -477,6 +477,18 @@ static int local_statfs(FsContext *s, const char *path, 
struct statfs *stbuf)
return statfs(rpath(s, path), stbuf);
 }
 
+static ssize_t local_lgetxattr(FsContext *ctx, const char *path,
+const char *name, void *value, size_t size)
+{
+return lgetxattr(rpath(ctx, path), name, value, size);
+}
+
+static ssize_t local_llistxattr(FsContext *ctx, const char *path,
+void *value, size_t size)
+{
+return llistxattr(rpath(ctx, path), value, size);
+}
+
 FileOperations local_ops = {
 .lstat = local_lstat,
 .readlink = local_readlink,
@@ -505,4 +517,6 @@ FileOperations local_ops = {
 .remove = local_remove,
 .fsync = local_fsync,
 .statfs = local_statfs,
+.lgetxattr = local_lgetxattr,
+.llistxattr = local_llistxattr,
 };
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 79d9195..ad383f9 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -263,6 +263,21 @@ static int v9fs_do_statfs(V9fsState *s, V9fsString *path, 
struct statfs *stbuf)
 return s-ops-statfs(s-ctx, path-data, stbuf);
 }
 
+static ssize_t v9fs_do_lgetxattr(V9fsState *s, V9fsString *path,
+ V9fsString *xattr_name,
+ void *value, size_t size)
+{
+return s-ops-lgetxattr(s-ctx, path-data,
+ xattr_name-data, value, size);
+}
+
+static ssize_t v9fs_do_llistxattr(V9fsState *s, V9fsString *path,
+  void *value, size_t size)
+{
+return s-ops-llistxattr(s-ctx, path-data,
+  value, size);
+}
+
 static void v9fs_string_init(V9fsString *str)
 {
 str-data = NULL;
@@ -1916,6 +1931,31 @@ out:
 qemu_free(vs);
 }
 
+static void v9fs_xattr_read(V9fsState *s, V9fsReadState *vs)
+{
+ssize_t err = 0;
+int read_count;
+int64_t xattr_len;
+
+xattr_len = vs-fidp-fs.xattr.len;
+read_count = xattr_len - vs-off;
+if (read_count  vs-count) {
+   read_count = vs-count;
+} else if (read_count  0) {
+   /*
+* read beyond XATTR value
+*/
+   read_count = 0;
+}
+vs-offset += pdu_marshal(vs-pdu, vs-offset, d, read_count);
+vs-offset += pdu_pack(vs-pdu, vs-offset,
+  ((char *)vs-fidp-fs.xattr.value) + vs-off,
+  read_count);
+err = vs-offset;
+complete_pdu(s, vs-pdu, err);
+qemu_free(vs);
+}
+
 static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
 {
 int32_t fid;
@@ -1937,7 +1977,7 @@ static void v9fs_read(V9fsState *s, V9fsPDU *pdu)
 goto out;
 }
 
-if (vs-fidp-fs.dir) {
+if (vs-fidp-fid_type == P9_FID_DIR  vs-fidp-fs.dir) {
 vs-max_count = vs-count;
 vs-count = 0;
 if (vs-off 

[Qemu-devel] [PATCH 05/20] virtio-9p: Compute iounit based on host filesystem block size

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: M. Mohan Kumar mo...@in.ibm.com

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
Reviewd-by: Sripathi Kodi sripat...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p.c |   96 +---
 hw/virtio-9p.h |9 +
 2 files changed, 86 insertions(+), 19 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 2918194..00527c4 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -253,6 +253,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;
@@ -1019,11 +1024,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;
@@ -1033,7 +1037,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);
@@ -1288,6 +1292,26 @@ out:
 v9fs_walk_complete(s, vs, err);
 }
 
+static int32_t get_iounit(V9fsState *s, V9fsString *name)
+{
+struct statfs stbuf;
+int32_t iounit = 0;
+
+/*
+ * iounit should be multiples of f_bsize (host filesystem block size
+ * and as well as less than (client msize - P9_IOHDRSZ))
+ */
+if (!v9fs_do_statfs(s, name, stbuf)) {
+iounit = stbuf.f_bsize;
+iounit *= (s-msize - P9_IOHDRSZ)/stbuf.f_bsize;
+}
+
+if (!iounit) {
+iounit = s-msize - P9_IOHDRSZ;
+}
+return iounit;
+}
+
 static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err)
 {
 if (vs-fidp-dir == NULL) {
@@ -1303,6 +1327,15 @@ out:
 
 }
 
+static void v9fs_open_post_getiounit(V9fsState *s, V9fsOpenState *vs)
+{
+int err;
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Qd, vs-qid, vs-iounit);
+err = vs-offset;
+complete_pdu(s, vs-pdu, err);
+qemu_free(vs);
+}
+
 static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
 {
 if (vs-fidp-fd == -1) {
@@ -1310,8 +1343,9 @@ static void v9fs_open_post_open(V9fsState *s, 
V9fsOpenState *vs, int err)
 goto out;
 }
 
-vs-offset += pdu_marshal(vs-pdu, vs-offset, Qd, vs-qid, 0);
-err = vs-offset;
+vs-iounit = get_iounit(s, vs-fidp-path);
+v9fs_open_post_getiounit(s, vs);
+return;
 out:
 complete_pdu(s, vs-pdu, err);
 qemu_free(vs);
@@ -1794,15 +1828,28 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_post_create(V9fsState *s, V9fsCreateState *vs, int err)
+static void v9fs_create_post_getiounit(V9fsState *s, V9fsCreateState *vs)
 {
-if (err == 0) {
-v9fs_string_copy(vs-fidp-path, vs-fullname);
-stat_to_qid(vs-stbuf, vs-qid);
+int err;
+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, vs-iounit);
+err = vs-offset;
 
-err = vs-offset;
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-name);
+v9fs_string_free(vs-extension);
+v9fs_string_free(vs-fullname);
+qemu_free(vs);
+}
+
+static void v9fs_post_create(V9fsState *s, V9fsCreateState *vs, int err)
+{
+if (err == 0) {
+vs-iounit = get_iounit(s, vs-fidp-path);
+v9fs_create_post_getiounit(s, vs);
+return;
 }
 
 complete_pdu(s, vs-pdu, err);
@@ -2267,23 +2314,34 @@ 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;
 }
 
+/*
+ * compute bsize factor based on host file system block size
+ * and client msize
+ */
+bsize_factor = (s-msize - P9_IOHDRSZ)/vs-stbuf.f_bsize;
+if (!bsize_factor) {
+bsize_factor = 1;
+}
 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;
-

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

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: Sripathi Kodi sripat...@in.ibm.com

SYNOPSIS

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

  size[4] Rsetattr tag[2]

   DESCRIPTION

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

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

The last two bits represent whether the time information
is being sent by the client's user space. In the absense
of these bits the server always uses server's time.

 mode[4]
File permission bits

 uid[4]
Owner id of file

 gid[4]
Group id of the file

 size[8]
File size

 atime_sec[8]
Time of last file access, seconds

 atime_nsec[8]
Time of last file access, nanoseconds

 mtime_sec[8]
Time of last file modification, seconds

 mtime_nsec[8]
Time of last file modification, nanoseconds

Explanation of the patches:
--

*) The kernel just copies relevent contents of iattr structure to p9_iattr_dotl
   structure and passes it down to the client. The only check it has is calling
   inode_change_ok()
*) The p9_iattr_dotl structure does not have ctime and ia_file parameters 
because
   I don't think these are needed in our case. The client user space can request
   updating just ctime by calling chown(fd, -1, -1). This is handled on server
   side without a need for putting ctime on the wire.
*) The server currently supports changing mode, time, ownership and size of the
   file.
*) 9P RFC says Either all the changes in wstat request happen, or none of them
   does: if the request succeeds, all changes were made; if it fails, none 
were.
   I have not done anything to implement this specifically because I don't see
   a reason.

[jv...@linux.vnet.ibm.com: Parts of code for handling chown(-1,-1)

Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-local.c |5 +-
 hw/virtio-9p.c   |  155 ++
 hw/virtio-9p.h   |   23 
 3 files changed, 182 insertions(+), 1 deletions(-)

diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index b29f513..1f72f2e 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -445,7 +445,10 @@ static int local_rename(FsContext *ctx, const char 
*oldpath,
 
 static int local_chown(FsContext *fs_ctx, const char *path, FsCred *credp)
 {
-if (fs_ctx-fs_sm == SM_MAPPED) {
+if ((credp-fc_uid == -1  credp-fc_gid == -1) ||
+(fs_ctx-fs_sm == SM_PASSTHROUGH)) {
+return lchown(rpath(fs_ctx, path), credp-fc_uid, credp-fc_gid);
+} else if (fs_ctx-fs_sm == SM_MAPPED) {
 return local_set_xattr(rpath(fs_ctx, path), credp);
 } else if (fs_ctx-fs_sm == SM_PASSTHROUGH) {
 return lchown(rpath(fs_ctx, path), credp-fc_uid, credp-fc_gid);
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 613abcd..b1b3cb5 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -665,6 +665,15 @@ static size_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, 
const char *fmt, ...)
 statp-n_muid);
 break;
 }
+case 'I': {
+V9fsIattr *iattr = va_arg(ap, V9fsIattr *);
+offset += pdu_unmarshal(pdu, offset, q,
+iattr-valid, iattr-mode,
+iattr-uid, iattr-gid, iattr-size,
+iattr-atime_sec, iattr-atime_nsec,
+iattr-mtime_sec, iattr-mtime_nsec);
+break;
+}
 default:
 break;
 }
@@ -1210,6 +1219,151 @@ out:
 qemu_free(vs);
 }
 
+/* From Linux kernel code */
+#define ATTR_MODE(1  0)
+#define ATTR_UID (1  1)
+#define ATTR_GID (1  2)
+#define ATTR_SIZE(1  3)
+#define ATTR_ATIME   (1  4)
+#define ATTR_MTIME   (1  5)
+#define ATTR_CTIME   (1  6)
+#define ATTR_MASK127
+#define ATTR_ATIME_SET  (1  7)
+#define ATTR_MTIME_SET  (1  8)
+
+static void v9fs_setattr_post_truncate(V9fsState *s, V9fsSetattrState *vs,
+  int err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+err = vs-offset;
+
+out:
+complete_pdu(s, vs-pdu, err);
+qemu_free(vs);
+}
+
+static void v9fs_setattr_post_chown(V9fsState 

[Qemu-devel] [PATCH 16/20] qemu: virtio-9p: Implement LOPEN

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: M. Mohan Kumar mo...@in.ibm.com

Implement 9p2000.L version of open(LOPEN) interface in qemu 9p server.

For LOPEN, no need to convert the flags to and from 9p mode to VFS mode.

Synopsis:

size[4] Tlopen tag[2] fid[4] mode[4]

size[4] Rlopen tag[2] qid[13] iounit[4]

Current qemu 9p server does not support following flags:
O_NOCTTY, O_NONBLOCK, O_ASYNC  O_CLOEXEC

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p.c |   24 ++--
 hw/virtio-9p.h |2 ++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 156d5dd..a9da10f 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1591,8 +1591,19 @@ out:
 qemu_free(vs);
 }
 
+static inline int valid_flags(int flag)
+{
+if (flag  O_NOCTTY || flag  O_NONBLOCK || flag  O_ASYNC ||
+flag  O_CLOEXEC)
+return 0;
+else
+return 1;
+}
+
 static void v9fs_open_post_lstat(V9fsState *s, V9fsOpenState *vs, int err)
 {
+int flags;
+
 if (err) {
 err = -errno;
 goto out;
@@ -1604,8 +1615,16 @@ static void v9fs_open_post_lstat(V9fsState *s, 
V9fsOpenState *vs, int err)
 vs-fidp-dir = v9fs_do_opendir(s, vs-fidp-path);
 v9fs_open_post_opendir(s, vs, err);
 } else {
-vs-fidp-fd = v9fs_do_open(s, vs-fidp-path,
-omode_to_uflags(vs-mode));
+if (s-proto_version == V9FS_PROTO_2000L) {
+if (!valid_flags(vs-mode)) {
+err = -EINVAL;
+goto out;
+}
+flags = vs-mode;
+} else {
+flags = omode_to_uflags(vs-mode);
+}
+vs-fidp-fd = v9fs_do_open(s, vs-fidp-path, flags);
 v9fs_open_post_open(s, vs, err);
 }
 return;
@@ -3046,6 +3065,7 @@ static pdu_handler_t *pdu_handlers[] = {
 [P9_TRENAME] = v9fs_rename,
 [P9_TMKDIR] = v9fs_mkdir,
 [P9_TVERSION] = v9fs_version,
+[P9_TLOPEN] = v9fs_open,
 [P9_TATTACH] = v9fs_attach,
 [P9_TSTAT] = v9fs_stat,
 [P9_TWALK] = v9fs_walk,
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index e9cc458..0c79400 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -15,6 +15,8 @@
 enum {
 P9_TSTATFS = 8,
 P9_RSTATFS,
+P9_TLOPEN = 12,
+P9_RLOPEN,
 P9_TLCREATE = 14,
 P9_RLCREATE,
 P9_TSYMLINK = 16,
-- 
1.6.5.2




[Qemu-devel] [PATCH 06/20] virtio-9p: getattr server implementation for 9P2000.L protocol.

2010-06-28 Thread Venkateswararao Jujjuri (JV)
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

 st_blocks[8]
Number of file system blocks allocated

 st_atime_sec[8]
Time of last access, seconds

 st_atime_nsec[8]
Time of last access, nanoseconds

 st_mtime_sec[8]
Time of last modification, seconds

 st_mtime_nsec[8]
Time of last modification, nanoseconds

 st_ctime_sec[8]
Time of last status change, seconds

 st_ctime_nsec[8]
Time of last status change, nanoseconds

This patch implements the client side of getattr implementation for 9P2000.L.
It introduces a new structure p9_stat_dotl for getting Linux stat information
along with QID. The data layout is similar to stat structure in Linux user
space with the following major differences:

inode (st_ino) is not part of data. Instead qid is.

device (st_dev) is not part of data because this doesn't make sense on the
client.

All time variables are 64 bit wide on the wire. The kernel seems to use
32 bit variables for these variables. However, some of the architectures
have used 64 bit variables and glibc exposes 64 bit variables to user
space on some architectures. Hence to be on the safer side we have made
these 64 bit in the protocol. Refer to the comments in
include/asm-generic/stat.h

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-debug.c |   32 +++
 hw/virtio-9p.c   |   82 ++
 hw/virtio-9p.h   |   28 +
 3 files changed, 142 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index 030b3e6..6072491 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -178,6 +178,30 @@ static void pprint_stat(V9fsPDU *pdu, int rx, size_t 
*offsetp, const char *name)
 fprintf(llogfile, });
 }
 
+static void pprint_stat_dotl(V9fsPDU *pdu, int rx, size_t *offsetp,
+  const char *name)
+{
+fprintf(llogfile, %s={, name);
+pprint_qid(pdu, rx, offsetp, qid);
+pprint_int32(pdu, rx, offsetp, , st_mode);
+pprint_int64(pdu, rx, offsetp, , st_nlink);
+pprint_int32(pdu, rx, offsetp, , st_uid);
+pprint_int32(pdu, rx, offsetp, , st_gid);
+pprint_int64(pdu, rx, offsetp, , st_rdev);
+pprint_int64(pdu, rx, offsetp, , st_size);
+pprint_int64(pdu, rx, offsetp, , st_blksize);
+pprint_int64(pdu, rx, offsetp, , st_blocks);
+pprint_int64(pdu, rx, offsetp, , atime);
+pprint_int64(pdu, rx, offsetp, , atime_nsec);
+pprint_int64(pdu, rx, offsetp, , mtime);
+pprint_int64(pdu, rx, offsetp, , mtime_nsec);
+pprint_int64(pdu, rx, offsetp, , ctime);
+pprint_int64(pdu, rx, offsetp, , ctime_nsec);
+fprintf(llogfile, });
+}
+
+
+
 static void pprint_strs(V9fsPDU *pdu, int rx, size_t *offsetp, const char 
*name)
 {
 int sg_count = get_sg_count(pdu, rx);
@@ -351,6 +375,14 @@ void pprint_pdu(V9fsPDU *pdu)
 pprint_int32(pdu, 1, offset, msize);
 pprint_str(pdu, 1, offset, , version);
 break;
+case P9_TGETATTR:
+fprintf(llogfile, TGETATTR: ();
+pprint_int32(pdu, 0, offset, fid);
+break;
+case P9_RGETATTR:
+fprintf(llogfile, RGETATTR: ();
+pprint_stat_dotl(pdu, 1, offset, getattr);
+break;
 case P9_TAUTH:
 fprintf(llogfile, TAUTH: ();
 pprint_int32(pdu, 0, offset, afid);
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 00527c4..3a1a524 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -736,6 +736,17 @@ static size_t pdu_marshal(V9fsPDU *pdu, size_t offset, 
const char *fmt, ...)
 statp-n_gid, statp-n_muid);
 break;
 }
+case 'A': {
+V9fsStatDotl *statp = va_arg(ap, V9fsStatDotl *);
+offset += 

[Qemu-devel] [PATCH 12/20] [virtio-9p] This patch implements TLCREATE for 9p2000.L protocol.

2010-06-28 Thread Venkateswararao Jujjuri (JV)
SYNOPSIS

size[4] Tlcreate tag[2] fid[4] name[s] flags[4] mode[4] gid[4]

size[4] Rlcreate tag[2] qid[13] iounit[4]

DESCRIPTION

The Tlreate request asks the file server to create a new regular file with the
name supplied, in the directory (dir) represented by fid.
The mode argument specifies the permissions to use. New file is created with
the uid if the fid and with supplied gid.

The flags argument represent Linux access mode flags with which the caller
is requesting to open the file with. Protocol allows all the Linux access
modes but it is upto the server to allow/disallow any of these acess modes.
If the server doesn't support any of the access mode, it is expected to
return error.

To start with we will not restricit/limit any Linux flags on this server.
If needed, We can start restricting as we move forward with various use cases.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-debug.c |   13 ++
 hw/virtio-9p.c   |  100 ++---
 hw/virtio-9p.h   |   13 ++
 3 files changed, 119 insertions(+), 7 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index e389959..a9680df 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -473,6 +473,19 @@ void pprint_pdu(V9fsPDU *pdu)
 fprintf(llogfile, RSYMLINK: ();
 pprint_qid(pdu, 1, offset, qid);
 break;
+case P9_TLCREATE:
+fprintf(llogfile, TLCREATE: ();
+pprint_int32(pdu, 0, offset, dfid);
+pprint_str(pdu, 0, offset, , name);
+pprint_int32(pdu, 0, offset, , flags);
+pprint_int32(pdu, 0, offset, , mode);
+pprint_int32(pdu, 0, offset, , gid);
+break;
+case P9_RLCREATE:
+fprintf(llogfile, RLCREATE: ();
+pprint_qid(pdu, 1, offset, qid);
+pprint_int32(pdu, 1, offset, , iounit);
+break;
 case P9_TREAD:
 fprintf(llogfile, TREAD: ();
 pprint_int32(pdu, 0, offset, fid);
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 60ad0fb..4073551 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -187,17 +187,18 @@ static int v9fs_do_fstat(V9fsState *s, int fd, struct 
stat *stbuf)
 return s-ops-fstat(s-ctx, fd, stbuf);
 }
 
-static int v9fs_do_open2(V9fsState *s, V9fsCreateState *vs)
+static int v9fs_do_open2(V9fsState *s, char *fullname, uid_t uid, gid_t gid,
+int flags, int mode)
 {
 FsCred cred;
-int flags;
 
 cred_init(cred);
-cred.fc_uid = vs-fidp-uid;
-cred.fc_mode = vs-perm  0777;
-flags = omode_to_uflags(vs-mode) | O_CREAT;
+cred.fc_uid = uid;
+cred.fc_gid = gid;
+cred.fc_mode = mode  0777;
+flags = flags;
 
-return s-ops-open2(s-ctx, vs-fullname.data, flags, cred);
+return s-ops-open2(s-ctx, fullname, flags, cred);
 }
 
 static int v9fs_do_symlink(V9fsState *s, V9fsFidState *fidp,
@@ -1641,6 +1642,88 @@ out:
 qemu_free(vs);
 }
 
+static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err)
+{
+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,
+vs-iounit);
+err = vs-offset;
+} else {
+err = -errno;
+}
+
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-name);
+v9fs_string_free(vs-fullname);
+qemu_free(vs);
+}
+
+static void v9fs_lcreate_post_get_iounit(V9fsState *s, V9fsLcreateState *vs,
+int err)
+{
+if (err) {
+err = -errno;
+goto out;
+}
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+
+out:
+v9fs_post_lcreate(s, vs, err);
+}
+
+static void v9fs_lcreate_post_do_open2(V9fsState *s, V9fsLcreateState *vs,
+int err)
+{
+if (vs-fidp-fd == -1) {
+err = -errno;
+goto out;
+}
+vs-iounit =  get_iounit(s, vs-fullname);
+v9fs_lcreate_post_get_iounit(s, vs, err);
+return;
+
+out:
+v9fs_post_lcreate(s, vs, err);
+}
+
+static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu)
+{
+int32_t dfid, flags, mode;
+gid_t gid;
+V9fsLcreateState *vs;
+ssize_t err = 0;
+
+vs = qemu_malloc(sizeof(*vs));
+vs-pdu = pdu;
+vs-offset = 7;
+
+v9fs_string_init(vs-fullname);
+
+pdu_unmarshal(vs-pdu, vs-offset, dsddd, dfid, vs-name, flags,
+mode, gid);
+
+vs-fidp = lookup_fid(s, dfid);
+if (vs-fidp == NULL) {
+err = -ENOENT;
+goto out;
+}
+
+v9fs_string_sprintf(vs-fullname, %s/%s, vs-fidp-path.data,
+ vs-name.data);
+
+vs-fidp-fd = v9fs_do_open2(s, vs-fullname.data, vs-fidp-uid,
+gid, flags, mode);
+v9fs_lcreate_post_do_open2(s, vs, err);
+return;
+
+out:
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-name);
+qemu_free(vs);
+}
+
 static void v9fs_clunk(V9fsState *s, V9fsPDU *pdu)
 {
 int32_t fid;
@@ -2228,7 +2311,9 @@ static void 

[Qemu-devel] [PATCH 13/20] qemu: virtio-9p: Implement TMKNOD

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: M. Mohan Kumar mo...@in.ibm.com

Implement TMKNOD as part of 2000.L Work

Synopsis

size[4] Tmknod tag[2] fid[4] name[s] mode[4] major[4] minor[4] gid[4]

size[4] Rmknod tag[2] qid[13]

Description

mknod asks the file server to create a device node with given device
type, mode and gid. The qid for the new device node is returned with
the mknod reply message.

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-debug.c |   13 +++
 hw/virtio-9p.c   |   90 ++
 hw/virtio-9p.h   |   11 ++
 3 files changed, 107 insertions(+), 7 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index a9680df..fdfd04f 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -486,6 +486,19 @@ void pprint_pdu(V9fsPDU *pdu)
 pprint_qid(pdu, 1, offset, qid);
 pprint_int32(pdu, 1, offset, , iounit);
 break;
+case P9_TMKNOD:
+   fprintf(llogfile, TMKNOD: ();
+pprint_int32(pdu, 0, offset, fid);
+pprint_str(pdu, 0, offset, name);
+pprint_int32(pdu, 0, offset, mode);
+pprint_int32(pdu, 0, offset, major);
+pprint_int32(pdu, 0, offset, minor);
+pprint_int32(pdu, 0, offset, gid);
+break;
+case P9_RMKNOD:
+fprintf(llogfile, RMKNOD: ));
+pprint_qid(pdu, 0, offset, qid);
+break;
 case P9_TREAD:
 fprintf(llogfile, TREAD: ();
 pprint_int32(pdu, 0, offset, fid);
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 4073551..9ae2a1a 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -160,15 +160,16 @@ static int v9fs_do_chmod(V9fsState *s, V9fsString *path, 
mode_t mode)
 return s-ops-chmod(s-ctx, path-data, cred);
 }
 
-static int v9fs_do_mknod(V9fsState *s, V9fsCreateState *vs, mode_t mode,
-dev_t dev)
+static int v9fs_do_mknod(V9fsState *s, char *name,
+mode_t mode, dev_t dev, uid_t uid, gid_t gid)
 {
 FsCred cred;
 cred_init(cred);
-cred.fc_uid = vs-fidp-uid;
+cred.fc_uid = uid;
+cred.fc_gid = gid;
 cred.fc_mode = mode;
 cred.fc_rdev = dev;
-return s-ops-mknod(s-ctx, vs-fullname.data, cred);
+return s-ops-mknod(s-ctx, name, cred);
 }
 
 static int v9fs_do_mkdir(V9fsState *s, V9fsCreateState *vs)
@@ -2302,13 +2303,16 @@ static void v9fs_create_post_lstat(V9fsState *s, 
V9fsCreateState *vs, int err)
 }
 
 nmode |= vs-perm  0777;
-err = v9fs_do_mknod(s, vs, nmode, makedev(major, minor));
+err = v9fs_do_mknod(s, vs-fullname.data, nmode,
+makedev(major, minor), vs-fidp-uid, -1);
 v9fs_create_post_perms(s, vs, err);
 } else if (vs-perm  P9_STAT_MODE_NAMED_PIPE) {
-err = v9fs_do_mknod(s, vs, S_IFIFO | (vs-perm  0777), 0);
+err = v9fs_do_mknod(s, vs-fullname.data, S_IFIFO | (vs-perm  0777),
+0, vs-fidp-uid, -1);
 v9fs_post_create(s, vs, err);
 } else if (vs-perm  P9_STAT_MODE_SOCKET) {
-err = v9fs_do_mknod(s, vs, S_IFSOCK | (vs-perm  0777), 0);
+err = v9fs_do_mknod(s, vs-fullname.data, S_IFSOCK | (vs-perm  0777),
+0, vs-fidp-uid, -1);
 v9fs_post_create(s, vs, err);
 } else {
 vs-fidp-fd = v9fs_do_open2(s, vs-fullname.data, vs-fidp-uid,
@@ -2820,6 +2824,77 @@ out:
 qemu_free(vs);
 }
 
+static void v9fs_mknod_post_lstat(V9fsState *s, V9fsMkState *vs, int err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+
+stat_to_qid(vs-stbuf, vs-qid);
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
+err = vs-offset;
+out:
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-fullname);
+v9fs_string_free(vs-name);
+qemu_free(vs);
+}
+
+static void v9fs_mknod_post_mknod(V9fsState *s, V9fsMkState *vs, int err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+v9fs_mknod_post_lstat(s, vs, err);
+return;
+out:
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-fullname);
+v9fs_string_free(vs-name);
+qemu_free(vs);
+}
+
+static void v9fs_mknod(V9fsState *s, V9fsPDU *pdu)
+{
+int32_t fid;
+V9fsMkState *vs;
+int err = 0;
+V9fsFidState *fidp;
+gid_t gid;
+int mode;
+int major, minor;
+
+vs = qemu_malloc(sizeof(*vs));
+vs-pdu = pdu;
+vs-offset = 7;
+
+v9fs_string_init(vs-fullname);
+pdu_unmarshal(vs-pdu, vs-offset, ds, fid, vs-name, mode,
+major, minor, gid);
+
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+err = -ENOENT;
+goto out;
+}
+
+v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
+err = v9fs_do_mknod(s, vs-fullname.data, mode, makedev(major, minor),
+fidp-uid, gid);
+v9fs_mknod_post_mknod(s, vs, err);
+return;
+
+out:
+

[Qemu-devel] [PATCH 01/20] qemu: virtio-9p: Recognize 9P2000.L protocol

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: M. Mohan Kumar mo...@in.ibm.com

Make 9P server recognize 9P2000.L protocol version

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p.c |6 +-
 hw/virtio-9p.h |6 ++
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index f8c85c3..e41c51e 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1025,7 +1025,11 @@ static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
 
 pdu_unmarshal(pdu, offset, ds, msize, version);
 
-if (strcmp(version.data, 9P2000.u)) {
+if (!strcmp(version.data, 9P2000.u)) {
+s-proto_version = V9FS_PROTO_2000U;
+} else if (!strcmp(version.data, 9P2000.L)) {
+s-proto_version = V9FS_PROTO_2000L;
+} else {
 v9fs_string_sprintf(version, unknown);
 }
 
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 67f8087..9286f59 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -57,6 +57,11 @@ enum {
 P9_QTFILE = 0x00,
 };
 
+enum p9_proto_version {
+V9FS_PROTO_2000U = 0x01,
+V9FS_PROTO_2000L = 0x02,
+};
+
 #define P9_NOTAG(u16)(~0)
 #define P9_NOFID(u32)(~0)
 #define P9_MAXWELEM 16
@@ -144,6 +149,7 @@ typedef struct V9fsState
 uint16_t tag_len;
 uint8_t *tag;
 size_t config_size;
+enum p9_proto_version proto_version;
 } V9fsState;
 
 typedef struct V9fsCreateState {
-- 
1.6.5.2




[Qemu-devel] [PATCH 19/20] virtio-9p: Implement TXATTRCREATE

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

TXATTRCREATE:  Prepare a fid for setting xattr value on a file system object.

 size[4] TXATTRCREATE tag[2] fid[4] name[s] attr_size[8] flags[4]
 size[4] RXATTRWALK tag[2]

txattrcreate gets a fid pointing to xattr. This fid can later be
used to get set the xattr value.

flag value is derived from set Linux setxattr. The manpage says
The flags parameter can be used to refine the semantics of the operation.
XATTR_CREATE specifies a pure create, which fails if the named attribute
exists already. XATTR_REPLACE specifies a pure replace operation, which
fails if the named attribute does not already exist. By default (no flags),
the extended attribute will be created if need be, or will simply replace
the value if the attribute exists.

The actual setxattr operation happens when the fid is clunked. At that point
the written byte count and the attr_size specified in TXATTRCREATE should be
same otherwise an error will be returned.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/file-op-9p.h  |2 +
 hw/virtio-9p-debug.c |9 +++
 hw/virtio-9p-local.c |7 +++
 hw/virtio-9p.c   |  143 ++---
 hw/virtio-9p.h   |2 +
 5 files changed, 154 insertions(+), 9 deletions(-)

diff --git a/hw/file-op-9p.h b/hw/file-op-9p.h
index 8f466b4..2563f7b 100644
--- a/hw/file-op-9p.h
+++ b/hw/file-op-9p.h
@@ -78,6 +78,8 @@ typedef struct FileOperations
 ssize_t (*lgetxattr)(FsContext *, const char *, const char *, void *,
 size_t);
 ssize_t (*llistxattr)(FsContext *, const char *, void *, size_t);
+int (*lsetxattr)(FsContext *, const char *, const char *, void *, size_t,
+int);
 void *opaque;
 } FileOperations;
 #endif
diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index 47d565a..70f2aec 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -586,6 +586,15 @@ void pprint_pdu(V9fsPDU *pdu)
 case P9_RXATTRWALK:
 fprintf(llogfile, RXATTRWALK: ();
 pprint_int64(pdu, 1, offset, xattrsize);
+case P9_TXATTRCREATE:
+fprintf(llogfile, TXATTRCREATE: ();
+pprint_int32(pdu, 0, offset, fid);
+pprint_str(pdu, 0, offset, , name);
+pprint_int64(pdu, 0, offset, , xattrsize);
+pprint_int32(pdu, 0, offset, , flags);
+break;
+case P9_RXATTRCREATE:
+fprintf(llogfile, RXATTRCREATE: ();
 break;
 default:
 fprintf(llogfile, unknown(%d): (, pdu-id);
diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 5a3f5b8..3944cf3 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -489,6 +489,12 @@ static ssize_t local_llistxattr(FsContext *ctx, const char 
*path,
 return llistxattr(rpath(ctx, path), value, size);
 }
 
+static int local_lsetxattr(FsContext *ctx, const char *path, const char *name,
+  void *value, size_t size, int flags)
+{
+return lsetxattr(rpath(ctx, path), name, value, size, flags);
+}
+
 FileOperations local_ops = {
 .lstat = local_lstat,
 .readlink = local_readlink,
@@ -519,4 +525,5 @@ FileOperations local_ops = {
 .statfs = local_statfs,
 .lgetxattr = local_lgetxattr,
 .llistxattr = local_llistxattr,
+.lsetxattr = local_lsetxattr,
 };
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index ad383f9..f7ca0f6 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -278,6 +278,14 @@ static ssize_t v9fs_do_llistxattr(V9fsState *s, V9fsString 
*path,
   value, size);
 }
 
+static int v9fs_do_lsetxattr(V9fsState *s, V9fsString *path,
+ V9fsString *xattr_name,
+ void *value, size_t size, int flags)
+{
+return s-ops-lsetxattr(s-ctx, path-data,
+ xattr_name-data, value, size, flags);
+}
+
 static void v9fs_string_init(V9fsString *str)
 {
 str-data = NULL;
@@ -431,8 +439,39 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
 return f;
 }
 
+static int v9fs_xattr_fid_clunk(V9fsState *s, V9fsFidState *fidp)
+{
+int retval = 0;
+
+if (fidp-fs.xattr.copied_len == -1) {
+   /* getxattr/listxattr fid */
+   goto free_value;
+}
+/*
+ * if this is fid for setxattr. clunk should
+ * result in setxattr localcall
+ */
+if (fidp-fs.xattr.len != fidp-fs.xattr.copied_len) {
+   /* clunk after partial write */
+   retval = -EINVAL;
+   goto free_out;
+}
+retval = v9fs_do_lsetxattr(s, fidp-path, fidp-fs.xattr.name,
+  fidp-fs.xattr.value,
+  fidp-fs.xattr.len,
+  fidp-fs.xattr.flags);
+free_out:
+v9fs_string_free(fidp-fs.xattr.name);
+free_value:
+if (fidp-fs.xattr.value) {
+   qemu_free(fidp-fs.xattr.value);
+}
+return retval;
+}
+
 static int 

[Qemu-devel] [PATCH 08/20] [virtio-9p] Make v9fs_do_utimensat accept timespec structures instead of v9stat.

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: Sripathi Kodi sripat...@in.ibm.com

Currently v9fs_do_utimensat takes a V9fsStat argument and builds
timespec structures. It sets tv_nsec values to 0 by default. Instead
of this it should take struct timespec[2] and pass it down to the
system directly. This will make it more generic and useful
elsewhere.

Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p.c |   37 ++---
 1 files changed, 18 insertions(+), 19 deletions(-)

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




[Qemu-devel] [PATCH 10/20] [virtio-9p] Implement TLINK for 9P2000.L

2010-06-28 Thread Venkateswararao Jujjuri (JV)
Create a Hardlink.

SYNOPSIS

size[4] Tlink tag[2] dfid[4] oldfid[4] newpath[s]

size[4] Rlink tag[2]

DESCRIPTION

Create a link 'newpath' in directory pointed by dfid linking to oldfid path.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-debug.c |9 +
 hw/virtio-9p.c   |   38 ++
 hw/virtio-9p.h   |2 ++
 3 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index 6072491..18ef485 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -495,6 +495,15 @@ void pprint_pdu(V9fsPDU *pdu)
 case P9_RCLUNK:
 fprintf(llogfile, RCLUNK: ();
 break;
+case P9_TLINK:
+fprintf(llogfile, TLINK: ();
+pprint_int32(pdu, 0, offset, fid);
+pprint_str(pdu, 0, offset, , oldpath);
+pprint_str(pdu, 0, offset, , newpath);
+break;
+case P9_RLINK:
+fprintf(llogfile, RLINK: ();
+break;
 case P9_TREMOVE:
 fprintf(llogfile, TREMOVE: ();
 pprint_int32(pdu, 0, offset, fid);
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index b1b3cb5..dc7ef10 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -2277,6 +2277,43 @@ static void v9fs_flush(V9fsState *s, V9fsPDU *pdu)
 complete_pdu(s, pdu, 7);
 }
 
+static void v9fs_link(V9fsState *s, V9fsPDU *pdu)
+{
+int32_t dfid, oldfid;
+V9fsFidState *dfidp, *oldfidp;
+V9fsString name, fullname;
+size_t offset = 7;
+int err = 0;
+
+v9fs_string_init(fullname);
+
+pdu_unmarshal(pdu, offset, dds, dfid, oldfid, name);
+
+dfidp = lookup_fid(s, dfid);
+if (dfidp == NULL) {
+err = -errno;
+goto out;
+}
+
+oldfidp = lookup_fid(s, oldfid);
+if (oldfidp == NULL) {
+err = -errno;
+goto out;
+}
+
+v9fs_string_sprintf(fullname, %s/%s, dfidp-path.data, name.data);
+err = offset;
+err = v9fs_do_link(s, oldfidp-path, fullname);
+if (err) {
+err = -errno;
+}
+v9fs_string_free(fullname);
+
+out:
+v9fs_string_free(name);
+complete_pdu(s, pdu, err);
+}
+
 static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs,
 int err)
 {
@@ -2651,6 +2688,7 @@ static pdu_handler_t *pdu_handlers[] = {
 [P9_TAUTH] = v9fs_auth,
 #endif
 [P9_TFLUSH] = v9fs_flush,
+[P9_TLINK] = v9fs_link,
 [P9_TCREATE] = v9fs_create,
 [P9_TWRITE] = v9fs_write,
 [P9_TWSTAT] = v9fs_wstat,
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index a0ee7d3..a31d5ff 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -21,6 +21,8 @@ enum {
 P9_RSETATTR,
 P9_TREADDIR = 40,
 P9_RREADDIR,
+P9_TLINK = 70,
+P9_RLINK,
 P9_TVERSION = 100,
 P9_RVERSION,
 P9_TAUTH = 102,
-- 
1.6.5.2




[Qemu-devel] [PATCH 11/20] [virtio-9p] Define and implement TSYMLINK for 9P2000.L

2010-06-28 Thread Venkateswararao Jujjuri (JV)
This patch implements creating a symlink for TSYMLINK request
and responds with RSYMLINK. In the case of error, we return RERROR.

SYNOPSIS

size[4] Tsymlink tag[2] fid[4] name[s] symtgt[s] gid[4]

size[4] Rsymlink tag[2] qid[13]

DESCRIPTION

Create a symbolic link named 'name' pointing to 'symtgt'.
gid represents the effective group id of the caller.
The  permissions of a symbolic link are irrelevant hence it is omitted
from the protocol.

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-debug.c |   11 +++
 hw/virtio-9p.c   |   78 ++
 hw/virtio-9p.h   |   14 +
 3 files changed, 97 insertions(+), 6 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index 18ef485..e389959 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -462,6 +462,17 @@ void pprint_pdu(V9fsPDU *pdu)
 pprint_qid(pdu, 1, offset, qid);
 pprint_int32(pdu, 1, offset, , iounit);
 break;
+case P9_TSYMLINK:
+fprintf(llogfile, TSYMLINK: ();
+pprint_int32(pdu, 0, offset, fid);
+pprint_str(pdu, 0, offset, , name);
+pprint_str(pdu, 0, offset, , symname);
+pprint_int32(pdu, 0, offset, , gid);
+break;
+case P9_RSYMLINK:
+fprintf(llogfile, RSYMLINK: ();
+pprint_qid(pdu, 1, offset, qid);
+break;
 case P9_TREAD:
 fprintf(llogfile, TREAD: ();
 pprint_int32(pdu, 0, offset, fid);
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index dc7ef10..60ad0fb 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -200,15 +200,16 @@ static int v9fs_do_open2(V9fsState *s, V9fsCreateState 
*vs)
 return s-ops-open2(s-ctx, vs-fullname.data, flags, cred);
 }
 
-static int v9fs_do_symlink(V9fsState *s, V9fsCreateState *vs)
+static int v9fs_do_symlink(V9fsState *s, V9fsFidState *fidp,
+const char *oldpath, const char *newpath, gid_t gid)
 {
 FsCred cred;
 cred_init(cred);
-cred.fc_uid = vs-fidp-uid;
-cred.fc_mode = vs-perm | 0777;
+cred.fc_uid = fidp-uid;
+cred.fc_gid = gid;
+cred.fc_mode = 0777;
 
-return s-ops-symlink(s-ctx, vs-extension.data, vs-fullname.data,
-cred);
+return s-ops-symlink(s-ctx, oldpath, newpath, cred);
 }
 
 static int v9fs_do_link(V9fsState *s, V9fsString *oldpath, V9fsString *newpath)
@@ -2182,7 +2183,8 @@ static void v9fs_create_post_lstat(V9fsState *s, 
V9fsCreateState *vs, int err)
 err = v9fs_do_mkdir(s, vs);
 v9fs_create_post_mkdir(s, vs, err);
 } else if (vs-perm  P9_STAT_MODE_SYMLINK) {
-err = v9fs_do_symlink(s, vs);
+err = v9fs_do_symlink(s, vs-fidp, vs-extension.data,
+vs-fullname.data, -1);
 v9fs_create_post_perms(s, vs, err);
 } else if (vs-perm  P9_STAT_MODE_LINK) {
 int32_t nfid = atoi(vs-extension.data);
@@ -2271,6 +2273,69 @@ out:
 qemu_free(vs);
 }
 
+static void v9fs_post_symlink(V9fsState *s, V9fsSymlinkState *vs, int err)
+{
+if (err == 0) {
+stat_to_qid(vs-stbuf, vs-qid);
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
+err = vs-offset;
+} else {
+err = -errno;
+}
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-name);
+v9fs_string_free(vs-symname);
+v9fs_string_free(vs-fullname);
+qemu_free(vs);
+}
+
+static void v9fs_symlink_post_do_symlink(V9fsState *s, V9fsSymlinkState *vs,
+int err)
+{
+if (err) {
+goto out;
+}
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+out:
+v9fs_post_symlink(s, vs, err);
+}
+
+static void v9fs_symlink(V9fsState *s, V9fsPDU *pdu)
+{
+int32_t dfid;
+V9fsSymlinkState *vs;
+int err = 0;
+gid_t gid;
+
+vs = qemu_malloc(sizeof(*vs));
+vs-pdu = pdu;
+vs-offset = 7;
+
+v9fs_string_init(vs-fullname);
+
+pdu_unmarshal(vs-pdu, vs-offset, dssd, dfid, vs-name,
+vs-symname, gid);
+
+vs-dfidp = lookup_fid(s, dfid);
+if (vs-dfidp == NULL) {
+err = -EINVAL;
+goto out;
+}
+
+v9fs_string_sprintf(vs-fullname, %s/%s, vs-dfidp-path.data,
+vs-name.data);
+err = v9fs_do_symlink(s, vs-dfidp, vs-symname.data,
+vs-fullname.data, gid);
+v9fs_symlink_post_do_symlink(s, vs, err);
+return;
+
+out:
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-name);
+v9fs_string_free(vs-symname);
+qemu_free(vs);
+}
+
 static void v9fs_flush(V9fsState *s, V9fsPDU *pdu)
 {
 /* A nop call with no return */
@@ -2689,6 +2754,7 @@ static pdu_handler_t *pdu_handlers[] = {
 #endif
 [P9_TFLUSH] = v9fs_flush,
 [P9_TLINK] = v9fs_link,
+[P9_TSYMLINK] = v9fs_symlink,
 [P9_TCREATE] = v9fs_create,
 [P9_TWRITE] = v9fs_write,
 [P9_TWSTAT] = v9fs_wstat,
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index a31d5ff..90ff58c 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -15,6 +15,8 @@
 

[Qemu-devel] [PATCH 14/20] qemu: virtio-9p: Implement TMKDIR

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: M. Mohan Kumar mo...@in.ibm.com

Synopsis

size[4] Tmkdir tag[2] fid[4] name[s] mode[4] gid[4]

size[4] Rmkdir tag[2] qid[13]

Description

mkdir asks the file server to create a directory with given name,
mode and gid. The qid for the new directory is returned with
the mkdir reply message.

Note: 72 is selected as the opcode for TMKDIR from the reserved list.

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
[jv...@linux.vnet.ibm.com: Fix perm handling when creating directory]

Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-debug.c |   11 ++
 hw/virtio-9p.c   |   83 +++---
 hw/virtio-9p.h   |2 +
 3 files changed, 91 insertions(+), 5 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index fdfd04f..18e355c 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -365,6 +365,17 @@ void pprint_pdu(V9fsPDU *pdu)
 pprint_data(pdu, 1, offset, , data);
 #endif
 break;
+case P9_TMKDIR:
+fprintf(llogfile, TMKDIR: ();
+pprint_int32(pdu, 0, offset, fid);
+pprint_str(pdu, 0, offset, name);
+pprint_int32(pdu, 0, offset, mode);
+pprint_int32(pdu, 0, offset, gid);
+break;
+case P9_RMKDIR:
+fprintf(llogfile, RMKDIR: ();
+pprint_qid(pdu, 0, offset, qid);
+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 9ae2a1a..4f28d86 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -172,15 +172,17 @@ static int v9fs_do_mknod(V9fsState *s, char *name,
 return s-ops-mknod(s-ctx, name, cred);
 }
 
-static int v9fs_do_mkdir(V9fsState *s, V9fsCreateState *vs)
+static int v9fs_do_mkdir(V9fsState *s, char *name, mode_t mode,
+uid_t uid, gid_t gid)
 {
 FsCred cred;
 
 cred_init(cred);
-cred.fc_uid = vs-fidp-uid;
-cred.fc_mode = vs-perm  0777;
+cred.fc_uid = uid;
+cred.fc_gid = gid;
+cred.fc_mode = mode;
 
-return s-ops-mkdir(s-ctx, vs-fullname.data, cred);
+return s-ops-mkdir(s-ctx, name, cred);
 }
 
 static int v9fs_do_fstat(V9fsState *s, int fd, struct stat *stbuf)
@@ -2264,7 +2266,8 @@ static void v9fs_create_post_lstat(V9fsState *s, 
V9fsCreateState *vs, int err)
 }
 
 if (vs-perm  P9_STAT_MODE_DIR) {
-err = v9fs_do_mkdir(s, vs);
+err = v9fs_do_mkdir(s, vs-fullname.data, vs-perm  0777,
+vs-fidp-uid, -1);
 v9fs_create_post_mkdir(s, vs, err);
 } else if (vs-perm  P9_STAT_MODE_SYMLINK) {
 err = v9fs_do_symlink(s, vs-fidp, vs-extension.data,
@@ -2895,6 +2898,75 @@ out:
 qemu_free(vs);
 }
 
+static void v9fs_mkdir_post_lstat(V9fsState *s, V9fsMkState *vs, int err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+
+stat_to_qid(vs-stbuf, vs-qid);
+vs-offset += pdu_marshal(vs-pdu, vs-offset, Q, vs-qid);
+err = vs-offset;
+out:
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-fullname);
+v9fs_string_free(vs-name);
+qemu_free(vs);
+}
+
+static void v9fs_mkdir_post_mkdir(V9fsState *s, V9fsMkState *vs, int err)
+{
+if (err == -1) {
+err = -errno;
+goto out;
+}
+
+err = v9fs_do_lstat(s, vs-fullname, vs-stbuf);
+v9fs_mkdir_post_lstat(s, vs, err);
+return;
+out:
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-fullname);
+v9fs_string_free(vs-name);
+qemu_free(vs);
+}
+
+static void v9fs_mkdir(V9fsState *s, V9fsPDU *pdu)
+{
+int32_t fid;
+V9fsMkState *vs;
+int err = 0;
+V9fsFidState *fidp;
+gid_t gid;
+int mode;
+
+vs = qemu_malloc(sizeof(*vs));
+vs-pdu = pdu;
+vs-offset = 7;
+
+v9fs_string_init(vs-fullname);
+pdu_unmarshal(vs-pdu, vs-offset, dsdd, fid, vs-name, mode,
+gid);
+
+fidp = lookup_fid(s, fid);
+if (fidp == NULL) {
+err = -ENOENT;
+goto out;
+}
+
+v9fs_string_sprintf(vs-fullname, %s/%s, fidp-path.data, 
vs-name.data);
+err = v9fs_do_mkdir(s, vs-fullname.data, mode, fidp-uid, gid);
+v9fs_mkdir_post_mkdir(s, vs, err);
+return;
+
+out:
+complete_pdu(s, vs-pdu, err);
+v9fs_string_free(vs-fullname);
+v9fs_string_free(vs-name);
+qemu_free(vs);
+}
+
 typedef void (pdu_handler_t)(V9fsState *s, V9fsPDU *pdu);
 
 static pdu_handler_t *pdu_handlers[] = {
@@ -2903,6 +2975,7 @@ static pdu_handler_t *pdu_handlers[] = {
 [P9_TGETATTR] = v9fs_getattr,
 [P9_TSETATTR] = v9fs_setattr,
 [P9_TMKNOD] = v9fs_mknod,
+[P9_TMKDIR] = v9fs_mkdir,
 [P9_TVERSION] = v9fs_version,
 [P9_TATTACH] = v9fs_attach,
 [P9_TSTAT] = v9fs_stat,
diff --git a/hw/virtio-9p.h b/hw/virtio-9p.h
index 4e7797a..81a1489 100644
--- a/hw/virtio-9p.h
+++ b/hw/virtio-9p.h
@@ -29,6 +29,8 @@ enum {
 P9_RREADDIR,
 P9_TLINK = 70,
 P9_RLINK,
+P9_TMKDIR = 72,
+

[Qemu-devel] [PATCH 17/20] virtio-9p: Add fidtype so that we can do type specific operation

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

We want to add type specific operation during read/write

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/virtio-9p.c |  110 ++--
 hw/virtio-9p.h |   24 +++-
 2 files changed, 81 insertions(+), 53 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index a9da10f..79d9195 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -408,8 +408,7 @@ static V9fsFidState *alloc_fid(V9fsState *s, int32_t fid)
 f = qemu_mallocz(sizeof(V9fsFidState));
 
 f-fid = fid;
-f-fd = -1;
-f-dir = NULL;
+f-fid_type = P9_FID_NONE;
 
 f-next = s-fid_list;
 s-fid_list = f;
@@ -434,11 +433,20 @@ static int free_fid(V9fsState *s, int32_t fid)
 fidp = *fidpp;
 *fidpp = fidp-next;
 
-if (fidp-fd != -1) {
-v9fs_do_close(s, fidp-fd);
+if (fidp-fid_type == P9_FID_FILE) {
+if (fidp-fs.fd != -1) {
+   v9fs_do_close(s, fidp-fs.fd);
+}
+}
+if (fidp-fid_type == P9_FID_DIR) {
+if (fidp-fs.dir) {
+   v9fs_do_closedir(s, fidp-fs.dir);
+}
 }
-if (fidp-dir) {
-v9fs_do_closedir(s, fidp-dir);
+if (fidp-fid_type == P9_FID_XATTR) {
+   if (fidp-fs.xattr.value) {
+   qemu_free(fidp-fs.xattr.value);
+   }
 }
 v9fs_string_free(fidp-path);
 qemu_free(fidp);
@@ -1489,8 +1497,7 @@ static void v9fs_walk(V9fsState *s, V9fsPDU *pdu)
 /* FIXME: is this really valid? */
 if (fid == newfid) {
 
-BUG_ON(vs-fidp-fd != -1);
-BUG_ON(vs-fidp-dir);
+BUG_ON(vs-fidp-fid_type != P9_FID_NONE);
 v9fs_string_init(vs-path);
 vs-name_idx = 0;
 
@@ -1554,11 +1561,12 @@ static int32_t get_iounit(V9fsState *s, V9fsString 
*name)
 
 static void v9fs_open_post_opendir(V9fsState *s, V9fsOpenState *vs, int err)
 {
-if (vs-fidp-dir == NULL) {
+if (vs-fidp-fs.dir == NULL) {
 err = -errno;
 goto out;
 }
 
+vs-fidp-fid_type = P9_FID_DIR;
 vs-offset += pdu_marshal(vs-pdu, vs-offset, Qd, vs-qid, 0);
 err = vs-offset;
 out:
@@ -1578,11 +1586,11 @@ static void v9fs_open_post_getiounit(V9fsState *s, 
V9fsOpenState *vs)
 
 static void v9fs_open_post_open(V9fsState *s, V9fsOpenState *vs, int err)
 {
-if (vs-fidp-fd == -1) {
+if (vs-fidp-fs.fd == -1) {
 err = -errno;
 goto out;
 }
-
+vs-fidp-fid_type = P9_FID_FILE;
 vs-iounit = get_iounit(s, vs-fidp-path);
 v9fs_open_post_getiounit(s, vs);
 return;
@@ -1612,7 +1620,7 @@ static void v9fs_open_post_lstat(V9fsState *s, 
V9fsOpenState *vs, int err)
 stat_to_qid(vs-stbuf, vs-qid);
 
 if (S_ISDIR(vs-stbuf.st_mode)) {
-vs-fidp-dir = v9fs_do_opendir(s, vs-fidp-path);
+vs-fidp-fs.dir = v9fs_do_opendir(s, vs-fidp-path);
 v9fs_open_post_opendir(s, vs, err);
 } else {
 if (s-proto_version == V9FS_PROTO_2000L) {
@@ -1624,7 +1632,7 @@ static void v9fs_open_post_lstat(V9fsState *s, 
V9fsOpenState *vs, int err)
 } else {
 flags = omode_to_uflags(vs-mode);
 }
-vs-fidp-fd = v9fs_do_open(s, vs-fidp-path, flags);
+vs-fidp-fs.fd = v9fs_do_open(s, vs-fidp-path, flags);
 v9fs_open_post_open(s, vs, err);
 }
 return;
@@ -1652,8 +1660,7 @@ static void v9fs_open(V9fsState *s, V9fsPDU *pdu)
 goto out;
 }
 
-BUG_ON(vs-fidp-fd != -1);
-BUG_ON(vs-fidp-dir);
+BUG_ON(vs-fidp-fid_type != P9_FID_NONE);
 
 err = v9fs_do_lstat(s, vs-fidp-path, vs-stbuf);
 
@@ -1698,7 +1705,7 @@ out:
 static void v9fs_lcreate_post_do_open2(V9fsState *s, V9fsLcreateState *vs,
 int err)
 {
-if (vs-fidp-fd == -1) {
+if (vs-fidp-fs.fd == -1) {
 err = -errno;
 goto out;
 }
@@ -1735,7 +1742,7 @@ static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu)
 v9fs_string_sprintf(vs-fullname, %s/%s, vs-fidp-path.data,
  vs-name.data);
 
-vs-fidp-fd = v9fs_do_open2(s, vs-fullname.data, vs-fidp-uid,
+vs-fidp-fs.fd = v9fs_do_open2(s, vs-fullname.data, vs-fidp-uid,
 gid, flags, mode);
 v9fs_lcreate_post_do_open2(s, vs, err);
 return;
@@ -1799,7 +1806,7 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, 
V9fsReadState *vs,
 vs-v9stat);
 if ((vs-len != (vs-v9stat.size + 2)) ||
 ((vs-count + vs-len)  vs-max_count)) {
-v9fs_do_seekdir(s, vs-fidp-dir, vs-dir_pos);
+v9fs_do_seekdir(s, vs-fidp-fs.dir, vs-dir_pos);
 v9fs_read_post_seekdir(s, vs, err);
 return;
 }
@@ -1807,11 +1814,11 @@ static void v9fs_read_post_dir_lstat(V9fsState *s, 
V9fsReadState *vs,
 v9fs_stat_free(vs-v9stat);
 v9fs_string_free(vs-name);
 vs-dir_pos = vs-dent-d_off;
-vs-dent = v9fs_do_readdir(s, vs-fidp-dir);
+vs-dent = v9fs_do_readdir(s, vs-fidp-fs.dir);
 v9fs_read_post_readdir(s, vs, err);
 return;
 out:
-

[Qemu-devel] [PATCH 20/20] virtio-9p: Hide user.virtfs xattr in case of mapped security.

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

With mapped security mode we use user.virtfs namespace is used
to store the virtFs related attributes. So hide it from user.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p-local.c |   75 --
 1 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-9p-local.c b/hw/virtio-9p-local.c
index 3944cf3..87ff953 100644
--- a/hw/virtio-9p-local.c
+++ b/hw/virtio-9p-local.c
@@ -480,18 +480,87 @@ static int local_statfs(FsContext *s, const char *path, 
struct statfs *stbuf)
 static ssize_t local_lgetxattr(FsContext *ctx, const char *path,
 const char *name, void *value, size_t size)
 {
+if ((ctx-fs_sm == SM_MAPPED) 
+(strncmp(name, user.virtfs., 12) == 0)) {
+/*
+ * Don't allow fetch of user.virtfs namesapce
+ * in case of mapped security
+ */
+errno = ENOATTR;
+return -1;
+}
+
 return lgetxattr(rpath(ctx, path), name, value, size);
 }
 
 static ssize_t local_llistxattr(FsContext *ctx, const char *path,
 void *value, size_t size)
 {
-return llistxattr(rpath(ctx, path), value, size);
+ssize_t retval;
+ssize_t actual_len = 0;
+char *orig_value, *orig_value_start;
+char *temp_value, *temp_value_start;
+ssize_t xattr_len, parsed_len = 0, attr_len;
+
+if (ctx-fs_sm != SM_MAPPED) {
+return llistxattr(rpath(ctx, path), value, size);
+}
+
+/* Get the actual len */
+xattr_len = llistxattr(rpath(ctx, path), value, 0);
+
+/* Now fetch the xattr and find the actual size */
+orig_value = qemu_malloc(xattr_len);
+xattr_len = llistxattr(rpath(ctx, path), orig_value, xattr_len);
+
+/*
+ * For mapped security model drop user.virtfs namespace
+ * from the list
+ */
+temp_value = qemu_mallocz(xattr_len);
+temp_value_start = temp_value;
+orig_value_start = orig_value;
+while (xattr_len  parsed_len) {
+attr_len = strlen(orig_value) + 1;
+if (strncmp(orig_value, user.virtfs., 12) != 0) {
+/* Copy this entry */
+strcat(temp_value, orig_value);
+temp_value  += attr_len;
+actual_len += attr_len;
+}
+parsed_len += attr_len;
+orig_value += attr_len;
+}
+if (!size) {
+retval = actual_len;
+goto out;
+} else if (size = actual_len) {
+/* now copy the parsed attribute list back */
+memset(value, 0, size);
+memcpy(value, temp_value_start, actual_len);
+retval = actual_len;
+goto out;
+}
+errno = ERANGE;
+retval = -1;
+out:
+qemu_free(orig_value_start);
+qemu_free(temp_value_start);
+return retval;
 }
 
 static int local_lsetxattr(FsContext *ctx, const char *path, const char *name,
-  void *value, size_t size, int flags)
-{
+   void *value, size_t size, int flags)
+{
+if ((ctx-fs_sm == SM_MAPPED) 
+(strncmp(name, user.virtfs., 12) == 0)) {
+/*
+ * Don't allow fetch of user.virtfs namesapce
+ * in case of mapped security
+ */
+errno = EACCES;
+return -1;
+}
 return lsetxattr(rpath(ctx, path), name, value, size, flags);
 }
 
-- 
1.6.5.2




[Qemu-devel] Re: [PATCH 3/7] net: Introduce VLANClientState-info_dict

2010-06-28 Thread Luiz Capitulino
On Wed, 23 Jun 2010 12:39:59 -0300
Miguel Di Ciurcio Filho miguel.fi...@gmail.com wrote:

 There is no standard format when formatting VLANClientState.info_str,
 so it is difficult to extract information and transmit it over QMP.
 
 This patch adds info_dict, a QDict to better handle this information.
 
 Signed-off-by: Miguel Di Ciurcio Filho miguel.fi...@gmail.com
 ---
  net.c |1 +
  net.h |1 +
  2 files changed, 2 insertions(+), 0 deletions(-)
 
 diff --git a/net.c b/net.c
 index 0703698..7daf253 100644
 --- a/net.c
 +++ b/net.c
 @@ -301,6 +301,7 @@ void qemu_del_vlan_client(VLANClientState *vc)
  
  qemu_free(vc-name);
  qemu_free(vc-model);
 +qemu_free(vc-info_dict);

QDECREF(vc-info_dict);

  qemu_free(vc);
  }
  
 diff --git a/net.h b/net.h
 index 518cf9c..cfe837f 100644
 --- a/net.h
 +++ b/net.h
 @@ -65,6 +65,7 @@ struct VLANClientState {
  char *model;
  char *name;
  char info_str[256];
 +QDict *info_dict;
  unsigned receive_disabled : 1;
  };
  




[Qemu-devel] Re: [PATCH 7/7] monitor/net: introduce 'info netdev' with QMP support

2010-06-28 Thread Luiz Capitulino
On Wed, 23 Jun 2010 12:40:03 -0300
Miguel Di Ciurcio Filho miguel.fi...@gmail.com wrote:

 Signed-off-by: Miguel Di Ciurcio Filho miguel.fi...@gmail.com
 ---
  monitor.c |8 +++
  net.c |   70 
 +
  net.h |2 +
  3 files changed, 80 insertions(+), 0 deletions(-)
 
 diff --git a/monitor.c b/monitor.c
 index 170b269..b44768c 100644
 --- a/monitor.c
 +++ b/monitor.c
 @@ -2314,6 +2314,14 @@ static const mon_cmd_t info_cmds[] = {
  .mhandler.info = do_info_network,
  },
  {
 +.name   = netdev,
 +.args_type  = ,
 +.params = ,
 +.help   = show information about network backend devices,
 +.user_print = do_info_netdev_print,
 +.mhandler.info_new = do_info_netdev,
 +},
 +{
  .name   = chardev,
  .args_type  = ,
  .params = ,
 diff --git a/net.c b/net.c
 index 7daf253..5e0eb0c 100644
 --- a/net.c
 +++ b/net.c
 @@ -36,6 +36,8 @@
  #include qemu-common.h
  #include qemu_socket.h
  #include hw/qdev.h
 +#include qdict.h
 +#include qjson.h
  
  static QTAILQ_HEAD(, VLANState) vlans;
  static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
 @@ -1249,6 +1251,74 @@ void do_info_network(Monitor *mon)
  }
  }
  
 +static void netdev_iter(QObject *obj, void *opaque)
 +{
 +
 +Monitor *mon = opaque;
 +QDict *net_device = qobject_to_qdict(obj);
 +
 +monitor_printf(mon, %s: , qdict_get_str(net_device, id));
 +
 +monitor_printf(mon, type=%s,, qdict_get_str(net_device, type));
 +
 +if (qdict_haskey(net_device, peer)) {
 +monitor_printf(mon, peer=%s,, qdict_get_str(net_device, peer));
 +}
 +
 +monitor_printf(mon,
 +qstring_get_str(qdict_to_qstring(qdict_get_qdict(net_device,
 +info), ,)));

The string returned by qdict_to_qstring() is leaking.

 +
 +monitor_printf(mon, \n);
 +
 +}
 +
 +void do_info_netdev_print(Monitor *mon, const QObject *ret_data)
 +{
 +
 +QList *net_devices;
 +
 +net_devices = qobject_to_qlist(ret_data);
 +
 +qlist_iter(net_devices, netdev_iter, mon);
 +
 +}
 +
 +void do_info_netdev(Monitor *mon, QObject **ret_data)
 +{
 +VLANClientState *vc;
 +QDict *net_device;
 +QList *device_list;
 +device_list = qlist_new();
 +QObject *obj;
 +
 +QTAILQ_FOREACH(vc, non_vlan_clients, next) {
 +
 +if (vc-info-type == NET_CLIENT_TYPE_NONE ||
 +vc-info-type == NET_CLIENT_TYPE_NIC ||
 +vc-info-type == NET_CLIENT_TYPE_SOCKET ||
 +vc-info-type == NET_CLIENT_TYPE_DUMP) {
 +continue;
 +}
 +
 +obj = qobject_from_jsonf({'id': %s, 'type': %s},
 +vc-name, vc-model);
 +
 +net_device = qobject_to_qdict(obj);
 +
 +QINCREF(vc-info_dict);
 +qdict_put(net_device, info, vc-info_dict);
 +
 +if (vc-peer) {
 +qdict_put(net_device, peer, qstring_from_str(vc-peer-name));
 +}
 +
 +qlist_append(device_list, net_device);
 +}
 +
 +*ret_data = QOBJECT(device_list);
 +}
 +
  int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data)
  {
  VLANState *vlan;
 diff --git a/net.h b/net.h
 index cfe837f..69a3c9f 100644
 --- a/net.h
 +++ b/net.h
 @@ -118,6 +118,8 @@ int qemu_find_nic_model(NICInfo *nd, const char * const 
 *models,
  const char *default_model);
  
  void do_info_network(Monitor *mon);
 +void do_info_netdev_print(Monitor *mon, const QObject *ret_data);
 +void do_info_netdev(Monitor *mon, QObject **ret_data);
  int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data);
  
  /* NIC info */




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

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: Sripathi Kodi sripat...@in.ibm.com

Signed-off-by: Sripathi Kodi sripat...@in.ibm.com

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

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

Signed-off-by: Sripathi Kodi sripat...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p.c |   11 ++-
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 20560e5..0540a74 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1877,14 +1877,15 @@ static void v9fs_flush(V9fsState *s, V9fsPDU *pdu)
 static void v9fs_remove_post_remove(V9fsState *s, V9fsRemoveState *vs,
 int err)
 {
-/* For TREMOVE we need to clunk the fid even on failed remove */
-err = free_fid(s, vs-fidp-fid);
 if (err  0) {
-goto out;
+err = -errno;
+} else {
+err = vs-offset;
 }
 
-err = vs-offset;
-out:
+/* For TREMOVE we need to clunk the fid even on failed remove */
+free_fid(s, vs-fidp-fid);
+
 complete_pdu(s, vs-pdu, err);
 qemu_free(vs);
 }
-- 
1.6.5.2




[Qemu-devel] Re: [PATCH 0/7] QMP: Introduce query-netdev

2010-06-28 Thread Luiz Capitulino
On Wed, 23 Jun 2010 12:39:56 -0300
Miguel Di Ciurcio Filho miguel.fi...@gmail.com wrote:

 This series implement the previously discussed QMP command query-netdev.
 
 There is small change in the specification from the last version: when type 
 is
 tap, the attribute sndbuf have been removed. sndbuf is not available on
 all platforms and most of the tap_set_sndbuf() implementations are stubs.

Apart from the two bugs I found, looks good to me.

My only remaining question is: isn't socket a backend?



[Qemu-devel] [PATCH 15/20] rename - change name of file or directory

2010-06-28 Thread Venkateswararao Jujjuri (JV)
From: M. Mohan Kumar mo...@in.ibm.com

size[4] Trename tag[2] fid[4] newdirfid[4] name[s]
size[4] Rrename tag[2]

Implement the 2000.L rename operation. A new function
v9fs_complete_rename is introduced that acts as a common entry point
for 2000.L rename operation and 2000.U rename opearation (via wstat).
As part of this change the field 'nname' (used only for rename) is
removed from the structure V9fsWstatState. Instead a new structure
V9fsRenameState is used for rename operations both by 2000.U and 2000.L
code paths. Both 2000.U and 2000.L rename code paths construct the
V9fsRenameState structure and passes that to v9fs_complete_rename
function.

Changes from previous version:
 Use qemu_mallocz to initialize
 Use strcpy,strcat functions instead of memcpy
 Changed the variable name to newdirfid
 Introduced post rename function
 Error checking
 Removed nname field from V9fsWstatState

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p.c |  157 
 hw/virtio-9p.h |   11 -
 2 files changed, 123 insertions(+), 45 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 4f28d86..156d5dd 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -2533,11 +2533,6 @@ static void v9fs_wstat_post_rename(V9fsState *s, 
V9fsWstatState *vs, int err)
 if (err  0) {
 goto out;
 }
-
-if (vs-v9stat.name.size != 0) {
-v9fs_string_free(vs-nname);
-}
-
 if (vs-v9stat.length != -1) {
 if (v9fs_do_truncate(s, vs-fidp-path, vs-v9stat.length)  0) {
 err = -errno;
@@ -2552,17 +2547,30 @@ out:
 qemu_free(vs);
 }
 
-static void v9fs_wstat_post_chown(V9fsState *s, V9fsWstatState *vs, int err)
+static int v9fs_complete_rename(V9fsState *s, V9fsRenameState *vs)
 {
-V9fsFidState *fidp;
-if (err  0) {
-goto out;
-}
+int err = 0;
+char *old_name, *new_name;
+char *end;
 
-if (vs-v9stat.name.size != 0) {
-char *old_name, *new_name;
-char *end;
+if (vs-newdirfid != -1) {
+V9fsFidState *dirfidp;
+dirfidp = lookup_fid(s, vs-newdirfid);
+
+if (dirfidp == NULL) {
+err = -ENOENT;
+goto out;
+}
+
+BUG_ON(dirfidp-fd != -1);
+BUG_ON(dirfidp-dir);
 
+new_name = qemu_mallocz(dirfidp-path.size + vs-name.size + 2);
+
+strcpy(new_name, dirfidp-path.data);
+strcat(new_name, /);
+strcat(new_name + dirfidp-path.size, vs-name.data);
+} else {
 old_name = vs-fidp-path.data;
 end = strrchr(old_name, '/');
 if (end) {
@@ -2570,44 +2578,75 @@ static void v9fs_wstat_post_chown(V9fsState *s, 
V9fsWstatState *vs, int err)
 } else {
 end = old_name;
 }
+new_name = qemu_mallocz(end - old_name + vs-name.size + 1);
 
-new_name = qemu_malloc(end - old_name + vs-v9stat.name.size + 1);
+strncat(new_name, old_name, end - old_name);
+strncat(new_name + (end - old_name), vs-name.data, vs-name.size);
+}
 
-memset(new_name, 0, end - old_name + vs-v9stat.name.size + 1);
-memcpy(new_name, old_name, end - old_name);
-memcpy(new_name + (end - old_name), vs-v9stat.name.data,
-vs-v9stat.name.size);
-vs-nname.data = new_name;
-vs-nname.size = strlen(new_name);
+v9fs_string_free(vs-name);
+vs-name.data = qemu_strdup(new_name);
+vs-name.size = strlen(new_name);
 
-if (strcmp(new_name, vs-fidp-path.data) != 0) {
-if (v9fs_do_rename(s, vs-fidp-path, vs-nname)) {
-err = -errno;
-} else {
-/*
- * Fixup fid's pointing to the old name to
- * start pointing to the new name
- */
-for (fidp = s-fid_list; fidp; fidp = fidp-next) {
-
-if (vs-fidp == fidp) {
-/*
- * we replace name of this fid towards the end
- * so that our below strcmp will work
- */
-continue;
-}
-if (!strncmp(vs-fidp-path.data, fidp-path.data,
- strlen(vs-fidp-path.data))) {
-/* replace the name */
-v9fs_fix_path(fidp-path, vs-nname,
-  strlen(vs-fidp-path.data));
-}
+if (strcmp(new_name, vs-fidp-path.data) != 0) {
+if (v9fs_do_rename(s, vs-fidp-path, vs-name)) {
+err = -errno;
+} else {
+V9fsFidState *fidp;
+/*
+* Fixup fid's pointing to the old name to
+* start pointing to the new name
+*/
+for (fidp = s-fid_list; fidp; fidp = fidp-next) {
+if (vs-fidp == fidp) 

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

2010-06-28 Thread chen huacai
Changes from V5:
Clean up old style save/restore code



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

2010-06-28 Thread Huacai Chen
Signed-off-by: Huacai Chen zltjiang...@gmail.com
---
 Makefile.target |2 +-
 hw/pci_ids.h|8 +
 hw/vt82c686.c   |  597 +++
 hw/vt82c686.h   |   11 +
 4 files changed, 617 insertions(+), 1 deletions(-)
 create mode 100644 hw/vt82c686.c
 create mode 100644 hw/vt82c686.h

diff --git a/Makefile.target b/Makefile.target
index eb852d4..caabacd 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..a0c5747
--- /dev/null
+++ b/hw/vt82c686.c
@@ -0,0 +1,597 @@
+/*
+ * 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
+#include sysemu.h
+#include qemu-timer.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 = 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 = 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] = 

[Qemu-devel] [PATCH v6 4/6] MIPS: Initial support of VIA USB controller used by fulong mini pc

2010-06-28 Thread Huacai Chen
Signed-off-by: Huacai Chen zltjiang...@gmail.com
---
 hw/usb-uhci.c |   28 
 hw/usb-uhci.h |1 +
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 624d55b..3eb9832 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1152,6 +1152,24 @@ 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);
+
+/* USB misc control 1/2 */
+pci_set_long(pci_conf + 0x40,0x1000);
+/* PM capability */
+pci_set_long(pci_conf + 0x80,0x00020001);
+/* USB legacy support  */
+pci_set_long(pci_conf + 0xc0,0x2000);
+
+return usb_uhci_common_initfn(s);
+}
+
 static PCIDeviceInfo uhci_info[] = {
 {
 .qdev.name= piix3-usb-uhci,
@@ -1164,6 +1182,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 +1206,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 v6 5/6] MIPS: Initial support of fulong mini pc (CPU definition)

2010-06-28 Thread Huacai Chen
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 a7f4697..bf094a3 100644
--- a/target-mips/mips-defs.h
+++ b/target-mips/mips-defs.h
@@ -41,6 +41,8 @@
 #defineASE_MICROMIPS   0x0008
 
 /* Chip specific instructions. */
+#defineINSN_LOONGSON2E  0x2000
+#defineINSN_LOONGSON2F  0x4000
 #defineINSN_VR54XX 0x8000
 
 /* MIPS CPU defines. */
@@ -49,6 +51,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 v6 1/6] MIPS: Initial support of bonito north bridge used by fulong mini pc

2010-06-28 Thread Huacai Chen
Signed-off-by: Huacai Chen zltjiang...@gmail.com
---
 Makefile.target  |1 +
 default-configs/mips64el-softmmu.mak |1 +
 hw/bonito.c  |  809 ++
 hw/mips.h|3 +
 4 files changed, 814 insertions(+), 0 deletions(-)
 create mode 100644 hw/bonito.c

diff --git a/Makefile.target b/Makefile.target
index f64702b..eb852d4 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..8b81032
--- /dev/null
+++ b/hw/bonito.c
@@ -0,0 +1,809 @@
+/*
+ * 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
+#include sysemu.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 

[Qemu-devel] [PATCH v6 6/6] MIPS: Initial support of fulong mini pc (machine construction)

2010-06-28 Thread Huacai Chen
Signed-off-by: Huacai Chen zltjiang...@gmail.com
---
 Makefile.target|2 +-
 hw/mips_fulong2e.c |  416 
 2 files changed, 417 insertions(+), 1 deletions(-)
 create mode 100644 hw/mips_fulong2e.c

diff --git a/Makefile.target b/Makefile.target
index caabacd..2423c76 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..d03c897
--- /dev/null
+++ b/hw/mips_fulong2e.c
@@ -0,0 +1,416 @@
+/*
+ * 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
+
+/*
+ * PMON is not part of qemu and released with BSD license, anyone
+ * who want to build a pmon binary please first git-clone the source
+ * from the git repository at:
+ * http://www.loongson.cn/support/git/pmon
+ * Then follow the Compile Guide available at:
+ * http://dev.lemote.com/code/pmon
+ *
+ * Notes:
+ * 1, don't use the source at http://dev.lemote.com/http_git/pmon.git
+ * 2, use Bonito2edev to replace dir_corresponding_to_your_target_hardware
+ * in the Compile Guide.
+ */
+#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-devel] [PATCH v6 3/6] MIPS: Initial support of VIA IDE controller used by fulong mini pc

2010-06-28 Thread Huacai Chen
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 |  191 ++
 4 files changed, 194 insertions(+), 0 deletions(-)
 create mode 100644 hw/ide/via.c

diff --git a/Makefile.objs b/Makefile.objs
index 53fb68e..67a0c23 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -202,6 +202,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..d933caf
--- /dev/null
+++ b/hw/ide/via.c
@@ -0,0 +1,191 @@
+/*
+ * 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] [Bug 599617] [NEW] qemu fail to parse command -net none

2010-06-28 Thread xudong
Public bug reported:

Host OS:ia32e
Guest OS :32e and pae
kvm.git Commit:a63e16c655f9e68d49d6fae4275ffda16b1888b2
qemu-kvm Commit:97011c7fce92f8c0928c9e94e9896f0dca1bdeb9
Host Kernel Version:2.6.35-rc3


Bug detailed description:
--
when use command qemu-system_x86 -smp 2 -m 1024 -hda /path/to/img -net none
to boot up a guest, guest cannot boot up. and no error message displayed.

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
qemu fail to parse command -net none
https://bugs.launchpad.net/bugs/599617
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:
Host OS:ia32e
Guest OS :32e and pae
kvm.git Commit:a63e16c655f9e68d49d6fae4275ffda16b1888b2
qemu-kvm Commit:97011c7fce92f8c0928c9e94e9896f0dca1bdeb9
Host Kernel Version:2.6.35-rc3


Bug detailed description:
--
when use command qemu-system_x86 -smp 2 -m 1024 -hda /path/to/img -net none
to boot up a guest, guest cannot boot up. and no error message displayed.





[Qemu-devel] [Bug 599617] Re: qemu fail to parse command -net none

2010-06-28 Thread xudong
qemu upstream has fix patch:

Signed-off-by: Amit Shah amit.s...@redhat.com
---
 net.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net.c b/net.c
index 4cb93ed..b681233 100644
--- a/net.c
+++ b/net.c
@@ -1119,7 +1119,7 @@ int net_client_init(Monitor *mon, QemuOpts *opts, int 
is_netdev)
 vlan = qemu_find_vlan(qemu_opt_get_number(opts, vlan, 0), 1);
 }
 
-ret = -1;
+ret = 0;
 if (net_client_types[i].init) {
 ret = net_client_types[i].init(opts, mon, name, vlan);
 if (ret  0) {

-- 
qemu fail to parse command -net none
https://bugs.launchpad.net/bugs/599617
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:
Host OS:ia32e
Guest OS :32e and pae
kvm.git Commit:a63e16c655f9e68d49d6fae4275ffda16b1888b2
qemu-kvm Commit:97011c7fce92f8c0928c9e94e9896f0dca1bdeb9
Host Kernel Version:2.6.35-rc3


Bug detailed description:
--
when use command qemu-system_x86 -smp 2 -m 1024 -hda /path/to/img -net none
to boot up a guest, guest cannot boot up. and no error message displayed.





[Qemu-devel] KVM call agenda for June 29

2010-06-28 Thread Chris Wright
Please send in any agenda items you are interested in covering.

If we have a lack of agenda items I'll cancel the week's call.

thanks,
-chris



[Qemu-devel] Re: [PATCH] device-assignment: Rework name of assigned pci device

2010-06-28 Thread Markus Armbruster
Hidetoshi Seto seto.hideto...@jp.fujitsu.com writes:

 Hao, Xudong xudong@intel.com writes:
  When assign one PCI device, qemu fail to parse the command line:
  qemu-system_x86 -smp 2 -m 1024 -hda /path/to/img -pcidevice host=00:19.0
  Error:
  qemu-system-x86_64: Parameter 'id' expects an identifier
  Identifiers consist of letters, digits, '-', '.', '_', starting with a 
  letter.
  pcidevice argument parse error; please check the help text for usage
  Could not add assigned device host=00:19.0
 
  https://bugs.launchpad.net/qemu/+bug/597932
 
  This issue caused by qemu-kvm commit 
  b560a9ab9be06afcbb78b3791ab836dad208a239.

 This patch is a response to the above report.

 Thanks,
 H.Seto

 =

 Because use of some characters in id is restricted recently, assigned
 device start to fail having implicit id that uses address string of
 host device, like 00:19.0 which includes restricted character ':'.

 It seems that this implicit id is intended to be run as name that
 could be passed with option -pcidevice ... ,name=... to specify a
 string to be used in log outputs.  In other words it seems that
 dev-dev.qdev.id of assigned device had been used to have such
 name, that is user-defined string or address string of host.

As far as I can tell, option name is just a leftover from pre-qdev
days, kept for compatibility.

 The problem is that name for specific use is not equal to id for
 universal use.  So it is better to remove this tricky mix up here.

 This patch introduces new function assigned_dev_name() that returns
 proper name string for the device.
 Now property name is explicitly defined in struct AssignedDevice.

 When if the device have neither name nor id, address string like
 :00:19.0 will be created and passed instead.  Once created, new
 field r_name holds the string to be reused and to be released later.

 Signed-off-by: Hidetoshi Seto seto.hideto...@jp.fujitsu.com

Comments inline.

 ---
  hw/device-assignment.c |   59 ++-
  hw/device-assignment.h |2 +
  2 files changed, 44 insertions(+), 17 deletions(-)

 diff --git a/hw/device-assignment.c b/hw/device-assignment.c
 index 585162b..d73516f 100644
 --- a/hw/device-assignment.c
 +++ b/hw/device-assignment.c
 @@ -62,6 +62,25 @@ static void assigned_dev_load_option_rom(AssignedDevice 
 *dev);
  
  static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev);
  
 +static const char *assigned_dev_name(AssignedDevice *dev)
 +{
 +/* use user-defined name if specified */
 +if (dev-u_name)
 +return dev-u_name;
 +/* else use id if available */
 +if (dev-dev.qdev.id)
 +return dev-dev.qdev.id;
 +/* otherwise use address of host device instead */
 +if (!dev-r_name) {
 +char buf[32];
 +
 +snprintf(buf, sizeof(buf), %04x:%02x:%02x.%01x,
 + dev-host.seg, dev-host.bus, dev-host.dev, 
 dev-host.func);
 +dev-r_name = qemu_strdup(buf);
 +}
 +return dev-r_name;
 +}
 +
  static uint32_t guest_to_host_ioport(AssignedDevRegion *region, uint32_t 
 addr)
  {
  return region-u.r_baseport + (addr - region-e_physbase);
 @@ -798,6 +817,10 @@ static void free_assigned_device(AssignedDevice *dev)
  dev-real_device.config_fd = 0;
  }
  
 +if (dev-r_name) {
 +qemu_free(dev-r_name);
 +}
 +
  #ifdef KVM_CAP_IRQ_ROUTING
  free_dev_irq_entries(dev);
  #endif
 @@ -885,7 +908,7 @@ static int assign_device(AssignedDevice *dev)
  if (dev-use_iommu) {
  if (!kvm_check_extension(kvm_state, KVM_CAP_IOMMU)) {
  fprintf(stderr, No IOMMU found.  Unable to assign device 
 \%s\\n,
 -dev-dev.qdev.id);
 +assigned_dev_name(dev));
  return -ENODEV;
  }
  assigned_dev_data.flags |= KVM_DEV_ASSIGN_ENABLE_IOMMU;
 @@ -897,7 +920,7 @@ static int assign_device(AssignedDevice *dev)
  r = kvm_assign_pci_device(kvm_context, assigned_dev_data);
  if (r  0) {
  fprintf(stderr, Failed to assign device \%s\ : %s\n,
 -dev-dev.qdev.id, strerror(-r));
 +assigned_dev_name(dev), strerror(-r));
  
  switch (r) {
  case -EBUSY:
 @@ -953,7 +976,7 @@ static int assign_irq(AssignedDevice *dev)
  r = kvm_assign_irq(kvm_context, assigned_irq_data);
  if (r  0) {
  fprintf(stderr, Failed to assign irq for \%s\: %s\n,
 -dev-dev.qdev.id, strerror(-r));
 +assigned_dev_name(dev), strerror(-r));
  fprintf(stderr, Perhaps you are assigning a device 
  that shares an IRQ with another device?\n);
  return r;
 @@ -977,7 +1000,7 @@ static void deassign_device(AssignedDevice *dev)
  r = kvm_deassign_pci_device(kvm_context, assigned_dev_data);
  if (r  0)
   fprintf(stderr, Failed to deassign device \%s\ : %s\n,
 -dev-dev.qdev.id, strerror(-r));
 +