Re: [libvirt] [PATCH] Clarify documentation on possible return values in case of errors

2014-01-08 Thread Claudio Bley
At Thu,  9 Jan 2014 08:07:25 +0100,
Claudio Bley wrote:
> 
> 
> Signed-off-by: Claudio Bley 
> ---
>  src/libvirt.c |   10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/src/libvirt.c b/src/libvirt.c
> index ffd4f8e..73972f2 100644

[I didn't push this under the trivial rule, but waiting for an ACK
 because of the freeze currently in effect.]

FTR, note that this patch is the result of my thoughts from
http://www.redhat.com/archives/libvir-list/2014-January/msg00366.html

Claudio
-- 
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:

Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

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

[libvirt] [libvirt-java] [PATCH 2/2] test: ensure the Device.listCapabilities method works

2014-01-08 Thread Claudio Bley
---
 src/test/java/org/libvirt/TestJavaBindings.java | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/src/test/java/org/libvirt/TestJavaBindings.java 
b/src/test/java/org/libvirt/TestJavaBindings.java
index bba4cdb..3600844 100644
--- a/src/test/java/org/libvirt/TestJavaBindings.java
+++ b/src/test/java/org/libvirt/TestJavaBindings.java
@@ -45,6 +45,20 @@ public final class TestJavaBindings extends TestCase {
 assertTrue("conn.isSecure", conn.isSecure() == 1);
 }
 
