Re: [libvirt] about open vswitch supporting?

2012-09-04 Thread yue wang
it seems the  'generic ethernet connection' network doesn't have the
'virtualport ' element, so there is no way to associate it with an
interface's uuid.
are there any workaround?

On Mon, Sep 3, 2012 at 6:41 PM, yue wang heuye.w...@gmail.com wrote:

 Hi:

 i used to use linux bridge and specify interfaces by 'Generic ethernet 
 connection'
 mode,after reading this page:
 http://libvirt.org/formatdomain.html#elementsNICS
 i am not sure if i need to change to another mode(eg:'virtual network') to
 specify interfaces when switching linux bridge to open vswitch?
 any suggestions?


 thanks!
 heuye

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

Re: [libvirt] [PATCH] qemu: Don't update graphic definitions on password change failure

2012-09-04 Thread Michal Privoznik
On 03.09.2012 17:07, Peter Krempa wrote:
 When the password change failed we updated the graphic definition
 anyways, which is not desired.
 ---
  src/qemu/qemu_hotplug.c | 5 +
  1 file changed, 5 insertions(+)
 

ACK

Michal

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


Re: [libvirt] make check failure

2012-09-04 Thread Michal Privoznik
On 03.09.2012 20:49, Laine Stump wrote:
 On 09/03/2012 11:52 AM, Shradha Shah wrote:
 Hello All,

 I wanted to ask a question regarding the tests that are run during make 
 check.

 If a particular test fails when running make check, how do we which test 
 failed
 and why?
 
 The test(s) that failed can be found by searching through the make check
 output for FAIL. Once you've found the test that failed, you can get
 more detailed output from that test by doing the following:
 
   cd tests
   VIR_TEST_DEBUG=2 ./${testname}

Moreover, if you need libvirt debug logs, set LIBVIRT_DEBUG or 
LIBVIRT_LOG_OUTPUTS env variables:

LIBVIRT_DEBUG=1 LIBVIRT_LOG_OUTPUTS=1:file:libvirt.log VIR_TEST_DEBUG=2 
./${testname}

 
 That should given enough information to figure out what's wrong.
 
 --
 libvir-list mailing list
 libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list
 

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


[libvirt] Problen in cloning of thin LVM

2012-09-04 Thread Pankaj Rawat
Hi all,

I have create a Thin lvm  and installed a guest os on it,
Now when i cloned that lvm using virt-clone

# virt-clone --prompt --force --original  lvm_thin1 --name  lvm_thin2 --file 
/dev/volgrp/lvm_thin2

The cloned Disk lvm_thin2 size is fully expanded , But I want a thin Lvm cloned 
image
Well according to my best of knowledge , It could be because the when lvm is 
getting cloned, The zero are read from the original image

#lvs

LV

VG

Attr

LSize

Pool Origin

Data%

lvm_thin1

Volgrp

Vwi-aotz

8.00g

pool

12.18

lvm_thin2

volgrp

Vwi-a-tz

8.00g

pool

100.00

pool

volgrp

twi-a-tz

100.00g



8.97


As you can see above the original LVM utilize only 12.18% disk space from the 
pool, but the cloned lvm_thin2 is fully expanded.

Is there is any way how can I clone a THIN LVM without fully expanding it ? Or 
Is there any way to shrink the cloned LVM to that size without loss of data.

Regards
Pankaj Rawat




DISCLAIMER:

---

The contents of this e-mail and any attachment(s) are confidential and
intended

for the named recipient(s) only. 

It shall not attach any liability on the originator or NECHCL or its

affiliates. Any views or opinions presented in 

this email are solely those of the author and may not necessarily reflect the

opinions of NECHCL or its affiliates. 

Any form of reproduction, dissemination, copying, disclosure, modification,

distribution and / or publication of 

this message without the prior written consent of the author of this e-mail is

strictly prohibited. If you have 

received this email in error please delete it and notify the sender

immediately. .

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

Re: [libvirt] [PATCH] qemu: Don't update graphic definitions on password change failure

2012-09-04 Thread Peter Krempa

On 09/04/12 09:03, Michal Privoznik wrote:

On 03.09.2012 17:07, Peter Krempa wrote:

When the password change failed we updated the graphic definition
anyways, which is not desired.
---
  src/qemu/qemu_hotplug.c | 5 +
  1 file changed, 5 insertions(+)



ACK



Pushed. Thanks!

Peter

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


Re: [libvirt] VM Migration with IEEE802.1Qbh and IEEE802.1Qbg

2012-09-04 Thread Martin Kletzander
On 09/02/2012 01:53 PM, Jagath Weerasinghe wrote:
 Hi All,
 
 Can a VM connected as IEEE802.1Qbh be migrated to a destination host
 as it were connected as IEEE802.1Qbg? What I wanted to know is, is it
 possible to change the configuration from IEEE802.1Qbh to IEEE802.1Qbg
 on the fly?
 

IIUC, you want to migrate the guest from host A, where it has a network
interface connected to 802.1Qbh switch, to host B, where it should be
connected to 802.1Qbg switch, right?

I see three possibilities to do that, but unfortunately I cannot say if
these will work.

If the guest has interface type='network' and that network has
virtualport type='802.1Qbh' on host A and virtualport
type='802.1Qbg' on host B, that might be working as-is.

If the guest has virtualport type='802.1Qbh' specified in its
interface, you should be able to change the type using migrate hook
[1] on host B.

There should be one more option in case the virtualport is specified
in the guest's interface. According to the docs [2], when no type=
is specified for the virtualport element, this should be
auto-completed on the domain startup, but that's most probably not
applicable for your situation (migration).

Is that what you wanted to know?

Martin

[1] http://libvirt.org/hooks.html#qemu_migration
[2] http://libvirt.org/formatdomain.html#elementsNICSVirtual

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


[libvirt] [PATCH v2 4/4] Register cpu hotplug netlink handler for lxc driver.

2012-09-04 Thread Tang Chen
This patch sets cpuset.cpus to the lastest value for lxc driver when the driver
is being initialized, and registers 2 cpu hotplug handlers for lxc driver:
- lxcNetlinkCpuHotplugHandleCallback()
- lxcNetlinkCpuHotplugRemoveCallback()

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 src/lxc/lxc_driver.c |   67 --
 1 file changed, 65 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index ff11c2c..a2f17de 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -63,6 +63,9 @@
 #include virtime.h
 #include virtypedparam.h
 #include viruri.h
+#include hotplug.h
+#include cgroup.h
+#include virnetlink.h
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
@@ -1396,11 +1399,48 @@ error:
 return -1;
 }
 
+static void
+lxcNetlinkCpuHotplugHandleCallback(unsigned char *msg,
+   int length,
+   struct sockaddr_nl *peer ATTRIBUTE_UNUSED,
+   bool *handled ATTRIBUTE_UNUSED,
+   void *opaque)
+{
+virCgroupPtr cgroup = NULL;
+
+/* opaque is a cgroup identifier pointing to libvirt root cgroup. */
+if (!opaque) {
+virReportSystemError(EINVAL,
+ %s,
+ _(invalid argument));
+return;
+}
+
+cgroup = (virCgroupPtr)opaque;
+
+if (virHotplugUpdateCgroupCpuset(msg, length, cgroup)  0) {
+virReportSystemError(errno,
+ %s,
+ _(Unable to update cpuset in cgroup));
+}
+
+return;
+}
+
+static void
+lxcNetlinkCpuHotplugRemoveCallback(int watch ATTRIBUTE_UNUSED,
+   const virMacAddrPtr macaddr 
ATTRIBUTE_UNUSED,
+   void *opaque ATTRIBUTE_UNUSED)
+{
+/* For now, nothing to do. */
+VIR_INFO(CPU hotplug netlink handler has been removed.);
+}
 
 static int lxcStartup(int privileged)
 {
 char *ld;
 int rc;
+char ebuf[1024];
 
 /* Valgrind gets very annoyed when we clone containers, so
  * disable LXC when under valgrind
@@ -1445,14 +1485,37 @@ static int lxcStartup(int privileged)
 
 rc = virCgroupForDriver(lxc, lxc_driver-cgroup, privileged, 1);
 if (rc  0) {
-char buf[1024] ATTRIBUTE_UNUSED;
 VIR_DEBUG(Unable to create cgroup for LXC driver: %s,
-  virStrerror(-rc, buf, sizeof(buf)));
+  virStrerror(-rc, ebuf, sizeof(ebuf)));
 /* Don't abort startup. We will explicitly report to
  * the user when they try to start a VM
  */
 }
 
+#if defined(__linux__)  defined(NETLINK_KOBJECT_UEVENT)
+/**
+ * If we had ever missed any cpu hotplug event, we need to update
+ * cpuset.cpus to the lastest value
+ */
+rc = virHotplugSetCpusetToLastest(lxc_driver-cgroup);
+if (rc  0) {
+VIR_INFO(Unable to reset cgroup for driver: %s,
+ virStrerror(-rc, ebuf, sizeof(ebuf)));
+}
+
+/* Register cpu hotplug event handler for lxc driver */
+if (virNetlinkEventServiceIsRunning(NETLINK_KOBJECT_UEVENT)) {
+rc = virNetlinkEventAddClient(lxcNetlinkCpuHotplugHandleCallback,
+  lxcNetlinkCpuHotplugRemoveCallback,
+  lxc_driver-cgroup, NULL,
+  NETLINK_KOBJECT_UEVENT);
+if (rc  0) {
+VIR_INFO(Unable to register cpu hotplug event handler for driver: 
%s,
+ virStrerror(-rc, ebuf, sizeof(ebuf)));
+}
+}
+#endif
+
 /* Call function to load lxc driver configuration information */
 if (lxcLoadDriverConfig(lxc_driver)  0)
 goto cleanup;
-- 
1.7.10.1

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


[libvirt] [PATCH v2 0/4] Add cpu hotplug support to libvirt.

2012-09-04 Thread Tang Chen
It seems that libvirt is not cpu hotplug aware.
Please refer to the following problem.

1. At first, we have 2 cpus.
# cat /cgroup/cpuset/cpuset.cpus 
0-1
# cat /cgroup/cpuset/libvirt/qemu/cpuset.cpus 
0-1

2. And we have a vm1 with following configuration.
  cputune
vcpupin vcpu='0' cpuset='1'/
emulatorpin cpuset='1'/
  /cputune

3. Offline cpu1.
# echo 0  /sys/devices/system/cpu/cpu1/online
# cat /sys/devices/system/cpu/cpu1/online 
0
# cat /cgroup/cpuset/cpuset.cpus 
0
# cat /cgroup/cpuset/libvirt/qemu/cpuset.cpus 
0
# cat /cgroup/cpuset/libvirt/lxc/cpuset.cpus 
0

4. Online cpu1.
# echo 1  /sys/devices/system/cpu/cpu1/online
# cat /sys/devices/system/cpu/cpu1/online 
1
# cat /cgroup/cpuset/cpuset.cpus 
0-1
# cat /cgroup/cpuset/libvirt/cpuset.cpus 
0
# cat /cgroup/cpuset/libvirt/qemu/cpuset.cpus 
0
# cat /cgroup/cpuset/libvirt/lxc/cpuset.cpus 
0

Here,cgroup updated cpuset.cpus,but not for libvirt directory,and also qemu and 
lxc directory.
vm1 cannot be started again.
# virsh start vm1
error: Failed to start domain vm1
error: Unable to set cpuset.cpus: Permission denied

And libvird gave the following errors.
2012-07-17 07:30:22.478+: 3118: error : qemuSetupCgroupVcpuPin:498 : Unable 
to set cpuset.cpus: Permission denied


These patches resolves this problem by listening on the netlink for cpu hotplug 
event.
When the netlink service gets the cpu hotplug event, it will attract the cpuid 
in the message,
and add it into cpuset.cpus in:
/cgroup/cpuset/libvirt
/cgroup/cpuset/libvirt/qemu
/cgroup/cpuset/libvirt/lxc


change log of v2:
[PATCH v2 1/4]:
* Move all the handlers from hotplug.c to modules who
  want to listen to cpu hotplug events.

[PATCH v2 2/4]:
* Set /libvirt/cpuset.cpus to the lastest value when
  libvirtd is being initialized.

[PATCH v2 3/4]:
* Set /libvirt/qemu/cpuset.cpus to the lastest value when
  qemu driver is being initialized.

[PATCH v2 4/4]:
* Set /libvirt/lxc/cpuset.cpus to the lastest value when
  lxc driver is being initialized.


Tang Chen (4):
  Add helpers to support cpu hotplug in libvirt.
  Register cpu hotplug netlink handler for libvirtd.
  Register cpu hotplug netlink handler for qemu driver.
  Register cpu hotplug netlink handler for lxc driver.

 daemon/libvirtd.c   |   62 +++
 include/libvirt/virterror.h |2 +
 src/Makefile.am |1 +
 src/libvirt_private.syms|7 ++
 src/lxc/lxc_driver.c|   67 +++-
 src/qemu/qemu_driver.c  |   64 
 src/util/cgroup.c   |   10 +-
 src/util/cgroup.h   |7 ++
 src/util/hotplug.c  |  240 +++
 src/util/hotplug.h  |   44 
 src/util/virterror.c|3 +-
 11 files changed, 499 insertions(+), 8 deletions(-)
 create mode 100644 src/util/hotplug.c
 create mode 100644 src/util/hotplug.h

-- 
1.7.10.1


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

[libvirt] [PATCH v2 1/4] Add helpers to support cpu hotplug in libvirt.

2012-09-04 Thread Tang Chen
This patch adds some helpers to support cpu hotplug in libvirt.

virHotplugGetCpuidFromMsg():
Get cpuid from cpu hotplug netlink message. The message is of the following
format:
{online|offline}@/devices/system/cpu/cpuxx (xx is cpuid)

virHotplugUpdateCgroupCpuset():
Update the cpuset.cpus in the specified cgroup when a cpu is hotpluged.

virHotplugSetCpusetToLastest():
Copy the cpuset from root to the specified cgroup.
This function could be used when there are cpu houplug events occurred
when libvirtd is not running.

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 include/libvirt/virterror.h |2 +
 src/Makefile.am |1 +
 src/libvirt_private.syms|6 ++
 src/util/cgroup.c   |4 +-
 src/util/cgroup.h   |3 +
 src/util/hotplug.c  |  240 +++
 src/util/hotplug.h  |   44 
 src/util/virterror.c|3 +-
 8 files changed, 300 insertions(+), 3 deletions(-)
 create mode 100644 src/util/hotplug.c
 create mode 100644 src/util/hotplug.h

diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h
index 5140c38..aabda04 100644
--- a/include/libvirt/virterror.h
+++ b/include/libvirt/virterror.h
@@ -114,6 +114,8 @@ typedef enum {
 
 VIR_FROM_SSH = 50,   /* Error from libssh2 connection transport */
 
+VIR_FROM_HOTPLUG = 51,  /* Error from Hotplug driver */
+
 # ifdef VIR_ENUM_SENTINELS
 VIR_ERR_DOMAIN_LAST
 # endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 95e1bea..c65ee37 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -60,6 +60,7 @@ UTIL_SOURCES =
\
util/event.c util/event.h   \
util/event_poll.c util/event_poll.h \
util/hooks.c util/hooks.h   \
+   util/hotplug.c util/hotplug.h   \
util/iptables.c util/iptables.h \
util/ebtables.c util/ebtables.h \
util/dnsmasq.c util/dnsmasq.h   \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6f14763..2ff7e0e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -94,6 +94,7 @@ virCgroupKillPainfully;
 virCgroupKillRecursive;
 virCgroupMounted;
 virCgroupMoveTask;
+virCgroupNew;
 virCgroupPathOfController;
 virCgroupRemove;
 virCgroupSetBlkioDeviceWeight;
@@ -643,6 +644,11 @@ virHookInitialize;
 virHookPresent;
 
 
+# hotplug.h
+virHotplugUpdateCgroupCpuset;
+virHotplugSetCpusetToLastest;
+
+
 # interface_conf.h
 virInterfaceAssignDef;
 virInterfaceDefFormat;
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 5dc0764..393d439 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -608,8 +608,8 @@ static int virCgroupMakeGroup(virCgroupPtr parent, 
virCgroupPtr group,
 }
 
 
-static int virCgroupNew(const char *path,
-virCgroupPtr *group)
+int virCgroupNew(const char *path,
+ virCgroupPtr *group)
 {
 int rc = 0;
 char *typpath = NULL;
diff --git a/src/util/cgroup.h b/src/util/cgroup.h
index 68ac232..e294495 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -68,6 +68,9 @@ int virCgroupPathOfController(virCgroupPtr group,
   const char *key,
   char **path);
 
+int virCgroupNew(const char *path,
+ virCgroupPtr *group);
+
 int virCgroupAddTask(virCgroupPtr group, pid_t pid);
 
 int virCgroupAddTaskController(virCgroupPtr group,
diff --git a/src/util/hotplug.c b/src/util/hotplug.c
new file mode 100644
index 000..7c44299
--- /dev/null
+++ b/src/util/hotplug.c
@@ -0,0 +1,240 @@
+/*
+ * Copyright (C) 2012 FUJITSU, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;  If not, see
+ * http://www.gnu.org/licenses/.
+ *
+ * Authors:
+ * Tang Chen tangc...@cn.fujitsu.com
+ */
+
+#include sys/types.h
+#include sys/socket.h
+#include string.h
+#include stdlib.h
+
+#include hotplug.h
+#include cgroup.h
+#include buf.h
+#include virterror_internal.h
+#include virnetlink.h
+#include logging.h
+#include memory.h
+#include util.h
+
+#define VIR_FROM_THIS VIR_FROM_HOTPLUG
+
+#ifdef __linux__
+
+/**
+ * CPU hotplug message is of the following format:
+ * 

[libvirt] [PATCH v2 3/4] Register cpu hotplug netlink handler for qemu driver.

2012-09-04 Thread Tang Chen
This patch sets cpuset.cpus to lastest for qemu driver when the driver
is being initialized, and then registers 2 cpu hotplug events handlers
for qemu driver:
- qemuNetlinkCpuHotplugHandleCallback()
- qemuNetlinkCpuHotplugRemoveCallback()

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 src/qemu/qemu_driver.c |   64 
 1 file changed, 64 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 53d6e5b..08f7be1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -92,6 +92,9 @@
 #include virnodesuspend.h
 #include virtime.h
 #include virtypedparam.h
+#include hotplug.h
+#include cgroup.h
+#include virnetlink.h
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -525,6 +528,43 @@ static void qemuDomainNetsRestart(void *payload,
 virDomainObjUnlock(vm);
 }
 
+static void
+qemuNetlinkCpuHotplugHandleCallback(unsigned char *msg,
+int length,
+struct sockaddr_nl *peer ATTRIBUTE_UNUSED,
+bool *handled ATTRIBUTE_UNUSED,
+void *opaque)
+{
+virCgroupPtr cgroup = NULL;
+
+/* opaque is a cgroup identifier pointing to libvirt root cgroup. */
+if (!opaque) {
+virReportSystemError(EINVAL,
+ %s,
+ _(invalid argument));
+return;
+}
+
+cgroup = (virCgroupPtr)opaque;
+
+if (virHotplugUpdateCgroupCpuset(msg, length, cgroup)  0) {
+virReportSystemError(errno,
+ %s,
+ _(Unable to update cpuset in cgroup));
+}
+
+return;
+}
+
+static void
+qemuNetlinkCpuHotplugRemoveCallback(int watch ATTRIBUTE_UNUSED,
+const virMacAddrPtr macaddr 
ATTRIBUTE_UNUSED,
+void *opaque ATTRIBUTE_UNUSED)
+{
+/* For now, nothing to do. */
+VIR_INFO(CPU hotplug netlink handler has been removed.);
+}
+
 /**
  * qemudStartup:
  *
@@ -682,6 +722,30 @@ qemudStartup(int privileged) {
  virStrerror(-rc, ebuf, sizeof(ebuf)));
 }
 
+#if defined(__linux__)  defined(NETLINK_KOBJECT_UEVENT)
+/**
+ * If we had ever missed any cpu hotplug event, we need to update
+ * cpuset.cpus to the lastest value
+ */
+rc = virHotplugSetCpusetToLastest(qemu_driver-cgroup);
+if (rc  0) {
+VIR_INFO(Unable to reset cgroup for driver: %s,
+ virStrerror(-rc, ebuf, sizeof(ebuf)));
+}
+
+/* Register cpu hotplug event handler for qemu driver */
+if (virNetlinkEventServiceIsRunning(NETLINK_KOBJECT_UEVENT)) {
+rc = virNetlinkEventAddClient(qemuNetlinkCpuHotplugHandleCallback,
+  qemuNetlinkCpuHotplugRemoveCallback,
+  qemu_driver-cgroup, NULL,
+  NETLINK_KOBJECT_UEVENT);
+if (rc  0) {
+VIR_INFO(Unable to register cpu hotplug event handler for driver: 
%s,
+ virStrerror(-rc, ebuf, sizeof(ebuf)));
+}
+}
+#endif
+
 if (qemudLoadDriverConfig(qemu_driver, driverConf)  0) {
 goto error;
 }
-- 
1.7.10.1

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


[libvirt] [PATCH v2 2/4] Register cpu hotplug netlink handler for libvirtd.

2012-09-04 Thread Tang Chen
This patch first sets cpuset.cpus to lastest value for libvirtd,
and then registers 2 callback for cpu hotplug event for libvirtd:
- daemonNetlinkCpuHotplugHandleCallback()
- daemonNetlinkCpuHotplugRemoveCallback()

Signed-off-by: Tang Chen tangc...@cn.fujitsu.com
---
 daemon/libvirtd.c|   62 ++
 src/libvirt_private.syms |1 +
 src/util/cgroup.c|6 ++---
 src/util/cgroup.h|4 +++
 4 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 6973df6..b612231 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -56,6 +56,8 @@
 #include uuid.h
 #include viraudit.h
 #include locking/lock_manager.h
+#include cgroup.h
+#include hotplug.h
 
 #ifdef WITH_DRIVER_MODULES
 # include driver.h
@@ -935,6 +937,43 @@ enum {
 OPT_VERSION = 129
 };
 
+static void
+daemonNetlinkCpuHotplugHandleCallback(unsigned char *msg,
+  int length,
+  struct sockaddr_nl *peer 
ATTRIBUTE_UNUSED,
+  bool *handled ATTRIBUTE_UNUSED,
+  void *opaque)
+{
+virCgroupPtr cgroup = NULL;
+
+/* opaque is a cgroup identifier pointing to libvirt root cgroup. */
+if (!opaque) {
+virReportSystemError(EINVAL,
+ %s,
+ _(invalid argument));
+return;
+}
+
+cgroup = (virCgroupPtr)opaque;
+
+if (virHotplugUpdateCgroupCpuset(msg, length, cgroup)  0) {
+virReportSystemError(errno,
+ %s,
+ _(Unable to update cpuset in cgroup));
+}
+
+return;
+}
+
+static void
+daemonNetlinkCpuHotplugRemoveCallback(int watch ATTRIBUTE_UNUSED,
+  const virMacAddrPtr macaddr 
ATTRIBUTE_UNUSED,
+  void *opaque ATTRIBUTE_UNUSED)
+{
+/* For now, nothing to do. */
+VIR_INFO(CPU hotplug netlink handler has been removed.);
+}
+
 #define MAX_LISTEN 5
 int main(int argc, char **argv) {
 virNetServerPtr srv = NULL;
@@ -954,6 +993,7 @@ int main(int argc, char **argv) {
 bool implicit_conf = false;
 char *run_dir = NULL;
 mode_t old_umask;
+virCgroupPtr rootgrp = NULL;
 
 struct option opts[] = {
 { verbose, no_argument, verbose, 1},
@@ -1327,11 +1367,32 @@ int main(int argc, char **argv) {
 #endif
 
 #if defined(__linux__)  defined(NETLINK_KOBJECT_UEVENT)
+/**
+ * If we had ever missed any cpu hotplug event, we need to update
+ * cpuset.cpus to the lastest value
+ */
+if (virCgroupAppRoot(privileged, rootgrp, 0) != 0 ||
+virHotplugSetCpusetToLastest(rootgrp)  0) {
+ret = VIR_DAEMON_ERR_INIT;
+goto cleanup;
+}
+
 /* Register the netlink event service for NETLINK_KOBJECT_UEVENT */
 if (virNetlinkEventServiceStart(NETLINK_KOBJECT_UEVENT, 1)  0) {
 ret = VIR_DAEMON_ERR_NETWORK;
 goto cleanup;
 }
+
+/* Register cpu hotplug event handler for libvirtd */
+if (virNetlinkEventServiceIsRunning(NETLINK_KOBJECT_UEVENT)) {
+if (virNetlinkEventAddClient(daemonNetlinkCpuHotplugHandleCallback,
+ daemonNetlinkCpuHotplugRemoveCallback,
+ rootgrp, NULL,
+ NETLINK_KOBJECT_UEVENT)  0) {
+ret = VIR_DAEMON_ERR_NETWORK;
+goto cleanup;
+}
+}
 #endif
 
 /* Run event loop. */
@@ -1362,6 +1423,7 @@ cleanup:
 if (pid_file_fd != -1)
 virPidFileReleasePath(pid_file, pid_file_fd);
 
+virCgroupFree(rootgrp);
 VIR_FREE(sock_file);
 VIR_FREE(sock_file_ro);
 VIR_FREE(pid_file);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2ff7e0e..752e3b0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -64,6 +64,7 @@ virCgroupAddTaskController;
 virCgroupAllowDevice;
 virCgroupAllowDeviceMajor;
 virCgroupAllowDevicePath;
+virCgroupAppRoot;
 virCgroupControllerTypeFromString;
 virCgroupControllerTypeToString;
 virCgroupDenyAllDevices;
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 393d439..a1b21de 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -641,9 +641,9 @@ err:
 return rc;
 }
 
-static int virCgroupAppRoot(int privileged,
-virCgroupPtr *group,
-int create)
+int virCgroupAppRoot(int privileged,
+ virCgroupPtr *group,
+ int create)
 {
 virCgroupPtr rootgrp = NULL;
 int rc;
diff --git a/src/util/cgroup.h b/src/util/cgroup.h
index e294495..f31346c 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -44,6 +44,10 @@ enum {
 
 VIR_ENUM_DECL(virCgroupController);
 
+int virCgroupAppRoot(int privileged,
+ virCgroupPtr *group,
+   

Re: [libvirt] [libvirt-perl PATCH] Fix several APIs

2012-09-04 Thread Daniel P. Berrange
On Mon, Sep 03, 2012 at 06:29:47PM +0800, Osier Yang wrote:
 On 2012年08月29日 14:44, Daniel P. Berrange wrote:
 On Wed, Aug 29, 2012 at 01:29:37AM -0400, Alex Jia wrote:
 ACK.
 
 --
 Regards,
 Alex
 
 
 - Original Message -
 From: Osier Yangjy...@redhat.com
 To: libvir-list@redhat.com
 Sent: Tuesday, August 28, 2012 11:52:24 PM
 Subject: [libvirt] [libvirt-perl PATCH] Fix several APIs
 
 These APIs accept one more argument (flags), which was ignored in
 the XS implementations.
 ---
   Virt.xs |   46 ++
   1 files changed, 26 insertions(+), 20 deletions(-)
 
 ACK, if you also update the Domain.pm docs to mention the new flags
 parameters
 
 
 Thanks, Pushed with the doc and nits pointed out by gren updated
 (btw, most of the flags for APIs are not documented, and even some
 constants, such as constants for virTypedParameterFlags, could be
 later patch).

Those constants should not be required, since the conversiuon is done
internally. There is a test suite which validates that all libvirt
public constants are present in the Perl binding, minus some blacklisted
constants like virTypedParameterFlags ones


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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

Re: [libvirt] None seclabel question

2012-09-04 Thread Daniel P. Berrange
On Mon, Sep 03, 2012 at 12:57:50PM -0300, Marcelo Cerri wrote:
 Hi,
 
 I was discussing with Jiri Denemark about the current behavior of
 none seclabels with multiple security drivers and I'd like to hear
 more opinions about how this should work.
 
 Currently, a none security label can be defined specifically to each
 enabled security driver. For example, using a default configuration
 (in which SELinux is enabled as default driver and DAC is enabled
 due to privileged mode), a guest definition can contain the
 following seclabel:
 
 seclabel type='none' model='selinux'/
 
 This will disable SELinux labeling and will keep labeling enabled
 for any other security drivers (DAC in this case).
 
 So, my question is: should none seclabels affect specific drivers
 (as done now) or just one none seclabel should be accepted affecting
 all security drivers in use?

No, as with your example above, the type=none is scoped to a specific
driver.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] None seclabel question

2012-09-04 Thread Jiri Denemark
On Tue, Sep 04, 2012 at 10:22:56 +0100, Daniel P. Berrange wrote:
 On Mon, Sep 03, 2012 at 12:57:50PM -0300, Marcelo Cerri wrote:
  Hi,
  
  I was discussing with Jiri Denemark about the current behavior of
  none seclabels with multiple security drivers and I'd like to hear
  more opinions about how this should work.
  
  Currently, a none security label can be defined specifically to each
  enabled security driver. For example, using a default configuration
  (in which SELinux is enabled as default driver and DAC is enabled
  due to privileged mode), a guest definition can contain the
  following seclabel:
  
  seclabel type='none' model='selinux'/
  
  This will disable SELinux labeling and will keep labeling enabled
  for any other security drivers (DAC in this case).
  
  So, my question is: should none seclabels affect specific drivers
  (as done now) or just one none seclabel should be accepted affecting
  all security drivers in use?
 
 No, as with your example above, the type=none is scoped to a specific
 driver.

And what happens if you have older libvirt and a domain configured with
seclabel type='none'/ and upgrade libvirt to the state when it actually
enables more than one security driver at a time. Shouldn't such generic
seclabel type='none'/ actually turn off any labeling, that is, affect all
the enabled drivers?

Jirka

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


Re: [libvirt] None seclabel question

2012-09-04 Thread Daniel P. Berrange
On Tue, Sep 04, 2012 at 11:28:19AM +0200, Jiri Denemark wrote:
 On Tue, Sep 04, 2012 at 10:22:56 +0100, Daniel P. Berrange wrote:
  On Mon, Sep 03, 2012 at 12:57:50PM -0300, Marcelo Cerri wrote:
   Hi,
   
   I was discussing with Jiri Denemark about the current behavior of
   none seclabels with multiple security drivers and I'd like to hear
   more opinions about how this should work.
   
   Currently, a none security label can be defined specifically to each
   enabled security driver. For example, using a default configuration
   (in which SELinux is enabled as default driver and DAC is enabled
   due to privileged mode), a guest definition can contain the
   following seclabel:
   
   seclabel type='none' model='selinux'/
   
   This will disable SELinux labeling and will keep labeling enabled
   for any other security drivers (DAC in this case).
   
   So, my question is: should none seclabels affect specific drivers
   (as done now) or just one none seclabel should be accepted affecting
   all security drivers in use?
  
  No, as with your example above, the type=none is scoped to a specific
  driver.
 
 And what happens if you have older libvirt and a domain configured with
 seclabel type='none'/ and upgrade libvirt to the state when it actually
 enables more than one security driver at a time. Shouldn't such generic
 seclabel type='none'/ actually turn off any labeling, that is, affect all
 the enabled drivers?

IMHO with the old libvirt, if no model= was set, this was implicitly
refering to the current model.


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


[libvirt] error: Failed to start pool (already mounted)

2012-09-04 Thread Ragnar Skúlason
Hi everyone,

I'm not sure if this belongs here, I sent a question to the users list
yesterday without getting a response, so I'm trying here.

I have storage-pool that for some reason became inactive (possibly due to
an error with pool-refresh in an old version of a Java API binding).

I want to restart the pool but am unable to, due to the volume being
mounted:

# virsh pool-start [uuid]
error: Failed to start pool [uuid]
error: Requested operation is not valid: Target '/mnt/[uuid]' is already
mounted

We have tested this with versions 0.9.12 and 0.9.13.

This did work in versions 0.8.x

Is it possible to bypass this mount check and start the storage pool
(forcefully)?

Many thanks,
Ragnar Skúlason
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] None seclabel question

2012-09-04 Thread Jiri Denemark
On Tue, Sep 04, 2012 at 10:31:54 +0100, Daniel P. Berrange wrote:
 On Tue, Sep 04, 2012 at 11:28:19AM +0200, Jiri Denemark wrote:
  On Tue, Sep 04, 2012 at 10:22:56 +0100, Daniel P. Berrange wrote:
   On Mon, Sep 03, 2012 at 12:57:50PM -0300, Marcelo Cerri wrote:

So, my question is: should none seclabels affect specific drivers
(as done now) or just one none seclabel should be accepted affecting
all security drivers in use?
   
   No, as with your example above, the type=none is scoped to a specific
   driver.
  
  And what happens if you have older libvirt and a domain configured with
  seclabel type='none'/ and upgrade libvirt to the state when it actually
  enables more than one security driver at a time. Shouldn't such generic
  seclabel type='none'/ actually turn off any labeling, that is, affect all
  the enabled drivers?
 
 IMHO with the old libvirt, if no model= was set, this was implicitly
 refering to the current model.

Yes, but there was just one model, thus it trivially affected all enabled
models. Also its semantics can be understood as do no labeling no matter what
security model is used. I'm mainly concerned about libvirt upgrades while
domains with seclabel type='none'/ are running.

Jirka

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


Re: [libvirt] None seclabel question

2012-09-04 Thread Daniel P. Berrange
On Tue, Sep 04, 2012 at 12:00:33PM +0200, Jiri Denemark wrote:
 On Tue, Sep 04, 2012 at 10:31:54 +0100, Daniel P. Berrange wrote:
  On Tue, Sep 04, 2012 at 11:28:19AM +0200, Jiri Denemark wrote:
   On Tue, Sep 04, 2012 at 10:22:56 +0100, Daniel P. Berrange wrote:
On Mon, Sep 03, 2012 at 12:57:50PM -0300, Marcelo Cerri wrote:
 
 So, my question is: should none seclabels affect specific drivers
 (as done now) or just one none seclabel should be accepted affecting
 all security drivers in use?

No, as with your example above, the type=none is scoped to a specific
driver.
   
   And what happens if you have older libvirt and a domain configured with
   seclabel type='none'/ and upgrade libvirt to the state when it actually
   enables more than one security driver at a time. Shouldn't such generic
   seclabel type='none'/ actually turn off any labeling, that is, affect 
   all
   the enabled drivers?
  
  IMHO with the old libvirt, if no model= was set, this was implicitly
  refering to the current model.
 
 Yes, but there was just one model, thus it trivially affected all enabled
 models. Also its semantics can be understood as do no labeling no matter what
 security model is used. I'm mainly concerned about libvirt upgrades while
 domains with seclabel type='none'/ are running.

I don't think that description of existing behaviour is accurate. With old
libvirt you have one seclabel (for SELinux/AppArmour), but secretly there
are 2 security drivers (SELinux/AppArmour + DAC). Setting type=none for
the seclabel only meant that the SELinux/AppArmour drivers ran the guest
unconfined. The second (DAC) driver would still be applied to the guest
making it run unprivileged/confined.

What actual problem have you seen with upgrades ?

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [PATCH V4] implement offline migration

2012-09-04 Thread Daniel P. Berrange
On Mon, Sep 03, 2012 at 02:23:24PM +0800, liguang wrote:
 allow migration even domain isn't active by
 inserting some stubs to tunnel migration path.
 
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  src/qemu/qemu_driver.c|2 +-
  src/qemu/qemu_migration.c |  181
 +++--
  src/qemu/qemu_migration.h |3 +-
  3 files changed, 178 insertions(+), 8 deletions(-)

I really don't like the general design of this patch, even
ignoring all the code bugs. I think this entire patch is
really just a solution in search of a problem. Offline migration
is already possible with existing libvirt APIs:

   domsrc = virDomainLookupByName(connsrc, someguest);
   xml = virDomainGetXMLDesc(domsrc);
   domdst virDomainDefine(conndst, xml);

This proposed patch does not offer enough (or indeed any) compelling
benefit over the above, to make it worth the including these hacks.

NACK to the entire patch.

Daniel.
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


[libvirt] [PATCH] qemu: Fix reboot with guest agent

2012-09-04 Thread Jiri Denemark
When reboot using qemu guest agent was requested, qemu driver kept
waiting for SHUTDOWN event from qemu. However, such event is never
emitted during guest reboot and qemu driver would keep waiting forever.
---
 src/qemu/qemu_agent.c   | 5 -
 src/qemu/qemu_agent.h   | 3 ++-
 src/qemu/qemu_process.c | 6 ++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 51e60d2..804c424 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1294,7 +1294,10 @@ int qemuAgentShutdown(qemuAgentPtr mon,
 if (!cmd)
 return -1;
 
-mon-await_event = QEMU_AGENT_EVENT_SHUTDOWN;
+if (mode == QEMU_AGENT_SHUTDOWN_REBOOT)
+mon-await_event = QEMU_AGENT_EVENT_RESET;
+else
+mon-await_event = QEMU_AGENT_EVENT_SHUTDOWN;
 ret = qemuAgentCommand(mon, cmd, reply,
VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK);
 
diff --git a/src/qemu/qemu_agent.h b/src/qemu/qemu_agent.h
index 528fee1..18740ba 100644
--- a/src/qemu/qemu_agent.h
+++ b/src/qemu/qemu_agent.h
@@ -55,7 +55,8 @@ void qemuAgentClose(qemuAgentPtr mon);
 typedef enum {
 QEMU_AGENT_EVENT_NONE = 0,
 QEMU_AGENT_EVENT_SHUTDOWN,
-QEMU_AGENT_EVENT_SUSPEND
+QEMU_AGENT_EVENT_SUSPEND,
+QEMU_AGENT_EVENT_RESET,
 } qemuAgentEvent;
 
 void qemuAgentNotifyEvent(qemuAgentPtr mon,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 5c3b89e..93653c6 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -511,9 +511,15 @@ qemuProcessHandleReset(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
 {
 struct qemud_driver *driver = qemu_driver;
 virDomainEventPtr event;
+qemuDomainObjPrivatePtr priv;
 
 virDomainObjLock(vm);
+
 event = virDomainEventRebootNewFromObj(vm);
+priv = vm-privateData;
+if (priv-agent)
+qemuAgentNotifyEvent(priv-agent, QEMU_AGENT_EVENT_RESET);
+
 virDomainObjUnlock(vm);
 
 if (event) {
-- 
1.7.12

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


Re: [libvirt] error: Failed to start pool (already mounted)

2012-09-04 Thread Ragnar Skúlason
Hi,

We found the problem, and the solution as well.
The problem was that there was inconsistency in the gluster storage volume
which was underneath the libvirt storage pool. One file in multiple
locations with different sizes. After this fixing those inconsistencies
pool-start worked correctly.

But the error message from virsh was way off.

Best regards
Raggi Skula


On Tue, Sep 4, 2012 at 9:45 AM, Ragnar Skúlason ra...@greenqloud.comwrote:

 Hi everyone,

 I'm not sure if this belongs here, I sent a question to the users list
 yesterday without getting a response, so I'm trying here.

 I have storage-pool that for some reason became inactive (possibly due to
 an error with pool-refresh in an old version of a Java API binding).

 I want to restart the pool but am unable to, due to the volume being
 mounted:

 # virsh pool-start [uuid]
 error: Failed to start pool [uuid]
 error: Requested operation is not valid: Target '/mnt/[uuid]' is already
 mounted

 We have tested this with versions 0.9.12 and 0.9.13.

 This did work in versions 0.8.x

 Is it possible to bypass this mount check and start the storage pool
 (forcefully)?

 Many thanks,
 Ragnar Skúlason
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] qemu: Fix reboot with guest agent

2012-09-04 Thread Michal Privoznik
On 04.09.2012 13:14, Jiri Denemark wrote:
 When reboot using qemu guest agent was requested, qemu driver kept
 waiting for SHUTDOWN event from qemu. However, such event is never
 emitted during guest reboot and qemu driver would keep waiting forever.
 ---
  src/qemu/qemu_agent.c   | 5 -
  src/qemu/qemu_agent.h   | 3 ++-
  src/qemu/qemu_process.c | 6 ++
  3 files changed, 12 insertions(+), 2 deletions(-)
 

ACK

Michal

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


Re: [libvirt] [PATCH v0] qemu: Add sandbox support.

2012-09-04 Thread Eric Blake
On 09/03/2012 03:07 PM, Doug Goldstein wrote:
 On Mon, Sep 3, 2012 at 7:03 AM, Ján Tomko jto...@redhat.com wrote:
 QEMU (since 1.2-rc0) supports setting up a syscall whitelist through
 libseccomp on linux kernel from 3.5-rc1. This is enabled by specifying
 -sandbox on on qemu command line.
 
 snip
 
 There's a big push to not rely on -help scraping, please work with
 qemu upstream to get this exposed through the QMP and query for the
 capability that way.

We already agreed upstream that 1.2 and older can use -help scraping,
and that 1.3 and newer will assume that all features present in 1.2 are
still present, and that QMP queries will supply the rest.  Therefore,
I'm okay with -help scraping for 1.2, and just blindly assuming that
-sandbox exists if we detected version 1.3 through a QMP query.

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



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

[libvirt] Compile libvirt on Solaris

2012-09-04 Thread Yang Zhou (yangzho)
Hi Experts,

I am compiling libvirt 0.9.9 on Solaris 9. But got following errors when run 
./configure --with-esx --with-qemu
---
checking for library containing dlopen... -ldl
checking for xen_vm_start in -lxenserver... no
checking for libxl_domain_create_new in -lxenlight... no
checking for xs_read in -lxenstore... no
checking linux/kvm.h usability... no
checking linux/kvm.h presence... no
checking for linux/kvm.h... no
checking for shell that supports  redirection... /bin/sh
checking linux/param.h usability... no
checking linux/param.h presence... no
checking for linux/param.h... no
configure: error: You must install kernel-headers in order to compile libvirt 
with QEMU or LXC support
bash-2.05$


After look at configure, it's found the headers of linux/param.h, 
linux/sockios.h. linux/if_bridge.h and linux/if_tun.h are required. Obviously 
these files are missing on Solaris platform. Anybody can help how to solve this 
issue?

Thanks!

Regards,

Yang



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

[libvirt] NFS over RDMA small block DIRECT_IO bug

2012-09-04 Thread Andrew Holway
Hello.

# Avi Kivity avi(a)redhat recommended I copy kvm in on this. It would also seem 
relevent to libvirt. #

I have a Centos 6.2 server and Centos 6.2 client.

[root@store ~]# cat /etc/exports 
/dev/shm
10.149.0.0/16(rw,fsid=1,no_root_squash,insecure)(I have tried with non 
tempfs targets also)


[root@node001 ~]# cat /etc/fstab 
store.ibnet:/dev/shm /mnt nfs  
rdma,port=2050,defaults 0 0


I wrote a little for loop one liner that dd'd the centos net install image to a 
file called 'hello' then checksummed that file. Each iteration uses a different 
block size.

Non DIRECT_IO seems to work fine. DIRECT_IO with 512byte, 1K and 2K block sizes 
get corrupted.

I want to run my KVM guests on top of NFS over RDMA. My guests cannot create 
filesystems.

Thanks,

Andrew.

bug report: https://bugzilla.linux-nfs.org/show_bug.cgi?id=228

[root@node001 mnt]# for f in 512 1024 2048 4096 8192 16384 32768 65536 131072; 
do dd bs=$f if=CentOS-6.3-x86_64-netinstall.iso of=hello iflag=direct 
oflag=direct  md5sum hello  rm -f hello; done

409600+0 records in
409600+0 records out
209715200 bytes (210 MB) copied, 62.3649 s, 3.4 MB/s
aadd0ffe3c9dfa35d8354e99ecac9276  hello -- 512 byte block 

204800+0 records in
204800+0 records out
209715200 bytes (210 MB) copied, 41.3876 s, 5.1 MB/s
336f6da78f93dab591edc18da81f002e  hello -- 1K block

102400+0 records in
102400+0 records out
209715200 bytes (210 MB) copied, 21.1712 s, 9.9 MB/s
f4cefe0a05c9b47ba68effdb17dc95d6  hello -- 2k block

51200+0 records in
51200+0 records out
209715200 bytes (210 MB) copied, 10.9631 s, 19.1 MB/s
690138908de516b6e5d7d180d085c3f3  hello -- 4k block

25600+0 records in
25600+0 records out
209715200 bytes (210 MB) copied, 5.4136 s, 38.7 MB/s
690138908de516b6e5d7d180d085c3f3  hello

12800+0 records in
12800+0 records out
209715200 bytes (210 MB) copied, 3.1448 s, 66.7 MB/s
690138908de516b6e5d7d180d085c3f3  hello

6400+0 records in
6400+0 records out
209715200 bytes (210 MB) copied, 1.77304 s, 118 MB/s
690138908de516b6e5d7d180d085c3f3  hello

3200+0 records in
3200+0 records out
209715200 bytes (210 MB) copied, 1.4331 s, 146 MB/s
690138908de516b6e5d7d180d085c3f3  hello

1600+0 records in
1600+0 records out
209715200 bytes (210 MB) copied, 0.922167 s, 227 MB/s
690138908de516b6e5d7d180d085c3f3  hello



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


Re: [libvirt] None seclabel question

2012-09-04 Thread Jiri Denemark
On Tue, Sep 04, 2012 at 11:14:35 +0100, Daniel P. Berrange wrote:
 On Tue, Sep 04, 2012 at 12:00:33PM +0200, Jiri Denemark wrote:
 
 I don't think that description of existing behaviour is accurate. With old
 libvirt you have one seclabel (for SELinux/AppArmour), but secretly there
 are 2 security drivers (SELinux/AppArmour + DAC). Setting type=none for
 the seclabel only meant that the SELinux/AppArmour drivers ran the guest
 unconfined. The second (DAC) driver would still be applied to the guest
 making it run unprivileged/confined.

Isn't DAC still applied in the same way?

 What actual problem have you seen with upgrades ?

I don't see any actual problem, I'm just trying to think about them :-) Let's
say there's a domain running with seclabel type='none'/ while libvirtd is
upgraded and reconfigured to enable more seclabels by default (a very
theoretical example could be [ selinux, apparmor ]. I think neither
selinux nor apparmor labeling should be applied for that domain. Or am I
wrong?

Jirka

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


Re: [libvirt] None seclabel question

2012-09-04 Thread Daniel P. Berrange
On Tue, Sep 04, 2012 at 01:43:43PM +0200, Jiri Denemark wrote:
 On Tue, Sep 04, 2012 at 11:14:35 +0100, Daniel P. Berrange wrote:
  On Tue, Sep 04, 2012 at 12:00:33PM +0200, Jiri Denemark wrote:
  
  I don't think that description of existing behaviour is accurate. With old
  libvirt you have one seclabel (for SELinux/AppArmour), but secretly there
  are 2 security drivers (SELinux/AppArmour + DAC). Setting type=none for
  the seclabel only meant that the SELinux/AppArmour drivers ran the guest
  unconfined. The second (DAC) driver would still be applied to the guest
  making it run unprivileged/confined.
 
 Isn't DAC still applied in the same way?
 
  What actual problem have you seen with upgrades ?
 
 I don't see any actual problem, I'm just trying to think about them :-) Let's
 say there's a domain running with seclabel type='none'/ while libvirtd is
 upgraded and reconfigured to enable more seclabels by default (a very
 theoretical example could be [ selinux, apparmor ]. I think neither
 selinux nor apparmor labeling should be applied for that domain. Or am I
 wrong?

When I think of upgrade issues, i consider the scenario where the new
libvirt is configured in the same way as the old livirt, and we need
to make sure the guest behaviour remains the same. This scenario you
describe obviously doesn't fall under that, since you're enabling new
behaviour that was not previously possible. I so don't think that is
an upgrade problem, but rather just a case of defining what the new
behaviour should be.

IMHO, the behaviour is thus

 - A single seclabel with no model=XXX attribute, refers to the first
   security driver
 - Multiple seclabel with explicit model=XXX attributes refer to the
   corresponding driver
 - Multiple seclabel with no model=XX - forbidden config

If you want to set behaviour for the secondary, or tertiary security
drivers then you are required to provide multiple seclabel elements
with explicit model= attributes. We shouldn't try to abuse a single
seclabel element to set properties against multiple security drivers.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [PATCH 1/2] conf: Support for Block Device IO Limits

2012-09-04 Thread Viktor Mihajlovski

On 08/31/2012 03:33 PM, Viktor Mihajlovski wrote:

On 08/30/2012 07:37 PM, Daniel P. Berrange wrote:


How about using this:

   blockio logical_size='512' physical_size='4096'/

Regards,
Daniel



That is perfectly fine with me. Any other suggestions for a v2 patch?


Hi Daniel,

since the original patch went upstream with iolimits ...: do you want 
me to change the element name in a follow up patch (in time for 0.10.2), 
or would you consent to leave as is.


BTW: Mike Snitzer has initially used the term i/o limits in the RHEL and 
Fedora Storage Admin guides but eventually switched to use i/o parameters.


--

Mit freundlichen Grüßen/Kind Regards
   Viktor Mihajlovski

IBM Deutschland Research  Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

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

Re: [libvirt] [PATCH 1/2] conf: Support for Block Device IO Limits

2012-09-04 Thread Daniel P. Berrange
On Tue, Sep 04, 2012 at 01:57:00PM +0200, Viktor Mihajlovski wrote:
 On 08/31/2012 03:33 PM, Viktor Mihajlovski wrote:
 On 08/30/2012 07:37 PM, Daniel P. Berrange wrote:
 
 How about using this:
 
blockio logical_size='512' physical_size='4096'/
 
 Regards,
 Daniel
 
 
 That is perfectly fine with me. Any other suggestions for a v2 patch?
 
 Hi Daniel,
 
 since the original patch went upstream with iolimits ...: do you
 want me to change the element name in a follow up patch (in time for
 0.10.2), or would you consent to leave as is.

Yes, please do a followup to rename this.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] NFS over RDMA small block DIRECT_IO bug

2012-09-04 Thread Myklebust, Trond
On Tue, 2012-09-04 at 11:31 +0200, Andrew Holway wrote:
 Hello.
 
 # Avi Kivity avi(a)redhat recommended I copy kvm in on this. It would also 
 seem relevent to libvirt. #
 
 I have a Centos 6.2 server and Centos 6.2 client.
 
 [root@store ~]# cat /etc/exports 
 /dev/shm  
 10.149.0.0/16(rw,fsid=1,no_root_squash,insecure)(I have tried with non 
 tempfs targets also)
 
 
 [root@node001 ~]# cat /etc/fstab 
 store.ibnet:/dev/shm /mnt nfs  
 rdma,port=2050,defaults 0 0
 
 
 I wrote a little for loop one liner that dd'd the centos net install image to 
 a file called 'hello' then checksummed that file. Each iteration uses a 
 different block size.
 
 Non DIRECT_IO seems to work fine. DIRECT_IO with 512byte, 1K and 2K block 
 sizes get corrupted.


That is expected behaviour. DIRECT_IO over RDMA needs to be page aligned
so that it can use the more efficient RDMA READ and RDMA WRITE memory
semantics (instead of the SEND/RECEIVE channel semantics).

 I want to run my KVM guests on top of NFS over RDMA. My guests cannot create 
 filesystems.
 
 Thanks,
 
 Andrew.
 
 bug report: https://bugzilla.linux-nfs.org/show_bug.cgi?id=228
 
 [root@node001 mnt]# for f in 512 1024 2048 4096 8192 16384 32768 65536 
 131072; do dd bs=$f if=CentOS-6.3-x86_64-netinstall.iso of=hello 
 iflag=direct oflag=direct  md5sum hello  rm -f hello; done
 
 409600+0 records in
 409600+0 records out
 209715200 bytes (210 MB) copied, 62.3649 s, 3.4 MB/s
 aadd0ffe3c9dfa35d8354e99ecac9276  hello -- 512 byte block 
 
 204800+0 records in
 204800+0 records out
 209715200 bytes (210 MB) copied, 41.3876 s, 5.1 MB/s
 336f6da78f93dab591edc18da81f002e  hello -- 1K block
 
 102400+0 records in
 102400+0 records out
 209715200 bytes (210 MB) copied, 21.1712 s, 9.9 MB/s
 f4cefe0a05c9b47ba68effdb17dc95d6  hello -- 2k block
 
 51200+0 records in
 51200+0 records out
 209715200 bytes (210 MB) copied, 10.9631 s, 19.1 MB/s
 690138908de516b6e5d7d180d085c3f3  hello -- 4k block
 
 25600+0 records in
 25600+0 records out
 209715200 bytes (210 MB) copied, 5.4136 s, 38.7 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 12800+0 records in
 12800+0 records out
 209715200 bytes (210 MB) copied, 3.1448 s, 66.7 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 6400+0 records in
 6400+0 records out
 209715200 bytes (210 MB) copied, 1.77304 s, 118 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 3200+0 records in
 3200+0 records out
 209715200 bytes (210 MB) copied, 1.4331 s, 146 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 1600+0 records in
 1600+0 records out
 209715200 bytes (210 MB) copied, 0.922167 s, 227 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 
 --
 To unsubscribe from this list: send the line unsubscribe linux-nfs in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Trond Myklebust
Linux NFS client maintainer

NetApp
trond.mykleb...@netapp.com
www.netapp.com


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


Re: [libvirt] [PATCH] nwfilter: drop use of awk

2012-09-04 Thread Daniel Veillard
On Fri, Aug 31, 2012 at 03:56:58PM -0700, Eric Blake wrote:
 Commit 2a41bc9 dropped a dependency on gawk, but we can go one step
 further and avoid awk altogether.
 
 * src/nwfilter/nwfilter_ebiptables_driver.c
 (iptablesLinkIPTablesBaseChain): Simplify command.
 (ebiptablesDriverInit, ebiptablesDriverShutdown): Drop awk probe.
 ---
 
 Caveat - I was not set up to test this via actual nwfilter operations,
 so it needs a thorough testing review.
 
  src/nwfilter/nwfilter_ebiptables_driver.c | 14 --
  1 file changed, 4 insertions(+), 10 deletions(-)
 
 diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c 
 b/src/nwfilter/nwfilter_ebiptables_driver.c
 index 034e6c4..8ffe737 100644
 --- a/src/nwfilter/nwfilter_ebiptables_driver.c
 +++ b/src/nwfilter/nwfilter_ebiptables_driver.c
 @@ -84,7 +84,6 @@ static char *ebtables_cmd_path;
  static char *iptables_cmd_path;
  static char *ip6tables_cmd_path;
  static char *grep_cmd_path;
 -static char *awk_cmd_path;
 
  #define PRINT_ROOT_CHAIN(buf, prefix, ifname) \
  snprintf(buf, sizeof(buf), libvirt-%c-%s, prefix, ifname)
 @@ -565,12 +564,11 @@ static int iptablesLinkIPTablesBaseChain(virBufferPtr 
 buf,
   int stopOnError)
  {
  virBufferAsprintf(buf,
 -  res=$($IPT -L %s -n --line-number | 
 -  %s \ %s \)\n
 +  res=$($IPT -L %s -n --line-number | %s '%s')\n
if [ $? -ne 0 ]; then\n
  $IPT -I %s %d -j %s\n
else\n
 -r=$(echo $res | %s '{print $1}')\n
 +set dummy $res; r=$2\n
  if [ \${r}\ != \%d\ ]; then\n
 CMD_DEF($IPT -I %s %d -j %s) CMD_SEPARATOR
 CMD_EXEC
 @@ -582,11 +580,9 @@ static int iptablesLinkIPTablesBaseChain(virBufferPtr 
 buf,
  fi\n
fi\n,
 
 -  syschain,
 -  grep_cmd_path, udchain,
 +  syschain, grep_cmd_path, udchain,
 
syschain, pos, udchain,
 -  awk_cmd_path,
 
pos,
 
 @@ -4295,7 +4291,6 @@ ebiptablesDriverInit(bool privileged)
  if (virMutexInit(execCLIMutex)  0)
  return -EINVAL;
 
 -awk_cmd_path = virFindFileInPath(awk);
  grep_cmd_path = virFindFileInPath(grep);
 
  /*
 @@ -4311,7 +4306,7 @@ ebiptablesDriverInit(bool privileged)
 
  /* ip(6)tables support needs awk  grep, ebtables doesn't */
  if ((iptables_cmd_path != NULL || ip6tables_cmd_path != NULL) 
 -(!grep_cmd_path || !awk_cmd_path)) {
 +!grep_cmd_path) {
  VIR_ERROR(_(essential tools to support ip(6)tables 
firewalls could not be located));
  VIR_FREE(iptables_cmd_path);
 @@ -4333,7 +4328,6 @@ ebiptablesDriverInit(bool privileged)
  static void
  ebiptablesDriverShutdown(void)
  {
 -VIR_FREE(awk_cmd_path);
  VIR_FREE(grep_cmd_path);
  VIR_FREE(ebtables_cmd_path);
  VIR_FREE(iptables_cmd_path);

 ACK,

Daniel

-- 
Daniel Veillard  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

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


Re: [libvirt] None seclabel question

2012-09-04 Thread Jiri Denemark
On Tue, Sep 04, 2012 at 12:50:55 +0100, Daniel P. Berrange wrote:
 When I think of upgrade issues, i consider the scenario where the new
 libvirt is configured in the same way as the old livirt, and we need
 to make sure the guest behaviour remains the same. This scenario you
 describe obviously doesn't fall under that, since you're enabling new
 behaviour that was not previously possible. I so don't think that is
 an upgrade problem, but rather just a case of defining what the new
 behaviour should be.
 
 IMHO, the behaviour is thus
 
  - A single seclabel with no model=XXX attribute, refers to the first
security driver
  - Multiple seclabel with explicit model=XXX attributes refer to the
corresponding driver
  - Multiple seclabel with no model=XX - forbidden config
 
 If you want to set behaviour for the secondary, or tertiary security
 drivers then you are required to provide multiple seclabel elements
 with explicit model= attributes. We shouldn't try to abuse a single
 seclabel element to set properties against multiple security drivers.

Fair enough and works for me :-) We ended up with a clearly defined behavior,
which is worth including in formatdomain.html

Jirka

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


Re: [libvirt] [PATCH] qemu: Fix reboot with guest agent

2012-09-04 Thread Jiri Denemark
On Tue, Sep 04, 2012 at 13:46:05 +0200, Michal Privoznik wrote:
 On 04.09.2012 13:14, Jiri Denemark wrote:
  When reboot using qemu guest agent was requested, qemu driver kept
  waiting for SHUTDOWN event from qemu. However, such event is never
  emitted during guest reboot and qemu driver would keep waiting forever.
  ---
   src/qemu/qemu_agent.c   | 5 -
   src/qemu/qemu_agent.h   | 3 ++-
   src/qemu/qemu_process.c | 6 ++
   3 files changed, 12 insertions(+), 2 deletions(-)
  
 
 ACK

Thanks, pushed.

Jirka

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


[libvirt] [libvirt-glib 2/4] config: Improve documentation of GVirConfigDomain::set_memory

2012-09-04 Thread Christophe Fergeau
Explicit the fact that it sets the maximum domain memory.
---
 libvirt-gconfig/libvirt-gconfig-domain.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c 
b/libvirt-gconfig/libvirt-gconfig-domain.c
index 2ca478f..e6f22bd 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -286,7 +286,7 @@ void gvir_config_domain_set_description(GVirConfigDomain 
*domain, const char *de
  * gvir_config_domain_get_memory:
  * @domain: a #GVirConfigDomain
  *
- * Returns: amount of RAM in kilobytes (i.e. blocks of 1024 bytes).
+ * Returns: maximum amount of RAM in kilobytes (i.e. blocks of 1024 bytes).
  */
 guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain)
 {
@@ -297,9 +297,10 @@ guint64 gvir_config_domain_get_memory(GVirConfigDomain 
*domain)
 /**
  * gvir_config_domain_set_memory:
  * @domain: a #GVirConfigDomain
- * @memory: The amount of RAM in kilobytes.
+ * @memory: The maximum amount of RAM in kilobytes.
  *
- * Sets the amount of RAM allocated to @domain in kilobytes (i.e. blocks of 
1024 bytes).
+ * Sets the maximum amount of RAM allocated to @domain in kilobytes (i.e.
+ * blocks of 1024 bytes).
  */
 void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory)
 {
-- 
1.7.11.4

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


[libvirt] [libvirt-glib 1/4] config: Allow NULL node name to gvir_config_object_set_content

2012-09-04 Thread Christophe Fergeau
This is useful when you want to set the content of the current node.
---
 libvirt-gconfig/libvirt-gconfig-object.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-object.c 
b/libvirt-gconfig/libvirt-gconfig-object.c
index a7352a5..ac0545c 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -534,7 +534,6 @@ gvir_config_object_set_node_content(GVirConfigObject 
*object,
 GVirConfigObject *node;
 
 g_return_if_fail(GVIR_CONFIG_IS_OBJECT(object));
-g_return_if_fail(node_name != NULL);
 
 if (value == NULL) {
 gvir_config_object_delete_child(object, node_name, NULL);
@@ -542,8 +541,12 @@ gvir_config_object_set_node_content(GVirConfigObject 
*object,
 return;
 }
 
-node = gvir_config_object_replace_child(object, node_name);
-g_return_if_fail(node != NULL);
+if (node_name != NULL) {
+node = gvir_config_object_replace_child(object, node_name);
+g_return_if_fail(node != NULL);
+} else {
+node = g_object_ref(G_OBJECT(object));
+}
 encoded_data = xmlEncodeEntitiesReentrant(node-priv-node-doc,
   (xmlChar *)value);
 xmlNodeSetContent(node-priv-node, encoded_data);
@@ -559,7 +562,6 @@ gvir_config_object_set_node_content_uint64(GVirConfigObject 
*object,
 char *str;
 
 g_return_if_fail(GVIR_CONFIG_IS_OBJECT(object));
-g_return_if_fail(node_name != NULL);
 
 str = g_strdup_printf(%G_GUINT64_FORMAT, value);
 gvir_config_object_set_node_content(object, node_name, str);
-- 
1.7.11.4

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


[libvirt] [libvirt-glib 3/4] config: Handle units in gvir_config_[gs]et_memory

2012-09-04 Thread Christophe Fergeau
gvir_config_[gs]et_memory have an optional 'unit' attribute which
indicates the unit used to express the memory size. This commit
adds support for parsing this unit, and adjusting the returned
value accordingly.
---
 libvirt-gconfig/libvirt-gconfig-domain.c | 81 ++--
 1 file changed, 76 insertions(+), 5 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c 
b/libvirt-gconfig/libvirt-gconfig-domain.c
index e6f22bd..dd4e232 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -275,13 +275,70 @@ const char 
*gvir_config_domain_get_description(GVirConfigDomain *domain)
  * @domain: a #GVirConfigDomain
  * @description: (allow-none):
  */
-void gvir_config_domain_set_description(GVirConfigDomain *domain, const char 
*description)
+void gvir_config_domain_set_description(GVirConfigDomain *domain,
+const char *description)
 {
 gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(domain),
 description, description);
 g_object_notify(G_OBJECT(domain), description);
 }
 
+static void insert_base(GHashTable *unit_bases,
+const char *unit,
+guint64 unit_base)
+{
+guint64 *base;
+base = g_slice_alloc(sizeof(*base));
+*base = unit_base;
+g_hash_table_insert(unit_bases, (gpointer)unit, base);
+}
+
+static gpointer set_unit_bases(G_GNUC_UNUSED gpointer user_data)
+{
+GHashTable *unit_bases;
+
+unit_bases = g_hash_table_new(g_str_hash, g_str_equal);
+
+insert_base(unit_bases, b, 1);
+insert_base(unit_bases, bytes, 1);
+insert_base(unit_bases, KB, 1000);
+insert_base(unit_bases, k, 1024);
+insert_base(unit_bases, KiB, 1024);
+insert_base(unit_bases, MB, 1000*1000);
+insert_base(unit_bases, M, 1024*1024);
+insert_base(unit_bases, MiB, 1024*1024);
+insert_base(unit_bases, GB, 1000*1000*1000);
+insert_base(unit_bases, G, 1024*1024*1024);
+insert_base(unit_bases, GiB, 1024*1024*1024);
+insert_base(unit_bases, TB, (guint64)1000*1000*1000*1000);
+insert_base(unit_bases, T, (guint64)1024*1024*1024*1024);
+insert_base(unit_bases, TiB, (guint64)1024*1024*1024*1024);
+
+return unit_bases;
+}
+
+static guint64 get_unit_base(const char *unit, guint64 default_base)
+{
+static GOnce set_unit_bases_once = G_ONCE_INIT;
+GHashTable *unit_bases;
+guint64 *unit_base;
+
+if (unit == NULL) {
+return default_base;
+}
+
+unit_bases = g_once (set_unit_bases_once, set_unit_bases, unit_bases);
+g_return_val_if_fail (unit_bases != NULL, default_base);
+
+unit_base = g_hash_table_lookup(unit_bases, unit);
+if (unit_base == NULL) {
+/* unknown unit, fall back to the default unit */
+g_return_val_if_reached(default_base);
+}
+
+return *unit_base;
+}
+
 /**
  * gvir_config_domain_get_memory:
  * @domain: a #GVirConfigDomain
@@ -290,8 +347,17 @@ void gvir_config_domain_set_description(GVirConfigDomain 
*domain, const char *de
  */
 guint64 gvir_config_domain_get_memory(GVirConfigDomain *domain)
 {
-return 
gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(domain),
-  memory);
+const char *unit;
+guint64 unit_base;
+guint64 memory;
+
+unit = gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(domain), 
memory, unit);
+unit_base = get_unit_base(unit, 1024);
+
+memory = 
gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(domain),
+memory);
+
+return memory * unit_base / 1024;
 }
 
 /**
@@ -304,8 +370,13 @@ guint64 gvir_config_domain_get_memory(GVirConfigDomain 
*domain)
  */
 void gvir_config_domain_set_memory(GVirConfigDomain *domain, guint64 memory)
 {
-gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(domain),
-   memory, memory);
+GVirConfigObject *node;
+
+node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(domain), 
memory);
+gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(node), NULL, 
memory);
+gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(node),
+ unit, KiB,
+ NULL);
 g_object_notify(G_OBJECT(domain), memory);
 }
 
-- 
1.7.11.4

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


[libvirt] [libvirt-glib 4/4] config: Add gvir_config_domain_[gs]et_current_memory

2012-09-04 Thread Christophe Fergeau
libvirt will insert a currentMemory node when setting the domain
maximum memory. If we want to be able to later increase the domain
maximum memory, libvirt-gconfig needs to be able to set this
currentMemory node as well, otherwise this will cap the available
memory in the domain.
---
 libvirt-gconfig/libvirt-gconfig-domain.c | 64 +++-
 libvirt-gconfig/libvirt-gconfig-domain.h |  2 +
 libvirt-gconfig/libvirt-gconfig.sym  |  6 +++
 3 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-domain.c 
b/libvirt-gconfig/libvirt-gconfig-domain.c
index dd4e232..e679e3a 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain.c
@@ -43,7 +43,8 @@ enum {
 PROP_DESCRIPTION,
 PROP_MEMORY,
 PROP_VCPU,
-PROP_FEATURES
+PROP_FEATURES,
+PROP_CURRENT_MEMORY
 };
 
 static void gvir_config_domain_get_property(GObject *object,
@@ -66,6 +67,9 @@ static void gvir_config_domain_get_property(GObject *object,
 case PROP_MEMORY:
 g_value_set_uint64(value, gvir_config_domain_get_memory(domain));
 break;
+case PROP_CURRENT_MEMORY:
+g_value_set_uint64(value, 
gvir_config_domain_get_current_memory(domain));
+break;
 case PROP_VCPU:
 g_value_set_uint64(value, gvir_config_domain_get_vcpus(domain));
 break;
@@ -98,6 +102,9 @@ static void gvir_config_domain_set_property(GObject *object,
 case PROP_MEMORY:
 gvir_config_domain_set_memory(domain, g_value_get_uint64(value));
 break;
+case PROP_CURRENT_MEMORY:
+gvir_config_domain_set_current_memory(domain, 
g_value_get_uint64(value));
+break;
 case PROP_VCPU:
 gvir_config_domain_set_vcpus(domain, g_value_get_uint64(value));
 break;
@@ -153,6 +160,15 @@ static void 
gvir_config_domain_class_init(GVirConfigDomainClass *klass)
 G_PARAM_READWRITE |
 
G_PARAM_STATIC_STRINGS));
 g_object_class_install_property(object_class,
+PROP_CURRENT_MEMORY,
+g_param_spec_uint64(current-memory,
+Current memory,
+Current Guest Memory 
(in kilobytes),
+0, G_MAXUINT64,
+0,
+G_PARAM_READWRITE |
+
G_PARAM_STATIC_STRINGS));
+g_object_class_install_property(object_class,
 PROP_VCPU,
 g_param_spec_uint64(vcpu,
 Virtual CPUs,
@@ -361,6 +377,27 @@ guint64 gvir_config_domain_get_memory(GVirConfigDomain 
*domain)
 }
 
 /**
+ * gvir_config_domain_get_current_memory:
+ * @domain: a #GVirConfigDomain
+ *
+ * Returns: current amount of RAM in kilobytes (i.e. blocks of 1024 bytes).
+ */
+guint64 gvir_config_domain_get_current_memory(GVirConfigDomain *domain)
+{
+const char *unit;
+guint64 unit_base;
+guint64 memory;
+
+unit = gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(domain), 
currentMemory, unit);
+unit_base = get_unit_base(unit, 1024);
+
+memory = 
gvir_config_object_get_node_content_uint64(GVIR_CONFIG_OBJECT(domain),
+currentMemory);
+
+return memory * unit_base / 1024;
+}
+
+/**
  * gvir_config_domain_set_memory:
  * @domain: a #GVirConfigDomain
  * @memory: The maximum amount of RAM in kilobytes.
@@ -380,6 +417,31 @@ void gvir_config_domain_set_memory(GVirConfigDomain 
*domain, guint64 memory)
 g_object_notify(G_OBJECT(domain), memory);
 }
 
+/**
+ * gvir_config_domain_set_current_memory:
+ * @domain: a #GVirConfigDomain
+ * @memory: The current amount of RAM in kilobytes.
+ *
+ * Sets the current amount of RAM allocated to @domain in kilobytes (i.e.
+ * blocks of 1024 bytes). This can be set to less than the maximum domain
+ * memory to allow to balloon the guest memory on the fly. Be aware that
+ * libvirt will set it automatically if it's not explictly set, which means
+ * you may need to set this value in addition to 'memory' if you want to
+ * change the available domain memory after creation.
+ */
+void gvir_config_domain_set_current_memory(GVirConfigDomain *domain,
+   guint64 memory)
+{
+GVirConfigObject *node;
+
+node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(domain), 
currentMemory);
+gvir_config_object_set_node_content_uint64(GVIR_CONFIG_OBJECT(node), NULL, 
memory);
+gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(node),
+ 

Re: [libvirt] NFS over RDMA small block DIRECT_IO bug

2012-09-04 Thread Andrew Holway
 
 That is expected behaviour. DIRECT_IO over RDMA needs to be page aligned
 so that it can use the more efficient RDMA READ and RDMA WRITE memory
 semantics (instead of the SEND/RECEIVE channel semantics).

Yes, I think I am understanding that now.

I need to find a way of getting around the lib-virt issue.

http://lists.gnu.org/archive/html/qemu-devel/2011-12/msg01570.html

Thanks,

Andrew


 
 I want to run my KVM guests on top of NFS over RDMA. My guests cannot create 
 filesystems.
 
 Thanks,
 
 Andrew.
 
 bug report: https://bugzilla.linux-nfs.org/show_bug.cgi?id=228
 
 [root@node001 mnt]# for f in 512 1024 2048 4096 8192 16384 32768 65536 
 131072; do dd bs=$f if=CentOS-6.3-x86_64-netinstall.iso of=hello 
 iflag=direct oflag=direct  md5sum hello  rm -f hello; done
 
 409600+0 records in
 409600+0 records out
 209715200 bytes (210 MB) copied, 62.3649 s, 3.4 MB/s
 aadd0ffe3c9dfa35d8354e99ecac9276  hello -- 512 byte block 
 
 204800+0 records in
 204800+0 records out
 209715200 bytes (210 MB) copied, 41.3876 s, 5.1 MB/s
 336f6da78f93dab591edc18da81f002e  hello -- 1K block
 
 102400+0 records in
 102400+0 records out
 209715200 bytes (210 MB) copied, 21.1712 s, 9.9 MB/s
 f4cefe0a05c9b47ba68effdb17dc95d6  hello -- 2k block
 
 51200+0 records in
 51200+0 records out
 209715200 bytes (210 MB) copied, 10.9631 s, 19.1 MB/s
 690138908de516b6e5d7d180d085c3f3  hello -- 4k block
 
 25600+0 records in
 25600+0 records out
 209715200 bytes (210 MB) copied, 5.4136 s, 38.7 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 12800+0 records in
 12800+0 records out
 209715200 bytes (210 MB) copied, 3.1448 s, 66.7 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 6400+0 records in
 6400+0 records out
 209715200 bytes (210 MB) copied, 1.77304 s, 118 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 3200+0 records in
 3200+0 records out
 209715200 bytes (210 MB) copied, 1.4331 s, 146 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 1600+0 records in
 1600+0 records out
 209715200 bytes (210 MB) copied, 0.922167 s, 227 MB/s
 690138908de516b6e5d7d180d085c3f3  hello
 
 
 --
 To unsubscribe from this list: send the line unsubscribe linux-nfs in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 
 -- 
 Trond Myklebust
 Linux NFS client maintainer
 
 NetApp
 trond.mykleb...@netapp.com
 www.netapp.com
 
 --
 To unsubscribe from this list: send the line unsubscribe kvm in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 



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


Re: [libvirt] [PATCH v2 0/4] Add cpu hotplug support to libvirt.

2012-09-04 Thread Daniel P. Berrange
On Tue, Sep 04, 2012 at 04:45:16PM +0800, Tang Chen wrote:
 It seems that libvirt is not cpu hotplug aware.
 Please refer to the following problem.
 
 1. At first, we have 2 cpus.
 # cat /cgroup/cpuset/cpuset.cpus 
 0-1
 # cat /cgroup/cpuset/libvirt/qemu/cpuset.cpus 
 0-1
 
 2. And we have a vm1 with following configuration.
   cputune
 vcpupin vcpu='0' cpuset='1'/
 emulatorpin cpuset='1'/
   /cputune
 
 3. Offline cpu1.
 # echo 0  /sys/devices/system/cpu/cpu1/online
 # cat /sys/devices/system/cpu/cpu1/online 
 0
 # cat /cgroup/cpuset/cpuset.cpus 
 0
 # cat /cgroup/cpuset/libvirt/qemu/cpuset.cpus 
 0
 # cat /cgroup/cpuset/libvirt/lxc/cpuset.cpus 
 0
 
 4. Online cpu1.
 # echo 1  /sys/devices/system/cpu/cpu1/online
 # cat /sys/devices/system/cpu/cpu1/online 
 1
 # cat /cgroup/cpuset/cpuset.cpus 
 0-1
 # cat /cgroup/cpuset/libvirt/cpuset.cpus 
 0
 # cat /cgroup/cpuset/libvirt/qemu/cpuset.cpus 
 0
 # cat /cgroup/cpuset/libvirt/lxc/cpuset.cpus 
 0
 
 Here,cgroup updated cpuset.cpus,but not for libvirt directory,and also qemu 
 and lxc directory.

I'm rather inclined to say this is the kernel's fault. This is
the same class of problem that we save with S3/S4 kernel support
where the cpuset got blanked out.

The kernel should *not* be altering the user specified cgroups
settings when offlining CPUs. The problem is that the kernel is
not distinguishing between the user requested cpuset mask and
the mask of available CPUs - it has overloaded both into one
config file.

The cgroup cpuset.cpus should only reflect the user config.
The kernel should privately AND this with the current mask
of CPUs which actually exist.

 vm1 cannot be started again.
 # virsh start vm1
 error: Failed to start domain vm1
 error: Unable to set cpuset.cpus: Permission denied
 
 And libvird gave the following errors.
 2012-07-17 07:30:22.478+: 3118: error : qemuSetupCgroupVcpuPin:498 : 
 Unable to set cpuset.cpus: Permission denied
 
 
 These patches resolves this problem by listening on the netlink for cpu 
 hotplug event.
 When the netlink service gets the cpu hotplug event, it will attract the 
 cpuid in the message,
 and add it into cpuset.cpus in:
 /cgroup/cpuset/libvirt
 /cgroup/cpuset/libvirt/qemu
 /cgroup/cpuset/libvirt/lxc

I don't think we should be doing this. eg, Consisder the host has 8 cpus an
the admin explicitly configured libvirt to only use cpus 1-4. If the host
admin onlines CPU 6, then libvirt should not be adding CPU 6 into its cpuset.

In addition we cannot assume that the 'libvirt' cgroup is immediately below
the root cgroup. There might be several other layers in the hierarchy above
which also loose their correct cpuset data, not to mention the cgroups of
all other apps in the system. This is a system-wide flaw, but your patch
is only addressing the libvirt impact. So I don't think we should be doing
this. The kernel should fix cgroups properly so all apps work correctly.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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

[libvirt] [PATCH 2/2] qemu: Add range checking for scheduler tunables

2012-09-04 Thread Peter Krempa
The quota and period tunables for cpu scheduler accept only a certain
range of values. When changing the live configuration invalid values get
rejected. This check is not performed when changing persistent config.

This patch adds a separate range check, that improves error messages
when changing live config and adds the check for persistent config.
---
 src/qemu/qemu_driver.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4b8b751..3d59594 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -106,6 +106,11 @@
 #define QEMU_NB_TOTAL_CPU_STAT_PARAM 3
 #define QEMU_NB_PER_CPU_STAT_PARAM 2

+#define QEMU_SCHED_MIN_PERIOD (long long)  1000
+#define QEMU_SCHED_MAX_PERIOD (long long)   100
+#define QEMU_SCHED_MIN_QUOTA  (long long)  1000
+#define QEMU_SCHED_MAX_QUOTA  (long long) 18446744073709551
+
 #if HAVE_LINUX_KVM_H
 # include linux/kvm.h
 #endif
@@ -7790,6 +7795,15 @@ cleanup:
 return -1;
 }

+#define SCHED_RANGE_CHECK(VAR, NAME, MIN, MAX)  \
+if (((VAR)  0  (VAR)  (MIN)) || (VAR)  (MAX)) {\
+virReportError(VIR_ERR_INVALID_ARG, \
+   _(value of '%s' is out of range [%lld,%lld]),  \
+   NAME, MIN, MAX); \
+rc = -1;\
+goto cleanup;   \
+}
+
 static int
 qemuSetSchedulerParametersFlags(virDomainPtr dom,
 virTypedParameterPtr params,
@@ -7876,6 +7890,9 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
 vmdef-cputune.shares = value_ul;

 } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
+SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD,
+  QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_PERIOD);
+
 if (flags  VIR_DOMAIN_AFFECT_LIVE  value_ul) {
 if ((rc = qemuSetVcpusBWLive(vm, group, value_ul, 0)))
 goto cleanup;
@@ -7887,6 +7904,9 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
 vmdef-cputune.period = params[i].value.ul;

 } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
+SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA,
+  QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_QUOTA);
+
 if (flags  VIR_DOMAIN_AFFECT_LIVE  value_l) {
 if ((rc = qemuSetVcpusBWLive(vm, group, 0, value_l)))
 goto cleanup;
@@ -7898,6 +7918,9 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
 vmdef-cputune.quota = value_l;

 } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD)) {
+SCHED_RANGE_CHECK(value_ul, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD,
+  QEMU_SCHED_MIN_PERIOD, QEMU_SCHED_MAX_PERIOD);
+
 if (flags  VIR_DOMAIN_AFFECT_LIVE  value_ul) {
 if ((rc = qemuSetEmulatorBandwidthLive(vm, group, value_ul, 
0)))
 goto cleanup;
@@ -7909,6 +7932,9 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
 vmdef-cputune.emulator_period = value_ul;

 } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA)) {
+SCHED_RANGE_CHECK(value_l, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA,
+  QEMU_SCHED_MIN_QUOTA, QEMU_SCHED_MAX_QUOTA);
+
 if (flags  VIR_DOMAIN_AFFECT_LIVE  value_l) {
 if ((rc = qemuSetEmulatorBandwidthLive(vm, group, 0, value_l)))
 goto cleanup;
@@ -7944,6 +7970,7 @@ cleanup:
 qemuDriverUnlock(driver);
 return ret;
 }
+#undef SCHED_RANGE_CHECK

 static int
 qemuSetSchedulerParameters(virDomainPtr dom,
-- 
1.7.12

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


[libvirt] [PATCH 1/2] qemu: clean up qemuSetSchedulerParametersFlags()

2012-09-04 Thread Peter Krempa
This patch tries to clean the code up a little bit and shorten very long
lines.
---
 src/qemu/qemu_driver.c | 69 +++---
 1 file changed, 31 insertions(+), 38 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b12d9bc..4b8b751 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7801,6 +7801,8 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
 virCgroupPtr group = NULL;
 virDomainObjPtr vm = NULL;
 virDomainDefPtr vmdef = NULL;
+unsigned long long value_ul;
+long long value_l;
 int ret = -1;
 int rc;

@@ -7857,74 +7859,65 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,

 for (i = 0; i  nparams; i++) {
 virTypedParameterPtr param = params[i];
+value_ul = param-value.ul;
+value_l = param-value.l;

 if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_CPU_SHARES)) {
 if (flags  VIR_DOMAIN_AFFECT_LIVE) {
-rc = virCgroupSetCpuShares(group, params[i].value.ul);
-if (rc != 0) {
+if ((rc = virCgroupSetCpuShares(group, value_ul))) {
 virReportSystemError(-rc, %s,
  _(unable to set cpu shares 
tunable));
 goto cleanup;
 }
-
-vm-def-cputune.shares = params[i].value.ul;
+vm-def-cputune.shares = value_ul;
 }

-if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
-vmdef-cputune.shares = params[i].value.ul;
-}
+if (flags  VIR_DOMAIN_AFFECT_CONFIG)
+vmdef-cputune.shares = value_ul;
+
 } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
-if (flags  VIR_DOMAIN_AFFECT_LIVE) {
-rc = qemuSetVcpusBWLive(vm, group, params[i].value.ul, 0);
-if (rc != 0)
+if (flags  VIR_DOMAIN_AFFECT_LIVE  value_ul) {
+if ((rc = qemuSetVcpusBWLive(vm, group, value_ul, 0)))
 goto cleanup;

-if (params[i].value.ul)
-vm-def-cputune.period = params[i].value.ul;
+vm-def-cputune.period = value_ul;
 }

-if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
+if (flags  VIR_DOMAIN_AFFECT_CONFIG)
 vmdef-cputune.period = params[i].value.ul;
-}
+
 } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
-if (flags  VIR_DOMAIN_AFFECT_LIVE) {
-rc = qemuSetVcpusBWLive(vm, group, 0, params[i].value.l);
-if (rc != 0)
+if (flags  VIR_DOMAIN_AFFECT_LIVE  value_l) {
+if ((rc = qemuSetVcpusBWLive(vm, group, 0, value_l)))
 goto cleanup;

-if (params[i].value.l)
-vm-def-cputune.quota = params[i].value.l;
+vm-def-cputune.quota = value_l;
 }

-if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
-vmdef-cputune.quota = params[i].value.l;
-}
+if (flags  VIR_DOMAIN_AFFECT_CONFIG)
+vmdef-cputune.quota = value_l;
+
 } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD)) {
-if (flags  VIR_DOMAIN_AFFECT_LIVE) {
-rc = qemuSetEmulatorBandwidthLive(vm, group, 
params[i].value.ul, 0);
-if (rc != 0)
+if (flags  VIR_DOMAIN_AFFECT_LIVE  value_ul) {
+if ((rc = qemuSetEmulatorBandwidthLive(vm, group, value_ul, 
0)))
 goto cleanup;

-if (params[i].value.ul)
-vm-def-cputune.emulator_period = params[i].value.ul;
+vm-def-cputune.emulator_period = value_ul;
 }

-if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
-vmdef-cputune.emulator_period = params[i].value.ul;
-}
+if (flags  VIR_DOMAIN_AFFECT_CONFIG)
+vmdef-cputune.emulator_period = value_ul;
+
 } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA)) {
-if (flags  VIR_DOMAIN_AFFECT_LIVE) {
-rc = qemuSetEmulatorBandwidthLive(vm, group, 0, 
params[i].value.l);
-if (rc != 0)
+if (flags  VIR_DOMAIN_AFFECT_LIVE  value_l) {
+if ((rc = qemuSetEmulatorBandwidthLive(vm, group, 0, value_l)))
 goto cleanup;

-if (params[i].value.l)
-vm-def-cputune.emulator_quota = params[i].value.l;
+vm-def-cputune.emulator_quota = value_l;
 }

-if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
-vmdef-cputune.emulator_quota = params[i].value.l;
-}
+if (flags  VIR_DOMAIN_AFFECT_CONFIG)
+vmdef-cputune.emulator_quota = value_l;
 }
 }

