Re: [libvirt] Can't connect ESXi ssl with virsh

2012-03-05 Thread Hu Tao
On Mon, Mar 05, 2012 at 02:50:51AM -0500, Zhimou Peng wrote:
 And my CA is also my client in this case.

I just noticed it.

  4, change the ESXi to maintance mode and change ssl keys on 
  /etc/vmware/ssl. restart hostd server
 then quit the maintance mode.

Steps of changing the default certificate I read from
http://pubs.vmware.com/vsphere-4-esxi-installable-vcenter/index.jsp?topic=/com.vmware.vsphere.esxi_server_config.doc_41/esx_server_config/authentication_and_user_management/t_replace_the_existing_certificate_with_a_ca-signed_certificate.html
are not the same as yours. Though I don't know the difference, I think
you can have a try.

-- 
Thanks,
Hu Tao

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [Patch]: spice agent-mouse support [v3]

2012-03-05 Thread Zhou Peng
Signed-off-by: Zhou Peng zhoup...@nfs.iscas.ac.cn

spice agent-mouse support

Usage:
graphics type='spice'
  mouse mode='client'|'server'/
graphics/

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 6fcca94..0adf859 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2809,6 +2809,14 @@ qemu-kvm -net nic,model=? /dev/null
   to codeno/code, span class=sincesince
   0.9.3/span.
 /p
+p
+  It can be specified whether client or server mouse mode
+  to use for spice. The default is client which enables
+  passing mouse events via Spice agent.
+  The mouse mode is set by the codemousecode/ element,
+  setting it's codemodecode/ attribute to one of
+  codeserver/code or codeclient/code.
+/p
   /dd
   dtcoderdp/code/dt
   dd
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 3908733..bb0df03 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1776,6 +1776,17 @@
 empty/
   /element
 /optional
+optional
+  element name=mouse
+attribute name=mode
+  choice
+valueserver/value
+valueclient/value
+  /choice
+/attribute
+empty/
+  /element
+/optional
   /interleave
 /group
 group
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f9654f1..b99e770 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -460,6 +460,12 @@ VIR_ENUM_IMPL(virDomainGraphicsSpicePlaybackCompression,
   on,
   off);

+VIR_ENUM_IMPL(virDomainGraphicsSpiceMouseMode,
+  VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_LAST,
+  default,
+  server,
+  client);
+
 VIR_ENUM_IMPL(virDomainGraphicsSpiceStreamingMode,
   VIR_DOMAIN_GRAPHICS_SPICE_STREAMING_MODE_LAST,
   default,
@@ -5710,6 +5716,26 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
 VIR_FREE(copypaste);

 def-data.spice.copypaste = copypasteVal;
+} else if (xmlStrEqual(cur-name, BAD_CAST mouse)) {
+const char *mode = virXMLPropString(cur, mode);
+int modeVal;
+
+if (!mode) {
+virDomainReportError(VIR_ERR_XML_ERROR, %s,
+ _(spice mouse missing mode));
+goto error;
+}
+
+if ((modeVal =
+
virDomainGraphicsSpiceMouseModeTypeFromString(mode)) = 0) {
+virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+ _(unknown mouse mode value
'%s'), mode);
+VIR_FREE(mode);
+goto error;
+}
+VIR_FREE(mode);
+
+def-data.spice.mousemode = modeVal;
 }
 }
 cur = cur-next;
@@ -11401,7 +11427,8 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
 }
 if (!children  (def-data.spice.image || def-data.spice.jpeg ||
   def-data.spice.zlib || def-data.spice.playback ||
-  def-data.spice.streaming ||
def-data.spice.copypaste)) {
+  def-data.spice.streaming ||
def-data.spice.copypaste ||
+  def-data.spice.mousemode)) {
 virBufferAddLit(buf, \n);
 children = 1;
 }
@@ -11420,6 +11447,9 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
 if (def-data.spice.streaming)
 virBufferAsprintf(buf,   streaming mode='%s'/\n,

virDomainGraphicsSpiceStreamingModeTypeToString(def-data.spice.streaming));
+if (def-data.spice.mousemode)
+virBufferAsprintf(buf,   mouse mode='%s'/\n,
+
virDomainGraphicsSpiceMouseModeTypeToString(def-data.spice.mousemode));
 if (def-data.spice.copypaste)
 virBufferAsprintf(buf,   clipboard copypaste='%s'/\n,

virDomainGraphicsSpiceClipboardCopypasteTypeToString(def-data.spice.copypaste));
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 596be4d..a9c118a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1003,6 +1003,14 @@ enum virDomainGraphicsSpicePlaybackCompression {
 VIR_DOMAIN_GRAPHICS_SPICE_PLAYBACK_COMPRESSION_LAST
 };

+enum virDomainGraphicsSpiceMouseMode {
+VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_DEFAULT = 0,
+VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_SERVER,
+VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_CLIENT,
+
+VIR_DOMAIN_GRAPHICS_SPICE_MOUSE_MODE_LAST
+};
+
 enum virDomainGraphicsSpiceStreamingMode {
 

Re: [libvirt] Can't connect ESXi ssl with virsh

2012-03-05 Thread Zhimou Peng
I'll have a try :)
Thanks

- Original Message -
From: Hu Tao hu...@cn.fujitsu.com
To: Zhimou Peng zhp...@redhat.com
Cc: libvir-list@redhat.com, Tingting Zheng tzh...@redhat.com
Sent: Monday, March 5, 2012 4:09:59 PM
Subject: Re: [libvirt] Can't connect ESXi ssl with virsh

On Mon, Mar 05, 2012 at 02:50:51AM -0500, Zhimou Peng wrote:
 And my CA is also my client in this case.

I just noticed it.

  4, change the ESXi to maintance mode and change ssl keys on 
  /etc/vmware/ssl. restart hostd server
 then quit the maintance mode.

Steps of changing the default certificate I read from
http://pubs.vmware.com/vsphere-4-esxi-installable-vcenter/index.jsp?topic=/com.vmware.vsphere.esxi_server_config.doc_41/esx_server_config/authentication_and_user_management/t_replace_the_existing_certificate_with_a_ca-signed_certificate.html
are not the same as yours. Though I don't know the difference, I think
you can have a try.

-- 
Thanks,
Hu Tao

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Can't connect ESXi ssl with virsh

2012-03-05 Thread Zhimou Peng
Ehh...I followed the ESXi5.0 guide.(my ENV is ESXi)

http://pubs.vmware.com/vsphere-50/topic/com.vmware.vsphere.security.doc_50/GUID-A261E6D8-03E4-48ED-ADB6-473C2DAAB7AD.html

http://pubs.vmware.com/vsphere-50/index.jsp?topic=/com.vmware.vsphere.solutions.doc_50/GUID-37AAEDFE-EF2E-45FC-B0C6-44841E4FB302.html

I ignore the steps for vcenter.

- Original Message -
From: Zhimou Peng zhp...@redhat.com
To: Hu Tao hu...@cn.fujitsu.com
Cc: libvir-list@redhat.com, Tingting Zheng tzh...@redhat.com
Sent: Monday, March 5, 2012 4:19:29 PM
Subject: Re: [libvirt] Can't connect ESXi ssl with virsh

I'll have a try :)
Thanks

- Original Message -
From: Hu Tao hu...@cn.fujitsu.com
To: Zhimou Peng zhp...@redhat.com
Cc: libvir-list@redhat.com, Tingting Zheng tzh...@redhat.com
Sent: Monday, March 5, 2012 4:09:59 PM
Subject: Re: [libvirt] Can't connect ESXi ssl with virsh

On Mon, Mar 05, 2012 at 02:50:51AM -0500, Zhimou Peng wrote:
 And my CA is also my client in this case.

I just noticed it.

  4, change the ESXi to maintance mode and change ssl keys on 
  /etc/vmware/ssl. restart hostd server
 then quit the maintance mode.

Steps of changing the default certificate I read from
http://pubs.vmware.com/vsphere-4-esxi-installable-vcenter/index.jsp?topic=/com.vmware.vsphere.esxi_server_config.doc_41/esx_server_config/authentication_and_user_management/t_replace_the_existing_certificate_with_a_ca-signed_certificate.html
are not the same as yours. Though I don't know the difference, I think
you can have a try.

-- 
Thanks,
Hu Tao

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] cpu: Add new flag supported by qemu to the cpu definition

2012-03-05 Thread Peter Krempa

On 03/03/2012 03:06 AM, Eric Blake wrote:

On 02/29/2012 07:53 AM, Peter Krempa wrote:

Some new cpu features were added to qemu. This patch adds some of them
to our CPU map.
---


Thanks; that helped review.  ACK.


Pushed; Thanks

Peter

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 2/9] docs: Add documentation for new attribute tray of disk target

2012-03-05 Thread Osier Yang
Example XML:

disk type='file' device='cdrom'
  driver name='qemu' type='raw'/
  source file='/tmp/cdrom.img'/
  target dev='hdd' bus='ide' tray='open'/
/disk
---
 docs/formatdomain.html.in |   13 +
 docs/schemas/domaincommon.rng |8 
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a61895f..158bafa 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1091,7 +1091,7 @@
 lt;/diskgt;
 lt;disk type='block' device='cdrom'gt;
   lt;driver name='qemu' type='raw'/gt;
-  lt;target dev='hdc' bus='ide'/gt;
+  lt;target dev='hdc' bus='ide' tray='open'/gt;
   lt;readonly/gt;
 lt;/diskgt;
 lt;disk type='block' device='lun'gt;
@@ -1202,10 +1202,15 @@
 possible values are driver specific, with typical values being
 ide, scsi, virtio, xen, usb or sata. If omitted, the bus
 type is inferred from the style of the device name. eg, a device named
-'sda' will typically be exported using a SCSI bus.
+'sda' will typically be exported using a SCSI bus. The optional
+attribute codetray/code indicates the tray status of the
+removable disks (i.e. CDROM or Floppy disk), the value can be either
+open or closed, defaults to closed. NB, the value of
+codetray/code could be updated while the domain is running.
 span class=sinceSince 0.0.3; codebus/code attribute since 
0.4.3;
-usb attribute value since after 0.4.4; sata attribute value since
-0.9.7/span/dd
+codetray/code attribute since 0.9.11; usb attribute value since
+after 0.4.4; sata attribute value since 0.9.7/span
+  /dd
   dtcodeiotune/code/dt
   ddThe optional codeiotune/code element provides the
 ability to provide additional per-device I/O tuning, with
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 3908733..e1e1027 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -959,6 +959,14 @@
   /choice
 /attribute
   /optional
+  optional
+attribute name=tray
+  choice
+valueopen/value
+valueclosed/value
+  /choice
+/attribute
+  /optional
 /element
   /define
   !--
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/9] Add support for event tray moved of removable disks

2012-03-05 Thread Osier Yang
This patch introduces a new event type for the QMP event
DEVICE_TRAY_MOVED, which occurs when the tray of a removable
disk is moved (i.e opened or closed):

VIR_DOMAIN_EVENT_ID_TRAY_MOVED

The event's data includes the device alias and the tray's
status, which indicates whether the tray has been opened
or closed.  Thus the callback definition for the event is:

typedef void
(*virConnectDomainEventTrayMovedCallback)(virConnectPtr conn,
  virDomainPtr dom,
  const char *devAlias,
  unsigned int trayOpened,
  void *opaque);
---
 daemon/remote.c|   33 +++
 examples/domain-events/events-c/event-test.c   |   21 +++-
 examples/domain-events/events-python/event-test.py |4 ++
 include/libvirt/libvirt.h.in   |   20 +++
 python/libvirt-override-virConnect.py  |   10 
 python/libvirt-override.c  |   50 +
 src/conf/domain_event.c|   58 
 src/conf/domain_event.h|6 ++
 src/libvirt_private.syms   |2 +
 src/qemu/qemu_monitor.c|   13 +
 src/qemu/qemu_monitor.h|7 +++
 src/qemu/qemu_monitor_json.c   |   18 ++
 src/qemu/qemu_process.c|   32 +++
 src/remote/remote_driver.c |   34 
 src/remote/remote_protocol.x   |9 +++-
 src/remote_protocol-structs|5 ++
 16 files changed, 320 insertions(+), 2 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 74a5f16..cc464fd 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -505,6 +505,38 @@ mem_error:
 }
 
 
+static int remoteRelayDomainEventTrayMoved(virConnectPtr conn ATTRIBUTE_UNUSED,
+   virDomainPtr dom,
+   const char *devAlias,
+   unsigned int trayOpened,
+   void *opaque) {
+virNetServerClientPtr client = opaque;
+remote_domain_event_tray_moved_msg data;
+
+if (!client)
+return -1;
+
+VIR_DEBUG(Relaying domain %s %d tray moved devAlias: %s trayOpened: %s,
+  dom-name, dom-id, devAlias, trayOpened ? yes: no);
+
+/* build return data */
+memset(data, 0, sizeof data);
+
+if (!(data.devAlias = strdup(devAlias))) {
+virReportOOMError();
+return -1;
+}
+data.trayOpened = trayOpened;
+
+make_nonnull_domain(data.dom, dom);
+
+remoteDispatchDomainEventSend(client, remoteProgram,
+  REMOTE_PROC_DOMAIN_EVENT_TRAY_MOVED,
+  
(xdrproc_t)xdr_remote_domain_event_tray_moved_msg, data);
+
+return 0;
+}
+
 static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot),
@@ -516,6 +548,7 @@ static virConnectDomainEventGenericCallback 
domainEventCallbacks[] = {
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventControlError),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockJob),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDiskChange),
+VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventTrayMoved),
 };
 
 verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
diff --git a/examples/domain-events/events-c/event-test.c 
b/examples/domain-events/events-c/event-test.c
index f4938c4..c7bcaeb 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -313,6 +313,17 @@ static int myDomainEventDiskChangeCallback(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 return 0;
 }
 
+static int myDomainEventTrayMovedCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+  virDomainPtr dom,
+  const char *devAlias,
+  unsigned int trayOpened,
+  void *opaque ATTRIBUTE_UNUSED)
+{
+printf(%s EVENT: Domain %s(%d) removable disk's tray moved devAlias: %s 
trayOpened: %s\n,
+   __func__, virDomainGetName(dom), virDomainGetID(dom),
+   devAlias, trayOpened ? yes : no);
+return 0;
+}
 
 static void myFreeFunc(void *opaque)
 {
@@ -349,6 +360,7 @@ int main(int argc, char **argv)
 int callback7ret = -1;
 int callback8ret = -1;
 int callback9ret = -1;
+int callback10ret = -1;
 struct sigaction action_stop;
 
 memset(action_stop, 0, sizeof action_stop);
@@ -419,6 +431,11 @@ int main(int 

[libvirt] [PATCH 3/9] conf: Parse and for the tray attribute

2012-03-05 Thread Osier Yang
The tray is only allowed for removable disks, i.e. CDROM and
Floppy disks.

As the value for tray defaults to closed, lots of tests are
updated to include tray='closed' in the disk target XML.
---
 src/conf/domain_conf.c |   33 +++-
 src/conf/domain_conf.h |9 +
 tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.xml |2 +-
 .../qemuxml2argv-boot-complex-bootindex.xml|6 ++--
 .../qemuxml2argvdata/qemuxml2argv-boot-complex.xml |6 ++--
 .../qemuxml2argvdata/qemuxml2argv-boot-floppy.xml  |2 +-
 ...uxml2argv-boot-menu-disable-drive-bootindex.xml |2 +-
 .../qemuxml2argv-boot-menu-disable-drive.xml   |2 +-
 .../qemuxml2argv-boot-menu-disable.xml |2 +-
 .../qemuxml2argv-boot-menu-enable.xml  |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-boot-multi.xml |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-boot-order.xml |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-bootloader.xml |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-disk-aio.xml   |2 +-
 .../qemuxml2argv-disk-cdrom-empty.xml  |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.xml |2 +-
 .../qemuxml2argv-disk-copy_on_read.xml |2 +-
 .../qemuxml2argv-disk-drive-boot-cdrom.xml |2 +-
 .../qemuxml2argv-disk-drive-boot-disk.xml  |2 +-
 .../qemuxml2argv-disk-drive-cache-directsync.xml   |2 +-
 .../qemuxml2argv-disk-drive-cache-unsafe.xml   |2 +-
 .../qemuxml2argv-disk-drive-cache-v1-none.xml  |2 +-
 .../qemuxml2argv-disk-drive-cache-v1-wb.xml|2 +-
 .../qemuxml2argv-disk-drive-cache-v1-wt.xml|2 +-
 .../qemuxml2argv-disk-drive-cache-v2-none.xml  |2 +-
 .../qemuxml2argv-disk-drive-cache-v2-wb.xml|2 +-
 .../qemuxml2argv-disk-drive-cache-v2-wt.xml|2 +-
 ...muxml2argv-disk-drive-error-policy-enospace.xml |2 +-
 .../qemuxml2argv-disk-drive-error-policy-stop.xml  |2 +-
 ...rgv-disk-drive-error-policy-wreport-rignore.xml |2 +-
 .../qemuxml2argv-disk-drive-fmt-qcow.xml   |2 +-
 .../qemuxml2argv-disk-drive-no-boot.xml|4 +-
 .../qemuxml2argv-disk-drive-readonly-disk.xml  |2 +-
 .../qemuxml2argv-disk-drive-readonly-no-device.xml |2 +-
 .../qemuxml2argv-disk-drive-shared.xml |2 +-
 .../qemuxml2argvdata/qemuxml2argv-disk-floppy.xml  |4 +-
 .../qemuxml2argv-disk-ioeventfd.xml|2 +-
 tests/qemuxml2argvdata/qemuxml2argv-disk-order.xml |2 +-
 .../qemuxml2argv-disk-snapshot.xml |2 +-
 .../qemuxml2argvdata/qemuxml2argv-disk-virtio.xml  |2 +-
 .../qemuxml2argvdata/qemuxml2argv-disk-xenvbd.xml  |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-event_idx.xml  |2 +-
 .../qemuxml2argv-floppy-drive-fat.xml  |2 +-
 .../qemuxml2argv-graphics-spice-timeout.xml|2 +-
 tests/qemuxml2argvdata/qemuxml2argv-lease.xml  |2 +-
 .../qemuxml2argv-net-bandwidth.xml |2 +-
 .../qemuxml2xmlout-graphics-spice-timeout.xml  |2 +-
 tests/vmx2xmldata/vmx2xml-cdrom-ide-device.xml |2 +-
 tests/vmx2xmldata/vmx2xml-cdrom-ide-file.xml   |2 +-
 tests/vmx2xmldata/vmx2xml-cdrom-scsi-device.xml|2 +-
 tests/vmx2xmldata/vmx2xml-cdrom-scsi-file.xml  |2 +-
 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-2.xml|8 ++--
 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-3.xml|4 +-
 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-5.xml|2 +-
 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-6.xml|2 +-
 tests/vmx2xmldata/vmx2xml-floppy-device.xml|2 +-
 tests/vmx2xmldata/vmx2xml-floppy-file.xml  |2 +-
 tests/vmx2xmldata/vmx2xml-ws-in-the-wild-1.xml |2 +-
 tests/vmx2xmldata/vmx2xml-ws-in-the-wild-2.xml |2 +-
 59 files changed, 109 insertions(+), 69 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f9654f1..f359f8f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -613,6 +613,10 @@ VIR_ENUM_IMPL(virDomainStartupPolicy, 
VIR_DOMAIN_STARTUP_POLICY_LAST,
   requisite,
   optional);
 
+VIR_ENUM_IMPL(virDomainDiskTray, VIR_DOMAIN_DISK_TRAY_LAST,
+  closed,
+  open);
+
 #define virDomainReportError(code, ...)  \
 virReportErrorHelper(VIR_FROM_DOMAIN, code, __FILE__,\
  __FUNCTION__, __LINE__, __VA_ARGS__)
@@ -2894,6 +2898,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
 char *authUsage = NULL;
 char *authUUID = NULL;
 char *usageType = NULL;
+char *tray = NULL;
 
 if (VIR_ALLOC(def)  0) {
 virReportOOMError();
@@ -3002,6 +3007,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
(xmlStrEqual(cur-name, BAD_CAST target))) {
 target = virXMLPropString(cur, dev);
 bus = 

[libvirt] [PATCH 5/9] qemu: Update tray status while tray moved event is emitted

2012-03-05 Thread Osier Yang
With this patch, libvirt won't start the guest with the medium
source which already ejected by guest when doing migration, or
saving/restoring.
---
 src/qemu/qemu_process.c |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 387811a..a75209d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1038,6 +1038,13 @@ qemuProcessHandleTrayMoved(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 event = virDomainEventTrayMovedNewFromObj(vm,
   devAlias,
   trayOpened);
+
+/* Update disk tray status */
+disk-tray_status = trayOpened;
+if (virDomainSaveStatus(driver-caps, driver-stateDir, vm)  0) {
+VIR_WARN(Unable to save status on vm %s after tray moved event,
+ vm-def-name);
+}
 }
 
 virDomainObjUnlock(vm);
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/9] Add supports for three new QMP events

2012-03-05 Thread Osier Yang
This patch series adds support for 3 new QMP events: WAKEUP,
SUSPEND, and DEVICE_TRAY_MOVED, and related changes on domain's
conf and status.

[1/9]
  Add support for tray moved event

[2/9] ~ [5/9]:
  New attribute tray is added to disk target, it indicates
the tray status of removable disk, i.e. CDROM and Floppy disks,
its value could be either of open or closed, defaults to
closed, and a removable disk with tray == open won't have
the source when domain is started.  The value of tray will
be updated while tray moved event is emitted from guest.
  Prior to these patches, if the user ejected the medium of
removable disk from guest side, and then do migration or
save/restoring, the guest will still starts the medium source
,and thus the medium will still exists in guest, which is
strange. These patches fix it.

[6/9] + [8/9]:
  Add support for wakeup event, and update the domain status
to paused if the domain is running, while the wakeup event is
emitted.

[7/9] + [9/9]:
  Add support for suspend event, and update the domain status
to running if the domain was paused by suspend event, while the
suspend event is emitted.

Osier Yang(9)
  Add support for event tray moved of removable disks
  docs: Add documentation for new attribute tray of disk target
  conf: Parse and for the tray attribute
  qemu: Do not start with source for removable disks if tray is open
  qemu: Update tray status while tray moved event is emitted
  Add support for the wakeup event
  Add support for the event suspend
  qemu: Update domain status to paused while suspend event is emitted
  qemu: Update domain status to running while wakeup event is emitted

 daemon/remote.c|   80 +++
 docs/formatdomain.html.in  |   13 ++-
 docs/schemas/domaincommon.rng  |8 +
 examples/domain-events/events-c/event-test.c   |   61 -
 examples/domain-events/events-python/event-test.py |   12 ++
 include/libvirt/libvirt.h.in   |   56 
 python/libvirt-override-virConnect.py  |   27 
 python/libvirt-override.c  |  146 
 src/conf/domain_conf.c |   33 +-
 src/conf/domain_conf.h |9 ++
 src/conf/domain_event.c|  117 
 src/conf/domain_event.h|   10 ++
 src/libvirt_private.syms   |6 +
 src/qemu/qemu_command.c|   16 ++-
 src/qemu/qemu_monitor.c|   37 +
 src/qemu/qemu_monitor.h|   14 ++
 src/qemu/qemu_monitor_json.c   |   37 +-
 src/qemu/qemu_process.c|  131 ++
 src/remote/remote_driver.c |   98 +
 src/remote/remote_protocol.x   |   19 +++-
 src/remote_protocol-structs|   11 ++
 tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.xml |2 +-
 .../qemuxml2argv-boot-complex-bootindex.xml|6 +-
 .../qemuxml2argvdata/qemuxml2argv-boot-complex.xml |6 +-
 .../qemuxml2argvdata/qemuxml2argv-boot-floppy.xml  |2 +-
 ...uxml2argv-boot-menu-disable-drive-bootindex.xml |2 +-
 .../qemuxml2argv-boot-menu-disable-drive.xml   |2 +-
 .../qemuxml2argv-boot-menu-disable.xml |2 +-
 .../qemuxml2argv-boot-menu-enable.xml  |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-boot-multi.xml |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-boot-order.xml |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-bootloader.xml |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-disk-aio.xml   |2 +-
 .../qemuxml2argv-disk-cdrom-empty.xml  |2 +-
 ...qemuxml2argv-disk-cdrom-tray-no-device-cap.args |4 +
 .../qemuxml2argv-disk-cdrom-tray-no-device-cap.xml |   32 +
 .../qemuxml2argv-disk-cdrom-tray.args  |   10 ++
 .../qemuxml2argv-disk-cdrom-tray.xml   |   43 ++
 tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.xml |2 +-
 .../qemuxml2argv-disk-copy_on_read.xml |2 +-
 .../qemuxml2argv-disk-drive-boot-cdrom.xml |2 +-
 .../qemuxml2argv-disk-drive-boot-disk.xml  |2 +-
 .../qemuxml2argv-disk-drive-cache-directsync.xml   |2 +-
 .../qemuxml2argv-disk-drive-cache-unsafe.xml   |2 +-
 .../qemuxml2argv-disk-drive-cache-v1-none.xml  |2 +-
 .../qemuxml2argv-disk-drive-cache-v1-wb.xml|2 +-
 .../qemuxml2argv-disk-drive-cache-v1-wt.xml|2 +-
 .../qemuxml2argv-disk-drive-cache-v2-none.xml  |2 +-
 .../qemuxml2argv-disk-drive-cache-v2-wb.xml|2 +-
 .../qemuxml2argv-disk-drive-cache-v2-wt.xml|2 +-
 ...muxml2argv-disk-drive-error-policy-enospace.xml |2 +-
 .../qemuxml2argv-disk-drive-error-policy-stop.xml  |2 +-
 

[libvirt] [PATCH 8/9] qemu: Update domain status to paused while suspend event is emitted

2012-03-05 Thread Osier Yang
This introduces a new paused reason VIR_DOMAIN_PAUSED_SUSPEND,
and new suspend event type VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND.

While a SUSPEND event occurs, the running domain status will be
transferred to paused with reason VIR_DOMAIN_PAUSED_SUSPEND,
and a new domain lifecycle event emitted with type
VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND.
---
 examples/domain-events/events-c/event-test.c |3 +++
 include/libvirt/libvirt.h.in |2 ++
 src/qemu/qemu_process.c  |   23 +++
 tools/virsh.c|2 ++
 4 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/examples/domain-events/events-c/event-test.c 
b/examples/domain-events/events-c/event-test.c
index 1629358..9231604 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -115,6 +115,9 @@ static const char *eventDetailToString(int event, int 
detail) {
 case VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT:
 ret = Snapshot;
 break;
+case VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND:
+ret = Event suspend;
+break;
 }
 break;
 case VIR_DOMAIN_EVENT_RESUMED:
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index aa02bcb..11b7388 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -145,6 +145,7 @@ typedef enum {
 VIR_DOMAIN_PAUSED_WATCHDOG = 6, /* paused due to a watchdog event */
 VIR_DOMAIN_PAUSED_FROM_SNAPSHOT = 7, /* paused after restoring from 
snapshot */
 VIR_DOMAIN_PAUSED_SHUTTING_DOWN = 8, /* paused during shutdown process */
+VIR_DOMAIN_PAUSED_SUSPEND = 9,   /* paused due to a suspend event */
 
 #ifdef VIR_ENUM_SENTINELS
 VIR_DOMAIN_PAUSED_LAST
@@ -2682,6 +2683,7 @@ typedef enum {
 VIR_DOMAIN_EVENT_SUSPENDED_WATCHDOG = 3,  /* Suspended due to a watchdog 
firing */
 VIR_DOMAIN_EVENT_SUSPENDED_RESTORED = 4,  /* Restored from paused state 
file */
 VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT = 5, /* Restored from paused 
snapshot */
+VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND = 6, /* Suspended due to a suspend 
event */
 
 #ifdef VIR_ENUM_SENTINELS
 VIR_DOMAIN_EVENT_SUSPENDED_LAST
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 2cff63e..19e6e03 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1085,10 +1085,33 @@ qemuProcessHandleSuspend(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 {
 struct qemud_driver *driver = qemu_driver;
 virDomainEventPtr event = NULL;
+virDomainEventPtr lifecycleEvent = NULL;
 
 virDomainObjLock(vm);
 event = virDomainEventSuspendNewFromObj(vm);
 
+if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
+qemuDomainObjPrivatePtr priv = vm-privateData;
+VIR_DEBUG(Transitioned guest %s to paused state due to 
+  QMP suspend event, vm-def-name);
+
+virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
+ VIR_DOMAIN_PAUSED_SUSPEND);
+lifecycleEvent = virDomainEventNewFromObj(vm,
+  VIR_DOMAIN_EVENT_SUSPENDED,
+  
VIR_DOMAIN_EVENT_SUSPENDED_SUSPEND);
+
+VIR_FREE(priv-lockState);
+if (virDomainLockProcessPause(driver-lockManager, vm, 
priv-lockState)  0)
+VIR_WARN(Unable to release lease on %s, vm-def-name);
+VIR_DEBUG(Preserving lock state '%s', NULLSTR(priv-lockState));
+
+if (virDomainSaveStatus(driver-caps, driver-stateDir, vm)  0) {
+VIR_WARN(Unable to save status on vm %s after suspend event,
+ vm-def-name);
+}
+}
+
 virDomainObjUnlock(vm);
 
 if (event) {
diff --git a/tools/virsh.c b/tools/virsh.c
index aef050f..9063131 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -18628,6 +18628,8 @@ vshDomainStateReasonToString(int state, int reason)
 return N_(from snapshot);
 case VIR_DOMAIN_PAUSED_SHUTTING_DOWN:
 return N_(shutting down);
+case VIR_DOMAIN_PAUSED_SUSPEND:
+return N_(Event suspend);
 case VIR_DOMAIN_PAUSED_UNKNOWN:
 case VIR_DOMAIN_PAUSED_LAST:
 ;
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 4/9] qemu: Do not start with source for removable disks if tray is open

2012-03-05 Thread Osier Yang
This is similiar with physical world, one will be surprised if the
box starts with medium exists while the tray is open.

New tests are added, tests disk-{cdrom,floppy}-tray are for the qemu
supports -device flag, and disk-{cdrom,floppy}-no-device-cap are
for old qemu, i.e. which doesn't support -device flag.
---
 src/qemu/qemu_command.c|   16 ++-
 ...qemuxml2argv-disk-cdrom-tray-no-device-cap.args |4 ++
 .../qemuxml2argv-disk-cdrom-tray-no-device-cap.xml |   32 +++
 .../qemuxml2argv-disk-cdrom-tray.args  |   10 +
 .../qemuxml2argv-disk-cdrom-tray.xml   |   43 
 ...emuxml2argv-disk-floppy-tray-no-device-cap.args |4 ++
 ...qemuxml2argv-disk-floppy-tray-no-device-cap.xml |   37 +
 .../qemuxml2argv-disk-floppy-tray.args |   10 +
 .../qemuxml2argv-disk-floppy-tray.xml  |   37 +
 tests/qemuxml2argvtest.c   |6 +++
 10 files changed, 196 insertions(+), 3 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray.xml
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray-no-device-cap.xml
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-floppy-tray.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index cddd6aa..60c3d16 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1885,8 +1885,12 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
 }
 
 /* disk-src is NULL when we use nbd disks */
-if (disk-src || (disk-type == VIR_DOMAIN_DISK_TYPE_NETWORK 
-  disk-protocol == VIR_DOMAIN_DISK_PROTOCOL_NBD)) {
+if ((disk-src ||
+(disk-type == VIR_DOMAIN_DISK_TYPE_NETWORK 
+ disk-protocol == VIR_DOMAIN_DISK_PROTOCOL_NBD)) 
+!((disk-device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
+   disk-device == VIR_DOMAIN_DISK_DEVICE_CDROM) 
+  disk-tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
 if (disk-type == VIR_DOMAIN_DISK_TYPE_DIR) {
 /* QEMU only supports magic FAT format for now */
 if (disk-driverType 
@@ -4694,7 +4698,13 @@ qemuBuildCommandLine(virConnectPtr conn,
 }
 }
 
-virCommandAddArgList(cmd, dev, file, NULL);
+/* Don't start with source if the tray is open for
+ * CDROM and Floppy device.
+ */
+if (!((disk-device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
+   disk-device == VIR_DOMAIN_DISK_DEVICE_CDROM) 
+  disk-tray_status == VIR_DOMAIN_DISK_TRAY_OPEN))
+virCommandAddArgList(cmd, dev, file, NULL);
 VIR_FREE(file);
 }
 }
diff --git 
a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.args 
b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.args
new file mode 100644
index 000..5cd000e
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.args
@@ -0,0 +1,4 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
+pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \
+-no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none \
+-serial none -parallel none -usb
diff --git 
a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml
new file mode 100644
index 000..9f891c7
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-tray-no-device-cap.xml
@@ -0,0 +1,32 @@
+domain type='qemu'
+  nameQEMUGuest1/name
+  uuidc7a5fdbd-edaf-9455-926a-d65c16db1809/uuid
+  memory219100/memory
+  currentMemory219100/currentMemory
+  vcpu1/vcpu
+  os
+type arch='i686' machine='pc'hvm/type
+boot dev='hd'/
+  /os
+  clock offset='utc'/
+  on_poweroffdestroy/on_poweroff
+  on_rebootrestart/on_reboot
+  on_crashdestroy/on_crash
+  devices
+emulator/usr/bin/qemu/emulator
+disk type='block' device='disk'
+  source dev='/dev/HostVG/QEMUGuest1'/
+  target dev='hda' bus='ide'/
+  address type='drive' controller='0' bus='0' target='0' unit='0'/
+/disk
+disk type='file' device='cdrom'
+  source file='/root/boot.iso'/
+  target dev='hdc' bus='ide' tray='open'/
+  readonly/
+  address type='drive' controller='0' bus='1' target='0' unit='0'/
+/disk
+controller type='usb' index='0'/
+controller type='ide' index='0'/
+

[libvirt] [PATCH 6/9] Add support for the wakeup event

2012-03-05 Thread Osier Yang
This patch introduces a new event type for the QMP event
WAKEUP:

   VIR_DOMAIN_EVENT_ID_WAKEUP

The event doesn't take any data. Thus the callback definition
is:

typedef void
(*virConnectDomainEventWakeupCallback)(virConnectPtr conn,
   virDomainPtr dom,
   void *opaque);
---
 daemon/remote.c|   24 ++
 examples/domain-events/events-c/event-test.c   |   19 +++-
 examples/domain-events/events-python/event-test.py |4 ++
 include/libvirt/libvirt.h.in   |   16 +++
 python/libvirt-override-virConnect.py  |8 +++
 python/libvirt-override.c  |   48 
 src/conf/domain_event.c|   31 +
 src/conf/domain_event.h|2 +
 src/libvirt_private.syms   |2 +
 src/qemu/qemu_monitor.c|   12 +
 src/qemu/qemu_monitor.h|4 ++
 src/qemu/qemu_monitor_json.c   |   10 -
 src/qemu/qemu_process.c|   21 +
 src/remote/remote_driver.c |   32 +
 src/remote/remote_protocol.x   |7 +++-
 src/remote_protocol-structs|7 ++-
 16 files changed, 242 insertions(+), 5 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index cc464fd..548faab 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -537,6 +537,29 @@ static int remoteRelayDomainEventTrayMoved(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 return 0;
 }
 
+static int remoteRelayDomainEventWakeup(virConnectPtr conn ATTRIBUTE_UNUSED,
+virDomainPtr dom,
+void *opaque) {
+virNetServerClientPtr client = opaque;
+remote_domain_event_wakeup_msg data;
+
+if (!client)
+return -1;
+
+VIR_DEBUG(Relaying domain %s %d system wakeup, dom-name, dom-id);
+
+/* build return data */
+memset(data, 0, sizeof data);
+make_nonnull_domain(data.dom, dom);
+
+remoteDispatchDomainEventSend(client, remoteProgram,
+  REMOTE_PROC_DOMAIN_EVENT_WAKEUP,
+  
(xdrproc_t)xdr_remote_domain_event_wakeup_msg, data);
+
+return 0;
+}
+
+
 static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot),
@@ -549,6 +572,7 @@ static virConnectDomainEventGenericCallback 
domainEventCallbacks[] = {
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockJob),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDiskChange),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventTrayMoved),
+VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventWakeup),
 };
 
 verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