+/*
+ * Excercise the listCapabilities method of the Device class.
+ */
+public void testDeviceListCapabilities() throws Exception {
+Device dev = this.conn.deviceLookupByName("computer");
+String[] caps = dev.listCapabilities();
+
+// check that all caps are non-empty strings
+for (String c: caps) {
+assertNotNull("capability is null", c);
+assertFalse("capability is empty", c.isEmpty());
+}
+}
+
 public void testNodeInfo() throws Exception {
 NodeInfo nodeInfo = conn.nodeInfo();
 assertEquals("nodeInfo.model", "i686", nodeInfo.model);
-- 
1.8.5.2.msysgit.0

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


[libvirt] [libvirt-java] [PATCH 0/2] Fixes for Device.listCapabilities

2014-01-08 Thread Claudio Bley
Let the Device.listCapabilities method return an array filled with
non-null string objects.  Furthermore, the decoding of the character
data does no longer depend upon the default JVM charset.

This also fixes a memleak because the allocated memory was not freed
in the old code.

Patch #2 just adds a unit test which simply uses this function.

Claudio Bley (2):
  Make Device.listCapabilities return only valid array elements
  test: ensure the Device.listCapabilities method works

 src/main/java/org/libvirt/Device.java   | 10 +++---
 src/main/java/org/libvirt/jna/Libvirt.java  |  2 +-
 src/test/java/org/libvirt/TestJavaBindings.java | 14 ++
 3 files changed, 22 insertions(+), 4 deletions(-)

-- 
1.8.5.2.msysgit.0

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


[libvirt] [libvirt-java] [PATCH 1/2] Make Device.listCapabilities return only valid array elements

2014-01-08 Thread Claudio Bley
The libvirt function virNodeDeviceListCaps might return fewer elements
than requested.  Take this into account and properly decode the UTF-8
strings returned.

Additionally, the given strings are freed before returning the resulting
string array.
---
 src/main/java/org/libvirt/Device.java  | 10 +++---
 src/main/java/org/libvirt/jna/Libvirt.java |  2 +-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/libvirt/Device.java 
b/src/main/java/org/libvirt/Device.java
index fe49ce9..d55321e 100644
--- a/src/main/java/org/libvirt/Device.java
+++ b/src/main/java/org/libvirt/Device.java
@@ -3,6 +3,8 @@ package org.libvirt;
 import org.libvirt.jna.DevicePointer;
 import static org.libvirt.Library.libvirt;
 
+import com.sun.jna.Pointer;
+
 /**
  * A device which is attached to a node
  */
@@ -135,13 +137,15 @@ public class Device {
  */
 public String[] listCapabilities() throws LibvirtException {
 int maxCaps = getNumberOfCapabilities();
-String[] names = new String[maxCaps];
 
 if (maxCaps > 0) {
-libvirt.virNodeDeviceListCaps(VDP, names, maxCaps);
+Pointer[] ptrs = new Pointer[maxCaps];
+int got = libvirt.virNodeDeviceListCaps(VDP, ptrs, maxCaps);
 processError();
+return Library.toStringArray(ptrs, got);
+} else {
+return Library.NO_STRINGS;
 }
-return names;
 }
 
 /**
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java 
b/src/main/java/org/libvirt/jna/Libvirt.java
index b026b04..a2bf42e 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -281,7 +281,7 @@ public interface Libvirt extends Library {
 String virNodeDeviceGetName(DevicePointer virDevicePointer);
 String virNodeDeviceGetParent(DevicePointer virDevicePointer);
 int virNodeDeviceNumOfCaps(DevicePointer virDevicePointer);
-int virNodeDeviceListCaps(DevicePointer virDevicePointer, String[] names, 
int maxNames);
+int virNodeDeviceListCaps(DevicePointer virDevicePointer, Pointer[] names, 
int maxNames);
 String virNodeDeviceGetXMLDesc(DevicePointer virDevicePointer);
 int virNodeDeviceFree(DevicePointer virDevicePointer);
 int virNodeDeviceDettach(DevicePointer virDevicePointer);
-- 
1.8.5.2.msysgit.0

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


[libvirt] [PATCH] Clarify documentation on possible return values in case of errors

2014-01-08 Thread Claudio Bley

Signed-off-by: Claudio Bley 
---
 src/libvirt.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index ffd4f8e..73972f2 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -14502,8 +14502,8 @@ virNodeDeviceGetName(virNodeDevicePtr dev)
  *
  * Accessor for the parent of the device
  *
- * Returns the name of the device's parent, or NULL if the
- * device has no parent.
+ * Returns the name of the device's parent, or NULL if an
+ * error occurred or when the device has no parent.
  */
 const char *
 virNodeDeviceGetParent(virNodeDevicePtr dev)
@@ -14537,7 +14537,8 @@ virNodeDeviceGetParent(virNodeDevicePtr dev)
  *
  * Accessor for the number of capabilities supported by the device.
  *
- * Returns the number of capabilities supported by the device.
+ * Returns the number of capabilities supported by the device or -1
+ * in case of error.
  */
 int
 virNodeDeviceNumOfCaps(virNodeDevicePtr dev)
@@ -14576,7 +14577,8 @@ error:
  *
  * Lists the names of the capabilities supported by the device.
  *
- * Returns the number of capability names listed in @names.
+ * Returns the number of capability names listed in @names or -1
+ * in case of error.
  */
 int
 virNodeDeviceListCaps(virNodeDevicePtr dev,
-- 
1.7.9.5

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


Re: [libvirt] [PATCH] libxl: Fix devid init in libxlMakeNicList

2014-01-08 Thread Jim Fehlig
Stefan Bader wrote: 
> This basically reverts commit ba64b97134a6129a48684f22f31be92c3b6eef96
> "libxl: Allow libxl to set NIC devid". However assigning devid's
> before calling libxlMakeNic does not work as that is calling
> libxl_device_nic_init which sets it back to -1.
> Right now auto-assignment only works in the hotplug case. But even if
> that would be fixed at some point (if that is possible at all), this
> would add a weird dependency between Xen and libvirt versions.

Yeah, I had numerous inquires and bugs come my way even after fixing vfb and
vkb devid initialization in libxl with xen.git commit 5420f265.  It took
some time for the fix to make its way to downstream users.  Since there is
not yet a fix in Xen, it only makes sense to do the nic devid initialization
in libvirt to fix PXE booting HVM domains.

> The change here should accept any auto-assignment that makes it into
> libxl_device_nic_init. My understanding is that a caller always is
> allowed to make the devid choice itself. And assuming libxlMakeNicList
> is only used on domain creation, a sequential numbering should be ok.
> 
> Signed-off-by: Stefan Bader 
> ---
>  src/libxl/libxl_conf.c |7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
> index 04d01af..4cefadf 100644
> --- a/src/libxl/libxl_conf.c
> +++ b/src/libxl/libxl_conf.c
> @@ -918,6 +918,13 @@ libxlMakeNicList(virDomainDefPtr def,  
> libxl_domain_config *d_config)
>  for (i = 0; i < nnics; i++) {
>  if (libxlMakeNic(def, l_nics[i], &x_nics[i]))
>  goto error;
> +/*
> + * The devid (at least right now) will not get initialized by
> + * libxl in the setup case but is required for starting the
> + * device-model.
> + */
> +if (x_nics[i].devid < 0)
> +x_nics[i].devid = i;

I think this is a better approach than the original code removed by ba64b971.
I've pushed this since it is clearly a bug fix and appropriate for 1.2.1.

Regards,
Jim

>  }
>  
>  d_config->nics = x_nics;



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


[libvirt] ANNOUNCE: ruby-libvirt 0.5.2

2014-01-08 Thread Chris Lalancette
All,
This is a release notification for ruby-libvirt 0.5.2.
ruby-libvirt is a ruby wrapper around the libvirt API.  The changelog
between 0.5.1 and 0.5.2 is:

* Fix to make sure we don't free more entries than retrieved (potential crash)

Version 0.5.2 is available from http://libvirt.org/ruby:

Tarball: http://libvirt.org/ruby/download/ruby-libvirt-0.5.2.tgz
Gem: http://libvirt.org/ruby/download/ruby-libvirt-0.5.2.gem

It is also available from rubygems.org; to get the latest version, run:

$ gem install ruby-libvirt

As usual, if you run into questions, problems, or bugs, please feel free to
mail me (clalancette gmail com) and the libvirt mailing list.

Thanks to Guido Günther for the patch to fix this problem.

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


[libvirt] [libvirt-sandbox PATCH v3] Add filter support.

2014-01-08 Thread Ian Main
This patch adds two new classes, filterref and filterref-parameter.
Network interfaces can now have an associated filter reference with any
number of filterref parameters.  Also added filter= option to
virt-sandbox tool.

---
V2:

- Changed set_filter to set_name and get_filter to get_name.

V3:

- Added type checks on all public methods.
- Call setters on property set.
- Fix install_property flags.
- Remove unneeded HANDLE defines.
- Add missing g_list_free().
- Add missing unref().
- Fixed names in copyright notices.
- Change order of files in Makefile.am

 libvirt-sandbox/Makefile.am|   4 +
 .../libvirt-sandbox-builder-container.c|  36 
 libvirt-sandbox/libvirt-sandbox-builder-machine.c  |  36 
 ...rt-sandbox-config-network-filterref-parameter.c | 208 
 ...rt-sandbox-config-network-filterref-parameter.h |  73 +++
 .../libvirt-sandbox-config-network-filterref.c | 218 +
 .../libvirt-sandbox-config-network-filterref.h |  74 +++
 libvirt-sandbox/libvirt-sandbox-config-network.c   |  42 
 libvirt-sandbox/libvirt-sandbox-config-network.h   |   4 +
 libvirt-sandbox/libvirt-sandbox-config.c   |  39 
 libvirt-sandbox/libvirt-sandbox.h  |   3 +
 libvirt-sandbox/libvirt-sandbox.sym|  16 ++
 12 files changed, 753 insertions(+)
 create mode 100644 
libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.c
 create mode 100644 
libvirt-sandbox/libvirt-sandbox-config-network-filterref-parameter.h
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-network-filterref.c
 create mode 100644 libvirt-sandbox/libvirt-sandbox-config-network-filterref.h

diff --git a/libvirt-sandbox/Makefile.am b/libvirt-sandbox/Makefile.am
index 0882490..720bb06 100644
--- a/libvirt-sandbox/Makefile.am
+++ b/libvirt-sandbox/Makefile.am
@@ -57,6 +57,8 @@ SANDBOX_HEADER_FILES = \
libvirt-sandbox-config.h \
libvirt-sandbox-config-network.h \
libvirt-sandbox-config-network-address.h \
+   libvirt-sandbox-config-network-filterref-parameter.h \
+   libvirt-sandbox-config-network-filterref.h \
libvirt-sandbox-config-network-route.h \
libvirt-sandbox-config-mount.h \
libvirt-sandbox-config-mount-file.h \
@@ -85,6 +87,8 @@ SANDBOX_SOURCE_FILES = \
libvirt-sandbox-config.c \
libvirt-sandbox-config-network.c \
libvirt-sandbox-config-network-address.c \
+   libvirt-sandbox-config-network-filterref.c \
+   libvirt-sandbox-config-network-filterref-parameter.c \
libvirt-sandbox-config-network-route.c \
libvirt-sandbox-config-mount.c \
libvirt-sandbox-config-mount-file.c \
diff --git a/libvirt-sandbox/libvirt-sandbox-builder-container.c 
b/libvirt-sandbox/libvirt-sandbox-builder-container.c
index 43ee5ef..bac8c70 100644
--- a/libvirt-sandbox/libvirt-sandbox-builder-container.c
+++ b/libvirt-sandbox/libvirt-sandbox-builder-container.c
@@ -324,6 +324,8 @@ static gboolean 
gvir_sandbox_builder_container_construct_devices(GVirSandboxBuil
 while (tmp) {
 const gchar *source, *mac;
 GVirSandboxConfigNetwork *network = 
GVIR_SANDBOX_CONFIG_NETWORK(tmp->data);
+GVirSandboxConfigNetworkFilterref *filterref;
+GVirConfigDomainInterfaceFilterref *glib_fref;
 
 iface = gvir_config_domain_interface_network_new();
 source = gvir_sandbox_config_network_get_source(network);
@@ -339,6 +341,40 @@ static gboolean 
gvir_sandbox_builder_container_construct_devices(GVirSandboxBuil
 
 gvir_config_domain_add_device(domain,
   GVIR_CONFIG_DOMAIN_DEVICE(iface));
+
+filterref = gvir_sandbox_config_network_get_filterref(network);
+if (filterref) {
+GList *param_iter, *parameters;
+const gchar *fref_name = 
gvir_sandbox_config_network_filterref_get_name(filterref);
+glib_fref = gvir_config_domain_interface_filterref_new();
+gvir_config_domain_interface_filterref_set_name(glib_fref, 
fref_name);
+param_iter = parameters = 
gvir_sandbox_config_network_filterref_get_parameters(filterref);
+while (param_iter) {
+const gchar *name;
+const gchar *value;
+GVirSandboxConfigNetworkFilterrefParameter *param = 
GVIR_SANDBOX_CONFIG_NETWORK_FILTERREF_PARAMETER(param_iter->data);
+GVirConfigDomainInterfaceFilterrefParameter *glib_param;
+
+name = 
gvir_sandbox_config_network_filterref_parameter_get_name(param);
+value = 
gvir_sandbox_config_network_filterref_parameter_get_value(param);
+
+   

Re: [libvirt] [PATCH 16/24] maint: improve VIR_ERR_INVALID_STORAGE_POOL usage

2014-01-08 Thread Eric Blake
On 01/02/2014 05:23 PM, John Ferlan wrote:
> 
> 
> On 12/28/2013 11:11 AM, Eric Blake wrote:
>> virStoragePoolBuild reported an invalid pool as if it were an
>> invalid network.  Likewise, we weren't consistent on whether to
>> use VIR_FROM_NONE or VIR_FROM_STORAGE.  Similar to previous
>> patches, use a common macro to make it nicer.  For now, we
>> don't need virCheckStoragePoolGoto().
>>
>> * src/datatypes.h (virCheckStoragePoolReturn): New macro.
>> (VIR_IS_STORAGE_POOL, VIR_IS_CONNECTED_STORAGE_POOL): Drop
>> unused macros.
>> * src/libvirt.c: Use macro throughout.
>> (virLibStoragePoolError): Drop unused macro.
>>
>> Signed-off-by: Eric Blake 
>> ---
>>  src/datatypes.h |  17 --
>>  src/libvirt.c   | 172 
>> +---
>>  2 files changed, 51 insertions(+), 138 deletions(-)
>>
> 
> Same as previous w/r/t connection required for GetName, GetUUID, and
> GetUUIDString

And same answer, fixed by improving the commit message.

> 
> ACK

Pushed.

-- 
Eric Blake   eblake 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] [PATCHv2] test driver: Add authentication to test driver.

2014-01-08 Thread Richard W.M. Jones
On Wed, Jan 08, 2014 at 01:10:52PM -0700, Eric Blake wrote:
> On 01/08/2014 12:45 PM, Richard W.M. Jones wrote:
> > There is no easy way to test authentication against libvirt.  This
> > commit modifies the test driver to allow simple username/password
> > authentication.
> > 
> > You modify the test XML by adding:
> > 
> >  
> >...
> >
> >  rich
> >  jane
> >
> >  
> > 
> 
> > 
> > Signed-off-by: Richard W.M. Jones 
> > ---
> >  src/test/test_driver.c | 111 
> > -
> >  1 file changed, 110 insertions(+), 1 deletion(-)
> 
> ACK.

Thanks, I have pushed this.

Two libguestfs regression tests now use this infrastructure when a
sufficiently new version of libvirt is detected:

https://github.com/libguestfs/libguestfs/commit/873db60c0e52893a38c374d867d0a305e5419d6a
https://github.com/libguestfs/libguestfs/commit/746a0b1f19667606ee63c8d3ab6a75531a8bd71c

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)

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


Re: [libvirt] [PATCHv2] test driver: Add authentication to test driver.

2014-01-08 Thread Eric Blake
On 01/08/2014 12:45 PM, Richard W.M. Jones wrote:
> There is no easy way to test authentication against libvirt.  This
> commit modifies the test driver to allow simple username/password
> authentication.
> 
> You modify the test XML by adding:
> 
>  
>...
>
>  rich
>  jane
>
>  
> 

> 
> Signed-off-by: Richard W.M. Jones 
> ---
>  src/test/test_driver.c | 111 
> -
>  1 file changed, 110 insertions(+), 1 deletion(-)

ACK.


-- 
Eric Blake   eblake 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] [PATCHv2] test driver: Add authentication to test driver.

2014-01-08 Thread Richard W.M. Jones
There is no easy way to test authentication against libvirt.  This
commit modifies the test driver to allow simple username/password
authentication.

You modify the test XML by adding:

 
   ...
   
 rich
 jane
   
 

If there are any /node/auth/user elements, then authentication is
required by the test driver (if none are present, then the test driver
will work as before and not require authentication).

In the example above, two phony users are added:

 rich  password: 123456
 jane  no password required

The test driver will demand a username.  If the password attribute is
present (or if the username entered is wrong), then the password is
also asked for and checked:

 $ virsh -c test://$(pwd)/testnode.xml list
 Enter username for localhost: rich
 Enter rich's password for localhost: ***
  IdName   State
 
  1 fv0running
  2 fc4running

Signed-off-by: Richard W.M. Jones 
---
 src/test/test_driver.c | 111 -
 1 file changed, 110 insertions(+), 1 deletion(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index cde82a1..b724f82 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -58,6 +58,7 @@
 #include "virrandom.h"
 #include "virstring.h"
 #include "cpu/cpu.h"
+#include "virauth.h"
 
 #define VIR_FROM_THIS VIR_FROM_TEST
 
@@ -82,6 +83,13 @@ typedef struct _testCell *testCellPtr;
 
 #define MAX_CELLS 128
 
+struct _testAuth {
+char *username;
+char *password;
+};
+typedef struct _testAuth testAuth;
+typedef struct _testAuth *testAuthPtr;
+
 struct _testConn {
 virMutex lock;
 
@@ -99,6 +107,8 @@ struct _testConn {
 virNodeDeviceObjList devs;
 int numCells;
 testCell cells[MAX_CELLS];
+size_t numAuths;
+testAuthPtr auths;
 
 virObjectEventStatePtr eventState;
 };
@@ -1355,6 +1365,45 @@ error:
 return ret;
 }
 
+static int
+testParseAuthUsers(testConnPtr privconn,
+   xmlXPathContextPtr ctxt)
+{
+int num, ret = -1;
+size_t i;
+xmlNodePtr *nodes = NULL;
+
+num = virXPathNodeSet("/node/auth/user", ctxt, &nodes);
+if (num < 0)
+goto error;
+
+privconn->numAuths = num;
+if (num && VIR_ALLOC_N(privconn->auths, num) < 0)
+goto error;
+
+for (i = 0; i < num; i++) {
+char *username, *password;
+
+ctxt->node = nodes[i];
+username = virXPathString("string(.)", ctxt);
+if (!username || STREQ(username, "")) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("missing username in /node/auth/user field"));
+VIR_FREE(username);
+goto error;
+}
+/* This field is optional. */
+password = virXMLPropString(nodes[i], "password");
+
+privconn->auths[i].username = username;
+privconn->auths[i].password = password;
+}
+
+ret = 0;
+error:
+VIR_FREE(nodes);
+return ret;
+}
 
 /* No shared state between simultaneous test connections initialized
  * from a file.  */
@@ -1417,6 +1466,8 @@ testOpenFromFile(virConnectPtr conn, const char *file)
 goto error;
 if (testParseNodedevs(privconn, file, ctxt) < 0)
 goto error;
+if (testParseAuthUsers(privconn, ctxt) < 0)
+goto error;
 
 xmlXPathFreeContext(ctxt);
 xmlFreeDoc(doc);
@@ -1439,9 +1490,63 @@ testOpenFromFile(virConnectPtr conn, const char *file)
 return VIR_DRV_OPEN_ERROR;
 }
 
+static int
+testConnectAuthenticate(virConnectPtr conn,
+virConnectAuthPtr auth)
+{
+testConnPtr privconn = conn->privateData;
+int ret = -1;
+ssize_t i;
+char *username = NULL, *password = NULL;
+
+if (privconn->numAuths == 0)
+return 0;
+
+/* Authentication is required because the test XML contains a
+ * non-empty  section.  First we must ask for a username.
+ */
+username = virAuthGetUsername(conn, auth, "test", NULL, "localhost"/*?*/);
+if (!username) {
+virReportError(VIR_ERR_AUTH_FAILED, "%s",
+   _("authentication failed when asking for username"));
+goto cleanup;
+}
+
+/* Does the username exist? */
+for (i = 0; i < privconn->numAuths; ++i) {
+if (STREQ(privconn->auths[i].username, username))
+goto found_user;
+}
+i = -1;
+
+found_user:
+/* Even if we didn't find the user, we still ask for a password. */
+if (i == -1 || privconn->auths[i].password != NULL) {
+password = virAuthGetPassword(conn, auth, "test",
+  username, "localhost");
+if (password == NULL) {
+virReportError(VIR_ERR_AUTH_FAILED, "%s",
+   _("authentication failed when asking for 
password"));
+goto cleanup;
+}
+}
+
+if (i == -1 ||
+(password && ST

Re: [libvirt] [PATCH 15/24] maint: improve VIR_ERR_INVALID_INTERFACE usage

2014-01-08 Thread Eric Blake
On 01/02/2014 05:19 PM, John Ferlan wrote:
> 
> 
> On 12/28/2013 11:11 AM, Eric Blake wrote:
>> When checking for a valid interface, we weren't consistent on
>> whether ew reported as VIR_FROM_NONE or VIR_FROM_INTERFACE.

s/ew/we/

>> Similar to previous patches, use a common macro to make it nicer.
>> For now, we don't need virCheckInterfaceGoto().
>>
>> * src/datatypes.h (virCheckInterfaceReturn): New macro.
>> (VIR_IS_INTERFACE, VIR_IS_CONNECTED_INTERFACE): Drop unused
>> macros.
>> * src/libvirt.c: Use macro throughout.
>> (virLibInterfaceError): Drop unused macro.
>>
>> Signed-off-by: Eric Blake 
>> ---
>>  src/datatypes.h | 17 +
>>  src/libvirt.c   | 74 
>> +++--
>>  2 files changed, 32 insertions(+), 59 deletions(-)
>>
> 
> Same concern as Networks - the virInterfaceGetName() and
> virInterfaceGetMACString() will require a connection...

And same response - I touched up the commit message to explain it better.

> 
> ACK

Pushed.


-- 
Eric Blake   eblake 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] test driver: Add authentication to test driver.

2014-01-08 Thread Richard W.M. Jones
On Wed, Jan 08, 2014 at 12:33:20PM -0700, Eric Blake wrote:
> > +username = virAuthGetUsername(conn, auth, "test", NULL, 
> > "localhost"/*?*/);
> 
> Is the /*?*/ intentional?

It's intentionally a question :-)

The virAuthGetUsername is demanding that I pass a non-null hostname
here.  I don't have a non-null hostname.  conn->uri->server is the
closest thing, but in the test driver that would always be NULL (it
might be non-NULL if visiting the test driver via the remote driver,
but this code is on the wrong side of the connection).

However this does not particularly matter.  virAuthGetUsername just
uses in a message for the user.

v2 patch coming up shortly.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/

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


Re: [libvirt] [PATCH] Add Documentation fields to systemd service files

2014-01-08 Thread Eric Blake
On 01/08/2014 12:29 PM, Guido Günther wrote:
> We point to the manpages where available and redirect to libvirt's
> homepage as a last resort.
> ---
>  daemon/libvirtd.service.in   | 2 ++
>  src/locking/virtlockd.service.in | 2 ++
>  tools/libvirt-guests.service.in  | 2 ++
>  3 files changed, 6 insertions(+)

ACK, worth having in 1.2.1


-- 
Eric Blake   eblake 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] event: clean up client side RPC code

2014-01-08 Thread Eric Blake
On 01/08/2014 10:51 AM, Michal Privoznik wrote:
> On 08.01.2014 18:23, Eric Blake wrote:
>> Commit cfd62c1 was incomplete; I found more cases where error
>> messages were being overwritten, and where the code between
>> the three registration/deregistration APIs was not consistent.
>>
>> Since it is fairly easy to trigger an attempt to register an
>> unregistered object, I also changed the error message from
>> VIR_ERR_INTERNAL_ERROR to VIR_ERR_INVALID_ARG.
>>
>> * src/conf/object_event.c (virObjectEventCallbackListEventID):
>> Inline...
>> (virObjectEventStateEventID): ...into lone caller, and report
>> error on failure.
>> (virObjectEventCallbackListAddID, virObjectEventStateCallbackID)
>> (virObjectEventCallbackListRemoveID)
>> (virObjectEventCallbackListMarkDeleteID): Tweak error category.
>> * src/remote/remote_driver.c (remoteConnectDomainEventRegister):
>> Don't leak registration on failure.
>> (remoteConnectDomainEventDeregisterAny)
>> (remoteConnectNetworkEventDeregisterAny): Don't overwrite error.
>>
>> Signed-off-by: Eric Blake 
>> ---
>>  src/conf/object_event.c| 57 
>> ++
>>  src/remote/remote_driver.c | 56 
>> ++---
>>  2 files changed, 55 insertions(+), 58 deletions(-)
> 
> ACK

Thanks; pushed.

-- 
Eric Blake   eblake 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] test driver: Add authentication to test driver.

2014-01-08 Thread Eric Blake
On 01/08/2014 11:39 AM, Richard W.M. Jones wrote:
> There is no easy way to test authentication against libvirt.  This
> commit modifies the test driver to allow simple username/password
> authentication.
> 
> You modify the test XML by adding:
> 
>  
>...
>
>  rich
>  jane
>
>  
> 
> If there are any /node/auth/user elements, then authentication is
> required by the test driver (if none are present, then the test driver
> will work as before and not require authentication).

Cool - just the sort of thing the test:/// URI is intended for :)


> @@ -99,6 +107,8 @@ struct _testConn {
>  virNodeDeviceObjList devs;
>  int numCells;
>  testCell cells[MAX_CELLS];
> +int numAuths;

size_t

> +testAuthPtr auths;
>  

> +testParseAuthUsers(testConnPtr privconn,
> +   xmlXPathContextPtr ctxt)
> +{
> +int num, ret = -1;
> +size_t i;
> +xmlNodePtr *nodes = NULL;
> +
> +num = virXPathNodeSet("/node/auth/user", ctxt, &nodes);
> +if (num < 0)
> +goto error;
> +
> +privconn->numAuths = num;
> +if (num && VIR_ALLOC_N(privconn->auths, num) < 0)
> +goto error;
> +
> +for (i = 0; i < num; i++) {
> +char *username, *password;
> +
> +ctxt->node = nodes[i];
> +username = virXPathString("string(.)", ctxt);
> +if (!username || STREQ(username, "")) {
> +virReportError(VIR_ERR_XML_ERROR, "%s",
> +   _("missing username in /node/auth/user field"));
> +goto error;
> +}

If username is "",...

> +/* This field is optional. */
> +password = virXMLPropString(nodes[i], "password");
> +
> +privconn->auths[i].username = username;
> +privconn->auths[i].password = password;
> +}
> +
> +ret = 0;
> +error:
> +VIR_FREE(nodes);
> +return ret;

...then you just leaked malloc'd memory.

> +/* Authentication is required because the test XML contains a
> + * non-empty  section.  First we must ask for a username.
> + */
> +username = virAuthGetUsername(conn, auth, "test", NULL, 
> "localhost"/*?*/);

Is the /*?*/ intentional?


> +
> +found_user:
> +/* Even if we didn't find the user, we still ask for a password. */
> +if (i == -1 || privconn->auths[i].password != NULL) {

Nice - matches good security practice of not hinting to the user which
usernames are valid.  (Not that any user/pw pair in the text XML can be
considered secure so much as a way to test the code base... Anyone
sticking a password they value in the test XML deserves what they get)

This is probably worth having in 1.2.1, if you clean up the problems in
time.

-- 
Eric Blake   eblake 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] Add Documentation fields to systemd service files

2014-01-08 Thread Guido Günther
We point to the manpages where available and redirect to libvirt's
homepage as a last resort.
---
 daemon/libvirtd.service.in   | 2 ++
 src/locking/virtlockd.service.in | 2 ++
 tools/libvirt-guests.service.in  | 2 ++
 3 files changed, 6 insertions(+)

diff --git a/daemon/libvirtd.service.in b/daemon/libvirtd.service.in
index 25979ef..dc2433a 100644
--- a/daemon/libvirtd.service.in
+++ b/daemon/libvirtd.service.in
@@ -9,6 +9,8 @@ Before=libvirt-guests.service
 After=network.target
 After=dbus.service
 After=iscsid.service
+Documentation=man:libvirtd(8)
+Documentation=http://libvirt.org
 
 [Service]
 EnvironmentFile=-/etc/sysconfig/libvirtd
diff --git a/src/locking/virtlockd.service.in b/src/locking/virtlockd.service.in
index a1298a3..57089b0 100644
--- a/src/locking/virtlockd.service.in
+++ b/src/locking/virtlockd.service.in
@@ -1,6 +1,8 @@
 [Unit]
 Description=Virtual machine lock manager
 Requires=virtlockd.socket
+Documentation=man:virtlockd(8)
+Documentation=http://libvirt.org
 
 [Service]
 EnvironmentFile=-/etc/sysconfig/virtlockd
diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
index d48d4b8..d8d7adf 100644
--- a/tools/libvirt-guests.service.in
+++ b/tools/libvirt-guests.service.in
@@ -1,6 +1,8 @@
 [Unit]
 Description=Suspend Active Libvirt Guests
 After=network.target libvirtd.service
+Documentation=man:libvirtd(8)
+Documentation=http://libvirt.org
 
 [Service]
 EnvironmentFile=-/etc/sysconfig/libvirt-guests
-- 
1.8.5.2

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


Re: [libvirt] [PATCHv2 6/7] lxc: add virProcessRunInMountNamespace

2014-01-08 Thread Eric Blake
On 01/08/2014 12:10 PM, Guido Günther wrote:
> On Mon, Dec 23, 2013 at 10:55:50PM -0700, Eric Blake wrote:
> [..snip..] 
>> +if (virAsprintf(&path, "/proc/%llu/ns/mnt", (unsigned long long)pid) < 
>> 0)
>> +goto cleanup;
>> +
>> +if ((fd = open(path, O_RDONLY)) < 0) {
>> +virReportSystemError(errno, "%s",
>> + _("Kernel does not provide mount namespace"));
>> +goto cleanup;
>> +}
> 
> So in case mount namespaces are unavailable we'll fail these operations
> entirely? I think this is the right thing to do but it will break
> distros that have a too old kernel. So shutting down of containers will
> no longer work (as it did before).

We'll fail the attempt to use initctl as the shutdown mechanism, but
should still gracefully fall back to the attempt to use signals (once
this patch is in [1]).  Or, if the user explicitly requested intictl
only, then they WANT to know that initctl didn't work.

[1] https://www.redhat.com/archives/libvir-list/2014-January/msg00277.html

-- 
Eric Blake   eblake 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] [PATCHv2 6/7] lxc: add virProcessRunInMountNamespace

2014-01-08 Thread Guido Günther
On Mon, Dec 23, 2013 at 10:55:50PM -0700, Eric Blake wrote:
[..snip..] 
> +if (virAsprintf(&path, "/proc/%llu/ns/mnt", (unsigned long long)pid) < 0)
> +goto cleanup;
> +
> +if ((fd = open(path, O_RDONLY)) < 0) {
> +virReportSystemError(errno, "%s",
> + _("Kernel does not provide mount namespace"));
> +goto cleanup;
> +}

So in case mount namespaces are unavailable we'll fail these operations
entirely? I think this is the right thing to do but it will break
distros that have a too old kernel. So shutting down of containers will
no longer work (as it did before).

Cheers,
 -- Guido

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


[libvirt] [PATCH] test driver: Add authentication to test driver.

2014-01-08 Thread Richard W.M. Jones
There is no easy way to test authentication against libvirt.  This
commit modifies the test driver to allow simple username/password
authentication.

You modify the test XML by adding:

 
   ...
   
 rich
 jane
   
 

If there are any /node/auth/user elements, then authentication is
required by the test driver (if none are present, then the test driver
will work as before and not require authentication).

In the example above, two phony users are added:

 rich  password: 123456
 jane  no password required

The test driver will demand a username.  If the password attribute is
present (or if the username entered is wrong), then the password is
also asked for and checked:

 $ virsh -c test://$(pwd)/testnode.xml list
 Enter username for localhost: rich
 Enter rich's password for localhost: ***
  IdName   State
 
  1 fv0running
  2 fc4running

Signed-off-by: Richard W.M. Jones 
---
 src/test/test_driver.c | 110 -
 1 file changed, 109 insertions(+), 1 deletion(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index cde82a1..ecad351 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -58,6 +58,7 @@
 #include "virrandom.h"
 #include "virstring.h"
 #include "cpu/cpu.h"
+#include "virauth.h"
 
 #define VIR_FROM_THIS VIR_FROM_TEST
 
@@ -82,6 +83,13 @@ typedef struct _testCell *testCellPtr;
 
 #define MAX_CELLS 128
 
+struct _testAuth {
+char *username;
+char *password;
+};
+typedef struct _testAuth testAuth;
+typedef struct _testAuth *testAuthPtr;
+
 struct _testConn {
 virMutex lock;
 
@@ -99,6 +107,8 @@ struct _testConn {
 virNodeDeviceObjList devs;
 int numCells;
 testCell cells[MAX_CELLS];
+int numAuths;
+testAuthPtr auths;
 
 virObjectEventStatePtr eventState;
 };
@@ -1355,6 +1365,44 @@ error:
 return ret;
 }
 
+static int
+testParseAuthUsers(testConnPtr privconn,
+   xmlXPathContextPtr ctxt)
+{
+int num, ret = -1;
+size_t i;
+xmlNodePtr *nodes = NULL;
+
+num = virXPathNodeSet("/node/auth/user", ctxt, &nodes);
+if (num < 0)
+goto error;
+
+privconn->numAuths = num;
+if (num && VIR_ALLOC_N(privconn->auths, num) < 0)
+goto error;
+
+for (i = 0; i < num; i++) {
+char *username, *password;
+
+ctxt->node = nodes[i];
+username = virXPathString("string(.)", ctxt);
+if (!username || STREQ(username, "")) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("missing username in /node/auth/user field"));
+goto error;
+}
+/* This field is optional. */
+password = virXMLPropString(nodes[i], "password");
+
+privconn->auths[i].username = username;
+privconn->auths[i].password = password;
+}
+
+ret = 0;
+error:
+VIR_FREE(nodes);
+return ret;
+}
 
 /* No shared state between simultaneous test connections initialized
  * from a file.  */
@@ -1417,6 +1465,8 @@ testOpenFromFile(virConnectPtr conn, const char *file)
 goto error;
 if (testParseNodedevs(privconn, file, ctxt) < 0)
 goto error;
+if (testParseAuthUsers(privconn, ctxt) < 0)
+goto error;
 
 xmlXPathFreeContext(ctxt);
 xmlFreeDoc(doc);
@@ -1439,9 +1489,63 @@ testOpenFromFile(virConnectPtr conn, const char *file)
 return VIR_DRV_OPEN_ERROR;
 }
 
+static int
+testConnectAuthenticate(virConnectPtr conn,
+virConnectAuthPtr auth)
+{
+testConnPtr privconn = conn->privateData;
+int ret = -1;
+int i;
+char *username = NULL, *password = NULL;
+
+if (privconn->numAuths == 0)
+return 0;
+
+/* Authentication is required because the test XML contains a
+ * non-empty  section.  First we must ask for a username.
+ */
+username = virAuthGetUsername(conn, auth, "test", NULL, "localhost"/*?*/);
+if (!username) {
+virReportError(VIR_ERR_AUTH_FAILED, "%s",
+   _("authentication failed when asking for username"));
+goto cleanup;
+}
+
+/* Does the username exist? */
+for (i = 0; i < privconn->numAuths; ++i) {
+if (STREQ(privconn->auths[i].username, username))
+goto found_user;
+}
+i = -1;
+
+found_user:
+/* Even if we didn't find the user, we still ask for a password. */
+if (i == -1 || privconn->auths[i].password != NULL) {
+password = virAuthGetPassword(conn, auth, "test",
+  username, "localhost");
+if (password == NULL) {
+virReportError(VIR_ERR_AUTH_FAILED, "%s",
+   _("authentication failed when asking for 
password"));
+goto cleanup;
+}
+}
+
+if (i == -1 ||
+(password && STRNEQ(privconn->auths[i].password, passwo

Re: [libvirt] [PATCH] event: clean up client side RPC code

2014-01-08 Thread Michal Privoznik
On 08.01.2014 18:23, Eric Blake wrote:
> Commit cfd62c1 was incomplete; I found more cases where error
> messages were being overwritten, and where the code between
> the three registration/deregistration APIs was not consistent.
> 
> Since it is fairly easy to trigger an attempt to register an
> unregistered object, I also changed the error message from
> VIR_ERR_INTERNAL_ERROR to VIR_ERR_INVALID_ARG.
> 
> * src/conf/object_event.c (virObjectEventCallbackListEventID):
> Inline...
> (virObjectEventStateEventID): ...into lone caller, and report
> error on failure.
> (virObjectEventCallbackListAddID, virObjectEventStateCallbackID)
> (virObjectEventCallbackListRemoveID)
> (virObjectEventCallbackListMarkDeleteID): Tweak error category.
> * src/remote/remote_driver.c (remoteConnectDomainEventRegister):
> Don't leak registration on failure.
> (remoteConnectDomainEventDeregisterAny)
> (remoteConnectNetworkEventDeregisterAny): Don't overwrite error.
> 
> Signed-off-by: Eric Blake 
> ---
>  src/conf/object_event.c| 57 
> ++
>  src/remote/remote_driver.c | 56 ++---
>  2 files changed, 55 insertions(+), 58 deletions(-)

ACK

Michal

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


[libvirt] [PATCH] event: clean up client side RPC code

2014-01-08 Thread Eric Blake
Commit cfd62c1 was incomplete; I found more cases where error
messages were being overwritten, and where the code between
the three registration/deregistration APIs was not consistent.

Since it is fairly easy to trigger an attempt to register an
unregistered object, I also changed the error message from
VIR_ERR_INTERNAL_ERROR to VIR_ERR_INVALID_ARG.

* src/conf/object_event.c (virObjectEventCallbackListEventID):
Inline...
(virObjectEventStateEventID): ...into lone caller, and report
error on failure.
(virObjectEventCallbackListAddID, virObjectEventStateCallbackID)
(virObjectEventCallbackListRemoveID)
(virObjectEventCallbackListMarkDeleteID): Tweak error category.
* src/remote/remote_driver.c (remoteConnectDomainEventRegister):
Don't leak registration on failure.
(remoteConnectDomainEventDeregisterAny)
(remoteConnectNetworkEventDeregisterAny): Don't overwrite error.

Signed-off-by: Eric Blake 
---
 src/conf/object_event.c| 57 ++
 src/remote/remote_driver.c | 56 ++---
 2 files changed, 55 insertions(+), 58 deletions(-)

diff --git a/src/conf/object_event.c b/src/conf/object_event.c
index b01ffe5..b69387a 100644
--- a/src/conf/object_event.c
+++ b/src/conf/object_event.c
@@ -210,8 +210,9 @@ virObjectEventCallbackListRemoveID(virConnectPtr conn,
 }
 }

-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("could not find event callback for removal"));
+virReportError(VIR_ERR_INVALID_ARG,
+   _("could not find event callback %d for deletion"),
+   callbackID);
 return -1;
 }

@@ -233,8 +234,9 @@ virObjectEventCallbackListMarkDeleteID(virConnectPtr conn,
 }
 }

-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("could not find event callback for deletion"));
+virReportError(VIR_ERR_INVALID_ARG,
+   _("could not find event callback %d for deletion"),
+   callbackID);
 return -1;
 }

@@ -357,7 +359,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn,
 if (virObjectEventCallbackLookup(conn, cbList, uuid,
  klass, eventID, callback,
  !callbackID) != -1) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+virReportError(VIR_ERR_INVALID_ARG, "%s",
_("event callback already tracked"));
 return -1;
 }
@@ -398,27 +400,6 @@ cleanup:
 }


-static int
-virObjectEventCallbackListEventID(virConnectPtr conn,
-  virObjectEventCallbackListPtr cbList,
-  int callbackID)
-{
-size_t i;
-
-for (i = 0; i < cbList->count; i++) {
-virObjectEventCallbackPtr cb = cbList->callbacks[i];
-
-if (cb->deleted)
-continue;
-
-if (cb->callbackID == callbackID && cb->conn == conn)
-return cb->eventID;
-}
-
-return -1;
-}
-
-
 /**
  * virObjectEventQueueClear:
  * @queue: pointer to the queue
@@ -897,7 +878,7 @@ virObjectEventStateCallbackID(virConnectPtr conn,
 virObjectEventStateUnlock(state);

 if (ret < 0)
-virReportError(VIR_ERR_INTERNAL_ERROR,
+virReportError(VIR_ERR_INVALID_ARG,
_("event callback function %p not registered"),
callback);
 return ret;
@@ -920,11 +901,27 @@ virObjectEventStateEventID(virConnectPtr conn,
virObjectEventStatePtr state,
int callbackID)
 {
-int ret;
+int ret = -1;
+size_t i;
+virObjectEventCallbackListPtr cbList = state->callbacks;

 virObjectEventStateLock(state);
-ret = virObjectEventCallbackListEventID(conn,
-state->callbacks, callbackID);
+for (i = 0; i < cbList->count; i++) {
+virObjectEventCallbackPtr cb = cbList->callbacks[i];
+
+if (cb->deleted)
+continue;
+
+if (cb->callbackID == callbackID && cb->conn == conn) {
+ret = cb->eventID;
+break;
+}
+}
 virObjectEventStateUnlock(state);
+
+if (ret < 0)
+virReportError(VIR_ERR_INVALID_ARG,
+   _("event callback id %d not registered"),
+   callbackID);
 return ret;
 }
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index fecb9b2..64d9d92 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2911,6 +2911,7 @@ done:
 return rv;
 }

+
 static int
 remoteConnectNetworkEventRegisterAny(virConnectPtr conn,
  virNetworkPtr net,
@@ -2968,16 +2969,12 @@ remoteConnectNetworkEventDeregisterAny(virConnectPtr 
conn,
 remoteDriverLock(priv);

 if ((eventID = virObjectEventStateEventID(conn, priv->eventState,
-  callbackID)) < 0) {
-   

Re: [libvirt] [Users] libvirt migration port configuration and virPortAllocator

2014-01-08 Thread Eric Blake
On 01/08/2014 02:45 AM, Dan Kenigsberg wrote:
> On Wed, Jan 08, 2014 at 01:26:23AM +0100, Gianluca Cecchi wrote:
>> Hello,
>> following the bugzilla here:
>> https://bugzilla.redhat.com/show_bug.cgi?id=1019053

This bug was tagged against upstream libvirt.  If you need it backported
to specific Fedora releases, it might be worth cloning the BZ and making
sure the clone is against Fedora instead of Virtualization Tools.

>>
>> we have
>> "
>> This is now fixed by v1.1.3-188-g0196845 and v1.1.3-189-ge3ef20d
>> "
>>
>> Does this mean that f19 that has
>> libvirt-1.0.5.8-1.fc19.x86_64
>> is out?

We can backport the patch to v1.0.5-maint if there is a compelling
reason (such as a BZ).

>> Any time soon to update it?

Fedora 19 and 20 will be betting a new build for CVE fixes anyways
(there's at least four CVEs found during December, some still under
embargo, and where the maintenance releases will probably be coordinated
with the 1.2.1 upstream release around Jan 15).

>> I see at
>> http://libvirt.org/sources/
>> files such as
>> libvirt-1.1.4-1.fc19.x86_64.rpm

That's from fedora-virt-preview, but we only maintain
fedora-virt-preview for a single release (that is, F19's virt-preview is
no longer getting any updates now that F20 is stable, and F20's
virt-preview is tracking what is in rawhide).  At this point, if you
want anything else fixed in F19, the fix has to go in 1.0.5.x, and
you'll have to use the Fedora repo rather than the fedora-virt-preview repo.

>> since beginning of November...
>> any particular reason for no packages neither in updates-testing repo?
>>
>> Also, Fedora 20 has libvirt-1.1.3.2-1.fc20.x86_64.rpm
>> Did it receive the patch update? I see nothing particular in its changelog...
> 
> I suspect that you'd see this bugfix only on libvirt>=1.2, but the best
> place for such questions is the libvirt mailing list (CCed).
> Unfortunately, that version is not even on virt-preview
> http://fedorapeople.org/groups/virt/virt-preview/fedora-19 (but it is on
> http://fedorapeople.org/groups/virt/virt-preview/fedora-20 !)

Again, virt-preview on F19 is dead.  virt-preview on F20 tracks rawhide.
 And for the non-virt-preview packages, if you need particular patched
backported to currently-maintained Fedora releases, bugzilla is the best
place to make sure the request isn't lost.

-- 
Eric Blake   eblake 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] Make sure AC_ARG_WITH is always executed

2014-01-08 Thread Guido Günther
On Tue, Jan 07, 2014 at 04:19:14PM -0700, Eric Blake wrote:
> On 01/07/2014 04:10 PM, Guido Günther wrote:
> > ---
> > I'm not sure whether it's good autoconf style to have AC_ARG_WITH in a
> > conditional so this patch moves it out.
> 
> Much of the code within AC_ARG_WITH gets executed unconditionally
> (because it gets hoisted to earlier parts of the configure than where
> you actually invoked it in configure.ac), so you are correct that using
> it unconditionally is better style.  ACK.
Pushed now. Thanks.
 -- Guido


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

Re: [libvirt] [PATCH 14/24] maint: improve VIR_ERR_INVALID_NETWORK usage

2014-01-08 Thread Eric Blake
On 01/02/2014 05:17 PM, John Ferlan wrote:
> 
> 
> On 12/28/2013 11:11 AM, Eric Blake wrote:
>> When checking for a valid network, we weren't consistent on
>> whether we reported an invalid network or a connection.  Similar
>> to previous patches, use a common macro to make it nicer.
>>
>> * src/datatypes.h (virCheckNetworkReturn, virCheckNetworkGoto): New
>> macros.
>> (VIR_IS_NETWORK, VIR_IS_CONNECTED_NETWORK): Drop unused macros.
>> * src/libvirt.c: Use macro throughout.
>> (virLibNetworkError): Drop unused macro.
>>
>> Signed-off-by: Eric Blake 
>> ---
>>  src/datatypes.h |  29 +++--
>>  src/libvirt.c   | 131 
>> 
>>  2 files changed, 61 insertions(+), 99 deletions(-)
>>
> 
> Just making sure it's now expected that virNetworkGetName(),
> virNetworkGetUUID(), and virNetworkGetUUIDString() will now have to have
> a connected network just like the new requirement for the various domain
> API's that previously just cared about a domain regardless of connection.

A "connected network" is a network that points to a valid virConnectPtr.
 But based on the way we do reference counting, this should ALWAYS be
the case for a valid network.  This is the same intentional change as
was made for domains in commit 6e130dd.  I'll tweak the commit message
to make the justification stronger.

> 
> ACK for the mechanical parts...

Even though it is now after freeze, this was reviewed before freeze and
I think it's better to have the whole series in the release rather than
half-and-half.  So I'll keep plowing through your review comments, and
in particular, I have now pushed this patch.

-- 
Eric Blake   eblake 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] Regression testing libvirt authentication

2014-01-08 Thread Richard W.M. Jones

I'm trying to find a way to regression-test a program which uses
libvirt authentication (virConnectAuth, virConnectAuthPtr).  Ideally
the test:/// driver would be able to fake authentication demands, but
it doesn't seem to be able to do that.

Any suggestions?  Would this feature belong in the test driver or
elsewhere?

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org

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


[libvirt] [libvirt-java] [PATCH 3/3] test: add testDomainScreenshot JUnit test

2014-01-08 Thread Claudio Bley
---
 src/test/java/org/libvirt/TestJavaBindings.java | 38 +
 1 file changed, 38 insertions(+)

diff --git a/src/test/java/org/libvirt/TestJavaBindings.java 
b/src/test/java/org/libvirt/TestJavaBindings.java
index bba4cdb..2d4ad9d 100644
--- a/src/test/java/org/libvirt/TestJavaBindings.java
+++ b/src/test/java/org/libvirt/TestJavaBindings.java
@@ -1,5 +1,8 @@
 package org.libvirt;
 
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
 import java.util.UUID;
 
 import junit.framework.TestCase;
@@ -216,4 +219,39 @@ public final class TestJavaBindings extends TestCase {
 assertTrue("pool1 should not be active", pool1.isActive() == 0);   
 
 assertTrue("Domain2 should be active", defaultPool.isActive() == 1);   
  
 }
+
+public void testDomainScreenshot() throws Exception {
+Stream str = this.conn.streamNew(0);
+Domain dom = this.conn.domainLookupByName("test");
+
+assertFalse("Domain \"test\" not found", dom == null);
+
+String mimetype = dom.screenshot(str, 0);
+
+ByteBuffer bb = ByteBuffer.allocateDirect(8192);
+
+while (str.read(bb) != -1) // consume data
+bb.clear();
+
+// ensure that read() repeatedly returns -1 after EOF
+
+assertEquals("Stream is at EOF (1)", -1, str.read(bb));
+assertEquals("Stream is at EOF (2)", -1, str.read(bb));
+assertEquals("Stream is at EOF (3)", -1, str.read(bb));
+
+// ensure that an ClosedChannelException gets thrown when
+// trying to read() after closing the stream
+
+boolean exceptionThrown = false;
+
+str.close();
+
+try {
+str.read(bb);
+} catch (ClosedChannelException e) {
+exceptionThrown = true;
+}
+assertTrue("ClosedChannelException is thrown calling read() on a 
closed stream",
+   exceptionThrown);
+}
 }
-- 
1.8.5.2.msysgit.0

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


[libvirt] [libvirt-java] [PATCH 1/3] Implement interface ByteChannel for Stream class

2014-01-08 Thread Claudio Bley
This makes the Stream class a native citizen of the Java API.

It can be used with the NIO Channel API, as well as (In,Out)putStream's
using the java.nio.channels.Channels convenience wrappers.
---
 src/main/java/org/libvirt/Stream.java  | 171 -
 src/main/java/org/libvirt/jna/Libvirt.java |   6 +-
 2 files changed, 172 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/libvirt/Stream.java 
b/src/main/java/org/libvirt/Stream.java
index 404c9a0..975e1b6 100644
--- a/src/main/java/org/libvirt/Stream.java
+++ b/src/main/java/org/libvirt/Stream.java
@@ -1,12 +1,48 @@
 package org.libvirt;
 
+import java.io.IOException;
+
+import java.nio.ByteBuffer;
+import java.nio.channels.ByteChannel;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.NonReadableChannelException;
+import java.nio.channels.NonWritableChannelException;
+
 import org.libvirt.jna.Libvirt;
 import org.libvirt.jna.StreamPointer;
 import static org.libvirt.Library.libvirt;
 
 import com.sun.jna.NativeLong;
 
-public class Stream {
+/**
+ * The Stream class is used to transfer data between a libvirt daemon
+ * and a client.
+ * 
+ * It implements the ByteChannel interface.
+ * 
+ * Basic usage:
+ *
+ * 
+ * {@code
+ * ByteBuffer buf = ByteBuffer.allocate(1024);
+ * Stream str = conn.streamNew(0);
+ *
+ * ... // open the stream e.g. calling Domain.screenshot
+ *
+ * while (str.read(buf) != -1) {
+ * buf.flip();
+ * ... // do something with the data
+ * buf.compact();
+ * }
+ * }
+ * 
+ * 
+ * If you want to use this class as an InputStream or OutputStream,
+ * convert it using the {@link java.nio.channels.Channels#newInputStream
+ *  Channels.newInputStream} and {@link 
java.nio.channels.Channels#newOutputStream
+ *  Channels.newOutputStream} respectively.
+ */
+public class Stream implements ByteChannel {
 
 public static int VIR_STREAM_NONBLOCK = (1 << 0);
 
@@ -20,6 +56,56 @@ public class Stream {
  */
 private Connect virConnect;
 
+private final static int CLOSED   =  0;
+private final static int READABLE =  1;
+private final static int WRITABLE =  2;
+private final static int OPEN = READABLE | WRITABLE;
+private final static int EOF  =  4;
+
+/* The status of the stream. A stream starts its live in the
+ * "CLOSED" state.
+ *
+ * It will be opened for input / output by another libvirt
+ * operation (e.g. virStorageVolDownload), which means it will
+ * be in state "READABLE" or "WRITABLE", exclusively.
+ *
+ * It will reach state "EOF", if {@link finish()} is called.
+ *
+ * It will be in the "CLOSED" state again, after calling abort()
+ * or close().
+ */
+private int state = CLOSED;
+
+void markReadable() {
+assert !isWritable()
+: "A Stream cannot be readable and writable at the same time";
+
+state |= READABLE;
+}
+
+void markWritable() {
+assert !isReadable()
+: "A Stream cannot be readable and writable at the same time";
+
+state |= WRITABLE;
+}
+
+boolean isReadable() {
+return (state & READABLE) != 0;
+}
+
+boolean isWritable() {
+return (state & WRITABLE) != 0;
+}
+
+protected boolean isEOF() {
+return (state & EOF) != 0;
+}
+
+private void markEOF() {
+state |= EOF;
+}
+
 Stream(Connect virConnect, StreamPointer VSP) {
 this.virConnect = virConnect;
 this.VSP = VSP;
@@ -32,6 +118,7 @@ public class Stream {
 public int abort() throws LibvirtException {
 int returnValue = libvirt.virStreamAbort(VSP);
 processError();
+this.state = CLOSED;
 return returnValue;
 }
 
@@ -70,6 +157,7 @@ public class Stream {
 public int finish() throws LibvirtException {
 int returnValue = libvirt.virStreamFinish(VSP);
 processError();
+markEOF();
 return returnValue;
 }
 
@@ -83,6 +171,7 @@ public class Stream {
 public int free() throws LibvirtException {
 int success = 0;
 if (VSP != null) {
+closeStream();
 success = libvirt.virStreamFree(VSP);
 processError();
 VSP = null;
@@ -108,11 +197,82 @@ public class Stream {
  * @throws LibvirtException
  */
 public int receive(byte[] data) throws LibvirtException {
-int returnValue = libvirt.virStreamRecv(VSP, data, new 
NativeLong(data.length));
+return receive(ByteBuffer.wrap(data));
+}
+
+protected int receive(ByteBuffer buffer) throws LibvirtException {
+int returnValue = libvirt.virStreamRecv(VSP, buffer, new 
NativeLong(buffer.remaining()));
 processError();
+buffer.position(buffer.position() + returnValue);
 return returnValue;
 }
 
+@Override
+public int read(ByteBuffer buffer) throws IOException {
+if (!isOpen()) throw new ClosedChannelException();

[libvirt] [libvirt-java] [PATCH 2/3] Domain: add screenshot method

2014-01-08 Thread Claudio Bley
This wraps the native virDomainScreenshot function.
---
 src/main/java/org/libvirt/Domain.java  | 11 +++
 src/main/java/org/libvirt/Stream.java  |  4 
 src/main/java/org/libvirt/jna/Libvirt.java |  1 +
 3 files changed, 16 insertions(+)

diff --git a/src/main/java/org/libvirt/Domain.java 
b/src/main/java/org/libvirt/Domain.java
index 2f70bf2..a57f7ca 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -1074,6 +1074,17 @@ public class Domain {
 processError();
 }
 
+public String screenshot(Stream stream, int screen) throws 
LibvirtException {
+Pointer ptr = 
org.libvirt.jna.LibvirtDirect.virDomainScreenshot(this.VDP, stream.getVSP(), 
screen, 0);
+if (ptr == null) processError();
+stream.markReadable();
+try {
+return Library.getString(ptr);
+} finally {
+Library.free(ptr);
+}
+}
+
 /**
  * Configures the network to be automatically started when the host machine
  * boots.
diff --git a/src/main/java/org/libvirt/Stream.java 
b/src/main/java/org/libvirt/Stream.java
index 975e1b6..aacaba1 100644
--- a/src/main/java/org/libvirt/Stream.java
+++ b/src/main/java/org/libvirt/Stream.java
@@ -180,6 +180,10 @@ public class Stream implements ByteChannel {
 return success;
 }
 
+StreamPointer getVSP() {
+return VSP;
+}
+
 /**
  * Error handling logic to throw errors. Must be called after every libvirt
  * call.
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java 
b/src/main/java/org/libvirt/jna/Libvirt.java
index fe74087..c161b27 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -236,6 +236,7 @@ public interface Libvirt extends Library {
 int virDomainRevertToSnapshot(DomainSnapshotPointer virDomainSnapshotPtr, 
int flags);
 int virDomainResume(DomainPointer virDomainPtr);
 int virDomainSave(DomainPointer virDomainPtr, String to);
+Pointer virDomainScreenshot(DomainPointer virDomainPtr, StreamPointer 
virStreamPtr, int screen, int flags);
 int virDomainSetAutostart(DomainPointer virDomainPtr, int autoStart);
 int virDomainSetMaxMemory(DomainPointer virDomainPtr, NativeLong 
maxMemory);
 int virDomainSetMemory(DomainPointer virDomainPtr, NativeLong maxMemory);
-- 
1.8.5.2.msysgit.0

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


[libvirt] [libvirt-java] [PATCH 0/3] Make the Java wrapper more fun to use

2014-01-08 Thread Claudio Bley
This patchset first implements the ByteChannel interface for the Stream
class which makes it readily usable with any standard Java library.

Note, that this changes the wrapping of the virStreamRecv and virStreamSend
function of the jna.Libvirt interface (which also makes this more efficient
because a ByteBuffer is used instead of an Array). However, this interface
should not be considered part of the public interface of the library, as with
all classes part of the org.libvirt.jna package.

In order to put this new functionality to use, the virDomainScreenshot
function is wrapped and a unit test added to exercise it a bit.

Claudio Bley (3):
  Implement interface ByteChannel for Stream class
  Domain: add screenshot method
  test: add testDomainScreenshot JUnit test

 src/main/java/org/libvirt/Domain.java   |  11 ++
 src/main/java/org/libvirt/Stream.java   | 175 +++-
 src/main/java/org/libvirt/jna/Libvirt.java  |   7 +-
 src/test/java/org/libvirt/TestJavaBindings.java |  38 +
 4 files changed, 226 insertions(+), 5 deletions(-)

-- 
1.8.5.2.msysgit.0

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


Re: [libvirt] [PATCHV2] qemu: Add support for changing timeout value to open unix monitor socket

2014-01-08 Thread Cole Robinson
On 01/07/2014 05:39 AM, Richard W.M. Jones wrote:
> On Tue, Jan 07, 2014 at 11:37:11AM +0100, Martin Kletzander wrote:
>> On Tue, Jan 07, 2014 at 10:28:41AM +, Richard W.M. Jones wrote:
>>> On Thu, Jan 02, 2014 at 06:29:35PM +0200, Pavel Fux wrote:
 Adding an option to change monitor socket opening timeout
 the current default is 3 seconds and in some cases it's not enough
>>>
>>> This should change the *default* to something way bigger than 3
>>> seconds, since lots of people are hitting this.  Just look at the
>>> dozen Ubuntu forum posts and many other bug reports:
>>>
>>> https://www.google.co.uk/search?q="monitor+socket+did+not+show+up";
>>>
>>> Sure it can be configurable if you want, but I don't want to have to
>>> tell each and every libguestfs user that they should change this to
>>> something sensible.  Make the default something much larger.
>>>
>>
>> I agree with you here, we could change it to at least 5 seconds *and*
>> make it configurable.  I'll propose the change of the default in
>> separate patch and try reviewing this ASAP.
> 
> Is there a reason not to make it 30 seconds?
> 
> The only downside I can see is that if qemu is really hanging/broken
> users will have to wait 30 seconds to see that it is hanging, versus
> waiting 3 or 5 seconds.  I can't see that is much of a drawback.
> 

I agree that bumping the timeout to 30 seconds should be fine: qemu actually
hanging before the monitor socket is setup is something I never hear about, so
the large timeout shouldn't matter much in practice. So ACK to raising it to 30.

- Cole

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


Re: [libvirt] [libvirt-java] [PATCH] Avoid calling processError for functions that cannot fail

2014-01-08 Thread Claudio Bley
At Wed, 08 Jan 2014 16:31:38 +0100,
Claudio Bley wrote:
> 
> At Wed,  8 Jan 2014 16:25:30 +0100,
> Claudio Bley wrote:
> > 
> > The libvirt functions virNodeDeviceNumOfCaps, virNodeDeviceGetParent
> > and virNodeDeviceListCaps never indicate an error because they do not
> > fail.
> > ---
> >  src/main/java/org/libvirt/Device.java  | 19 ++-
> >  src/main/java/org/libvirt/jna/Libvirt.java |  2 +-
> >  2 files changed, 7 insertions(+), 14 deletions(-)
> > 
> > diff --git a/src/main/java/org/libvirt/jna/Libvirt.java 
> > b/src/main/java/org/libvirt/jna/Libvirt.java
> > index b026b04..a2bf42e 100644
> > --- a/src/main/java/org/libvirt/jna/Libvirt.java
> > +++ b/src/main/java/org/libvirt/jna/Libvirt.java
> > @@ -281,7 +281,7 @@ public interface Libvirt extends Library {
> >  String virNodeDeviceGetName(DevicePointer virDevicePointer);
> >  String virNodeDeviceGetParent(DevicePointer virDevicePointer);
> >  int virNodeDeviceNumOfCaps(DevicePointer virDevicePointer);
> > -int virNodeDeviceListCaps(DevicePointer virDevicePointer, String[] 
> > names, int maxNames);
> > +int virNodeDeviceListCaps(DevicePointer virDevicePointer, Pointer[] 
> > names, int maxNames);
> >  String virNodeDeviceGetXMLDesc(DevicePointer virDevicePointer);
> >  int virNodeDeviceFree(DevicePointer virDevicePointer);
> >  int virNodeDeviceDettach(DevicePointer virDevicePointer);
> 
> I just realized that this hunk does not belong to the patch. Please
> ignore it when reviewing.

Looking at this patch again made me think...

Libvirt is a connection based (ie. client / server) system. Which
means that basically *any* function could fail -- except those which
don't require a valid connection.

Self-NACK in this case.

This is a bit misleading in the documentation; I would have assumed
that a function documented as returning NULL representing "nothing
found" has no other meaning of indicating an error. But, rather, it
means either nothing found or an error occurred and I have to check
for an error, right?

Claudio
-- 
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:

Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

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

Re: [libvirt] [libvirt-java] [PATCH] Avoid calling processError for functions that cannot fail

2014-01-08 Thread Claudio Bley
At Wed,  8 Jan 2014 16:25:30 +0100,
Claudio Bley wrote:
> 
> The libvirt functions virNodeDeviceNumOfCaps, virNodeDeviceGetParent
> and virNodeDeviceListCaps never indicate an error because they do not
> fail.
> ---
>  src/main/java/org/libvirt/Device.java  | 19 ++-
>  src/main/java/org/libvirt/jna/Libvirt.java |  2 +-
>  2 files changed, 7 insertions(+), 14 deletions(-)
> 
> diff --git a/src/main/java/org/libvirt/jna/Libvirt.java 
> b/src/main/java/org/libvirt/jna/Libvirt.java
> index b026b04..a2bf42e 100644
> --- a/src/main/java/org/libvirt/jna/Libvirt.java
> +++ b/src/main/java/org/libvirt/jna/Libvirt.java
> @@ -281,7 +281,7 @@ public interface Libvirt extends Library {
>  String virNodeDeviceGetName(DevicePointer virDevicePointer);
>  String virNodeDeviceGetParent(DevicePointer virDevicePointer);
>  int virNodeDeviceNumOfCaps(DevicePointer virDevicePointer);
> -int virNodeDeviceListCaps(DevicePointer virDevicePointer, String[] 
> names, int maxNames);
> +int virNodeDeviceListCaps(DevicePointer virDevicePointer, Pointer[] 
> names, int maxNames);
>  String virNodeDeviceGetXMLDesc(DevicePointer virDevicePointer);
>  int virNodeDeviceFree(DevicePointer virDevicePointer);
>  int virNodeDeviceDettach(DevicePointer virDevicePointer);

I just realized that this hunk does not belong to the patch. Please
ignore it when reviewing.

Claudio
-- 
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:

Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

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

[libvirt] [libvirt-java] [PATCH] Use virFree in order to release memory acquired from libvirt

2014-01-08 Thread Claudio Bley
When JNA is linked to a different runtime library than libvirt, using
JNA's Native.free will probably lead to crashes as witnessed on
Windows:

 # A fatal error has been detected by the Java Runtime Environment:
 #
 #  EXCEPTION_ACCESS_VIOLATION (0xc005) at pc=0x77363290, 
pid=10180, tid=9908
 #
 # JRE version: 7.0_25-b16
 # Java VM: Java HotSpot(TM) 64-Bit Server VM (23.25-b01 mixed mode 
windows-amd64 compressed oops)
 # Problematic frame:
 # C  [ntdll.dll+0x53290]  RtlFreeHeap+0xd0

The root cause is that the libvirt DLL uses MSVCRT as its runtime
library, whereas the jnidispatch DLL of JNA uses a different one.

At runtime, when calling org.sun.com.jna.Native.free() the OS function
RtlFreeHeap is called with an invalid Pointer that was actually
allocated by MSVCRT's malloc.

Basically, we cannot simply mix and match memory allocation functions
from different runtime libraries, but have to call virFree for
pointers orignating from libvirt itself.

So, this patch re-adds and uses the virFree method which had been
removed in commit 3220de292990bed71828fba2f3700bc846d440f2.

Signed-off-by: Claudio Bley 
---
 src/main/java/org/libvirt/Library.java | 4 ++--
 src/main/java/org/libvirt/jna/Libvirt.java | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/libvirt/Library.java 
b/src/main/java/org/libvirt/Library.java
index 0136095..33d3042 100644
--- a/src/main/java/org/libvirt/Library.java
+++ b/src/main/java/org/libvirt/Library.java
@@ -4,6 +4,7 @@ import org.libvirt.jna.Libvirt;
 
 import com.sun.jna.Native;
 import com.sun.jna.Pointer;
+import com.sun.jna.ptr.PointerByReference;
 
 /**
  * This class represents an instance of the JNA mapped libvirt
@@ -38,8 +39,7 @@ final class Library {
  * Free memory pointed to by ptr.
  */
 static void free(Pointer ptr) {
-Native.free(Pointer.nativeValue(ptr));
-Pointer.nativeValue(ptr, 0L);
+libvirt.virFree(new PointerByReference(ptr));
 }
 
 /**
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java 
b/src/main/java/org/libvirt/jna/Libvirt.java
index 813f09b..b026b04 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -7,6 +7,7 @@ import com.sun.jna.NativeLong;
 import com.sun.jna.Pointer;
 import com.sun.jna.ptr.IntByReference;
 import com.sun.jna.ptr.LongByReference;
+import com.sun.jna.ptr.PointerByReference;
 
 /**
  * The libvirt interface which is exposed via JNA. The complete API is
@@ -171,6 +172,7 @@ public interface Libvirt extends Library {
 int virGetVersion(LongByReference libVer, String type, LongByReference 
typeVer);
 int virInitialize();
 int virCopyLastError(virError error);
+void virFree(PointerByReference ptr);
 virError virGetLastError();
 void virResetLastError();
 void virSetErrorFunc(Pointer userData, VirErrorCallback callback);
-- 
1.8.5.2.msysgit.0

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


[libvirt] [libvirt-java] [PATCH] Avoid calling processError for functions that cannot fail

2014-01-08 Thread Claudio Bley
The libvirt functions virNodeDeviceNumOfCaps, virNodeDeviceGetParent
and virNodeDeviceListCaps never indicate an error because they do not
fail.
---
 src/main/java/org/libvirt/Device.java  | 19 ++-
 src/main/java/org/libvirt/jna/Libvirt.java |  2 +-
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/libvirt/Device.java 
b/src/main/java/org/libvirt/Device.java
index fe49ce9..5492b69 100644
--- a/src/main/java/org/libvirt/Device.java
+++ b/src/main/java/org/libvirt/Device.java
@@ -98,23 +98,19 @@ public class Device {
 /**
  * Returns the number of capabilities which the instance has.
  *
- * @throws LibvirtException
+ * @throws LibvirtException never
  */
 public int getNumberOfCapabilities() throws LibvirtException {
-int num = libvirt.virNodeDeviceNumOfCaps(VDP);
-processError();
-return num;
+return libvirt.virNodeDeviceNumOfCaps(VDP);
 }
 
 /**
  * Returns the parent of the device
  *
- * @throws LibvirtException
+ * @throws LibvirtException never
  */
 public String getParent() throws LibvirtException {
-String parent = libvirt.virNodeDeviceGetParent(VDP);
-processError();
-return parent;
+return libvirt.virNodeDeviceGetParent(VDP);
 }
 
 /**
@@ -123,15 +119,13 @@ public class Device {
  * @throws LibvirtException
  */
 public String getXMLDescription() throws LibvirtException {
-String desc = libvirt.virNodeDeviceGetXMLDesc(VDP);
-processError();
-return desc;
+return processError(libvirt.virNodeDeviceGetXMLDesc(VDP));
 }
 
 /**
  * List the capabilities of the device
  *
- * @throws LibvirtException
+ * @throws LibvirtException never
  */
 public String[] listCapabilities() throws LibvirtException {
 int maxCaps = getNumberOfCapabilities();
@@ -139,7 +133,6 @@ public class Device {
 
 if (maxCaps > 0) {
 libvirt.virNodeDeviceListCaps(VDP, names, maxCaps);
-processError();
 }
 return names;
 }
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java 
b/src/main/java/org/libvirt/jna/Libvirt.java
index b026b04..a2bf42e 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -281,7 +281,7 @@ public interface Libvirt extends Library {
 String virNodeDeviceGetName(DevicePointer virDevicePointer);
 String virNodeDeviceGetParent(DevicePointer virDevicePointer);
 int virNodeDeviceNumOfCaps(DevicePointer virDevicePointer);
-int virNodeDeviceListCaps(DevicePointer virDevicePointer, String[] names, 
int maxNames);
+int virNodeDeviceListCaps(DevicePointer virDevicePointer, Pointer[] names, 
int maxNames);
 String virNodeDeviceGetXMLDesc(DevicePointer virDevicePointer);
 int virNodeDeviceFree(DevicePointer virDevicePointer);
 int virNodeDeviceDettach(DevicePointer virDevicePointer);
-- 
1.8.5.2.msysgit.0

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


Re: [libvirt] [PATCH 0/2 v2] Fixes on shareable SCSI host device

2014-01-08 Thread Osier Yang

On 08/01/14 22:51, Osier Yang wrote:

Forgot to mention that the lacked tests for scsi utils will come
soon.


*** BLURB HERE ***

Osier Yang (2):
   util: Add "shareable" field for virSCSIDevice struct
   qemu: Don't fail if the SCSI host device is shareable between domains

  src/libvirt_private.syms |  3 +-
  src/qemu/qemu_cgroup.c   |  3 +-
  src/qemu/qemu_hostdev.c  | 84 ++--
  src/security/security_apparmor.c |  3 +-
  src/security/security_dac.c  |  6 ++-
  src/security/security_selinux.c  |  6 ++-
  src/util/virscsi.c   | 59 +++-
  src/util/virscsi.h   | 11 --
  8 files changed, 116 insertions(+), 59 deletions(-)



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


[libvirt] [PATCH 2/2] qemu: Don't fail if the SCSI host device is shareable between domains

2014-01-08 Thread Osier Yang
It doesn't make sense to fail if the SCSI host device is specified
as "shareable" explicitly between domains (NB, it works if and only
if the device is specified as "shareable" for *all* domains,
otherwise it fails).

To fix the problem, this patch introduces an array for virSCSIDevice
struct, which records all the names of domain which are using the
device (note that the recorded domains must specifiy the device as
shareable).  And the change on the data struct brings on many
subsequent changes in the code.

* src/util/virscsi.h:
  - Remove virSCSIDeviceGetUsedBy
  - Change definition of virSCSIDeviceGetUsedBy and virSCSIDeviceListDel
  - Add virSCSIDeviceIsAvailable

* src/util/virscsi.c:
  - struct virSCSIDevice: Change "used_by" to be an array; Add
"n_used_by" as the array count
  - virSCSIDeviceGetUsedBy: Removed
  - virSCSIDeviceFree: frees the "used_by" array
  - virSCSIDeviceSetUsedBy: Copy the domain name to avoid potential
memory corruption
  - virSCSIDeviceIsAvailable: New
  - virSCSIDeviceListDel: Change the logic, for device which is already
in the list, just remove the corresponding entry in "used_by"
  - Copyright updating

* src/libvirt_private.sys:
  - virSCSIDeviceGetUsedBy: Remove
  - virSCSIDeviceIsAvailable: New

* src/qemu/qemu_hostdev.c:
  - qemuUpdateActiveScsiHostdevs: Check if the device existing before
adding it to the list;
  - qemuPrepareHostdevSCSIDevices: Error out if the not all domains
use the device as "shareable"; Also don't try to add the device
to the activeScsiHostdevs list if it already there.
  - qemuDomainReAttachHostScsiDevices: Change the logic according
to the changes on helpers.
---
 src/libvirt_private.syms |  2 +-
 src/qemu/qemu_hostdev.c  | 75 ++--
 src/util/virscsi.c   | 48 +--
 src/util/virscsi.h   |  7 +++--
 4 files changed, 84 insertions(+), 48 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 65d1bde..bd5f466 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1677,7 +1677,7 @@ virSCSIDeviceGetSgName;
 virSCSIDeviceGetShareable;
 virSCSIDeviceGetTarget;
 virSCSIDeviceGetUnit;
-virSCSIDeviceGetUsedBy;
+virSCSIDeviceIsAvailable;
 virSCSIDeviceListAdd;
 virSCSIDeviceListCount;
 virSCSIDeviceListDel;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 86a463a..9d81e94 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -250,13 +250,14 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
 virDomainHostdevDefPtr hostdev = NULL;
 size_t i;
 int ret = -1;
+virSCSIDevicePtr scsi = NULL;
+virSCSIDevicePtr tmp = NULL;
 
 if (!def->nhostdevs)
 return 0;
 
 virObjectLock(driver->activeScsiHostdevs);
 for (i = 0; i < def->nhostdevs; i++) {
-virSCSIDevicePtr scsi = NULL;
 hostdev = def->hostdevs[i];
 
 if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
@@ -271,11 +272,18 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
   hostdev->shareable)))
 goto cleanup;
 
-virSCSIDeviceSetUsedBy(scsi, def->name);
-
-if (virSCSIDeviceListAdd(driver->activeScsiHostdevs, scsi) < 0) {
+if ((tmp = virSCSIDeviceListFind(driver->activeScsiHostdevs, scsi))) {
+if (virSCSIDeviceSetUsedBy(tmp, def->name) < 0) {
+virSCSIDeviceFree(scsi);
+goto cleanup;
+}
 virSCSIDeviceFree(scsi);
-goto cleanup;
+} else {
+if (virSCSIDeviceSetUsedBy(scsi, def->name) < 0 ||
+virSCSIDeviceListAdd(driver->activeScsiHostdevs, scsi) < 0) {
+virSCSIDeviceFree(scsi);
+goto cleanup;
+}
 }
 }
 ret = 0;
@@ -1118,24 +1126,26 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
 for (i = 0; i < count; i++) {
 virSCSIDevicePtr scsi = virSCSIDeviceListGet(list, i);
 if ((tmp = virSCSIDeviceListFind(driver->activeScsiHostdevs, scsi))) {
-const char *other_name = virSCSIDeviceGetUsedBy(tmp);
-
-if (other_name)
-virReportError(VIR_ERR_OPERATION_INVALID,
-   _("SCSI device %s is in use by domain %s"),
-   virSCSIDeviceGetName(tmp), other_name);
-else
+if (!(virSCSIDeviceGetShareable(scsi) &&
+  virSCSIDeviceGetShareable(tmp))) {
 virReportError(VIR_ERR_OPERATION_INVALID,
-   _("SCSI device %s is already in use"),
+   _("SCSI device %s is already in use "
+ "by other domain(s)"),
virSCSIDeviceGetName(tmp));
-goto error;
-}
+goto error;
+}
 
-virSCSIDeviceSetUsedB

Re: [libvirt] [PATCH] util: Use new array management macros

2014-01-08 Thread Osier Yang

On 07/01/14 23:16, Eric Blake wrote:

On 01/07/2014 08:03 AM, Osier Yang wrote:

Like commit 94a26c7e from Eric Blake, the old fuzzy code should
be replaced by the new array management macros now.

And the type of scsi->count should be changed into "size_t", and
thus virSCSIDeviceListCount should return size_t instead, similar
for vir{PCI,USB}DeviceListCount.
---
  src/util/virpci.c  |  2 +-
  src/util/virpci.h  |  2 +-
  src/util/virscsi.c | 35 ++-
  src/util/virscsi.h |  2 +-
  src/util/virusb.c  |  2 +-
  src/util/virusb.h  |  2 +-
  6 files changed, 15 insertions(+), 30 deletions(-)

Not quite.


@@ -387,24 +382,14 @@ virSCSIDeviceListSteal(virSCSIDeviceListPtr list,
  size_t i;
  
  for (i = 0; i < list->count; i++) {

-if (list->devs[i]->adapter != dev->adapter ||
-list->devs[i]->bus != dev->bus ||
-list->devs[i]->target != dev->target ||
-list->devs[i]->unit != dev->unit)

In the old code, if 3 of the 4 items match, but the fourth does not,
then we skip that item.


-continue;
-
-ret = list->devs[i];
-
-if (i != list->count--)
-memmove(&list->devs[i],
-&list->devs[i+1],
-sizeof(*list->devs) * (list->count - i));
-
-if (VIR_REALLOC_N(list->devs, list->count) < 0) {
-; /* not fatal */
+if (list->devs[i]->adapter == dev->adapter ||
+list->devs[i]->bus == dev->bus ||
+list->devs[i]->target == dev->target ||
+list->devs[i]->unit == dev->unit) {

In the new code as written, only 1 of the 4 items has to match.  You
applied deMorgan's theorem incorrectly; this must be:


I was too quick, fixed and pushed. Thanks.

Regards.
Osier

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


[libvirt] [libvirt-java] [PATCH] Fix wrapping of virStreamSend

2014-01-08 Thread Claudio Bley
The native virStreamSend function is meant to be used to transfer
byte data.

Wrapping the function to use a Java String as the data depends on
the default charset of the JVM and might impose further problems
transferring \0 characters.

Use a byte Array as the parameter type instead, as for virStreamRecv.

Add the Stream.receive(byte[]) method which should be used instead
of the legacy Stream.receive(String) method.  The old method is kept
for backward compatibility, but marked as deprecated.
---
 src/main/java/org/libvirt/Stream.java  | 27 +--
 src/main/java/org/libvirt/jna/Libvirt.java |  2 +-
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/libvirt/Stream.java 
b/src/main/java/org/libvirt/Stream.java
index bd8e87f..404c9a0 100644
--- a/src/main/java/org/libvirt/Stream.java
+++ b/src/main/java/org/libvirt/Stream.java
@@ -142,6 +142,27 @@ public class Stream {
 }
 
 /**
+ * Write the data of the given string to a stream.
+ *
+ * @param data
+ *the string data to write
+ * @return the number of bytes written, -1 on error, -2 if the buffer is
+ * full
+ * @throws LibvirtException
+ *
+ * @deprecated This libvirt API was previously wrapped incorrectly, since
+ * the native function is meant to transfer bytes, not string
+ * data.
+ * Its effect depends on the default Charset on your platform
+ * which is determined on JVM startup.
+ * Use the {@link #send(byte[])} method instead.
+ */
+@Deprecated
+public int send(String data) throws LibvirtException {
+return send(data.getBytes(java.nio.charset.Charset.defaultCharset()));
+}
+
+/**
  * Write a series of bytes to the stream.
  *
  * @param data
@@ -149,9 +170,11 @@ public class Stream {
  * @return the number of bytes written, -1 on error, -2 if the buffer is
  * full
  * @throws LibvirtException
+ *
+ * @since  1.5.2
  */
-public int send(String data) throws LibvirtException {
-int returnValue = libvirt.virStreamSend(VSP, data, new 
NativeLong(data.length()));
+public int send(byte[] data) throws LibvirtException {
+int returnValue = libvirt.virStreamSend(VSP, data, new 
NativeLong(data.length));
 processError();
 return returnValue;
 }
diff --git a/src/main/java/org/libvirt/jna/Libvirt.java 
b/src/main/java/org/libvirt/jna/Libvirt.java
index 813f09b..98f2125 100644
--- a/src/main/java/org/libvirt/jna/Libvirt.java
+++ b/src/main/java/org/libvirt/jna/Libvirt.java
@@ -368,7 +368,7 @@ public interface Libvirt extends Library {
 int virStreamFinish(StreamPointer virStreamPtr) ;
 int virStreamFree(StreamPointer virStreamPtr) ;
 StreamPointer virStreamNew(ConnectionPointer virConnectPtr, int flags) ;
-int virStreamSend(StreamPointer virStreamPtr, String data, NativeLong 
size);
+int virStreamSend(StreamPointer virStreamPtr, byte[] data, NativeLong 
size);
 int virStreamSendAll(StreamPointer virStreamPtr, 
Libvirt.VirStreamSourceFunc handler, Pointer opaque);
 int virStreamRecv(StreamPointer virStreamPtr, byte[] data, NativeLong 
length);
 int virStreamRecvAll(StreamPointer virStreamPtr, Libvirt.VirStreamSinkFunc 
handler, Pointer opaque);
-- 
1.8.5.2.msysgit.0

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


[libvirt] [PATCH 0/2 v2] Fixes on shareable SCSI host device

2014-01-08 Thread Osier Yang
*** BLURB HERE ***

Osier Yang (2):
  util: Add "shareable" field for virSCSIDevice struct
  qemu: Don't fail if the SCSI host device is shareable between domains

 src/libvirt_private.syms |  3 +-
 src/qemu/qemu_cgroup.c   |  3 +-
 src/qemu/qemu_hostdev.c  | 84 ++--
 src/security/security_apparmor.c |  3 +-
 src/security/security_dac.c  |  6 ++-
 src/security/security_selinux.c  |  6 ++-
 src/util/virscsi.c   | 59 +++-
 src/util/virscsi.h   | 11 --
 8 files changed, 116 insertions(+), 59 deletions(-)

-- 
1.8.1.4

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


[libvirt] [PATCH 1/2] util: Add "shareable" field for virSCSIDevice struct

2014-01-08 Thread Osier Yang
Unlike the host devices of other types, SCSI host device XML supports
"shareable" tag. This patch introduces it for the virSCSIDevice struct
for a later patch use (to detect if the SCSI device is shareable when
preparing the SCSI host device in QEMU driver).
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_cgroup.c   |  3 ++-
 src/qemu/qemu_hostdev.c  |  9 ++---
 src/security/security_apparmor.c |  3 ++-
 src/security/security_dac.c  |  6 --
 src/security/security_selinux.c  |  6 --
 src/util/virscsi.c   | 11 ++-
 src/util/virscsi.h   |  4 +++-
 8 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index fbc9e11..65d1bde 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1674,6 +1674,7 @@ virSCSIDeviceGetDevName;
 virSCSIDeviceGetName;
 virSCSIDeviceGetReadonly;
 virSCSIDeviceGetSgName;
+virSCSIDeviceGetShareable;
 virSCSIDeviceGetTarget;
 virSCSIDeviceGetUnit;
 virSCSIDeviceGetUsedBy;
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index a18955e..10b1131 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -295,7 +295,8 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm,
  dev->source.subsys.u.scsi.bus,
  dev->source.subsys.u.scsi.target,
  dev->source.subsys.u.scsi.unit,
- dev->readonly)) == NULL)
+ dev->readonly,
+ dev->shareable)) == NULL)
 goto cleanup;
 
 if (virSCSIDeviceFileIterate(scsi,
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index dee61e7..86a463a 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -267,7 +267,8 @@ qemuUpdateActiveScsiHostdevs(virQEMUDriverPtr driver,
   hostdev->source.subsys.u.scsi.bus,
   hostdev->source.subsys.u.scsi.target,
   hostdev->source.subsys.u.scsi.unit,
-  hostdev->readonly)))
+  hostdev->readonly,
+  hostdev->shareable)))
 goto cleanup;
 
 virSCSIDeviceSetUsedBy(scsi, def->name);
@@ -1097,7 +1098,8 @@ qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
   hostdev->source.subsys.u.scsi.bus,
   hostdev->source.subsys.u.scsi.target,
   hostdev->source.subsys.u.scsi.unit,
-  hostdev->readonly)))
+  hostdev->readonly,
+  hostdev->shareable)))
 goto cleanup;
 
 if (scsi && virSCSIDeviceListAdd(list, scsi) < 0) {
@@ -1395,7 +1397,8 @@ qemuDomainReAttachHostScsiDevices(virQEMUDriverPtr driver,
   hostdev->source.subsys.u.scsi.bus,
   hostdev->source.subsys.u.scsi.target,
   hostdev->source.subsys.u.scsi.unit,
-  hostdev->readonly))) {
+  hostdev->readonly,
+  hostdev->shareable))) {
 VIR_WARN("Unable to reattach SCSI device %s:%d:%d:%d on domain %s",
  hostdev->source.subsys.u.scsi.adapter,
  hostdev->source.subsys.u.scsi.bus,
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index a9f04d2..86a033f 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -833,7 +833,8 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
  dev->source.subsys.u.scsi.bus,
  dev->source.subsys.u.scsi.target,
  dev->source.subsys.u.scsi.unit,
- dev->readonly);
+ dev->readonly,
+ dev->shareable);
 
  if (!scsi)
  goto done;
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index cb7d322..0952df9 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -536,7 +536,8 @@ virSecurityDACSetSecurityHostdevLabel(virSecurityManagerPtr 
mgr,
  dev->source.subsys.u.scsi.bus,
  dev->source.subsys.u.scsi.target,
  dev->source.subsys.u.scsi.unit,
- dev->readonly);
+ dev->readonly,
+ dev->shareable);
 
 if (!scsi)
 goto