-- 
1.7.12

--
libvir-list 

[libvirt] [PATCH 0/2] Add range checking for scheduler tunables

2012-09-04 Thread Peter Krempa
Peter Krempa (2):
  qemu: clean up qemuSetSchedulerParametersFlags()
  qemu: Add range checking for scheduler tunables

 src/qemu/qemu_driver.c | 96 ++
 1 file changed, 58 insertions(+), 38 deletions(-)

-- 
1.7.12

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


[libvirt] [PATCH] conf: describe security_driver behavior

2012-09-04 Thread Martin Kletzander
As a request was raised for this, I added few lines in the Notes
part of the security_driver comments about allowed values.
---
The related bug for this patch is here:
https://bugzilla.redhat.com/show_bug.cgi?id=853925

 src/qemu/qemu.conf | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index d3175fa..f0ba163 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -164,7 +164,10 @@
 #
 #   security_driver = [ selinux, apparmor ]
 #
-# Note: The DAC security driver is always enabled.
+# Notes: The DAC security driver is always enabled, setting the
+# security_driver to that value is not allowed as well as adding dac
+# into the list of security drivers. Value none is special value and
+# cannot be used in the list of security drivers.
 #
 #security_driver = selinux

--
1.7.12

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


[libvirt] [PATCH] docs: correct dompmwakeup description