diff --git a/examples/domain-events/events-c/event-test.c 
b/examples/domain-events/events-c/event-test.c
index c7bcaeb..15cf5b3 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -325,6 +325,15 @@ static int myDomainEventTrayMovedCallback(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 return 0;
 }
 
+static int myDomainEventWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+   virDomainPtr dom,
+   void *opaque ATTRIBUTE_UNUSED)
+{
+printf(%s EVENT: Domain %s(%d) system wakeup,
+   __func__, virDomainGetName(dom), virDomainGetID(dom));
+return 0;
+}
+
 static void myFreeFunc(void *opaque)
 {
 char *str = opaque;
@@ -361,6 +370,7 @@ int main(int argc, char **argv)
 int callback8ret = -1;
 int callback9ret = -1;
 int callback10ret = -1;
+int callback11ret = -1;
 struct sigaction action_stop;
 
 memset(action_stop, 0, sizeof action_stop);
@@ -436,6 +446,11 @@ int main(int argc, char **argv)
  
VIR_DOMAIN_EVENT_ID_TRAY_MOVED,
  
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventTrayMovedCallback),
  strdup(tray moved), 
myFreeFunc);
+callback11ret = virConnectDomainEventRegisterAny(dconn,
+ NULL,
+ 
VIR_DOMAIN_EVENT_ID_WAKEUP,
+ 
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventWakeupCallback),
+ strdup(system wakeup), 
myFreeFunc);
 
 if ((callback1ret != -1) 
 (callback2ret != -1) 
@@ -445,7 +460,8 @@ int main(int argc, char **argv)
 (callback6ret 

[libvirt] [PATCH 7/9] Add support for the event suspend

2012-03-05 Thread Osier Yang
This patch introduces a new event type for the QMP event
SUSPEND:

VIR_DOMAIN_EVENT_ID_SUSPEND

The event doesn't take any data. Thus the callback definition
is:

typedef void
(*virConnectDomainEventSuspendCallback)(virConnectPtr conn,
virDomainPtr dom,
void *opaque);
---
 daemon/remote.c|   23 +
 examples/domain-events/events-c/event-test.c   |   21 -
 examples/domain-events/events-python/event-test.py |4 ++
 include/libvirt/libvirt.h.in   |   16 +++
 python/libvirt-override-virConnect.py  |9 
 python/libvirt-override.c  |   48 
 src/conf/domain_event.c|   28 +++
 src/conf/domain_event.h|2 +
 src/libvirt_private.syms   |6 ++-
 src/qemu/qemu_monitor.c|   12 +
 src/qemu/qemu_monitor.h|3 +
 src/qemu/qemu_monitor_json.c   |9 
 src/qemu/qemu_process.c|   22 +
 src/remote/remote_driver.c |   32 +
 src/remote/remote_protocol.x   |7 +++-
 src/remote_protocol-structs|3 +
 16 files changed, 240 insertions(+), 5 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 548faab..6a48456 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -559,6 +559,28 @@ static int remoteRelayDomainEventWakeup(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 return 0;
 }
 
+static int remoteRelayDomainEventSuspend(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ void *opaque) {
+virNetServerClientPtr client = opaque;
+remote_domain_event_suspend_msg data;
+
+if (!client)
+return -1;
+
+VIR_DEBUG(Relaying domain %s %d system suspend, dom-name, dom-id);
+
+/* build return data */
+memset(data, 0, sizeof data);
+make_nonnull_domain(data.dom, dom);
+
+remoteDispatchDomainEventSend(client, remoteProgram,
+  REMOTE_PROC_DOMAIN_EVENT_SUSPEND,
+  
(xdrproc_t)xdr_remote_domain_event_suspend_msg, data);
+
+return 0;
+}
+
 
 static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
@@ -573,6 +595,7 @@ static virConnectDomainEventGenericCallback 
domainEventCallbacks[] = {
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDiskChange),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventTrayMoved),
 VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventWakeup),
+VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventSuspend),
 };
 
 verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
diff --git a/examples/domain-events/events-c/event-test.c 
b/examples/domain-events/events-c/event-test.c
index 15cf5b3..1629358 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -334,6 +334,15 @@ static int myDomainEventWakeupCallback(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 return 0;
 }
 