[libvirt] [libvirt-java] [PATCH] Fix javadoc warning about snapshotCreateXML(int)

2014-01-08 Thread Claudio Bley
Javadoc complains about:

[javadoc] x:\src\libvirt-java1\src\main\java\org\libvirt\Domain.java:1212:
warning - Tag @see: can't find snapshotCreateXML(int) in org.libvirt.Domain

There is no such method, snapshotCreateXML(String, int) was intended.
---
Pushing under the trivial rule.

 src/main/java/org/libvirt/Domain.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/libvirt/Domain.java 
b/src/main/java/org/libvirt/Domain.java
index ee26a95..e4c45f6 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -1189,7 +1189,7 @@ public class Domain {
  * This is just a convenience method, it has the same effect
  * as calling {@code snapshotCreateXML(xmlDesc, 0);}.
  *
- * @see #snapshotCreateXML(int)
+ * @see #snapshotCreateXML(String, int)
  * @see http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotCreateXML";>Libvirt
  *  Documentation
-- 
1.8.5.2.msysgit.0

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


[libvirt] [libvirt-java] [PATCH] Fix javadoc comments

2014-01-08 Thread Claudio Bley
Correct some typos and paste the right documentation from
virInterfaceCreate, virInterfaceDestroy to the Interface.create
and Interface.destroy doc comments.
---
Pushing under the trivial rule.

 src/main/java/org/libvirt/Domain.java  |  2 +-
 .../java/org/libvirt/DomainInterfaceStats.java |  2 +-
 src/main/java/org/libvirt/DomainSnapshot.java  |  2 +-
 src/main/java/org/libvirt/Interface.java   | 22 ++
 src/main/java/org/libvirt/Stream.java  |  4 ++--
 5 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/libvirt/Domain.java 
b/src/main/java/org/libvirt/Domain.java
index e4c45f6..2f70bf2 100644
--- a/src/main/java/org/libvirt/Domain.java
+++ b/src/main/java/org/libvirt/Domain.java
@@ -370,7 +370,7 @@ public class Domain {
 }
 
 /**
- * Provides a boolean value indicating whether the network is configured to
+ * Provides a boolean value indicating whether the domain is configured to
  * be automatically started when the host machine boots.
  *
  * @return the result
diff --git a/src/main/java/org/libvirt/DomainInterfaceStats.java 
b/src/main/java/org/libvirt/DomainInterfaceStats.java
index 0e948d5..eab5c44 100644
--- a/src/main/java/org/libvirt/DomainInterfaceStats.java
+++ b/src/main/java/org/libvirt/DomainInterfaceStats.java
@@ -3,7 +3,7 @@ package org.libvirt;
 import org.libvirt.jna.virDomainInterfaceStats;
 
 /**
- * The Domain.interfaceStats method returns th network counters in this object
+ * The Domain.interfaceStats method returns the network counters in this 
object.
  *
  * @author stoty
  *
diff --git a/src/main/java/org/libvirt/DomainSnapshot.java 
b/src/main/java/org/libvirt/DomainSnapshot.java
index b58fd20..9409fef 100644
--- a/src/main/java/org/libvirt/DomainSnapshot.java
+++ b/src/main/java/org/libvirt/DomainSnapshot.java
@@ -27,7 +27,7 @@ public class DomainSnapshot {
  *  
href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotDelete";>Libvirt
  *  Documentation
  * @param flags
- *controls teh deletion
+ *controls the deletion
  * @return 0 if the selected snapshot(s) were successfully deleted, -1 on 
error.
  * @throws LibvirtException
  */
diff --git a/src/main/java/org/libvirt/Interface.java 
b/src/main/java/org/libvirt/Interface.java
index 7782fb9..6ea21b6 100644
--- a/src/main/java/org/libvirt/Interface.java
+++ b/src/main/java/org/libvirt/Interface.java
@@ -40,8 +40,13 @@ public class Interface {
 }
 
 /**
- * Create and start a defined network. If the call succeed the network 
moves
- * from the defined to the running networks pools.
+ * Activate an interface (i.e. call "ifup").
+ * 
+ * If there was an open network config transaction at the time
+ * this interface was defined (that is, if
+ * virInterfaceChangeBegin() had been called), the interface will
+ * be brought back down (and then undefined) if
+ * virInterfaceChangeRollback() is called.
  *
  * @throws LibvirtException
  */
@@ -52,8 +57,17 @@ public class Interface {
 }
 
 /**
- * Destroy the network object. The running instance is shutdown if not down
- * already and all resources used by it are given back to the hypervisor.
+ * Deactivate an interface (i.e. call "ifdown").
+ * 
+ * This does not remove the interface from the config, and does
+ * not free the associated virInterfacePtr object.
+ * 
+ * If there is an open network config transaction at the time this
+ * interface is destroyed (that is, if virInterfaceChangeBegin()
+ * had been called), and if the interface is later undefined and
+ * then virInterfaceChangeRollback() is called, the restoral of
+ * the interface definition will also bring the interface back
+ * up.
  *
  * @throws LibvirtException
  */
diff --git a/src/main/java/org/libvirt/Stream.java 
b/src/main/java/org/libvirt/Stream.java
index 84e300c..bd8e87f 100644
--- a/src/main/java/org/libvirt/Stream.java
+++ b/src/main/java/org/libvirt/Stream.java
@@ -100,10 +100,10 @@ public class Stream {
 }
 
 /**
- * Receieves data from teh stream into the buffer provided.
+ * Receives data from the stream into the buffer provided.
  *
  * @param data
- *the put the sata into
+ *buffer to put the data into
  * @return the number of bytes read, -1 on error, -2 if the buffer is empty
  * @throws LibvirtException
  */
-- 
1.8.5.2.msysgit.0

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


[libvirt] [PATCH] conf: trivial typo fix

2014-01-08 Thread Martin Kletzander
Signed-off-by: Martin Kletzander 
---

Notes:
Pushed as trivial.

 src/conf/domain_conf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e65f3e3..416d96e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1,7 +1,7 @@
 /*
  * domain_conf.c: domain XML processing
  *
- * Copyright (C) 2006-2013 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -2692,7 +2692,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def,

 /* This switch statement is here to trigger compiler warning when adding
  * a new device type. When you are adding a new field to the switch you
- * also have to add a iteration statement above. Otherwise the switch
+ * also have to add an iteration statement above. Otherwise the switch
  * statement has no real function here and should be optimized out by the
  * compiler. */
 i = VIR_DOMAIN_DEVICE_LAST;
-- 
1.8.5.2

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


[libvirt] [PATCH RESEND] qemuBuildNicDevStr: Set vectors= on Multiqueue

2014-01-08 Thread Michal Privoznik
Yet another advice appeared on the Multiqueue wiki page:

http://www.linux-kvm.org/page/Multiqueue#Enable_MQ_feature

We should add vectors=N onto the qemu command line, where
N = 2 * (number of queues) + 1.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_command.c | 13 +++--
 src/qemu/qemu_command.h |  2 +-
 src/qemu/qemu_hotplug.c |  4 +---
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 35b7c67..81486df 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4980,7 +4980,7 @@ qemuBuildNicDevStr(virDomainDefPtr def,
virDomainNetDefPtr net,
int vlan,
int bootindex,
-   bool multiqueue,
+   int vhostfdSize,
virQEMUCapsPtr qemuCaps)
 {
 virBuffer buf = VIR_BUFFER_INITIALIZER;
@@ -5035,8 +5035,11 @@ qemuBuildNicDevStr(virDomainDefPtr def,
   
virDomainVirtioEventIdxTypeToString(net->driver.virtio.event_idx));
 }
 }