2012-09-04 Thread Martin Kletzander
The command 'dompmwakeup' can wakeup any pmsuspended domain, not only
domains suspended previously by dompmsuspend and this patch fixed the
man page and help string for that.
---
 tools/virsh-domain.c | 6 +++---
 tools/virsh.pod  | 7 ---
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f0ec742..45c5c48 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2242,9 +2242,9 @@ cleanup:
  */

 static const vshCmdInfo info_dom_pm_wakeup[] = {
-{help, N_(wakeup a domain suspended by dompmsuspend command)},
-{desc, N_(Wakeup a domain previously suspended 
-by dompmsuspend command.)},
+{help, N_(wakeup a domain from pmsuspended state)},
+{desc, N_(Wakeup a domain that was previously suspended 
+by power management.)},
 {NULL, NULL}
 };

diff --git a/tools/virsh.pod b/tools/virsh.pod
index a26c420..dca5288 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1523,9 +1523,10 @@ domain's guest OS.

 =item Bdompmwakeup Idomain

-Wakeup a domain suspended by dompmsuspend command. Injects a wakeup
-into the guest that previously used dompmsuspend, rather than waiting
-for the previously requested duration (if any) to elapse.
+Wakeup a domain from pmsuspended state (either suspended by dompmsuspend or
+from the guest itself). Injects a wakeup into the guest that is in pmsuspended
+state, rather than waiting for the previously requested duration (if any) to
+elapse. This operation doesn't not necessarily fail if the domain is running.

 =item Bttyconsole Idomain

--
1.7.12

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


[libvirt] [PATCH] qemu: don't pin all the cpus

2012-09-04 Thread Martin Kletzander
This is another fix for the emulator-pin series. When going through
the cputune pinning settings, the current code is trying to pin all
the CPUs, even when not all of them are specified. This causes error
in the subsequent function which, of course, cannot find the cpu to
pin. Since it's enough to pass the correct VCPU ID to the function,
the fix is trivial.
---
 src/qemu/qemu_cgroup.c | 25 +
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 7298e28..5b42793 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -542,7 +542,7 @@ int qemuSetupCgroupForVcpu(struct qemud_driver *driver, 
virDomainObjPtr vm)
 qemuDomainObjPrivatePtr priv = vm-privateData;
 virDomainDefPtr def = vm-def;
 int rc;
-unsigned int i;
+unsigned int i, j;
 unsigned long long period = vm-def-cputune.period;
 long long quota = vm-def-cputune.quota;

@@ -603,13 +603,22 @@ int qemuSetupCgroupForVcpu(struct qemud_driver *driver, 
virDomainObjPtr vm)
 }

 /* Set vcpupin in cgroup if vcpupin xml is provided */
-if (def-cputune.nvcpupin 
-qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPUSET) 
-qemuSetupCgroupVcpuPin(cgroup_vcpu,
-   def-cputune.vcpupin,
-   def-cputune.nvcpupin,
-   i)  0)
-goto cleanup;
+if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPUSET)) {
+/* find the right CPU to pin, otherwise
+ * qemuSetupCgroupVcpuPin will fail. */
+for (j = 0; j  def-cputune.nvcpupin; j++) {
+if (def-cputune.vcpupin[j]-vcpuid != i)
+continue;
+
+if (qemuSetupCgroupVcpuPin(cgroup_vcpu,
+   def-cputune.vcpupin,
+   def-cputune.nvcpupin,
+   i)  0)
+goto cleanup;
+
+break;
+}
+}

 virCgroupFree(cgroup_vcpu);
 }
-- 
1.7.12

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


[libvirt] [PATCH] Rename iolimit to blockio.

2012-09-04 Thread Viktor Mihajlovski
After discussion with DB we decided to rename the new iolimit
element as it creates the impression it would be there to
limit (i.e. throttle) I/O instead of specifying immutable
characteristics of a block device.
This is also backed by the fact that the term I/O Limits has
vanished from newer storage admin documentation.

Signed-off-by: Viktor Mihajlovski mihaj...@linux.vnet.ibm.com
---
 docs/formatdomain.html.in  |6 ++--
 docs/schemas/domaincommon.rng  |6 ++--
 src/conf/domain_conf.c |   30 +-
 src/conf/domain_conf.h |2 +-
 src/qemu/qemu_capabilities.c   |4 +-
 src/qemu/qemu_capabilities.h   |2 +-
 src/qemu/qemu_command.c|   10 +++---
 tests/qemuhelptest.c   |8 ++--
 .../qemuxml2argv-disk-blockio.args |9 +
 .../qemuxml2argvdata/qemuxml2argv-disk-blockio.xml |   33 
 .../qemuxml2argv-disk-iolimits.args|9 -
 .../qemuxml2argv-disk-iolimits.xml |   33 
 tests/qemuxml2argvtest.c   |4 +-
 13 files changed, 78 insertions(+), 78 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-blockio.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-blockio.xml
 delete mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.args
 delete mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 5cb5a56..503685f 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1288,7 +1288,7 @@
   lt;driver name='qemu' type='raw'/gt;
   lt;source dev='/dev/sda'/gt;
   lt;geometry cyls='16383' heads='16' secs='63' trans='lba'/gt;
-  lt;iolimits logical_block_size='512' physical_block_size='4096'/gt;
+  lt;blockio logical_block_size='512' physical_block_size='4096'/gt;
   lt;target dev='hda' bus='ide'/gt;
 lt;/diskgt;
   lt;/devicesgt;
@@ -1657,8 +1657,8 @@
 BIOS-Translation-Modus (none, lba or auto)/dd
 /dl
   /dd
-  dtcodeiolimits/code/dt
-  ddIf present, the codeiolimits/code element allows
+  dtcodeblockio/code/dt
+  ddIf present, the codeblockio/code element allows
 to override any of the block device properties listed below.
 span class=sinceSince 0.10.2 (QEMU and KVM)/span
 dl
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index abd0e8f..c2c6184 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -890,7 +890,7 @@
 ref name=geometry/
   /optional
   optional
-ref name=diskIoLimits/
+ref name=diskBlockIo/
   /optional
 /interleave
   /define
@@ -1116,8 +1116,8 @@
   /optional
 /element
   /define
-  define name=diskIoLimits
-element name=iolimits
+  define name=diskBlockIo
+element name=blockio
   optional
 attribute name=logical_block_size
   data type=integer/
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c34a0a8..8952b69 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3439,8 +3439,8 @@ virDomainDiskDefParseXML(virCapsPtr caps,
 def-geometry.sectors = 0;
 def-geometry.trans = VIR_DOMAIN_DISK_TRANS_DEFAULT;
 
-def-iolimits.logical_block_size = 0;
-def-iolimits.physical_block_size = 0;
+def-blockio.logical_block_size = 0;
+def-blockio.physical_block_size = 0;
 
 ctxt-node = node;
 
@@ -3580,12 +3580,12 @@ virDomainDiskDefParseXML(virCapsPtr caps,
 goto error;
 }
 }
-} else if (xmlStrEqual(cur-name, BAD_CAST iolimits)) {
+} else if (xmlStrEqual(cur-name, BAD_CAST blockio)) {
 logical_block_size =
 virXMLPropString(cur, logical_block_size);
 if (logical_block_size 
 virStrToLong_ui(logical_block_size, NULL, 0,
-def-iolimits.logical_block_size)  0) {
+def-blockio.logical_block_size)  0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_(invalid logical block size '%s'),
logical_block_size);
@@ -3595,7 +3595,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
 virXMLPropString(cur, physical_block_size);
 if (physical_block_size 
 virStrToLong_ui(physical_block_size, NULL, 0,
-def-iolimits.physical_block_size)  0) {
+def-blockio.physical_block_size)  0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,

Re: [libvirt] [PATCH 1/2] qemu: clean up qemuSetSchedulerParametersFlags()

2012-09-04 Thread Eric Blake
On 09/04/2012 08:12 AM, Peter Krempa wrote:
 This patch tries to clean the code up a little bit and shorten very long
 lines.
 ---
  src/qemu/qemu_driver.c | 69 
 +++---
  1 file changed, 31 insertions(+), 38 deletions(-)
 
 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index b12d9bc..4b8b751 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -7801,6 +7801,8 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
  virCgroupPtr group = NULL;
  virDomainObjPtr vm = NULL;
  virDomainDefPtr vmdef = NULL;
 +unsigned long long value_ul;
 +long long value_l;
  int ret = -1;
  int rc;
 
 @@ -7857,74 +7859,65 @@ qemuSetSchedulerParametersFlags(virDomainPtr dom,
 
  for (i = 0; i  nparams; i++) {
  virTypedParameterPtr param = params[i];
 +value_ul = param-value.ul;
 +value_l = param-value.l;

Technically, reading two distinct values from a single union is
undefined behavior; it is only well-defined to read a single value
according to the discriminating type found outside the union.  In
practice, though, I see no practical issues with this, if Coverity and
the like don't complain.

  } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)) {
 -if (flags  VIR_DOMAIN_AFFECT_LIVE) {
 -rc = qemuSetVcpusBWLive(vm, group, params[i].value.ul, 0);
 -if (rc != 0)
 +if (flags  VIR_DOMAIN_AFFECT_LIVE  value_ul) {
 +if ((rc = qemuSetVcpusBWLive(vm, group, value_ul, 0)))
  goto cleanup;
 
 -if (params[i].value.ul)
 -vm-def-cputune.period = params[i].value.ul;
 +vm-def-cputune.period = value_ul;
  }

This is a slight change in semantics; beforehand, it called
qemuSetVcpusBWLive even when the value was 0; now it only calls the
helper function for a non-zero value.  Your commit message made it sound
like this patch has no semantic impact; either it is wrong (this is
intentional, so you should document it), or it was right (and this hunk
is wrong).  Which is it?

  } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_VCPU_QUOTA)) {
 -if (flags  VIR_DOMAIN_AFFECT_LIVE) {
 -rc = qemuSetVcpusBWLive(vm, group, 0, params[i].value.l);
 -if (rc != 0)
 +if (flags  VIR_DOMAIN_AFFECT_LIVE  value_l) {

And another one of those semantic changes.

  } else if (STREQ(param-field, 
 VIR_DOMAIN_SCHEDULER_EMULATOR_PERIOD)) {
 -if (flags  VIR_DOMAIN_AFFECT_LIVE) {
 -rc = qemuSetEmulatorBandwidthLive(vm, group, 
 params[i].value.ul, 0);
 -if (rc != 0)
 +if (flags  VIR_DOMAIN_AFFECT_LIVE  value_ul) {

And another.

  } else if (STREQ(param-field, VIR_DOMAIN_SCHEDULER_EMULATOR_QUOTA)) 
 {
 -if (flags  VIR_DOMAIN_AFFECT_LIVE) {
 -rc = qemuSetEmulatorBandwidthLive(vm, group, 0, 
 params[i].value.l);
 -if (rc != 0)
 +if (flags  VIR_DOMAIN_AFFECT_LIVE  value_l) {

And another.

Depending on how you answer my complaint, I might be able to ack this
with just an improved commit message, instead of needing a v2.

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



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

[libvirt] [PATCH] Pass a correct pointer type to localtime_r(3).

2012-09-04 Thread Jasper Lievisse Adriaanse
From b53dc971cc50b5ac397e4568449d25041477c8d6 Mon Sep 17 00:00:00 2001
From: Jasper Lievisse Adriaanse jas...@humppa.nl
Date: Tue, 4 Sep 2012 16:47:26 +0200
Subject: [PATCH] Pass a correct pointer type to localtime_r(3).

Fixes a warning:
warning: passing argument 1 of 'localtime_r' from incompatible pointer type
---
 tools/virsh-domain.c |3 ++-
 tools/virsh.c|3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f0ec742..535779c 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -3711,6 +3711,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const 
char *mime)
 struct tm time_info;
 const char *ext = NULL;
 char *ret = NULL;
+time_t sec = (time_t) cur_time.tv_sec;
 
 if (!dom) {
 vshError(ctl, %s, _(Invalid domain supplied));
@@ -3724,7 +3725,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const 
char *mime)
 /* add mime type here */
 
 gettimeofday(cur_time, NULL);
-localtime_r(cur_time.tv_sec, time_info);
+localtime_r(sec, time_info);
 strftime(timestr, sizeof(timestr), %Y-%m-%d-%H:%M:%S, time_info);
 
 if (virAsprintf(ret, %s-%s%s, virDomainGetName(dom),
diff --git a/tools/virsh.c b/tools/virsh.c
index 5cf3237..5be2a3c 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2189,6 +2189,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const 
char *msg_format,
 const char *lvl = ;
 struct timeval stTimeval;
 struct tm *stTm;
+time_t sec = stTimeval.tv_sec;
 
 if (ctl-log_fd == -1)
 return;
@@ -2199,7 +2200,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const 
char *msg_format,
  * [.MM.DD HH:MM:SS SIGNATURE PID] LOG_LEVEL message
 */
 gettimeofday(stTimeval, NULL);
-stTm = localtime(stTimeval.tv_sec);
+stTm = localtime(sec);
 virBufferAsprintf(buf, [%d.%02d.%02d %02d:%02d:%02d %s %d] ,
   (1900 + stTm-tm_year),
   (1 + stTm-tm_mon),
-- 
1.7.6


-- 
Cheers,
Jasper

Stay Hungry. Stay Foolish

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


Re: [libvirt] [PATCH] conf: describe security_driver behavior

2012-09-04 Thread Eric Blake
On 09/04/2012 08:23 AM, Martin Kletzander wrote:
 As a request was raised for this, I added few lines in the Notes
 part of the security_driver comments about allowed values.
 ---
 The related bug for this patch is here:
 https://bugzilla.redhat.com/show_bug.cgi?id=853925
 
  src/qemu/qemu.conf | 5 -
  1 file changed, 4 insertions(+), 1 deletion(-)
 
 diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
 index d3175fa..f0ba163 100644
 --- a/src/qemu/qemu.conf
 +++ b/src/qemu/qemu.conf
 @@ -164,7 +164,10 @@
  #
  #   security_driver = [ selinux, apparmor ]
  #
 -# Note: The DAC security driver is always enabled.
 +# Notes: The DAC security driver is always enabled, setting the
 +# security_driver to that value is not allowed as well as adding dac
 +# into the list of security drivers. Value none is special value and
 +# cannot be used in the list of security drivers.

Grammar; might I suggest:

The DAC security driver is always enabled; as a result, the value of
security_driver cannot contain dac.  The value none is a special
value; security_driver can be set to that value in isolation, but it
cannot appear in a list of drivers.

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



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

[libvirt] [PATCH] Define DYNLIB_NAME on OpenBSD.

2012-09-04 Thread Jasper Lievisse Adriaanse
From 05dd99030d865127c874d1b489b9c17412bdbb3b Mon Sep 17 00:00:00 2001
From: Jasper Lievisse Adriaanse jas...@humppa.nl
Date: Tue, 4 Sep 2012 16:48:51 +0200
Subject: [PATCH] Define DYNLIB_NAME on OpenBSD.

---
 src/vbox/vbox_XPCOMCGlue.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c
index e7e9c37..63470ae 100644
--- a/src/vbox/vbox_XPCOMCGlue.c
+++ b/src/vbox/vbox_XPCOMCGlue.c
@@ -48,7 +48,7 @@
 
/***
 *   Defined Constants And Macros   
*
 
***/
-#if defined(__linux__) || defined(__linux_gnu__) || defined(__sun__) || 
defined(__FreeBSD__)
+#if defined(__linux__) || defined(__linux_gnu__) || defined(__sun__) || 
defined(__FreeBSD__) || defined(__OpenBSD__)
 # define DYNLIB_NAMEVBoxXPCOMC.so
 #elif defined(__APPLE__)
 # define DYNLIB_NAMEVBoxXPCOMC.dylib
-- 
1.7.6

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


Re: [libvirt] [PATCH] docs: correct dompmwakeup description

2012-09-04 Thread Eric Blake
On 09/04/2012 08:23 AM, Martin Kletzander wrote:
 The command 'dompmwakeup' can wakeup any pmsuspended domain, not only
 domains suspended previously by dompmsuspend and this patch fixed the
 man page and help string for that.
 ---
  tools/virsh-domain.c | 6 +++---
  tools/virsh.pod  | 7 ---
  2 files changed, 7 insertions(+), 6 deletions(-)

ACK.

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



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

Re: [libvirt] [PATCH] Rename iolimit to blockio.

2012-09-04 Thread Eric Blake
On 09/04/2012 08:30 AM, Viktor Mihajlovski wrote:
 After discussion with DB we decided to rename the new iolimit
 element as it creates the impression it would be there to
 limit (i.e. throttle) I/O instead of specifying immutable
 characteristics of a block device.
 This is also backed by the fact that the term I/O Limits has
 vanished from newer storage admin documentation.
 
 Signed-off-by: Viktor Mihajlovski mihaj...@linux.vnet.ibm.com
 ---
  docs/formatdomain.html.in  |6 ++--
  docs/schemas/domaincommon.rng  |6 ++--
  src/conf/domain_conf.c |   30 +-
  src/conf/domain_conf.h |2 +-
  src/qemu/qemu_capabilities.c   |4 +-
  src/qemu/qemu_capabilities.h   |2 +-
  src/qemu/qemu_command.c|   10 +++---
  tests/qemuhelptest.c   |8 ++--
  .../qemuxml2argv-disk-blockio.args |9 +
  .../qemuxml2argvdata/qemuxml2argv-disk-blockio.xml |   33 
 
  .../qemuxml2argv-disk-iolimits.args|9 -
  .../qemuxml2argv-disk-iolimits.xml |   33 
 
  tests/qemuxml2argvtest.c   |4 +-
  13 files changed, 78 insertions(+), 78 deletions(-)
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-blockio.args
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-blockio.xml
  delete mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.args
  delete mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-iolimits.xml

Your diff would be smaller if you used 'git config diff.renames true',
as it would then show file renames instead of delete/create actions.
But that's only in the presentation, and not a flaw in the patch itself.

ACK and will push shortly.

 +++ b/src/qemu/qemu_capabilities.c
 @@ -172,7 +172,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
bridge, /* 100 */
lsi,
virtio-scsi-pci,
 -  iolimits,
 +  blockio,
disable-s3,

This hunk will invalidate any running domains that were started with
libvirt.git after the original patch but prior to applying this patch;
but since that is unreleased code, I think anyone affected will be
reading this list, so I'm not worried about it.

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



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

Re: [libvirt] [PATCH] Pass a correct pointer type to localtime_r(3).

2012-09-04 Thread Jasper Lievisse Adriaanse
FYI, these patches and those I will send later supersede the previous patchsets
I sent yesterday for fixing and making libvirt work on OpenBSD.

On Tue, Sep 04, 2012 at 04:49:52PM +0200, Jasper Lievisse Adriaanse wrote:
 From b53dc971cc50b5ac397e4568449d25041477c8d6 Mon Sep 17 00:00:00 2001
 From: Jasper Lievisse Adriaanse jas...@humppa.nl
 Date: Tue, 4 Sep 2012 16:47:26 +0200
 Subject: [PATCH] Pass a correct pointer type to localtime_r(3).
 
 Fixes a warning:
 warning: passing argument 1 of 'localtime_r' from incompatible pointer type
 ---
  tools/virsh-domain.c |3 ++-
  tools/virsh.c|3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)
 
 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
 index f0ec742..535779c 100644
 --- a/tools/virsh-domain.c
 +++ b/tools/virsh-domain.c
 @@ -3711,6 +3711,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const 
 char *mime)
  struct tm time_info;
  const char *ext = NULL;
  char *ret = NULL;
 +time_t sec = (time_t) cur_time.tv_sec;
  
  if (!dom) {
  vshError(ctl, %s, _(Invalid domain supplied));
 @@ -3724,7 +3725,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const 
 char *mime)
  /* add mime type here */
  
  gettimeofday(cur_time, NULL);
 -localtime_r(cur_time.tv_sec, time_info);
 +localtime_r(sec, time_info);
  strftime(timestr, sizeof(timestr), %Y-%m-%d-%H:%M:%S, time_info);
  
  if (virAsprintf(ret, %s-%s%s, virDomainGetName(dom),
 diff --git a/tools/virsh.c b/tools/virsh.c
 index 5cf3237..5be2a3c 100644
 --- a/tools/virsh.c
 +++ b/tools/virsh.c
 @@ -2189,6 +2189,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const 
 char *msg_format,
  const char *lvl = ;
  struct timeval stTimeval;
  struct tm *stTm;
 +time_t sec = stTimeval.tv_sec;
  
  if (ctl-log_fd == -1)
  return;
 @@ -2199,7 +2200,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const 
 char *msg_format,
   * [.MM.DD HH:MM:SS SIGNATURE PID] LOG_LEVEL message
  */
  gettimeofday(stTimeval, NULL);
 -stTm = localtime(stTimeval.tv_sec);
 +stTm = localtime(sec);
  virBufferAsprintf(buf, [%d.%02d.%02d %02d:%02d:%02d %s %d] ,
(1900 + stTm-tm_year),
(1 + stTm-tm_mon),
 -- 
 1.7.6
 
 
 -- 
 Cheers,
 Jasper
 
 Stay Hungry. Stay Foolish
 
 --
 libvir-list mailing list
 libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list

-- 
Cheers,
Jasper

Stay Hungry. Stay Foolish

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


Re: [libvirt] about open vswitch supporting?

2012-09-04 Thread Laine Stump
On 09/04/2012 02:20 AM, yue wang wrote:
 it seems the  'generic ethernet connection' network doesn't have the
 'virtualport ' element, so there is no way to associate it with an
 interface's uuid.
 are there any workaround?

See the other reply I just sent (I thought I'd typed it up yesterday,
but forgot to hit send). You shouldn't be using the generic ethernet
connection type for either standard linux bridges or Open vSwitch
bridges (unless you are using Open vSwitch *and* your libvirt is older
than 0.9.11, and in that case there is no type='openvswitch' for
virtualport anyway).

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

Re: [libvirt] [PATCH 2/2] qemu: Add range checking for scheduler tunables

2012-09-04 Thread Eric Blake
On 09/04/2012 08:12 AM, Peter Krempa wrote:
 The quota and period tunables for cpu scheduler accept only a certain
 range of values. When changing the live configuration invalid values get
 rejected. This check is not performed when changing persistent config.
 
 This patch adds a separate range check, that improves error messages
 when changing live config and adds the check for persistent config.
 ---
  src/qemu/qemu_driver.c | 27 +++
  1 file changed, 27 insertions(+)
 
 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index 4b8b751..3d59594 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -106,6 +106,11 @@
  #define QEMU_NB_TOTAL_CPU_STAT_PARAM 3
  #define QEMU_NB_PER_CPU_STAT_PARAM 2
 
 +#define QEMU_SCHED_MIN_PERIOD (long long)  1000

Under-parenthesized; if you insist on the cast, it should be:

#define QEMU_SCHED_MIN_PERIOD ((long long) 1000)

that said, it is possible to be more concise (with no parentheses
necessary):

#define QEMU_SCHED_MIN_PERIOD 1000LL

 +#define QEMU_SCHED_MAX_PERIOD (long long)   100
 +#define QEMU_SCHED_MIN_QUOTA  (long long)  1000
 +#define QEMU_SCHED_MAX_QUOTA  (long long) 18446744073709551

Furthermore, in the case of MAX_QUOTA, your code is wrong.  The C
compiler treats this as ((long long) ((int) 18446744073709551)), which
is 1271310319; here, you absolutely need the LL suffix, at which point
you no longer need the cast.

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



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

[libvirt] [PATCH] Use sockpeercred on OpenBSD.

2012-09-04 Thread Jasper Lievisse Adriaanse
From 0f352c0577f76a64924636a8c9ba72de5862b6d6 Mon Sep 17 00:00:00 2001
From: Jasper Lievisse Adriaanse jas...@humppa.nl
Date: Tue, 4 Sep 2012 16:59:55 +0200
Subject: [PATCH] Use sockpeercred on OpenBSD.

---
 src/rpc/virnetsocket.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 5a48300..27ead13 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -988,7 +988,11 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
 gid_t *gid,
 pid_t *pid)
 {
+#if defined (__OpenBSD__)
+struct sockpeercred cr;
+#else
 struct ucred cr;
+#endif
 socklen_t cr_len = sizeof(cr);
 virMutexLock(sock-lock);
 
-- 
1.7.6

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


[libvirt] [PATCH] Include some extra headers needed for OpenBSD.

2012-09-04 Thread Jasper Lievisse Adriaanse
From bafcb4ed2b90b5ba845ca6b61861e3caa548b16a Mon Sep 17 00:00:00 2001
From: Jasper Lievisse Adriaanse jas...@humppa.nl
Date: Tue, 4 Sep 2012 16:57:09 +0200
Subject: [PATCH] Include some extra headers needed for OpenBSD.

---
 src/util/virnetdevbridge.c |9 +
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c
index 7b11bee..8559223 100644
--- a/src/util/virnetdevbridge.c
+++ b/src/util/virnetdevbridge.c
@@ -30,6 +30,15 @@
 #include intprops.h
 
 #include sys/ioctl.h
+
+#ifdef HAVE_SYS_PARAM_H
+# include sys/param.h
+#endif
+
+#ifdef HAVE_SYS_SOCKET_H
+# include sys/socket.h
+#endif
+
 #ifdef HAVE_NET_IF_H
 # include net/if.h
 #endif
-- 
1.7.6


-- 
Cheers,
Jasper

Stay Hungry. Stay Foolish

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


Re: [libvirt] [PATCH 00/45 v3] Atomic APIs to list objects

2012-09-04 Thread Peter Krempa
Now that we're after the release it would be time to get this series 
finished up. Could you please post a rebased version (There will be some 
problem probably after splitting virsh) so that we can get this wrapped 
up early in the devel phase.


Also, I'd like to ask you to send it split by new API function ... so 
that reviewing is easier. (It's (psychologically) hard to start 
reviewing a 45 patch series opposed to a 10 patch one :) ).


Thanks.

Peter

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


[libvirt] [PATCH] Don't link with -lrt on OpenBSD

2012-09-04 Thread Jasper Lievisse Adriaanse
From bdf3bce37531ec346474bc5c4f37a5d2985d1d35 Mon Sep 17 00:00:00 2001
From: Jasper Lievisse Adriaanse jas...@humppa.nl
Date: Tue, 4 Sep 2012 17:03:43 +0200
Subject: [PATCH] Don't link with -lrt on OpenBSD

---
 configure.ac |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index e0d00d5..54d049d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -188,7 +188,13 @@ RT_LIBS=
 LIBS=$LIBS $LIB_PTHREAD -lrt
 AC_CHECK_FUNC([clock_gettime],[
  AC_DEFINE([HAVE_CLOCK_GETTIME],[],[Defined if clock_gettime() exists in 
librt.so])
- RT_LIBS=-lrt
+ case $host in
+   *-*-openbsd*)
+ ;;
+   *)
+ RT_LIBS=-lrt
+ ;;
+ esac
 ])
 LIBS=$old_libs
 AC_SUBST(RT_LIBS)
-- 
1.7.6


-- 
Cheers,
Jasper

Stay Hungry. Stay Foolish

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


[libvirt] [PATCH] qemu: Do not require auth scheme in graphics events

2012-09-04 Thread Jiri Denemark
Only VNC_{{DIS,}CONNECTED,INITIALIZED} and SPICE_INITIALIZED events are
documented to support server/auth field and even there it is marked as
optional. Emit  auth scheme in case QEMU didn't send it.
---
 src/qemu/qemu_monitor_json.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 643431c..bab6ca2 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -685,8 +685,9 @@ static void qemuMonitorJSONHandleGraphics(qemuMonitorPtr 
mon, virJSONValuePtr da
 
 authScheme = virJSONValueObjectGetString(server, auth);
 if (!authScheme) {
-VIR_WARN(missing auth scheme in graphics event);
-return;
+/* not all events are required to contain auth scheme */
+VIR_DEBUG(missing auth scheme in graphics event);
+authScheme = ;
 }
 
 localFamily = virJSONValueObjectGetString(server, family);
-- 
1.7.12

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


Re: [libvirt] about open vswitch supporting?

2012-09-04 Thread Laine Stump
On 09/03/2012 06:41 AM, yue wang wrote:


 Hi:


 i used to use linux bridge and specify interfaces
 by 'Generic ethernet connection' mode,after
 reading this page:


 http://libvirt.org/formatdomain.html#elementsNICS


Actually, for a standard linux bridge, you should be using interface
type='bridge' rather than interface type='ethernet' (generic
ethernet connection):

  http://www.libvirt.org/formatdomain.html#elementsNICSBridge

type='ethernet' should only be used if there is some special setup that
can't be taken care of by the standard types; type='ethernet' requires
special permissions that aren't normally required, and taints the
guest - it's considered to be unsupported.



 i am not sure if i need to change to another
 mode(eg:'virtual network') to specify interfaces
 when switching linux bridge to open vswitch?

   any suggestions?


As long as your libvirt version is new enough (0.9.11 or newer), you can
continue to use interface type='bridge' (as you should have previously
been), and add a virtualport type='openvswitch' element to the
interface definition. For example, if you were previously using a linux
bridge at br0, you would have have used:

   interface type='bridge'
 source bridge='br0'/
 ...
   /interface

and if you switch to using an Open vSwitch bridge named ovsbr0, you
would change that to:

   interface type='bridge'
 source bridge='ovsbr0'/
 virtualport type='openvswitch'/
 ...
   /interface

(you will notice that after you've edited you interface definition like
this, libvirt will automatically add a parameters interfaceid=[some
uuid string]/ to the virtualport element. This is so that the
guest's interface can be known by a stable id that won't change as the
guest is stopped/restarted/migrated.)


If your libvirt is older than 0.9.11,you will need to either use the
Open vSwitch compatibility library to make your Open vSwitch bridge
appear to be a standard Linux host bridge, *or* you wil need to use
interface type='ethernet' along with an ifup script. I would
*strongly* recommend that you upgrade to 0.9.11+ if at all possible.

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

Re: [libvirt] [PATCH 00/45 v3] Atomic APIs to list objects

2012-09-04 Thread Osier Yang

On 2012年09月04日 23:04, Peter Krempa wrote:

Now that we're after the release it would be time to get this series
finished up. Could you please post a rebased version (There will be some
problem probably after splitting virsh) so that we can get this wrapped
up early in the devel phase.


Actually I'm just doing it...


Also, I'd like to ask you to send it split by new API function ... so
that reviewing is easier. (It's (psychologically) hard to start
reviewing a 45 patch series opposed to a 10 patch one :) ).


... Just finish the pool patches. I will post.

Regards,
Osier

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

Re: [libvirt] VM Migration with IEEE802.1Qbh and IEEE802.1Qbg

2012-09-04 Thread Laine Stump
On 09/04/2012 04:29 AM, Martin Kletzander wrote:
 On 09/02/2012 01:53 PM, Jagath Weerasinghe wrote:
 Hi All,

 Can a VM connected as IEEE802.1Qbh be migrated to a destination host
 as it were connected as IEEE802.1Qbg? What I wanted to know is, is it
 possible to change the configuration from IEEE802.1Qbh to IEEE802.1Qbg
 on the fly?

 IIUC, you want to migrate the guest from host A, where it has a network
 interface connected to 802.1Qbh switch, to host B, where it should be
 connected to 802.1Qbg switch, right?

 I see three possibilities to do that, but unfortunately I cannot say if
 these will work.

 If the guest has interface type='network' and that network has
 virtualport type='802.1Qbh' on host A and virtualport
 type='802.1Qbg' on host B, that might be working as-is.

Yes, that's the intent of allowing virtualport settings in network
objects - it divorces the guest config from the specifics of the network
it's connecting to (which is really an attribute of the *host* that the
guest happens to be running on, so could change).

Basically, the guest names a network it wants to use, and a network of
that name should be available on both hosts, with virtualport setup
appropriately.

If this doesn't work, it's a bug. In that case (and also if it does
work!) please report back here. As rare as it is to have either 802.1Qbg
or 802.1Qbh hardware available for testing, it is even more rare to have
both available at the same time, so the results of your testing would be
very valuable!


 If the guest has virtualport type='802.1Qbh' specified in its
 interface, you should be able to change the type using migrate hook
 [1] on host B.

Yes, but more complicated to setup, which implies more fragile.
Definitely prefer the first method Martin suggested.

 There should be one more option in case the virtualport is specified
 in the guest's interface. According to the docs [2], when no type=
 is specified for the virtualport element, this should be
 auto-completed on the domain startup, but that's most probably not
 applicable for your situation (migration).

That is only the case for 1) very new libvirt (0.10.0+) and 2)
interface type='network'. It's purpose is to allow specifying, for
example, both an openvswitch interfaceid and an 802.11Qbh profileid at
the same time (for cases when the guest doesn't know whether the network
it connects to will be openvswitch or 802.1Qbh, and wants to specify the
appropriate setting for both possibilities).


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


Re: [libvirt] [PATCH] (updated) additional parameters needed for dnsmasq

2012-09-04 Thread Eric Blake
On 08/22/2012 11:47 AM, Eric Blake wrote:
 On 08/22/2012 11:39 AM, Eric Blake wrote:
 On 08/22/2012 10:59 AM, Gene Czarcinski wrote:
 As I said in a previous message, dnsmasq is forwarding a number of
 queries upstream that should not be done.  There still remains an MX
 query for a plain name with no domain specified that will be forwarded
 is dnsmasq has --domain=xxx  --local=/xxx/ specified. This does not
 happen with no domain name and --local=// ... not a libvirt problem.


 ACK and pushed with the above tweak, and with adding you to AUTHORS (let
 us know if you prefer any other spelling or email address; the file is
 in UTF-8).
 
 Oh, and now that I've already pushed, I have a high-level question: what
 is the minimum version of 'dnsmasq' that supports the command-line
 syntax that this patch introduces?
 
 +--local=// --domain-needed --filterwin2k \
 
 If older dnsmasq doesn't recognize --local=// or the new --domain-needed
 or --filterwin2k options, then we either need to make this code
 conditional based on probing 'dnsmasq --help' at startup, or else change
 the spec file to require a larger minimum version of dnsmasq (we already
 require 2.41 for other reasons).

Just as I feared, we introduced a regression:

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

Apparently, --filterwin2k disables features needed by Windows guests.
Gene, what is the benefit vs. cost of adding this flag?  I'm trying to
figure out whether we need to expose it as something user-configurable,
or whether we should just revert back to the pre-patch version that did
not supply that option.

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



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

[libvirt] [PATCH 02/10] list: Add helpers for listing storage pool objects

2012-09-04 Thread Osier Yang
src/conf/storage_conf.c: Add virStoragePoolMatch to filter the
pools; Add virStoragePoolList to iterate over the pool objects
with filter.

src/conf/storage_conf.h: Declare virStoragePoolMatch,
virStoragePoolList, and the macros for filters.

src/libvirt_private.syms: Export helper virStoragePoolList.
---
 src/conf/storage_conf.c  |  116 ++
 src/conf/storage_conf.h  |   35 ++
 src/libvirt_private.syms |1 +
 3 files changed, 152 insertions(+), 0 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 3132aae..b14564f 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1883,3 +1883,119 @@ void virStoragePoolObjUnlock(virStoragePoolObjPtr obj)
 {
 virMutexUnlock(obj-lock);
 }
+
+#define MATCH(FLAG) (flags  (FLAG))
+static bool
+virStoragePoolMatch(virStoragePoolObjPtr poolobj,
+unsigned int flags)
+{
+/* filter by active state */
+if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) 
+!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE) 
+   virStoragePoolObjIsActive(poolobj)) ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE) 
+   !virStoragePoolObjIsActive(poolobj
+return false;
+
+/* filter by persistence */
+if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_PERSISTENT) 
+!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT) 
+   poolobj-configFile) ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT) 
+   !poolobj-configFile)))
+return false;
+
+/* filter by autostart option */
+if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART) 
+!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART) 
+   poolobj-autostart) ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART) 
+   !poolobj-autostart)))
+return false;
+
+/* filter by pool type */
+if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)) {
+if (!((MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_DIR) 
+   (poolobj-def-type == VIR_STORAGE_POOL_DIR)) ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FS) 
+   (poolobj-def-type == VIR_STORAGE_POOL_FS))  ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_NETFS) 
+   (poolobj-def-type == VIR_STORAGE_POOL_NETFS))   ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL) 
+   (poolobj-def-type == VIR_STORAGE_POOL_LOGICAL)) ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_DISK) 
+   (poolobj-def-type == VIR_STORAGE_POOL_DISK))||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI) 
+   (poolobj-def-type == VIR_STORAGE_POOL_ISCSI))   ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_SCSI) 
+   (poolobj-def-type == VIR_STORAGE_POOL_SCSI))||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_MPATH) 
+   (poolobj-def-type == VIR_STORAGE_POOL_MPATH))   ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_RBD) 
+   (poolobj-def-type == VIR_STORAGE_POOL_RBD)) ||
+  (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG) 
+   (poolobj-def-type == VIR_STORAGE_POOL_SHEEPDOG
+return false;
+}
+
+return true;
+}
+#undef MATCH
+
+int
+virStoragePoolList(virConnectPtr conn,
+   virStoragePoolObjList poolobjs,
+   virStoragePoolPtr **pools,
+   unsigned int flags)
+{
+virStoragePoolPtr *tmp_pools = NULL;
+virStoragePoolPtr pool = NULL;
+int npools = 0;
+int ret = -1;
+int i;
+
+if (pools) {
+if (VIR_ALLOC_N(tmp_pools, poolobjs.count + 1)  0) {
+virReportOOMError();
+goto cleanup;
+}
+}
+
+for (i = 0; i  poolobjs.count; i++) {
+virStoragePoolObjPtr poolobj = poolobjs.objs[i];
+virStoragePoolObjLock(poolobj);
+if (virStoragePoolMatch(poolobj, flags)) {
+if (pools) {
+if (!(pool = virGetStoragePool(conn,
+   poolobj-def-name,
+   poolobj-def-uuid))) {
+virStoragePoolObjUnlock(poolobj);
+goto cleanup;
+}
+tmp_pools[npools] = pool;
+}
+npools++;
+}
+virStoragePoolObjUnlock(poolobj);
+}
+
+if (tmp_pools) {
+/* trim the array to the final size */
+ignore_value(VIR_REALLOC_N(tmp_pools, npools + 1));
+*pools = tmp_pools;
+tmp_pools = NULL;
+}
+
+ret = npools;
+
+cleanup:
+if (tmp_pools) {
+for (i = 0; i  npools; i++) {
+if (tmp_pools[i])
+virStoragePoolFree(tmp_pools[i]);
+}
+}
+
+VIR_FREE(tmp_pools);
+return ret;
+}
diff --git a/src/conf/storage_conf.h 