+static int myDomainEventSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+virDomainPtr dom,
+void *opaque ATTRIBUTE_UNUSED)
+{
+printf(%s EVENT: Domain %s(%d) system suspend,
+   __func__, virDomainGetName(dom), virDomainGetID(dom));
+return 0;
+}
+
 static void myFreeFunc(void *opaque)
 {
 char *str = opaque;
@@ -371,6 +380,7 @@ int main(int argc, char **argv)
 int callback9ret = -1;
 int callback10ret = -1;
 int callback11ret = -1;
+int callback12ret = -1;
 struct sigaction action_stop;
 
 memset(action_stop, 0, sizeof action_stop);
@@ -450,7 +460,12 @@ int main(int argc, char **argv)
  NULL,
  
VIR_DOMAIN_EVENT_ID_WAKEUP,
  
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventWakeupCallback),
- strdup(system wakeup), 
myFreeFunc);
+ strdup(wakeup), 
myFreeFunc);
+callback12ret = virConnectDomainEventRegisterAny(dconn,
+ NULL,
+ 
VIR_DOMAIN_EVENT_ID_SUSPEND,
+ 
VIR_DOMAIN_EVENT_CALLBACK(myDomainEventSuspendCallback),
+ strdup(suspend), 
myFreeFunc);
 
 if ((callback1ret != -1) 
 (callback2ret 

[libvirt] [PATCH 9/9] qemu: Update domain status to running while wakeup event is emitted

2012-03-05 Thread Osier Yang
This introduces a new running reason VIR_DOMAIN_RUNNING_WAKEUP,
and new suspend event type VIR_DOMAIN_EVENT_STARTED_WAKEUP.

While a wakeup event is emitted, the domain which was paused with
reason VIR_DOMAIN_PAUSED_SUSPEND will be transferred to running
with reason VIR_DOMAIN_RUNNING_WAKEUP, and a new domain lifecycle
event emitted with type VIR_DOMAIN_EVENT_STARTED_WAKEUP.
---
 examples/domain-events/events-c/event-test.c |3 ++
 include/libvirt/libvirt.h.in |2 +
 src/qemu/qemu_process.c  |   30 -
 tools/virsh.c|2 +
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/examples/domain-events/events-c/event-test.c 
b/examples/domain-events/events-c/event-test.c
index 9231604..79a89b0 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -93,6 +93,9 @@ static const char *eventDetailToString(int event, int detail) 
{
 case VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT:
 ret = Snapshot;
 break;
+case VIR_DOMAIN_EVENT_STARTED_WAKEUP:
+ret = Event wakeup;
+break;
 }
 break;
 case VIR_DOMAIN_EVENT_SUSPENDED:
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 11b7388..7c8c820 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -121,6 +121,7 @@ typedef enum {
 VIR_DOMAIN_RUNNING_UNPAUSED = 5,/* returned from paused state */
 VIR_DOMAIN_RUNNING_MIGRATION_CANCELED = 6,  /* returned from migration */
 VIR_DOMAIN_RUNNING_SAVE_CANCELED = 7,   /* returned from failed save 
process */
+VIR_DOMAIN_RUNNING_WAKEUP = 8,  /* returned due to a wakeup event 
*/
 
 #ifdef VIR_ENUM_SENTINELS
 VIR_DOMAIN_RUNNING_LAST
@@ -2665,6 +2666,7 @@ typedef enum {
 VIR_DOMAIN_EVENT_STARTED_MIGRATED = 1, /* Incoming migration from another 
host */
 VIR_DOMAIN_EVENT_STARTED_RESTORED = 2, /* Restored from a state file */
 VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT = 3, /* Restored from snapshot */
+VIR_DOMAIN_EVENT_STARTED_WAKEUP = 4,   /* Started due to a wakeup event */
 
 #ifdef VIR_ENUM_SENTINELS
 VIR_DOMAIN_EVENT_STARTED_LAST
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 19e6e03..c75067d 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1064,15 +1064,41 @@ qemuProcessHandleWakeup(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 {
 struct qemud_driver *driver = qemu_driver;
 virDomainEventPtr event = NULL;
+virDomainEventPtr lifecycleEvent = NULL;
+int reason;
+
 
 virDomainObjLock(vm);
 event = virDomainEventWakeupNewFromObj(vm);
 
 virDomainObjUnlock(vm);
 
-if (event) {
+/* Don't set domain status back to running if it wasn't paused
+ * from guest side, otherwise it can just cause confusion.
+ */
+if ((virDomainObjGetState(vm, reason) == VIR_DOMAIN_PAUSED) 
+(reason == VIR_DOMAIN_PAUSED_SUSPEND)) {
+VIR_DEBUG(Transitioned guest %s to running state due to 
+  QMP wakeup event, vm-def-name);
+
+virDomainObjSetState(vm, VIR_DOMAIN_RUNNING,
+ VIR_DOMAIN_RUNNING_WAKEUP);
+lifecycleEvent = virDomainEventNewFromObj(vm,
+  VIR_DOMAIN_EVENT_STARTED,
+  
VIR_DOMAIN_EVENT_STARTED_WAKEUP);
+
+if (virDomainSaveStatus(driver-caps, driver-stateDir, vm)  0) {
+VIR_WARN(Unable to save status on vm %s after wakeup event,
+ vm-def-name);
+}
+}
+
+if (event || lifecycleEvent) {
 qemuDriverLock(driver);
-qemuDomainEventQueue(driver, event);
+if (event)
+qemuDomainEventQueue(driver, event);
+if (lifecycleEvent)
+qemuDomainEventQueue(driver, lifecycleEvent);
 qemuDriverUnlock(driver);
 }
 
diff --git a/tools/virsh.c b/tools/virsh.c
index 9063131..09e3290 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -18596,6 +18596,8 @@ vshDomainStateReasonToString(int state, int reason)
 return N_(migration canceled);
 case VIR_DOMAIN_RUNNING_SAVE_CANCELED:
 return N_(save canceled);
+case VIR_DOMAIN_RUNNING_WAKEUP:
+return N_(event wakeup);
 case VIR_DOMAIN_RUNNING_UNKNOWN:
 case VIR_DOMAIN_RUNNING_LAST:
 ;
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] qemu: Fix indention

2012-03-05 Thread Osier Yang
Pushed under trivial rule.
---
 src/qemu/qemu_driver.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2afcc3f..27478c0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12136,10 +12136,10 @@ qemuDomainPMSuspendForDuration(virDomainPtr dom,
 if (!qemuCapsGet(priv-qemuCaps, QEMU_CAPS_WAKEUP) 
 (target == VIR_NODE_SUSPEND_TARGET_MEM ||
  target == VIR_NODE_SUSPEND_TARGET_HYBRID)) {
-   qemuReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, %s,
-   _(Unable to suspend domain due to 
- missing system_wakeup monitor command));
-   goto cleanup;
+qemuReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, %s,
+_(Unable to suspend domain due to 
+  missing system_wakeup monitor command));
+goto cleanup;
 }
 
 if (priv-agentError) {
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Fix typo and add missed comment for diskChange callback

2012-03-05 Thread Osier Yang
Comment for parameter devAlias is missed. And a typo should
be caused by copy  paste.

--
Pushed under trivial rule.
---
 include/libvirt/libvirt.h.in |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 58c4366..92cc30c 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3624,6 +3624,7 @@ typedef enum {
  * @dom: domain on which the event occurred
  * @oldSrcPath: old source path
  * @newSrcPath: new source path
+ * @devAlias: device alias name
  * @reason: reason why this callback was called; any of
  *  virConnectDomainEventDiskChangeReason
  * @opaque: application specified data
@@ -3634,7 +3635,7 @@ typedef enum {
  * for more details.
  *
  * The callback signature to use when registering for an event of type
- * VIR_DOMAIN_EVENT_ID_IO_ERROR with virConnectDomainEventRegisterAny()
+ * VIR_DOMAIN_EVENT_ID_DISK_CHANGE with virConnectDomainEventRegisterAny()
  */
 typedef void (*virConnectDomainEventDiskChangeCallback)(virConnectPtr conn,
virDomainPtr dom,
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] build: Fix build with dtrace + apparmor

2012-03-05 Thread Jiri Denemark
On Thu, Mar 01, 2012 at 08:45:20 -0700, Eric Blake wrote:
 On 03/01/2012 08:12 AM, Jiri Denemark wrote:
  Building virt-aa-helper with dtrace probes enabled, ldd complained about
  undefined references:
  
  ./.libs/libvirt_util.a(libvirt_util_la-event_poll.o):(.note.stapsdt+0x24):
  undefined reference to `libvirt_event_poll_purge_timeout_semaphore'
  ...
  ---
   src/Makefile.am |3 +++
   1 files changed, 3 insertions(+), 0 deletions(-)
 
 ACK.

Thanks, pushed.

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] rpc: Fix client crash on connection close

2012-03-05 Thread Jiri Denemark
On Fri, Mar 02, 2012 at 16:12:16 -0700, Eric Blake wrote:
 On 03/02/2012 01:49 PM, Jiri Denemark wrote:
  A multi-threaded client with event loop may crash if one of its threads
  closes a connection while event loop is in the middle of sending
  keep-alive message (either request or response). The right place for it
  is inside virNetClientIOEventLoop() between poll() and
  virNetClientLock(). We should only close a connection directly if no-one
  is using it and defer the closing to the last user otherwise. So far we
  only did so if the close was initiated by keep-alive timeout.
  ---
   src/rpc/virnetclient.c |   18 --
   1 files changed, 4 insertions(+), 14 deletions(-)
  
 
  @@ -512,19 +510,11 @@ virNetClientCloseLocked(virNetClientPtr client)
   
   void virNetClientClose(virNetClientPtr client)
   {
  -if (!client)
  -return;
  -
  -virNetClientLock(client);
  -virNetClientCloseLocked(client);
  -virNetClientUnlock(client);
  -}
  -
  -static void
  -virNetClientRequestClose(virNetClientPtr client)
  -{
   VIR_DEBUG(client=%p, client);
 
 The diff that git picked is a bit confusing;

And I explicitly chose --patience diff since it generated better diff, which
represents exactly what I did :-)

 but it looks like all you are doing is stating that virNetClientClose should
 do the same thing as virNetClientRequestClose did (which is safer); and now
 that they do the same, you don't need two names, so pick the shorter name.

Right.

 ACK.

Thanks and pushed.

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2] libvirt-guests: Add parallel startup and shutdown of guests

2012-03-05 Thread Peter Krempa

On 03/03/2012 03:03 AM, Eric Blake wrote:

On 03/01/2012 07:23 AM, Peter Krempa wrote:

With this patch, it's possible to shut down guests in parallel. Parallel
startup was possible before, but this functionality was not documented
properly.

To enable parallel startup set the START_DELAY to 0.

Parallel shutdown has a configurable parameter PARALLEL_SHUTDOWN that
defines the number of machines being shut down in parallel. Enabling
this feature changes the semantics of SHUTDOWN_TIMEOUT parameter that is
applied as a cumulative timeout to shutdown all guests on a URI.
---



+# shutdown_guests_parallel URI GUESTS
+# Shutdown guests GUESTS on machine URI in parallel
+shutdown_guests_parallel()
+{
+uri=$1
+guests=$2
+
+on_shutdown=


check_timeout=false


+timeout=$SHUTDOWN_TIMEOUT


if [ $timeout -gt 0 ]; then
 check_timeout=true
fi


+while [ -n $on_shutdown ] || [ -n $guests ]; do
+while [ -n $guests ]
+  [ $(guest_count $on_shutdown) -lt $PARALLEL_SHUTDOWN ]; do
+set -- $guests
+guest=$1
+shift
+guests=$*
+shutdown_guest_async $uri $guest
+on_shutdown=$on_shutdown $guest
+done
+sleep 1


if $check_timeout; then


+timeout=$(($timeout - 1))
+if [ $timeout -le 0 ]; then
+eval_gettext Timeout expired while shutting down domains; echo
+RETVAL=1
+return
+fi


fi


+on_shutdown_prev=$on_shutdown
+on_shutdown=$(check_guests_shutdown $uri $on_shutdown)
+print_guests_shutdown $uri $on_shutdown_prev $on_shutdown
+done
+}
+




-# number of seconds we're willing to wait for a guest to shut down
+# If set to non-zero, shutdown will suspend guests concurrently. Number of
+# guests on shutdown at any time will not exceed number set in this variable.
+#PARALLEL_SHUTDOWN=0
+
+# Number of seconds we're willing to wait for a guest to shut down. If parallel
+# shutdown is enabled, this timeout applies as a timeout for shutting down all
+# guests on a single URI defined in the variable URIS. This must be set to
+# a nonzero positive value if the shutdown action is requested.


Change the last sentence:

If this is 0, then there is no time out (use with caution, as guests
might not respond to a shutdown request).  (Hmm, maybe we want to
default to 300 [5 minutes], and document our non-zero default, so that
you have to explicitly request 0 to avoid timeouts.)

ACK with those lines added to shutdown_guests_parallel, and the wording
change to the config file, and with the optional change to the timeout
default.



The same check for the timeout was also needed in shutdown_guest(). I 
added the checks, changed the wording in the config file and set the 
default SHUTDOWN_TIMEOUT to 300 (with a note in the docs) and pushed the 
result.


Thanks

Peter

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: Shared or readonly disks are always safe wrt migration

2012-03-05 Thread Michal Privoznik
On 05.03.2012 15:15, Jiri Denemark wrote:
 No matter what cache mode is used, readonly disks are always safe wrt
 migration. Shared disks are required to be readonly or to disable
 host-side cache, which makes them safe as well.
 ---
  src/qemu/qemu_migration.c |8 +---
  1 files changed, 5 insertions(+), 3 deletions(-)
 

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] qemu: Shared or readonly disks are always safe wrt migration

2012-03-05 Thread Jiri Denemark
No matter what cache mode is used, readonly disks are always safe wrt
migration. Shared disks are required to be readonly or to disable
host-side cache, which makes them safe as well.
---
 src/qemu/qemu_migration.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 84037e4..5c4297c 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -828,10 +828,12 @@ qemuMigrationIsSafe(virDomainDefPtr def)
 for (i = 0 ; i  def-ndisks ; i++) {
 virDomainDiskDefPtr disk = def-disks[i];
 
-/* shared  !readonly implies cache=none */
+/* Our code elsewhere guarantees shared disks are either readonly (in
+ * which case cache mode doesn't matter) or used with cache=none */
 if (disk-src 
-disk-cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE 
-(disk-cachemode || !disk-shared || disk-readonly)) {
+!disk-shared 
+!disk-readonly 
+disk-cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) {
 int cfs;
 if ((cfs = virStorageFileIsClusterFS(disk-src)) == 1)
 continue;
-- 
1.7.8.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: Shared or readonly disks are always safe wrt migration

2012-03-05 Thread Jiri Denemark
On Mon, Mar 05, 2012 at 15:20:10 +0100, Michal Privoznik wrote:
 On 05.03.2012 15:15, Jiri Denemark wrote:
  No matter what cache mode is used, readonly disks are always safe wrt
  migration. Shared disks are required to be readonly or to disable
  host-side cache, which makes them safe as well.
  ---
   src/qemu/qemu_migration.c |8 +---
   1 files changed, 5 insertions(+), 3 deletions(-)
  
 
 ACK

Pushed, thanks.

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] util: fail attempts to use same mac address for guest and tap

2012-03-05 Thread Laine Stump
This patch is in response to:

  https://bugzilla.redhat.com/show_bug.cgi?id=798467

If a guest's tap device is created using the same MAC address the
guest uses for its own network card (which connects to the tap
device), the Linux kernel will log the following message and traffic
will not pass:

 kernel: vnet9: received packet with own address as source address

This patch disallows MAC addresses with a first byte of 0xFE, but only in
the case that the MAC address is used for a guest interface that's
connected by way of a standard tap device. (In other words, the
validation is done at runtime at the same place the MAC address is
modified for the tap device, rather than when mac address is parsed,
the idea being that it is then we know for sure the address will be
problematic.)
---
 src/util/virnetdevtap.c |   22 --
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
index fb0a8d2..b19c006 100644
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2011 Red Hat, Inc.
+ * Copyright (C) 2007-2012 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -45,6 +45,10 @@
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+#define virNetDevTapError(code, ...)\
+virReportErrorHelper(VIR_FROM_NONE, code, __FILE__, \
+ __FUNCTION__, __LINE__, __VA_ARGS__)
+
 /**
  * virNetDevProbeVnetHdr:
  * @tapfd: a tun/tap file descriptor
@@ -293,8 +297,22 @@ int virNetDevTapCreateInBridgePort(const char *brname,
  * device before we set our static MAC.
  */
 memcpy(tapmac, macaddr, VIR_MAC_BUFLEN);
-if (!(flags  VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE))
+if (!(flags  VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE)) {
+if (macaddr[0] == 0xFE) {
+/* For normal use, the tap device's MAC address cannot
+ * match the MAC address used by the guest. This results
+ * in received packet on vnetX with own address as source
+ * address error logs from the kernel.
+ */
+virNetDevTapError(VIR_ERR_CONFIG_UNSUPPORTED,
+  Unable to use MAC address starting with 
+  reserved value 0xFE - 
'%02X:%02X:%02X:%02X:%02X:%02X' - ,
+  macaddr[0], macaddr[1], macaddr[2],
+  macaddr[3], macaddr[4], macaddr[5]);
+goto error;
+}
 tapmac[0] = 0xFE; /* Discourage bridge from using TAP dev MAC */
+}
 
 if (virNetDevSetMAC(*ifname, tapmac)  0)
 goto error;
-- 
1.7.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] util: fail attempts to use same mac address for guest and tap

2012-03-05 Thread Eric Blake
On 03/05/2012 09:05 AM, Laine Stump wrote:
 This patch is in response to:
 
   https://bugzilla.redhat.com/show_bug.cgi?id=798467
 
 If a guest's tap device is created using the same MAC address the
 guest uses for its own network card (which connects to the tap
 device), the Linux kernel will log the following message and traffic
 will not pass:
 
  kernel: vnet9: received packet with own address as source address
 
 This patch disallows MAC addresses with a first byte of 0xFE, but only in
 the case that the MAC address is used for a guest interface that's
 connected by way of a standard tap device. (In other words, the
 validation is done at runtime at the same place the MAC address is
 modified for the tap device, rather than when mac address is parsed,
 the idea being that it is then we know for sure the address will be
 problematic.)
 ---
  src/util/virnetdevtap.c |   22 --
  1 files changed, 20 insertions(+), 2 deletions(-)

ACK.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/4] pci: Add two new pci utils pciDeviceGetVirtualFunctionInfo and pciConfigAddressToSysfsFile

2012-03-05 Thread Laine Stump
On 03/04/2012 10:15 PM, Roopa Prabhu wrote:
 From: Roopa Prabhu ropra...@cisco.com

 pciDeviceGetVirtualFunctionInfo returns pf netdevice name and virtual
 function index for a given vf. This is just a wrapper around existing 
 functions
 to return vf's pf and vf_index with one api call

 pciConfigAddressToSysfsfile returns the sysfile pci device link
 from a 'struct pci_config_address'

 Signed-off-by: Roopa Prabhu ropra...@cisco.com
 ---
  src/util/pci.c |   55 +++
  src/util/pci.h |7 +++
  2 files changed, 62 insertions(+), 0 deletions(-)

ACK.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] blockResize: add flag for bytes

2012-03-05 Thread Eric Blake
On 03/03/2012 05:36 PM, Laine Stump wrote:
 On 03/03/2012 09:48 AM, Eric Blake wrote:
 Qemu supports sizing by bytes; we shouldn't force the user to
 round up if they really wanted an unaligned total size.

 * include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_RESIZE_BYTES):
 New flag.
 * src/libvirt.c (virDomainBlockResize): Document it.
 * src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockResize): Take
 size in bytes.
 * src/qemu/qemu_monitor_text.c (qemuMonitorTextBlockResize):
 Likewise.  Pass bytes, not megabytes, to monitor.
 * src/qemu/qemu_driver.c (qemuDomainBlockResize): Implement new
 flag.
 ---
 
 Looks okay to me. ACK.

Thanks; pushed.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/4] virtnetdev: Add support functions for mac and portprofile associations on a hostdev

2012-03-05 Thread Laine Stump
On 03/04/2012 10:15 PM, Roopa Prabhu wrote:
 From: Roopa Prabhu ropra...@cisco.com

 This patch adds the following:
 - functions to set and get vf configs
 - Functions to replace and store vf configs (Only mac address is handled 
 today.
   But the functions can be easily extended for vlans and other vf configs)
 - function to dump link dev info (This is moved from virnetdevvportprofile.c)

 Signed-off-by: Roopa Prabhu ropra...@cisco.com
 ---
  src/util/virnetdev.c |  531 
 ++
  src/util/virnetdev.h |   19 ++
  2 files changed, 549 insertions(+), 1 deletions(-)

(BTW, I never thought about doing it this way before, but I'm glad you
added the function here in a separate patch from the patch that removes
it from virnetdevvportprofile.c - that makes it easy to open the two
patches side-by-side and verify that it really is moving the same code
(well, mostly).)



 diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
 index 9d76d47..25f2155 100644
 --- a/src/util/virnetdev.c
 +++ b/src/util/virnetdev.c
 @@ -1127,8 +1127,497 @@ virNetDevGetPhysicalFunction(const char *ifname, char 
 **pfname)
  
  return ret;
  }
 -#else /* !__linux__ */

The functions here that use libnl need to be inside of

  #if defined(__linux__)  defined(HAVE_LIBNL)

since there are linux platforms that don't have libnl, or don't have the
proper LIBNL (RHEL5, in particular, still has libnl-1.0)

  
 +static struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
 +[IFLA_VF_MAC]   = { .type = NLA_UNSPEC,
 +.maxlen = sizeof(struct ifla_vf_mac) },
 +[IFLA_VF_VLAN]  = { .type = NLA_UNSPEC,
 +.maxlen = sizeof(struct ifla_vf_vlan) },
 +};
 +
 +/**
 + * virNetDevLinkDump:
 + *
 + * @ifname: The name of the interface; only use if ifindex  0
 + * @ifindex: The interface index; may be  0 if ifname is given
 + * @nltarget_kernel: whether to send the message to the kernel or another
 + *   process
 + * @nlattr: pointer to a pointer of netlink attributes that will contain
 + *  the results
 + * @recvbuf: Pointer to the buffer holding the returned netlink response
 + *   message; free it, once not needed anymore
 + * @getPidFunc: Pointer to a function that will be invoked if the kernel
 + *  is not the target of the netlink message but it is to be
 + *  sent to another process.
 + *
 + * Get information about an interface given its name or index.
 + *
 + * Returns 0 on success, -1 on fatal error.
 + */
 +int
 +virNetDevLinkDump(const char *ifname, int ifindex,
 +  bool nltarget_kernel, struct nlattr **tb,
 +  unsigned char **recvbuf,
 +  uint32_t (*getPidFunc)(void))
 +{
 +int rc = 0;
 +struct nlmsghdr *resp;
 +struct nlmsgerr *err;
 +struct ifinfomsg ifinfo = {
 +.ifi_family = AF_UNSPEC,
 +.ifi_index  = ifindex
 +};
 +unsigned int recvbuflen;
 +uint32_t pid = 0;
 +struct nl_msg *nl_msg;
 +
 +*recvbuf = NULL;
 +
 +if (ifindex = 0  virNetDevGetIndex(ifname, ifindex)  0)
 +return -1;
 +
 +ifinfo.ifi_index = ifindex;
 +
 +nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
 +if (!nl_msg) {
 +virReportOOMError();
 +return -1;
 +}
 +
 +if (nlmsg_append(nl_msg,  ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO)  0)
 +goto buffer_too_small;
 +
 +if (ifindex  0  ifname) {
 +if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname)  0)
 +goto buffer_too_small;
 +}


Is this bit necessary any more? You've added code above that converts
the ifname into an ifindex, and we've already returned if it wasn't
successful.


 +
 +if (!nltarget_kernel) {
 +pid = getPidFunc();
 +if (pid == 0) {
 +rc = -1;
 +goto cleanup;
 +}
 +}
 +
 +if (virNetlinkCommand(nl_msg, recvbuf, recvbuflen, pid)  0) {
 +rc = -1;
 +goto cleanup;
 +}
 +
 +if (recvbuflen  NLMSG_LENGTH(0) || *recvbuf == NULL)
 +goto malformed_resp;
 +
 +resp = (struct nlmsghdr *)*recvbuf;
 +
 +switch (resp-nlmsg_type) {
 +case NLMSG_ERROR:
 +err = (struct nlmsgerr *)NLMSG_DATA(resp);
 +if (resp-nlmsg_len  NLMSG_LENGTH(sizeof(*err)))
 +goto malformed_resp;
 +
 +if (err-error) {
 +virReportSystemError(-err-error,
 + _(error dumping %s (%d) interface),
 + ifname, ifindex);
 +rc = -1;
 +}
 +break;
 +
 +case GENL_ID_CTRL:
 +case NLMSG_DONE:
 +rc = nlmsg_parse(resp, sizeof(struct ifinfomsg),
 + tb, IFLA_MAX, NULL);
 +if (rc  0)
 +goto malformed_resp;
 +break;
 +
 +default:
 +goto malformed_resp;
 +}
 +
 +if (rc != 0)
 +

Re: [libvirt] [PATCH 3/4] virnetdevvportprofile: Changes to support portprofiles for hostdevs

2012-03-05 Thread Laine Stump
I encountered two conflicts when I rebased this patch to upstream. Noted
in the comments.

On 03/04/2012 10:15 PM, Roopa Prabhu wrote:
 From: Roopa Prabhu ropra...@cisco.com

 This patch includes the following changes
 - removes some netlink functions which are now available in virnetdev.c
 - Adds a vf argument to all port profile functions

 For 802.1Qbh devices, the port profile calls can use a vf argument if
 passed by the caller. If the vf argument is -1 it will try to derive the vf
 if the device passed is a virtual function.

 For 802.1Qbg devices, This patch introduces a null check for the device
 argument because during port profile assignment on a hostdev, this argument
 can be null. Stefan CC'ed for comments

 Signed-off-by: Roopa Prabhu ropra...@cisco.com
 ---
  src/qemu/qemu_migration.c|2 
  src/util/virnetdevmacvlan.c  |6 +
  src/util/virnetdevvportprofile.c |  203 
 +-
  src/util/virnetdevvportprofile.h |8 +
  4 files changed, 42 insertions(+), 177 deletions(-)


 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
 index 7df2d4f..b80ed69 100644
 --- a/src/qemu/qemu_migration.c
 +++ b/src/qemu/qemu_migration.c
 @@ -2605,6 +2605,7 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr 
 def) {
 
 virDomainNetGetActualVirtPortProfile(net),
 net-mac,
 
 virDomainNetGetActualDirectDev(net),
 +   -1,
 def-uuid,
 
 VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_FINISH)  0)
  goto err_exit;
 @@ -2622,6 +2623,7 @@ err_exit:
 
 virDomainNetGetActualVirtPortProfile(net),
 net-mac,
 
 virDomainNetGetActualDirectDev(net),
 +   -1,
 
 VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_FINISH));
  }
  }
 diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
 index 25d0846..498a2a0 100644
 --- a/src/util/virnetdevmacvlan.c
 +++ b/src/util/virnetdevmacvlan.c
 @@ -486,6 +486,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char 
 *tgifname,
  uint32_t macvtapMode;
  const char *cr_ifname;
  int ret;
 +int vf = -1;
  
  macvtapMode = modeMap[mode];
  
 @@ -547,6 +548,7 @@ create_name:
 virtPortProfile,
 macaddress,
 linkdev,
 +   vf,
 vmuuid, vmOp)  0) {
  rc = -1;
  goto link_del_exit;
 @@ -597,6 +599,7 @@ disassociate_exit:
 virtPortProfile,
 macaddress,
 linkdev,
 +   vf,
 vmOp));
  
  link_del_exit:
 @@ -624,6 +627,8 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char 
 *ifname,
 char *stateDir)
  {
  int ret = 0;
 +int vf = -1;
 +
  if (mode == VIR_NETDEV_MACVLAN_MODE_PASSTHRU) {
  ignore_value(virNetDevRestoreMacAddress(linkdev, stateDir));
  }
 @@ -633,6 +638,7 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char 
 *ifname,
virtPortProfile,
macaddr,
linkdev,
 +  vf,

 VIR_NETDEV_VPORT_PROFILE_OP_DESTROY)  0)
  ret = -1;
  if (virNetDevMacVLanDelete(ifname)  0)
 diff --git a/src/util/virnetdevvportprofile.c 
 b/src/util/virnetdevvportprofile.c
 index 67fd7bc..8d9e906 100644
 --- a/src/util/virnetdevvportprofile.c
 +++ b/src/util/virnetdevvportprofile.c
 @@ -126,11 +126,6 @@ static struct nla_policy ifla_port_policy[IFLA_PORT_MAX 
 + 1] =
  {
[IFLA_PORT_RESPONSE]  = { .type = NLA_U16 },
  };
 -static struct nla_policy ifla_policy[IFLA_MAX + 1] =
 -{
 -  [IFLA_VF_PORTS] = { .type = NLA_NESTED },
 -};
 -
  
  static uint32_t
  virNetDevVPortProfileGetLldpadPid(void) {
 @@ -164,126 +159,6 @@ virNetDevVPortProfileGetLldpadPid(void) {
  return pid;
  }
  
 -
 -/**
 - * virNetDevVPortProfileLinkDump:
 - *
 - * @ifname: The name of the interface; only use if ifindex  0
 - * @ifindex: The interface index; may be  0 if 

[libvirt] [PATCH] Fix build after commit e3ba4025

2012-03-05 Thread Jim Fehlig
This patch fixes some build error I've encountered, but would prefer an
ACK before pushing.

Thanks,
Jim

From ff81637b66793fd4b2b46e8e04357e8d406dde31 Mon Sep 17 00:00:00 2001
From: Jim Fehlig jfeh...@suse.com
Date: Mon, 5 Mar 2012 12:08:54 -0700
Subject: [PATCH] Fix build after commit e3ba4025

Commit e3ba4025 introduced a few build errors with HAVE_LIBNL undefined.
---
 src/util/virnetdevvportprofile.c |2 +-
 src/util/virnetlink.c|   10 ++
 src/util/virnetlink.h|2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index 00fd123..f6db292 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -1071,7 +1071,7 @@ int virNetDevVPortProfileAssociate(const char *macvtap_ifname ATTRIBUTE_UNUSED,
const char *linkdev ATTRIBUTE_UNUSED,
const unsigned char *vmuuid ATTRIBUTE_UNUSED,
enum virNetDevVPortProfileOp vmOp ATTRIBUTE_UNUSED,
-   bool setlink_only)
+   bool setlink_only ATTRIBUTE_UNUSED)
 {
 virReportSystemError(ENOSYS, %s,
  _(Virtual port profile association not supported on this platform));
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index 264fcdb..63d 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -585,9 +585,10 @@ int virNetlinkEventServiceIsRunning(void)
  * virNetlinkEventAddClient: register a callback for handling of
  * netlink messages
  */
-int virNetlinkEventAddClient(virNetlinkEventHandleCallback cb,
- virNetlinkEventRemoveCallback cb,
- void *opaque, const unsigned char *macaddr)
+int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB ATTRIBUTE_UNUSED,
+ virNetlinkEventRemoveCallback removeCB ATTRIBUTE_UNUSED,
+ void *opaque ATTRIBUTE_UNUSED,
+ const unsigned char *macaddr ATTRIBUTE_UNUSED)
 {
 netlinkError(VIR_ERR_INTERNAL_ERROR,
 %s,
@@ -602,7 +603,8 @@ int virNetlinkEventAddClient(virNetlinkEventHandleCallback cb,
 /**
  * virNetlinkEventRemoveClient: unregister a callback from a netlink monitor
  */
-int virNetlinkEventRemoveClient(int watch, const unsigned char *macaddr)
+int virNetlinkEventRemoveClient(int watch ATTRIBUTE_UNUSED,
+const unsigned char *macaddr ATTRIBUTE_UNUSED)
 {
 netlinkError(VIR_ERR_INTERNAL_ERROR,
 %s,
diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
index 75533a3..71c962e 100644
--- a/src/util/virnetlink.h
+++ b/src/util/virnetlink.h
@@ -55,7 +55,7 @@ int virNetlinkEventServiceStart(void);
 /**
  * virNetlinkEventServiceIsRunning: returns if the netlink event service is running.
  */
-bool virNetlinkEventServiceIsRunning(void);
+int virNetlinkEventServiceIsRunning(void);
 
 /**
  * virNetlinkEventAddClient: register a callback for handling of netlink messages
-- 
1.7.8.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] Fix build after commit e3ba4025

2012-03-05 Thread Eric Blake
On 03/05/2012 12:17 PM, Jim Fehlig wrote:
 This patch fixes some build error I've encountered, but would prefer an
 ACK before pushing.
 
 Thanks,
 Jim
 

 +++ b/src/util/virnetdevvportprofile.c
 @@ -1071,7 +1071,7 @@ int virNetDevVPortProfileAssociate(const char 
 *macvtap_ifname ATTRIBUTE_UNUSED,
 const char *linkdev ATTRIBUTE_UNUSED,
 const unsigned char *vmuuid ATTRIBUTE_UNUSED,
 enum virNetDevVPortProfileOp vmOp 
 ATTRIBUTE_UNUSED,
 -   bool setlink_only)
 +   bool setlink_only ATTRIBUTE_UNUSED)

Changes like these to add annotations are okay.

 +++ b/src/util/virnetlink.h
 @@ -55,7 +55,7 @@ int virNetlinkEventServiceStart(void);
  /**
   * virNetlinkEventServiceIsRunning: returns if the netlink event service is 
 running.
   */
 -bool virNetlinkEventServiceIsRunning(void);
 +int virNetlinkEventServiceIsRunning(void);

But this hunk looks wrong.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] util: eliminate crash in virNetDevMacVLanCreateWithVPortProfile

2012-03-05 Thread Laine Stump
From: root r...@vlap.laine.org

Commit 723d5c (added after the release of 0.9.10) adds a
NetlinkEventClient for each interface sent to
virNetDevMacVLanCreateWithVPortProfile. This should only be done if
the interface actually *has* a virtPortProfile, otherwise the event
handler would be a NOP. The bigger problem is that part of the setup
to create the NetlinkEventClient is to do a memcpy of virtPortProfile
- if it's NULL, this triggers a segv.

This patch just qualifies the code that adds the client - if
virtPortProfile is NULL, it's skipped.
---
 src/util/virnetdevmacvlan.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 57fc69e..e18b149 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -915,7 +915,7 @@ create_name:
 goto disassociate_exit;
 }
 
-if (virNetlinkEventServiceIsRunning()) {
+if (virtPortProfile  virNetlinkEventServiceIsRunning()) {
 if (VIR_ALLOC(calld)  0)
 goto memory_error;
 if ((calld-cr_ifname = strdup(cr_ifname)) == NULL)
-- 
1.7.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] util: eliminate crash in virNetDevMacVLanCreateWithVPortProfile

2012-03-05 Thread Michal Privoznik
On 05.03.2012 20:42, Laine Stump wrote:
 From: root r...@vlap.laine.org
 
 Commit 723d5c (added after the release of 0.9.10) adds a
 NetlinkEventClient for each interface sent to
 virNetDevMacVLanCreateWithVPortProfile. This should only be done if
 the interface actually *has* a virtPortProfile, otherwise the event
 handler would be a NOP. The bigger problem is that part of the setup
 to create the NetlinkEventClient is to do a memcpy of virtPortProfile
 - if it's NULL, this triggers a segv.
 
 This patch just qualifies the code that adds the client - if
 virtPortProfile is NULL, it's skipped.
 ---
  src/util/virnetdevmacvlan.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 

ACK

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 3/4] virnetdevvportprofile: Changes to support portprofiles for hostdevs

2012-03-05 Thread Roopa Prabhu



On 3/5/12 11:16 AM, Laine Stump la...@laine.org wrote:

 I encountered two conflicts when I rebased this patch to upstream. Noted
 in the comments.
 
 On 03/04/2012 10:15 PM, Roopa Prabhu wrote:
 From: Roopa Prabhu ropra...@cisco.com
 
 This patch includes the following changes
 - removes some netlink functions which are now available in virnetdev.c
 - Adds a vf argument to all port profile functions
 
 For 802.1Qbh devices, the port profile calls can use a vf argument if
 passed by the caller. If the vf argument is -1 it will try to derive the vf
 if the device passed is a virtual function.
 
 For 802.1Qbg devices, This patch introduces a null check for the device
 argument because during port profile assignment on a hostdev, this argument
 can be null. Stefan CC'ed for comments
 
 Signed-off-by: Roopa Prabhu ropra...@cisco.com
 ---
  src/qemu/qemu_migration.c|2
  src/util/virnetdevmacvlan.c  |6 +
  src/util/virnetdevvportprofile.c |  203
 +-
  src/util/virnetdevvportprofile.h |8 +
  4 files changed, 42 insertions(+), 177 deletions(-)
 
 
 diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
 index 7df2d4f..b80ed69 100644
 --- a/src/qemu/qemu_migration.c
 +++ b/src/qemu/qemu_migration.c
 @@ -2605,6 +2605,7 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr
 def) {
 
 virDomainNetGetActualVirtPortProfile(net),
 net-mac,
 
 virDomainNetGetActualDirectDev(net),
 +   -1,
 def-uuid,
 
 VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_FINISH)  0)
  goto err_exit;
 @@ -2622,6 +2623,7 @@ err_exit:
 
 virDomainNetGetActualVirtPortProfile(net),
 net-mac,
 
 virDomainNetGetActualDirectDev(net),
 +   -1,
 
 VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_FINISH));
  }
  }
 diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
 index 25d0846..498a2a0 100644
 --- a/src/util/virnetdevmacvlan.c
 +++ b/src/util/virnetdevmacvlan.c
 @@ -486,6 +486,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char
 *tgifname,
  uint32_t macvtapMode;
  const char *cr_ifname;
  int ret;
 +int vf = -1;
  
  macvtapMode = modeMap[mode];
  
 @@ -547,6 +548,7 @@ create_name:
 virtPortProfile,
 macaddress,
 linkdev,
 +   vf,
 vmuuid, vmOp)  0) {
  rc = -1;
  goto link_del_exit;
 @@ -597,6 +599,7 @@ disassociate_exit:
 virtPortProfile,
 macaddress,
 linkdev,
 +   vf,
 vmOp));
  
  link_del_exit:
 @@ -624,6 +627,8 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char
 *ifname,
 char *stateDir)
  {
  int ret = 0;
 +int vf = -1;
 +
  if (mode == VIR_NETDEV_MACVLAN_MODE_PASSTHRU) {
  ignore_value(virNetDevRestoreMacAddress(linkdev, stateDir));
  }
 @@ -633,6 +638,7 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char
 *ifname,
virtPortProfile,
macaddr,
linkdev,
 +  vf,
 
 VIR_NETDEV_VPORT_PROFILE_OP_DESTROY)  0)
  ret = -1;
  if (virNetDevMacVLanDelete(ifname)  0)
 diff --git a/src/util/virnetdevvportprofile.c
 b/src/util/virnetdevvportprofile.c
 index 67fd7bc..8d9e906 100644
 --- a/src/util/virnetdevvportprofile.c
 +++ b/src/util/virnetdevvportprofile.c
 @@ -126,11 +126,6 @@ static struct nla_policy ifla_port_policy[IFLA_PORT_MAX
 + 1] =
  {
[IFLA_PORT_RESPONSE]  = { .type = NLA_U16 },
  };
 -static struct nla_policy ifla_policy[IFLA_MAX + 1] =
 -{
 -  [IFLA_VF_PORTS] = { .type = NLA_NESTED },
 -};
 -
  
  static uint32_t
  virNetDevVPortProfileGetLldpadPid(void) {
 @@ -164,126 +159,6 @@ virNetDevVPortProfileGetLldpadPid(void) {
  return pid;
  }
  
 -
 -/**
 - * virNetDevVPortProfileLinkDump:
 - *
 - * @ifname: The name of the interface; only use if ifindex  0
 - * @ifindex: The interface index; may be  0 if ifname is given
 - * @nltarget_kernel: whether to send the message to the kernel or another
 - *   process
 - * @nlattr: pointer to a pointer of netlink attributes that will contain
 - * 

Re: [libvirt] [PATCH 2/4] virtnetdev: Add support functions for mac and portprofile associations on a hostdev

2012-03-05 Thread Roopa Prabhu



On 3/5/12 10:23 AM, Laine Stump la...@laine.org wrote:

 On 03/04/2012 10:15 PM, Roopa Prabhu wrote:
 From: Roopa Prabhu ropra...@cisco.com
 
 This patch adds the following:
 - functions to set and get vf configs
 - Functions to replace and store vf configs (Only mac address is handled
 today.
   But the functions can be easily extended for vlans and other vf configs)
 - function to dump link dev info (This is moved from virnetdevvportprofile.c)
 
 Signed-off-by: Roopa Prabhu ropra...@cisco.com
 ---
  src/util/virnetdev.c |  531
 ++
  src/util/virnetdev.h |   19 ++
  2 files changed, 549 insertions(+), 1 deletions(-)
 
 (BTW, I never thought about doing it this way before, but I'm glad you
 added the function here in a separate patch from the patch that removes
 it from virnetdevvportprofile.c - that makes it easy to open the two
 patches side-by-side and verify that it really is moving the same code
 (well, mostly).)
 
 
 
 diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
 index 9d76d47..25f2155 100644
 --- a/src/util/virnetdev.c
 +++ b/src/util/virnetdev.c
 @@ -1127,8 +1127,497 @@ virNetDevGetPhysicalFunction(const char *ifname, char
 **pfname)
  
  return ret;
  }
 -#else /* !__linux__ */
 
 The functions here that use libnl need to be inside of
 
   #if defined(__linux__)  defined(HAVE_LIBNL)
 
 since there are linux platforms that don't have libnl, or don't have the
 proper LIBNL (RHEL5, in particular, still has libnl-1.0)
 

I was hoping someone will point out what #defines to use here. So thanks. I
will add HAVE_LIBNL. We also need it for IFLA_VF_MAC and VLAN. They were
under HAVE_VIRTPORT before. Can you suggest what I can do here ?
 

  
 +static struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
 +[IFLA_VF_MAC]   = { .type = NLA_UNSPEC,
 +.maxlen = sizeof(struct ifla_vf_mac) },
 +[IFLA_VF_VLAN]  = { .type = NLA_UNSPEC,
 +.maxlen = sizeof(struct ifla_vf_vlan) },
 +};
 +
 +/**
 + * virNetDevLinkDump:
 + *
 + * @ifname: The name of the interface; only use if ifindex  0
 + * @ifindex: The interface index; may be  0 if ifname is given
 + * @nltarget_kernel: whether to send the message to the kernel or another
 + *   process
 + * @nlattr: pointer to a pointer of netlink attributes that will contain
 + *  the results
 + * @recvbuf: Pointer to the buffer holding the returned netlink response
 + *   message; free it, once not needed anymore
 + * @getPidFunc: Pointer to a function that will be invoked if the kernel
 + *  is not the target of the netlink message but it is to be
 + *  sent to another process.
 + *
 + * Get information about an interface given its name or index.
 + *
 + * Returns 0 on success, -1 on fatal error.
 + */
 +int
 +virNetDevLinkDump(const char *ifname, int ifindex,
 +  bool nltarget_kernel, struct nlattr **tb,
 +  unsigned char **recvbuf,
 +  uint32_t (*getPidFunc)(void))
 +{
 +int rc = 0;
 +struct nlmsghdr *resp;
 +struct nlmsgerr *err;
 +struct ifinfomsg ifinfo = {
 +.ifi_family = AF_UNSPEC,
 +.ifi_index  = ifindex
 +};
 +unsigned int recvbuflen;
 +uint32_t pid = 0;
 +struct nl_msg *nl_msg;
 +
 +*recvbuf = NULL;
 +
 +if (ifindex = 0  virNetDevGetIndex(ifname, ifindex)  0)
 +return -1;
 +
 +ifinfo.ifi_index = ifindex;
 +
 +nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
 +if (!nl_msg) {
 +virReportOOMError();
 +return -1;
 +}
 +
 +if (nlmsg_append(nl_msg,  ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO)  0)
 +goto buffer_too_small;
 +
 +if (ifindex  0  ifname) {
 +if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname)  0)
 +goto buffer_too_small;
 +}
 
 
 Is this bit necessary any more? You've added code above that converts
 the ifname into an ifindex, and we've already returned if it wasn't
 successful.
 
 
Ok yes I will remove it. I added the virNetDevGetIndex at the end because
for some reason rhel kernel allowed a ifindex in setlink but not getlink
(And this is a deviation from the upstream kernel). I will fix it.


 +
 +if (!nltarget_kernel) {
 +pid = getPidFunc();
 +if (pid == 0) {
 +rc = -1;
 +goto cleanup;
 +}
 +}
 +
 +if (virNetlinkCommand(nl_msg, recvbuf, recvbuflen, pid)  0) {
 +rc = -1;
 +goto cleanup;
 +}
 +
 +if (recvbuflen  NLMSG_LENGTH(0) || *recvbuf == NULL)
 +goto malformed_resp;
 +
 +resp = (struct nlmsghdr *)*recvbuf;
 +
 +switch (resp-nlmsg_type) {
 +case NLMSG_ERROR:
 +err = (struct nlmsgerr *)NLMSG_DATA(resp);
 +if (resp-nlmsg_len  NLMSG_LENGTH(sizeof(*err)))
 +goto malformed_resp;
 +
 +if (err-error) {
 +

Re: [libvirt] [PATCH] util: fail attempts to use same mac address for guest and tap

2012-03-05 Thread Laine Stump
On 03/05/2012 11:14 AM, Eric Blake wrote:
 On 03/05/2012 09:05 AM, Laine Stump wrote:
 This patch is in response to:

   https://bugzilla.redhat.com/show_bug.cgi?id=798467

 If a guest's tap device is created using the same MAC address the
 guest uses for its own network card (which connects to the tap
 device), the Linux kernel will log the following message and traffic
 will not pass:

  kernel: vnet9: received packet with own address as source address

 This patch disallows MAC addresses with a first byte of 0xFE, but only in
 the case that the MAC address is used for a guest interface that's
 connected by way of a standard tap device. (In other words, the
 validation is done at runtime at the same place the MAC address is
 modified for the tap device, rather than when mac address is parsed,
 the idea being that it is then we know for sure the address will be
 problematic.)
 ---
  src/util/virnetdevtap.c |   22 --
  1 files changed, 20 insertions(+), 2 deletions(-)
 ACK.

Thanks. I recieved the additional info that this was discovered not by
someone manually setting the mac address to fe:xx:xx:xx:xx:xx in some
ill-informed attempt to match what they saw in the tap device's ifconfig
output, but because a management application automatically chose an
address that started with 0xFE. I'm waiting to push until I hear back
whether or not that management application can be configured to *not* do
that.


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/4] virtnetdev: Add support functions for mac and portprofile associations on a hostdev

2012-03-05 Thread Roopa Prabhu



On 3/5/12 11:50 AM, Roopa Prabhu ropra...@cisco.com wrote:

 
 
 
 On 3/5/12 10:23 AM, Laine Stump la...@laine.org wrote:
 
 On 03/04/2012 10:15 PM, Roopa Prabhu wrote:
 From: Roopa Prabhu ropra...@cisco.com
 
 This patch adds the following:
 - functions to set and get vf configs
 - Functions to replace and store vf configs (Only mac address is handled
 today.
   But the functions can be easily extended for vlans and other vf configs)
 - function to dump link dev info (This is moved from
 virnetdevvportprofile.c)
 
 Signed-off-by: Roopa Prabhu ropra...@cisco.com
 ---
  src/util/virnetdev.c |  531
 ++
  src/util/virnetdev.h |   19 ++
  2 files changed, 549 insertions(+), 1 deletions(-)
 
 (BTW, I never thought about doing it this way before, but I'm glad you
 added the function here in a separate patch from the patch that removes
 it from virnetdevvportprofile.c - that makes it easy to open the two
 patches side-by-side and verify that it really is moving the same code
 (well, mostly).)
 
 
 
 diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
 index 9d76d47..25f2155 100644
 --- a/src/util/virnetdev.c
 +++ b/src/util/virnetdev.c
 @@ -1127,8 +1127,497 @@ virNetDevGetPhysicalFunction(const char *ifname,
 char
 **pfname)
  
  return ret;
  }
 -#else /* !__linux__ */
 
 The functions here that use libnl need to be inside of
 
   #if defined(__linux__)  defined(HAVE_LIBNL)
 
 since there are linux platforms that don't have libnl, or don't have the
 proper LIBNL (RHEL5, in particular, still has libnl-1.0)
 
 
 I was hoping someone will point out what #defines to use here. So thanks. I
 will add HAVE_LIBNL. We also need it for IFLA_VF_MAC and VLAN. They were
 under HAVE_VIRTPORT before. Can you suggest what I can do here ?
  
 
Correction: They were under WITH_VIRUALPORT (which has a configure option
and a check for IFLA_VF_PORT_MAX).

We will need a check for IFLA_VF_MAX here.

I think I will try putting this under defined(IFLA_VF_MAX). This should
cover IFLA_VF_MAC and IFLA_VF_VLAN I think. If you have any other
suggestions let me know.

Thanks,
Roopa


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/4] virtnetdev: Add support functions for mac and portprofile associations on a hostdev

2012-03-05 Thread Laine Stump
On 03/05/2012 02:50 PM, Roopa Prabhu wrote:


 On 3/5/12 10:23 AM, Laine Stump la...@laine.org wrote:

 On 03/04/2012 10:15 PM, Roopa Prabhu wrote:
 From: Roopa Prabhu ropra...@cisco.com

 This patch adds the following:
 - functions to set and get vf configs
 - Functions to replace and store vf configs (Only mac address is handled
 today.
   But the functions can be easily extended for vlans and other vf configs)
 - function to dump link dev info (This is moved from 
 virnetdevvportprofile.c)

 Signed-off-by: Roopa Prabhu ropra...@cisco.com
 ---
  src/util/virnetdev.c |  531
 ++
  src/util/virnetdev.h |   19 ++
  2 files changed, 549 insertions(+), 1 deletions(-)
 (BTW, I never thought about doing it this way before, but I'm glad you
 added the function here in a separate patch from the patch that removes
 it from virnetdevvportprofile.c - that makes it easy to open the two
 patches side-by-side and verify that it really is moving the same code
 (well, mostly).)


 diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
 index 9d76d47..25f2155 100644
 --- a/src/util/virnetdev.c
 +++ b/src/util/virnetdev.c
 @@ -1127,8 +1127,497 @@ virNetDevGetPhysicalFunction(const char *ifname, 
 char
 **pfname)
  
  return ret;
  }
 -#else /* !__linux__ */
 The functions here that use libnl need to be inside of

   #if defined(__linux__)  defined(HAVE_LIBNL)

 since there are linux platforms that don't have libnl, or don't have the
 proper LIBNL (RHEL5, in particular, still has libnl-1.0)

 I was hoping someone will point out what #defines to use here. So thanks. I
 will add HAVE_LIBNL. We also need it for IFLA_VF_MAC and VLAN. They were
 under HAVE_VIRTPORT before. Can you suggest what I can do here ?

I would put it inside HAVE_LIBNL, because that's the library you need to
compile it.

  

  
 +static struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
 +[IFLA_VF_MAC]   = { .type = NLA_UNSPEC,
 +.maxlen = sizeof(struct ifla_vf_mac) },
 +[IFLA_VF_VLAN]  = { .type = NLA_UNSPEC,
 +.maxlen = sizeof(struct ifla_vf_vlan) },
 +};
 +
 +/**
 + * virNetDevLinkDump:
 + *
 + * @ifname: The name of the interface; only use if ifindex  0
 + * @ifindex: The interface index; may be  0 if ifname is given
 + * @nltarget_kernel: whether to send the message to the kernel or another
 + *   process
 + * @nlattr: pointer to a pointer of netlink attributes that will contain
 + *  the results
 + * @recvbuf: Pointer to the buffer holding the returned netlink response
 + *   message; free it, once not needed anymore
 + * @getPidFunc: Pointer to a function that will be invoked if the kernel
 + *  is not the target of the netlink message but it is to be
 + *  sent to another process.
 + *
 + * Get information about an interface given its name or index.
 + *
 + * Returns 0 on success, -1 on fatal error.
 + */
 +int
 +virNetDevLinkDump(const char *ifname, int ifindex,
 +  bool nltarget_kernel, struct nlattr **tb,
 +  unsigned char **recvbuf,
 +  uint32_t (*getPidFunc)(void))
 +{
 +int rc = 0;
 +struct nlmsghdr *resp;
 +struct nlmsgerr *err;
 +struct ifinfomsg ifinfo = {
 +.ifi_family = AF_UNSPEC,
 +.ifi_index  = ifindex
 +};
 +unsigned int recvbuflen;
 +uint32_t pid = 0;
 +struct nl_msg *nl_msg;
 +
 +*recvbuf = NULL;
 +
 +if (ifindex = 0  virNetDevGetIndex(ifname, ifindex)  0)
 +return -1;
 +
 +ifinfo.ifi_index = ifindex;
 +
 +nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
 +if (!nl_msg) {
 +virReportOOMError();
 +return -1;
 +}
 +
 +if (nlmsg_append(nl_msg,  ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO)  0)
 +goto buffer_too_small;
 +
 +if (ifindex  0  ifname) {
 +if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname)  0)
 +goto buffer_too_small;
 +}

 Is this bit necessary any more? You've added code above that converts
 the ifname into an ifindex, and we've already returned if it wasn't
 successful.


 Ok yes I will remove it. I added the virNetDevGetIndex at the end because
 for some reason rhel kernel allowed a ifindex in setlink but not getlink
 (And this is a deviation from the upstream kernel). I will fix it.


 +
 +if (!nltarget_kernel) {
 +pid = getPidFunc();
 +if (pid == 0) {
 +rc = -1;
 +goto cleanup;
 +}
 +}
 +
 +if (virNetlinkCommand(nl_msg, recvbuf, recvbuflen, pid)  0) {
 +rc = -1;
 +goto cleanup;
 +}
 +
 +if (recvbuflen  NLMSG_LENGTH(0) || *recvbuf == NULL)
 +goto malformed_resp;
 +
 +resp = (struct nlmsghdr *)*recvbuf;
 +
 +switch (resp-nlmsg_type) {
 +case NLMSG_ERROR:
 +err = (struct nlmsgerr *)NLMSG_DATA(resp);
 +if (resp-nlmsg_len  

Re: [libvirt] [PATCH] Fix build after commit e3ba4025

2012-03-05 Thread Jim Fehlig
Eric Blake wrote:
 On 03/05/2012 12:17 PM, Jim Fehlig wrote:
   

 +++ b/src/util/virnetlink.h
 @@ -55,7 +55,7 @@ int virNetlinkEventServiceStart(void);
  /**
   * virNetlinkEventServiceIsRunning: returns if the netlink event service is 
 running.
   */
 -bool virNetlinkEventServiceIsRunning(void);
 +int virNetlinkEventServiceIsRunning(void);
 

 But this hunk looks wrong.
   

Yes, it is wrong.  I changed the definition in virnetlink.c, as it
should have been, and pushed the result.

Thanks,
Jim

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 12/17] qemu: refactor hotplug detach of hostdevs

2012-03-05 Thread Michal Privoznik
On 28.02.2012 21:14, Laine Stump wrote:
 This refactoring is necessary to support hotplug detach of
 type=hostdev network devices, but needs to be in a separate patch to
 make potential debugging of regressions more practical.
 
 Rather than the lowest level functions searching for a matching
 device, the search is now done in the toplevel function, and an
 intermediate-level function (qemuDomainDetachThisHostDevice()), which
 expects that the device's entry is already found, is called (this
 intermediate function will be called by qemuDomainDetachNetDevice() in
 order to support detach of type=hostdev net devices)
 
 This patch should result in 0 differences in functionality.
 ---
 New patch for V2.
 
  src/qemu/qemu_hotplug.c |  228 
 +++
  1 files changed, 93 insertions(+), 135 deletions(-)

Nice cleanup. I wish we have more like these :)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 14/17] qemu: support type='hostdev' network devices at domain start

2012-03-05 Thread Michal Privoznik
On 28.02.2012 21:14, Laine Stump wrote:
 This patch makes sure that each network device (interface) of
 type='hostdev' appears on both the hostdevs list and the nets list of
 the virDomainDef, and it modifies the qemu driver startup code so that
 these devices will be presented to qemu on the commandline as hostdevs
 rather than as network devices.
 
 It does not add support for hotplug of these type of devices, or code
 to honor the mac address or virtualport given in the config (both
 of those will be done in separate patches).
 
 Once each device is placed on both lists, much of what this patch does
 is modify places in the code that traverse all the device lists so
 that these hybrid devices are only acted on once - either along with
 the other hostdevs, or along with the other interfaces. (In many
 cases, only one of the lists is traversed / a specific operation is
 performed on only one type of device. In those instances, the code can
 remain unchanged.)
 
 There is one special case - when building the commandline, interfaces
 are allowed to proceed all the way through
 networkAllocateActualDevice() before deciding to skip - this is so
 that (once we have support for networks with pools of hostdev devices)
 we can get the actual device allocated, then rely on the loop
 processing all hostdevs to generate the correct commandline.
 ---
 New patch in V2.
 
  src/conf/domain_conf.c |   54 
 +---
  src/qemu/qemu_command.c|   36 --
  .../qemuxml2argvdata/qemuxml2argv-net-hostdev.args |7 +++
  .../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml  |7 ---
  tests/qemuxml2argvtest.c   |2 +
  5 files changed, 88 insertions(+), 18 deletions(-)
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.args
 

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 15/17] conf: change virDomainNetRemove from static to global

2012-03-05 Thread Michal Privoznik
On 28.02.2012 21:14, Laine Stump wrote:
 This exact code is duplicated in qemuDomainDetachNetDevice().
 ---
 New patch in V2.
 
 (yeah, I just noticed the movement of the virDomainHostdevXX()
 declarations in this patch; I guess I was rearranging for consistent
 ordering. If this concerns anyone, I can squash it out before I push.)
 
  src/conf/domain_conf.c   |2 +-
  src/conf/domain_conf.h   |5 +++--
  src/libvirt_private.syms |1 +
  3 files changed, 5 insertions(+), 3 deletions(-)
 
 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
 index 7135024..b994718 100644
 --- a/src/conf/domain_conf.c
 +++ b/src/conf/domain_conf.c
 @@ -7084,7 +7084,7 @@ int virDomainNetIndexByMac(virDomainDefPtr def, const 
 unsigned char *mac)
  return -1;
  }
  
 -static void virDomainNetRemove(virDomainDefPtr def, size_t i)
 +void virDomainNetRemove(virDomainDefPtr def, size_t i)
  {
  virDomainNetDefPtr net = def-nets[i];
  
 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
 index 6ab5f32..a9426b3 100644
 --- a/src/conf/domain_conf.h
 +++ b/src/conf/domain_conf.h
 @@ -1902,12 +1902,13 @@ int virDomainDiskRemoveByName(virDomainDefPtr def, 
 const char *name);
  
  int virDomainNetIndexByMac(virDomainDefPtr def, const unsigned char *mac);
  int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net);
 +void virDomainNetRemove(virDomainDefPtr def, size_t i);
  int virDomainNetRemoveByMac(virDomainDefPtr def, const unsigned char *mac);
  
 -int virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr 
 hostdev);
 -void virDomainHostdevRemove(virDomainDefPtr def, size_t i);
  int virDomainHostdevFind(virDomainDefPtr def, virDomainHostdevDefPtr match,
   virDomainHostdevDefPtr *found);
 +int virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr 
 hostdev);
 +void virDomainHostdevRemove(virDomainDefPtr def, size_t i);

Maybe my brain is too small for this, but this looks useless to me.
However, not a show stopper.

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 13/17] conf: parse/format type='hostdev' network interfaces

2012-03-05 Thread Michal Privoznik
On 28.02.2012 21:14, Laine Stump wrote:
 This is the new interface type that sets up a PCI/USB network device
 to be assigned to the guest with PCI/USB passthrough after
 initializing some network device-specific things from the config
 (e.g. MAC address, virtualport profile parameters). Here is an example
 of the syntax:
 
   interface type='hostdev' managed='yes'
 source
   address type='pci' domain='0' bus='0' slot='4' function='0'/
 /source
 mac address='00:11:22:33:44:55'/
 address type='pci' domain='0' bus='0' slot='7' function='0'/
   /interface
 
 This would assign the PCI card from bus 0 slot 4 function 0 on the
 host, to bus 0 slot 7 function 0 on the guest, but would first set the
 MAC address of the card to 00:11:22:33:44:55.
 
 Although it's not expected to be used very much, usb network hostdevs
 are also supported for completeness. source syntax is identical to
 that for plain hostdev devices, except that the address element
 should have type='usb' added if it's specified:
 
   interface type='hostdev'
 source
   address type='usb' bus='0' device='4'/
 /source
 mac address='00:11:22:33:44:55'/
   /interface
 
 If the vendor/product form of usb specification is used, type='usb'
 is implied:
 
   interface type='hostdev'
 source
   vendor id='0x0012'/
   product id='0x24dd'/
 /source
 mac address='00:11:22:33:44:55'/
   /interface
 ---
 V2: address Eric's concerns from V1
  - check for OOM after strdup
  - put in a NOP virDomainHostdevDefClear() rather than just commenting
there is nothing in the HostdevDef that needs to be freed
  - eliminate inconsistent {} usage.
 
  docs/formatdomain.html.in  |   41 +
  docs/schemas/domaincommon.rng  |   50 +++
  src/conf/domain_conf.c |  154 
 ++--
  src/conf/domain_conf.h |   10 ++
  src/libvirt_private.syms   |1 +
  src/qemu/qemu_command.c|1 +
  src/uml/uml_conf.c |5 +
  src/xenxs/xen_sxpr.c   |1 +
  .../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml  |   48 ++
  tests/qemuxml2xmltest.c|1 +
  10 files changed, 297 insertions(+), 15 deletions(-)
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml
 

 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml 
 b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml
 new file mode 100644
 index 000..504e4f6
 --- /dev/null
 +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml
 @@ -0,0 +1,48 @@
 +domain type='qemu'
 +  nameQEMUGuest1/name
 +  uuidc7a5fdbd-edaf-9455-926a-d65c16db1809/uuid
 +  memory219136/memory
 +  currentMemory219136/currentMemory
 +  vcpu1/vcpu
 +  os
 +type arch='i686' machine='pc'hvm/type
 +boot dev='hd'/
 +  /os
 +  clock offset='utc'/
 +  on_poweroffdestroy/on_poweroff
 +  on_rebootrestart/on_reboot
 +  on_crashdestroy/on_crash
 +  devices
 +emulator/usr/bin/qemu/emulator
 +disk type='block' device='disk'
 +  source dev='/dev/HostVG/QEMUGuest1'/
 +  target dev='hda' bus='ide'/
 +  address type='drive' controller='0' bus='0' target='0' unit='0'/
 +/disk
 +controller type='usb' index='0'/
 +controller type='ide' index='0'/
 +interface type='hostdev' managed='yes'
 +  mac address='00:11:22:33:44:55'/
 +  source
 +address type='pci' domain='0x0002' bus='0x03' slot='0x07' 
 function='0x1'/
 +  /source
 +  virtualport type='802.1Qbg'
 +parameters managerid='11' typeid='1193047' typeidversion='2' 
 instanceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/
 +  /virtualport
 +/interface
 +interface type='hostdev'
 +  mac address='11:11:22:33:44:55'/
 +  source
 +address type='usb' bus='0' device='2'/
 +  /source
 +/interface
 +interface type='hostdev'
 +  mac address='22:11:22:33:44:55'/
 +  source
 +vendor id='0x0012'/
 +product id='0x24dd'/
 +  /source
 +/interface

This looks odd to me; I mean why add this interface here but remove it
in the very next patch? Maybe to prove/test that parsing and formatting
works correctly even for this case.

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 16/17] qemu: use virDomainNetRemove instead of inline code

2012-03-05 Thread Michal Privoznik
On 28.02.2012 21:14, Laine Stump wrote:
 The code being replaced is exactly identical to the newly global
 function, right down to the comment.
 ---
 New patch in V2
 
  src/qemu/qemu_hotplug.c |   14 +-
  1 files changed, 1 insertions(+), 13 deletions(-)
 

ACK definitely.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 17/17] qemu: support type=hostdev network device hotplug attach/detach

2012-03-05 Thread Michal Privoznik
On 28.02.2012 21:14, Laine Stump wrote:
 qemuDomainAttachNetDevice
 
   - re-ordered some things at start of function because
 networkAllocateActualDevice should always be run and a slot
 in def-nets always allocated, but host_net_add isn't needed
 if the actual type is hostdev.
 
   - if actual type is hostdev, defer to
 qemuDomainAttachHostDevice (which will reach up to the NetDef
 for things like MAC address when necessary). After return
 from qemuDomainAttachHostDevice, slip directly to cleanup,
 since the rest of the function is specific to emulated net
 devices.
 
   - put assignment of new NetDef into expanded def-nets down
 below cleanup: (but only on success) since it is also needed
 for emulated and hostdev net devices.
 
 qemuDomainDetachHostDevice
 
   - after locating the exact device to detach, check if it's a
 network device and, if so, use toplevel
 qemuDomainDetachNetDevice instead so that the def-nets list
 is properly updated, and 'actual device' properly returned to
 network pool if appropriate. Otherwise, for normal hostdevs,
 call the lower level qemuDomainDetachThisDevice.
 
 qemuDomainDetachNetDevice
 
   - This is where it gets a bit tricky. After locating the device
 on the def-nets list, if the network device type == hostdev,
 call the *lower level* qemuDomainDetachThisDevice (which will
 reach back up to the parent net device for MAC address /
 virtualport when appropriate, then clear the device out of
 def-hostdevs) before skipping past all the emulated
 net-device-specific code to cleanup:, where the network
 device is removed from def-nets, and the network device
 object is freed.
 
 In short, any time a hostdev-type network device is detached, we must
 go through the toplevel virDomaineDetachNetDevice function first and
 last, to make sure 1) the def-nnets list is properly managed, and 2)
 any device allocated with networkAllocateActualDevice is properly
 freed. At the same time, in the middle we need to go through the
 lower-level virDomainDetach*This*HostDevice to be sure that 1) the
 def-hostdevs list is properly managed, 2) the PCI device is properly
 detached from the guest and reattached to the host (if appropriate),
 and 3) any higher level setup/teardown is called at the appropriate
 time, by reaching back up to the NetDef config (part (3) will be
 covered in a separate patch).
 
 ---
  src/qemu/qemu_hotplug.c |   61 +-
  1 files changed, 44 insertions(+), 17 deletions(-)
 
 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
 index 6119108..50563c5 100644
 --- a/src/qemu/qemu_hotplug.c
 +++ b/src/qemu/qemu_hotplug.c
 @@ -661,9 +661,9 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
  bool iface_connected = false;
  int actualType;
  
 -if (!qemuCapsGet(priv-qemuCaps, QEMU_CAPS_HOST_NET_ADD)) {
 -qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
 -_(installed qemu version does not support 
 host_net_add));
 +/* preallocate new slot for device */
 +if (VIR_REALLOC_N(vm-def-nets, vm-def-nnets+1)  0) {
 +virReportOOMError();
  return -1;
  }
  
 @@ -672,9 +672,27 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
   * to the one defined in the network definition.
   */
  if (networkAllocateActualDevice(net)  0)
 -goto cleanup;
 +return -1;

Okay, vm-def-nets won't leak, but will be one item bigger; Do we want
to realloc it back as we do in all detach functions, e.g.
virDomainNetRemove() ? The vm-def-nnets counter isn't changed yet so I
guess this is alright.

Anyway, looking good so ACK.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 15/17] conf: change virDomainNetRemove from static to global

2012-03-05 Thread Laine Stump
On 03/05/2012 03:45 PM, Michal Privoznik wrote:
 On 28.02.2012 21:14, Laine Stump wrote:
 This exact code is duplicated in qemuDomainDetachNetDevice().
 ---
 New patch in V2.

 (yeah, I just noticed the movement of the virDomainHostdevXX()
 declarations in this patch; I guess I was rearranging for consistent
 ordering. If this concerns anyone, I can squash it out before I push.)

  src/conf/domain_conf.c   |2 +-
  src/conf/domain_conf.h   |5 +++--
  src/libvirt_private.syms |1 +
  3 files changed, 5 insertions(+), 3 deletions(-)

 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
 index 7135024..b994718 100644
 --- a/src/conf/domain_conf.c
 +++ b/src/conf/domain_conf.c
 @@ -7084,7 +7084,7 @@ int virDomainNetIndexByMac(virDomainDefPtr def, const 
 unsigned char *mac)
  return -1;
  }
  
 -static void virDomainNetRemove(virDomainDefPtr def, size_t i)
 +void virDomainNetRemove(virDomainDefPtr def, size_t i)
  {
  virDomainNetDefPtr net = def-nets[i];
  
 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
 index 6ab5f32..a9426b3 100644
 --- a/src/conf/domain_conf.h
 +++ b/src/conf/domain_conf.h
 @@ -1902,12 +1902,13 @@ int virDomainDiskRemoveByName(virDomainDefPtr def, 
 const char *name);
  
  int virDomainNetIndexByMac(virDomainDefPtr def, const unsigned char *mac);
  int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net);
 +void virDomainNetRemove(virDomainDefPtr def, size_t i);
  int virDomainNetRemoveByMac(virDomainDefPtr def, const unsigned char *mac);
  
 -int virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr 
 hostdev);
 -void virDomainHostdevRemove(virDomainDefPtr def, size_t i);
  int virDomainHostdevFind(virDomainDefPtr def, virDomainHostdevDefPtr match,
   virDomainHostdevDefPtr *found);
 +int virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr 
 hostdev);
 +void virDomainHostdevRemove(virDomainDefPtr def, size_t i);
 Maybe my brain is too small for this, but this looks useless to me.
 However, not a show stopper.

Just changes one function from a static to global. The other extra lines
at the end are re-ordering of existing function prototypes that got into
the patch by accident.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 13/17] conf: parse/format type='hostdev' network interfaces

2012-03-05 Thread Laine Stump
On 03/05/2012 03:45 PM, Michal Privoznik wrote:
 On 28.02.2012 21:14, Laine Stump wrote:
 This is the new interface type that sets up a PCI/USB network device
 to be assigned to the guest with PCI/USB passthrough after
 initializing some network device-specific things from the config
 (e.g. MAC address, virtualport profile parameters). Here is an example
 of the syntax:

   interface type='hostdev' managed='yes'
 source
   address type='pci' domain='0' bus='0' slot='4' function='0'/
 /source
 mac address='00:11:22:33:44:55'/
 address type='pci' domain='0' bus='0' slot='7' function='0'/
   /interface

 This would assign the PCI card from bus 0 slot 4 function 0 on the
 host, to bus 0 slot 7 function 0 on the guest, but would first set the
 MAC address of the card to 00:11:22:33:44:55.

 Although it's not expected to be used very much, usb network hostdevs
 are also supported for completeness. source syntax is identical to
 that for plain hostdev devices, except that the address element
 should have type='usb' added if it's specified:

   interface type='hostdev'
 source
   address type='usb' bus='0' device='4'/
 /source
 mac address='00:11:22:33:44:55'/
   /interface

 If the vendor/product form of usb specification is used, type='usb'
 is implied:

   interface type='hostdev'
 source
   vendor id='0x0012'/
   product id='0x24dd'/
 /source
 mac address='00:11:22:33:44:55'/
   /interface
 ---
 V2: address Eric's concerns from V1
  - check for OOM after strdup
  - put in a NOP virDomainHostdevDefClear() rather than just commenting
there is nothing in the HostdevDef that needs to be freed
  - eliminate inconsistent {} usage.

  docs/formatdomain.html.in  |   41 +
  docs/schemas/domaincommon.rng  |   50 +++
  src/conf/domain_conf.c |  154 
 ++--
  src/conf/domain_conf.h |   10 ++
  src/libvirt_private.syms   |1 +
  src/qemu/qemu_command.c|1 +
  src/uml/uml_conf.c |5 +
  src/xenxs/xen_sxpr.c   |1 +
  .../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml  |   48 ++
  tests/qemuxml2xmltest.c|1 +
  10 files changed, 297 insertions(+), 15 deletions(-)
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml

 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml 
 b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml
 new file mode 100644
 index 000..504e4f6
 --- /dev/null
 +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-hostdev.xml
 @@ -0,0 +1,48 @@
 +domain type='qemu'
 +  nameQEMUGuest1/name
 +  uuidc7a5fdbd-edaf-9455-926a-d65c16db1809/uuid
 +  memory219136/memory
 +  currentMemory219136/currentMemory
 +  vcpu1/vcpu
 +  os
 +type arch='i686' machine='pc'hvm/type
 +boot dev='hd'/
 +  /os
 +  clock offset='utc'/
 +  on_poweroffdestroy/on_poweroff
 +  on_rebootrestart/on_reboot
 +  on_crashdestroy/on_crash
 +  devices
 +emulator/usr/bin/qemu/emulator
 +disk type='block' device='disk'
 +  source dev='/dev/HostVG/QEMUGuest1'/
 +  target dev='hda' bus='ide'/
 +  address type='drive' controller='0' bus='0' target='0' unit='0'/
 +/disk
 +controller type='usb' index='0'/
 +controller type='ide' index='0'/
 +interface type='hostdev' managed='yes'
 +  mac address='00:11:22:33:44:55'/
 +  source
 +address type='pci' domain='0x0002' bus='0x03' slot='0x07' 
 function='0x1'/
 +  /source
 +  virtualport type='802.1Qbg'
 +parameters managerid='11' typeid='1193047' typeidversion='2' 
 instanceid='09b11c53-8b5c-4eeb-8f00-d84eaa0aaa4f'/
 +  /virtualport
 +/interface
 +interface type='hostdev'
 +  mac address='11:11:22:33:44:55'/
 +  source
 +address type='usb' bus='0' device='2'/
 +  /source
 +/interface
 +interface type='hostdev'
 +  mac address='22:11:22:33:44:55'/
 +  source
 +vendor id='0x0012'/
 +product id='0x24dd'/
 +  /source
 +/interface
 This looks odd to me; I mean why add this interface here but remove it
 in the very next patch? Maybe to prove/test that parsing and formatting
 works correctly even for this case.

I put that case in when the test case only tested the parser and
formatter, but then when I added the code to handle commandline
generation in the next patch (along with extending the test case to test
that as well) the new test began to fail. This was because it's
impossible to test the vendor/product id format of address specification
without having an actual device on the bus to compare against, and
qemusml2argvtest can't do that, so I had to remove it.

I actually thought that I'd squashed the removal back into the same test
where I'd added it, which is what I'll do before pushing. (It's

Re: [libvirt] [PATCH 17/17] qemu: support type=hostdev network device hotplug attach/detach

2012-03-05 Thread Laine Stump
On 03/05/2012 03:46 PM, Michal Privoznik wrote:
 On 28.02.2012 21:14, Laine Stump wrote:
 qemuDomainAttachNetDevice

   - re-ordered some things at start of function because
 networkAllocateActualDevice should always be run and a slot
 in def-nets always allocated, but host_net_add isn't needed
 if the actual type is hostdev.

   - if actual type is hostdev, defer to
 qemuDomainAttachHostDevice (which will reach up to the NetDef
 for things like MAC address when necessary). After return
 from qemuDomainAttachHostDevice, slip directly to cleanup,
 since the rest of the function is specific to emulated net
 devices.

   - put assignment of new NetDef into expanded def-nets down
 below cleanup: (but only on success) since it is also needed
 for emulated and hostdev net devices.

 qemuDomainDetachHostDevice

   - after locating the exact device to detach, check if it's a
 network device and, if so, use toplevel
 qemuDomainDetachNetDevice instead so that the def-nets list
 is properly updated, and 'actual device' properly returned to
 network pool if appropriate. Otherwise, for normal hostdevs,
 call the lower level qemuDomainDetachThisDevice.

 qemuDomainDetachNetDevice

   - This is where it gets a bit tricky. After locating the device
 on the def-nets list, if the network device type == hostdev,
 call the *lower level* qemuDomainDetachThisDevice (which will
 reach back up to the parent net device for MAC address /
 virtualport when appropriate, then clear the device out of
 def-hostdevs) before skipping past all the emulated
 net-device-specific code to cleanup:, where the network
 device is removed from def-nets, and the network device
 object is freed.

 In short, any time a hostdev-type network device is detached, we must
 go through the toplevel virDomaineDetachNetDevice function first and
 last, to make sure 1) the def-nnets list is properly managed, and 2)
 any device allocated with networkAllocateActualDevice is properly
 freed. At the same time, in the middle we need to go through the
 lower-level virDomainDetach*This*HostDevice to be sure that 1) the
 def-hostdevs list is properly managed, 2) the PCI device is properly
 detached from the guest and reattached to the host (if appropriate),
 and 3) any higher level setup/teardown is called at the appropriate
 time, by reaching back up to the NetDef config (part (3) will be
 covered in a separate patch).

 ---
  src/qemu/qemu_hotplug.c |   61 
 +-
  1 files changed, 44 insertions(+), 17 deletions(-)

 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
 index 6119108..50563c5 100644
 --- a/src/qemu/qemu_hotplug.c
 +++ b/src/qemu/qemu_hotplug.c
 @@ -661,9 +661,9 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
  bool iface_connected = false;
  int actualType;
  
 -if (!qemuCapsGet(priv-qemuCaps, QEMU_CAPS_HOST_NET_ADD)) {
 -qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
 -_(installed qemu version does not support 
 host_net_add));
 +/* preallocate new slot for device */
 +if (VIR_REALLOC_N(vm-def-nets, vm-def-nnets+1)  0) {
 +virReportOOMError();
  return -1;
  }
  
 @@ -672,9 +672,27 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
   * to the one defined in the network definition.
   */
  if (networkAllocateActualDevice(net)  0)
 -goto cleanup;
 +return -1;
 Okay, vm-def-nets won't leak, but will be one item bigger; Do we want
 to realloc it back as we do in all detach functions, e.g.
 virDomainNetRemove() ? The vm-def-nnets counter isn't changed yet so I
 guess this is alright.

I wondered about this too, but am just copying existing behavior which,
as you say, is relying on the fact that there's no leak, the item is
just one longer (and that one extra in length will be used up the next
time someone wants to grow the array).


 Anyway, looking good so ACK.


Thanks to you and to Eric for all the reviews!

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 09/15] xml: use better types for memory values

2012-03-05 Thread Eric Blake
Using 'unsigned long' for memory values is risky on 32-bit platforms,
as a PAE guest can have more than 4GiB memory.  Our API is
(unfortunately) locked at 'unsigned long' and a scale of 1024, but
the rest of our system should consistently use 64-bit values,
especially since the previous patch centralized overflow checking.

* src/conf/domain_conf.h (_virDomainDef): Always use 64-bit values
for memory.  Change hugepage_backed to a bool.
* src/conf/domain_conf.c (virDomainDefParseXML)
(virDomainDefCheckABIStability, virDomainDefFormatInternal): Fix
clients.
* src/vmx/vmx.c (virVMXFormatConfig): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxpr, xenFormatSxpr): Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetULongLong): New function.
(xenXMConfigGetULong, xenXMConfigSetInt): Avoid truncation.
(xenParseXM, xenFormatXM): Fix clients.
* src/phyp/phyp_driver.c (phypBuildLpar): Likewise.
* src/openvz/openvz_driver.c (openvzDomainSetMemoryInternal):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDefineXML): Likewise.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
* src/qemu/qemu_process.c (qemuProcessStart): Likewise.
* src/qemu/qemu_monitor.h (qemuMonitorGetBalloonInfo): Likewise.
* src/qemu/qemu_monitor_text.h (qemuMonitorTextGetBalloonInfo):
Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetBalloonInfo):
Likewise.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONGetBalloonInfo):
Likewise.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONGetBalloonInfo):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainGetInfo)
(qemuDomainGetXMLDesc): Likewise.
* src/uml/uml_conf.c (umlBuildCommandLine): Likewise.
---

v2: new

 src/conf/domain_audit.c  |2 +-
 src/conf/domain_conf.c   |   46 
 src/conf/domain_conf.h   |   14 +-
 src/openvz/openvz_driver.c   |8 +++---
 src/phyp/phyp_driver.c   |   10 +++---
 src/qemu/qemu_command.c  |2 +-
 src/qemu/qemu_driver.c   |4 +-
 src/qemu/qemu_monitor.c  |2 +-
 src/qemu/qemu_monitor.h  |2 +-
 src/qemu/qemu_monitor_json.c |2 +-
 src/qemu/qemu_monitor_json.h |2 +-
 src/qemu/qemu_monitor_text.c |2 +-
 src/qemu/qemu_monitor_text.h |2 +-
 src/qemu/qemu_process.c  |6 
 src/uml/uml_conf.c   |2 +-
 src/vbox/vbox_tmpl.c |4 +-
 src/vmx/vmx.c|   10 +++---
 src/xenxs/xen_sxpr.c |8 ++---
 src/xenxs/xen_xm.c   |   58 +++--
 19 files changed, 115 insertions(+), 71 deletions(-)

diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 934e546..b885906 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -1,7 +1,7 @@
 /*
  * domain_audit.c: Domain audit management
  *
- * Copyright (C) 2006-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 41d0eca..fa44d3e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7292,27 +7292,27 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
 goto error;

 /* Extract domain memory */
-if (virXPathULong(string(./memory[1]), ctxt,
-  def-mem.max_balloon)  0) {
+if (virXPathULongLong(string(./memory[1]), ctxt,
+  def-mem.max_balloon)  0) {
 virDomainReportError(VIR_ERR_INTERNAL_ERROR,
  %s, _(missing memory element));
 goto error;
 }

-if (virXPathULong(string(./currentMemory[1]), ctxt,
-  def-mem.cur_balloon)  0)
+if (virXPathULongLong(string(./currentMemory[1]), ctxt,
+  def-mem.cur_balloon)  0)
 def-mem.cur_balloon = def-mem.max_balloon;

 if (def-mem.cur_balloon  def-mem.max_balloon) {
 virDomainReportError(VIR_ERR_INTERNAL_ERROR,
- _(current memory '%luk' exceeds maximum '%luk'),
+ _(current memory '%lluk' exceeds maximum 
'%lluk'),
  def-mem.cur_balloon, def-mem.max_balloon);
 goto error;
 }

 node = virXPathNode(./memoryBacking/hugepages, ctxt);
 if (node)
-def-mem.hugepage_backed = 1;
+def-mem.hugepage_backed = true;

 /* Extract blkio cgroup tunables */
 if (virXPathUInt(string(./blkiotune/weight), ctxt,
@@ -7346,20 +7346,20 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
 VIR_FREE(nodes);

 /* Extract other memory tunables */
-if (virXPathULong(string(./memtune/hard_limit), ctxt,
-  def-mem.hard_limit)  0)
+if (virXPathULongLong(string(./memtune/hard_limit), ctxt,
+  def-mem.hard_limit)  0)
 def-mem.hard_limit = 0;

-if (virXPathULong(string(./memtune/soft_limit[1]), ctxt,
-  

[libvirt] [PATCHv2 03/15] util: new function for scaling numbers

2012-03-05 Thread Eric Blake
Scaling an integer based on a suffix is something we plan on reusing
in several contexts: XML parsing, virsh CLI parsing, and possibly
elsewhere.  Make it easy to reuse, as well as adding in support for
powers of 1000.

* src/util/util.h (virScaleInteger): New function.
* src/util/util.c (virScaleInteger): Implement it.
* src/libvirt_private.syms (util.h): Export it.
---

v2: new, but borrows ideas from memory v1 3/3

 src/libvirt_private.syms |1 +
 src/util/util.c  |   66 ++
 src/util/util.h  |4 +++
 3 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a104e70..a6d053b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1121,6 +1121,7 @@ virKillProcess;
 virParseNumber;
 virParseVersionString;
 virPipeReadUntilEOF;
+virScaleInteger;
 virSetBlocking;
 virSetCloseExec;
 virSetInherit;
diff --git a/src/util/util.c b/src/util/util.c
index 7c58c7b..1b71680 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1632,6 +1632,72 @@ virHexToBin(unsigned char c)
 }
 }

+/* Scale an integer VALUE by an optional SUFFIX in-place, defaulting
+ * to SCALE if no suffix is present.  Ensure that the result does not
+ * exceed LIMIT.  Return 0 on success, -1 with error message raised on
+ * failure.  */
+int
+virScaleInteger(unsigned long long *value, const char *suffix,
+unsigned long long scale, unsigned long long limit)
+{
+if (!suffix || !*suffix) {
+if (!scale) {
+virUtilError(VIR_ERR_INTERNAL_ERROR,
+ _(invalid scale %llu), scale);
+return -1;
+}
+suffix = ;
+} else if (STRCASEEQ(suffix, b) || STRCASEEQ(suffix, byte) ||
+   STRCASEEQ(suffix, bytes)) {
+scale = 1;
+} else {
+int base;
+
+if (!suffix[1] || STRCASEEQ(suffix + 1, iB)) {
+base = 1024;
+} else if (c_tolower(suffix[1]) == 'b'  !suffix[2]) {
+base = 1000;
+} else {
+virUtilError(VIR_ERR_INVALID_ARG,
+ _(unknown suffix '%s'), suffix);
+return -1;
+}
+scale = 1;
+switch (c_tolower(*suffix)) {
+case 'e':
+scale *= base;
+/* fallthrough */
+case 'p':
+scale *= base;
+/* fallthrough */
+case 't':
+scale *= base;
+/* fallthrough */
+case 'g':
+scale *= base;
+/* fallthrough */
+case 'm':
+scale *= base;
+/* fallthrough */
+case 'k':
+scale *= base;
+break;
+default:
+virUtilError(VIR_ERR_INVALID_ARG,
+ _(unknown suffix '%s'), suffix);
+return -1;
+}
+}
+
+if (*value = (limit / scale)) {
+virUtilError(VIR_ERR_OVERFLOW, _(value too large: %llu%s),
+ *value, suffix);
+return -1;
+}
+*value *= scale;
+return 0;
+}
+
 /**
  * virSkipSpaces:
  * @str: pointer to the char pointer used
diff --git a/src/util/util.h b/src/util/util.h
index 5c945cc..85e8bd6 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -157,6 +157,10 @@ int virStrToDouble(char const *s,
char **end_ptr,
double *result);

+int virScaleInteger(unsigned long long *value, const char *suffix,
+unsigned long long scale, unsigned long long limit)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+
 int virHexToBin(unsigned char c);

 void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
-- 
1.7.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 00/15] clean up unit handling of memory and storage

2012-03-05 Thread Eric Blake
This turned into a bigger project than I originally planned, but
I'm happy with how things look after this series.
v1 (memory): 
https://www.redhat.com/archives/libvir-list/2012-February/msg00959.html
v1 (virsh): https://www.redhat.com/archives/libvir-list/2012-March/msg00108.html

In this series:

Eric Blake (15):
1: new, but partially factored out of memory 3/3
  docs: use correct terminology for 1024 bytes

2: new
  api: add overflow error

3: new, but partially factored out of memory 3/3
  util: new function for scaling numbers

4: new, based on feedback of memory 1/3
  xml: share 'unit' in RNG

5: rework of memory 1/3
  xml: output memory unit for clarity

6: new
  storage: support more scaling suffixes

7: minor rework of memory 2/3
  xml: drop unenforced minimum memory limit from RNG

8-9: new
  xml: use long long internally, to centralize overflow checks
  xml: use better types for memory values

10: rework of memory 3/3
  xml: allow scaled memory on input

11-13: unchanged from virsh 1-3/3
  virsh: add option aliases
  virsh: use option aliases
  virsh: add command aliases, and rename nodedev-detach

14-15: new
  virsh: improve storage unit parsing
  virsh: improve memory unit parsing

Also available at:
 git fetch git://repo.or.cz/libvirt/ericb.git units
or browseable at:
 http://repo.or.cz/w/libvirt/ericb.git/shortlog/refs/heads/units

 daemon/remote.c|   17 +-
 docs/formatdomain.html.in  |   55 +++-
 docs/formatstorage.html.in |   17 +-
 docs/schemas/basictypes.rng|   19 ++
 docs/schemas/domaincommon.rng  |   19 +-
 docs/schemas/storagepool.rng   |   47 +--
 docs/schemas/storagevol.rng|   56 +---
 include/libvirt/virterror.h|3 +-
 src/conf/domain_audit.c|2 +-
 src/conf/domain_conf.c |  127 ++--
 src/conf/domain_conf.h |   14 +-
 src/conf/storage_conf.c|   73 +
 src/conf/storage_conf.h|   12 +-
 src/driver.h   |2 +-
 src/esx/esx_driver.c   |4 +-
 src/libvirt.c  |   47 ++-
 src/libvirt_private.syms   |1 +
 src/libxl/libxl_driver.c   |8 +-
 src/lxc/lxc_driver.c   |6 +-
 src/openvz/openvz_driver.c |8 +-
 src/phyp/phyp_driver.c |   10 +-
 src/qemu/qemu_command.c|2 +-
 src/qemu/qemu_driver.c |   14 +-
 src/qemu/qemu_monitor.c|2 +-
 src/qemu/qemu_monitor.h|2 +-
 src/qemu/qemu_monitor_json.c   |2 +-
 src/qemu/qemu_monitor_json.h   |2 +-
 src/qemu/qemu_monitor_text.c   |2 +-
 src/qemu/qemu_monitor_text.h   |2 +-
 src/qemu/qemu_process.c|6 +
 src/rpc/gendispatch.pl |1 -
 src/test/test_driver.c |4 +-
 src/uml/uml_conf.c |2 +-
 src/uml/uml_driver.c   |6 +-
 src/util/util.c|   66 
 src/util/util.h|4 +
 src/util/virterror.c   |6 +
 src/vbox/vbox_tmpl.c   |4 +-
 src/vmx/vmx.c  |   10 +-
 src/xen/xen_driver.c   |6 +-
 src/xen/xen_hypervisor.c   |4 +-
 src/xen/xend_internal.c|   12 +-
 src/xen/xend_internal.h|4 +-
 src/xen/xm_internal.c  |6 +-
 src/xen/xm_internal.h  |4 +-
 src/xen/xs_internal.c  |   10 +-
 src/xen/xs_internal.h  |4 +-
 src/xenapi/xenapi_driver.c |6 +-
 src/xenxs/xen_sxpr.c   |8 +-
 src/xenxs/xen_xm.c |   58 +++-
 tests/define-dev-segfault  |4 +-
 tests/domainschemadata/domain-lxc-simple.xml   |2 +-
 tests/domainschemadata/portprofile.xml |2 +-
 .../qemu-simple-description-title.xml  |4 +-
 tests/domainschemadata/timers.xml  |4 +-
 tests/domainsnapshotxml2xmlout/disk_snapshot.xml   |4 +-
 tests/domainsnapshotxml2xmlout/full_domain.xml |4 +-
 tests/domainsnapshotxml2xmlout/metadata.xml|4 +-
 

[libvirt] [PATCHv2 13/15] virsh: add command aliases, and rename nodedev-detach

2012-03-05 Thread Eric Blake
Just because our public API has a typo doesn't mean that virsh
has to keep the typo.

* tools/virsh.c (VSH_CMD_FLAG_ALIAS): New flag.
(nodedevCmds): Use it.
(cmdHelp): Omit alias commands.
(cmdNodeDeviceDettach): Rename...
(cmdNodeDeviceDetach): ...to this.
* tools/virsh.pod (nodedev-detach): Document it.
---

v2: no real change

 tools/virsh.c   |   30 +++---
 tools/virsh.pod |   10 ++
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 75a1a3b..4361a6b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -212,6 +212,7 @@ typedef struct vshCmdOpt {
  */
 enum {
 VSH_CMD_FLAG_NOCONNECT = (1  0),  /* no prior connection needed */
+VSH_CMD_FLAG_ALIAS = (1  1),  /* command is an alias */
 };

 /*
@@ -685,9 +686,12 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd)
 vshPrint(ctl, _( %s (help keyword '%s'):\n), grp-name,
  grp-keyword);

-for (def = grp-commands; def-name; def++)
+for (def = grp-commands; def-name; def++) {
+if (def-flags  VSH_CMD_FLAG_ALIAS)
+continue;
 vshPrint(ctl, %-30s %s\n, def-name,
  _(vshCmddefGetInfo(def, help)));
+}

 vshPrint(ctl, \n);
 }
@@ -12939,22 +12943,22 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd 
*cmd)
 }

 /*
- * nodedev-dettach command
+ * nodedev-detach command
  */
-static const vshCmdInfo info_node_device_dettach[] = {
-{help, N_(dettach node device from its device driver)},
-{desc, N_(Dettach node device from its device driver before assigning 
to a domain.)},
+static const vshCmdInfo info_node_device_detach[] = {
+{help, N_(detach node device from its device driver)},
+{desc, N_(Detach node device from its device driver before assigning to 
a domain.)},
 {NULL, NULL}
 };


-static const vshCmdOptDef opts_node_device_dettach[] = {
+static const vshCmdOptDef opts_node_device_detach[] = {
 {device, VSH_OT_DATA, VSH_OFLAG_REQ, N_(device key)},
 {NULL, 0, 0, NULL}
 };

 static bool
-cmdNodeDeviceDettach (vshControl *ctl, const vshCmd *cmd)
+cmdNodeDeviceDetach (vshControl *ctl, const vshCmd *cmd)
 {
 const char *name = NULL;
 virNodeDevicePtr device;
@@ -12969,10 +12973,12 @@ cmdNodeDeviceDettach (vshControl *ctl, const vshCmd 
*cmd)
 return false;
 }

+/* Yes, our public API is misspelled.  At least virsh can accept
+ * either spelling.  */
 if (virNodeDeviceDettach(device) == 0) {
-vshPrint(ctl, _(Device %s dettached\n), name);
+vshPrint(ctl, _(Device %s detached\n), name);
 } else {
-vshError(ctl, _(Failed to dettach device %s), name);
+vshError(ctl, _(Failed to detach device %s), name);
 ret = false;
 }
 virNodeDeviceFree(device);
@@ -17090,8 +17096,10 @@ static const vshCmdDef nodedevCmds[] = {
  info_node_device_create, 0},
 {nodedev-destroy, cmdNodeDeviceDestroy, opts_node_device_destroy,
  info_node_device_destroy, 0},
-{nodedev-dettach, cmdNodeDeviceDettach, opts_node_device_dettach,
- info_node_device_dettach, 0},
+{nodedev-detach, cmdNodeDeviceDetach, opts_node_device_detach,
+ info_node_device_detach, 0},
+{nodedev-dettach, cmdNodeDeviceDetach, opts_node_device_detach,
+ info_node_device_detach, VSH_CMD_FLAG_ALIAS},
 {nodedev-dumpxml, cmdNodeDeviceDumpXML, opts_node_device_dumpxml,
  info_node_device_dumpxml, 0},
 {nodedev-list, cmdNodeListDevices, opts_node_list_devices,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 1bc55c4..b365624 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1442,7 +1442,7 @@ Attach a device to the domain, using a device definition 
in an XML file.
 See the documentation to learn about libvirt XML format for a device.
 For cdrom and floppy devices, this command only replaces the media within
 the single existing device; consider using Bupdate-device for this usage.
-For passthrough host devices, see also Bnodedev-dettach, needed if
+For passthrough host devices, see also Bnodedev-detach, needed if
 the device does not use managed mode.

 =item Battach-disk Idomain-id Isource Itarget
@@ -1571,7 +1571,7 @@ guest domains, nor by multiple active guests at once.  If 
the
 hostdev description includes the attribute Bmanaged='yes', and the
 hypervisor driver supports it, then the device is in managed mode, and
 attempts to use that passthrough device in an active guest will
-automatically behave as if Bnodedev-dettach (guest start, device
+automatically behave as if Bnodedev-detach (guest start, device
 hot-plug) and Bnodedev-reattach (guest stop, device hot-unplug) were
 called at the right points (currently, qemu does this for PCI devices,
 but not USB).  If a device is not marked as managed, then it must
@@ -1596,11 +1596,13 @@ Destroy (stop) a device on the host.  Note that this 
makes libvirt
 quit managing 

[libvirt] [PATCHv2 01/15] docs: use correct terminology for 1024 bytes

2012-03-05 Thread Eric Blake
Yes, I like kilobytes better than kibibytes (when I say kilobytes,
I generally mean 1024).  But since the term is ambiguous, it can't
hurt to say what we mean, by using both the correct name and
calling out the numeric equivalent.

* src/libvirt.c (virDomainGetMaxMemory, virDomainSetMaxMemory)
(virDomainSetMemory, virDomainSetMemoryFlags)
(virNodeGetFreeMemory): Tweak wording.
* docs/formatdomain.html.in: Likewise.
* docs/formatstorage.html.in: Likewise.
---

v2: separate doc changes out early

 docs/formatdomain.html.in  |   15 ---
 docs/formatstorage.html.in |8 ++--
 src/libvirt.c  |   10 +-
 3 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a61895f..0855c7f 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -424,7 +424,7 @@
 dl
   dtcodememory/code/dt
   ddThe maximum allocation of memory for the guest at boot time.
-The units for this value are kilobytes (i.e. blocks of 1024 bytes)/dd
+The units for this value are kibibytes (i.e. blocks of 1024 bytes)/dd
   dtcodecurrentMemory/code/dt
   ddThe actual allocation of memory for the guest. This value can
 be less than the maximum allocation, to allow for ballooning
@@ -480,21 +480,21 @@
 determine so one needs guess and try./dd
   dtcodehard_limit/code/dt
   dd The optional codehard_limit/code element is the maximum memory
-the guest can use. The units for this value are kilobytes (i.e. blocks
+the guest can use. The units for this value are kibibytes (i.e. blocks
 of 1024 bytes)/dd
   dtcodesoft_limit/code/dt
   dd The optional codesoft_limit/code element is the memory limit to
 enforce during memory contention. The units for this value are
-kilobytes (i.e. blocks of 1024 bytes)/dd
+kibibytes (i.e. blocks of 1024 bytes)/dd
   dtcodeswap_hard_limit/code/dt
   dd The optional codeswap_hard_limit/code element is the maximum
 memory plus swap the guest can use. The units for this value are
-kilobytes (i.e. blocks of 1024 bytes). This has to be more than
+kibibytes (i.e. blocks of 1024 bytes). This has to be more than
 hard_limit value provided/dd
   dtcodemin_guarantee/code/dt
   dd The optional codemin_guarantee/code element is the guaranteed
 minimum memory allocation for the guest. The units for this value are
-kilobytes (i.e. blocks of 1024 bytes)/dd
+kibibytes (i.e. blocks of 1024 bytes)/dd
 /dl


@@ -774,7 +774,7 @@
 p
   Each codecell/code element specifies a NUMA cell or a NUMA node.
   codecpus/code specifies the CPU or range of CPUs that are part of
-  the node. codememory/code specifies the node memory in kilobytes
+  the node. codememory/code specifies the node memory in kibibytes
   (i.e. blocks of 1024 bytes). Each cell or node is assigned cellid
   or nodeid in the increasing order starting from 0.
 /p
@@ -2920,7 +2920,8 @@ qemu-kvm -net nic,model=? /dev/null
 attribute which takes the value vga, cirrus, vmvga, xen,
 vbox, or qxl (span class=sincesince 0.8.6/span)
 depending on the hypervisor features available.
-You can also provide the amount of video memory in kilobytes using
+You can also provide the amount of video memory in kibibytes
+(blocks of 1024 bytes) using
 codevram/code and the number of screen with codeheads/code.
   /dd

diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index 0dcf6df..93d8ab2 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -236,8 +236,12 @@
 br/
 By default this is specified in bytes, but an optional
 codeunit/code can be specified to adjust the passed value.
-Values can be: 'K' (kilobytes), 'M' (megabytes), 'G' (gigabytes),
-'T' (terabytes), 'P' (petabytes), or 'E' (exabytes).
+Values can be: 'K' (kibibytes, 2sup10/sup or 1024), 'M'
+(mebibytes, 2sup20/sup or 1,048,576), 'G' (gibibytes,
+2sup30/sup or 1,073,741,824), 'T' (tebibytes,
+2sup40/sup or 1,099,511,627,776), 'P' (pebibytes,
+2sup50/sup or 1,125,899,906,842,624), or 'E' (exbibytes,
+2sup60/sup or 1,152,921,504,606,846,976).
 span class=sinceSince 0.4.1/span/dd
   dtcodecapacity/code/dt
   ddProviding the logical capacity for the volume. This value is
diff --git a/src/libvirt.c b/src/libvirt.c
index d98741b..650252e 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3582,7 +3582,7 @@ error:
  * domain. If domain is NULL, then this get the amount of memory reserved
  * to Domain0 i.e. the domain where the application runs.
  *
- * Returns the memory size in kilobytes or 0 in case of error.
+ * Returns the memory size in kibibytes (blocks of 1024), or 0 in case of 
error.
  */
 unsigned long
 

[libvirt] [PATCHv2 06/15] storage: support more scaling suffixes

2012-03-05 Thread Eric Blake
Disk manufacturers are fond of quoting sizes in powers of 10,
rather than powers of 2 (after all, 2.1 GB sounds larger than
2.0 GiB, even though the exact opposite is true).  So, we might
as well follow coreutils lead in supporting three types of
suffix: single letter ${u} (which we already had) and ${u}iB
for the power of 2, and ${u}B for power of 10.

Additionally, it is impossible to create a file with more than
2**63 bytes, since off_t is signed (if you have enough storage
to even create one 8EiB file, I'm jealous).  This now reports
failure up front rather than down the road when the kernel
finally refuses an impossible size.

* docs/schemas/basictypes.rng (unit): Add suffixes.
* src/conf/storage_conf.c (virStorageSize): Use new function.
* docs/formatstorage.html.in: Document it.
---

v2: new

 docs/formatstorage.html.in |   21 +---
 docs/schemas/basictypes.rng|2 +-
 src/conf/storage_conf.c|   61 +++-
 tests/storagevolxml2xmlin/vol-file-backing.xml |4 +-
 tests/storagevolxml2xmlin/vol-file.xml |4 +-
 5 files changed, 26 insertions(+), 66 deletions(-)

diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index 93d8ab2..b0acaf3 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -236,13 +236,20 @@
 br/
 By default this is specified in bytes, but an optional
 codeunit/code can be specified to adjust the passed value.
-Values can be: 'K' (kibibytes, 2sup10/sup or 1024), 'M'
-(mebibytes, 2sup20/sup or 1,048,576), 'G' (gibibytes,
-2sup30/sup or 1,073,741,824), 'T' (tebibytes,
-2sup40/sup or 1,099,511,627,776), 'P' (pebibytes,
-2sup50/sup or 1,125,899,906,842,624), or 'E' (exbibytes,
-2sup60/sup or 1,152,921,504,606,846,976).
-span class=sinceSince 0.4.1/span/dd
+Values can be: 'B' or 'bytes' for bytes, 'KB' (kilobytes,
+10sup3/sup or 1000), 'K' or 'KiB' (kibibytes,
+2sup10/sup or 1024), 'MB' (megabytes, 10sup6/sup or
+1,000,000), 'M' or 'MiB' (mebibytes, 2sup20/sup or
+1,048,576), 'GB' (gigabytes, 10sup9/sup or 1,000,000,000),
+'G' or 'GiB' (gibibytes, 2sup30/sup or 1,073,741,824),
+'TB' (terabytes, 10sup12/sup or 1,000,000,000,000), 'T' or
+'TiB' (tebibytes, 2sup40/sup or 1,099,511,627,776), 'PB'
+(petabytes, 10sup15/sup or 1,000,000,000,000,000), 'P' or
+'PiB' (pebibytes, 2sup50/sup or 1,125,899,906,842,624),
+'EB' (exabytes, 10sup18/sup or 1,000,000,000,000,000,000),
+or 'E' or 'EiB' (exbibytes, 2sup60/sup or
+1,152,921,504,606,846,976).  span class=sinceSince 0.4.1,
+multi-character codeunit/code since 0.9.11/span/dd
   dtcodecapacity/code/dt
   ddProviding the logical capacity for the volume. This value is
 in bytes by default, but a codeunit/code attribute can be
diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng
index a50349c..cc0bc12 100644
--- a/docs/schemas/basictypes.rng
+++ b/docs/schemas/basictypes.rng
@@ -140,7 +140,7 @@

   define name='unit'
 data type='string'
-  param name='pattern'(bytes)|[kKmMgGtTpPeE]/param
+  param 
name='pattern'([bB]([yY][tT][eE][sS]?)?)|([kKmMgGtTpPeE]([iI]?[bB])?)/param
 /data
   /define
   define name='scaledInteger'
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 07f3f5b..d1558ee 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -944,64 +944,17 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def) {
 static int
 virStorageSize(const char *unit,
const char *val,
-   unsigned long long *ret) {
-unsigned long long mult;
-char *end;
-
-if (!unit) {
-mult = 1;
-} else {
-switch (unit[0]) {
-case 'k':
-case 'K':
-mult = 1024ull;
-break;
-
-case 'm':
-case 'M':
-mult = 1024ull * 1024ull;
-break;
-
-case 'g':
-case 'G':
-mult = 1024ull * 1024ull * 1024ull;
-break;
-
-case 't':
-case 'T':
-mult = 1024ull * 1024ull * 1024ull * 1024ull;
-break;
-
-case 'p':
-case 'P':
-mult = 1024ull * 1024ull * 1024ull * 1024ull * 1024ull;
-break;
-
-case 'e':
-case 'E':
-mult = 1024ull * 1024ull * 1024ull * 1024ull * 1024ull *
-1024ull;
-break;
-
-default:
-virStorageReportError(VIR_ERR_XML_ERROR,
-  _(unknown size units '%s'), unit);
-return -1;
-}
-}
-
-if (virStrToLong_ull (val, end, 10, ret)  0) {
+   unsigned long long *ret)
+{
+if (virStrToLong_ull(val, NULL, 10, ret)  0) {
 virStorageReportError(VIR_ERR_XML_ERROR,
   

[libvirt] [PATCHv2 12/15] virsh: use option aliases

2012-03-05 Thread Eric Blake
Command line interfaces should use dash, not underscore, as many
keyboard layouts allow that to be typed with fewer shift key presses.

Also, the US spelling of --tunneled gets more google hits than the
UK spelling of --tunnelled.

* tools/virsh.c (opts_migrate): Allow US variant.
(opts_blkdeviotune): Prefer - over _.
* tools/virsh.pod (blkdeviotune): Fix spelling.
---

v2: no real change

 tools/virsh.c   |   49 +++--
 tools/virsh.pod |   18 +-
 2 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 77cf4ac..75a1a3b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -6879,6 +6879,7 @@ static const vshCmdOptDef opts_migrate[] = {
 {live, VSH_OT_BOOL, 0, N_(live migration)},
 {p2p, VSH_OT_BOOL, 0, N_(peer-2-peer migration)},
 {direct, VSH_OT_BOOL, 0, N_(direct migration)},
+{tunneled, VSH_OT_ALIAS, 0, tunnelled},
 {tunnelled, VSH_OT_BOOL, 0, N_(tunnelled migration)},
 {persistent, VSH_OT_BOOL, 0, N_(persist VM on destination)},
 {undefinesource, VSH_OT_BOOL, 0, N_(undefine VM on source)},
@@ -7574,17 +7575,23 @@ static const vshCmdInfo info_blkdeviotune[] = {
 static const vshCmdOptDef opts_blkdeviotune[] = {
 {domain, VSH_OT_DATA, VSH_OFLAG_REQ, N_(domain name, id or uuid)},
 {device, VSH_OT_DATA, VSH_OFLAG_REQ, N_(block device)},
-{total_bytes_sec, VSH_OT_INT, VSH_OFLAG_NONE,
+{total_bytes_sec, VSH_OT_ALIAS, 0, total-bytes-sec},
+{total-bytes-sec, VSH_OT_INT, VSH_OFLAG_NONE,
  N_(total throughput limit in bytes per second)},
-{read_bytes_sec, VSH_OT_INT, VSH_OFLAG_NONE,
+{read_bytes_sec, VSH_OT_ALIAS, 0, read-bytes-sec},
+{read-bytes-sec, VSH_OT_INT, VSH_OFLAG_NONE,
  N_(read throughput limit in bytes per second)},
-{write_bytes_sec, VSH_OT_INT, VSH_OFLAG_NONE,
+{write_bytes_sec, VSH_OT_ALIAS, 0, write-bytes-sec},
+{write-bytes-sec, VSH_OT_INT, VSH_OFLAG_NONE,
  N_(write throughput limit in bytes per second)},
-{total_iops_sec, VSH_OT_INT, VSH_OFLAG_NONE,
+{total_iops_sec, VSH_OT_ALIAS, 0, total-iops-sec},
+{total-iops-sec, VSH_OT_INT, VSH_OFLAG_NONE,
  N_(total I/O operations limit per second)},
-{read_iops_sec, VSH_OT_INT, VSH_OFLAG_NONE,
+{read_iops_sec, VSH_OT_ALIAS, 0, read-iops-sec},
+{read-iops-sec, VSH_OT_INT, VSH_OFLAG_NONE,
  N_(read I/O operations limit per second)},
-{write_iops_sec, VSH_OT_INT, VSH_OFLAG_NONE,
+{write_iops_sec, VSH_OT_ALIAS, 0, write-iops-sec},
+{write-iops-sec, VSH_OT_INT, VSH_OFLAG_NONE,
  N_(write I/O operations limit per second)},
 {config, VSH_OT_BOOL, 0, N_(affect next boot)},
 {live, VSH_OT_BOOL, 0, N_(affect running domain)},
@@ -7630,7 +7637,8 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
 if (vshCommandOptString(cmd, device, disk)  0)
 goto cleanup;

-if ((rv = vshCommandOptULongLong(cmd, total_bytes_sec, 
total_bytes_sec))  0) {
+if ((rv = vshCommandOptULongLong(cmd, total-bytes-sec,
+ total_bytes_sec))  0) {
 vshError(ctl, %s,
  _(Unable to parse integer parameter));
 goto cleanup;
@@ -7638,7 +7646,8 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
 nparams++;
 }

-if ((rv = vshCommandOptULongLong(cmd, read_bytes_sec, read_bytes_sec)) 
 0) {
+if ((rv = vshCommandOptULongLong(cmd, read-bytes-sec,
+ read_bytes_sec))  0) {
 vshError(ctl, %s,
  _(Unable to parse integer parameter));
 goto cleanup;
@@ -7646,7 +7655,8 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
 nparams++;
 }

-if ((rv = vshCommandOptULongLong(cmd, write_bytes_sec, 
write_bytes_sec))  0) {
+if ((rv = vshCommandOptULongLong(cmd, write-bytes-sec,
+ write_bytes_sec))  0) {
 vshError(ctl, %s,
  _(Unable to parse integer parameter));
 goto cleanup;
@@ -7654,7 +7664,8 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
 nparams++;
 }

-if ((rv = vshCommandOptULongLong(cmd, total_iops_sec, total_iops_sec)) 
 0) {
+if ((rv = vshCommandOptULongLong(cmd, total-iops-sec,
+ total_iops_sec))  0) {
 vshError(ctl, %s,
  _(Unable to parse integer parameter));
 goto cleanup;
@@ -7662,7 +7673,8 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
 nparams++;
 }

-if ((rv = vshCommandOptULongLong(cmd, read_iops_sec, read_iops_sec))  
0) {
+if ((rv = vshCommandOptULongLong(cmd, read-iops-sec,
+ read_iops_sec))  0) {
 vshError(ctl, %s,
  _(Unable to parse integer parameter));
 goto cleanup;
@@ -7670,7 +7682,8 @@ cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd)
 nparams++;
 }

-if ((rv = 

[libvirt] [PATCHv2 04/15] xml: share 'unit' in RNG

2012-03-05 Thread Eric Blake
The code supported unit='E' for exabyte, but the RNG did not;
conversely, the RNG supported z and y but the code did not
(I'm jealous if you have that much storage, particularly since
it won't fit in 64-bit off_t).  Also, the code supported
allocation unit='...', but not the RNG.

In an effort to make 'unit' more worthwhile in future patches,
it's easier to share it between files.

In making this factorization, note that absFilePath is more
permissive than 'path', so storage pools and storage volumes
will now validate with a wider set of file names than before.
I don't think this should be a problem in practice.

* docs/schemas/storagepool.rng: Include basic types, rather than
repeating things here.
* docs/schemas/storagevol.rng: Likewise.
* docs/schemas/basictypes.rng: Add 'unsignedLong', 'unit', and fix
to match storage code.
---

v2: new

 docs/schemas/basictypes.rng  |   11 
 docs/schemas/storagepool.rng |   47 +-
 docs/schemas/storagevol.rng  |   56 -
 3 files changed, 41 insertions(+), 73 deletions(-)

diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng
index 3b4b952..4f16fa7 100644
--- a/docs/schemas/basictypes.rng
+++ b/docs/schemas/basictypes.rng
@@ -8,6 +8,11 @@
   param name=pattern[0-9]+/param
 /data
   /define
+  define name='unsignedLong'
+data type='unsignedLong'
+  param name='pattern'[0-9]+/param
+/data
+  /define

   define name=positiveInteger
 data type=positiveInteger
@@ -133,4 +138,10 @@
 /data
   /define

+  define name='unit'
+data type='string'
+  param name='pattern'[kKmMgGtTpPeE]/param
+/data
+  /define
+
 /grammar
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index 3301472..6399f12 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -2,6 +2,7 @@
 !-- A Relax NG schema for the libvirt storage pool XML format --
 grammar xmlns=http://relaxng.org/ns/structure/1.0;
 datatypeLibrary=http://www.w3.org/2001/XMLSchema-datatypes;
+  include href='basictypes.rng'/
   start
 ref name='pool'/
   /start
@@ -127,7 +128,7 @@
 /element
 optional
   element name='uuid'
-ref name='uuid'/
+ref name='UUID'/
   /element
 /optional
   /define
@@ -135,17 +136,17 @@
   define name='sizing'
 optional
   element name='capacity'
-ref name='uint'/
+ref name='unsignedLong'/
   /element
 /optional
 optional
   element name='allocation'
-ref name='uint'/
+ref name='unsignedLong'/
   /element
 /optional
 optional
   element name='available'
-ref name='uint'/
+ref name='unsignedLong'/
   /element
 /optional
   /define
@@ -154,13 +155,13 @@
 optional
   element name='permissions'
 element name='mode'
-  ref name='uint'/
+  ref name='unsignedInt'/
 /element
 element name='owner'
-  ref name='uint'/
+  ref name='unsignedInt'/
 /element
 element name='group'
-  ref name='uint'/
+  ref name='unsignedInt'/
 /element
 optional
   element name='label'
@@ -175,7 +176,7 @@
 element name='target'
   optional
 element name='path'
-  ref name='path'/
+  ref name='absFilePath'/
 /element
   /optional
   ref name='permissions'/
@@ -200,7 +201,7 @@
 element name='device'
   attribute name='path'
 choice
-  ref name='path'/
+  ref name='absFilePath'/
   ref name='name'/
 /choice
   /attribute
@@ -226,10 +227,10 @@
 oneOrMore
   element name='freeExtent'
 attribute name='start'
-  ref name='uint'/
+  ref name='unsignedLong'/
 /attribute
 attribute name='end'
-  ref name='uint'/
+  ref name='unsignedLong'/
 /attribute
   /element
 /oneOrMore
@@ -238,7 +239,7 @@
   define name='sourceinfodir'
 element name='dir'
   attribute name='path'
-ref name='path'/
+ref name='absFilePath'/
   /attribute
   empty/
 /element
@@ -454,28 +455,6 @@
   param name=pattern[a-zA-Z0-9_\+\-]+/param
 /data
   /define
-  define name='uuid'
-choice
-  data type='string'
-param name=pattern[a-fA-F0-9]{32}/param
-  /data
-  data type='string'
-param 
name=pattern[a-fA-F0-9]{8}\-([a-fA-F0-9]{4}\-){3}[a-fA-F0-9]{12}/param
-  /data
-/choice
-  /define
-
-  define name='uint'
-data type='string'
-  param name=pattern[0-9]+/param
-/data
-  /define
-
-  define name='path'
-data type='string'
-  param name=pattern/[a-zA-Z0-9_\+\-/%]+/param
-/data
-  /define

   define name=PortNumber
 data type=short
diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 994004d..d06884c 100644
--- 

[libvirt] [PATCHv2 14/15] virsh: improve storage unit parsing

2012-03-05 Thread Eric Blake
Now can now do:

virsh vol-resize $vol 10M
virsh blockresize $dom $vol 10M

to get both interfaces to resize to 10MiB.  The remaining wart
is that vol-resize defaults to bytes, but blockresize defaults
to KiB, but we can't break existing scripts; oh well, it's no
worse than the same wart of the underlying virDomainBlockResize.

* tools/virsh.c (vshCommandOptScaledInt): New function.
(cmdVolResize): Don't pass negative size.
(cmdVolSize): Use new helper routine.
(cmdBlockResize): Likewise; also support bytes.
* tools/virsh.pod (NOTES): Document suffixes.
(blockresize, vol-create-as, vol-resize): Point to notes.
---

v2: new

 tools/virsh.c   |  113 +++
 tools/virsh.pod |   43 
 2 files changed, 98 insertions(+), 58 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 4361a6b..d5cc46b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -313,6 +313,10 @@ static int vshCommandOptLongLong(const vshCmd *cmd, const 
char *name,
 static int vshCommandOptULongLong(const vshCmd *cmd, const char *name,
   unsigned long long *value)
 ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
+static int vshCommandOptScaledInt(const vshCmd *cmd, const char *name,
+  unsigned long long *value, int scale,
+  unsigned long long max)
+ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK;
 static bool vshCommandOptBool(const vshCmd *cmd, const char *name);
 static const vshCmdOpt *vshCommandOptArgv(const vshCmd *cmd,
   const vshCmdOpt *opt);
@@ -7471,9 +7475,10 @@ static const vshCmdInfo info_block_resize[] = {

 static const vshCmdOptDef opts_block_resize[] = {
 {domain, VSH_OT_DATA, VSH_OFLAG_REQ, N_(domain name, id or uuid)},
-{path, VSH_OT_DATA, VSH_OFLAG_REQ, N_(Fully-qualified path of block 
device)},
-{size, VSH_OT_INT, VSH_OFLAG_REQ, N_(New size of the block device in 
kilobytes, 
-   the size must be integer)},
+{path, VSH_OT_DATA, VSH_OFLAG_REQ,
+ N_(Fully-qualified path of block device)},
+{size, VSH_OT_INT, VSH_OFLAG_REQ,
+ N_(New size of the block device, as scaled integer (default KiB))},
 {NULL, 0, 0, NULL}
 };

@@ -7494,15 +7499,16 @@ cmdBlockResize(vshControl *ctl, const vshCmd *cmd)
 return false;
 }

-if (vshCommandOptULongLong(cmd, size, size)  0) {
+if (vshCommandOptScaledInt(cmd, size, size, 1024, ULLONG_MAX)  0) {
 vshError(ctl, %s, _(Unable to parse integer));
 return false;
 }

-if (size  ULLONG_MAX / 1024) {
-vshError(ctl, _(Size must be less than %llu), ULLONG_MAX / 1024);
-return false;
-}
+/* Prefer the older interface of KiB.  */
+if (size % 1024 == 0)
+size /= 1024;
+else
+flags |= VIR_DOMAIN_BLOCK_RESIZE_BYTES;

 if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
 return false;
@@ -10892,43 +10898,26 @@ static const vshCmdInfo info_vol_create_as[] = {
 static const vshCmdOptDef opts_vol_create_as[] = {
 {pool, VSH_OT_DATA, VSH_OFLAG_REQ, N_(pool name)},
 {name, VSH_OT_DATA, VSH_OFLAG_REQ, N_(name of the volume)},
-{capacity, VSH_OT_DATA, VSH_OFLAG_REQ, N_(size of the vol with optional 
k,M,G,T suffix)},
-{allocation, VSH_OT_STRING, 0, N_(initial allocation size with optional 
k,M,G,T suffix)},
-{format, VSH_OT_STRING, 0, N_(file format type 
raw,bochs,qcow,qcow2,vmdk)},
-{backing-vol, VSH_OT_STRING, 0, N_(the backing volume if taking a 
snapshot)},
-{backing-vol-format, VSH_OT_STRING, 0, N_(format of backing volume if 
taking a snapshot)},
+{capacity, VSH_OT_DATA, VSH_OFLAG_REQ,
+ N_(size of the vol, as scaled integer (default bytes))},
+{allocation, VSH_OT_STRING, 0,
+ N_(initial allocation size, as scaled integer (default bytes))},
+{format, VSH_OT_STRING, 0,
+ N_(file format type raw,bochs,qcow,qcow2,vmdk)},
+{backing-vol, VSH_OT_STRING, 0,
+ N_(the backing volume if taking a snapshot)},
+{backing-vol-format, VSH_OT_STRING, 0,
+ N_(format of backing volume if taking a snapshot)},
 {NULL, 0, 0, NULL}
 };

-static int cmdVolSize(const char *data, unsigned long long *val)
+static int
+cmdVolSize(const char *data, unsigned long long *val)
 {
 char *end;
 if (virStrToLong_ull(data, end, 10, val)  0)
 return -1;
-
-if (end  *end) {
-/* Deliberate fallthrough cases here :-) */
-switch (*end) {
-case 'T':
-*val *= 1024;
-/* fallthrough */
-case 'G':
-*val *= 1024;
-/* fallthrough */
-case 'M':
-*val *= 1024;
-/* fallthrough */
-case 'k':
-*val *= 1024;
-break;
-default:
-return -1;
-}
-end++;
-if (*end)
-return -1;
-}
-return 0;
+   

[libvirt] [PATCHv2 07/15] xml: drop unenforced minimum memory limit from RNG

2012-03-05 Thread Eric Blake
The test domain allows memory0/memory, but the RNG was stating
that memory had to be at least 4096000 bytes.  Hypervisors should
enforce their own limits, rather than complicating the RNG.

Meanwhile, some copy and paste had introduced some fishy constructs
in various unit tests.

* docs/schemas/domaincommon.rng (memoryKB, memoryKBElement): Drop
limit that isn't enforced in code.
* src/conf/domain_conf.c (virDomainDefParseXML): Require current
= maximum.
* tests/qemuxml2argvdata/*.xml: Fix offenders.
---

rework of memory v1 2/3
v2: fix bogus comment regarding 4000KiB limit

 docs/schemas/domaincommon.rng  |7 +--
 src/conf/domain_conf.c |7 +++
 .../qemuxml2argv-smartcard-controller.xml  |2 +-
 .../qemuxml2argv-smartcard-host-certificates.xml   |2 +-
 .../qemuxml2argv-smartcard-host.xml|2 +-
 ...qemuxml2argv-smartcard-passthrough-spicevmc.xml |2 +-
 .../qemuxml2argv-smartcard-passthrough-tcp.xml |2 +-
 .../qemuxml2argv-usb-controller.xml|2 +-
 tests/qemuxml2argvdata/qemuxml2argv-usb-hub.xml|2 +-
 .../qemuxml2argv-usb-ich9-companion.xml|2 +-
 .../qemuxml2argv-usb-ich9-ehci-addr.xml|2 +-
 .../qemuxml2argv-usb-piix3-controller.xml  |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-usb-ports.xml  |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-usb-redir.xml  |2 +-
 tests/qemuxml2argvdata/qemuxml2argv-usb1-usb2.xml  |2 +-
 15 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index c8b403e..99b3861 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3027,10 +3027,6 @@

   !--
Type library
-
-   A domain name should be made of ascii, numbers, _-+ and is non-empty
-   memoryKB request at least 4Mbytes though Xen will grow bigger if too low
-   weight currently is in range [100, 1000]
 --
   define name=cpuset
 data type=string
@@ -3072,6 +3068,7 @@
   param name=minInclusive-1/param
 /data
   /define
+  !-- weight currently is in range [100, 1000] --
   define name=weight
 data type=unsignedInt
   param name=pattern[0-9]+/param
@@ -3083,7 +3080,6 @@
   define name=memoryKB
 data type=unsignedInt
   param name=pattern[0-9]+/param
-  param name=minInclusive4000/param
 /data
   /define
   !-- Memory as an element, with optional unit attribute --
@@ -3095,7 +3091,6 @@
 /optional
 data type='unsignedInt'
   param name='pattern'[0-9]+/param
-  param name='minInclusive'4000/param
 /data
   /define
   define name=domainName
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 331d923..41d0eca 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7303,6 +7303,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
   def-mem.cur_balloon)  0)
 def-mem.cur_balloon = def-mem.max_balloon;

+if (def-mem.cur_balloon  def-mem.max_balloon) {
+virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+ _(current memory '%luk' exceeds maximum '%luk'),
+ def-mem.cur_balloon, def-mem.max_balloon);
+goto error;
+}
+
 node = virXPathNode(./memoryBacking/hugepages, ctxt);
 if (node)
 def-mem.hugepage_backed = 1;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-controller.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-controller.xml
index 1914c6b..3256010 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-controller.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-controller.xml
@@ -2,7 +2,7 @@
   nameQEMUGuest1/name
   uuidc7a5fdbd-edaf-9455-926a-d65c16db1809/uuid
   memory unit='KiB'219136/memory
-  currentMemory unit='KiB'219200/currentMemory
+  currentMemory unit='KiB'219136/currentMemory
   vcpu1/vcpu
   os
 type arch='i686' machine='pc'hvm/type
diff --git 
a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host-certificates.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host-certificates.xml
index 2f58068..d91afcc 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host-certificates.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host-certificates.xml
@@ -2,7 +2,7 @@
   nameQEMUGuest1/name
   uuidc7a5fdbd-edaf-9455-926a-d65c16db1809/uuid
   memory unit='KiB'219136/memory
-  currentMemory unit='KiB'219200/currentMemory
+  currentMemory unit='KiB'219136/currentMemory
   vcpu1/vcpu
   os
 type arch='i686' machine='pc'hvm/type
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host.xml
index b0415b3..7069279 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-smartcard-host.xml
@@ -2,7 +2,7 @@
   nameQEMUGuest1/name
   

[libvirt] [PATCHv2 02/15] api: add overflow error

2012-03-05 Thread Eric Blake
Overflow can be user-induced, so it deserves more than being called
an internal error.  Note that in general, 32-bit platforms have
far more places to trigger this error (anywhere the public API
used 'unsigned long' but the other side of the connection is a
64-bit server); but some are possible on 64-bit platforms (where
the public API computes the product of two numbers).

* include/libvirt/virterror.h (VIR_ERR_OVERFLOW): New error.
* src/util/virterror.c (virErrorMsg): Translate it.
* src/libvirt.c (virDomainSetVcpusFlags, virDomainGetVcpuPinInfo)
(virDomainGetVcpus, virDomainGetCPUStats): Use it.
* daemon/remote.c (HYPER_TO_TYPE): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockResize): Likewise.
---

v2: new

 daemon/remote.c |   17 +
 include/libvirt/virterror.h |3 ++-
 src/libvirt.c   |   30 +++---
 src/qemu/qemu_driver.c  |2 +-
 src/util/virterror.c|6 ++
 5 files changed, 41 insertions(+), 17 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 74a5f16..be51d6f 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -57,14 +57,15 @@
  __FUNCTION__, __LINE__, __VA_ARGS__)

 #if SIZEOF_LONG  8
-# define HYPER_TO_TYPE(_type, _to, _from) \
-do {  \
-if ((_from) != (_type)(_from)) {  \
-virNetError(VIR_ERR_INTERNAL_ERROR,   \
-_(conversion from hyper to %s overflowed), #_type); \
-goto cleanup; \
-} \
-(_to) = (_from);  \
+# define HYPER_TO_TYPE(_type, _to, _from)   \
+do {\
+if ((_from) != (_type)(_from)) {\
+virNetError(VIR_ERR_OVERFLOW,   \
+_(conversion from hyper to %s overflowed),\
+#_type);\
+goto cleanup;   \
+}   \
+(_to) = (_from);\
 } while (0)

 # define HYPER_TO_LONG(_to, _from) HYPER_TO_TYPE(long, _to, _from)
diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index a3f9199..38ac15e 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -4,7 +4,7 @@
  * Description: Provides the interfaces of the libvirt library to handle
  *  errors raised while using the library.
  *
- * Copy:  Copyright (C) 2006, 2010-2011 Red Hat, Inc.
+ * Copy:  Copyright (C) 2006, 2010-2012 Red Hat, Inc.
  *
  * See COPYING.LIB for the License of this software
  *
@@ -246,6 +246,7 @@ typedef enum {
 VIR_ERR_AUTH_CANCELLED = 79,/* authentication cancelled */
 VIR_ERR_NO_DOMAIN_METADATA = 80,/* The metadata is not present */
 VIR_ERR_MIGRATE_UNSAFE = 81,/* Migration is not safe */
+VIR_ERR_OVERFLOW = 82,  /* integer overflow */
 } virErrorNumber;

 /**
diff --git a/src/libvirt.c b/src/libvirt.c
index 650252e..de23db8 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -8506,10 +8506,14 @@ virDomainSetVcpusFlags(virDomainPtr domain, unsigned 
int nvcpus,
 }

 /* Perform some argument validation common to all implementations.  */
-if (nvcpus  1 || (unsigned short) nvcpus != nvcpus) {
+if (nvcpus  1) {
 virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 goto error;
 }
+if ((unsigned short) nvcpus != nvcpus) {
+virLibDomainError(VIR_ERR_OVERFLOW, _(input too large: %u), nvcpus);
+goto error;
+}
 conn = domain-conn;

 if (conn-driver-domainSetVcpusFlags) {
@@ -8773,11 +8777,15 @@ virDomainGetVcpuPinInfo(virDomainPtr domain, int 
ncpumaps,
 return -1;
 }

-if (ncpumaps  1 || !cpumaps || maplen = 0 ||
-INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) {
+if (ncpumaps  1 || !cpumaps || maplen = 0) {
 virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
 goto error;
 }
+if (INT_MULTIPLY_OVERFLOW(ncpumaps, maplen)) {
+virLibDomainError(VIR_ERR_OVERFLOW, _(input too large: %d * %d),
+  ncpumaps, maplen);
+goto error;
+}

 /* At most one of these two flags should be set.  */
 if ((flags  VIR_DOMAIN_AFFECT_LIVE) 
@@ -8852,11 +8860,15 @@ virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr 
info, int maxinfo,

 /* Ensure that domainGetVcpus (aka remoteDomainGetVcpus) does not

[libvirt] [PATCHv2 15/15] virsh: improve memory unit parsing

2012-03-05 Thread Eric Blake
The last vestige of the inaccurate 'kilobytes' when we meant 1024 is
now gone.  And virsh is now useful for setting memory in units other
than KiB.

* tools/virsh.c (cmdSetmem, cmdSetmaxmem): Use new helper routine,
allow passing bogus arguments on to hypervisor to test driver
sanity checking, and fix leak on parse error.
(cmdMemtuneGetSize): New helper.
(cmdMemtune): Use it.
* tools/virsh.pod (setmem, setmaxmem, memtune): Document this.
---

v2: new

 tools/virsh.c   |  110 +--
 tools/virsh.pod |   48 
 2 files changed, 90 insertions(+), 68 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index d5cc46b..b93706f 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -5668,7 +5668,7 @@ cleanup:
 }

 /*
- * setmemory command
+ * setmem command
  */
 static const vshCmdInfo info_setmem[] = {
 {help, N_(change memory allocation)},
@@ -5678,7 +5678,9 @@ static const vshCmdInfo info_setmem[] = {

 static const vshCmdOptDef opts_setmem[] = {
 {domain, VSH_OT_DATA, VSH_OFLAG_REQ, N_(domain name, id or uuid)},
-{kilobytes, VSH_OT_INT, VSH_OFLAG_REQ, N_(number of kilobytes of 
memory)},
+{kilobytes, VSH_OT_ALIAS, 0, size},
+{size, VSH_OT_INT, VSH_OFLAG_REQ,
+ N_(new memory size, as scaled integer (default KiB))},
 {config, VSH_OT_BOOL, 0, N_(affect next boot)},
 {live, VSH_OT_BOOL, 0, N_(affect running domain)},
 {current, VSH_OT_BOOL, 0, N_(affect current domain)},
@@ -5689,8 +5691,9 @@ static bool
 cmdSetmem(vshControl *ctl, const vshCmd *cmd)
 {
 virDomainPtr dom;
-virDomainInfo info;
-unsigned long kilobytes = 0;
+unsigned long long bytes = 0;
+unsigned long long max;
+unsigned long kibibytes = 0;
 bool ret = true;
 int config = vshCommandOptBool(cmd, config);
 int live = vshCommandOptBool(cmd, live);
@@ -5719,36 +5722,25 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
 if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
 return false;

-if (vshCommandOptUL(cmd, kilobytes, kilobytes)  0) {
+/* The API expects 'unsigned long' KiB, so depending on whether we
+ * are 32-bit or 64-bit determines the maximum we can use.  */
+if (sizeof(kibibytes)  sizeof(max))
+max = 1024ull * ULONG_MAX;
+else
+max = ULONG_MAX;
+if (vshCommandOptScaledInt(cmd, size, bytes, 1024, max)  0) {
 vshError(ctl, %s, _(memory size has to be a number));
-return false;
-}
-
-if (kilobytes = 0) {
-virDomainFree(dom);
-vshError(ctl, _(Invalid value of %lu for memory size), kilobytes);
-return false;
-}
-
-if (virDomainGetInfo(dom, info) != 0) {
 virDomainFree(dom);
-vshError(ctl, %s, _(Unable to verify MaxMemorySize));
-return false;
-}
-
-if (kilobytes  info.maxMem) {
-virDomainFree(dom);
-vshError(ctl, _(Requested memory size %lu kb is larger than maximum 
of %lu kb),
- kilobytes, info.maxMem);
 return false;
 }
+kibibytes = VIR_DIV_UP(bytes, 1024);

 if (flags == -1) {
-if (virDomainSetMemory(dom, kilobytes) != 0) {
+if (virDomainSetMemory(dom, kibibytes) != 0) {
 ret = false;
 }
 } else {
-if (virDomainSetMemoryFlags(dom, kilobytes, flags)  0) {
+if (virDomainSetMemoryFlags(dom, kibibytes, flags)  0) {
 ret = false;
 }
 }
@@ -5768,7 +5760,9 @@ static const vshCmdInfo info_setmaxmem[] = {

 static const vshCmdOptDef opts_setmaxmem[] = {
 {domain, VSH_OT_DATA, VSH_OFLAG_REQ, N_(domain name, id or uuid)},
-{kilobytes, VSH_OT_INT, VSH_OFLAG_REQ, N_(maximum memory limit in 
kilobytes)},
+{kilobytes, VSH_OT_ALIAS, 0, size},
+{size, VSH_OT_INT, VSH_OFLAG_REQ,
+ N_(new maximum memory size, as scaled integer (default KiB))},
 {config, VSH_OT_BOOL, 0, N_(affect next boot)},
 {live, VSH_OT_BOOL, 0, N_(affect running domain)},
 {current, VSH_OT_BOOL, 0, N_(affect current domain)},
@@ -5779,7 +5773,9 @@ static bool
 cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
 {
 virDomainPtr dom;
-int kilobytes = 0;
+unsigned long long bytes = 0;
+unsigned long long max;
+unsigned long kibibytes = 0;
 bool ret = true;
 int config = vshCommandOptBool(cmd, config);
 int live = vshCommandOptBool(cmd, live);
@@ -5807,24 +5803,26 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
 if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
 return false;

-if (vshCommandOptInt(cmd, kilobytes, kilobytes)  0) {
+/* The API expects 'unsigned long' KiB, so depending on whether we
+ * are 32-bit or 64-bit determines the maximum we can use.  */
+if (sizeof(kibibytes)  sizeof(max))
+max = 1024ull * ULONG_MAX;
+else
+max = ULONG_MAX;
+if (vshCommandOptScaledInt(cmd, size, bytes, 1024, max)  0) {
 vshError(ctl, %s, _(memory size has to be a number));
- 

[libvirt] [PATCHv2 05/15] xml: output memory unit for clarity

2012-03-05 Thread Eric Blake
Make it obvious to 'dumpxml' readers what unit we are using,
since our default of KiB for memory (1024) differs from
qemu's default of MiB; while we use bytes for storage.

Tests were updated via:

$ find tests/*data tests/*out -name '*.xml' | \
  xargs sed -i 
's/\(memory\|currentMemory\|hard_limit\|soft_limit\|min_guarantee\|swap_hard_limit\)/\1
 unit=''KiB'/
$ find tests/*data tests/*out -name '*.xml' | \
  xargs sed -i 's/\(capacity\|allocation\|available\)/\1 unit=''bytes'/

followed by a few fixes for the stragglers.

* docs/schemas/basictypes.rng (unit): Add 'bytes'.
(scaledInteger): New define.
* docs/schemas/storagevol.rng (sizing): Use it.
* docs/schemas/storagepool.rng (sizing): Likewise.
* docs/schemas/domaincommon.rng (memoryKBElement): New define; use
for memory elements.
* src/conf/storage_conf.c (virStoragePoolDefFormat)
(virStorageVolDefFormat): Likewise.
* src/conf/domain_conf.h (_virDomainDef): Document unit used
internally.
* src/conf/storage_conf.h (_virStoragePoolDef, _virStorageVolDef):
Likewise.
* tests/*data/*.xml: Update all tests.
* tests/*out/*.xml: Likewise.
* tests/define-dev-segfault: Likewise.
* tests/openvzutilstest.c (testReadNetworkConf): Likewise.
* tests/qemuargv2xmltest.c (blankProblemElements): Likewise.
---

corresponds to memory v1 1/3;
v2: also output units for storage, use 'unit=' not 'units=', use common RNG

Portions of this patch elided to reduce mail size; see cover letter
for git repo to see entire patch.

 docs/schemas/basictypes.rng|   10 +++-
 docs/schemas/domaincommon.rng  |   25 +++
 docs/schemas/storagepool.rng   |6 ++--
 docs/schemas/storagevol.rng|   14 +-
 src/conf/domain_conf.c |   21 
 src/conf/domain_conf.h |   12 
 src/conf/storage_conf.c|   12 
 src/conf/storage_conf.h|   12 
 tests/define-dev-segfault  |4 +-
 tests/domainschemadata/domain-lxc-simple.xml   |2 +-
 tests/domainschemadata/portprofile.xml |2 +-
 .../qemu-simple-description-title.xml  |4 +-
 tests/domainschemadata/timers.xml  |4 +-
 tests/domainsnapshotxml2xmlout/disk_snapshot.xml   |4 +-
 tests/domainsnapshotxml2xmlout/full_domain.xml |4 +-
 tests/domainsnapshotxml2xmlout/metadata.xml|4 +-
 tests/openvzutilstest.c|4 +-
 tests/qemuargv2xmltest.c   |5 ++-
 .../qemuxml2argv-balloon-device-auto.xml   |4 +-
 .../qemuxml2argv-balloon-device.xml|4 +-
 tests/qemuxml2argvdata/qemuxml2argv-bios.xml   |4 +-
 .../qemuxml2argvdata/qemuxml2argv-blkdeviotune.xml |4 +-
 .../qemuxml2argv-blkiotune-device.xml  |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-blkiotune.xml  |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.xml |4 +-
 .../qemuxml2argv-boot-complex-bootindex.xml|4 +-
 .../qemuxml2argvdata/qemuxml2argv-boot-complex.xml |4 +-
 .../qemuxml2argvdata/qemuxml2argv-boot-floppy.xml  |4 +-
 ...uxml2argv-boot-menu-disable-drive-bootindex.xml |4 +-
 .../qemuxml2argv-boot-menu-disable-drive.xml   |4 +-
 .../qemuxml2argv-boot-menu-disable.xml |4 +-
 .../qemuxml2argv-boot-menu-enable.xml  |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-boot-multi.xml |4 +-
 .../qemuxml2argvdata/qemuxml2argv-boot-network.xml |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-boot-order.xml |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-bootloader.xml |4 +-
 .../qemuxml2argv-channel-guestfwd.xml  |4 +-
 .../qemuxml2argv-channel-spicevmc-old.xml  |2 +-
 .../qemuxml2argv-channel-spicevmc.xml  |2 +-
 .../qemuxml2argv-channel-virtio-auto.xml   |4 +-
 .../qemuxml2argv-channel-virtio.xml|4 +-
 .../qemuxml2argvdata/qemuxml2argv-clock-france.xml |4 +-
 .../qemuxml2argv-clock-localtime.xml   |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-clock-utc.xml  |4 +-
 .../qemuxml2argv-clock-variable.xml|4 +-
 .../qemuxml2argv-console-compat-auto.xml   |4 +-
 .../qemuxml2argv-console-compat-chardev.xml|4 +-
 .../qemuxml2argv-console-compat.xml|4 +-
 .../qemuxml2argv-console-virtio-many.xml   |4 +-
 .../qemuxml2argv-console-virtio.xml|4 +-
 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml |4 +-
 .../qemuxml2argv-cpu-exact2-nofallback.xml |4 +-
 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.xml |4 +-
 .../qemuxml2argvdata/qemuxml2argv-cpu-fallback.xml |4 +-
 .../qemuxml2argv-cpu-host-kvmclock.xml |4 +-
 

[libvirt] [PATCHv2 10/15] xml: allow scaled memory on input

2012-03-05 Thread Eric Blake
Output is still in kibibytes, but input can now be in different
scales for ease of typing.

* src/conf/domain_conf.c (virDomainParseMemory): New helper.
(virDomainDefParseXML): Use it when parsing.
* docs/schemas/domaincommon.rng: Expand XML; rename memoryKBElement
to memoryElement and update callers.
* docs/formatdomain.html.in (elementsMemoryAllocation): Document
scaling.
* tests/qemuxml2argvdata/qemuxml2argv-memtune.xml: Adjust test.
* tests/qemuxml2xmltest.c: Likewise.
* tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml: New file.
---

v2: reuse code introduced earlier in series, add tests

 docs/formatdomain.html.in  |   42 +++--
 docs/schemas/domaincommon.rng  |   23 ++
 src/conf/domain_conf.c |   93 +++
 tests/qemuxml2argvdata/qemuxml2argv-memtune.xml|6 +-
 .../qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml  |   31 +++
 tests/qemuxml2xmltest.c|2 +-
 6 files changed, 147 insertions(+), 50 deletions(-)
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 0855c7f..1e4a990 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -415,8 +415,8 @@
 pre
 lt;domaingt;
   ...
-  lt;memorygt;524288lt;/memorygt;
-  lt;currentMemorygt;524288lt;/currentMemorygt;
+  lt;memory unit='KiB'gt;524288lt;/memorygt;
+  lt;currentMemory unit='KiB'gt;524288lt;/currentMemorygt;
   ...
 lt;/domaingt;
 /pre
@@ -424,12 +424,30 @@
 dl
   dtcodememory/code/dt
   ddThe maximum allocation of memory for the guest at boot time.
-The units for this value are kibibytes (i.e. blocks of 1024 bytes)/dd
+The units for this value are determined by the optional
+atttribute codeunit/code, which defaults to KiB
+(kibibytes, 2sup10/sup or blocks of 1024 bytes).  Valid
+units are b or bytes for bytes, KB for kilobytes
+(10sup3/sup or 1,000), k or KiB for kibibytes (1024),
+MB for megabytes (10sup6/sup or 1,000,000), M or MiB
+for mebibytes (2sup20/sup or 1,048,576), GB for
+gigabytes (10sup9/sup or 1,000,000,000), G or GiB for
+gibibytes (2sup30/sup or 1,073,741,824), TB for
+terabytes (10sup12/sup or 1,000,000,000,000), or T or
+TiB for tebibytes (2sup40/sup or 1,099,511,627,776).
+However, the value will be rounded up to the nearest kibibyte
+by libvirt, and may be further rounded to the granularity
+supported by the hypervisor.  Some hypervisors also enforce a
+minimum, such as
+4000KiB. span class='since'codeunit/code since
+0.9.11/span/dd
   dtcodecurrentMemory/code/dt
   ddThe actual allocation of memory for the guest. This value can
 be less than the maximum allocation, to allow for ballooning
 up the guests memory on the fly. If this is omitted, it defaults
-to the same value as the codememory/code element/dd
+to the same value as the codememory/code element.
+The codeunit/code attribute behaves the same as
+for codememory/code./dd
 /dl


@@ -460,10 +478,10 @@
 lt;domaingt;
   ...
   lt;memtunegt;
-lt;hard_limitgt;1048576lt;/hard_limitgt;
-lt;soft_limitgt;131072lt;/soft_limitgt;
-lt;swap_hard_limitgt;2097152lt;/swap_hard_limitgt;
-lt;min_guaranteegt;65536lt;/min_guaranteegt;
+lt;hard_limit unit='G'gt;1lt;/hard_limitgt;
+lt;soft_limit unit='M'gt;128lt;/soft_limitgt;
+lt;swap_hard_limit unit='G'gt;2lt;/swap_hard_limitgt;
+lt;min_guarantee unit='bytes'gt;67108864lt;/min_guaranteegt;
   lt;/memtunegt;
   ...
 lt;/domaingt;
@@ -477,7 +495,13 @@
 parameters are applied to the QEMU process as a whole. Thus, when
 counting them, one needs to add up guest RAM, guest video RAM, and
 some memory overhead of QEMU itself. The last piece is hard to
-determine so one needs guess and try./dd
+determine so one needs guess and try.  For each tunable, it
+is possible to designate which unit the number is in on
+input, using the same values as
+for codelt;memorygt;/code.  For backwards
+compatibility, output is always in
+KiB.  span class='since'codeunit/code
+since 0.9.11/span/dd
   dtcodehard_limit/code/dt
   dd The optional codehard_limit/code element is the maximum memory
 the guest can use. The units for this value are kibibytes (i.e. blocks
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 99b3861..dfa1d1e 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -412,11 +412,11 @@
   define name=resources
 interleave
   element name=memory
-ref name='memoryKBElement'/
+ref name='scaledInteger'/
   /element
   optional
 element name=currentMemory
-  ref 

[libvirt] [PATCHv2 11/15] virsh: add option aliases

2012-03-05 Thread Eric Blake
In the past, we have created some virsh options with less-than-stellar
names.  For back-compat reasons, those names must continue to parse,
but we don't want to document them in help output.  This introduces
a new option type, an alias, which points to a canonical option name
later in the option list.

I'm actually quite impressed that our code has already been factored
to do all option parsing through common entry points, such that I
got this added in relatively few lines of code!

* tools/virsh.c (VSH_OT_ALIAS): New option type.
(opts_echo): Hook up an alias, for easy testing.
(vshCmddefOptParse, vshCmddefHelp, vshCmddefGetOption): Allow for
aliases.
* tests/virshtest.c (mymain): Test new feature.
---

v2: no real change

 tests/virshtest.c |6 ++
 tools/virsh.c |   28 ++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/tests/virshtest.c b/tests/virshtest.c
index 6474c19..87b1336 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -386,6 +386,12 @@ mymain(void)
 DO_TEST(30, --shell a\n,
 echo \t '-'\-\ \t --shell \t a);

+/* Tests of alias handling.  */
+DO_TEST(31, hello\n, echo, --string, hello);
+DO_TEST(32, hello\n, echo --string hello);
+DO_TEST(33, hello\n, echo, --str, hello);
+DO_TEST(34, hello\n, echo --str hello);
+
 # undef DO_TEST

 VIR_FREE(custom_uri);
diff --git a/tools/virsh.c b/tools/virsh.c
index aef050f..77cf4ac 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -138,7 +138,8 @@ typedef enum {
 VSH_OT_STRING,   /* optional string option */
 VSH_OT_INT,  /* optional or mandatory int option */
 VSH_OT_DATA, /* string data (as non-option) */
-VSH_OT_ARGV  /* remaining arguments */
+VSH_OT_ARGV, /* remaining arguments */
+VSH_OT_ALIAS,/* alternate spelling for a later argument */
 } vshCmdOptType;

 /*
@@ -190,7 +191,8 @@ typedef struct {
 const char *name;   /* the name of option, or NULL for list end */
 vshCmdOptType type; /* option type */
 unsigned int flags; /* flags */
-const char *help;   /* non-NULL help string */
+const char *help;   /* non-NULL help string; or for VSH_OT_ALIAS
+ * the name of a later public option */
 } vshCmdOptDef;

 /*
@@ -15209,6 +15211,7 @@ static const vshCmdInfo info_echo[] = {
 static const vshCmdOptDef opts_echo[] = {
 {shell, VSH_OT_BOOL, 0, N_(escape for shell use)},
 {xml, VSH_OT_BOOL, 0, N_(escape for XML use)},
+{str, VSH_OT_ALIAS, 0, string},
 {string, VSH_OT_ARGV, 0, N_(arguments to echo)},
 {NULL, 0, 0, NULL}
 };
@@ -17256,6 +17259,18 @@ vshCmddefOptParse(const vshCmdDef *cmd, uint32_t 
*opts_need_arg,
 return -1; /* bool options can't be mandatory */
 continue;
 }
+if (opt-type == VSH_OT_ALIAS) {
+int j;
+if (opt-flags || !opt-help)
+return -1; /* alias options are tracked by the original name */
+for (j = i + 1; cmd-opts[j].name; j++) {
+if (STREQ(opt-help, cmd-opts[j].name))
+break;
+}
+if (!cmd-opts[j].name)
+return -1; /* alias option must map to a later option name */
+continue;
+}
 if (opt-flags  VSH_OFLAG_REQ_OPT) {
 if (opt-flags  VSH_OFLAG_REQ)
 *opts_required |= 1  i;
@@ -17287,6 +17302,10 @@ vshCmddefGetOption(vshControl *ctl, const vshCmdDef 
*cmd, const char *name,
 const vshCmdOptDef *opt = cmd-opts[i];

 if (STREQ(opt-name, name)) {
+if (opt-type == VSH_OT_ALIAS) {
+name = opt-help;
+continue;
+}
 if ((*opts_seen  (1  i))  opt-type != VSH_OT_ARGV) {
 vshError(ctl, _(option --%s already seen), name);
 return NULL;
@@ -17465,6 +17484,9 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)
 : _([%s]...);
 }
 break;
+case VSH_OT_ALIAS:
+/* aliases are intentionally undocumented */
+continue;
 default:
 assert(0);
 }
@@ -17506,6 +17528,8 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)
  shortopt ? _([--%s] string) : _(%s),
  opt-name);
 break;
+case VSH_OT_ALIAS:
+continue;
 default:
 assert(0);
 }
-- 
1.7.7.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv2 08/15] xml: use long long internally, to centralize overflow checks

2012-03-05 Thread Eric Blake
On 64-bit platforms, unsigned long and unsigned long long are
identical, so we don't have to worry about overflow checks.
On 32-bit platforms, anywhere we narrow unsigned long long back
to unsigned long, we have to worry about overflow; it's easier
to do this in one place by having most of the code use the same
or wider types, and only doing the narrowing at the last minute.
Therefore, the memory set commands remain unsigned long, and
the memory get command now centralizes the overflow check into
libvirt.c, so that drivers don't have to repeat the work.

* src/driver.h (virDrvDomainGetMaxMemory): Use long long.
* src/libvirt.c (virDomainGetMaxMemory): Raise overflow.
* src/test/test_driver.c (testGetMaxMemory): Fix driver.
* src/rpc/gendispatch.pl (name_to_ProcName): Likewise.
* src/xen/xen_hypervisor.c (xenHypervisorGetMaxMemory): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainGetMaxMemory): Likewise.
* src/xen/xend_internal.c (xenDaemonDomainGetMaxMemory):
Likewise.
* src/xen/xend_internal.h (xenDaemonDomainGetMaxMemory):
Likewise.
* src/xen/xm_internal.c (xenXMDomainGetMaxMemory): Likewise.
* src/xen/xm_internal.h (xenXMDomainGetMaxMemory): Likewise.
* src/xen/xs_internal.c (xenStoreDomainGetMaxMemory): Likewise.
* src/xen/xs_internal.h (xenStoreDomainGetMaxMemory): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainGetMaxMemory):
Likewise.
* src/esx/esx_driver.c (esxDomainGetMaxMemory): Likewise.
* src/libxl/libxl_driver.c (libxlDomainGetMaxMemory): Likewise.
* src/qemu/qemu_driver.c (qemudDomainGetMaxMemory): Likewise.
* src/lxc/lxc_driver.c (lxcDomainGetMaxMemory): Likewise.
* src/uml/uml_driver.c (umlDomainGetMaxMemory): Likewise.
---

v2: new

 src/driver.h   |2 +-
 src/esx/esx_driver.c   |4 ++--
 src/libvirt.c  |7 ++-
 src/libxl/libxl_driver.c   |8 
 src/lxc/lxc_driver.c   |6 --
 src/qemu/qemu_driver.c |8 +---
 src/rpc/gendispatch.pl |1 -
 src/test/test_driver.c |4 ++--
 src/uml/uml_driver.c   |6 --
 src/xen/xen_driver.c   |6 +++---
 src/xen/xen_hypervisor.c   |4 ++--
 src/xen/xend_internal.c|   12 ++--
 src/xen/xend_internal.h|4 ++--
 src/xen/xm_internal.c  |6 +++---
 src/xen/xm_internal.h  |4 ++--
 src/xen/xs_internal.c  |   10 +-
 src/xen/xs_internal.h  |4 ++--
 src/xenapi/xenapi_driver.c |6 +++---
 18 files changed, 56 insertions(+), 46 deletions(-)

diff --git a/src/driver.h b/src/driver.h
index 212d2f5..03d249b 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -142,7 +142,7 @@ typedef int
  unsigned int flags);
 typedef char *
 (*virDrvDomainGetOSType)   (virDomainPtr domain);
-typedef unsigned long
+typedef unsigned long long
 (*virDrvDomainGetMaxMemory)(virDomainPtr domain);
 typedef int
 (*virDrvDomainSetMaxMemory)(virDomainPtr domain,
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index b6b22f8..6943534 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2,7 +2,7 @@
 /*
  * esx_driver.c: core driver functions for managing VMware ESX hosts
  *
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 Red Hat, Inc.
  * Copyright (C) 2009-2011 Matthias Bolte matthias.bo...@googlemail.com
  * Copyright (C) 2009 Maximilian Wilhelm m...@rfc2324.org
  *
@@ -2073,7 +2073,7 @@ esxDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED)



-static unsigned long
+static unsigned long long
 esxDomainGetMaxMemory(virDomainPtr domain)
 {
 esxPrivate *priv = domain-conn-privateData;
diff --git a/src/libvirt.c b/src/libvirt.c
index de23db8..73fb8de 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3602,10 +3602,15 @@ virDomainGetMaxMemory(virDomainPtr domain)
 conn = domain-conn;

 if (conn-driver-domainGetMaxMemory) {
-unsigned long ret;
+unsigned long long ret;
 ret = conn-driver-domainGetMaxMemory (domain);
 if (ret == 0)
 goto error;
+if ((unsigned long) ret != ret) {
+virLibDomainError(VIR_ERR_OVERFLOW, _(result too large: %llu),
+  ret);
+goto error;
+}
 return ret;
 }

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index d5fa64a..a7bb751 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1,7 +1,7 @@
 /*---*/
-/*  Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
+/*  Copyright (C) 2006-2012 Red Hat, Inc.
+ *  Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
  *  Copyright (C) 2011 Univention GmbH.
- *  Copyright (C) 2006-2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1592,12 +1592,12 @@ cleanup:
 return type;
 }

-static 

[libvirt] [PATCH 3/4 v3] virnetdevvportprofile: Changes to support portprofiles for hostdevs

2012-03-05 Thread Roopa Prabhu
From: Roopa Prabhu ropra...@cisco.com

This patch includes the following changes
- removes some netlink functions which are now available in virnetdev.c
- Adds a vf argument to all port profile functions

For 802.1Qbh devices, the port profile calls can use a vf argument if
passed by the caller. If the vf argument is -1 it will try to derive the vf
if the device passed is a virtual function.

For 802.1Qbg devices, This patch introduces a null check for the device
argument because during port profile assignment on a hostdev, this argument
can be null. Stefan CC'ed for comments

Signed-off-by: Roopa Prabhu ropra...@cisco.com
---
 src/qemu/qemu_migration.c|2 
 src/util/virnetdevmacvlan.c  |8 +
 src/util/virnetdevvportprofile.c |  221 --
 src/util/virnetdevvportprofile.h |8 +
 4 files changed, 59 insertions(+), 180 deletions(-)


diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 5c4297c..77d40c0 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2650,6 +2650,7 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def) 
{

virDomainNetGetActualVirtPortProfile(net),
net-mac,

virDomainNetGetActualDirectDev(net),
+   -1,
def-uuid,

VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_FINISH, false)  0)
 goto err_exit;
@@ -2667,6 +2668,7 @@ err_exit:

virDomainNetGetActualVirtPortProfile(net),
net-mac,

virDomainNetGetActualDirectDev(net),
+   -1,

VIR_NETDEV_VPORT_PROFILE_OP_MIGRATE_IN_FINISH));
 }
 }
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index f38a98c..647679f 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -452,6 +452,7 @@ struct virNetlinkCallbackData {
 virNetDevVPortProfilePtr virtPortProfile;
 unsigned char *macaddress;
 char *linkdev;
+int vf;
 unsigned char *vmuuid;
 enum virNetDevVPortProfileOp vmOp;
 unsigned int linkState;
@@ -719,6 +720,7 @@ virNetDevMacVLanVPortProfileCallback(unsigned char *msg,
 calld-virtPortProfile,
 calld-macaddress,
 calld-linkdev,
+calld-vf,
 calld-vmuuid,
 calld-vmOp, true));
 *handled = true;
@@ -810,6 +812,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char 
*tgifname,
 const char *cr_ifname;
 virNetlinkCallbackDataPtr calld = NULL;
 int ret;
+int vf = -1;
 
 macvtapMode = modeMap[mode];
 
@@ -871,6 +874,7 @@ create_name:
virtPortProfile,
macaddress,
linkdev,
+   vf,
vmuuid, vmOp, false)  0) {
 rc = -1;
 goto link_del_exit;
@@ -948,6 +952,7 @@ disassociate_exit:
virtPortProfile,
macaddress,
linkdev,
+   vf,
vmOp));
 
 link_del_exit:
@@ -975,6 +980,8 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char 
*ifname,
char *stateDir)
 {
 int ret = 0;
+int vf = -1;
+
 if (mode == VIR_NETDEV_MACVLAN_MODE_PASSTHRU) {
 ignore_value(virNetDevRestoreMacAddress(linkdev, stateDir));
 }
@@ -984,6 +991,7 @@ int virNetDevMacVLanDeleteWithVPortProfile(const char 
*ifname,
   virtPortProfile,
   macaddr,
   linkdev,
+  vf,
   
VIR_NETDEV_VPORT_PROFILE_OP_DESTROY)  0)
 ret = -1;
 if (virNetDevMacVLanDelete(ifname)  0)
diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index f6db292..bd356d8 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -126,11 +126,6 @@ static struct 

[libvirt] [PATCH 2/4 v3] virtnetdev: Add support functions for mac and portprofile associations on a hostdev

2012-03-05 Thread Roopa Prabhu
From: Roopa Prabhu ropra...@cisco.com

This patch adds the following:
- functions to set and get vf configs
- Functions to replace and store vf configs (Only mac address is handled today.
  But the functions can be easily extended for vlans and other vf configs)
- function to dump link dev info (This is moved from virnetdevvportprofile.c)

Signed-off-by: Roopa Prabhu ropra...@cisco.com
---
 src/util/virnetdev.c |  535 ++
 src/util/virnetdev.h |   19 ++
 2 files changed, 553 insertions(+), 1 deletions(-)


diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 4aa7639..9f93fda 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -1127,8 +1127,47 @@ virNetDevGetPhysicalFunction(const char *ifname, char 
**pfname)
 
 return ret;
 }
-#else /* !__linux__ */
 
+/**
+ * virNetDevGetVirtualFunctionInfo:
+ * @vfname: name of the virtual function interface
+ * @pfname: name of the physical function
+ * @vf: vf index
+ *
+ * Returns 0 on success, -errno on failure.
+ *
+ */
+int
+virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname,
+int *vf)
+{
+char *pf_sysfs_path = NULL, *vf_sysfs_path = NULL;
+int ret = -1;
+
+*pfname = NULL;
+
+if (virNetDevGetPhysicalFunction(vfname, pfname)  0)
+return ret;
+
+if (virNetDevSysfsFile(pf_sysfs_path, *pfname, device)  0)
+goto cleanup;
+
+if (virNetDevSysfsFile(vf_sysfs_path, vfname, device)  0)
+goto cleanup;
+
+ret = pciGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf);
+
+cleanup:
+if (ret  0)
+VIR_FREE(*pfname);
+
+VIR_FREE(vf_sysfs_path);
+VIR_FREE(pf_sysfs_path);
+
+return ret;
+}
+
+#else /* !__linux__ */
 int
 virNetDevGetVirtualFunctions(const char *pfname ATTRIBUTE_UNUSED,
  char ***vfname ATTRIBUTE_UNUSED,
@@ -1165,4 +1204,498 @@ virNetDevGetPhysicalFunction(const char *ifname 
ATTRIBUTE_UNUSED,
  _(Unable to get physical function status on this 
platform));
 return -1;
 }
+
 #endif /* !__linux__ */
+#if defined(__linux__)  defined(HAVE_LIBNL)
+
+static struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
+[IFLA_VF_MAC]   = { .type = NLA_UNSPEC,
+.maxlen = sizeof(struct ifla_vf_mac) },
+[IFLA_VF_VLAN]  = { .type = NLA_UNSPEC,
+.maxlen = sizeof(struct ifla_vf_vlan) },
+};
+
+/**
+ * virNetDevLinkDump:
+ *
+ * @ifname: The name of the interface; only use if ifindex  0
+ * @ifindex: The interface index; may be  0 if ifname is given
+ * @nltarget_kernel: whether to send the message to the kernel or another
+ *   process
+ * @nlattr: pointer to a pointer of netlink attributes that will contain
+ *  the results
+ * @recvbuf: Pointer to the buffer holding the returned netlink response
+ *   message; free it, once not needed anymore
+ * @getPidFunc: Pointer to a function that will be invoked if the kernel
+ *  is not the target of the netlink message but it is to be
+ *  sent to another process.
+ *
+ * Get information about an interface given its name or index.
+ *
+ * Returns 0 on success, -1 on fatal error.
+ */
+int
+virNetDevLinkDump(const char *ifname, int ifindex,
+  bool nltarget_kernel, struct nlattr **tb,
+  unsigned char **recvbuf,
+  uint32_t (*getPidFunc)(void))
+{
+int rc = 0;
+struct nlmsghdr *resp;
+struct nlmsgerr *err;
+struct ifinfomsg ifinfo = {
+.ifi_family = AF_UNSPEC,
+.ifi_index  = ifindex
+};
+unsigned int recvbuflen;
+uint32_t pid = 0;
+struct nl_msg *nl_msg;
+
+*recvbuf = NULL;
+
+if (ifname  ifindex = 0  virNetDevGetIndex(ifname, ifindex)  0)
+return -1;
+
+ifinfo.ifi_index = ifindex;
+
+nl_msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST);
+if (!nl_msg) {
+virReportOOMError();
+return -1;
+}
+
+if (nlmsg_append(nl_msg,  ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO)  0)
+goto buffer_too_small;
+
+if (ifname) {
+if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname)  0)
+goto buffer_too_small;
+}
+
+if (!nltarget_kernel) {
+pid = getPidFunc();
+if (pid == 0) {
+rc = -1;
+goto cleanup;
+}
+}
+
+if (virNetlinkCommand(nl_msg, recvbuf, recvbuflen, pid)  0) {
+rc = -1;
+goto cleanup;
+}
+
+if (recvbuflen  NLMSG_LENGTH(0) || *recvbuf == NULL)
+goto malformed_resp;
+
+resp = (struct nlmsghdr *)*recvbuf;
+
+switch (resp-nlmsg_type) {
+case NLMSG_ERROR:
+err = (struct nlmsgerr *)NLMSG_DATA(resp);
+if (resp-nlmsg_len  NLMSG_LENGTH(sizeof(*err)))
+goto malformed_resp;
+
+if (err-error) {
+virReportSystemError(-err-error,
+ 

[libvirt] [PATCH 4/4 v3] qemu_hostdev: Add support to install port profile and mac address on hostdevs

2012-03-05 Thread Roopa Prabhu
From: Roopa Prabhu ropra...@cisco.com

These changes are applied only if the hostdev has a parent net device.
If the parent netdevice has virtual port information, the original virtualport
associate functions are called (these set and restore both mac and port profile
on an interface). Else, only mac address is set on the device
using other methods depending on if its a sriov device or not.

Changes also include hotplug pci devices

Signed-off-by: Roopa Prabhu ropra...@cisco.com
---
 src/qemu/qemu_hostdev.c |  241 +--
 src/qemu/qemu_hostdev.h |8 +-
 src/qemu/qemu_hotplug.c |   10 ++
 3 files changed, 246 insertions(+), 13 deletions(-)


diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index b3cad8e..ebcdc52 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -29,6 +29,13 @@
 #include memory.h
 #include pci.h
 #include hostusb.h
+#include virnetdev.h
+
+VIR_ENUM_IMPL(virNetDevVPort, VIR_NETDEV_VPORT_PROFILE_LAST,
+  none,
+  802.1Qbg,
+  802.1Qbh,
+  openvswitch)
 
 static pciDeviceList *
 qemuGetPciHostDeviceList(virDomainHostdevDefPtr *hostdevs, int nhostdevs)
@@ -156,19 +163,192 @@ int qemuUpdateActivePciHostdevs(struct qemud_driver 
*driver,
 return 0;
 }
 
+static int
+qemuDomainHostdevPciSysfsPath(virDomainHostdevDefPtr hostdev, char 
**sysfs_path)
+{
+struct pci_config_address config_address;
+
+config_address.domain = hostdev-source.subsys.u.pci.domain;
+config_address.bus = hostdev-source.subsys.u.pci.bus;
+config_address.slot = hostdev-source.subsys.u.pci.slot;
+config_address.function = hostdev-source.subsys.u.pci.function;
+
+return pciConfigAddressToSysfsFile(config_address, sysfs_path);
+}
+
+int
+qemuDomainHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev)
+{
+char *sysfs_path = NULL;
+int ret = -1;
+
+if (qemuDomainHostdevPciSysfsPath(hostdev, sysfs_path)  0)
+return ret;
+
+ret = pciDeviceIsVirtualFunction(sysfs_path);
+
+VIR_FREE(sysfs_path);
+
+return ret;
+}
+
+static int
+qemuDomainHostdevNetDevice(virDomainHostdevDefPtr hostdev, char **linkdev,
+   int *vf)
+{
+int ret = -1;
+char *sysfs_path = NULL;
+
+if (qemuDomainHostdevPciSysfsPath(hostdev, sysfs_path)  0)
+return ret;
+
+if (pciDeviceIsVirtualFunction(sysfs_path) == 1) {
+if (pciDeviceGetVirtualFunctionInfo(sysfs_path, linkdev,
+vf)  0)
+goto cleanup;
+} else {
+if (pciDeviceNetName(sysfs_path, linkdev)  0)
+goto cleanup;
+*vf = -1;
+}
+
+ret = 0;
+
+cleanup:
+VIR_FREE(sysfs_path);
+
+return ret;
+}
+
+static int
+qemuDomainHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
+  virNetDevVPortProfilePtr virtPort,
+  const unsigned char *macaddr,
+  const unsigned char *uuid,
+  int associate)
+{
+int ret = -1;
+
+if (!virtPort)
+return ret;
+
+switch(virtPort-virtPortType) {
+case VIR_NETDEV_VPORT_PROFILE_NONE:
+case VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH:
+case VIR_NETDEV_VPORT_PROFILE_8021QBG:
+case VIR_NETDEV_VPORT_PROFILE_LAST:
+qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(virtualport type %s is 
+currently not supported on interfaces of type 
+hostdev),
+virNetDevVPortTypeToString(virtPort-virtPortType));
+break;
+
+case VIR_NETDEV_VPORT_PROFILE_8021QBH:
+if (associate)
+ret = virNetDevVPortProfileAssociate(NULL, virtPort, macaddr,
+ linkdev, vf, uuid,
+ 
VIR_NETDEV_VPORT_PROFILE_OP_CREATE, false);
+else
+ret = virNetDevVPortProfileDisassociate(NULL, virtPort,
+macaddr, linkdev, vf,
+
VIR_NETDEV_VPORT_PROFILE_OP_DESTROY);
+break;
+}
+
+return ret;
+}
+
+int
+qemuDomainHostdevNetConfigReplace(virDomainHostdevDefPtr hostdev,
+  const unsigned char *uuid,
+  char *stateDir)
+{
+char *linkdev = NULL;
+virNetDevVPortProfilePtr virtPort;
+int ret = -1;
+int vf = -1;
+int vlanid = -1;
+int port_profile_associate = 1;
+int isvf;
+
+isvf = qemuDomainHostdevIsVirtualFunction(hostdev);
+if (isvf = 0) {
+qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+_(Interface type hostdev is currently supported on
+ sriov Virtual functions only));
+return ret;
+}
+
+if 

[libvirt] [PATCH 0/4 v3] Support mac and port profile for interface type='hostdev'

2012-03-05 Thread Roopa Prabhu
v3: 
Changes include:
- Review comments from Laine
- rebased with latest upstream

v2:
changes include:
- feedback from stefan for 802.1Qbg. Code now prints an error if virtualport is 
specified for 802.1Qbg on an interface of type hostdev
- feedback from laine for non-sriov devices. Interface type hostdev for 
non-sriov devices
is not supported. 

v1: https://www.redhat.com/archives/libvir-list/2012-March/msg00015.html

This patch series is based on laines patches to support interface 
type='hostdev'.
https://www.redhat.com/archives/libvir-list/2012-February/msg01126.html

It support to set mac and port profile on an interface of type hostdev.
* If virtualport is specified, the existing virtual port functions are
called to set mac, vlan and port profile.

* If virtualport is not specified and device is a sriov virtual function,
- mac is set using IFLA_VF_MAC

* If virtualport is not specified and device is a non-sriov virtual function,
- mac is set using existing SIOCGIFHWADDR (This requires that the
netdev be present on the host before starting the VM)

This series implements the below :
01/4 pci: Add two new pci util pciDeviceGetVirtualFunctionInfo and 
pciConfigAddressToSysfsFile
02/4 virtnetdev: Add support functions for mac and portprofile associations on 
a hostdev
03/4 virnetdevvportprofile: Changes to support portprofiles for hostdevs
04/4 qemu_hostdev: Add support to install port profile and mac address on 
hostdev

Stefan Berger is CC'ed for 802.1Qbg changes in patch 03/4. Current code for 
802.1Qbg uses macvtap ifname. And for network interfaces with type=hostdev a 
macvtap ifname does not exist. This patch just adds a null check for ifname in 
802.1Qbg port profile handling code.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/4 v3] pci: Add two new pci utils pciDeviceGetVirtualFunctionInfo and pciConfigAddressToSysfsFile

2012-03-05 Thread Roopa Prabhu
From: Roopa Prabhu ropra...@cisco.com

pciDeviceGetVirtualFunctionInfo returns pf netdevice name and virtual
function index for a given vf. This is just a wrapper around existing functions
to return vf's pf and vf_index with one api call

pciConfigAddressToSysfsfile returns the sysfile pci device link
from a 'struct pci_config_address'

Signed-off-by: Roopa Prabhu ropra...@cisco.com
---
 src/util/pci.c |   55 +++
 src/util/pci.h |7 +++
 2 files changed, 62 insertions(+), 0 deletions(-)


diff --git a/src/util/pci.c b/src/util/pci.c
index c660e8d..c8a5287 100644
--- a/src/util/pci.c
+++ b/src/util/pci.c
@@ -2081,6 +2081,20 @@ pciSysfsFile(char *pciDeviceName, char 
**pci_sysfs_device_link)
 return 0;
 }
 
+int
+pciConfigAddressToSysfsFile(struct pci_config_address *dev,
+char **pci_sysfs_device_link)
+{
+if (virAsprintf(pci_sysfs_device_link,
+PCI_SYSFS devices/%04x:%02x:%02x.%x, dev-domain,
+dev-bus, dev-slot, dev-function)  0) {
+virReportOOMError();
+return -1;
+}
+
+return 0;
+}
+
 /*
  * Returns the network device name of a pci device
  */
@@ -2123,6 +2137,38 @@ out:
 
  return ret;
 }
+
+int
+pciDeviceGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
+char **pfname, int *vf_index)
+{
+struct pci_config_address *pf_config_address = NULL;
+char *pf_sysfs_device_path = NULL;
+int ret = -1;
+
+if (pciGetPhysicalFunction(vf_sysfs_device_path, pf_config_address)  0)
+return ret;
+
+if (pciConfigAddressToSysfsFile(pf_config_address,
+pf_sysfs_device_path)  0) {
+
+VIR_FREE(pf_config_address);
+return ret;
+}
+
+if (pciGetVirtualFunctionIndex(pf_sysfs_device_path, vf_sysfs_device_path,
+vf_index)  0)
+goto cleanup;
+
+ret = pciDeviceNetName(pf_sysfs_device_path, pfname);
+
+cleanup:
+VIR_FREE(pf_config_address);
+VIR_FREE(pf_sysfs_device_path);
+
+return ret;
+}
+
 #else
 int
 pciGetPhysicalFunction(const char *vf_sysfs_path ATTRIBUTE_UNUSED,
@@ -2170,4 +2216,13 @@ pciDeviceNetName(char *device_link_sysfs_path 
ATTRIBUTE_UNUSED,
supported on non-linux platforms));
 return -1;
 }
+
+int
+pciDeviceGetVirtualFunctionInfo(const char *vf_sysfs_device_path 
ATTRIBUTE_UNUSED,
+char **pfname, int *vf_index ATTRIBUTE_UNUSED)
+{
+pciReportError(VIR_ERR_INTERNAL_ERROR, _(pciDeviceGetVirtualFunctionInfo 
+   is not supported on non-linux platforms));
+return -1;
+}
 #endif /* __linux__ */
diff --git a/src/util/pci.h b/src/util/pci.h
index 25b5b66..b71bb12 100644
--- a/src/util/pci.h
+++ b/src/util/pci.h
@@ -111,6 +111,9 @@ int pciGetVirtualFunctionIndex(const char 
*pf_sysfs_device_link,
const char *vf_sysfs_device_link,
int *vf_index);
 
+int pciConfigAddressToSysfsFile(struct pci_config_address *dev,
+char **pci_sysfs_device_link);
+
 int pciDeviceNetName(char *device_link_sysfs_path, char **netname);
 
 int pciSysfsFile(char *pciDeviceName, char **pci_sysfs_device_link)
@@ -122,4 +125,8 @@ int pciGetDeviceAddrString(unsigned domain,
unsigned function,
char **pciConfigAddr)
 ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;
+
+int pciDeviceGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
+char **pfname, int *vf_index);
+
 #endif /* __VIR_PCI_H__ */

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Add migration APIs for libxl driver

2012-03-05 Thread Jim Fehlig
Chunyan Liu wrote:
 Add migration APIs for libxl driver. 
 Implemented in migration version 3. Based on xen 4.1.
   

I didn't get a chance to test this yet, but have some initial review
comments.

 Signed-off-by: Chunyan Liu cy...@suse.com
 ---
  src/libxl/libxl_driver.c |  617 
 ++
  src/libxl/libxl_driver.h |   17 ++-
  2 files changed, 632 insertions(+), 2 deletions(-)

 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
 index d5fa64a..4037635 100644
 --- a/src/libxl/libxl_driver.c
 +++ b/src/libxl/libxl_driver.c
 @@ -30,6 +30,12 @@
  #include math.h
  #include libxl.h
  #include fcntl.h
 +#include stdlib.h
 +#include string.h
 +#include sys/types.h
 +#include sys/socket.h
 +#include arpa/inet.h
 +#include netdb.h
  
  #include internal.h
  #include logging.h
 @@ -60,6 +66,13 @@
  #define XEN_SCHED_CREDIT_NPARAM   2
  
  static libxlDriverPrivatePtr libxl_driver = NULL;
 +static virThread migrate_receive_thread;
   

This prevents receiving concurrent migrations.

 +
 +typedef struct migrate_receive_args {
 +virConnectPtr conn;
 +virDomainObjPtr vm;
 +int sockfd;
 +} migrate_receive_args;
   

If there is a future need to extend this structure, will it cause
incompatibility issues between a source with the extensions and a
destination without?  Or vise versa?

  
  /* Function declarations */
  static int
 @@ -1095,6 +1108,17 @@ libxlClose(virConnectPtr conn ATTRIBUTE_UNUSED)
  return 0;
  }
  
 +static int
 +libxlSupportsFeature(virConnectPtr conn ATTRIBUTE_UNUSED, int feature)
 +{
 +switch (feature) {
 +case VIR_DRV_FEATURE_MIGRATION_V3:
 +return 1;
 +default:
 +return 0;
 +}
 +}
 +
  static const char *
  libxlGetType(virConnectPtr conn ATTRIBUTE_UNUSED)
  {
 @@ -3842,12 +3866,600 @@ libxlIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
  return 1;
  }
  
 +static int libxlReadFixedMessage(int fd, const void *msg, int msgsz)
 +{
 +char buf[msgsz];
 +
 +if (saferead(fd, buf, msgsz) != msgsz || memcmp(buf, msg, msgsz)) {
 +return -1;
 +}
 +
 +return 0;
 +}
 +
 +static int doParseURI(const char *uri, char **p_hostname, int *p_port)
 +{
 +char *p, *hostname;
 +char port[16] = 0;
 +
 +if (strstr (uri, //)) {   /* Full URI. */
 +virURIPtr uriptr = virURIParse(uri);
 +if (!uriptr) {
 +libxlError(VIR_ERR_INVALID_ARG,
 +   _(Invalid URI));
 +return -1;
 +}
 +if (uriptr-scheme  STRCASENEQ(uriptr-scheme, xlmigr)) {
 +libxlError(VIR_ERR_INVALID_ARG,
 +_(Only xlmigr://
 + migrations are supported by Xen));
 +xmlFreeURI(uriptr);
 +return -1;
 +}
   

This is just tcp migration.  Any reason for requiring the xlmigr scheme?

 +if (!uriptr-server) {
 +libxlError(VIR_ERR_INVALID_ARG,
 +  _(A hostname must be
 + specified in the URI));
 +xmlFreeURI(uriptr);
 +return -1;
 +}
 +hostname = strdup(uriptr-server);
   

I think it would be better to rework this, and other uses of strdup()
and snprintf() in this function, to use virAsprintf().

 +if (!hostname) {
 +virReportOOMError();
 +xmlFreeURI(uriptr);
 +return -1;
 +}
 +if (uriptr-port)
 +snprintf(port, sizeof(port), %d, uriptr-port);
 +xmlFreeURI(uriptr);
 +}
 +else if ((p = strrchr(uri, ':')) != NULL) { /* hostname:port */
 +int port_nr, n;
 +
 +if (virStrToLong_i(p+1, NULL, 10, port_nr)  0) {
 +libxlError(VIR_ERR_INVALID_ARG,
 + _(Invalid port number));
 +return -1;
 +}
 +snprintf(port, sizeof(port), %d, port_nr);
 +
 +/* Get the hostname. */
 +n = p - uri; /* n = Length of hostname in bytes. */
 +hostname = strdup(uri);
 +if (!hostname) {
 +virReportOOMError();
 +return -1;
 +}
 +hostname[n] = '\0';
 +}
 +else {/* hostname (or IP address) */
 +hostname = strdup(uri);
 +if (!hostname) {
 +virReportOOMError();
 +return -1;
 +}
 +}
 +*p_hostname = hostname;
 +*p_port = atoi(port);
 +return 0;
 +}
 +
 +static bool libxlMigrationFromIsAllowed(libxlDriverPrivatePtr driver, 
 virDomainObjPtr vm)
 +{
 +/* to be extended */
 +VIR_DEBUG(driver=%p, vm=%p, driver, vm);
 +return true;
 +}
 +
 +static bool libxlMigrationToIsAllowed(libxlDriverPrivatePtr driver, 
 virDomainDefPtr def)
 +{
 +/* to be extended */
 +VIR_DEBUG(driver=%p, def=%p, driver, def);
 +return true;
 +}
   

I think these functions (and their call sites) can be added in a future
patch that provides an implementation.

 +
 +static char *
 

Re: [libvirt] [PATCH] Add migration APIs for libxl driver

2012-03-05 Thread Chun Yan Liu
 I didn't get a chance to test this yet, but have some initial review
 comments.

 Signed-off-by: Chunyan Liu 
 ---
  src/libxl/libxl_driver.c |  617
 ++
  src/libxl/libxl_driver.h |   17 ++-
  2 files changed, 632 insertions(+), 2 deletions(-)

 diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
 index d5fa64a..4037635 100644
 --- a/src/libxl/libxl_driver.c
 +++ b/src/libxl/libxl_driver.c
 @@ -30,6 +30,12 @@
  #include 
  #include 
  #include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 

  #include internal.h
  #include logging.h
 @@ -60,6 +66,13 @@
  #define XEN_SCHED_CREDIT_NPARAM   2

  static libxlDriverPrivatePtr libxl_driver = NULL;
 +static virThread migrate_receive_thread;


 This prevents receiving concurrent migrations.
Yes. It is a problem. Defined as static is to be used in Begin3 function 
virThreadCreate and in Finish3() function virThreadJoin, but actually the 
thread will exit when receiving data completed or meets error, so virThreadJoin 
doesn't have much effect here. If a call of virThreadJoin is not needed, then 
can specify migrate_receive_thread as a local variable.


 +
 +typedef struct migrate_receive_args {
 +virConnectPtr conn;
 +virDomainObjPtr vm;
 +int sockfd;
 +} migrate_receive_args;


 If there is a future need to extend this structure, will it cause
 incompatibility issues between a source with the extensions and a
 destination without?  Or vise versa?
It will if send logic and receive logic doesn't match. Maybe need to add some 
extra check, but seems no better way to completely avoid that?


  /* Function declarations */
  static int
 @@ -1095,6 +1108,17 @@ libxlClose(virConnectPtr conn ATTRIBUTE_UNUSED)
  return 0;
  }

 +static int
 +libxlSupportsFeature(virConnectPtr conn ATTRIBUTE_UNUSED, int feature)
 +{
 +switch (feature) {
 +case VIR_DRV_FEATURE_MIGRATION_V3:
 +return 1;
 +default:
 +return 0;
 +}
 +}
 +
  static const char *
  libxlGetType(virConnectPtr conn ATTRIBUTE_UNUSED)
  {
 @@ -3842,12 +3866,600 @@ libxlIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
  return 1;
  }

 +static int libxlReadFixedMessage(int fd, const void *msg, int msgsz)
 +{
 +char buf[msgsz];
 +
 +if (saferead(fd, buf, msgsz) != msgsz || memcmp(buf, msg, msgsz)) {
 +return -1;
 +}
 +
 +return 0;
 +}
 +
 +static int doParseURI(const char *uri, char **p_hostname, int *p_port)
 +{
 +char *p, *hostname;
 +char port[16] = 0;
 +
 +if (strstr (uri, //)) {   /* Full URI. */
 +virURIPtr uriptr = virURIParse(uri);
 +if (!uriptr) {
 +libxlError(VIR_ERR_INVALID_ARG,
 +   _(Invalid URI));
 +return -1;
 +}
 +if (uriptr-scheme  STRCASENEQ(uriptr-scheme, xlmigr)) {
 +libxlError(VIR_ERR_INVALID_ARG,
 +_(Only xlmigr://
 + migrations are supported by Xen));
 +xmlFreeURI(uriptr);
 +return -1;
 +}


 This is just tcp migration.  Any reason for requiring the xlmigr scheme?
It's not a necessary. Just refer to xen_driver syntax, migration uri could be 
[xlmigr://]IP[:Port]. We can also define libxl own syntax, migration uri like 
IP[:Port].

 +if (!uriptr-server) {
 +libxlError(VIR_ERR_INVALID_ARG,
 +  _(A hostname must be
 + specified in the URI));
 +xmlFreeURI(uriptr);
 +return -1;
 +}
 +hostname = strdup(uriptr-server);


 I think it would be better to rework this, and other uses of strdup()
 and snprintf() in this function, to use virAsprintf().

 +if (!hostname) {
 +virReportOOMError();
 +xmlFreeURI(uriptr);
 +return -1;
 +}
 +if (uriptr-port)
 +snprintf(port, sizeof(port), %d, uriptr-port);
 +xmlFreeURI(uriptr);
 +}
 +else if ((p = strrchr(uri, ':')) != NULL) { /* hostname:port */
 +int port_nr, n;
 +
 +if (virStrToLong_i(p+1, NULL, 10, port_nr)  0) {
 +libxlError(VIR_ERR_INVALID_ARG,
 + _(Invalid port number));
 +return -1;
 +}
 +snprintf(port, sizeof(port), %d, port_nr);
 +
 +/* Get the hostname. */
 +n = p - uri; /* n = Length of hostname in bytes. */
 +hostname = strdup(uri);
 +if (!hostname) {
 +virReportOOMError();
 +return -1;
 +}
 +hostname[n] = '\0';
 +}
 +else {/* hostname (or IP address) */
 +hostname = strdup(uri);
 +if (!hostname) {
 +virReportOOMError();
 +return -1;
 +}
 +}
 +*p_hostname = hostname;
 +*p_port = atoi(port);
 +return 0;
 +}
 +
 +static bool libxlMigrationFromIsAllowed(libxlDriverPrivatePtr driver,
 virDomainObjPtr vm)
 +{
 +