-if (usingVirtio && multiqueue)
-virBufferAddLit(&buf, ",mq=on");
+if (usingVirtio && vhostfdSize > 1) {
+/* As advised at http://www.linux-kvm.org/page/Multiqueue
+ * we should add vectors=2*N+1 where N is the vhostfdSize */
+virBufferAsprintf(&buf, ",mq=on,vectors=%d", 2 * vhostfdSize + 1);
+}
 if (vlan == -1)
 virBufferAsprintf(&buf, ",netdev=host%s", net->info.alias);
 else
@@ -7591,10 +7594,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
 virCommandAddArgList(cmd, "-netdev", host, NULL);
 }
 if (qemuDomainSupportsNicdev(def, qemuCaps, net)) {
-bool multiqueue = tapfdSize > 1 || vhostfdSize > 1;
-
 if (!(nic = qemuBuildNicDevStr(def, net, vlan, bootindex,
-   multiqueue, qemuCaps)))
+   vhostfdSize, qemuCaps)))
 goto cleanup;
 virCommandAddArgList(cmd, "-device", nic, NULL);
 } else {
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 66c23cc..de7683d 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -105,7 +105,7 @@ char * qemuBuildNicDevStr(virDomainDefPtr def,
   virDomainNetDefPtr net,
   int vlan,
   int bootindex,
-  bool multiqueue,
+  int vhostfdSize,
   virQEMUCapsPtr qemuCaps);
 
 char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 7a8caf1..4315df2 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -998,10 +998,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
 }
 
 if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