[libvirt] [PATCH v4 00/10] Atomic API to list storage pools

2012-09-04 Thread Osier Yang
Think the subject tells enough after 3 rounds, so ommits words here.

v3 - v4:
  * Just rebase on the top:
- Version changes
- rebase after virsh split cleanups

1/10 ~ 2/10 are ACK'ed in v3, but for easy viewing, they are still
posted.

Osier Yang (10):
  list: Define new API virStorageListAllStoragePools
  list: Add helpers for listing storage pool objects
  list: Implement the RPC calls for virConnectListAllStoragePools
  list: Implement listAllStoragePools for storage driver
  list: Implement listAllStoragePools for test driver
  list: Add helper to convert strings separated by ', ' to array
  virsh: Fix the wrong doc for pool-list
  list: Change MATCH for common use in virsh
  list: Use virConnectListAllStoragePools in virsh
  python: Expose virStorageListAllStoragePools to python binding

 daemon/remote.c   |   54 +++
 include/libvirt/libvirt.h.in  |   33 ++
 python/generator.py   |5 +-
 python/libvirt-override-api.xml   |6 +
 python/libvirt-override-virConnect.py |   12 +
 python/libvirt-override.c |   47 +++
 src/conf/storage_conf.c   |  116 ++
 src/conf/storage_conf.h   |   35 ++
 src/driver.h  |5 +
 src/libvirt.c |  112 ++-
 src/libvirt_private.syms  |1 +
 src/libvirt_public.syms   |5 +
 src/remote/remote_driver.c|   64 
 src/remote/remote_protocol.x  |   13 +-
 src/remote_protocol-structs   |   12 +
 src/storage/storage_driver.c  |   18 +
 src/test/test_driver.c|   17 +
 tools/virsh-domain-monitor.c  |2 -
 tools/virsh-domain.c  |   19 +-
 tools/virsh-pool.c|  631 -
 tools/virsh.c |   44 +++
 tools/virsh.h |3 +
 tools/virsh.pod   |   33 ++-
 23 files changed, 1249 insertions(+), 38 deletions(-)

-- 
1.7.7.3

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


[libvirt] [PATCH 03/10] list: Implement the RPC calls for virConnectListAllStoragePools

2012-09-04 Thread Osier Yang
The RPC generator doesn't support returning list of object, this patch do
the work manually.

  * daemon/remote.c:
Implement the server side handler remoteDispatchConnectListAllStoragePools

  * src/remote/remote_driver.c:
Add remote driver handler remoteConnectListAllStoragePools.

  * src/remote/remote_protocol.x:
New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS and
structs to represent the args and ret for it.

  * src/remote_protocol-structs: Likewise.
---
 daemon/remote.c  |   54 +++
 src/remote/remote_driver.c   |   64 ++
 src/remote/remote_protocol.x |   13 -
 src/remote_protocol-structs  |   12 
 4 files changed, 142 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 24928f4..9056439 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4099,6 +4099,60 @@ cleanup:
 return rv;
 }
 
+static int
+remoteDispatchConnectListAllStoragePools(virNetServerPtr server 
ATTRIBUTE_UNUSED,
+ virNetServerClientPtr client,
+ virNetMessagePtr msg ATTRIBUTE_UNUSED,
+ virNetMessageErrorPtr rerr,
+ 
remote_connect_list_all_storage_pools_args *args,
+ 
remote_connect_list_all_storage_pools_ret *ret)
+{
+virStoragePoolPtr *pools = NULL;
+int npools = 0;
+int i;
+int rv = -1;
+struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+if (!priv-conn) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s, _(connection not open));
+goto cleanup;
+}
+
+if ((npools = virConnectListAllStoragePools(priv-conn,
+args-need_results ? pools : 
NULL,
+args-flags))  0)
+goto cleanup;
+
+if (pools  npools) {
+if (VIR_ALLOC_N(ret-pools.pools_val, npools)  0) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret-pools.pools_len = npools;
+
+for (i = 0; i  npools; i++)
+make_nonnull_storage_pool(ret-pools.pools_val + i, pools[i]);
+} else {
+ret-pools.pools_len = 0;
+ret-pools.pools_val = NULL;
+}
+
+ret-ret = npools;
+
+rv = 0;
+
+cleanup:
+if (rv  0)
+virNetMessageSaveError(rerr);
+if (pools) {
+for (i = 0; i  npools; i++)
+virStoragePoolFree(pools[i]);
+VIR_FREE(pools);
+}
+return rv;
+}
+
 /*- Helpers. -*/
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index cf1f079..c1f9044 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2857,6 +2857,69 @@ done:
 return rv;
 }
 