-bool multiqueue = tapfdSize > 1 || vhostfdSize > 1;
-
 if (!(nicstr = qemuBuildNicDevStr(vm->def, net, vlan, 0,
-  multiqueue, priv->qemuCaps)))
+  vhostfdSize, priv->qemuCaps)))
 goto try_remove;
 } else {
 if (!(nicstr = qemuBuildNicStr(net, NULL, vlan)))
-- 
1.8.5.1

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


Re: [libvirt] Redefining the XML of VM

2014-01-08 Thread Eric Blake
On 01/08/2014 05:54 AM, kangta123 wrote:
> Hi,
> 
> I'm a newbie to Libvirt,

Any reason you posted the same message twice with just a couple minutes
between them?  Probably because you didn't realize that non-subscribers
are welcome to post.  We'd like to improve our list documentation to
make it more obvious to first time posters that they should NOT double
post, once as a non-subscriber and once as a subscriber, because
subscribing will not make a difference on whether the post goes through
moderation successfully.  But to do that, we need to know what URLs you
used in finding out about the list, whether those pages already mention
this fact, and what we can do to make that information more prominent.

-- 
Eric Blake   eblake 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] Redefining the XML of VM

2014-01-08 Thread Eric Blake
On 01/08/2014 06:36 AM, Ján Tomko wrote:
> On 01/08/2014 01:56 PM, kangta123 wrote:
>> Hi,
>>
>> I'm a newbie to Libvirt, i want to know if i can change the vm definition 
>> xml dynamically. like change cpu, network value.
> 
> You can't do that with hooks. You'll need to edit the domain definition before
> you ask libvirt to start it.

There are _some_ things you can change on a running domain, such as
network devices, by means of hotplug operations.  But you can't do a
wholesale change of the XML outside of hotplug except for an offline domain.

-- 
Eric Blake   eblake 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] Redefining the XML of VM

2014-01-08 Thread Ján Tomko
On 01/08/2014 01:56 PM, kangta123 wrote:
> Hi,
> 
> I'm a newbie to Libvirt, i want to know if i can change the vm definition xml 
> dynamically. like change cpu, network value.

You can't do that with hooks. You'll need to edit the domain definition before
you ask libvirt to start it.

> 
> I found the hook in Libvirt, and i can get the xml from standard input. but i 
> change it and out put to standard output, it no effect. 

Libvirt only reads the standard output of the migrate hook script.

> 
> I was try to execute “virsh define” shell command in python script on hook, 
> but it was blocked and unabled to execute another Libvirt command.

You shouldn't call libvirt functions from your hook script, see
http://libvirt.org/hooks.html#recursive or [1].

> 
> Is there create vm hook in Libvirt?

No (and it wouldn't let you change the definition anyway).

Jan

[1] https://www.redhat.com/archives/libvirt-users/2013-November/msg00020.html




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

Re: [libvirt] [sandbox PATCH v2] Fix FSF address on bin/virt-sandbox-service

2014-01-08 Thread Christophe Fergeau
On Tue, Jan 07, 2014 at 03:12:34PM +0100, Cédric Bosdonnat wrote:
> ---
>  Use the URLized version
> 
>  bin/virt-sandbox-service | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service
> index 2dcbfb8..884acac 100755
> --- a/bin/virt-sandbox-service
> +++ b/bin/virt-sandbox-service
> @@ -15,8 +15,7 @@
>  # GNU General Public License for more details.
>  #
>  # You should have received a copy of the GNU General Public License
> -# along with this program; if not, write to the Free Software
> -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> +# along with this library.  If not, see .

ACK.

Christophe


pgpo8opzWYzMO.pgp
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] Redefining the XML of VM