+static int
+remoteConnectListAllStoragePools (virConnectPtr conn,
+  virStoragePoolPtr **pools,
+  unsigned int flags)
+{
+int rv = -1;
+int i;
+virStoragePoolPtr *tmp_pools = NULL;
+remote_connect_list_all_storage_pools_args args;
+remote_connect_list_all_storage_pools_ret ret;
+
+struct private_data *priv = conn-privateData;
+
+remoteDriverLock(priv);
+
+args.need_results = !!pools;
+args.flags = flags;
+
+memset(ret, 0, sizeof(ret));
+if (call(conn,
+ priv,
+ 0,
+ REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS,
+ (xdrproc_t) xdr_remote_connect_list_all_storage_pools_args,
+ (char *) args,
+ (xdrproc_t) xdr_remote_connect_list_all_storage_pools_ret,
+ (char *) ret) == -1)
+goto done;
+
+if (pools) {
+if (VIR_ALLOC_N(tmp_pools, ret.pools.pools_len + 1)  0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (i = 0; i  ret.pools.pools_len; i++) {
+tmp_pools[i] = get_nonnull_storage_pool(conn, 
ret.pools.pools_val[i]);
+if (!tmp_pools[i]) {
+virReportOOMError();
+goto cleanup;
+}
+}
+*pools = tmp_pools;
+tmp_pools = NULL;
+}
+
+rv = ret.ret;
+
+cleanup:
+if (tmp_pools) {
+for (i = 0; i  ret.pools.pools_len; i++)
+if (tmp_pools[i])
+virStoragePoolFree(tmp_pools[i]);
+VIR_FREE(tmp_pools);
+}
+
+xdr_free((xdrproc_t) xdr_remote_connect_list_all_storage_pools_ret, (char 
*) ret);
+
+done:
+remoteDriverUnlock(priv);
+return rv;
+}
+
 /*--*/
 
 static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
@@ -5612,6 +5675,7 @@ static virStorageDriver storage_driver = {
 .listPools = remoteListStoragePools, /* 0.4.1 */
 

[libvirt] [PATCH 05/10] list: Implement listAllStoragePools for test driver

2012-09-04 Thread Osier Yang
src/test/test_driver.c: Implement listAllStoragePools
---
 src/test/test_driver.c |   17 +
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index aa4418a..1504251 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3944,6 +3944,22 @@ no_memory:
 return -1;
 }
 
+static int
+testStorageListAllPools(virConnectPtr conn,
+virStoragePoolPtr **pools,
+unsigned int flags)
+{
+testConnPtr privconn = conn-privateData;
+int ret = -1;
+
+virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL, -1);
+
+testDriverLock(privconn);
+ret = virStoragePoolList(conn, privconn-pools, pools, flags);
+testDriverUnlock(privconn);
+
+return ret;
+}
 
 static int testStoragePoolIsActive(virStoragePoolPtr pool)
 {
@@ -5662,6 +5678,7 @@ static virStorageDriver testStorageDriver = {
 .listPools = testStorageListPools, /* 0.5.0 */
 .numOfDefinedPools = testStorageNumDefinedPools, /* 0.5.0 */
 .listDefinedPools = testStorageListDefinedPools, /* 0.5.0 */
+.listAllPools = testStorageListAllPools, /* 0.10.0 */
 .findPoolSources = testStorageFindPoolSources, /* 0.5.0 */
 .poolLookupByName = testStoragePoolLookupByName, /* 0.5.0 */
 .poolLookupByUUID = testStoragePoolLookupByUUID, /* 0.5.0 */
-- 
1.7.7.3

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


Re: [libvirt] [PATCH] Include some extra headers needed for OpenBSD.

2012-09-04 Thread Eric Blake
On 09/04/2012 08:57 AM, Jasper Lievisse Adriaanse wrote:
From bafcb4ed2b90b5ba845ca6b61861e3caa548b16a Mon Sep 17 00:00:00 2001
 From: Jasper Lievisse Adriaanse jas...@humppa.nl
 Date: Tue, 4 Sep 2012 16:57:09 +0200
 Subject: [PATCH] Include some extra headers needed for OpenBSD.
 
 ---
  src/util/virnetdevbridge.c |9 +
  1 files changed, 9 insertions(+), 0 deletions(-)

Please show the compiler errors that you got without these includes.  I
can't help but wonder if you have instead uncovered a bug in the gnulib
headers, but knowing which symbols were not declared makes a difference
in answering that question.

 
 diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c
 index 7b11bee..8559223 100644
 --- a/src/util/virnetdevbridge.c
 +++ b/src/util/virnetdevbridge.c
 @@ -30,6 +30,15 @@
  #include intprops.h
  
  #include sys/ioctl.h
 +
 +#ifdef HAVE_SYS_PARAM_H

sys/param.h is non-standard; what are we using that requires us to
probe for its existence?  Should gnulib consider guaranteeing this
header in spite of it being non-standard?

 +# include sys/param.h
 +#endif
 +
 +#ifdef HAVE_SYS_SOCKET_H

This line shouldn't be necessary; gnulib guarantees a working
sys/socket.h on all architectures.

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



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

[libvirt] [PATCH 04/10] list: Implement listAllStoragePools for storage driver

2012-09-04 Thread Osier Yang
src/storage/storage_driver.c: Implement listAllStoragePools.
---
 src/storage/storage_driver.c |   18 ++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 3dc66db..4f99eb9 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2285,6 +2285,23 @@ cleanup:
 return ret;
 }
 
+static int
+storageListAllPools(virConnectPtr conn,
+virStoragePoolPtr **pools,
+unsigned int flags)
+{
+virStorageDriverStatePtr driver = conn-storagePrivateData;
+int ret = -1;
+
+virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ALL, -1);
+
+storageDriverLock(driver);
+ret = virStoragePoolList(conn, driver-pools, pools, flags);
+storageDriverUnlock(driver);
+
+return ret;
+}
+
 static virStorageDriver storageDriver = {
 .name = storage,
 .open = storageOpen, /* 0.4.0 */
@@ -2293,6 +2310,7 @@ static virStorageDriver storageDriver = {
 .listPools = storageListPools, /* 0.4.0 */
 .numOfDefinedPools = storageNumDefinedPools, /* 0.4.0 */
 .listDefinedPools = storageListDefinedPools, /* 0.4.0 */
+.listAllPools = storageListAllPools, /* 0.10.0 */
 .findPoolSources = storageFindPoolSources, /* 0.4.0 */
 .poolLookupByName = storagePoolLookupByName, /* 0.4.0 */
 .poolLookupByUUID = storagePoolLookupByUUID, /* 0.4.0 */
-- 
1.7.7.3

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


[libvirt] [PATCH 08/10] list: Change MATCH for common use in virsh

2012-09-04 Thread Osier Yang
Move definition of MATCH from virsh-domain-monitor.c into
virsh.h for further use.
---
 tools/virsh-domain-monitor.c |2 --
 tools/virsh.h|2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 7e252d2..e599159 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1290,7 +1290,6 @@ vshDomainListFree(vshDomainListPtr domlist)
 VIR_FREE(domlist);
 }
 
-#define MATCH(FLAG) (flags  (FLAG))
 static vshDomainListPtr
 vshDomainListCollect(vshControl *ctl, unsigned int flags)
 {
@@ -1509,7 +1508,6 @@ cleanup:
 VIR_FREE(ids);
 return list;
 }
-#undef MATCH
 
 static const vshCmdOptDef opts_list[] = {
 {inactive, VSH_OT_BOOL, 0, N_(list inactive domains)},
diff --git a/tools/virsh.h b/tools/virsh.h
index 2a9c6a2..2758d37 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -47,6 +47,8 @@
 
 # define GETTIMEOFDAY(T) gettimeofday(T, NULL)
 
+# define MATCH(FLAG) (flags  (FLAG))
+
 /**
  * The log configuration
  */
-- 
1.7.7.3

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


[libvirt] [PATCH 01/10] list: Define new API virStorageListAllStoragePools

2012-09-04 Thread Osier Yang
This introduces a new API to list the storage pool objects,
4 groups of flags are provided to filter the returned pools:

  * Active or not

  * Autostarting or not

  * Persistent or not

  * And the pool type.

include/libvirt/libvirt.h.in: New enum virConnectListAllStoragePoolFlags;
  Declare the API.
python/generator.py: Skip the generating
src/driver.h: (virDrvConnectListAllStoragePools)
src/libvirt.c: Implementation for the API.
src/libvirt_public.syms: Export the symbol.
---
 include/libvirt/libvirt.h.in |   33 
 python/generator.py  |5 +-
 src/driver.h |5 ++
 src/libvirt.c|  112 +++---
 src/libvirt_public.syms  |5 ++
 5 files changed, 150 insertions(+), 10 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index cfe5047..0c52271 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2554,6 +2554,39 @@ int 
virConnectListDefinedStoragePools(virConnectPtr conn,
   int maxnames);
 
 /*
+ * virConnectListAllStoragePoolsFlags:
+ *
+ * Flags used to tune pools returned by virConnectListAllStoragePools().
+ * Note that these flags come in groups; if all bits from a group are 0,
+ * then that group is not used to filter results.
+ */
+typedef enum {
+VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE  = 1  0,
+VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE= 1  1,
+
+VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT= 1  2,
+VIR_CONNECT_LIST_STORAGE_POOLS_TRANSIENT = 1  3,
+
+VIR_CONNECT_LIST_STORAGE_POOLS_AUTOSTART = 1  4,
+VIR_CONNECT_LIST_STORAGE_POOLS_NO_AUTOSTART  = 1  5,
+
+/* List pools by type */
+VIR_CONNECT_LIST_STORAGE_POOLS_DIR   = 1  6,
+VIR_CONNECT_LIST_STORAGE_POOLS_FS= 1  7,
+VIR_CONNECT_LIST_STORAGE_POOLS_NETFS = 1  8,
+VIR_CONNECT_LIST_STORAGE_POOLS_LOGICAL   = 1  9,
+VIR_CONNECT_LIST_STORAGE_POOLS_DISK  = 1  10,
+VIR_CONNECT_LIST_STORAGE_POOLS_ISCSI = 1  11,
+VIR_CONNECT_LIST_STORAGE_POOLS_SCSI  = 1  12,
+VIR_CONNECT_LIST_STORAGE_POOLS_MPATH = 1  13,
+VIR_CONNECT_LIST_STORAGE_POOLS_RBD   = 1  14,
+VIR_CONNECT_LIST_STORAGE_POOLS_SHEEPDOG  = 1  15,
+} virConnectListAllStoragePoolsFlags;
+
+int virConnectListAllStoragePools(virConnectPtr conn,
+  virStoragePoolPtr 
**pools,
+  unsigned int flags);
+/*
  * Query a host for storage pools of a particular type
  */
 char *  virConnectFindStoragePoolSources(virConnectPtr conn,
diff --git a/python/generator.py b/python/generator.py
index 7beb361..261efe0 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -337,7 +337,7 @@ foreign_encoding_args = (
 #
 ###
 
-# Class methods which are written by hand in libvir.c but the Python-level
+# Class methods which are written by hand in libvirt.c but the Python-level
 # code is still automatically generated (so they are not in skip_function()).
 skip_impl = (
 'virConnectGetVersion',
@@ -457,9 +457,10 @@ skip_function = (
 'virConnectDomainEventDeregisterAny', # overridden in virConnect.py
 'virSaveLastError', # We have our own python error wrapper
 'virFreeError', # Only needed if we use virSaveLastError
-'virConnectListAllDomains', #overridden in virConnect.py
+'virConnectListAllDomains', # overridden in virConnect.py
 'virDomainListAllSnapshots', # overridden in virDomain.py
 'virDomainSnapshotListAllChildren', # overridden in virDomainSnapshot.py
+'virConnectListAllStoragePools', # overridden in virConnect.py
 
 'virStreamRecvAll', # Pure python libvirt-override-virStream.py
 'virStreamSendAll', # Pure python libvirt-override-virStream.py
diff --git a/src/driver.h b/src/driver.h
index e88ab28..342f6b5 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1252,6 +1252,10 @@ typedef int
 (*virDrvConnectListDefinedStoragePools)  (virConnectPtr conn,
   char **const names,
   int maxnames);
+typedef int
+(*virDrvConnectListAllStoragePools)  (virConnectPtr conn,
+  virStoragePoolPtr **pools,
+  unsigned int flags);
 typedef char *
 (*virDrvConnectFindStoragePoolSources)   (virConnectPtr conn,
   const char *type,
@@ -1396,6 +1400,7 @@ struct _virStorageDriver {
 virDrvConnectListStoragePools   listPools;
 virDrvConnectNumOfDefinedStoragePools   numOfDefinedPools;
 virDrvConnectListDefinedStoragePools

[libvirt] [PATCH 09/10] list: Use virConnectListAllStoragePools in virsh

2012-09-04 Thread Osier Yang
tools/virsh-pool.c:
  * vshStoragePoolSorter to sort the pool list by pool name.

  * struct vshStoragePoolList to present the pool list, pool info
is collected by list-poolinfo if 'details' is specified by
user.

  * vshStoragePoolListFree to free the pool list

  * vshStoragePoolListCollect to collect the pool list, new API
virStorageListAllPools is tried first, if it's not supported,
fall back to older APIs.

  * New options --persistent, --transient, --autostart, --no-autostart
and --type for pool-list. --persistent or --transient is to filter
the returned pool list by whether the pool is persistent or not.
--autostart or --no-autostart is to filter the returned pool list
by whether the pool is autostarting or not. --type is to filter
the pools by pool types. E.g.

% virsh pool-list --all --persistent --type dir,disk

tools/virsh.pod:
   * Add documentations for the new options.
---
 tools/virsh-pool.c |  631 +++-
 tools/virsh.pod|   24 ++-
 2 files changed, 652 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index fd239d2..0b328cc 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -36,6 +36,7 @@
 #include memory.h
 #include util.h
 #include xml.h
+#include conf/storage_conf.h
 
 virStoragePoolPtr
 vshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
@@ -551,6 +552,232 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
 return ret;
 }
 
+static int
+vshStoragePoolSorter(const void *a, const void *b)
+{
+virStoragePoolPtr *pa = (virStoragePoolPtr *) a;
+virStoragePoolPtr *pb = (virStoragePoolPtr *) b;
+
+if (*pa  !*pb)
+return -1;
+
+if (!*pa)
+return *pb != NULL;
+
+return vshStrcasecmp(virStoragePoolGetName(*pa),
+ virStoragePoolGetName(*pb));
+}
+
+struct vshStoragePoolList {
+virStoragePoolPtr *pools;
+size_t npools;
+};
+typedef struct vshStoragePoolList *vshStoragePoolListPtr;
+
+static void
+vshStoragePoolListFree(vshStoragePoolListPtr list)
+{
+int i;
+
+if (list  list-pools) {
+for (i = 0; i  list-npools; i++) {
+if (list-pools[i])
+virStoragePoolFree(list-pools[i]);
+}
+VIR_FREE(list-pools);
+}
+VIR_FREE(list);
+}
+
+static vshStoragePoolListPtr
+vshStoragePoolListCollect(vshControl *ctl,
+  unsigned int flags)
+{
+vshStoragePoolListPtr list = vshMalloc(ctl, sizeof(*list));
+int i;
+int ret;
+char **names = NULL;
+virStoragePoolPtr pool;
+bool success = false;
+size_t deleted = 0;
+int persistent;
+int autostart;
+int nActivePools = 0;
+int nInactivePools = 0;
+int nAllPools = 0;
+
+/* try the list with flags support (0.10.0 and later) */
+if ((ret = virConnectListAllStoragePools(ctl-conn,
+ list-pools,
+ flags)) = 0) {
+list-npools = ret;
+goto finished;
+}
+
+/* check if the command is actually supported */
+if (last_error  last_error-code == VIR_ERR_NO_SUPPORT) {
+vshResetLibvirtError();
+goto fallback;
+}
+
+if (last_error  last_error-code ==  VIR_ERR_INVALID_ARG) {
+/* try the new API again but mask non-guaranteed flags */
+unsigned int newflags = flags  (VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE 
|
+ 
VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE);
+vshResetLibvirtError();
+if ((ret = virConnectListAllStoragePools(ctl-conn, list-pools,
+ newflags)) = 0) {
+list-npools = ret;
+goto filter;
+}
+}
+
+/* there was an error during the first or second call */
+vshError(ctl, %s, _(Failed to list pools));
+goto cleanup;
+
+
+fallback:
+/* fall back to old method (0.9.13 and older) */
+vshResetLibvirtError();
+
+/* There is no way to get the pool type */
+if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)) {
+vshError(ctl, %s, _(Filtering using --type is not supported 
+  by this libvirt));
+goto cleanup;
+}
+
+/* Get the number of active pools */
+if (!MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
+MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE)) {
+if ((nActivePools = virConnectNumOfStoragePools(ctl-conn))  0) {
+vshError(ctl, %s, _(Failed to get the number of active pools 
));
+goto cleanup;
+}
+}
+
+/* Get the number of inactive pools */
+if (!MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) ||
+MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE)) {
+if ((nInactivePools = virConnectNumOfDefinedStoragePools(ctl-conn))  
0) {
+vshError(ctl, %s, _(Failed 

[libvirt] [PATCH 06/10] list: Add helper to convert strings separated by ', ' to array

2012-09-04 Thread Osier Yang
tools/virsh.c: New helper function vshStringToArray.
tools/virsh.h: Declare vshStringToArray.
tools/virsh-domain.c: use the helper in cmdUndefine.
---
 tools/virsh-domain.c |   19 ++-
 tools/virsh.c|   44 
 tools/virsh.h|1 +
 3 files changed, 47 insertions(+), 17 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f0ec742..27d5dc1 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2443,23 +2443,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
 
 /* tokenize the string from user and save it's parts into an array */
 if (volumes) {
-/* count the delimiters */
-volume_tok = volumes;
-nvolume_tokens = 1; /* we need at least one member */
-while (*volume_tok) {
-if (*(volume_tok++) == ',')
-nvolume_tokens++;
-}
-
-volume_tokens = vshCalloc(ctl, nvolume_tokens, sizeof(char *));
-
-/* tokenize the input string */
-nvolume_tokens = 0;
-volume_tok = volumes;
-do {
-volume_tokens[nvolume_tokens] = strsep(volume_tok, ,);
-nvolume_tokens++;
-} while (volume_tok);
+if ((nvolume_tokens = vshStringToArray(volumes, volume_tokens))  
0)
+goto cleanup;
 }
 
 if ((nvolumes = virXPathNodeSet(./devices/disk, ctxt,
diff --git a/tools/virsh.c b/tools/virsh.c
index 5cf3237..684f7ca 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -166,6 +166,50 @@ vshPrettyCapacity(unsigned long long val, const char 
**unit)
 }
 }
 
+/*
+ * Convert the strings separated by ',' into array. The caller
+ * must free the returned array after use.
+ *
+ * Returns the length of the filled array on success, or -1
+ * on error.
+ */
+int
+vshStringToArray(char *str,
+ char ***array)
+{
+char *str_tok = NULL;
+unsigned int nstr_tokens = 0;
+char **arr = NULL;
+
+/* tokenize the string from user and save it's parts into an array */
+if (str) {
+nstr_tokens = 1;
+
+/* count the delimiters */
+str_tok = str;
+while (*str_tok) {
+if (*str_tok == ',')
+nstr_tokens++;
+str_tok++;
+}
+
+if (VIR_ALLOC_N(arr, nstr_tokens)  0) {
+virReportOOMError();
+return -1;
+}
+
+/* tokenize the input string */
+nstr_tokens = 0;
+str_tok = str;
+do {
+arr[nstr_tokens] = strsep(str_tok, ,);
+nstr_tokens++;
+} while (str_tok);
+}
+
+*array = arr;
+return nstr_tokens;
+}
 
 virErrorPtr last_error;
 
diff --git a/tools/virsh.h b/tools/virsh.h
index 8923f94..2a9c6a2 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -328,6 +328,7 @@ int vshAskReedit(vshControl *ctl, const char *msg);
 int vshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
   void *opaque);
 double vshPrettyCapacity(unsigned long long val, const char **unit);
+int vshStringToArray(char *str, char ***array);
 
 /* Typedefs, function prototypes for job progress reporting.
  * There are used by some long lingering commands like
-- 
1.7.7.3

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


[libvirt] [PATCH 07/10] virsh: Fix the wrong doc for pool-list

2012-09-04 Thread Osier Yang
The storage pool's management doesn't relate with a domain, it
probably was an intention, but not achieved yet. And the fact
is only active pools are listed by default.
---
 tools/virsh.pod |9 -
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/virsh.pod b/tools/virsh.pod
index a26c420..98ed4b0 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2187,11 +2187,10 @@ Returns basic information about the Ipool object.
 
 =item Bpool-list [I--inactive | I--all] [I--details]
 
-List pool objects known to libvirt.  By default, only pools in use by
-active domains are listed; I--inactive lists just the inactive
-pools, and I--all lists all pools. The I--details option instructs
-virsh to additionally display pool persistence and capacity related
-information where available.
+List pool objects known to libvirt.  By default, only active pools
+are listed; I--inactive lists just the inactive pools, and I--all
+lists all pools. The I--details option instructs virsh to additionally
+display pool persistence and capacity related information where available.
 
 =item Bpool-name Iuuid
 
-- 
1.7.7.3

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


Re: [libvirt] [PATCH] Pass a correct pointer type to localtime_r(3).

2012-09-04 Thread Eric Blake
[adding bug-gnulib]

On 09/04/2012 08:49 AM, Jasper Lievisse Adriaanse wrote:
From b53dc971cc50b5ac397e4568449d25041477c8d6 Mon Sep 17 00:00:00 2001
 From: Jasper Lievisse Adriaanse jas...@humppa.nl
 Date: Tue, 4 Sep 2012 16:47:26 +0200
 Subject: [PATCH] Pass a correct pointer type to localtime_r(3).
 
 Fixes a warning:
 warning: passing argument 1 of 'localtime_r' from incompatible pointer type
 ---
  tools/virsh-domain.c |3 ++-
  tools/virsh.c|3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)

NACK from the libvirt point of view.  tv_sec is required by POSIX to be
of type time_t; so this is a bug in the OpenBSD header, and gnulib
should be working around this bug.

 
 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
 index f0ec742..535779c 100644
 --- a/tools/virsh-domain.c
 +++ b/tools/virsh-domain.c
 @@ -3711,6 +3711,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const 
 char *mime)
  struct tm time_info;
  const char *ext = NULL;
  char *ret = NULL;
 +time_t sec = (time_t) cur_time.tv_sec;
  
  if (!dom) {
  vshError(ctl, %s, _(Invalid domain supplied));
 @@ -3724,7 +3725,7 @@ vshGenFileName(vshControl *ctl, virDomainPtr dom, const 
 char *mime)
  /* add mime type here */
  
  gettimeofday(cur_time, NULL);
 -localtime_r(cur_time.tv_sec, time_info);
 +localtime_r(sec, time_info);
  strftime(timestr, sizeof(timestr), %Y-%m-%d-%H:%M:%S, time_info);
  

 +++ b/tools/virsh.c
 @@ -2189,6 +2189,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const 
 char *msg_format,
  const char *lvl = ;
  struct timeval stTimeval;
  struct tm *stTm;
 +time_t sec = stTimeval.tv_sec;
  
  if (ctl-log_fd == -1)
  return;
 @@ -2199,7 +2200,7 @@ vshOutputLogFile(vshControl *ctl, int log_level, const 
 char *msg_format,
   * [.MM.DD HH:MM:SS SIGNATURE PID] LOG_LEVEL message
  */
  gettimeofday(stTimeval, NULL);
 -stTm = localtime(stTimeval.tv_sec);
 +stTm = localtime(sec);

Even grosser - why is virsh using localtime() instead of localtime_r()?

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



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

[libvirt] [PATCH 10/10] python: Expose virStorageListAllStoragePools to python binding

2012-09-04 Thread Osier Yang
The implementation is done manually as the generator does not support
wrapping lists of C pointers into Python objects.

python/libvirt-override-api.xml: Document
python/libvirt-override-virConnect.py: Add listAllStoragePools
python/libvirt-override.c: Implementation for the wrapper.
---
 python/libvirt-override-api.xml   |6 
 python/libvirt-override-virConnect.py |   12 
 python/libvirt-override.c |   47 +
 3 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 67ef36e..d16755c 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -306,6 +306,12 @@
   arg name='conn' type='virConnectPtr' info='pointer to the hypervisor 
connection'/
   return type='str *' info='the list of Names of None in case of error'/
 /function
+function name='virConnectListAllStoragePools' file='python'
+  inforeturns list of all storage pools/info
+  arg name='conn' type='virConnectPtr' info='pointer to the hypervisor 
connection'/
+  arg name='flags' type='unsigned int' info='optional flags'/
+  return type='pool *' info='the list of pools or None in case of error'/
+/function
 function name='virStoragePoolListVolumes' file='python'
   infolist the storage volumes, stores the pointers to the names in 
@names/info
   arg name='pool' type='virStoragePoolPtr' info='pointer to the storage 
pool'/
diff --git a/python/libvirt-override-virConnect.py 
b/python/libvirt-override-virConnect.py
index 50177ab..87a737f 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -206,3 +206,15 @@
 retlist.append(virDomain(self, _obj=domptr))
 
 return retlist
+
+def listAllStoragePools(self, flags):
+Returns a list of storage pool objects
+ret = libvirtmod.virConnectListAllStoragePools(self._o, flags)
+if ret is None:
+raise libvirtError(virConnectListAllStoragePools() failed, 
conn=self)
+
+retlist = list()
+for poolptr in ret:
+retlist.append(virStoragePool(self, _obj=poolptr))
+
+return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 65e8c69..1e3ad89 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -2983,6 +2983,52 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self 
ATTRIBUTE_UNUSED,
 return py_retval;
 }
 
+static PyObject *
+libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
+  PyObject *args)
+{
+PyObject *pyobj_conn;
+PyObject *py_retval = NULL;
+PyObject *tmp = NULL;
+virConnectPtr conn;
+virStoragePoolPtr *pools = NULL;
+int c_retval = 0;
+int i;
+unsigned int flags;
+
+if (!PyArg_ParseTuple(args, (char *)Oi:virConnectListAllStoragePools,
+  pyobj_conn, flags))
+return NULL;
+conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virConnectListAllStoragePools(conn, pools, flags);
+LIBVIRT_END_ALLOW_THREADS;
+if (c_retval  0)
+return VIR_PY_NONE;
+
+if (!(py_retval = PyList_New(c_retval)))
+goto cleanup;
+
+for (i = 0; i  c_retval; i++) {
+if (!(tmp = libvirt_virStoragePoolPtrWrap(pools[i])) ||
+PyList_SetItem(py_retval, i, tmp)  0) {
+Py_XDECREF(tmp);
+Py_DECREF(py_retval);
+py_retval = NULL;
+goto cleanup;
+}
+/* python steals the pointer */
+pools[i] = NULL;
+}
+
+cleanup:
+for (i = 0; i  c_retval; i++)
+if (pools[i])
+virStoragePoolFree(pools[i]);
+VIR_FREE(pools);
+return py_retval;
+}
 
 static PyObject *
 libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
@@ -5878,6 +5924,7 @@ static PyMethodDef libvirtMethods[] = {
 {(char *) virDomainGetVcpuPinInfo, libvirt_virDomainGetVcpuPinInfo, 
METH_VARARGS, NULL},
 {(char *) virConnectListStoragePools, 
libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
 {(char *) virConnectListDefinedStoragePools, 
libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
+{(char *) virConnectListAllStoragePools, 
libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
 {(char *) virStoragePoolGetAutostart, 
libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
 {(char *) virStoragePoolListVolumes, libvirt_virStoragePoolListVolumes, 
METH_VARARGS, NULL},
 {(char *) virStoragePoolGetInfo, libvirt_virStoragePoolGetInfo, 
METH_VARARGS, NULL},
-- 
1.7.7.3

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


Re: [libvirt] [PATCH] Don't link with -lrt on OpenBSD

2012-09-04 Thread Eric Blake
On 09/04/2012 09:04 AM, Jasper Lievisse Adriaanse wrote:
From bdf3bce37531ec346474bc5c4f37a5d2985d1d35 Mon Sep 17 00:00:00 2001
 From: Jasper Lievisse Adriaanse jas...@humppa.nl
 Date: Tue, 4 Sep 2012 17:03:43 +0200
 Subject: [PATCH] Don't link with -lrt on OpenBSD
 
 ---
  configure.ac |8 +++-
  1 files changed, 7 insertions(+), 1 deletions(-)
 
 diff --git a/configure.ac b/configure.ac
 index e0d00d5..54d049d 100644
 --- a/configure.ac
 +++ b/configure.ac
 @@ -188,7 +188,13 @@ RT_LIBS=
  LIBS=$LIBS $LIB_PTHREAD -lrt
  AC_CHECK_FUNC([clock_gettime],[
   AC_DEFINE([HAVE_CLOCK_GETTIME],[],[Defined if clock_gettime() exists in 
 librt.so])
 - RT_LIBS=-lrt
 + case $host in
 +   *-*-openbsd*)
 + ;;
 +   *)
 + RT_LIBS=-lrt
 + ;;
 + esac

I'd much rather write this as a probe to see if linking with -rt makes a
difference, and only add it when it matters, than trying to blindly add
it (the pre-patch version) or to blindly exclude it for some platforms
(the post-patch version).  I also wonder if gnulib has some help on this
front.  NACK to this version while I investigate.

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



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

Re: [libvirt] Fwd: Compiling a simple code which include libvirt

2012-09-04 Thread Rahul Bansal
On 3 September 2012 20:05, Eric Blake ebl...@redhat.com wrote:

 On 09/03/2012 06:39 AM, Rahul Bansal wrote:

 [Please don't top-post on technical lists.]

  I ran 'sudo make install' in /path/to/libvirt. But same error is coming.
  Maybe following will be helpful:
  - I extracted the libvirt.0.10.1 in ~/Downloads
  - And I am running the code in ~/Downloads/libvirt-0.10.1
  - I ran 'sudo make install' in the above directory.

 And what ./configure arguments did you use?  If you didn't supply
 anything in particular, then this installed your copy of libvirt into
 /usr/local/, and depending on your setup, your compiler might not be
 looking into that directory by default.

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


I have been finally able to compile my libvirt code. Actually I reinstalled
libvirt with some change in autobuild.sh
so that it installed libraries in /usr/local.
Thanks all for your valuable help and suggestions.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] Use sockpeercred on OpenBSD.

2012-09-04 Thread Eric Blake
On 09/04/2012 09:00 AM, Jasper Lievisse Adriaanse wrote:
From 0f352c0577f76a64924636a8c9ba72de5862b6d6 Mon Sep 17 00:00:00 2001
 From: Jasper Lievisse Adriaanse jas...@humppa.nl
 Date: Tue, 4 Sep 2012 16:59:55 +0200
 Subject: [PATCH] Use sockpeercred on OpenBSD.
 
 ---
  src/rpc/virnetsocket.c |4 
  1 files changed, 4 insertions(+), 0 deletions(-)

I _hate_ OS-specific #ifdefs.  I'd much rather see a configure-time
check to determine whether 'struct ucred', 'struct sockpeercred', or
both, exist, and then base the decision on which struct to use based on
the result of that configure-time check.

 
 diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
 index 5a48300..27ead13 100644
 --- a/src/rpc/virnetsocket.c
 +++ b/src/rpc/virnetsocket.c
 @@ -988,7 +988,11 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
  gid_t *gid,
  pid_t *pid)
  {
 +#if defined (__OpenBSD__)
 +struct sockpeercred cr;
 +#else
  struct ucred cr;
 +#endif
  socklen_t cr_len = sizeof(cr);
  virMutexLock(sock-lock);

Give me some time to try to help turn this into a proper configure-time
check.

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



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

[libvirt] [PATCH 6/6] list: Expose virStoragePoolListAllVolumes to Python binding

2012-09-04 Thread Osier Yang
The implementation is done manually as the generator does not support
wrapping lists of C pointers into Python objects.

python/libvirt-override-api.xml: Document

python/libvirt-override-virStoragePool.py:
  * New file, includes implementation of listAllVolumes.

python/libvirt-override.c: Implementation for the wrapper.
---
 python/libvirt-override-api.xml   |8 -
 python/libvirt-override-virStoragePool.py |   11 ++
 python/libvirt-override.c |   50 +
 3 files changed, 68 insertions(+), 1 deletions(-)
 create mode 100644 python/libvirt-override-virStoragePool.py

diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index d16755c..8a228fb 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -315,7 +315,13 @@
 function name='virStoragePoolListVolumes' file='python'
   infolist the storage volumes, stores the pointers to the names in 
@names/info
   arg name='pool' type='virStoragePoolPtr' info='pointer to the storage 
pool'/
-  return type='str *' info='the list of Names of None in case of error'/
+  return type='str *' info='the list of Names or None in case of error'/
+/function
+function name='virStoragePoolListAllVolumes' file='python'
+  inforeturn list of storage volume objects/info
+  arg name='pool' type='virStoragePoolPtr' info='pointer to the storage 
pool'/
+  arg name='flags' type='unsigned int' info='optional flags'/
+  return type='volume *' info='the list of volumes or None in case of 
error'/
 /function
 function name='virStoragePoolGetInfo' file='python'
   infoExtract information about a storage pool. Note that if the 
connection used to get the domain is limited only a partial set of the 
information can be extracted./info
diff --git a/python/libvirt-override-virStoragePool.py 
b/python/libvirt-override-virStoragePool.py
new file mode 100644
index 000..ffe160c
--- /dev/null
+++ b/python/libvirt-override-virStoragePool.py
@@ -0,0 +1,11 @@
+def listAllVolumes(self, flags):
+List all storage volumes and returns a list of storage volume 
objects
+ret = libvirtmod.virStoragePoolListAllVolumes(self._o, flags)
+if ret is None:
+raise libvirtError(virStoragePoolListAllVolumes() failed, 
conn=self)
+
+retlist = list()
+for volptr in ret:
+retlist.append(virStorageVol(self, _obj=volptr))
+
+return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 1e3ad89..8b402b0 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3083,6 +3083,55 @@ libvirt_virStoragePoolListVolumes(PyObject *self 
ATTRIBUTE_UNUSED,
 }
 
 static PyObject *
+libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+PyObject *py_retval = NULL;
+PyObject *tmp = NULL;
+virStoragePoolPtr pool;
+virStorageVolPtr *vols = NULL;
+int c_retval = 0;
+int i;
+unsigned int flags;
+PyObject *pyobj_pool;
+
+if (!PyArg_ParseTuple(args, (char *)Oi:virStoragePoolListAllVolumes,
+  pyobj_pool, flags))
+return NULL;
+
+pool = (virStoragePoolPtr) PyvirStoragePool_Get(pyobj_pool);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virStoragePoolListAllVolumes(pool, vols, flags);
+LIBVIRT_END_ALLOW_THREADS;
+if (c_retval  0)
+return VIR_PY_NONE;
+
+if (!(py_retval = PyList_New(c_retval)))
+goto cleanup;
+
+for (i = 0; i  c_retval; i++) {
+if (!(tmp = libvirt_virStorageVolPtrWrap(vols[i])) ||
+PyList_SetItem(py_retval, i, tmp)  0) {
+Py_XDECREF(tmp);
+Py_DECREF(py_retval);
+py_retval = NULL;
+goto cleanup;
+}
+/* python steals the pointer */
+vols[i] = NULL;
+}
+
+cleanup:
+for (i = 0; i  c_retval; i++)
+if (vols[i])
+virStorageVolFree(vols[i]);
+VIR_FREE(vols);
+return py_retval;
+}
+
+
+static PyObject *
 libvirt_virStoragePoolGetAutostart(PyObject *self ATTRIBUTE_UNUSED, PyObject 
*args) {
 PyObject *py_retval;
 int c_retval, autostart;
@@ -5927,6 +5976,7 @@ static PyMethodDef libvirtMethods[] = {
 {(char *) virConnectListAllStoragePools, 
libvirt_virConnectListAllStoragePools, METH_VARARGS, NULL},
 {(char *) virStoragePoolGetAutostart, 
libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
 {(char *) virStoragePoolListVolumes, libvirt_virStoragePoolListVolumes, 
METH_VARARGS, NULL},
+{(char *) virStoragePoolListAllVolumes, 
libvirt_virStoragePoolListAllVolumes, METH_VARARGS, NULL},
 {(char *) virStoragePoolGetInfo, libvirt_virStoragePoolGetInfo, 
METH_VARARGS, NULL},
 {(char *) virStorageVolGetInfo, libvirt_virStorageVolGetInfo, 
METH_VARARGS, NULL},
 {(char *) virStoragePoolGetUUID, 

[libvirt] [PATCH 2/6] list: Implemente RPC calls for virStoragePoolListAllVolumes

2012-09-04 Thread Osier Yang
The RPC generator doesn't returning support list of object, this
patch do the work manually.

  * daemon/remote.c:
Implemente the server side handler remoteDispatchStoragePoolListAllVolumes

  * src/remote/remote_driver.c:
Add remote driver handler remoteStoragePoolListAllVolumes

  * src/remote/remote_protocol.x:
New RPC procedure REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES and
structs to represent the args and ret for it.

  * src/remote_protocol-structs: Likewise.
---
 daemon/remote.c  |   58 
 src/remote/remote_driver.c   |   66 ++
 src/remote/remote_protocol.x |   14 -
 src/remote_protocol-structs  |   13 
 4 files changed, 150 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 9056439..8208c71 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4153,6 +4153,64 @@ cleanup:
 return rv;
 }
 
+static int
+remoteDispatchStoragePoolListAllVolumes(virNetServerPtr server 
ATTRIBUTE_UNUSED,
+virNetServerClientPtr client,
+virNetMessagePtr msg ATTRIBUTE_UNUSED,
+virNetMessageErrorPtr rerr,
+
remote_storage_pool_list_all_volumes_args *args,
+
remote_storage_pool_list_all_volumes_ret *ret)
+{
+virStorageVolPtr *vols = NULL;
+virStoragePoolPtr pool = NULL;
+int nvols = 0;
+int i;
+int rv = -1;
+struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+if (!priv-conn) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s, _(connection not open));
+goto cleanup;
+}
+
+if (!(pool = get_nonnull_storage_pool(priv-conn, args-pool)))
+goto cleanup;
+
+if ((nvols = virStoragePoolListAllVolumes(pool,
+  args-need_results ? vols : 
NULL,
+  args-flags))  0)
+goto cleanup;
+
+if (vols  nvols) {
+if (VIR_ALLOC_N(ret-vols.vols_val, nvols)  0) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret-vols.vols_len = nvols;
+
+for (i = 0; i  nvols; i++)
+make_nonnull_storage_vol(ret-vols.vols_val + i, vols[i]);
+} else {
+ret-vols.vols_len = 0;
+ret-vols.vols_val = NULL;
+}
+
+ret-ret = nvols;
+
+rv = 0;
+
+cleanup:
+if (rv  0)
+virNetMessageSaveError(rerr);
+if (vols) {
+for (i = 0; i  nvols; i++)
+virStorageVolFree(vols[i]);
+VIR_FREE(vols);
+}
+return rv;
+}
+
 /*- Helpers. -*/
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index c1f9044..8d4420e 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2920,6 +2920,71 @@ done:
 return rv;
 }
 
+static int
+remoteStoragePoolListAllVolumes(virStoragePoolPtr pool,
+virStorageVolPtr **vols,
+unsigned int flags)
+{
+int rv = -1;
+int i;
+virStorageVolPtr *tmp_vols = NULL;
+remote_storage_pool_list_all_volumes_args args;
+remote_storage_pool_list_all_volumes_ret ret;
+
+struct private_data *priv = pool-conn-privateData;
+
+remoteDriverLock(priv);
+
+make_nonnull_storage_pool(args.pool, pool);
+args.need_results = !!vols;
+args.flags = flags;
+
+memset(ret, 0, sizeof(ret));
+if (call(pool-conn,
+ priv,
+ 0,
+ REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES,
+ (xdrproc_t) xdr_remote_storage_pool_list_all_volumes_args,
+ (char *) args,
+ (xdrproc_t) xdr_remote_storage_pool_list_all_volumes_ret,
+ (char *) ret) == -1)
+goto done;
+
+if (vols) {
+if (VIR_ALLOC_N(tmp_vols, ret.vols.vols_len + 1)  0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (i = 0; i  ret.vols.vols_len; i++) {
+tmp_vols[i] = get_nonnull_storage_vol(pool-conn, 
ret.vols.vols_val[i]);
+if (!tmp_vols[i]) {
+virReportOOMError();
+goto cleanup;
+}
+}
+*vols = tmp_vols;
+tmp_vols = NULL;
+}
+
+rv = ret.ret;
+
+cleanup:
+if (tmp_vols) {
+for (i = 0; i  ret.vols.vols_len; i++)
+if (tmp_vols[i])
+virStorageVolFree(tmp_vols[i]);
+VIR_FREE(tmp_vols);
+}
+
+xdr_free((xdrproc_t) xdr_remote_storage_pool_list_all_volumes_ret, (char 
*) ret);
+
+done:
+remoteDriverUnlock(priv);
+return rv;
+}
+
+
 /*--*/
 
 static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
@@ -5694,6 +5759,7 

[libvirt] [PATCH 4/6] list: Implement virStoragePoolListAllVolumes for test driver

2012-09-04 Thread Osier Yang
src/test/test_driver.c: Implement poolListAllVolumes.
---
 src/test/test_driver.c |   67 
 1 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 1504251..8d93129 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4555,6 +4555,72 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
 return -1;
 }
 
+static int
+testStoragePoolListAllVolumes(virStoragePoolPtr obj,
+  virStorageVolPtr **vols,
+  unsigned int flags) {
+testConnPtr privconn = obj-conn-privateData;
+virStoragePoolObjPtr pool;
+int i;
+virStorageVolPtr *tmp_vols = NULL;
+virStorageVolPtr vol = NULL;
+int nvols = 0;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+testDriverLock(privconn);
+pool = virStoragePoolObjFindByUUID(privconn-pools, obj-uuid);
+testDriverUnlock(privconn);
+
+if (!pool) {
+virReportError(VIR_ERR_NO_STORAGE_POOL, %s,
+   _(no storage pool with matching uuid));
+goto cleanup;
+}
+
+if (!virStoragePoolObjIsActive(pool)) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(storage pool is not active));
+goto cleanup;
+}
+
+ /* Just returns the volumes count */
+if (!vols) {
+ret = pool-volumes.count;
+goto cleanup;
+}
+
+if (VIR_ALLOC_N(tmp_vols, pool-volumes.count + 1)  0) {
+ virReportOOMError();
+ goto cleanup;
+}
+
+for (i = 0 ; i  pool-volumes.count; i++) {
+if (!(vol = virGetStorageVol(obj-conn, pool-def-name,
+ pool-volumes.objs[i]-name,
+ pool-volumes.objs[i]-key)))
+goto cleanup;
+tmp_vols[nvols++] = vol;
+}
+
+*vols = tmp_vols;
+tmp_vols = NULL;
+ret = nvols;
+
+ cleanup:
+if (tmp_vols) {
+for (i = 0; i  nvols; i++) {
+if (tmp_vols[i])
+virStorageVolFree(tmp_vols[i]);
+}
+}
+
+if (pool)
+virStoragePoolObjUnlock(pool);
+
+return ret;
+}
 
 static virStorageVolPtr
 testStorageVolumeLookupByName(virStoragePoolPtr pool,
@@ -5697,6 +5763,7 @@ static virStorageDriver testStorageDriver = {
 .poolSetAutostart = testStoragePoolSetAutostart, /* 0.5.0 */
 .poolNumOfVolumes = testStoragePoolNumVolumes, /* 0.5.0 */
 .poolListVolumes = testStoragePoolListVolumes, /* 0.5.0 */
+.poolListAllVolumes = testStoragePoolListAllVolumes, /* 0.10.0 */
 
 .volLookupByName = testStorageVolumeLookupByName, /* 0.5.0 */
 .volLookupByKey = testStorageVolumeLookupByKey, /* 0.5.0 */
-- 
1.7.7.3

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


[libvirt] [PATCH 3/6] list: Implement virStoragePoolListAllVolumes for storage driver

2012-09-04 Thread Osier Yang
src/storage/storage_driver.c: Implement poolListAllVolumes.
---
 src/storage/storage_driver.c |   67 ++
 1 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 4f99eb9..4f83348 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1153,6 +1153,72 @@ storagePoolListVolumes(virStoragePoolPtr obj,
 return -1;
 }
 
+static int
+storagePoolListAllVolumes(virStoragePoolPtr pool,
+  virStorageVolPtr **vols,
+  unsigned int flags) {
+virStorageDriverStatePtr driver = pool-conn-storagePrivateData;
+virStoragePoolObjPtr obj;
+int i;
+virStorageVolPtr *tmp_vols = NULL;
+virStorageVolPtr vol = NULL;
+int nvols = 0;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+storageDriverLock(driver);
+obj = virStoragePoolObjFindByUUID(driver-pools, pool-uuid);
+storageDriverUnlock(driver);
+
+if (!obj) {
+virReportError(VIR_ERR_NO_STORAGE_POOL, %s,
+   _(no storage pool with matching uuid));
+goto cleanup;
+}
+
+if (!virStoragePoolObjIsActive(obj)) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(storage pool is not active));
+goto cleanup;
+}
+
+ /* Just returns the volumes count */
+if (!vols) {
+ret = obj-volumes.count;
+goto cleanup;
+}
+
+if (VIR_ALLOC_N(tmp_vols, obj-volumes.count + 1)  0) {
+ virReportOOMError();
+ goto cleanup;
+}
+
+for (i = 0 ; i  obj-volumes.count; i++) {
+if (!(vol = virGetStorageVol(pool-conn, obj-def-name,
+ obj-volumes.objs[i]-name,
+ obj-volumes.objs[i]-key)))
+goto cleanup;
+tmp_vols[nvols++] = vol;
+}
+
+*vols = tmp_vols;
+tmp_vols = NULL;
+ret = nvols;
+
+ cleanup:
+if (tmp_vols) {
+for (i = 0; i  nvols; i++) {
+if (tmp_vols[i])
+virStorageVolFree(tmp_vols[i]);
+}
+}
+
+if (obj)
+virStoragePoolObjUnlock(obj);
+
+return ret;
+}
 
 static virStorageVolPtr
 storageVolumeLookupByName(virStoragePoolPtr obj,
@@ -2329,6 +2395,7 @@ static virStorageDriver storageDriver = {
 .poolSetAutostart = storagePoolSetAutostart, /* 0.4.0 */
 .poolNumOfVolumes = storagePoolNumVolumes, /* 0.4.0 */
 .poolListVolumes = storagePoolListVolumes, /* 0.4.0 */
+.poolListAllVolumes = storagePoolListAllVolumes, /* 0.10.0 */
 
 .volLookupByName = storageVolumeLookupByName, /* 0.4.0 */
 .volLookupByKey = storageVolumeLookupByKey, /* 0.4.0 */
-- 
1.7.7.3

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


[libvirt] [PATCH 5/6] list: Use virStoragePoolListAllVolumes in virsh

2012-09-04 Thread Osier Yang
tools/virsh-volume.c:
  * vshStorageVolSorter to sort storage vols by name

  * vshStorageVolumeListFree to free the volume objects list

  * vshStorageVolumeListCollect to collect the volume objects, trying
to use new API first, fall back to older APIs if it's not supported.
---
 tools/virsh-volume.c |  197 ++
 1 files changed, 150 insertions(+), 47 deletions(-)

diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 6ab271e..ec0b5b0 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -966,6 +966,133 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
 return ret;
 }
 
+static int
+vshStorageVolSorter(const void *a, const void *b)
+{
+virStorageVolPtr *va = (virStorageVolPtr *) a;
+virStorageVolPtr *vb = (virStorageVolPtr *) b;
+
+if (*va  !*vb)
+return -1;
+
+if (!*va)
+return *vb != NULL;
+
+return vshStrcasecmp(virStorageVolGetName(*va),
+  virStorageVolGetName(*vb));
+}
+
+struct vshStorageVolList {
+virStorageVolPtr *vols;
+size_t nvols;
+};
+typedef struct vshStorageVolList *vshStorageVolListPtr;
+
+static void
+vshStorageVolListFree(vshStorageVolListPtr list)
+{
+int i;
+
+if (list  list-vols) {
+for (i = 0; i  list-nvols; i++) {
+if (list-vols[i])
+virStorageVolFree(list-vols[i]);
+}
+VIR_FREE(list-vols);
+}
+VIR_FREE(list);
+}
+
+static vshStorageVolListPtr
+vshStorageVolListCollect(vshControl *ctl,
+ virStoragePoolPtr pool,
+ unsigned int flags)
+{
+vshStorageVolListPtr list = vshMalloc(ctl, sizeof(*list));
+int i;
+char **names = NULL;
+virStorageVolPtr vol = NULL;
+bool success = false;
+size_t deleted = 0;
+int nvols = 0;
+int ret = -1;
+
+/* try the list with flags support (0.10.0 and later) */
+if ((ret = virStoragePoolListAllVolumes(pool,
+list-vols,
+flags)) = 0) {
+list-nvols = ret;
+goto finished;
+}
+
+/* check if the command is actually supported */
+if (last_error  last_error-code == VIR_ERR_NO_SUPPORT) {
+vshResetLibvirtError();
+goto fallback;
+}
+
+/* there was an error during the call */
+vshError(ctl, %s, _(Failed to list volumes));
+goto cleanup;
+
+fallback:
+/* fall back to old method (0.9.13 and older) */
+vshResetLibvirtError();
+
+/* Determine the number of volumes in the pool */
+if ((nvols = virStoragePoolNumOfVolumes(pool))  0) {
+vshError(ctl, %s, _(Failed to list storage volumes));
+goto cleanup;
+}
+
+if (nvols == 0) {
+success = true;
+return list;
+}
+
+/* Retrieve the list of volume names in the pool */
+names = vshCalloc(ctl, nvols, sizeof(*names));
+if ((nvols = virStoragePoolListVolumes(pool, names, nvols))  0) {
+vshError(ctl, %s, _(Failed to list storage volumes));
+goto cleanup;
+}
+
+list-vols = vshMalloc(ctl, sizeof(virStorageVolPtr) * (nvols));
+list-nvols = 0;
+
+/* get the vols */
+for (i = 0; i  nvols; i++) {
+if (!(vol = virStorageVolLookupByName(pool, names[i])))
+continue;
+list-vols[list-nvols++] = vol;
+}
+
+/* truncate the list for not found vols */
+deleted = nvols - list-nvols;
+
+finished:
+/* sort the list */
+if (list-vols  list-nvols)
+qsort(list-vols, list-nvols, sizeof(*list-vols), 
vshStorageVolSorter);
+
+if (deleted)
+VIR_SHRINK_N(list-vols, list-nvols, deleted);
+
+success = true;
+
+cleanup:
+for (i = 0; i  nvols; i++)
+VIR_FREE(names[i]);
+VIR_FREE(names);
+
+if (!success) {
+vshStorageVolListFree(list);
+list = NULL;
+}
+
+return list;
+}
+
 /*
  * vol-list command
  */
@@ -986,14 +1113,13 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 {
 virStorageVolInfo volumeInfo;
 virStoragePoolPtr pool;
-char **activeNames = NULL;
 char *outputStr = NULL;
 const char *unit;
 double val;
 bool details = vshCommandOptBool(cmd, details);
-int numVolumes = 0, i;
+int i;
 int ret;
-bool functionReturn;
+bool functionReturn = false;
 int stringLength = 0;
 size_t allocStrLength = 0, capStrLength = 0;
 size_t nameStrLength = 0, pathStrLength = 0;
@@ -1005,43 +1131,22 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 char *type;
 };
 struct volInfoText *volInfoTexts = NULL;
+vshStorageVolListPtr list = NULL;
 
 /* Look up the pool information given to us by the user */
 if (!(pool = vshCommandOptPool(ctl, cmd, pool, NULL)))
 return false;
 
-/* Determine the number of volumes in the pool */
-numVolumes = virStoragePoolNumOfVolumes(pool);
-
-if 

[libvirt] [PATCH 0/6 v4] Atomic API to list storage volumes

2012-09-04 Thread Osier Yang
v3 - v4:
  * Just rebase on the top, and split each API from the big set.

Osier Yang (6):
  list: Define new API virStoragePoolListAllVolumes
  list: Implemente RPC calls for virStoragePoolListAllVolumes
  list: Implement virStoragePoolListAllVolumes for storage driver
  list: Implement virStoragePoolListAllVolumes for test driver
  list: Use virStoragePoolListAllVolumes in virsh
  list: Expose virStoragePoolListAllVolumes to Python binding

 daemon/remote.c   |   58 +
 include/libvirt/libvirt.h.in  |3 +
 python/generator.py   |1 +
 python/libvirt-override-api.xml   |8 +-
 python/libvirt-override-virStoragePool.py |   11 ++
 python/libvirt-override.c |   50 
 src/driver.h  |6 +-
 src/libvirt.c |   50 
 src/libvirt_public.syms   |1 +
 src/remote/remote_driver.c|   66 ++
 src/remote/remote_protocol.x  |   14 ++-
 src/remote_protocol-structs   |   13 ++
 src/storage/storage_driver.c  |   67 ++
 src/test/test_driver.c|   67 ++
 tools/virsh-volume.c  |  197 ++---
 15 files changed, 562 insertions(+), 50 deletions(-)
 create mode 100644 python/libvirt-override-virStoragePool.py

-- 
1.7.7.3

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


[libvirt] [PATCH 1/6] list: Define new API virStoragePoolListAllVolumes

2012-09-04 Thread Osier Yang
Simply returns the storage volume objects. No supported filter
flags.

include/libvirt/libvirt.h.in: Declare the API
python/generator.py: Skip the function for generating. virStoragePool.py
 will be added in later patch.
src/driver.h: virDrvStoragePoolListVolumesFlags
src/libvirt.c: Implementation for the API.
src/libvirt_public.syms: Export the symbol to public
---
 include/libvirt/libvirt.h.in |3 ++
 python/generator.py  |1 +
 src/driver.h |6 -
 src/libvirt.c|   50 ++
 src/libvirt_public.syms  |1 +
 5 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 0c52271..58cd6ff 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2654,6 +2654,9 @@ int virStoragePoolNumOfVolumes  
(virStoragePoolPtr pool)
 int virStoragePoolListVolumes   (virStoragePoolPtr 
pool,
  char **const names,
  int maxnames);
+int virStoragePoolListAllVolumes(virStoragePoolPtr 
pool,
+ virStorageVolPtr 
**vols,
+ unsigned int flags);
 
 virConnectPtr   virStorageVolGetConnect (virStorageVolPtr vol);
 
diff --git a/python/generator.py b/python/generator.py
index 261efe0..276b4ff 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -461,6 +461,7 @@ skip_function = (
 'virDomainListAllSnapshots', # overridden in virDomain.py
 'virDomainSnapshotListAllChildren', # overridden in virDomainSnapshot.py
 'virConnectListAllStoragePools', # overridden in virConnect.py
+'virStoragePoolListAllVolumes', # overridden in virStoragePool.py
 
 'virStreamRecvAll', # Pure python libvirt-override-virStream.py
 'virStreamSendAll', # Pure python libvirt-override-virStream.py
diff --git a/src/driver.h b/src/driver.h
index 342f6b5..1bdfd29 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1311,7 +1311,10 @@ typedef int
 (*virDrvStoragePoolListVolumes)  (virStoragePoolPtr pool,
   char **const names,
   int maxnames);
-
+typedef int
+(*virDrvStoragePoolListAllVolumes)   (virStoragePoolPtr pool,
+  virStorageVolPtr **vols,
+  unsigned int flags);
 
 typedef virStorageVolPtr
 (*virDrvStorageVolLookupByName)  (virStoragePoolPtr pool,
@@ -1419,6 +1422,7 @@ struct _virStorageDriver {
 virDrvStoragePoolSetAutostart   poolSetAutostart;
 virDrvStoragePoolNumOfVolumes   poolNumOfVolumes;
 virDrvStoragePoolListVolumespoolListVolumes;
+virDrvStoragePoolListAllVolumes poolListAllVolumes;
 
 virDrvStorageVolLookupByNamevolLookupByName;
 virDrvStorageVolLookupByKey volLookupByKey;
diff --git a/src/libvirt.c b/src/libvirt.c
index 4e4f96b..700dbef 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -12596,6 +12596,54 @@ error:
 return -1;
 }
 
+/**
+ * virStoragePoolListAllVolumes:
+ * @pool: Pointer to storage pool
+ * @vols: Pointer to a variable to store the array containing storage volume
+ *objects or NULL if the list is not required (just returns number
+ *of volumes).
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Collect the list of storage volumes, and allocate an array to store those
+ * objects.
+ *
+ * Returns the number of storage volumes found or -1 and sets @vols to
+ * NULL in case of error.  On success, the array stored into @vols is
+ * guaranteed to have an extra allocated element set to NULL but not included
+ * in the return count, to make iteration easier.  The caller is responsible
+ * for calling virStorageVolFree() on each array element, then calling
+ * free() on @vols.
+ */
+int
+virStoragePoolListAllVolumes(virStoragePoolPtr pool,
+ virStorageVolPtr **vols,
+ unsigned int flags)
+{
+VIR_DEBUG(pool=%p, vols=%p, flags=%x, pool, vols, flags);
+
+virResetLastError();
+
+if (!VIR_IS_STORAGE_POOL(pool)) {
+virLibConnError(VIR_ERR_INVALID_STORAGE_POOL, __FUNCTION__);
+virDispatchError(NULL);
+return -1;
+}
+
+if (pool-conn-storageDriver 
+pool-conn-storageDriver-poolListAllVolumes) {
+int ret;
+ret = pool-conn-storageDriver-poolListAllVolumes(pool, vols, flags);
+if (ret  0)
+goto error;
+return ret;
+}
+
+virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+virDispatchError(pool-conn);
+

Re: [libvirt] [PATCH] qemu: Do not require auth scheme in graphics events

2012-09-04 Thread Eric Blake
On 09/04/2012 09:03 AM, Jiri Denemark wrote:
 Only VNC_{{DIS,}CONNECTED,INITIALIZED} and SPICE_INITIALIZED events are
 documented to support server/auth field and even there it is marked as
 optional. Emit  auth scheme in case QEMU didn't send it.
 ---
  src/qemu/qemu_monitor_json.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

ACK.

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



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

[libvirt] [PATCH 1/7] list: Define new API virConnectListAllNetworks

2012-09-04 Thread Osier Yang
This is to list the network objects, supported filtering flags
are: active|inactive, persistent|transient, autostart|no-autostart.

include/libvirt/libvirt.h.in: Declare enum virConnectListAllNetworkFlags
  and virConnectListAllNetworks.
python/generator.py: Skip auto-generating
src/driver.h: (virDrvConnectListAllNetworks)
src/libvirt.c: Implement the public API
src/libvirt_public.syms: Export the symbol to public
---
 include/libvirt/libvirt.h.in |   20 ++
 python/generator.py  |1 +
 src/driver.h |5 ++
 src/libvirt.c|   86 +-
 src/libvirt_public.syms  |1 +
 5 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 58cd6ff..50d865c 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2279,6 +2279,26 @@ int virConnectNumOfDefinedNetworks  
(virConnectPtr conn);
 int virConnectListDefinedNetworks   (virConnectPtr conn,
  char **const names,
  int maxnames);
+/*
+ * virConnectListAllNetworks:
+ *
+ * Flags used to filter the returned networks. Flags in each group
+ * are exclusive attributes of a network.
+ */
+typedef enum {
+VIR_CONNECT_LIST_NETWORKS_INACTIVE  = 1  0,
+VIR_CONNECT_LIST_NETWORKS_ACTIVE= 1  1,
+
+VIR_CONNECT_LIST_NETWORKS_PERSISTENT= 1  2,
+VIR_CONNECT_LIST_NETWORKS_TRANSIENT = 1  3,
+
+VIR_CONNECT_LIST_NETWORKS_AUTOSTART = 1  4,
+VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART  = 1  5,
+} virConnectListAllNetworksFlags;
+
+int virConnectListAllNetworks   (virConnectPtr conn,
+ virNetworkPtr **nets,
+ unsigned int flags);
 
 /*
  * Lookup network by name or uuid
diff --git a/python/generator.py b/python/generator.py
index 276b4ff..a9a401b 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -462,6 +462,7 @@ skip_function = (
 'virDomainSnapshotListAllChildren', # overridden in virDomainSnapshot.py
 'virConnectListAllStoragePools', # overridden in virConnect.py
 'virStoragePoolListAllVolumes', # overridden in virStoragePool.py
+'virConnectListAllNetworks', # overridden in virConnect.py
 
 'virStreamRecvAll', # Pure python libvirt-override-virStream.py
 'virStreamSendAll', # Pure python libvirt-override-virStream.py
diff --git a/src/driver.h b/src/driver.h
index 1bdfd29..534da05 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -1082,6 +1082,10 @@ typedef int
 (*virDrvListDefinedNetworks)(virConnectPtr conn,
  char **const names,
  int maxnames);
+typedef int
+(*virDrvListAllNetworks)(virConnectPtr conn,
+ virNetworkPtr **nets,
+ unsigned int flags);
 typedef virNetworkPtr
 (*virDrvNetworkLookupByUUID)(virConnectPtr conn,
  const unsigned char *uuid);
@@ -1140,6 +1144,7 @@ struct _virNetworkDriver {
 virDrvListNetworks  listNetworks;
 virDrvNumOfDefinedNetworks  numOfDefinedNetworks;
 virDrvListDefinedNetworks   listDefinedNetworks;
+virDrvListAllNetworks   listAllNetworks;
 virDrvNetworkLookupByUUID   networkLookupByUUID;
 virDrvNetworkLookupByName   networkLookupByName;
 virDrvNetworkCreateXML  networkCreateXML;
diff --git a/src/libvirt.c b/src/libvirt.c
index 700dbef..686af8a 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -9799,6 +9799,76 @@ virNetworkGetConnect (virNetworkPtr net)
 }
 
 /**
+ * virConnectListAllNetworks:
+ * @conn: Pointer to the hypervisor connection.
+ * @nets: Pointer to a variable to store the array containing the network
+ *objects or NULL if the list is not required (just returns number
+ *of networks).
+ * @flags: bitwise-OR of virConnectListAllNetworksFlags.
+ *
+ * Collect the list of networks, and allocate an array to store those
+ * objects. This API solves the race inherent between virConnectListNetworks
+ * and virConnectListDefinedNetworks.
+ *
+ * Normally, all networks are returned; however, @flags can be used to
+ * filter the results for a smaller list of targeted networks.  The valid
+ * flags are divided into groups, where each group contains bits that
+ * describe mutually exclusive attributes of a network, and where all bits
+ * within a group describe all possible networks.
+ *
+ * The first group of @flags is VIR_CONNECT_LIST_NETWORKS_ACTIVE (up) and
+ * VIR_CONNECT_LIST_NETWORKS_INACTIVE (down) to filter the networks by state.
+ *
+ * The 

[libvirt] [PATCH 3/7] list: Add helpers to list network objects

2012-09-04 Thread Osier Yang
src/conf/network_conf.c: Add virNetworkMatch to filter the networks;
and virNetworkList to iterate over all the networks with the filter.

src/conf/network_conf.h: Declare virNetworkList and define the macros
for filters.

src/libvirt_private.syms: Export virNetworkList.
---
 src/conf/network_conf.c  |   91 ++
 src/conf/network_conf.h  |   22 +++
 src/libvirt_private.syms |1 +
 3 files changed, 114 insertions(+), 0 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 9d53d8e..1ee0951 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -2056,3 +2056,94 @@ void virNetworkObjUnlock(virNetworkObjPtr obj)
 {
 virMutexUnlock(obj-lock);
 }
+
+#define MATCH(FLAG) (flags  (FLAG))
+static bool
+virNetworkMatch (virNetworkObjPtr netobj,
+ unsigned int flags)
+{
+/* filter by active state */
+if (MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) 
+!((MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE) 
+   virNetworkObjIsActive(netobj)) ||
+  (MATCH(VIR_CONNECT_LIST_NETWORKS_INACTIVE) 
+   !virNetworkObjIsActive(netobj
+return false;
+
+/* filter by persistence */
+if (MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT) 
+!((MATCH(VIR_CONNECT_LIST_NETWORKS_PERSISTENT) 
+   netobj-persistent) ||
+  (MATCH(VIR_CONNECT_LIST_NETWORKS_TRANSIENT) 
+   !netobj-persistent)))
+return false;
+
+/* filter by autostart option */
+if (MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART) 
+!((MATCH(VIR_CONNECT_LIST_NETWORKS_AUTOSTART) 
+   netobj-autostart) ||
+  (MATCH(VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART) 
+   !netobj-autostart)))
+return false;
+
+return true;
+}
+#undef MATCH
+
+int
+virNetworkList(virConnectPtr conn,
+   virNetworkObjList netobjs,
+   virNetworkPtr **nets,
+   unsigned int flags)
+{
+virNetworkPtr *tmp_nets = NULL;
+virNetworkPtr net = NULL;
+int nnets = 0;
+int ret = -1;
+int i;
+
+if (nets) {
+if (VIR_ALLOC_N(tmp_nets, netobjs.count + 1)  0) {
+virReportOOMError();
+goto cleanup;
+}
+}
+
+for (i = 0; i  netobjs.count; i++) {
+virNetworkObjPtr netobj = netobjs.objs[i];
+virNetworkObjLock(netobj);
+if (virNetworkMatch(netobj, flags)) {
+if (nets) {
+if (!(net = virGetNetwork(conn,
+  netobj-def-name,
+  netobj-def-uuid))) {
+virNetworkObjUnlock(netobj);
+goto cleanup;
+}
+tmp_nets[nnets] = net;
+}
+nnets++;
+}
+virNetworkObjUnlock(netobj);
+}
+
+if (tmp_nets) {
+/* trim the array to the final size */
+ignore_value(VIR_REALLOC_N(tmp_nets, nnets + 1));
+*nets = tmp_nets;
+tmp_nets = NULL;
+}
+
+ret = nnets;
+
+cleanup:
+if (tmp_nets) {
+for (i = 0; i  nnets; i++) {
+if (tmp_nets[i])
+virNetworkFree(tmp_nets[i]);
+}
+}
+
+VIR_FREE(tmp_nets);
+return ret;
+}
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index f49c367..5dbf50d 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -321,4 +321,26 @@ void virNetworkObjUnlock(virNetworkObjPtr obj);
 
 VIR_ENUM_DECL(virNetworkForward)
 
+# define VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE   \
+(VIR_CONNECT_LIST_NETWORKS_ACTIVE | \
+ VIR_CONNECT_LIST_NETWORKS_INACTIVE)
+
+# define VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT   \
+(VIR_CONNECT_LIST_NETWORKS_PERSISTENT | \
+ VIR_CONNECT_LIST_NETWORKS_TRANSIENT)
+
+# define VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART\
+(VIR_CONNECT_LIST_NETWORKS_AUTOSTART |  \
+ VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART)
+
+# define VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL  \
+(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE | \
+ VIR_CONNECT_LIST_NETWORKS_FILTERS_PERSISTENT | \
+ VIR_CONNECT_LIST_NETWORKS_FILTERS_AUTOSTART)
+
+int virNetworkList(virConnectPtr conn,
+   virNetworkObjList netobjs,
+   virNetworkPtr **nets,
+   unsigned int flags);
+
 #endif /* __NETWORK_CONF_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index abfee47..7464c59 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -837,6 +837,7 @@ virNetworkFindByName;
 virNetworkFindByUUID;
 virNetworkIpDefNetmask;
 virNetworkIpDefPrefix;
+virNetworkList;
 virNetworkLoadAllConfigs;
 virNetworkObjIsDuplicate;
 virNetworkObjListFree;
-- 
1.7.7.3

--
libvir-list mailing list
libvir-list@redhat.com

[libvirt] [PATCH 4/7] list: Implement listAllNetworks for network driver

2012-09-04 Thread Osier Yang
src/network/bridge_driver.c: Implement listAllNetworks.
---
 src/network/bridge_driver.c |   17 +
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 53eebed..73ad43f 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2263,6 +2263,22 @@ static int networkListDefinedNetworks(virConnectPtr 
conn, char **const names, in
 return -1;
 }
 
+static int
+networkListAllNetworks(virConnectPtr conn,
+   virNetworkPtr **nets,
+   unsigned int flags)
+{
+struct network_driver *driver = conn-networkPrivateData;
+int ret = -1;
+
+virCheckFlags(VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL, -1);
+
+networkDriverLock(driver);
+ret = virNetworkList(conn, driver-networks, nets, flags);
+networkDriverUnlock(driver);
+
+return ret;
+}
 
 static int networkIsActive(virNetworkPtr net)
 {
@@ -2793,6 +2809,7 @@ static virNetworkDriver networkDriver = {
 .listNetworks = networkListNetworks, /* 0.2.0 */
 .numOfDefinedNetworks = networkNumDefinedNetworks, /* 0.2.0 */
 .listDefinedNetworks = networkListDefinedNetworks, /* 0.2.0 */
+.listAllNetworks = networkListAllNetworks, /* 0.10.0 */
 .networkLookupByUUID = networkLookupByUUID, /* 0.2.0 */
 .networkLookupByName = networkLookupByName, /* 0.2.0 */
 .networkCreateXML = networkCreate, /* 0.2.0 */
-- 
1.7.7.3

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


[libvirt] [PATCH 5/7] list: Implement listAllNetworks for test driver

2012-09-04 Thread Osier Yang
src/test/test_driver.c: Implement listAllNetworks.
---
 src/test/test_driver.c |   17 +
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 8d93129..821cf72 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3039,6 +3039,22 @@ no_memory:
 return -1;
 }
 
+static int
+testNetworkListAllNetworks(virConnectPtr conn,
+   virNetworkPtr **nets,
+   unsigned int flags)
+{
+testConnPtr privconn = conn-privateData;
+int ret = -1;
+
+virCheckFlags(VIR_CONNECT_LIST_NETWORKS_FILTERS_ALL, -1);
+
+testDriverLock(privconn);
+ret = virNetworkList(conn, privconn-networks, nets, flags);
+testDriverUnlock(privconn);
+
+return ret;
+}
 
 static int testNetworkIsActive(virNetworkPtr net)
 {
@@ -5698,6 +5714,7 @@ static virNetworkDriver testNetworkDriver = {
 .listNetworks = testListNetworks, /* 0.3.2 */
 .numOfDefinedNetworks = testNumDefinedNetworks, /* 0.3.2 */
 .listDefinedNetworks = testListDefinedNetworks, /* 0.3.2 */
+.listAllNetworks = testNetworkListAllNetworks, /* 0.10.0 */
 .networkLookupByUUID = testLookupNetworkByUUID, /* 0.3.2 */
 .networkLookupByName = testLookupNetworkByName, /* 0.3.2 */
 .networkCreateXML = testNetworkCreate, /* 0.3.2 */
-- 
1.7.7.3

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


[libvirt] [PATCH 6/7] list: Use virConnectListAllNetworks in virsh

2012-09-04 Thread Osier Yang
tools/virsh-network.c:
  * vshNetworkSorter to sort networks by name

  * vshNetworkListFree to free the network objects list.

  * vshNetworkListCollect to collect the network objects, trying
to use new API first, fall back to older APIs if it's not supported.

  * New options --persistent, --transient, --autostart, --no-autostart,
for net-list, and new field 'Persistent' for its output.

tools/virsh.pod:
  * Add documents for the new options.
---
 tools/virsh-network.c |  352 
 tools/virsh.pod   |   12 ++-
 2 files changed, 275 insertions(+), 89 deletions(-)

diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index db204af..f6623ff 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -36,6 +36,7 @@
 #include memory.h
 #include util.h
 #include xml.h
+#include conf/network_conf.h
 
 virNetworkPtr
 vshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
@@ -342,6 +343,225 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
 return true;
 }
 
+static int
+vshNetworkSorter(const void *a, const void *b)
+{
+virNetworkPtr *na = (virNetworkPtr *) a;
+virNetworkPtr *nb = (virNetworkPtr *) b;
+
+if (*na  !*nb)
+return -1;
+
+if (!*na)
+return *nb != NULL;
+
+return vshStrcasecmp(virNetworkGetName(*na),
+  virNetworkGetName(*nb));
+}
+
+struct vshNetworkList {
+virNetworkPtr *nets;
+size_t nnets;
+};
+typedef struct vshNetworkList *vshNetworkListPtr;
+
+static void
+vshNetworkListFree(vshNetworkListPtr list)
+{
+int i;
+
+if (list  list-nnets) {
+for (i = 0; i  list-nnets; i++) {
+if (list-nets[i])
+virNetworkFree(list-nets[i]);
+}
+VIR_FREE(list-nets);
+}
+VIR_FREE(list);
+}
+
+static vshNetworkListPtr
+vshNetworkListCollect(vshControl *ctl,
+  unsigned int flags)
+{
+vshNetworkListPtr list = vshMalloc(ctl, sizeof(*list));
+int i;
+int ret;
+char **names = NULL;
+virNetworkPtr net;
+bool success = false;
+size_t deleted = 0;
+int persistent;
+int autostart;
+int nActiveNets = 0;
+int nInactiveNets = 0;
+int nAllNets = 0;
+
+/* try the list with flags support (0.10.0 and later) */
+if ((ret = virConnectListAllNetworks(ctl-conn,
+ list-nets,
+ flags)) = 0) {
+list-nnets = ret;
+goto finished;
+}
+
+/* check if the command is actually supported */
+if (last_error  last_error-code == VIR_ERR_NO_SUPPORT) {
+vshResetLibvirtError();
+goto fallback;
+}
+
+if (last_error  last_error-code ==  VIR_ERR_INVALID_ARG) {
+/* try the new API again but mask non-guaranteed flags */
+unsigned int newflags = flags  (VIR_CONNECT_LIST_NETWORKS_ACTIVE |
+ VIR_CONNECT_LIST_NETWORKS_INACTIVE);
+
+vshResetLibvirtError();
+if ((ret = virConnectListAllNetworks(ctl-conn, list-nets,
+ newflags)) = 0) {
+list-nnets = ret;
+goto filter;
+}
+}
+
+/* there was an error during the first or second call */
+vshError(ctl, %s, _(Failed to list networks));
+goto cleanup;
+
+
+fallback:
+/* fall back to old method (0.9.13 and older) */
+vshResetLibvirtError();
+
+/* Get the number of active networks */
+if (!MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
+MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) {
+if ((nActiveNets = virConnectNumOfNetworks(ctl-conn))  0) {
+vshError(ctl, %s, _(Failed to get the number of active 
networks));
+goto cleanup;
+}
+}
+
+/* Get the number of inactive networks */
+if (!MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
+MATCH(VIR_CONNECT_LIST_NETWORKS_INACTIVE)) {
+if ((nInactiveNets = virConnectNumOfDefinedNetworks(ctl-conn))  0) {
+vshError(ctl, %s, _(Failed to get the number of inactive 
networks));
+goto cleanup;
+}
+}
+
+nAllNets = nActiveNets + nInactiveNets;
+
+if (nAllNets == 0)
+ return list;
+
+names = vshMalloc(ctl, sizeof(char *) * nAllNets);
+
+/* Retrieve a list of active network names */
+if (!MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
+MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) {
+if (virConnectListNetworks(ctl-conn,
+   names, nActiveNets)  0) {
+vshError(ctl, %s, _(Failed to list active networks));
+goto cleanup;
+}
+}
+
+/* Add the inactive networks to the end of the name list */
+if (!MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) ||
+MATCH(VIR_CONNECT_LIST_NETWORKS_ACTIVE)) {
+if (virConnectListDefinedNetworks(ctl-conn,
+  

[libvirt] [PATCH 2/7] list: Implement RPC calls for virConnectListAllNetworks

2012-09-04 Thread Osier Yang
The RPC generator doesn't support returning list of object, this patch
do the work manually.

* daemon/remote.c:
  Implemente the server side handler remoteDispatchConnectListAllNetworks.

* src/remote/remote_driver.c:
  Add remote driver handler remoteConnectListAllNetworks.

* src/remote/remote_protocol.x:
  New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS and
  structs to represent the args and ret for it.

* src/remote_protocol-structs: Likewise.
---
 daemon/remote.c  |   55 
 src/remote/remote_driver.c   |   64 ++
 src/remote/remote_protocol.x |   13 -
 src/remote_protocol-structs  |   12 
 4 files changed, 143 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 8208c71..dba51a7 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4211,6 +4211,61 @@ cleanup:
 return rv;
 }
 
+static int
+remoteDispatchConnectListAllNetworks(virNetServerPtr server ATTRIBUTE_UNUSED,
+ virNetServerClientPtr client,
+ virNetMessagePtr msg ATTRIBUTE_UNUSED,
+ virNetMessageErrorPtr rerr,
+ remote_connect_list_all_networks_args 
*args,
+ remote_connect_list_all_networks_ret *ret)
+{
+virNetworkPtr *nets = NULL;
+int nnets = 0;
+int i;
+int rv = -1;
+struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+if (!priv-conn) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s, _(connection not open));
+goto cleanup;
+}
+
+if ((nnets = virConnectListAllNetworks(priv-conn,
+   args-need_results ? nets : NULL,
+   args-flags))  0)
+goto cleanup;
+
+if (nets  nnets) {
+if (VIR_ALLOC_N(ret-nets.nets_val, nnets)  0) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret-nets.nets_len = nnets;
+
+for (i = 0; i  nnets; i++)
+make_nonnull_network(ret-nets.nets_val + i, nets[i]);
+} else {
+ret-nets.nets_len = 0;
+ret-nets.nets_val = NULL;
+}
+
+ret-ret = nnets;
+
+rv = 0;
+
+cleanup:
+if (rv  0)
+virNetMessageSaveError(rerr);
+if (nets) {
+for (i = 0; i  nnets; i++)
+virNetworkFree(nets[i]);
+VIR_FREE(nets);
+}
+return rv;
+}
+
+
 /*- Helpers. -*/
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 8d4420e..56e50a6 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2718,6 +2718,69 @@ done:
 return rv;
 }
 
+static int
+remoteConnectListAllNetworks(virConnectPtr conn,
+ virNetworkPtr **nets,
+ unsigned int flags)
+{
+int rv = -1;
+int i;
+virNetworkPtr *tmp_nets = NULL;
+remote_connect_list_all_networks_args args;
+remote_connect_list_all_networks_ret ret;
+
+struct private_data *priv = conn-privateData;
+
+remoteDriverLock(priv);
+
+args.need_results = !!nets;
+args.flags = flags;
+
+memset(ret, 0, sizeof(ret));
+if (call(conn,
+ priv,
+ 0,
+ REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS,
+ (xdrproc_t) xdr_remote_connect_list_all_networks_args,
+ (char *) args,
+ (xdrproc_t) xdr_remote_connect_list_all_networks_ret,
+ (char *) ret) == -1)
+goto done;
+
+if (nets) {
+if (VIR_ALLOC_N(tmp_nets, ret.nets.nets_len + 1)  0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (i = 0; i  ret.nets.nets_len; i++) {
+tmp_nets[i] = get_nonnull_network (conn, ret.nets.nets_val[i]);
+if (!tmp_nets[i]) {
+virReportOOMError();
+goto cleanup;
+}
+}
+*nets = tmp_nets;
+tmp_nets = NULL;
+}
+
+rv = ret.ret;
+
+cleanup:
+if (tmp_nets) {
+for (i = 0; i  ret.nets.nets_len; i++)
+if (tmp_nets[i])
+virNetworkFree(tmp_nets[i]);
+VIR_FREE(tmp_nets);
+}
+
+xdr_free((xdrproc_t) xdr_remote_connect_list_all_networks_ret, (char *) 
ret);
+
+done:
+remoteDriverUnlock(priv);
+return rv;
+}
+
 
 /*--*/
 
@@ -5696,6 +5759,7 @@ static virNetworkDriver network_driver = {
 .listNetworks = remoteListNetworks, /* 0.3.0 */
 .numOfDefinedNetworks = remoteNumOfDefinedNetworks, /* 0.3.0 */
 .listDefinedNetworks = remoteListDefinedNetworks, /* 0.3.0 */
+.listAllNetworks = remoteConnectListAllNetworks, /* 0.10.0 */
 .networkLookupByUUID = 

[libvirt] [PATCH 0/7 v4] Atomic API to list networks

2012-09-04 Thread Osier Yang
v3 - v4:
  - Just rebase on top, and split the API from the big set

Osier Yang (7):
  list: Define new API virConnectListAllNetworks
  list: Implement RPC calls for virConnectListAllNetworks
  list: Add helpers to list network objects
  list: Implement listAllNetworks for network driver
  list: Implement listAllNetworks for test driver
  list: Use virConnectListAllNetworks in virsh
  list: Expose virConnectListAllNetworks to Python binding

 daemon/remote.c   |   55 +
 include/libvirt/libvirt.h.in  |   20 ++
 python/generator.py   |1 +
 python/libvirt-override-api.xml   |6 +
 python/libvirt-override-virConnect.py |   12 ++
 python/libvirt-override.c |   48 +
 src/conf/network_conf.c   |   91 +
 src/conf/network_conf.h   |   22 ++
 src/driver.h  |5 +
 src/libvirt.c |   86 -
 src/libvirt_private.syms  |1 +
 src/libvirt_public.syms   |1 +
 src/network/bridge_driver.c   |   17 ++
 src/remote/remote_driver.c|   64 ++
 src/remote/remote_protocol.x  |   13 ++-
 src/remote_protocol-structs   |   12 ++
 src/test/test_driver.c|   17 ++
 tools/virsh-network.c |  352 
 tools/virsh.pod   |   12 +-
 19 files changed, 743 insertions(+), 92 deletions(-)

-- 
1.7.7.3

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


[libvirt] [PATCH 7/7] list: Expose virConnectListAllNetworks to Python binding

2012-09-04 Thread Osier Yang
The implementation is done manually as the generator does not support
wrapping lists of C pointers into Python objects.

python/libvirt-override-api.xml: Document

python/libvirt-override-virConnect.py: Implement listAllNetworks.

python/libvirt-override.c: Implementation for the wrapper.
---
 python/libvirt-override-api.xml   |6 
 python/libvirt-override-virConnect.py |   12 
 python/libvirt-override.c |   48 +
 3 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 8a228fb..5f51fc7 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -37,6 +37,12 @@
   arg name='conn' type='virConnectPtr' info='pointer to the hypervisor 
connection'/
   return type='str *' info='the list of Names or None in case of error'/
 /function
+function name='virConnectListAllNetworks' file='python'
+  inforeturns list of all networks/info
+  arg name='conn' type='virConnectPtr' info='pointer to the hypervisor 
connection'/
+  arg name='flags' type='unsigned int' info='optional flags'/
+  return type='network *' info='the list of networks or None in case of 
error'/
+/function
 function name='virDomainLookupByUUID' file='python'
   infoTry to lookup a domain on the given hypervisor based on its 
UUID./info
   return type='virDomainPtr' info='a new domain object or NULL in case of 
failure'/
diff --git a/python/libvirt-override-virConnect.py 
b/python/libvirt-override-virConnect.py
index 87a737f..85db5fe 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -218,3 +218,15 @@
 retlist.append(virStoragePool(self, _obj=poolptr))
 
 return retlist
+
+def listAllNetworks(self, flags):
+Returns a list of network objects
+ret = libvirtmod.virConnectListAllNetworks(self._o, flags)
+if ret is None:
+raise libvirtError(virConnectListAllNetworks() failed, conn=self)
+
+retlist = list()
+for netptr in ret:
+retlist.append(virNetwork(self, _obj=netptr))
+
+return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 8b402b0..3426560 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -2594,6 +2594,53 @@ libvirt_virConnectListDefinedNetworks(PyObject *self 
ATTRIBUTE_UNUSED,
 return py_retval;
 }
 
+static PyObject *
+libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
+  PyObject *args)
+{
+PyObject *pyobj_conn;
+PyObject *py_retval = NULL;
+PyObject *tmp = NULL;
+virConnectPtr conn;
+virNetworkPtr *nets = NULL;
+int c_retval = 0;
+int i;
+unsigned int flags;
+
+if (!PyArg_ParseTuple(args, (char *)Oi:virConnectListAllNetworks,
+  pyobj_conn, flags))
+return NULL;
+conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virConnectListAllNetworks(conn, nets, flags);
+LIBVIRT_END_ALLOW_THREADS;
+if (c_retval  0)
+return VIR_PY_NONE;
+
+if (!(py_retval = PyList_New(c_retval)))
+goto cleanup;
+
+for (i = 0; i  c_retval; i++) {
+if (!(tmp = libvirt_virNetworkPtrWrap(nets[i])) ||
+PyList_SetItem(py_retval, i, tmp)  0) {
+Py_XDECREF(tmp);
+Py_DECREF(py_retval);
+py_retval = NULL;
+goto cleanup;
+}
+/* python steals the pointer */
+nets[i] = NULL;
+}
+
+cleanup:
+for (i = 0; i  c_retval; i++)
+if (nets[i])
+virNetworkFree(nets[i]);
+VIR_FREE(nets);
+return py_retval;
+}
+
 
 static PyObject *
 libvirt_virNetworkGetUUID(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
@@ -5943,6 +5990,7 @@ static PyMethodDef libvirtMethods[] = {
 {(char *) virConnGetLastError, libvirt_virConnGetLastError, 
METH_VARARGS, NULL},
 {(char *) virConnectListNetworks, libvirt_virConnectListNetworks, 
METH_VARARGS, NULL},
 {(char *) virConnectListDefinedNetworks, 
libvirt_virConnectListDefinedNetworks, METH_VARARGS, NULL},
+{(char *) virConnectListAllNetworks, libvirt_virConnectListAllNetworks, 
METH_VARARGS, NULL},
 {(char *) virNetworkGetUUID, libvirt_virNetworkGetUUID, METH_VARARGS, 
NULL},
 {(char *) virNetworkGetUUIDString, libvirt_virNetworkGetUUIDString, 
METH_VARARGS, NULL},
 {(char *) virNetworkLookupByUUID, libvirt_virNetworkLookupByUUID, 
METH_VARARGS, NULL},
-- 
1.7.7.3

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


[libvirt] [PATCH 0/5 v4] Atomic API to list host interfaces

2012-09-04 Thread Osier Yang
v3 - v4:
  - Just rebase on the top, split the API from v3's big set.

Osier Yang (5):
  list: Define new API virConnectListAllInterfaces
  list: Implemente RPC calls for virConnectListAllInterfaces
  list: Implement listAllInterfaces
  list: Use virConnectListAllInterfaces in virsh
  list: Expose virConnectListAllInterfaces to Python binding

 daemon/remote.c   |   54 +++
 include/libvirt/libvirt.h.in  |   13 ++
 python/generator.py   |1 +
 python/libvirt-override-api.xml   |6 +
 python/libvirt-override-virConnect.py |   12 ++
 python/libvirt-override.c |   48 ++
 src/driver.h  |5 +
 src/interface/netcf_driver.c  |  135 +
 src/libvirt.c |   77 ++-
 src/libvirt_public.syms   |1 +
 src/remote/remote_driver.c|   64 
 src/remote/remote_protocol.x  |   13 ++-
 src/remote_protocol-structs   |   12 ++
 tools/virsh-interface.c   |  257 +++--
 14 files changed, 621 insertions(+), 77 deletions(-)

-- 
1.7.7.3

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


[libvirt] [PATCH 3/5] list: Implement listAllInterfaces

2012-09-04 Thread Osier Yang
This is not that ideal as API for other objects, as it's still
O(n). Because interface driver uses netcf APIs to manage the
stuffs, instead of by itself. And netcf APIs don't return a object.
It provides APIs like old libvirt APIs:

   ncf_number_of_interfaces
   ncf_list_interfaces
   ncf_lookup_by_name
   ..

Perhaps we should further hack netcf to let it provide an API
to return the object, but it could be a later patch. And anyway,
we will still befinit from the new API for the simplification,
and no race like the old APIs.

src/interface/netcf_driver.c: Implement listAllInterfaces
---
 src/interface/netcf_driver.c |  135 ++
 1 files changed, 135 insertions(+), 0 deletions(-)

diff --git a/src/interface/netcf_driver.c b/src/interface/netcf_driver.c
index 935be66..1dae99b 100644
--- a/src/interface/netcf_driver.c
+++ b/src/interface/netcf_driver.c
@@ -259,6 +259,140 @@ static int interfaceListDefinedInterfaces(virConnectPtr 
conn, char **const names
 
 }
 
+static int
+interfaceListAllInterfaces(virConnectPtr conn,
+   virInterfacePtr **ifaces,
+   unsigned int flags)
+{
+struct interface_driver *driver = conn-interfacePrivateData;
+int count;
+int i;
+struct netcf_if *iface = NULL;
+virInterfacePtr *tmp_iface_objs = NULL;
+virInterfacePtr iface_obj = NULL;
+unsigned int status;
+int niface_objs = 0;
+int ret = -1;
+char **names;
+
+virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
+  VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+
+interfaceDriverLock(driver);
+
+/* List all interfaces, in case of we might support new filter flags
+ * except active|inactive in future.
+ */
+count = ncf_num_of_interfaces(driver-netcf, NETCF_IFACE_ACTIVE |
+  NETCF_IFACE_INACTIVE);
+if (count  0) {
+const char *errmsg, *details;
+int errcode = ncf_error(driver-netcf, errmsg, details);
+virReportError(netcf_to_vir_err(errcode),
+   _(failed to get number of host interfaces: %s%s%s),
+   errmsg, details ?  -  : ,
+   details ? details : );
+return -1;
+}
+
+if (count == 0)
+return 0;
+
+if (VIR_ALLOC_N(names, count)  0) {
+virReportOOMError();
+return -1;
+}
+
+if ((count = ncf_list_interfaces(driver-netcf, count, names,
+ NETCF_IFACE_ACTIVE |
+ NETCF_IFACE_INACTIVE))  0) {
+const char *errmsg, *details;
+int errcode = ncf_error(driver-netcf, errmsg, details);
+virReportError(netcf_to_vir_err(errcode),
+   _(failed to list host interfaces: %s%s%s),
+   errmsg, details ?  -  : ,
+   details ? details : );
+goto cleanup;
+}
+
+if (ifaces) {
+if (VIR_ALLOC_N(tmp_iface_objs, count + 1)  0) {
+virReportOOMError();
+goto cleanup;
+}
+}
+
+for (i = 0; i  count; i++) {
+iface = ncf_lookup_by_name(driver-netcf, names[i]);
+if (!iface) {
+const char *errmsg, *details;
+int errcode = ncf_error(driver-netcf, errmsg, details);
+if (errcode != NETCF_NOERROR) {
+virReportError(netcf_to_vir_err(errcode),
+   _(couldn't find interface named '%s': %s%s%s),
+   names[i], errmsg,
+   details ?  -  : , details ? details : );
+} else {
+virReportError(VIR_ERR_NO_INTERFACE,
+ _(couldn't find interface named '%s'), 
names[i]);
+}
+goto cleanup;
+}
+
+if (ncf_if_status(iface, status)  0) {
+const char *errmsg, *details;
+int errcode = ncf_error(driver-netcf, errmsg, details);
+virReportError(netcf_to_vir_err(errcode),
+   _(failed to get status of interface %s: %s%s%s),
+   names[i], errmsg, details ?  -  : ,
+   details ? details : );
+goto cleanup;
+}
+
+/* XXX: Filter the result, need to be splitted once new fitler flags
+ * except active|inactive are supported.
+ */
+if (((status  NETCF_IFACE_ACTIVE) 
+ (flags  VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
+((status  NETCF_IFACE_INACTIVE) 
+ (flags  VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
+if (ifaces) {
+iface_obj = virGetInterface(conn, ncf_if_name(iface),
+ncf_if_mac_string(iface));
+tmp_iface_objs[niface_objs] = iface_obj;
+}
+niface_objs++;
+}
+}
+
+if (tmp_iface_objs) {
+ 

[libvirt] [PATCH 2/5] list: Implemente RPC calls for virConnectListAllInterfaces

2012-09-04 Thread Osier Yang
The RPC generator doesn't support returning list of object yet, this patch
do the work manually.

  * daemon/remote.c:
Implemente the server side handler remoteDispatchConnectListAllInterfaces.

  * src/remote/remote_driver.c:
Add remote driver handler remoteConnectListAllInterfaces.

  * src/remote/remote_protocol.x:
New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES and
structs to represent the args and ret for it.

  * src/remote_protocol-structs: Likewise.
---
 daemon/remote.c  |   54 +++
 src/remote/remote_driver.c   |   64 ++
 src/remote/remote_protocol.x |   13 -
 src/remote_protocol-structs  |   12 
 4 files changed, 142 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index dba51a7..fe2f9dd 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4265,6 +4265,60 @@ cleanup:
 return rv;
 }
 
+static int
+remoteDispatchConnectListAllInterfaces(virNetServerPtr server ATTRIBUTE_UNUSED,
+   virNetServerClientPtr client,
+   virNetMessagePtr msg ATTRIBUTE_UNUSED,
+   virNetMessageErrorPtr rerr,
+   remote_connect_list_all_interfaces_args 
*args,
+   remote_connect_list_all_interfaces_ret 
*ret)
+{
+virInterfacePtr *ifaces = NULL;
+int nifaces = 0;
+int i;
+int rv = -1;
+struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+if (!priv-conn) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s, _(connection not open));
+goto cleanup;
+}
+
+if ((nifaces = virConnectListAllInterfaces(priv-conn,
+   args-need_results ? ifaces : 
NULL,
+   args-flags))  0)
+goto cleanup;
+
+if (ifaces  nifaces) {
+if (VIR_ALLOC_N(ret-ifaces.ifaces_val, nifaces)  0) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret-ifaces.ifaces_len = nifaces;
+
+for (i = 0; i  nifaces; i++)
+make_nonnull_interface(ret-ifaces.ifaces_val + i, ifaces[i]);
+} else {
+ret-ifaces.ifaces_len = 0;
+ret-ifaces.ifaces_val = NULL;
+}
+
+ret-ret = nifaces;
+
+rv = 0;
+
+cleanup:
+if (rv  0)
+virNetMessageSaveError(rerr);
+if (ifaces) {
+for (i = 0; i  nifaces; i++)
+virInterfaceFree(ifaces[i]);
+VIR_FREE(ifaces);
+}
+return rv;
+}
+
 
 /*- Helpers. -*/
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 56e50a6..5c97061 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2781,6 +2781,69 @@ done:
 return rv;
 }
 
+static int
+remoteConnectListAllInterfaces(virConnectPtr conn,
+   virInterfacePtr **ifaces,
+   unsigned int flags)
+{
+int rv = -1;
+int i;
+virInterfacePtr *tmp_ifaces = NULL;
+remote_connect_list_all_interfaces_args args;
+remote_connect_list_all_interfaces_ret ret;
+
+struct private_data *priv = conn-privateData;
+
+remoteDriverLock(priv);
+
+args.need_results = !!ifaces;
+args.flags = flags;
+
+memset(ret, 0, sizeof(ret));
+if (call(conn,
+ priv,
+ 0,
+ REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES,
+ (xdrproc_t) xdr_remote_connect_list_all_interfaces_args,
+ (char *) args,
+ (xdrproc_t) xdr_remote_connect_list_all_interfaces_ret,
+ (char *) ret) == -1)
+goto done;
+
+if (ifaces) {
+if (VIR_ALLOC_N(tmp_ifaces, ret.ifaces.ifaces_len + 1)  0) {
+virReportOOMError();
+goto cleanup;
+}
+
+for (i = 0; i  ret.ifaces.ifaces_len; i++) {
+tmp_ifaces[i] = get_nonnull_interface (conn, 
ret.ifaces.ifaces_val[i]);
+if (!tmp_ifaces[i]) {
+virReportOOMError();
+goto cleanup;
+}
+}
+*ifaces = tmp_ifaces;
+tmp_ifaces = NULL;
+}
+
+rv = ret.ret;
+
+cleanup:
+if (tmp_ifaces) {
+for (i = 0; i  ret.ifaces.ifaces_len; i++)
+if (tmp_ifaces[i])
+virInterfaceFree(tmp_ifaces[i]);
+VIR_FREE(tmp_ifaces);
+}
+
+xdr_free((xdrproc_t) xdr_remote_connect_list_all_interfaces_ret, (char *) 
ret);
+
+done:
+remoteDriverUnlock(priv);
+return rv;
+}
+
 
 /*--*/
 
@@ -5783,6 +5846,7 @@ static virInterfaceDriver interface_driver = {
 .listInterfaces = remoteListInterfaces, /* 0.7.2 */
 .numOfDefinedInterfaces = remoteNumOfDefinedInterfaces, /* 0.7.2 */
 .listDefinedInterfaces = remoteListDefinedInterfaces, 

[libvirt] [PATCH 5/5] list: Expose virConnectListAllInterfaces to Python binding

2012-09-04 Thread Osier Yang
The implementation is done manually as the generator does not support
wrapping lists of C pointers into Python objects.

python/libvirt-override-api.xml: Document

python/libvirt-override-virConnect.py:
  * New file, includes implementation of listAllInterfaces.

python/libvirt-override.c: Implementation for the wrapper.
---
 python/libvirt-override-api.xml   |6 
 python/libvirt-override-virConnect.py |   12 
 python/libvirt-override.c |   48 +
 3 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index 5f51fc7..ab6f407 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -416,6 +416,12 @@
   arg name='conn' type='virConnectPtr' info='pointer to the hypervisor 
connection'/
   return type='str *' info='the list of Names of None in case of error'/
 /function
+function name='virConnectListAllInterfaces' file='python'
+  inforeturns list of all interfaces/info
+  arg name='conn' type='virConnectPtr' info='pointer to the hypervisor 
connection'/
+  arg name='flags' type='unsigned int' info='optional flags'/
+  return type='interface *' info='the list of interfaces or None in case 
of error'/
+/function
 function name='virConnectBaselineCPU' file='python'
   infoComputes the most feature-rich CPU which is compatible with all 
given host CPUs./info
   return type='char *' info='XML description of the computed CPU or NULL 
on error.'/
diff --git a/python/libvirt-override-virConnect.py 
b/python/libvirt-override-virConnect.py
index 85db5fe..ffa1a3c 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -230,3 +230,15 @@
 retlist.append(virNetwork(self, _obj=netptr))
 
 return retlist
+
+def listAllInterfaces(self, flags):
+Returns a list of interface objects
+ret = libvirtmod.virConnectListAllInterfaces(self._o, flags)
+if ret is None:
+raise libvirtError(virConnectListAllInterfaces() failed, 
conn=self)
+
+retlist = list()
+for ifaceptr in ret:
+retlist.append(virInterface(self, _obj=ifaceptr))
+
+return retlist
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 3426560..0675545 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -3824,6 +3824,53 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self 
ATTRIBUTE_UNUSED,
 
 
 static PyObject *
+libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
+PyObject *args)
+{
+PyObject *pyobj_conn;
+PyObject *py_retval = NULL;
+PyObject *tmp = NULL;
+virConnectPtr conn;
+virInterfacePtr *ifaces = NULL;
+int c_retval = 0;
+int i;
+unsigned int flags;
+
+if (!PyArg_ParseTuple(args, (char *)Oi:virConnectListAllInterfaces,
+  pyobj_conn, flags))
+return NULL;
+conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+LIBVIRT_BEGIN_ALLOW_THREADS;
+c_retval = virConnectListAllInterfaces(conn, ifaces, flags);
+LIBVIRT_END_ALLOW_THREADS;
+if (c_retval  0)
+return VIR_PY_NONE;
+
+if (!(py_retval = PyList_New(c_retval)))
+goto cleanup;
+
+for (i = 0; i  c_retval; i++) {
+if (!(tmp = libvirt_virInterfacePtrWrap(ifaces[i])) ||
+PyList_SetItem(py_retval, i, tmp)  0) {
+Py_XDECREF(tmp);
+Py_DECREF(py_retval);
+py_retval = NULL;
+goto cleanup;
+}
+/* python steals the pointer */
+ifaces[i] = NULL;
+}
+
+cleanup:
+for (i = 0; i  c_retval; i++)
+if (ifaces[i])
+virInterfaceFree(ifaces[i]);
+VIR_FREE(ifaces);
+return py_retval;
+}
+
+static PyObject *
 libvirt_virConnectBaselineCPU(PyObject *self ATTRIBUTE_UNUSED,
   PyObject *args) {
 PyObject *pyobj_conn;
@@ -6049,6 +6096,7 @@ static PyMethodDef libvirtMethods[] = {
 {(char *) virConnectListNWFilters, libvirt_virConnectListNWFilters, 
METH_VARARGS, NULL},
 {(char *) virConnectListInterfaces, libvirt_virConnectListInterfaces, 
METH_VARARGS, NULL},
 {(char *) virConnectListDefinedInterfaces, 
libvirt_virConnectListDefinedInterfaces, METH_VARARGS, NULL},
+{(char *) virConnectListAllInterfaces, 
libvirt_virConnectListAllInterfaces, METH_VARARGS, NULL},
 {(char *) virConnectBaselineCPU, libvirt_virConnectBaselineCPU, 
METH_VARARGS, NULL},
 {(char *) virDomainGetJobInfo, libvirt_virDomainGetJobInfo, 
METH_VARARGS, NULL},
 {(char *) virDomainSnapshotListNames, 
libvirt_virDomainSnapshotListNames, METH_VARARGS, NULL},
-- 
1.7.7.3

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


  1   2   >