2014-01-08 Thread kangta123
Hi,

I'm a newbie to Libvirt, i want to know if i can change the vm definition xml 
dynamically. like change cpu, network value.

I found the hook in Libvirt, and i can get the xml from standard input. but i 
change it and out put to standard output, it no effect. 

I was try to execute “virsh define” shell command in python script on hook, but 
it was blocked and unabled to execute another Libvirt command.

Is there create vm hook in Libvirt?

Any help is appreciated.


 
Regards,

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


[libvirt] Redefining the XML of VM

2014-01-08 Thread kangta123
Hi,

I'm a newbie to Libvirt, i want to know if i can change the vm definition xml 
dynamically. like change cpu, network value.

I found the hook in Libvirt, and i can get the xml from standard input. but i 
change it and out put to standard output, it no effect. 

I was try to execute “virsh define” shell command in python script on hook, but 
it was blocked and unabled to execute another Libvirt command.

Is there create vm hook in Libvirt?

Any help is appreciated.


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

Re: [libvirt] [PATCH] libxl: Fix devid init in libxlMakeNicList

2014-01-08 Thread Ian Campbell
On Wed, 2014-01-08 at 12:20 +0100, Stefan Bader wrote:
> On 08.01.2014 11:42, Ian Campbell wrote:
> > On Wed, 2014-01-08 at 11:39 +0100, Stefan Bader wrote:
> >> This basically reverts commit ba64b97134a6129a48684f22f31be92c3b6eef96
> >> "libxl: Allow libxl to set NIC devid". However assigning devid's
> >> before calling libxlMakeNic does not work as that is calling
> >> libxl_device_nic_init which sets it back to -1.
> >> Right now auto-assignment only works in the hotplug case. But even if
> >> that would be fixed at some point (if that is possible at all),
> > 
> > I think it should be -- any chance you could prepare a patch to libxl as
> > well?
> 
> Not sure that is that simple. At least not in libxl_device_nic_init. The way I
> understand this is done does not seem to allow a good solution. Creation looks
> to allow initializing NIC definitions in some array that is not connected to a
> specific domain, yet.

Right, I think I previously concluded that for the domain create case
this could be done in initiate_domain_create, with the hotplug case
handled via the existing code in libxl_device_nic_add.

> I suppose what I could come up with is the kind of modification I was 
> proposing
> in one of those emails last year (sounds like an awful long time :)). So at 
> the
> point where the device-model is about to get started and the code already 
> loops
> over the NIC definitions. That won't give the libvirt path default devid's but
> any other user that has not done yet.
> 
> -Stefan
> 


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


Re: [libvirt] [PATCH 1/1] virsh nodecpustats erroneously returns stats for offline cpus on Linux

2014-01-08 Thread Pradipta Kumar Banerjee
ping.


On 12/19/2013 10:10 AM, Pradipta Kr. Banerjee wrote:
> From: "Pradipta Kr. Banerjee" 
> 
> virsh nodecpustats erroneously returns stats for offline cpus on Linux
> 
> To retrieve node cpu statistics on Linux system, the
> linuxNodeGetCPUstats function performs a minimal match of the input
> cpuid with the cpuid read from /proc/cpustat. On systems with larger
> cpus this can result in erroneous data.
> For eg if /proc/stat has similar data
>  cpu  3645648 485 361475 3691194868 176595 40645 69850 0 1526172 0
>  cpu0 494045 62 42763 138516619 16107 2339 2431 0 248345 0
>  cpu4 402646 59 34745 138617562 17738 1413 1196 0 193948 0
>  cpu8 318662 32 32119 138715131 7903 927 982 0 115429 0
>  cpu12 247004 33 30465 138791438 5251 759 913 0 51938 0
> 
> and cpu 1,2 are offline, then
> 
> 'virsh nodecpustats 1' displays data for cpu12
> 
> whereas virsh nodecpustats 2 correctly throws the following error
> 
> "error: Unable to get node cpu stats
> error: Invalid cpuNum in linuxNodeGetCPUStats"
> 
> This patch fixes the above mentioned problem
> 
> Signed-off-by: Pradipta Kr. Banerjee 
> ---
>  src/nodeinfo.c | 13 +
>  1 file changed, 13 insertions(+)
> 
> diff --git a/src/nodeinfo.c b/src/nodeinfo.c
> index 1838547..c9e5ff1 100644
> --- a/src/nodeinfo.c
> +++ b/src/nodeinfo.c
> @@ -614,6 +614,8 @@ linuxNodeGetCPUStats(FILE *procstat,
>  unsigned long long usr, ni, sys, idle, iowait;
>  unsigned long long irq, softirq, steal, guest, guest_nice;
>  char cpu_header[3 + INT_BUFSIZE_BOUND(cpuNum)];
> +char cpu_header_read[3 + INT_BUFSIZE_BOUND(cpuNum)];
> +char cpu_header_fmt[8];
> 
>  if ((*nparams) == 0) {
>  /* Current number of cpu stats supported by linux */
> @@ -631,8 +633,11 @@ linuxNodeGetCPUStats(FILE *procstat,
> 
>  if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) {
>  strcpy(cpu_header, "cpu");
> +snprintf(cpu_header_fmt, sizeof(cpu_header_fmt), "%%%ds", 3);
>  } else {
>  snprintf(cpu_header, sizeof(cpu_header), "cpu%d", cpuNum);
> +snprintf(cpu_header_fmt, sizeof(cpu_header_fmt), "%%%ds",
> + (int)(3 + INT_BUFSIZE_BOUND(cpuNum)));
>  }
> 
>  while (fgets(line, sizeof(line), procstat) != NULL) {
> @@ -649,6 +654,14 @@ linuxNodeGetCPUStats(FILE *procstat,
>  continue;
>  }
> 
> +/*
> + * Process with stats gathering only if the cpuid from /proc/stat
> + * matches exactly with the input cpuid
> +*/
> +sscanf(buf, cpu_header_fmt, cpu_header_read);
> +if (STRNEQ(cpu_header, cpu_header_read))
> +continue;
> +
>  for (i = 0; i < *nparams; i++) {
>  virNodeCPUStatsPtr param = ¶ms[i];
> 
> --
> 1.8.3.1
> 


-- 
Regards,
Pradipta

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


Re: [libvirt] [PATCH] libxl: Fix devid init in libxlMakeNicList

2014-01-08 Thread Stefan Bader
On 08.01.2014 11:42, Ian Campbell wrote:
> On Wed, 2014-01-08 at 11:39 +0100, Stefan Bader wrote:
>> This basically reverts commit ba64b97134a6129a48684f22f31be92c3b6eef96
>> "libxl: Allow libxl to set NIC devid". However assigning devid's
>> before calling libxlMakeNic does not work as that is calling
>> libxl_device_nic_init which sets it back to -1.
>> Right now auto-assignment only works in the hotplug case. But even if
>> that would be fixed at some point (if that is possible at all),
> 
> I think it should be -- any chance you could prepare a patch to libxl as
> well?

Not sure that is that simple. At least not in libxl_device_nic_init. The way I
understand this is done does not seem to allow a good solution. Creation looks
to allow initializing NIC definitions in some array that is not connected to a
specific domain, yet.
I suppose what I could come up with is the kind of modification I was proposing
in one of those emails last year (sounds like an awful long time :)). So at the
point where the device-model is about to get started and the code already loops
over the NIC definitions. That won't give the libvirt path default devid's but
any other user that has not done yet.

-Stefan



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] libxl: Fix devid init in libxlMakeNicList

2014-01-08 Thread Ian Campbell
On Wed, 2014-01-08 at 11:39 +0100, Stefan Bader wrote:
> This basically reverts commit ba64b97134a6129a48684f22f31be92c3b6eef96
> "libxl: Allow libxl to set NIC devid". However assigning devid's
> before calling libxlMakeNic does not work as that is calling
> libxl_device_nic_init which sets it back to -1.
> Right now auto-assignment only works in the hotplug case. But even if
> that would be fixed at some point (if that is possible at all),

I think it should be -- any chance you could prepare a patch to libxl as
well?


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


[libvirt] [PATCH] libxl: Fix devid init in libxlMakeNicList

2014-01-08 Thread Stefan Bader
This basically reverts commit ba64b97134a6129a48684f22f31be92c3b6eef96
"libxl: Allow libxl to set NIC devid". However assigning devid's
before calling libxlMakeNic does not work as that is calling
libxl_device_nic_init which sets it back to -1.
Right now auto-assignment only works in the hotplug case. But even if
that would be fixed at some point (if that is possible at all), this
would add a weird dependency between Xen and libvirt versions.
The change here should accept any auto-assignment that makes it into
libxl_device_nic_init. My understanding is that a caller always is
allowed to make the devid choice itself. And assuming libxlMakeNicList
is only used on domain creation, a sequential numbering should be ok.

Signed-off-by: Stefan Bader 
---
 src/libxl/libxl_conf.c |7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 04d01af..4cefadf 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -918,6 +918,13 @@ libxlMakeNicList(virDomainDefPtr def,  libxl_domain_config 
*d_config)
 for (i = 0; i < nnics; i++) {
 if (libxlMakeNic(def, l_nics[i], &x_nics[i]))
 goto error;
+/*
+ * The devid (at least right now) will not get initialized by
+ * libxl in the setup case but is required for starting the
+ * device-model.
+ */
+if (x_nics[i].devid < 0)
+x_nics[i].devid = i;
 }
 
 d_config->nics = x_nics;
-- 
1.7.9.5

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


Re: [libvirt] [PATCH] docs: add LXC multi console command docs and a example

2014-01-08 Thread Michal Privoznik
On 08.01.2014 08:58, Gao feng wrote:
> On 01/08/2014 11:17 AM, Chen Hanxiao wrote:
>> From: Chen Hanxiao 
>>
>> Signed-off-by: Chen Hanxiao 
>> ---
>>  docs/drvlxc.html.in | 17 +
>>  1 file changed, 13 insertions(+), 4 deletions(-)
>>

> 
> ACK
> 

Pushed now.

Michal

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


Re: [libvirt] [PATCH] LXC: create monitor socket under selinux context of domain

2014-01-08 Thread Michal Privoznik
On 08.01.2014 04:03, Gao feng wrote:
> the unix socket /var/run/libvirt/lxc/domain.sock is not created
> under the selinux context which configured by .
> 
> If we try to connect the domain.sock under the selinux context
> of domain in virtLXCProcessConnectMonitor,selinux will deny
> this connect operation.
> 
> type=AVC msg=audit(1387953696.067:662): avc:  denied  { connectto } for  
> pid=21206 comm="libvirtd" path="/usr/local/var/run/libvirt/lxc/systemd.sock" 
> scontext=unconfined_u:system_r:svirt_lxc_net_t:s0:c770,c848 
> tcontext=unconfined_u:system_r:unconfined_t:s0-s0:c0.c1023 
> tclass=unix_stream_socket
> 
> fix this problem by creating socket under selinux context of domain.
> 
> Signed-off-by: Gao feng 
> ---
>  src/lxc/lxc_controller.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
> index a2ae599..5ca960f 100644
> --- a/src/lxc/lxc_controller.c
> +++ b/src/lxc/lxc_controller.c
> @@ -745,6 +745,9 @@ static int 
> virLXCControllerSetupServer(virLXCControllerPtr ctrl)
>   ctrl)))
>  goto error;
>  
> +if (virSecurityManagerSetSocketLabel(ctrl->securityManager, ctrl->def) < 
> 0)
> +goto error;
> +
>  if (!(svc = virNetServerServiceNewUNIX(sockpath,
> 0700,
> 0,
> @@ -757,6 +760,9 @@ static int 
> virLXCControllerSetupServer(virLXCControllerPtr ctrl)
> 5)))
>  goto error;
>  
> +if (virSecurityManagerClearSocketLabel(ctrl->securityManager, ctrl->def) 
> < 0)
> +goto error;
> +
>  if (virNetServerAddService(ctrl->server, svc, NULL) < 0)
>  goto error;
>  virObjectUnref(svc);
> 

ACKed & pushed.

Michal

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


Re: [libvirt] [Users] libvirt migration port configuration and virPortAllocator

2014-01-08 Thread Dan Kenigsberg
On Wed, Jan 08, 2014 at 01:26:23AM +0100, Gianluca Cecchi wrote:
> Hello,
> following the bugzilla here:
> https://bugzilla.redhat.com/show_bug.cgi?id=1019053
> 
> we have
> "
> This is now fixed by v1.1.3-188-g0196845 and v1.1.3-189-ge3ef20d
> "
> 
> Does this mean that f19 that has
> libvirt-1.0.5.8-1.fc19.x86_64
> is out?
> Any time soon to update it?
> I see at
> http://libvirt.org/sources/
> files such as
> libvirt-1.1.4-1.fc19.x86_64.rpm
> since beginning of November...
> any particular reason for no packages neither in updates-testing repo?
> 
> Also, Fedora 20 has libvirt-1.1.3.2-1.fc20.x86_64.rpm
> Did it receive the patch update? I see nothing particular in its changelog...

I suspect that you'd see this bugfix only on libvirt>=1.2, but the best
place for such questions is the libvirt mailing list (CCed).
Unfortunately, that version is not even on virt-preview
http://fedorapeople.org/groups/virt/virt-preview/fedora-19 (but it is on
http://fedorapeople.org/groups/virt/virt-preview/fedora-20 !)

Dan.

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


Re: [libvirt] [PATCH 2/2] virsh: Use inactive definition when removing disk from config

2014-01-08 Thread Peter Krempa
On 01/07/14 18:47, Eric Blake wrote:
> On 01/07/2014 10:12 AM, Peter Krempa wrote:
>> https://bugzilla.redhat.com/show_bug.cgi?id=1049529
>>
>> The 'detach-disk' command in virsh used the active XML definition of a
>> domain even when attempting to remove a disk from the config only. If
>> the disk was only in the inactive definition the operation failed. Fix
>> this by using the inactive XML in case that only the config is affected.
>> ---
>>  tools/virsh-domain.c | 7 ++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> ACK.
> 
>>
>> -if (!(doc = virDomainGetXMLDesc(dom, 0)))
>> +if (flags == VIR_DOMAIN_AFFECT_CONFIG)
> 
> Might be a bit more robust as:
> (flags & (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG)) ==
> VIR_DOMAIN_AFFECT_CONFIG
> in case we have other flags set for other reasons; but right now we
> don't so this works.
> 

Thanks; Series pushed.

Peter



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] virConnectUnregisterCloseCallback: Unlock @conn prior to error dispatch

2014-01-08 Thread Michal Privoznik
On 07.01.2014 18:42, Eric Blake wrote:
> On 01/07/2014 10:25 AM, Michal Privoznik wrote:
>> The function checks for @conn to be valid and locks its mutex. Then, it
>> checks if callee is unregistering the same callback that he registered
>> previously. If this fails an error is reported and  the control jumps to
>> 'error' label. Here, if @conn has some errors (and it certainly does -
>> the one that's been just reported) the conn->mutex is locked again -
>> without any previous unlock:
> 
> ACK; bug introduced in commit ca0ea2a.

AHA! In that case this patch is incomplete as looking at the blamed
commit I've found another candidate worth fixing (even though I have not
experienced any deadlock in it yet): virConnectRegisterCloseCallback().

I've squashed this in prior to push:

diff --git a/src/libvirt.c b/src/libvirt.c
index 1f5590f..619da80 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -20446,9 +20446,9 @@ virConnectRegisterCloseCallback(virConnectPtr conn,
 return 0;

 error:
-virDispatchError(conn);
 virObjectUnlock(conn->closeCallback);
 virMutexUnlock(&conn->lock);
+virDispatchError(conn);
 virObjectUnref(conn);
 return -1;
 }

Thanks!

Michal

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


[libvirt] New feature discussion: Grouping multiple libvirt's in a "pool"

2014-01-08 Thread Ahmed Ossama

Greetings All,

I would like to say "Hi" to everyone on the list since this is my first 
message.


I have couple of servers running CentOS and Debian with kvm and libvirt 
on top. Lately I've been thinking of coordinating them together in a 
pool like XenServer groups servers in a "Pool".


I am totally aware that this feature can be achieved by installing 
OpenStack or any similar orchestrator on top of libvirt. But I would 
like to achieve this feature using libvirt alone as I don't want to 
install any stuff above libvirt.


I was also thinking if each libvirt on every server is aware of other 
resources (Domains, Storage and Network), this could provide better 
support and view to any higher orchestrator utilizing libvirt.


So I am wondering if such feature was discussed previously? And would 
like to hear thoughts or concerns about it.


--
Regards,
Ahmed Ossama

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